Aleo: Zero Knowledge Dapps - Blockchain at FIU

Patrick Devaney · Intermediate ·🎨 Image & Video AI ·2y ago

Key Takeaways

This video explores zero-knowledge technology and its applications in blockchain

Full Transcript

so Bitcoin plus privacy will become zcash I don't know if everybody is familiar with zcash is pretty much the very first blockchain that enabled this uh sort of privacy transactions onchain then we have Alo so that's sort of the positioning of Alo in this ecosystem is that we're trying to enable privacy but also the the flexibility of programmability uh on top of blockchain so I'll talk a little bit more about the offchain in a bit and that also enable this unlimited application runtime so blockchain execution here means you know running uh sort of like the in the ethereum virtual machines you have to uh you know whenever the code that you write in solidity they're going to be comp compiled into bite codes right and those each bite code means different steps so you have to run all that on every single Noe in the blockchain because everybody needs to run their ethereum virtual machine um and then once they once they execute all this solidity code they'll update their state on their no and they every single node in the blockchain will do that but in Alo it's a little bit different not everybody needs to run the execution they just need to validate pretty much three types of roles uh on the very far left on the very far left is validators and then in the middle is the approvers and then on the right is developers like us so starting from the developers we're the one who are creating magic we're the one who are coding the smart contract that can run on top of Alo and the language that we use to run run uh to write uh Alo smart contract it's called Leo uh it's a functional programming language for ZK circuits so if you're not familiar what ZK circuit means is basically a a sort of a setup for for for certain inputs to be passed in so to make sure this input can pass through all these Gates and at last it creates sort of a it has this sort of a proof result um so once you go through that and then you create this proof result and this proof result can be validated by different parties to to ensure that okay you your based on the input the public input and the proof that you provided you know and using my validation program that I run using these two input the the public input and the proof that you provide I can validate that oh you actually Ren the program correctly I can trust you uh but I don't have to know the details the what was the private impos was but I can still trust you so coming back uh with vo you're writing the smart contracts and once you finished writing the smart contract Logics then uh you'll be running your your codes and the execution environment happens at the provs so it's in the middle um the the actual term is called snar VM so snart virtual machine and it pretty much what it does is uh let's say uh let's say let's say you have you want to do a function call like you want to do like a uni swap like a swap function right normally on ethereum what you do is you send that request to ethereum network and some of that noes or some of the miners are going to pick up that request and then they'll be first they'll broadcast that request to the other noes uh nearby that's first and the second will be they will execute uh they will sort that transaction request into the blog and and then try to run it blah blah blah so that happens there but for Leo it's for Alo it's a little bit different instead of sending that transaction requests to the miners uh but instead it has two approaches so first you can either run that request locally on your own device just your own device and by running it uh you have your own input locally and you generate you you you run the start VM execution environment on your local device locally and then after you run it you create that proof and then that that proof creation process also happen locally and after all that's done what you do is you pass the proof that is generated and the public inputs that you step into this snar VM for the execution you pass both of these to the validators on the very far left and they would and validators you can just think of as as like a uh like the the miners in in blockchain there you can think of them as the miners in blockchain from the ethereum standpoint but uh what they what they're actually doing is just validating the proof that is generated from these local clients right so what does it mean so if you kind of compare is that instead of running running that cold logic in every single noes in the network instead in Alo what they do is you only need to run once and then you're generating that proof with the inputs together uh and you just pass it to the a group of validators to validate and validate usually take about 01 time so what does 01 time means it's just constant time and it's super super efficient so that's why we try we're trying to say it's like more scalable numbers of execution doesn't scale approver uh approver services but it's still offchain uh you only need to run once and they they will be downloading that Alo program or they already have it on their local device uh from the validators because we as you can see we we just uploaded our Alo program to program registry right so they'll be downloading that to their local execution environment uh you know activate the snbm and then they will run this Alo program specifically the the the example that I was giving is the unisoft swap functions so they'll be running that and and you know after they have this proof generated after they finish running generating the proof they'll upload that proof to uh to onchain so this will be the onchain part so after the op chain execution is done which is the far left and then they will set the proof over to validators again and the validators will you know get the the proof result and then the encrypted data and then they'll just validate the the correctness if your execution if it passes and if it works then they'll update the entire execution of result on chain and also return to the user who whoever call that uh swap request uh for an update say hey your transaction succeeded congrats and then once all these knows are agreed on one single data uh one sort of one set of data that they uh they they read on uh then they'll upload it to the chain so so that's how they work uh but with verifiable oracles it's a little bit different so instead of having multiple notes that is running to fetch the same data and then have everyone to agree it on and then submit it on chain uh with zero knowledge you can just like oh you know whoever fetched the data just create a proof of you're fetching right the fetching process and then I'll just validate you I I'll just check like oh okay you have a proove you have your input I'll check it okay it works so I'll I'll Trust you as simple as that it saves a lot of the overhaul and private and compliance stable coins will just be you know providing reliable Financial transactions with privacy guarantee by trei so try is still uh it's a pretty general term uh I would even say just a marketing term too but it's just like just trading uh in general and for web develop there are there are different solutions too like zero knowledge gaining so verifiable Randomness this is something very hard to achieve uh when there's zero know proof technically speaking you know random number generation on top of zero knowledge proof it's just pretty hard uh almost impossible uh but we do provide uh a random number on in Leo uh language so which uh developers can utilize uh and also there's privac Pres in machine learning so something like uh something like for instance like maybe maybe like you develop like a privacy preserving machine learning model and then the inputs uh we should have really covered this at the after the Leo language introduction but because of the Fe because of the nature of Leo language uh that you can set variables into privates so so that creates the possibility of privacy preserving machine learning and zero Notch authentification pretty much like I can review that I'm over 18 without without showing you my ID something like that very expensive and if you want to create like a proof on top of a very large number then the proof generation gets extreme uh more one level one level more complicated so you want to be really careful of what kind of numbers that you're using as small as possible definitely uh and just yeah so so I that's sort of coming from the from the blockchain performance perspective there's that's why there's this requirement if you have to specify your numbers uh specify your your variables into the very specific data type yeah but you can do casting among these so so so that's totally available yeah so so there are different data types uh 16 Primitives to be exact so on the very left you have Fields scaler groups so these are not very intuitive to us if you're coming from other programming languages um but you can kind of understand field as uh so so so on zero knowledge there is something uh there's some uh you know they usually work with a prime number field so it it doesn't really go above that prime number Fields so whenever I want to create a proof I have to work with numbers that is within this pre prime number field so that's why there's this field element so this fuel element is usually used for uh for proof generations and also um and also just some decryption and that kind of related uh operations so you want to specify your input as field elements and that the range of that field uh is set in stone uh with the Alo blockchain so Alo I I forgot the exact number because it's really complicated looking uh but but yeah uh you have to fit your number within that Prim of field uh if your number goes above that field number uh the field size then pretty much it will just take the modulo of that number uh uh of the entire prime number field uh so so just the remaining and scalers and groups they kind of work together uh it's pretty much for ecdsa um uh how do I explain uh so ecdsa is sort of like a encryption scheme where encryption DEC scheme where you know you're you're having a different pairs uh uh you're maybe I should have put a graph up here actually uh yeah but but pretty much like if you want to do encryption and decryption then you want to use groups and scalers and scalers are the ones that is used to to multiply uh to to divide uh with the group numbers so you can think of scaler as the coefficient for for for group variables um um but we'll see these three interactions in a bit um but later uh and then we have binaries which is bullying which in a lot of programming languages we already have which just true and false data type we also have address and string integers we we got a lot of unsign unsign in and also just integers in general and then we have strs and Records uh Records might be a little bit unfamiliar to most people which I'll explain a bit yeah so if we look at the very left the stru type is just how you want to define a sort of like a like a struck like in any other languages uh but record is a little bit different so record is what we really use as to show the the sort of like the asset transfer sort of relations on blockchain level so let's say I own let's say I own about 10 tokens so how shows up in blockchain so on ethereum how it usually shows up that is that you know uh it just shows that under this smart contract this token contract token it will have an array that store say hey under this address uh you know this uh under this user address you know there's this amount of balance so so it's just like a state model uh and for every sort of transaction let's say I put I I purchase like 10 more tokens then all they need to do is just changing that array uh of let's say it's a key value pair and they would just use my address as a key and then the value would just add 10 increase 10 there and all they need to update on ethereum client it will be just update that State uh but on Alo is a little bit different because Alo is not a state model it's a utx utxo model uh it's it's pretty much the Bitcoin model so everything has everything is sort of a transaction histories right so let's say if I want to own like 10 token records then I need to create those token records and then I need to transfer that into my address and I only I I will be only owning this records and if I want to transfer like let's say I minted 100 tokens then I'll be creating the 100 tokens and then transfer that records to me so I'm only records instead of the tokens although it's like token records uh and then if I want to transfer 10 tokens to some other folks that what I will do is just split this one record into two records of 90 tokens and 10 tokens and this 10 token records will send over to someone else that I wanted to give to and 90 token records will stay within me so it's not like just changing a variable in a in a map or array that kind of a symbol uh but instead is you have to just you have to manipulate with with the records um and on blockchain too uh you know uh the entire sort of uh transaction history is actually shown as you know changing in records so if you look at this very top you have mapping so mapping is pretty much mapping in another language is you have key and value yeah so so mapping mapping is pretty much just keym value pair right uh so uh this is how you init in this is how you declare mapping so what this means is you know I'm creating a mapping sort of variable called balances and the key of this balances mapping is address the value isign it 64 and I'm also declaring a token standard records uh which it will specify the owner of the token and the amount of tokens and struck here will be the message uh it would include the senders address and objects um in unsign unsign in 64 so this is the sort of the very specific part of Alo uh that gets kind of tricky to understand so there's transition functions there's finalized functions and there's function functions so all three of these are functions but they they're named differently how are they different so for everything that is written inside transition functions it happens option so let's say if I want to do a uni swap uh actually is a bad example uh let's say if I just want to uh if I just want to decrypt something uh if I want to decrypt something then it doesn't have to run on chain that I can just write the decrypt function inside this trans trans function uh and then I can just fetch that uh fetch that result locally I don't even need to submit the final result to the state or anything because it's just I need to decrypt something for my offchain executions uh but after trans after transition function is done then you can see it's followed by this part it's called then finalize so what does this mean um and you can see the name is also same too like the transition function and the final function they're name the same but it's just the the prefix the transition and final is different so the difference here is um if I call this mint public function what's going to happen in this my contract is that it's going to first execute the transition function off chain and then once the the code inside this transition function is done running then is going to pass the proof and the input uh to this finalized function and this finalized function runs only onchain so finales keywords is trying to is to specify whether this function is uh is is specifying the function is running on chain so transition is to specify a function that runs off chain so now that I'm passing the proof and the inputs to the finalized function then this part will actually run by every single validators on the network and the result will also be updated to the mapping because this is what they're doing right setting the mapping uh with the account and receiver uh and also the the amounts yeah and so so what about this function what does this do so pretty much you can just think of it as like a helper function or in a easier term sort of like just make the code prettier so instead of having this code a plus b written inside one of these they want to separate the logic out so that you know it's more modular and the code is more reusable you can just write it inside the finalize or transition if you want but you can also just write it outside so so that's totally up to you up up to your coding convention you so so that's sort of the general outline of how Leo smart contract Works before to understand for a lot of the developers actually because it's like it's just specifying whether I want to run something off chain or whether I want to run something on chain uh but like you mentioned there might be something that is more zero knowledge focused and it's just really hard to get your idea get your heads around uh I think there's some examples it's like these librar yeah so so something like this so so these are hashing libraries that you can use um so so this will be really just uh yeah it depends on the depends on the application that you're building uh and you can choose any kinds of hash that you want uh and also you can convert your hash into different variable types like scaler groups or uh or or field and these are some of the things that are supported but not a lot of people know how to use it uh but but yeah but pretty much it's just like Shot 2 5 uh 256 um which you can see here and there's like a couple other options but there are some of the ones that are you know Poseidon 2 48 you know these are some of the hash functions that are not supported in chains but supported here so it's just worth taking a look and also this commit even myself I'm I haven't really used it yet uh but but yeah this is like a commit function I am not 100% sure what this is for actually yeah so so so here something like this too uh but other than that you know everything else is very similar when it comes to just programming the OS smart contracts because they really made it a way that is just very similar to your original uh coding experience uh besides you need to think you need to think in another dimension where you want to run something on chain or off chain so so you want to be more careful be more mindful of that but other than that everything else should be a very similar experience uh except commit I'm not too sure of that myself what makes posidon different from other hash functions so hash functions is another sort of a topic uh but posidon it's just faster yeah it's faster than Shara 256 uh it's a pretty new one there's even Poseidon 2 which is even faster and there's like blight three just all these sort of namings uh but yeah eventually it's just Pro uh improving in performance yeah I guess one of the other points I was kind of bringing up with like ZK proofs would we need to know like the way that the Alo virtual machine works or bite code or that sort of thing so if you uh you can like if you want to um you know so so so how this works is if I if I create a new Alo smart contract sort of project then this is how the entire sort of project outline uh folder looks like and what and if we build it it's going to create a file called main. under build folder so what is main. Alo so Alo is pretty much the B level language uh that you can use to write your own circuits uh what's different from Alo to Leo is pretty much you can think of Alo as the assembly version of Leo language uh so so Leo will be the the front end language and then Alo will be the the back end or just like compiled version uh so yeah if you want to really optimize your code and make your ZK circuit more I don't know just smaller I guess more optimized you can do so at the Alo code level but still even that you don't need to touch the virtual machine yeah so the virtual machine should be just an instance that you run without you do any sort of configuration uh but if you want to optimize your code for verik circuits you can do so at the Alo code level yeah so so just like in solidity instead of just like in ethereum instead of writing solidity you're writing evm bike codes for your program so that's more hardcore uh there are for Frameworks for that something like Huff uh you know pretty much just having you to it's a framework for you to raise evm bite codes smart contracts uh it's kind of complicated um but it gets the job done really well and is more efficient to to rate your smart contract that way but yeah but but for Alo it's a little bit different because a lot of the computation can happen off chain so the computation resources might be for the op computation part you know you don't have to consider too much about the optimization uh but of course you would want to uh just for the better performance uh but since you know op competition you only need to run once so you don't have to be that mindful compared to the aing competition part yeah so if you want to optimize I would definitely recommend optimize onchain computation Parts by codes a codes Leo wallet that we just download here so that will be a wallet extension on the website like a Chrome extension you can use this for sure uh but you can also just since we're just testing and playing around we can also use this terminal command called Leo account new and if I just type enter then it will create a new Leo account for me and what it has is what it contains is private Key View key and address so what is private key private key is basically like the uh sort of like the the most important information of your wallet if you expose your private key to other folks they can use that private key to retrieve your wallet and gain access to your wallet uh for for everything you know they can just do anything with the private key so you don't want to expose private key like I'm doing right now actual message of that transaction instead of viewing the encrypted message so so yeah V key is pretty much just a decryption key to C transaction activities so yeah once your account is created you know uh you can also you can gain your test tokens by going to Alo faucet so it's this uh what you want to do is text this phone number with this message send 50 credits to this address and this 81 XXXX is pretty much the address here so you want to send a text message to this and then you'll receive your your 50 credits uh in no time it's yeah it's not the best experience I hope they use another approach but this is what Alo has so yeah stick with it guys um or was y but since it's like local testing so I don't think you need to have I don't think you need to have test net tokens unless you want to deploy to call this main function because uh by calling this main function is still a transaction request right and this transaction request will be stored this this this history will be stored on blockchain um but some parts of this request will be public some parts of it will be private so the public part will be the input a but the B will be private so so that technically uh technically that's sort of what it means uh and the result C is it will also be private so the output from this transaction will also stay private so so yeah from other users who are not the one who call this main main transaction request all I can see is just I injected a number into this function uh to this a variables and I know that there are some other variables or whatever things that happen for B and there's something coming out as C but I don't know what the values are so that's how it that's how it store that's how it exists in the blockchain here uh if you call this smart call this function so yeah so so what this called that is just Tak a input private B input and then getting the C private output and then return it right and under this input file uh so what this does is specifying um if I wanted to test out some of these functions this main function then what are some of the inputs that I want to put it into uh so these are just some of like U test scripts or or demo Scripts and you're just writing some toy data to test out some of the features so you have public a which is one and then private B which is two right here so the result should be three right so let's try to run this run main so by specifying V run main I'm I'm telling the Leo Leo command line that hey you know call this main function call this main function not the main. Leo but call this main function uh and if you want to find the input of this main functions it's either I specify here you know I either I specify here and then if I didn't specify then go to this input folders and look for Ain file and inside there I should have specified it so which I have and it will take the inputs from here one and two and the result is three so yeah that's that's how the the folder structure and how the testing uh with all these code works out of my 100 token balance uh which will get the senders balance and from senders balance I'm going to create a new record which is the 90 tokens that is remaining and also I'm also creating a token record for the recipient which will be the 10 tokens specifying the owner is the receiver and I'll return both of these records uh after calling this functions so so this is exactly what I'd explain at the very beginning say I own 100 tokens uh in one record and if I want to split this 100 tokens in uh if I want to transfer part of this 100 tokens to someone else then I need to first split this 100 tokens into two two records and one of the records will be the amount will be the information uh the amount of tokens that I want to transfer to Le Clipper uh then I'll I'll send this record to him and I'll keep the the second half of the record to Me Myself and to prove that I actually own this records I own these tokens yeah so so this is what it does uh it's not that complicated but kind of overe explaining to everyone just to make sure everybody understands it uh so now let's go into inputs so now that we have defined so now that we have defined mint and transfer functions I've also written some of the inputs that you can follow so you can just kind of copy from this GitHub you know Define input section and just copy this and then past it specified its owner and specified its balance now I want to do a transfer so this transfer will be uh it's going to take the receiver's address and the amount of token that they're going to be getting and the input of my token record so this token record will not work because you know actually not the record that I own it has to be the record that I own which is this the one that I just mined so I have to copy this and then I'll paste it on here and just get rid of these so now that I have defi I have what I have specified is okay I'm going to send I'm going to send 10 tokens to this address of the token of this token that I own that is Created from the Mt function so I'll just call Leo run transfer which is this function name and as you can see it has created 10 tokens uh for this address that we're sending to this 1 yn6 h

