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

Loading player…

Confidential EVM? ROFL! - ETHGlobal Singapore 2024

ETHGlobalWed, Oct 9, 2024, 12:00 AM

Join us for a workshop with Matevz Jekovec titled, "Confidential EVM? ROFL!." Oasis Sapphire is a production-ready confidential EVM chain. But there's more. The next-gen dApps can now run computationally expensive tasks offline, while being integrated with Sapphire, preserving trust and confidentiality. Here comes ROFL! This workshop took place at ETHGlobal Singapore 2024, a 3-day hackathon held from September 20 to 22, 2024, that brought together the most skilled web3 developers, designers and product builders from all around the globe for a weekend-long adventure to advance the Ethereum ecosystem! ________ Follow us: x.com/ethglobal Website: https://ethglobal.com Email us at: hello@ethglobal.com

Transcript

[Music] okay hi my name is Matos I'm a software engineer at theis protocol Foundation uh and today I'm going to talk about the Hot Topics we're currently tackling uh at deasis uh before we start I just wanted to ask you uh how many of you program in solidity uh yeah had okay cool uh and what about in Rust single one okay not bad two yes okay awesome um so right uh let's talk about confidential blockchain and what why are we doing uh blockchain from the first place so it's a distributed network of nodes right there is no centralized Authority no censorship uh which is great um computation is very robust uh it's completely redundant so is the storage every note stores everything and knows about everything that's going on on chain um but there are also some caveats right because it's a complete redundancy the storage and the computation is really um expansive overall um we have a blockchain which consists of blocks right so despite having an instant uh finality for example aasis Network you still have to wait for a block time uh in the worst case so so this is this is 6 seconds in our case so expected time is what about 3 seconds which may be too much for some applications uh and finally at least in ethereum um world State try is completely public it's transparent to everyone uh transactions are public um so at Oasis uh this this was years ago we developed a confidential evm compatible blockchain we call it Oasis Sapphire uh so what do you get you get an encrypted contract State this means that everyone will be able to access any contract but uh it will not be able to see what's inside the contract State uh then you have transactions all transactions uh can be end to endend encrypted so the whole Ledger of transactions will contain well it will contain normal transactions everyone will see those transactions but the content the call data of those transactions uh will be encrypted you will still see the from the two address uh the gas information but not the call data uh itself uh we are evm compatible so even though this sounds uh uh awesome to have an encrypted contract State we are still uh try to be evm compatible apart from that e get storage at calls for example that gives you uh the contract storage state which cannot work uh in our chain of course um how do we do it well we run uh the complete Sapphire evm inside The Trusted execution environment uh int sgx to be more precise um so this is how how we we preserve uh the Privacy so every node operator Who Wants To Be A compute node uh needs to have sjx support and he cannot he has no idea what exactly is going on inside the trusted Enclave uh right so on the client side if you want to have encrypted transactions you need to use our wrapper for either typescript go or python um and then all the queries and transactions will be end to endend encrypted uh so on top of that we also extended uh the functionality of solidity we offer sapphire. uh library and you can do some really exciting stuff with it you can have a run random number generator which runs completely uh on chain uh and then you since you have random numbers you can also generate derve new key Pairs and once you have key pairs you can sign messages you can encrypt decrypt everything uh on chain which is really really cool um and for those of you who maybe are familiar with the sign in with ethereum uh Cu uh so this is a mechanism uh developed a year ago uh basically for users who have uh metamask wallet and they want to use some web to applications and without having you know email address and so on they can just you know log in with their ethereum wallet well now we so support cwe uh parser uh onchain so you can now have a complete web 3 application running completely um onchain uh even the message the C login message can be parsed um onchain uh for cross chain communication we have opal uh it's an abbrevation for Oasis privacy layer so if you have an app running on some other chain and you have you want to have some portion of that app running on the confidential uh chain for uh managing confidential data or some logins Keys whatever uh then opal uses seller Bridge uh under the hood uh so we prepared some uh you know basic building blocks for that and now uh to illustrate this so basically you import our uh Sapphire Sol Library uh to Generate random number simply call sapphire. random bytes and this will give you in this case 32 random bytes and then if you want return a favorite number of your user or if he won a lottery for example or if he got a swag or not uh you just U do the model operation uh and extract the the number or if you want to generate a key pair you call the generate signing key pair function providing the the seed um we also support so the the sapit 256 as well as the ed25519 uh encryption scheme uh then you can encrypt and decrypt onchain these are all prec compile so they're very cheap um then you can uh sign a message and verify if the signature is correct and there's also one cool thing you can do with it you can also generate an ethereum transaction on chain and sign it on chain and then you can sign it with some account which is funded so basically you get the gasless transactions for your for your users uh very very easy uh so those of you who um follow the uh account abstraction uh debate in the ethereum world uh well this thing is much easier it's a straightforward implementation um of the simple you know signing the the transaction and it already works like today in production um and finally I mentioned cwe before uh so this is the nice popup uh metamask shows you if you want to log into some app um and how we do it well you Store The Domain where your dep lives uh inside the smart contract and basically the user then calls the login function of our contract our parser checks whether the login credentials match the signature of the message and then it obtains the barer token and with that barer token he can then uh proceed doing some confidential queries uh to your smart contract um and uh this in in this code here this o message sender helper will extract um the me the original the proper message sender uh from the beer token the user is providing each time he tries to communicate with the smart contract okay but this is all blockchain this is all onchain and this is so 2023 you know this is what we did in the past Safar is now I think two years old it's running in production for a year now on mayet um what we did uh this year and what we're still working on uh is like wouldn't it be cool if we um use this trusted execution environment to execute uh transactions uh to to to do the computation offchain since it's running inside the trusted execution onclave we can still trust it although it's not running strictly uh on chain uh so uh the positive points on this are it's it's local it's much much cheaper because uh if you consider AI or gaming or whatever uh it needs to be fast and cheap and uh even uh the Nvidia h100s support The Trusted enclaves uh so you can basically uh do perform um computation offchain and just use the blockchain part uh for signaling right so to to manage your uh offchain application to manage the authorization who can uh run computation um to build any any users that they want to use your platform for this uh so we basically combined Both Worlds like the the um performance from the offchain world and um the trust uh from the from the onchain uh blockchain and we call this ruffle so no pun intended it's just a runtime offchain logic okay uh and as I mentioned this is ideal for uh for dii if you want to have machine learning which is confidential which you can actually you know prove that your model was strained on a specific set because it was strained inside the te so you can actually trust it um this is cool for gaming because uh the block waiting time is as I mentioned like 3 seconds expected on Oasis and uh here you can just you know um open channel in parallel and have an in instant response uh and anyone familiar with dexes the decentralized exchanges they always need some oracles behind the scenes you know to fetch the prices from other chains and uh synchronize uh the price quotes now you can actually develop Oracle an oracle uh inside rafle and you can trust it because it runs inside a trusted on so it won't be any censorship involved uh because you can actually see the code and you know verify it that the ruffle is really running what it's claiming to to be running uh the mandatory sketch looks like this so uh each Oasis note uh can run um rafle app inside the te uh there's the light Cent and the attestation because it rest assur that uh the rle really connects to the chain you want it to connect so uh you don't connect to any third party chain that could spof any of your confidential data uh it communicates with sapphire so uh any storage you want to have for example uh storing your private key to access your AI um to decrypt your AI training Set uh is stored inside some smart contract on Sapphire for example but in parallel you can also open https connections freely this is something you cannot do inside a smart contract right you cannot just connect to Amazon whatever in inside solidity because it's a closed it's a closed environment and here you can use rule to open htps connections at your own choice and then do some computation and maybe store it on chain or just fetch some data from onchain to process it okay now uh I made an a small example of this so we are going to build an oracle that will uh fetch prices from uh coin uh no from binance uh and store them on chain like every block so this is the solidity part of the code um basically what you do in solidity is you store this uh rle app ID this is something similar to what you have in uh the Chrome Store or uh play so every app has its own ID even though it's upgraded to new version the app ID Remains the Same so here we kind of uh uh prohibit any other apps accessing this smart contract apart from this um app we Define inter con Constructor I think uh yeah here it is so we store the rafle app ID in the Constructor and then this modifier only O app um makes sure that the uh whichever app is contacting the smart contract it checks whether uh it matches the stored rule app ID that is allowed to to store um the price quotes and the submit observation is the the main you know function which basically just pushes um the observation of the price quote the price quote is here so it's a value and it's a it's a block when this price quote was taken um okay now the fun part this is the rust code and uh this is the uh code that runs inside rafle and that does actual fetching of the price quotes so here it connects to binance it checks the row usdt uh value uh it's a Json format so you need to decode it and then because well ethereum doesn't know anything about uh floating Point operations we multiply it by a million uh and have a integer at the end of the day and then we store this price uh by calling our smart contract submit observation function and passing um this data and then we set the guess fee and we sign and submit the transaction using the built-in signer of the rafle so uh this is done all seamlessly and it connects to the sapphire the one who you configured your rafle to to ATT test with right so safr in our case uh right and then there is some B plate uh for raffle you need to define the trust route this is uh the height of the block you trust it's hash uh the runtime ID so this is the run time this is the ID of sapphire and the chain context right the hash of the Gen block basically um the app ID is also stored inside rafle um and this is basically so it it runs itself and then uh on every on every uh incoming block it um it runs uh this uh run Oracle uh function so fetching price quotes from binance and storing them uh on chain okay so for the hackathon here uh I'd like to point out some resources uh so Doc wases iio is your Holy Bible for everything uh and um then we have the dep Sapphire sub page which is all about saphar uh rafle sub page for rafle uh if you are building a cross chain app then uh opal uh dep opal uh is the toolkit you want to use uh we have a wonderful playground. oasis. website which collects all the previous hackathon projects and any other cool uh projects demo projects educational um material uh running on chain on ois and finally uh I prepared the cheat sheet um you can follow this link or scan the QR code uh so it's a A4 uh plain uh paper and it there are a bunch of links uh to documentation mentioned here uh the wallet the Explorer and every other tool you will need uh to lift off um okay so I have a minute right yet so uh let me just show you quickly that this actually works so I I'm running uh Sapphire local net here on my computer currently and it's running in a simulated mode that that means that you don't need sjx uh to run it and here what I did was there are a few accounts which are funded and I also compiled the ruffle I just presented to you so it's fashion price feeds and what it does is uh so we have um yeah the rule is up and running and if we now check the smart contract part we should see that the last obser observed price is uh 67,000 not dollars but millions of dollars so that's like 6.

