New Ethereum talks, every Monday. The week's conference uploads by event, in your inbox.

Loading player…

Secret Contracts: Private Data in dApps - Victor Grau Serrat

ETHGlobalFri, Oct 9, 2020, 12:00 AM

Secret Contracts: Private Data in dApps with Victor Grau Serrat from Enigma

Transcript

I have this this light with some of the words the worship materials I'll keep putting this light a few more times and prolly at the end but basically all the information that you wanna hack with us is in this on this link and Ignazio slash Waterloo okay having said this I'm going to start my talk and I guess I want to start by saying that research shows that in talks like this people will get at the most three ideas out of any top so I'm just gonna try to make the job easy and just outline those three ideas key ideas that I want you to get out of this top and out of this talk and I'll keep hammering those it so first is come on in first one is that if you think about privacy in the theory of ecosystem we want you to think about enigma second one is that analogous to the smart contracts in etherium we have secret contracts on enigma and the secret contracts are written in rust I'll talk more about this and number three is that we provide a truffle like environment for developers so if you are familiar with truffle for your cerium development of the apps then we are trying to make it as you like you should feel very familiar very would look very familiar to you in in the environment that we provide so privacy equals the nygma secret raw secret contracts are written in rust and truffle like development environment so let's start talking about about the problem of privacy we all know that data on blog chains are public by default and we believe that these greatly limited potential applications think about health care think about finance think about identity I think about any games that rely on not knowing your position of your opponents etcetera etcetera all these things are things that right now you cannot do on a theorem and we want to change that because we think that if we have to grow ecosystem we have to provide tools that allow for private data and so we solve specifically this issue of computing over sensitive data without compromising on decentralization so we have a network of nodes that have what is called trust and trusted execution environments or T's for short that's a technology that comes almost by default in new Intel machines and basically provides sort of an black box inside your computer where no not even the the person that controls the host or that machine can see what happens inside that black box and then so that's that's the Enigma network where the computation happens and the verification or consensus we for that we rely on on etherium and that's good news because that makes our network 100% compatible with etherium and that's why we come to the etherium hackathons for people to to use this technology so we are several weeks or maybe a month or two away from releasing our public test net which we codename discovery and that's the person that were that publicly enables this notion of secret contracts which is permissionless network it's economically incentivized like or very similar to a proof of stake network and again it's compatible with a serial it it helps to to understand how our network works from the side--oh from the point of view of the different stakeholders and much like aetherium we have developers who deploy taps we have users who interact with those tabs and we have a set of nodes like aetherium but we'll call them workers to distinguish them which are the ones who execute the tasks or compute over that encrypted data and so if we for the next two or three slides I'm gonna look at the flow of information in our network so we start on the left hand side with developers that write secret contracts compile them to bytecode and deploy them on the Enigma and network in that deployment also that they are registered on the etherium blockchain which again it's our source of truth that's that's our consensus layer is on is on ethereal so then users interact with dabs by submitting encrypted data we have we provide the JavaScript library much like theorems web 3 that makes all this process sort of seamless to the user and the user again in encrypt their data sends it to the network there's some register some some keeping track of those tasks on aetherium so that they are in order and if they are they are they will be executed in the order that they were sent to the network and then the task is sent off to the network so then workers receive those tasks based on a stake or weighted lottery the selected worker execute the tasks the selected worker can decrypt that information and only that worker you can decrypt that information and again think about those black boxes where no one can peek inside those boxes not even us not even the people who run the network no one like that sort of the beauty of this technology that we get from from Intel and then the worker executes those types and disseminates the the results across the network and the worker return the results back to the back to the user so that the user can see the results and also to the to the etherium network so that they can be committed on one chain or hashes of of those of those tasks so if you're all this sounds very complicated to me this is the slide that simplifies it so there is something that goes in that goes encrypted the worker does it's magic in the black box and then you can get encrypted outputs and and you and we maintain an encrypted state so this is a state that I guess like the Assyrian state is kept throughout throughout the different computations of the different functions and it remains encrypted at all times in the network and then there's the option of having an ethereal call back where you can you can interact with the theorem with say non sensitive data let's say we have a secret voting that say we we want to decide how to allocate $100,000 and each of us votes and we don't know what each of us voted but we know that at the end there's an ethereal call back that says transfer a hundred thousand to this address and that's what the etherium call back best and it has it separated from say the secret voting flow that is inside the the worker and we will never be able to know who voted for what again this is the materials here you will have all you need to to hack with us so last thing about what can you build with enigma think about games that require you to hide actions like rock paper scissors or battleships quiz are were competitions like jeopardy or hangman scavenger hunt with secret locations secret messaging and here I want to highlight where's Ainsley and John they are in the back they are two of our people in our team who basically spend their job is to think about applications right so what I like to say is that anything that you can come up with they probably have started before and they are well or in some form or another or they can relate to something that you might be thinking so use them use them as resources and say well I'm thinking about this is this feasible is this not and they they will relate to any idea that you might have and brainstorm with you so we know that in a hat in a hackathon there's limited time you use those resources that you have at your disposal to get the most out of your time here okay so I'm moving to I not yet we provide dr. Network because we don't have as I said as I said at the beginning of the presentation we'll go public in about a month or month and a half so we don't yet have a public person at or maynot so we provide a docker environment where you can launch a self-contained instance of the network and interact with it you just launch it and see all the we can all the nodes in the network interacting with one another but what I want to get to today is develop a secret contract so number two secret contracts are written in rust and if I were a participant in a hackathon I said geez yet another language I have to learn sorry like I'm sorry but obviously we don't choose the language you know that will run our infrastructure on how is it is to hack I hope you appreciate that decision but rather because it's memory safe it's highly performant well and it has the plus that has a wonderful community but basically it's like actually I want to I want to ask a question who has the experience coding in rust yeah so that's I mean that's what we are expecting um because well rest is not that pervasive in the theorem ecosystem yet but we're gonna provide you with I'm actually the rest of my talk is mostly demystifying rust and making it easy for you to get started on on on rest so I like learning by doing so will I'm gonna just walk you through what would writing a secret contract for the millionaires problem look like and if you are familiar with y'all some villanous problem this is about two people Alice and Bob who are millionaires and we're they are always obsessed to know who's richer but they do not want to disclose their wealth to one another and so they are obsessed with privacy as as we are so what happens here is that they we create this millionaires problem secret contract where both Alice and Bob submit in encrypted form their wealth and the the contract basically returns who either Alice or Bob as the richest without disclosing the individual nouns so my tip for okay you have you come here you have some ideas for a really cool dab you realize that you need privacy you choose to code with enigma and then you are confronted with a challenge of coding your secret contract in rust this is the first place where I would start this is our when our main repo has one to nine secret contracts already written that you basically can cut and paste it's like okay I need to store a variable in the state there's a function here I need to write from the state okay this this contract does this I need to make an ethereal call work okay this one does and you just look through the code and look for the bits and pieces and essentially copy/paste all those all those contracts are thoroughly documented and inline and so on so it should be easier so that's what one secret contract looks like but I'm gonna break it down almost line by line and the the milliner's problem secret contract is about 80 lines long including Commons you can see that in this first twenty three more than half are common so you're looking at 40 lines long I claimed that over those 40 almost 15 or 20 are always the same so you just copy-paste so you didn't you have to write like 20 lines of code I think you can do it so again this first 25 lines is everything's done everything it it always is the same the first one is that because we're going to run our code inside the enclaves the enclaves cannot support all of the standard functionality of Russ so we take it out we bring two crates into scope which provide the runtime which allow for reading from the state writing from the state and printing for debugging purposes we bring these other crate that allows us to call etherium functions at the very end of the execution and then these other crate that allows for serialization and deserialization of data in and out of the contract crates are the equivalent of packages or libraries in JavaScript or other languages so all this is just like copy paste and then we in order to write and read from the state we basically have a hash map the hash map is indexed by this string so I'm just gonna write whatever identifier I want to use to to access the state this is how we declared data that we will write and read from the state and it's like a struct where you basically define with key value pairs and here you go into what types are supported these are rest types but in the appendix there's also the equivalence between rest types and solidity types and then here we declare the functions that will be publicly available from our secret contract and the ones that the users will be able to call there's a constructor but because it it's empty we can go with the default and this is essentially the this is where the code actually starts where I want to get a millionaire from the state so I read from the state with the string that I defined before and I know I'll get some vector otherwise if the state is empty just give me an empty vector and then I want to add a millionaire that's when Alice and Bob send their wealth to the contract they'll send their address first parameter and the an integral for their net worth and so I'll read from the state to get if there are others I'll push the the data that it's been passed on to the contract and I write all that to the state if you think at a high level this is fairly simple I read from the state I get whatever the state is I add my data and I push that into the state and all that and then every the network handles the there keeps the privacy and the encryption there so you know four or five lines here and then at the end I want to compute richest so this is a rust as it's at its best where you get a lot of stuff done in in a line basically where I want to read from the state get the millionaire's iterate over the array that I will get and then find the maximum by key where I'm using the net worth as the key and I will get something in return or nothing and I just the known is so that we can handle if again the error if nothing is returned so that's that so then I've written this secret contract in rust I I use the environment that we provide much like truffle compile I use discovery compile and then disc release properties generates the compiled bytecode which in the Enigma network happens to be webassembly and that the wasum files and so then you like truffle you do this discovery migrate and this will deploy this contract onto the Enigma network and have it ready for the users to start interacting with skip this and then basically mention that we have a client-side library for interacting with secret contracts which is responsible for encrypting the user inputs submitting the test to enigma and getting the computation resolves or status from enigma and it looks like something like compute task where the first parameter is the function that I want to compute say add millionaire the arguments are the arguments that to that function say the address and the net worth and then the gas limit and gas price like aetherium the sender that would be the user and the address of the secret contract where I'm sending this computation tasks and then I can get the test results and check this the status of the test when it's you know it's pending computation and then eventually it's done and then I can interact with it I'm gonna skip this in the interest of time go here and I know I'm gonna finish early oh I want to say two other things so we have again I'm gonna insist on use the resources that we bring to the hackathon there are six of us in addition to John and Ainsley that I introduced before from the business development there's Fred and I hi Fred the we've are both developers we have developed this protocol alongside with a larger team and we are happy we are here only to answer or mostly to answer your questions to support in your installation to help you write those secret contracts like we're just standing by for you to come and talk to us and help you up and if you decide well this is all complicated it's all over my head I'm not gonna make it but I think that privacy is needed enigma school I want to make sure you talk to Aaron and tour there who are leading our community marketing communication efforts they build or they manage a wonderful community of enigma ambassadors or whether you want to start blockchain club at the University Aaron is your guy utilizes like we are here just so that you talk to us in person because we know how much how how much of a difference talking to people rather than being on a forum or slag or whatnot make so with that I have a couple minutes left to spare if you want to do Q&A ask questions or we can just empty the room and let the next ones come in yes question yep no no this this is a parameter that that you pass so you would pass in this case you would pass dear and aetherium address as the message sender type of thing I guess let's take let's take this conversation offline but I like you are thinking already we're getting in deep into the stuff yes yes yep yeah I didn't show it because if you don't specify it it goes it uses a default constructor but if then you can override it and say I need to make this constructor and pass these variables into the constructor then then you you specified I guess we are trying to make it simpler and simpler in that if you don't need it you don't have to worry about it if you will need it then you it's available to you yes so all the computations are paid for in Eng the enigma token and but do you only need and then the etherium callbacks are paid in aetherium but there's an automatic conversion that happens you send more Eng and the energy is converted at the rate the running rate to pay for that atrium callback so again we try to make it as seamless and as possible so you pay you make one transaction where you pay it class in Eng and then that the network takes care of it how do I do a computation of an encrypted data so at the beginning of the talk I said that the network relies on this trusted execution environments so the answer is that I decrypt the data I do the competition and encrypt again because I there's a key exchange that happens through using diffie-hellman where I I know what it what is the worker or the node that will do my computations and I communicate direct I send my public key to that node the node generates the counterpart and then I have that one one-to-one with with that worker eventually we want to run we we want to use what's called multi-party computation but we are not there yet and we thought that this was a faster way to get to prove that I don't think that no one is is implementing MPC for real like in a viable way the wheel though we believe that it will be possible in the future that the person that the CEO that founded the company his research was on MPC at the Masters level so that's why I triggered the whole thing and the original paper was an Ingmar running on MPC but for viability purposes in the short to medium term we had to implement with this residency in America great questions I think my time is up thank you very much for your time we'll be outside

Automatic transcript — names and jargon may be misspelled.