Original Description

zkWorkshop: A Deep Dive into Zero-Knowledge Technology Join us for an exclusive exploration into the world of zero-knowledge technology at the Aleo zkWorkshop. What: An exclusive opportunity to dive deep into the privacy-centric realm of blockchain with Aleo's DevRel Ambassador, Brian Seong, and learn how to craft private applications that redefine the landscape of decentralized apps. Who: Developers, researchers, students, and all technology enthusiasts keen to understand and contribute to the future of zk technology. Where: 1501 Biscayne Blvd Miami, FL 33132, USA Agenda: Presentation "Aleo: ZK by Design": Discover the principles of Aleo's zero-knowledge proofs with Brian Seong. Workshop "Learning Leo": Embark on a guided hands-on experience in programming with Leo, Aleo's proprietary language. Deployment Challenge: Deploy on Aleo and stand a chance to win an Amazon Gift Card worth USD 100. About Aleo: Aleo stands as a unique Layer-1 blockchain platform, merging the programmability of Ethereum, the privacy provisions of Zcash, and the scalability offered by rollups. Join us in building private applications on Aleo, a trailblazing Web3 protocol where the development, deployment, and execution of zero-knowledge applications are simplified, removing the need for a BD team or a prover API. #Aleo #zkWorkshop #ZeroKnowledge #Blockchain #Web3
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Related Reads

📰
50+ Sequential Images, One Prompt in Codex
Learn to generate sequential images with Codex using a single prompt and understand the limitations of this approach
Medium · ChatGPT
📰
How can I batch-generate 3D assets from prompts or images using an API, and which 3D generation APIs support batch generation?
Learn to batch-generate 3D assets from prompts or images using APIs for efficient pipeline creation
Reddit r/artificial
📰
How AI Head Swap Works: The Technology Behind Realistic AI Image Replacement
Learn how AI head swap technology works and its applications in image editing
Dev.to AI
📰
How I Built an AI Pet Portrait Generator That Turns Photos Into Art
Learn how to build an AI pet portrait generator that turns photos into art using deep learning techniques and Python libraries
Dev.to · William Li
Up next
How to Create Quick & Easy Product Animation Videos with AI
Maksims Sics
Watch →