7 cents for a rose token okay and the block number was 4749 this is running locally so every second there's a new block mind on my computer and if I repeat this the block yeah the block number increases and the price you know slightly um uh changes um every now and then okay so uh the point being you can develop profile apps now you can also deploy it on testet uh but you can also deploy it just you know locally and to test it out to debug it and this is already for for the hack owners um all right any questions yes go ahead [Music] uh I would need to check this actually so not sure but uh if you're referring to the messaging there is no way to directly communicate with rafle from the chain yet so you need to rely basically on reading the contract state if something changes and then you know uh reacting on that so if you want to send a message directly to the rafle either you need to open a separate you know htps connction to some Port IP somewhere outside or you just you know regularly pull the sub the the contract uh state if there is a message waiting for you uh you you you need to implement this by yourself I know an array of messages and then get last message and some count Li to how CP no no connection yes so uh the rafle keep in mind that rafle runs inside the Oasis Noe so you must run the Oasis node with sapphire and then besides you you know initialize another ruffle and then those two communicate with each other so that's why you can you know do the this PS to the chain very cheaply because you don't communicate to actually everyone around you just communicate to your neighbor process on the same physical uh machine another question sooy the only inst register how many run so you have the Run f first when you register a rafle app you define this policy file this policy yl file inside you define uh how many instances there are allowed and you can also uh Whit list the nodes so each node has its unique you know identity and you can Define the public key which notes are allowed to run your ruffle if you want just you limit to a couple of you know notes but at the end of the day yes if it's open to everyone then everyone can load your ruffle and run it and uh there's no limit basically because the only way they communicate is via blockchain anyway so there's no you know reason why not to run so it's a complete distributed network of waffles in that matter uh running in parallel with the blockchain yeah so uh each sorry each node has its own uh key pair which it runs rawle you know from so you need to fund each noes instance yes and if you're using this built-in mechanism to submit queries you can always you know uh store another key pair inside rafle if you want and then use that for signing transactions but uh the The Trusted way of currently how it's done is basically you take the noes key and the note funds your transactions yeah okay yeah can we make sure that only couple of wallets can have access to that and it will be uh so the sapphire blockchain is fully encrypted so whatever you store to the smart contract there will be encrypted so if you store a wallet key inside the smart contract that's perfectly fine and then you need to build your own you know smart contract logic in solidity who can access that key whose key is that yes yes so every smart conct should have some kind of the access control list yeah and it's much more important here because we we have a confidential State and you need to make sure that only you know specific users can also run queries because you have this gas cost attack uh you can you know assume what's the internal state of the contract if there are some if statements inside your business logic of the smart contract that depends on the who what's the balance of something then take this path what's the balance they take the other path then then uh someone could you know Forge uh the message sender and try to behave like simulate call if I were someone else like and then you know extract some important data from the smart contracts so that's why we prohibit um doing simulated calls uh if they are if they are unsigned if the queries are unsigned then uh The Message Center will always be zero regardless of whatever you you you define it in the call otherwise yeah if you sign the call sign sign a transaction that means that you are you and then the message sender is valid and yeah you can do the rest of the business logic okay uh I have one more question just quick quick one yeah yes I mean uh you can do rafle you can start with the the example I I showed maybe and then do some yeah fetch price quotes um but yeah from the 2023 story uh like the sapphire story you can do the whole Myriad you know of uh awesome apps you can do inside the confidential smart contract yeah so guess this transaction is just one thing um you can do cross-chain uh opl uh you can do login with cwe um uh yeah so wallet your your colleague mentioned like onchain wallet for example um yeah okay thank you [Applause] [Music]

Automatic transcript — names and jargon may be misspelled.