ZK Hack Lisbon: Pragmatic Privacy with Liminal - Aleph Zero
20 Apr 2023 · 36:23
Recorded at ZK Hack Lisbon, Zero Knowledge's first in-person zk hackathon, this talk from the team at Liminal covers pragmatic approaches to privacy built on Aleph Zero. It touches on the zero-knowledge tooling and domain-specific languages hackathon builders used over the event and how privacy-preserving techniques can move from research into real-world applications.
Topics
Transcript
foreign [Music] and today alongside my my colleague and actually our co-founder Adam we're gonna tell you a bit about our shielder which is our like latest privacy offering and our smart contracts and our blockchain and everything so this is meant to be uh on my side a very practical introduction for those interested in building with Outlet zero Adam's part which comes at the end will
contain a lot more you know like higher science and looking into the future so please stay for that as well oh I'm going to take the clicker okay um right so so in case you know you want to go hack on your projects and I I want to be completely transparent here and I'm going to say what I'm gonna say uh first I'm gonna do a very short intro to Alex zero as a blockchain as a platform uh then we're gonna take a look at the shielder like you know a very very broad overview bird's eye view basically then I'm gonna do a short demo of the shielder [Music] next we're gonna take a look at the Ink Smart contracts uh I'm sure a lot of you
already know how to write Ink Smart contracts but hey that's what I do I talk about ink so um I'm gonna do just that then a short demo of how to create a PSP 22 token on ls0 using open brush the the library and then comes Adams comes Adam's part with uh with the kind of future of defy in context of privacy and the shielder and possible extensions and whatnot uh it's going to be good stay tuned for that um okay so the the context of this whole talk is lf0 our layer one proof of stake blockchain with some nice privacy Solutions um very fast finality time to finality
very low transaction cost sounds good doesn't it and then well we have Smart contracts in ink and actually as of last week they are deployed on mainnet there's there's some products being ran there's some you know protocols some sorry the ol this week yeah it was this week wow um it's it's the release date is in the past it's already released you can even mint yourself an nft um if you're into that so yeah uh this is for for the useful links in case you want to you know like interactively follow along or even uh just you know to make it handy for you
to to play around with the with the chain and the smart contracts uh this QR code is actually the first link our main website which uh in I think at most two hops will lead you to all of the other stuff so so yeah you can you can scan that um I I see someone scanning that's good yeah please do or you can just type in the addresses there or not super complicated um everyone done oh no see I never I'm never on time with uh scanning so I want to give you some some room all done cool that's very cool okay so so this this is
maybe a bit trivial but and pretty apparent to to everyone but uh in a lot of use cases we don't want to reveal exactly what we are doing exactly what funds are being sent where um you know the whole privacy thing so examples of such settings in which you want to you know hide something from the prying eye would be for example voting as seen in Taos so private voting really cool [Music] and I guess voting in general yeah like imagine a voting in the country should be private ideally um yeah the nzk identity you know like kyc KYB also really cool if not everyone sees a scan of your ID
um dark pools so you know if you want to for example sell a lot of some some asset without impacting the market price that's also a good use case for privacy and as we will see later with Adam's talk actually defy uh yeah the Privacy fits very well and can give you some serious you know like value add added um yeah let's let's move on so so what what you're proposing here and uh mind you that this this is of course like live in a sense that you can as a developer uh go to the repository and play with it it's actually very convenient as we're gonna see later uh but of course the you know the work never stops the building never stops we're constantly working on adding new
features and new extensions and whatnot um but what I would like to present here now is basically a private wallet so imagine a place where you can send your assets and there they are completely you know uh private there in a sense that I cannot go into the into the shielder and uh say that okay I see that you've got X of the of some token right you can just see the the overall amounts of tokens in the shielder but not individual account balances and then of course you can you can withdraw uh to your own account or to another account uh thereby you know having something like a shielded
transfers as we are going to see later this is actually hugely expressive and can allow you to interact with a whole range of D5 products in a well I wouldn't say private but but like more private way shielded way is perhaps the word um yeah of course there's there's some there's some the the Privacy land here is um basically short for some ZK snark magic I don't really have the grasp off but uh but yeah I I trust the people who built it it's uh they are smart people and um yeah I think it works you can check out for yourself in the in the wrapper which
by the way is here um if you choose to scan this one uh you'll have the shielder GitHub repository um which is quite cool because as we're gonna see in just uh in just a moment it's actually extremely easy to set up and to play around with and to experiment and to you know even extend um yeah you're scanning that's cool I actually have the very same QR code on the next slide as well so uh I think in like five seconds I'm gonna switch but the code is going to stay ah there you go um so first of all what I myself dislike
about uh you know bootstrapping like programming projects is the the number of dependencies um here that's not the case because for like your most basic use case and uh getting to know shielder you just need Docker obviously uh Docker Docker compose in the Standalone version this will probably change but for now it's the Standalone versions of the one with the you know with the hyphen and JQ which is the the Json thing you know the library that can parse Json and process Json uh if you're going to play around more with uh with the shielder and more specifically with the cargo contracts or if you want to build Chiller yourself and so on uh you will eventually need rust and
cargo the usual combo but also the cargo contract extension uh that's that's like a manager for the for the smart contracts have this cool yeah so once once you've done with the once you're done with the previous slide uh and this is pretty amazing because you just use this this this magical script and um and yeah it just you know spews a lot of output and there you have it like um a few Docker containers some contracts some accounts set up so basically you don't need to do any of the of the grunt work of having to you know launch some instances launching a local local chain uh bootstrapping the the accounts and
everything that's just there for you to play with so I would say it it took me like all of I don't know five minutes to to to to actually get to the to the real deal um and like I said I'm not I'm not one of the developers working on that so uh yeah I'm a good Benchmark actually um yeah um oh by the way if you're following this along which I maybe someone is then the accounts we're gonna use Wherever Whenever shielder asks you for the seed would be Damian enhance which is uh slash slash zero and slash one in their real setting you'd probably use a very
different seeds but this is just a you know we will be here we'll be working within the context of like a local local chain and local instances so that's that's just convenient have this keep forgetting um yeah so basically the shielder contains like three folders one for the deploy one one for the contracts or actually four maybe right one for the for the tokens and one for the CLI and inside it should already be built but if you don't have this binary in your target slash release folder in the CLI you can just run cargo build uh that's that's release and and it will it will be built for you and then you can
just use the binary um so first what we can do is show the assets that are inside the shielder and I'm very much at you know at conflict with myself whether I want to actually show you how this works uh with a live demo maybe later actually maybe later um so yeah this will just show you the assets and I think without you know loss of generality I can say that those will be the assets that you deposit into the shielder right so you won't be able to to Snoop on anyone else um but you know to in order to have some assets to show You're Gonna Want to deposit something into the shielder so the oh I have an error here it's it's
actually it deposits a hundred monies not not 10. but that's okay the zero here is the like the index of the smart contract in the default setup you will have two so here we're using the first smart contract so those are like two PSP 22 tokens if if you were not familiar with PSP 22 it's like erc20 basically lots of acronyms I guess but that's okay it's very simple um yeah so once you deposit of course uh you can you can withdraw well you can withdraw what you've deposited or you can withdraw less uh in which case the shielder will internally do do its crypto magic and update your balance also it will make sure that
you're not withdrawing more than you've deposited this would be bad um you need to you need to supply the deposit ID if you're doing the show assets you're gonna see which deposit has switch ID so it's it's pretty straightforward of course you need to give it the amount but the the API is just as simple as that one cool thing is that you don't really need to deposit into your own account you can deposit into well someone else's account which is sort of kind of sort of like a shielded transfer here actually if you maybe I'll post the slides because this account here is uh one of the accounts already bootstrapped in the in the project
which you can by the way learn by inspecting the deploy sh file so it works actually the same same way as regular withdrawal you just Supply the recipient field and yeah just like that you know and that's that's pretty much it when it comes to like the user facing side of the shielder now what you choose to do with it is a whole other story but I think Adam is gonna is gonna get to that in just a few minutes actually um but yeah you know like the I would say that Simplicity is the ultimate complexity as someone said uh I don't know who Mick Jagger Maybe um yeah so here I wanted to kind of like
swerve towards uh familiar territory because when you're shielding assets with shielder obviously you'll need to have some assets to Shield and uh on lf0 you'll most probably want to do that in ink actually uh it's it's interesting because you theoretically wouldn't have to do it in ink you can do it in anything that compiles to wasm but in ink is basically the the simplest way uh so what's ink well ink is an edsl for rust uh that stands for embedded domain specific language which which is a fancy word for well Inc being basically a subset of rust with some additional macros that
take care of a few things for you so it's actually really cool that you know you don't have to learn a separate language you don't have this overhead if you know rust you can just start writing but if you don't know rust actually Inc is very simple to learn because it's Inc is arguably way less complex than the full rust uh full rust language with all its constructs so we think rust is pretty cool because it's a modern language like it has quite evidently been designed with by someone who has done his research but at the same time was very practical when doing so so yeah really cool features type safety with without uh Without Really you know some weird constructs memory
safety without overhead which is actually really cool the tooling is good for us and rust constantly keeps winning like stack Overflow surveys for the most liked Language by the developers so I think that counts for something now the the like the flavor of rust we were using here are basically the compiler backend we're using here is uh wasm which you probably know right web assembly which is cool because it's ubiquitous in a sense that it's supported by by everything it's fast and secure I'm not gonna dive into into the the security of of wasm
but but something I want to touch upon and please don't pay too close attention to this table because it's mostly a pretext for me to talk about differences and similarities between solidity and ink because well uh most of the developers will be probably coming to from solidity or will have some prior experience so basically uh like a soft guarantee I'm I'm giving to to our projects is that uh more or less the concepts from solidity map one to one to rust right or to Inc in that case uh so it's well you probably have to use a slightly different syntax and maybe Express the
concepts in slightly a different way but there's no fundamental like differences in in philosophy uh I would say ink is slightly safer and uh at least to me provides less pitfalls and ways of shooting yourself in the foot but uh well that's for you to for to decide just you know go and check it out it's um it's actually fairly easy to to part most solidity contracts and a lot of teams have already done so now this is just for the curious but this is basically what I'm interested in so I decided I'm gonna put it here so when you take a look at well if you compile the contract to to azim and then uh well then you basically get a binary blob that tells you nothing but you can
use like a decompiler to to retrieve the let's say assembly form of of huasm uh well like text form of wasm and now if you look closely you will see it's very familiar to lisp if everyone anyone has ever used like racket or scheme or closure then you will be very familiar with how this looks like and uh and yeah and uh the interesting thing about the execution of wasm is that it's actually a stack machine right so a concept so simple that it's actually beautiful uh yeah basically all your program you know execution boils down to like popping things of the stack uh
it's it's really beautiful um okay uh yeah so this is yet another slide that's here but you can basically treat it as a picture and not as as text really so this is uh bird's eye view of how you interact with a contract from your machine right you first need to install some required tooling uh then you you bootstrap the contract by writing cargo contract new then you write your code uh but a lot of that structure is actually set up for you by the cargo contract new call so uh so yeah so you just you know change the change the logic at some fields and so on as as you do and then you simply
first test then you then you build the the like the release package and you're left with some artifacts the first one is the The wasm Blob the the actual code the second artifact is a Json file with the metadata which basically allows the chain to display you know like dog strings about your code and uh yeah and allows other software to find basically what is where in your code in the in the binary blob and also the two bundled together uh if you if you see my lame joke on this slide then good for you I'm not gonna embarrass myself any further um also I think it's worth noting that
there already exists some tooling for for ink that allows you to bootstrap the development much quicker you can check out inkathon by the one of our community members and also open brush that I'm gonna talk about in just a second um yeah so sorry for you know pasting a blob of code on the slide but this goes to show that basically implementing this PSP 22 code which is basically Paul cutout for erc20 like I mentioned before uh it's just you know simple simple as that a few Imports a few macros then all you need to do is implement the PSP 22 trade do I have a laser pointer here
whoa look at that implement the PSP 22 trade and then you know decide what you'll be supplying on contract Creation instantiation in the Constructor and then you know it's pretty self-explanatory because you need to Mint the the new token with some initial Supply and just like that you're done right uh oh also every contract needs to have the the the storage struct by the way it it's only allowed to have exactly one uh well you need to Mark the fields that just open brush stuff but uh yeah that's that's pretty much it that's how you define a fully working you know PSP 22
token with open brush now the cool thing about this is how modular it is so let's say I want to extend the token and be able to to Mint it right um so just like that I'm well there's also some imports that I skipped but you'll be able to find that in the docs really easily but what I'm doing is basically implementing a trade for for the mintable extension and then just you know like delegating to to one of the internal methods and boom you can mint the token now what's even cooler you you can take a look at the modifiers only owner because we want to make sure that some of the functions are you know uh
that only the owner can call them so what you do is you use another Lego block right uh you can implement the ownable trade for for the for your contract and yeah you can you can use those modifiers only owner so basically what it will do automatically is on on when someone calls this message it will check whether the the like account of the of the color is the same as the account of the person that instantiated the contract in the first place right that's uh as simple as that we have some more expressive means of Access Control in our GitHub org you're very welcome to to take a look um yeah so this basically concludes my
my part uh which was you know like like I said very practical I hope so at least um so yeah the shielder is is like it's a pretty expressive as it is uh simple but expressive uh it's actually the complexity is under the hood but to the user it's very simple but you can build a lot of interesting things with it but now if you'd like to see what's uh what the future holds or what what you know you can we'll be building in the future and what we'll be working on uh I would like to invite you to listen to our co-founder Adam yeah thank you I'll do a kick oh okay uh so here is
move uh more theoretical part which is nice word for not practical or not practical yet so um here's more like uh Vision or how we would like shooter to be used now and in the future so we initially at least want to see want to use it as a mean to integrate to integrate with defy so first what is defy or maybe how it usually works so I'd like to claim that D5 basically operates with one single interaction pattern which is where is the user or actually uh contract which sends some tokens and some data to Smart contract which then
sends back some other tokens and sometimes some other data but usually just tokens so the obvious example here is the standardized exchange oh by the way uh I would uh it's like I'm not gonna talk much about ink and code anymore so probably it's less useful for hackathon itself but it's not going to be very long uh so the obvious example is the central exchange so Bob can for example send some usdt and some additional data for example slippage tolerance so like what's the worst price what Bob is willing to accept and when Dax will do some internal computation and we'll send back some usdc tokens or perhaps transaction can also fail if a preferred
price will not be will not be matched so maybe it's not obvious at the first glance but actually I mean the case of Dex is obvious but the other or maybe not or maybe less but the dexes look the same for liquidity providers so what happens with included providers they are providing some liquidity and they are also getting some tokens in return namely so-called LP tokens which represents their rights to reclaim the liquidity they provide the same for landing protocols so you put some collaterals you get some tokens back or put some liquidity get some LP tokens backs same for liquid staking meaning of synthetic assets and well way way more
D5 protocols so what does it mean for us to integrate Shield derivatify is basically to translate this particular interaction pattern into a private interaction so how how would it look like what we would like to user to do is to basically use the shielder as a back-end back-end for a wallet so basically by default keep all of the tokens in the shielder and whenever user wishes to interact with any device primitive he would interact from inside of a shielder so um it's maybe important to point what's
public here and whatnot but Bob keeping some tokens in the shoulder would send these tokens to the smart contract with this additional call data and receive the tokens back which would immediately be reclaimed by him in the shielder so would we put into the anonymity pool instantly when if someone would like to watch this interaction from the outside it's not maybe it was important to to say here it's not entirely private but it's Anonymous meaning that the Christopher here would see how many tokens have came into the smart contracts and how many tokens have have came out of it what would uh what he wouldn't see or is who actually
initiated the action so the only public thing could be that well that was someone in the shoulder so in the perfect world we would like majority of of the users to actually initiate action from the shielder so so that gives very very big anonymity set and what's even more important or even cooler but this particular smart contract doesn't need to be privacy enhancing or in any way so this can be any regular smart smart contracts written in ink it doesn't need to even need to support any specific private API so so this this interaction protocol is is so that it's able to to basically mimic interaction from normal account
so uh it's not like we need to create yet another new private defy we just want to introduce a single crypto primitive which will allow to privately interact with normal device as we as we know it now so that's where that's the general like way we would like sugar to be used and one more project which we're working on and we think it's going to be important is the ID system which will be and become part of a shielder so of course privacy in D5 is pretty controversial because of course most of you probably know what happens with tornado cache and in generally the problem is even not
that it's these Protocols are not compliance to uh for to to deploy or like not compliant by themselves but they are sometimes problematic for the users in the sense that having funds which interact with privacy protocols can be problematic for example because some centralized exchanges can can make some problems when accepting such funds so what's important is to allow users to provide specific proofs at stating that this funds had nothing to do for example with with blacklisted addresses how we are planning to do it is with the ID system that will be hard-coded into the shielder so the
users would have fully private ID which they would could claim and then I'm not going to go into cryptographic details of how that would be implemented this is complex way out of scope of stock but what's important is that based on this private ID that that would No One by but the user would know they would attach very specific cryptographic data to every deposit and every every withdrawal um one important Point here is that this particular interaction pattern that I just discussed a few minutes ago this is not problematic because from the compliance reasons because no tokens are
changing hands here so basically using a shielder you can interact with have a very complex history of interaction with defy you can do it for literally years and still while you're using the same ID it's not going to be problematic because when you exchange funds on the decks the funds you get are coming to the same same address in the shielder so the only problematic actions are actual withdrawals where you are getting out of the shoulder to another account and this thing will also get this private specific identifier which will allow you to for example
you'll be able to prove that no transaction which is connected to your ID have ever anything to do with publicly available list of sanctioned addresses so if you have on-chain Oracle which tells you which addresses got sanctioned when you'll be able to generate it proof like General proofs of Innocence not only for a specific withdrawal but for entire history well entire history of your ID if you if you would like to reveal the history of your ID or part of it into any party also you will be able to do so
and prove the correctness of this particular part of the history also what's uh was possible the children generally um is able to operate with any token type so you can have a token which for example will have withdrawal limits based on based on ID so you can have some ID verification system and then you can design a token in such a way that if the user doesn't have the ID verified or is in at some low verification level then it can be have for example weekly withdrawal limits this seems reasonable for example for stable coins or or assets which for
which the regulatory control is tighter than for normal utility coins um oh this is complex stuff actually so basically this is how we see how we see the future of overshielder and I have two more slides and I would like to skip over this one and just go to this one so uh so this is the late game that we see for for defy on our chain the next primitive that we'd like to implement is multi-party computation and what it basically allows to do is it allows to keep secrets which are recoverable only when a specific
committee colludes and and basically majority of it becomes malicious so we see it as basically the blockchain keeping secrets or maybe the other way you can see it is smart contract keeping secret so right now with all the ZK technology that we have it's pretty achievable already to have user own secret which are attested against the blockchain but it's not really possible for a smart contract to have secrets for example you cannot have a decks with a secret pool State well by default anything that is owned by smart contract needs to be
owned by blog producers because they need to be able to compute and you need to be able to compute the state transition so they need to know everything about the state of smart contracts so what we are planning to do we are planning to allow smart contracts to have parts of each state in the MPC committee so why is it useful one of those cases is the dart pools that that piot mentioned initially so normally when you interact with with unisa for example even if you interact from the shoulder the amounts that are being traded needs to be public that's because the state of the pools in the
universe is public so even if you could somehow cryptographically conceal the transaction itself someone could just watch the change in the pools in the unit swap so he could see that well okay there was like 1010 tokens now it's one thousand so that's obvious that someone just got 10 tokens out of a unit swap so even if the transaction itself will be private well you could infer it from the change of a pools in the unit swap so if the pools would be in uh in keep kept in NPC then that's a dark pool that's the decks where the amounts being traded are not public
your strategy markets that's a bit more complex complex case maybe but what's already being done on on multiple blockchains are protocols that had hard-coded investment strategies so that users can invest funds into these strategies and usually it works like that that deployers of these protocols code strategies themselves so whenever you for example invest in year in finance you invest in practice in the strategies that are deployed by the core core deployers of a platform what would be really nice to do is a protocol where
there can be a specific role of let's say strategist or algorithmic Trader so anyone could submit his own idea for the strategies and then users could choose which strategies they would like to invest in what's problematic in this is that such a such a market could be very prone for copying strategies of other other Traders so like if some strategy could be doing very well you could easily just submit identical strategy as a as a Trader and hope that some users will choose you over the other guy perhaps because you are for example offering lower Commission so the way to to actually solve this problem is
to have it so that the strategies are executed in private so they are not um it's not possible to actually copy copy the strategy itself and and deploy it as a copycat Trader I'm on purpose leaving the not talking about the common decks because it's pretty complex and we just copied the slide for from a way longer presentation so yeah I think that summer is the vision so the first part was what we're doing right now and what we're planning for this year then PC stuff we already started work on NPC although I would say that we're rather not planning deployment of it on the minute this year but that's definitely part of the vision of how we see the private defy to uh to
develop in the future so thanks a lot and hope I hope that some of you will choose our bounties and good luck [Applause]