Introduction to Aztec
ETHGlobal·Wed, Oct 9, 2019, 12:00 AM
The team from Aztec explains Aztec at a workshop at ETHNewYork. ETHNewYork was a hackathon organized by ETHGlobal and a team of hackers, developers and enthusiasts interested in building and creating in the ethereum ecosystem. ETHNewYork ethereum focused hackathon took place May 8-10, 2019 at New Lab at the Brooklyn Navy Yard. For more information visit https://ethnewyork.com/ and https://ethglobal.co/
Transcript
cool right welcome guys this is the aztec developer workshop so today we're basically going to do a couple of things we're going to take you through an overview of what aztec is and how it works and then secondly we're going to do like a demonstration of some code to talk through how you can use us they can integrate with it but first of all join our discord channel so just wait your smartphone scan the barcode and just take you straight through to our disco channel we can ask any questions you want and you'll ping me and Joe straight away and we'll be on there to help out so I think first of all if we just introduced the Aztec bounties everyone's interested in so we've got one thousand dollars for the best use of a stick in any depth so that's any sort of implementation of that of a stick which is pretty interesting into some interesting stuff and then secondly we have five hundred dollars for the best use case of a stick in the private identity solution so I've got any questions about that feel free to ping us later on and then today you've got me and Joe both form a stick I'm gonna talk you through an overview what it does what the ecosystem looks like and then Joe is going to take you through some example flows so if we start off why is privacy important so traditional financial services offer privacy by default when you have a bank account you have privacy built in by default if you're going to rebuild these services and markets on chain then this is a pre record prerequisite it has to be built into whatever product you use this essential across the industry and it will also allow users to control third-party access to their financial and personal data so privacy is essential I'm really important if you are ever going to take some of these markets already exist in the traditional world and rebuild them on chain so what does I say come into this well as Tech is a toolbox of plug-and-play cryptography it has a few different quite interesting properties so it's interoperable between different apps we have a single just to set up and a single common reference drink it's extremely gas efficient so gas everybody knows you have to pay for computation work on ethereum and this is expressed in gas and so you want your gas costs to be as low as possible and aztec is currently about eight hundred thousand to about 900 thousand gas forest under transfer but with AI p110 rate which is on its way that will hopefully reduce some of these elliptic curve operations down so that a single transaction cost between about 200 thousand three hundred thousand gas so gas efficiency is important and a stick has fast proof construction which makes it possible to use in a browser for example on a mobile phone and the Alfre is ready today if you look on a github page on some of our blogs you'll see that the alpha is out there and we're going to go through what some of this looks like so if we move on then to what the aztec ecosystem is so this three core components and we'll start first with the central box in the middle the aztec cryptography engine otherwise known as the ACE so this is an ER C at the moment and basically this is like the central nervous system of the whole Aztec ecosystem at coordinates things the ACE has a set of validator contracts that you can see on the right hand side joined split bilateral swap mint there's about seven at the moment and basically what the ACE does is it takes proofs now I've been served to it I've been constructed by these ZK asses and it will verify them using these validator contracts it will check whether the zero knowledge proof is a valid zero knowledge proof and whether whatever type of financial transaction that you're trying to perform is legitimate the Aztec cryptography engine checks the mathematical legitimacy of these transactions so total imports equal total outputs and then the Z key assets which you can think of almost as like a confidential equivalent kind of to an e rc 20 they have that same sort of standard interface they deal with permissioning and all the sort of flows and this is how it all kind of links together with a user DAP the cryptography engine the validator contracts and the zhurqis acid so that's a bit abstract that's a high-level view of what the Aztec ecosystem looks like and if we just move on to the proofs so currently we've got a few proofs I think this seven in total we're representing a few here so the basic one is send so this is how you this is how personally pays person be you send what we call us tech notes otherwise this transactions also called a joint split you can also swap confidential digital assets using a stick a bilateral swap you can pay interest use an Aztek there is a zero knowledge proof called a dividend proof which lets you calculate one note as a ratio of another and so you can pay interest you can mint directly Aztec notes which is useful for stable coin applications and similarly you can burn us tech notes and destroy these representations of value and Aztec note is an encrypted representation of value in our ecosystem and lastly there are proofs called private range and public range proof which allow you to check that these encrypted representations of value are greater than or less than another value so that's a Lightspeed overview of our ecosystem of our different proofs that we've got and now to bring this all to life Joe is going to demo some of the things that you can build with that stack and some of the things that you guys might be working on today so with that it's over to Joe give me two seconds just to get this so everyone can see it cool so what we've got here is one of our starter kits implements a confidential loan and we'll need you yeah so yeah what we've got here is it's one of our starter kits if you look on the discord channel there's a link to the github repo under the hood here we're actually integrated with the graph protocol to make this a real-time UI we don't use meta maths because of some of the signing flows they require access to public keys and private keys which you can't currently do with meta masks so we use a hot wallet so first of all let me just go to the docs and grab my very secure mnemonic here so just so this under the hood it's it's got a set of mappings to kind of just make the UI real time it's a react app of craft QL to kind of just make this usable so in this app we're gonna create notes Aztec notes which are confidential and then we're gonna settle alone confidentially with an e rc 20 token and then we're going to stream interest out of that loan in real time and all of that's kind of facilitated by the graphs it's actually just our own private one and we'll be launching our own ya local ganache yeah yes so it's just right here we'll be launching a public Aztec sub graph in about 3 or 4 weeks and it's not ready for this one so so I'm just gonna add the wallet it's a lovely secure password of tests and we'll restore the wallet yeah so we're gonna treat the left-hand side as the borrower and the right-hand side is the lender so the first step is to go in and create a loan so and what we're trying to do here is create a loan where the notional is obscured from public view so when this is broadcast to the smart contract in the contracts in the inputs you can't deduce kind of for the actual notional value is we're going to use a local representation of die as the UFC 20 to settle the loan in that attempts an interest rate and would have a very short loan because we don't have much time so when I create this loan we're actually using the mint proof to under the hood create an Aztec note registry mint notes inside that or mint one note worth 150,000 which represents the loans notional if we go to the left hand side at the right hand side sorry we can see the lenders view and there's a loan it's been created there's the public terms of the loan here but the notional is obscured in private so the next step is if a lender wants to come along and is potentially interested in fulfilling this loan they have to kind of request access to to the loans notional and what this is doing under the hood is every Aztec note has a viewing key which allows user to decrypt it and we're going to share that viewing key with the lender through the graph so if we go here we can see we've now got a new viewing request which comes from this aetherium dress so we're now going to use some is encryption just to share the viewing key across the graph and as we do that the loan will move from pending loans to approve loans and we'll now be able to see the notional balance so the next step if if the lender is still happy to proceed is to settle the loan so what we're going to do here is perform a bilateral swap we're going to swap one hundred and fifty thousand died for the loan note which is worth one hundred fifty thousand and what ace and as to yesterday cryptography engine is going to do is validate the 150,000 150,000 equal and if they are it will perform the swap and the the assets will change hands so in order to do that we have a min table dye contract that lets us mint one hundred fifty thousand died which would be nice in real life but so the first step here is just to give us a hundred fifty thousand die and then we're going to perform the swap it's worth noting here that the 150,000 I don't instantly get sent to the borrower they're actually owned by in note form that owned by the smart contract which allows some pretty complex flows such as interest streaming which will we'll see in a second so when I press this under the hood we're constructing a bilateral swap proof which is going to settle the loan we're going to send that up down to the local ganache instance and the loans now settled and we can see that interest is now occurring on the loan in real time and under the hood here using using Aztek we can withdraw interest to the nearest block time and we can have the blockchain validate that the correct amount of interest has been withdraw we've drawn in a non interactive way so on the left hand side the borrower can withdraw the balance if they want to say - any accrued interest so say they've got a working capital requirement they need to withdraw 50,000 I know they'll withdraw that and we'll see in the top right hand corner using the graph as that note is created we're able to decrypt that and add it to the users account balance and on the left-hand side we're actually gonna use as Tom was explaining earlier the dividend proof to compute the currently accrued interest as a function of the elapsed duration of the loan and we're going to have the smart contract validate that the proof the lender sends is correct and if it is correct because it owns the underlying balance note it can perform a joint split to split the currently accrued interest and the balance into two notes one owned but it's not contractor one owned by the lender so here if I trying withdraw a portion of that we'll see that there's some quirks of integer arithmetic and solidity so we have to find an amount that corresponds to an actual second so once we've done that we'll then be able to withdraw 11,000 388 died which we'll see in our account here some other interesting use cases of this if the lender decides sorry the borrowers are responsible and they decide they want to withdraw the entire balance of the loan the loan will start this one is actually already so let me just create one more line this one's actually already matured so it actually I was going to show you the default functionality we have a proof that uses our private range proof which allows a smart contract to validate that the collateral stored in the collateral account is currently less than the accrued interest which allows kind of programmatic default to occur so in this case if if this loan was back 20 security such as on chain real estate such as a house you could transfer the title of that security on result of a default to a new owner or if it was a kind of crypto backed loan you could transfer any collateral to a new owner but unfortunately this loans matured so let me just create anyone very very quickly actually we can we can show you this tomorrow actually because we haven't got that much time and we want to get people coding so all of this is possible kind of with aztec this is available as a starter kit on github it's using the graph and it's got a load of kind of helper functions just to make integrating as take on the front end easier so feel free to grab me tomorrow if you want to talk through any of how we set up this interface and how we set up the graph for now though we're going to switch back to the presentation and we're going to run through a small a small instead of what you can build for a stack so aztec was originally made in our in our previous life were a company called credit mint and we were trying to put a large-scale syndicated loans on the blockchain but aetherium kept promising the privacy was coming and a year and a half later it never materialized so we ended up building it and pivoting to a kind of privacy protocol so it's obviously very useful for large-scale financial markets some of the other use cases which we're excited about people building in the hackathon are services like a private demo so being able to send money confidentially confidentiality confidentially using aetherium and also private identity solutions so using the range proof which is the latest addition to our tool kits you can prove very interesting things about your identity so you can prove that your se above 21 and you live in a u.s. state that supports gambling without revealing which state or how old you are or you could prove that you have a salary above $70,000 to get a mortgage but not say how high above it is to make sure that your rents not increased too much or you could do interesting things with your credit score proving your credit scores in a certain range without revealing what it is which is very interesting for some defy applications so we're very excited to see what you will build I think the main takeaway now is just to get everyone coding and before we do that I'll just do quick one or two questions if there's anything I've missed but then we'll get everyone coding and we'll clone down a quick repo to kind of get as tech deployed to a local blockchain and run through basically how it works so just just for now we used to hop what just for ease of signing flows there's a there's an EIP can't think it's one of the meta masky I please basically which allows delegated signing flows which one since integrated we'll be able to use meta mask but for kind of large scale loans would probably suggest that they integrate with the custody provider that provides access to the private key to allow the signing probably on a server say that the hot wallets just a an example right now it's kind of get up and running about from the settlement like GRC 20 the die so for ED for public token there's one kind of place where the confidentiality falls down when you transfer tokens into the Aztec ecosystem that's obviously public but once the tokens are in note form its confidential so for a real use case would recommend kind of not using any RC 20 and have a Fiat provider or stable coin provider that mints directly antastic so I'm receiver bank transfer they'll mint a note worth $100,000 or something to be able to settle the loan in that case it's completely it's impossible to tell that notes worth only you and the bank kind of all right so let's get coding so if you head to our discord channel I'm gonna end this PowerPoint all I'm a second so just quickly but actually before I end this we're gonna run for an example of how to build private vem oh using aztec and under lines of code so the flow we're going to kind of go through is Bob is gonna deposit $100 in this case we're assuming that there's a bank account API that will tell us on receipt 100 dollars and we can issue a note worth $100 to Bob he's then gonna take a taxi to Eve New York it was raining today if you didn't realize then he's gonna pay Sally $25 for the taxi but he wishes to pay confidentiality so in order to do that we're gonna do a joint split which splits the notes his original hundred dollar note into 75 dollars and $25 he'll retain the 75 dollar note the hundred dollar note will be destroyed and the $25 note will be owned by Sally and yeah obviously in this the values of the mint and cent transactions confidential confidential it's worth noting that Aztec follows UTX own model similar to Bitcoin so you have to keep track of a lot of notes which is where the graph comes in and it's quite useful because it allows you to every time I know it's created or destroyed we use it to kind of tally up those notes and as associated them with a particular user so if I head over to get up it's also 6:00 a.m. for us so if this doesn't make sense please explain ask me to stop and I'll go over this again so if everyone can go to github zoom in on this we have a Aztec ganache ganache starter kit and we are going to just run through kind of I'm going to do it with your just kind of cloning this and following the readme and I'll hopefully the code and hopefully by the end of this we'll have everyone set up with a development environment where you can start writing smart contracts and integrate with a local version of Aztec and I'll talk through some of the proof construction and we'll talk through all of those flows in private demo example so as everyone go up to this point of cloning the repo let me just quit this this is really small so first step let's clone the repo now we're just going to CD into that directory and this using this means we need to have node installed and yarn so assuming that's the case we can just run yawn install when install kind of all of the packages we need I'm just gonna try a zoom in on the display because it's not gonna be visible on the live stream okay so the next step included in this we've got a dot M file which has just some deterministic aetherium accounts which we've given a thousand efore to just to make it easier to develop and the the startup command will start a ganache instance with those accounts it just makes local development a bit easier so the next step is just to rename the m fault or something that ganache can talk to if you just type this come up and paste this command the files called rename me--don't m and this command will just mean it it would if you just paste this command it will rename it if you just paste that whole command it will do it for you it will take this file and it will rename it to this file so then you'll be good to go and then the next step we're just gonna run yarn start which will start off our ganache instance and I'm now just gonna open up another tab and just quickly before I do this I'm going to compare the contracts you have to add the compile flag just because there's a few it's quite a few at Aztec contracts that we need to compile here you can see we've compiled all the validators and the reference implementations of our PRC 1724 which is a standard for confidential assets we've compiled all of those books we'll be using them and the in the private demo example so after we've done that script now actually August and we'll run through what's happening under the hood so I think the first thing to to talk through is the migrations that are required to deploy a switch is that central central kind of coordinator the system requires to a local blockchain we have deployed versions already on Rigby and our main net release will go live in q3 but for local development it's much easier to obviously just have one on kamesh so you can test this out without having to deploy every time so first of all we're going to require all of the artifacts we just compiled with truffle aces obviously the cryptography engine and then as tom was saying we have toolkit validators each of these corresponds to a different zero knowledge proof they just supply is for minting and burning the bilateral swap is our swapping proof which can be used for trades dividend computation is the interest one private range allows you to prove that one Aztec note is greater than another a stick note and then join split is obviously descending so you can split a note into multiple we also have a devtools package which allows us to kind of require some constants which we used inside ace so the first thing we do is we deploy ace and all of the validators we need so once we've done that we need to set our common reference string so Aztec uses a very efficient range proof to enable it to be around 800,000 gasps and this common reference string basically tells Aztec which which set of trust has set up database points to use we've run an internal trusted set up right now and this just points to our own kind of test trusted setup which goes up to a million points the production version will go up to two to the 32 so two to the thirty I think which is just over one hundred million so this is just I don't tell us Aztec which set of points each of the notes will use and is used for the underlying cryptography we then have to tell the cryptography engine which validated contracts it should use for each of the proofs these are upgradeable over time so if we add new proofs we can overwrite these validators or we can add new ones as kind of the the range of functionality grows so once we've done that when we weren't truffle migrates we'll have a working implementation of ACE one chain and we can start writing our own contracts so I head over to an example say k asset think it would be important just to bring up one of these contracts quickly actually just to talk through what the circuit actually does so the Zeki asset contract is our let me do the interface the Zeki asset contract is is meant to be very similar to any RC 20 even though it follows aut EXO model we implement a confidential approved function which allows the owners of notes to approve smart contracts or other users to spend notes confidential transfer which is the default transfer functionality under the hood this takes a joint split proof and will actually process the transfer and then the confidential transfer from is used for some of the more involved signing flows in order to call this you have to have first approved every note for spending inside ace so if we go back to our migrations for a basic zero knowledge asset we're just going to look at the bottom one here we're initializing a new sewer knowledge assets that's min table this means that this total supply of the asset can be adjusted so we can it will start at zero and on receipt of any bank transfer we can issue new notes increasing the supply to that value so to initialize the asset we have to set the ace address that it should listen to to validate all the proofs usually the second parameter of the constructor function for a new zhurqis asset is the link token in this case we don't have a link token because it's a fully private asset but if you wanted to link this to die like in the loan example you would pass in a link token there's an a scaling factor which is if there is a link token and you want to express larger numbers than the range of the trust is set up you can multiply by an integer here to help achieve different different token values if you if you need more granularity and then the last two points are velocity parameters sorry R if the supply can be adjusted so in this case it's min table so the supply can be adjusted and the last point is can you convert back to an EOC 20 token so you're noticing this one it's it's false but in our standards okay asset that's linked to a test CRC 20 the last parameter is true meaning it's convertible back to OC 20 form and it's not adjustable because every single Aztec now has to be one-to-one backed with ERC 20 that's owned by Ace so after we've done that in the migrations that's all you need to put a very basic zeki asset one chain and we can then use that ok Asset mint notes and use the Aztec toolkit proves to interact with interacting in various confidential fashions so if I switch over to actually implementing private venmo all of this code would actually run on the client side but for ease of use we just have a set of tests that implement this so just before I going I'm just going to show you what these do so the first thing we do is we just create two accounts this is similar to our hot wallet setup on the client but this is running in a test so we just create an account for Bob and an account this Ally the set K 2 5 6 K 1 package is just a helper package we've published to NPM that just makes it easier to interact the theory and wallets in a node environment and then we then have to get instances of both the ZK asset min table which we're going to call our private memo contract and the joint split contract which is going to value validate the actual transfers so if we look at our tests the first thing we want to do is we want to deposit and note worth $100 has everyone got to the stage in their demo so far just ok so the first thing we're going to do is we're going to use aztec jeaious to create a note the Bob owns we do this by using polls public key and we create a note worth a hundred this would usually happen on the client so only Bob would know this value when we mint a note we need when we use the mint proof we use the proof part of the SDGs library and we use the encode mint transaction we pass in a new total an old total and the note that Bob's going to be basically granted out of this once this transaction is sent to these air KIC contract it will automatically mint this note and Bob will have a note in the note e worth 100 so that's the minting step done for you and it's as simple as just using one of these off-the-shelf tool kits so when we call confidential mint here we're actually going to validate that proof and in one go mint the proof so the next step is to do a joint split transaction which is the basic send functionality of Aztec so we're going to make a note for Sally worth twenty five and a new note for Bob worth seventy five and in the joint split transaction the only requirement the ACE is validating is that the sum of the inputs equal the sum of the outputs if that's correct allow the transfer to proceed so here we're gonna use Bob's first note which we can see was worth 100 as an input note and we're gonna split that into Sally's taxi note weft 25 and Bob's new remained a note worth 75 there's some signing that goes on under the hood that the input notes have to be signed by Bob but once we've constructed this proof using Aztec Jess we can then send this to the decade asset contract using confidential transfer and the transfer will happen so if we run test you should see and that's how you kind of do private confidential transactions with Aztek me and Tom are going to be around all weekend to help you in the discord Channel we've got a series of articles which kind of walk you through getting set up with Aztec and hopefully everyone gets to build some really cool stuff and we can't wait to see what one builds any questions if we've got time [Applause] it just makes if we go back to the loan example building I know many people have built you eyes on etherion but it's not very fun having to kind of query contracts and in react is a very good library called Apollo which allows you to have a graph QL server and the graph just puts a so you can write mappings for all your smart contract events and you can just query normalized at a much more readable format yeah it's just like a nicer interface for connecting tono's it's currently centralized but they're applying a decentralized solution for it it's just easier for ya so we just use that in this to make building interfaces easier and it's useful for keeping track of notes so if you have a note registry that's outputting create events and destroy create note events and destroy note events you can listen to that and you can assign them for a particularly user it's much easier for kind of figuring out the total battle of a particular users notes so in the future we'll be launching a aztecs off graph which will be kind of maintained by us to make that easier but it's a used a few upgrades to the protocol before we can do it properly and the reason doesn't work with meta maths right now is you just need for some of the flows you need more access to the private key to sign so to approve a note for spending you need to sign the note in a particular type data format with your private key and that flows not currently possible with it will be soon to use masking so all of the all of the sense of the blockchain are through battery and like the graph is kind of pulling both dates back down so it's kind of a cycle so you don't need to use the bath it's just we just found it out of perfect personal preference for building an actual UI you can prototype very fast because it's for web developers it's you don't need to even know there's a lot of change basically it's just for a few out so anywhere else that's a great question and so currently on the standard implementation we just do confidentiality so just the balancers obscured but the protocols for compatible with stealth addresses and so you can make the owner of any note a stealth address implementing stuff addresses on aetherium is kind of someone else's job but it is compatible with it so if someone builds a good staff address wallet that can do that as text compatible with it there's a small issue with the gas cost and who pays for gas and we have some solutions for that which we'll be talking about in q3 we have like a mixing service that's the abstract sir but if you have a kind of centralized transaction relay you can have fully anonymous transactions as well and museum staff addresses yeah I say for any mint herbal asset there's one note that keeps track of the total mintage and the total burned so the owner of the zk e asset who crates that particular assets their private key can always decrypt the value of that note improve the total mintage well this we talked about with a proof yes but it's not public yeah it's in note form and if you want to prove it you could prove it to someone so you could you could use the range proof to prove that was above a certain value or below us in a body if you want to do and and the owner of the note registry so in your case the dapper and I could do that cool look forward to seeing everyone builds an area will be around or weekend just ping us on discord or come and grab us and we'll happy to help you build and ask any questions about architecting or same [Applause]
Automatic transcript — names and jargon may be misspelled.