Building Confidential Smart Contracts by Nikhil Sharma of Oasis Labs
ETHGlobal·Fri, Oct 9, 2020, 12:00 AM
Oasis Labs Engineer Nikhil Sharma gives a talk at ETHBoston, an ethereum focused hackathon that took place Sep. 6-8 at Northwest Building, Harvard Campus. The talk explains how to build confidential smart contracts on Oasis Labs' platform. ETHBoston was a hackathon organized by ETHGlobal and a team of hackers, developers and enthusiasts interested in building and creating in the ethereum ecosystem. The ethereum focused hackathon took place for 3 days at Northwest Building, Harvard Campus in Cambridge, MA. For more information visit eth.boston and ethglobal.co
Transcript
all right so we're gonna get started so we are already slots and this workshop is to teach you about building confidential in France so just out of curiosity by show of hands how many of you have heard of us so we're gonna do two things first reenact what why you should build it on our platform and then we actually show you how to do so as I'm sure all you know there are quite a few data breaches that have been happening in the past couple of decades and most recently probably the Equifax memory and so all of these data breaches put personal information at risk and that leads to a lot of mistrust of major corporations for example study the public post ran about why uses a quick Facebook decided to do so the leading reason was that there is no longer customers so what is the way supplants do it allows you to build applications that are decentralized and preserve a lot of or provide a lot of integrity guarantees but also give strong privacy and security guarantees that work without how to compressed any centralized third party so how does this all work what's going to an overview so there are a lot of trust issues with both cloud infrastructure and applications that run on them and discuss that leads to undesirable do and the Oasis platform uses smart contracts that are scalable due to our new approaches a level of consensus and all contracts code is one within trusted and execute environments which gives confidential confidentiality guarantees and together these two things table us to do things like analytics and machine learning so smart contracts by themselves they enable replicated compute which and like give gives integrity guarantees upon his own and has the ability ledger but these two things by themselves don't provide any kind of privacy guarantees for that you need secure on clips for us to execute environments so what these are are been essentially black boxes in memory on notes within the oasis network and so even if you don't trust the notes the network the nodes actually don't see anything that any of your personal data the smart contract code and encrypted sensitive leaders these are black box computation is that only so how does all of this tie together a lot of developed so we have a new SDK that mean - at least that includes a CLI that makes building things easy a gateway and some new rest libraries that make what changed specific things this also comes with new laws and run time which is useful for compiling and running your programs within secure enclaves and we also have a developer dashboard that serves as a portal where you can deploy your smart contracts and monitor their activity so this is a diagram of how everything ties together so we have our CLI which lets you initialize projects build them and also then you can deploy them on our dashboard where you can track them and once these services are these contracts are deployed you can interact them with them via the Oasis client which is a JavaScript library that lets you sections and these transactions go through either our new asus gateway or an existing web 3 gateway and the code to our network where they are submitted to know it's that run with these transactions within or running all compute within a secure update using that wasn't time okay so let's go ahead and get into some specifics of how to do that so I'm going to show you how to build and test a secret ballot which is a voting application that has no centralized party managing the votes so then we're going to run a local Oasis blockchain - which will deploy the service and we're going to execute a few transactions - yeah this preppin previous life those are voices notes are both bad you guys currently yes eventually anyway so yeah let's get right into how to actually do this so this is an example of a rust smart contract so when you users feel like to initialize an application you'll you can just use run command oasis in it when you have we'll make this directory structure we have both an application layer and a service layer so this service layer is really just a rust package and your actual smart contract code will go within this main dot RS file so this is what that looks like and within that main RS you want to do two things you want to define the state that you want your spark contract to manage and you also wanted to define our pcs to actually manipulate or or read that state so to define your state that you can do just with a standard Brussel struct so for a secret voting application you want to manage this the description of what the vote is for a list of tens before how many votes each minute has whether or not voting is open who is the administrator of the boat and can do things like close and I'm not who has voted for what and again all of this information is to be stored improve it and be private - at all times unless it's being and then you'll notice this annotation here that essentially is a trait that tells our platform or that enables this contractor to have that state read from and updated in our platform storage so actually updating that state that's done within at this imple ballot where you have a constructor where you can visualize a ballot with the description in the list of candidates you have some getters we can get the list of candidates the description and whether or not putting is still open and one thing you might notice that's there for all of these are PCs are is this context tag Sabri those of you that are familiar with the solidity this is actually the same as message so message sender here and all the things that message typically has its Lippi contracts power then you can go ahead and do other functionality like voting if voting is closed its not accept many votes you try to vote for somebody that's not candidates but you so on try to close a ballot but it will return error unless you are the one that created the ballot and once voting is closed if you you can read both the winner and also a list yeah and so we also another difference between without writing standard Russ packages and our smart contracts are is this one macro that the service macro so all this does is when from our CLI we try to build this application it'll tell you to if that handles how this rust code is compiled into a wasn't binary that can then be read in our names if you're on all right so let's go ahead and try building that so I'm in that same service directory and I can just go ahead and waste it's build that'll take a minute and so while that's happening when I talk about testing so you can write unit tests for these contracts before you have to redeploy or do anything with them just as you can do normally in rust you have this functionality to create an account using Nueces test library and so we can go ahead and be a couple accounts one that's gonna be for our admin and 150 for a generic owner then initialize the ballot object that has this admin set as the admin then you can check the description and candidate so it's going to be check that building is indeed open and check that you cannot actually be in the luminary quite yet you both so the generic voter first voted for I 0 and then change their vote - I have one yogurt and then the decided to also vote for yogurt is there in Iran yeah then a couple more checks to make sure that the admin 10 closed voting but generic reporters camped the track to see that nobody can check or nobody can build out for voting is closed and a few checks to ensure that the winner and results are expected so you have to now that mark ballot is prepared we can run these test cases super simply with just awakes its test so I'll take a couple seconds any questions but is it this all the transactions [Music] yeah they're all like when you deploy deploy it confidentially by default you can set up like to make it all this transaction just reading so you see you can so that's yeah so that's still a thing that we're working out solving anybody can still read the list of transactions such as like who executed what methods on which contract but you can't see the actual state as all that static opinions and oh dear lady feels okay so as you can see these test cases past you try to mess with it and try to see if closed yeah okay so so you have to now you have clearly broken the test and then let's move on to the actual application so to run the application and to actually do that we need to run a local block chain for transactions to be made to I had thought you can use super simply with our command line also its chain see you get a bunch of different accounts and now you have this local chain or Nick that's listening or transactions so how does it the application actually work so we have this secret ballot front-end app that is using pj s and pretty much all of it you can ignore as like front-end specific stuff the only important stuff for actually interacting with our client happens in this storage is file which in the view is the mechanism for a local state management so what state do we wanna grab so it's how what which Pokemon is that starter and a list of twizz's objects that is currently in all but when we deploy it with our client you have this white code that was generated so when I ran away this build that luck to you place to this target directory are getting serviced that it was a binary and so this is a link to that and this gateway refers to that locally running about gene that you have so when you try to connect to it wix's you this is an example using the web to be gateway you can also do it with our Oasis developer gateway but essentially you initialize a wallet objects from then if you want a display service you have to read it that was a bytecode and call this Oasis deploy function for our client and along with the bytecode you also pass it instructor arguments and if you want you can pack some things like the castle bed and with whether you might be confidential or not that's what does it and to actually interact with your deployed service from our plan as super as influence you have that valid object created after deploy you just call the methods directly and so yeah and so yeah so now that actually should have be running on and you can see the the boat running so what's happening now is that it's deploying a service now that that service is deployed this like deal comes up with employer parameters which is just that's a Bigfoot this ID is really just the address at which or smart contract is deployed to identify it you can participate in boat which gets that like uses the Gators for getting the description of the candidates and enables you to vote for 51 Charmander is my personal favorite for him since I am the admin of the boat and I deployed it I have this option to vote and now that I closed it I can view results which should show up but you can see that Charmander has one and if you go back to that place or any local of team all these clicks executed transactions about that locally right chain the plant and you can like parts of not everyone it's any other transactions in work you can see errors in scope and so yeah so that's that demo application no it's just if listen you want each time you like if you wanted to you I guess that you like that so if you since what ideas if you did it would just so yeah so going back to this we have a bunch of resources to get started so this is a real that I talk you through start guide we also have a and we have our developer top story yeah so anybody hopefully this device and on behalf [Music] yeah so everybody can see the tallies in the books yeah it's like super simple to change it up to like that was just so I could show the cool graph if you wanted to you could just not have this result function and then you could only have this [Music] totally appear right now it's in figuring so that leave any and all students in one yeah well thank you and we'll be around to help guide anybody else you
Automatic transcript — names and jargon may be misspelled.