Boba Network 🛠Understanding Hybrid Compute - Kevin Riedl
ETHGlobal·Mon, Oct 9, 2023, 12:00 AM
Join Kevin Riedl from Boba Network for a workshop titled "Understanding Hybrid Compute." Thank you to everyone who joined us for ETHBogotá 🇨🇴 and helped us kick off Devcon Week. With over 1400 attendees from 62 different countries, ETHBogotá was our biggest hackathon in Latin America ever! ----------------------------------------- Follow us: https://twitter.com/ETHGlobal​ Check us out: https://ethglobal.co​m Email us at: hello@ethglobal.com #ethereum #web3 #blockchain #eth
Transcript
foreign [Applause] [Music] I'm Kevin from Boba not sure if you have heard about Boba Network yet it's an optimistic call up that allows you to make off-chain calls within one single Atomic transaction and that's called hybrid compute formally Turing that's what I'm super grateful today that I'm allowed to present you today to give a little bit of backstory of why we started with hybrid compute basically we have all seen the craze last year we have to play to earned games right x infinity and all those uh copycats and comparable um played your own games which unfortunately weren't that sustainable right and we don't have a solution for that unfortunately too but we at Boba believe that it's time for great games right and great games what have all of them in common create your ex right they have a amazing gameplay it's not like you need to wait for some things it's easy it makes fun and you don't play games just to earn money but because it's fun and to maybe even have some additional benefits like Gathering collecting some nfts or whatever right and that's what hybrid compute for right and before I get too deep into the technicalities um I want to give you a little bit of backstory what's the differentiation between hybrid compute where you can make these off chain calls and regular oracles right because that might be the first thing that you think about when I say you can directly call from your smart contract external API point and do some cool stuff with it right I'm not sure if everyone here ever used chain link Uma optimistic Oracle that's also here today um all of them have amazing Solutions all right don't get me wrong they have their use case they do incredible work with requesting data in a decentralized secure manner right but when looking at game file do we always need that async fully decentralized way of collecting data into our smart contract right I'm a smart contract developer myself I love decentralization right um so why are we talking about centralization now in the whole blockchain Space we always have that trade-off between scalability security decentralization right and when we go back one step and think about game fire ux is still a great gameplay still the most important aspect in the whole game for space and then almost all web free games incredibly unfortunately fail at this right and we need to change that so in comparison to all these oracles that we have now has had different use case where we need to wait several transactions mainly hours or even longer depending on the sensitivity of the data um there might be the need at some point that you can actually request data on time right within the same transaction just think about when you play a game you earn a nice little skin like a cool jacket or anything like that and you would like to personalize that in some kind of way right you want that uh some personal data that you have on your central as backend want to have that within your nft in a autonomous and uh trustless manner as much as possible right so what you can do now you can have within your smart contract can call your API endpoint in a synchronous way get the data and directly work with it and that actually gives you a whole new possibility or opportunities to build some great new applications right as said different use case than oracles and that's what we are going to do today so basically to give you some understanding how that enchantment works right Boba is has said a layer 2 solution so what we basically did we modified layer 2 gaff and when you basically call that smart contract function that triggers that API call then we intercept that RPC call and replace the original call data with the result of the API API call and save both of them to layer 1 which is in our case ethereum and that enables us to do that in the same transaction so to give you some understanding let me get that um to the other screen to give you some understanding before you uh get shocked Away by code um the whole touring landscape which is I said the old name for hybrid compute you will see that now and then on some places because everyone who has ever won a company knows that replacing a name is unfortunately a really difficult task um in China world we have three core components right or actually it's four we have your own smart contract that triggers the API call makes sense right then we have your backhand itself that understands or needs to understand some way uh that needs to understand what kind of information you're sending from your smart contract to the backend because it will be or needs to be API encoded it just can't be plain text or something like that and the same way or do we want if you return data from your backend to the smart contract it also needs to be in an understandable format and now we are coming to two uh order smart contracts that we might need to know or think about and that's on one hand the so-called touring helper or hybrid compute helper as you wish and the touring credit and both of them have a really close interplay one of them the touring helper is a smart contract that every project needs to deploy themselves that contract basically is nothing else than your personal let's say key to your backend let's put it that way and the during credit contract basically keeps track of your touring help on your smart contract but why am I saying this um as with every Oracle you need to pay for each transaction right for each API call you need to make a small deposit um in our case it's a prepay as you need to prepay your um if you basically deploy your project you need to prepay the amount of boba tokens that you want to uh Fund in at once all right so that your users can actually trigger those smart contract functions so every time you call your smart contract there will be 0.01 Boba token which is around a few cents currently uh deducted from your prepaid balance and the touring credit contract is deployed by us the Boba team which keeps track of your balance basically and the touring helper contract is some kind of authorization right so that only you only your users or the contracts that you want your custom Smart contract can actually call that endpoint otherwise I could just use your endpoint for free right and you would pay for it that's why we have two smart contracts here but enough Theory sorry for that um I want to show you a little bit um what you see here is really uh quite minimalistic example that I want to implement with you today and what it basically does it calculates the time deletion from based on the special relativity Theory by Albert Einstein sounds complicated right now it's just a basic math formula which would be quite hard to calculate in a smart contract as you can imagine right and that's why I chose that for today if you want to uh do that with me I have prepared uh a starter Repository that we that I would ask you to clone then we could actually do that basically it's uh on our official organization and it's called hybrid compute underscore tutorial the default branch is already the one that you can use to implement that with me today and um yeah there's basically everything is already set up and we will go through every step that it's actually needed to perform your touring call to give you a first uh insights on what we are talking about at all um I want to show you how does such a API API call actually look like right [Music] um the most right let me look here that's a more beautiful example [Music] you can see it here basically it's really just a one-liner right you can actually call your smart contract by calling a method on the so-called Turing helper that asset your project needs to deploy themselves but you don't need to change a single line there it's really just fully prepared already uh ready to deploy a smart contract that you can use you just needed to actually keep track of your balance right [Music] um to get back to the Repository [Music] to give your asset a little bit of overview we have have said we have a couple of components here right we have our own custom Smart contract that we will Implement today we have our so-called touring helper ready to deploy nothing to change basically copy paste that actually tracks if your smart contract is allowed to call that endpoint to actually be charged for that so it's a white listing and some other you know error handling stuff and whatever but as said you basically just need to know two core functions that will be useful for you on one hand you have the so-called touring random function which gives you a super strong soil random number directly from layer to Gap and we have the so-called touring TX function where you can call any endpoint with any call data you want that's where you can actually do your off-chain calculations or call further API apis such as Twitter or whatsoever and yeah basically that's the Turing helper that's our Custom Contract that we will deploy today and then you will need your own custom backend right that understands the data you're sending to and data that you're returning from in our case we just used uh AWS Lambda function that's already prepared for us I still uploaded it here so that you can actually have a look at it and understand it but basically everything that it does is decode uh the API encoded data and encodes the result as well so nothing super complicated on Magic here but as said that already deployed so if you have cloned that for yourself what you can do now is as always if we Deploy on testnet we will need some kind of testnet tokens right otherwise it's going to be hard to actually deploy anything we have a nice little faucet for that on on our Gateway you can find it if you type on the search bar Gateway linkabee dot Boba dot Network and as you can imagine right now that's the faucet basically this faucet itself actually uses hybrid compute itself what it does is it asks you to copy your so-called Boba Tech which is nothing else then the Boba prefix with md5 hash of your public key and post that on Twitter just like I did here if you have that just need to copy the link and can put it in here what this does now if you click on authenticated faucet it actually requests from the smart contract the Tweet API and checks if you have posted that and then sends you step over and if so that's what you would need to follow the workshop today so if we go back to our own project now what I did is to actually give everyone here a little bit of a safe haven if you code that today then I want you to be sure that it actually works right for that very same reason I wrote a simple test that actually checks if you did it right so nothing to be done here but basically what this test does is it returns uh it checks the event that I'm emitting in the smart contract which we need to do right right now it's undefined Undeclared uh variable and yeah then basically just checks if the value within the event is the one that we are expecting to and yeah small hint not too confused too much but basically as you might know solidity smart contracts don't support floating numbers and this formula returns actually a really small number that's why I multiply it on the back end uh the floating number with 1 trillion and here I'm just dividing it back to a value that makes sense so basically what this would do now it calculates how many minutes basically your time is stretched if you almost move at the speed of light right we're very close uh to the speed of light here that's the velocity parameter and then we have the proper time which is the original time that we we as a person actually feel like it is I think everyone here or most people have seen the movie Interstellar not all of it is science fiction the part of it where gravity and uh basically the speed of your aircraft uh stretches the time is true so let's get Hands-On right I have prepared some Setters on top here which you don't necessarily need right as you know you can't provide everything yourself but basically every time when we want to use hybrid compute we need our own custom Turing helper alright that's the contract that we need to deploy ourselves that's the one that we had a look at before right to run with error codes and with the touring tags function with the Turing random function and so on so that's basically just deployed bars I'm just assuming that for now and basically what you need to do is provide that address to the contract so that your custom Smart contract knows where to redirect your call data to the second would be what's your actual backhand right what your actual backend API URL and that can be anything as you might guess in our case it will be AWS Lambda instance which you can use yourself I already pasted it in the in the tests if you look here it's on top it's here that's already live so basically that's our python file that we see here so to actually make that work now we now have or assume that we have our hybrid compute helper we assume that we know where the information should actually flow to and now we actually need to do three basic steps which could be in theory of one line now but I want to make it simple so the first thing we would need to do is encode our parameters that we want to send to our backend in a way that the smart contract is able to handle so basically what we need to do is we need to create uh a byte value I'm just calling it right now problems and we basically just encode our two parameters that we get from this function proper time that those are the 15 minutes that we saw before and the speed that we're moving at so that's the first thing basically we encode the data in our understandable format so the next thing that we need to do is to actually do our synchronous API request so that Works uh in a quite similar way with the Turing TX method that we saw before what we get from the API itself is again a bytes value so it's really uh it needs to be in a format again that the smart contract understands so basically we get here our bytes memory again I'm calling it USB for now and now that's not best practice and now our so-called hybrid compute helper comes into play and we see now that we have our joint TX entering random function that we can use the touring the X function basically let me see if we see that even even here yeah requests that we send the URL that's our um HC endpoint in this case just just a regular string and our already encoded parameters the ones above that's it basically that sample line sensor API request to your backend no callback nothing else super simple and the next thing what should I do with bytes now no usage for that I want to have some kind of proper value right you want to have a number I want to have a string whatsoever now it would be great if you know what your backhand returns right otherwise you get some random uh value out of it in our case I know that it's an integer value so what I'm doing now is um defining that the first value of my Tuple is just a number and I decode the rest B value that we just got into urine it's always great to develop onto this place so that should be it right that result that we get now we just emit the event so that our test can actually read it and check for the accuracy that would be the whole Magic this asset um I hope I didn't confuse you too much right it's always a little bit difficult to go from Silver to 100 but basically this enables you to do a lot of crazy new things all right things that you couldn't do that easily before but everything is possible right now right we have oracles we can't do everything but we all know we all went to uh through call by Cal in web 2 and it also can exist in web free right asset chain link Uma all oracles are great they have the use case this is a different one so now I'm going to do the most risky part of my presentation I'm trying to run the tests let me let me see if everything works so what these tests now do they basically deploy our touring helper let me show you Ploy the Turing helper here I said that's just our prepared contract from before our own smart contract where we actually provide the Turing helper address and our backend URL this case asset AWS Lambda instance and what we need to do now is we need to know basically the Turing helper needs to know which smart contract is actually allowed to call maturing help on my endpoint right for Which smart contract I'm willing to pay for right otherwise I said I could deploy a smart contract and one of you needs to pay for it right wouldn't be so cool that's this line basically a white listing to protect your funds when we're talking about funds we also need to basically fund I found the touring credit contract which keeps track over your funds by actually knowing your touring helper contract address because you're touring helper triggers that API call finally and that's why the Turing credit knows from where the call comes from that's what we do here we basically just add some boba tokens to the twin credit contract and the rest is just some basic checking if if we get the correct address back and so on so that's basically it I'm super happy that this works and I hope you learned something maybe uh you've got even some kind of like crazy ideas for the next few days I don't know I would love to know them and yeah get any questions I'm happy to answer [Applause]
Automatic transcript — names and jargon may be misspelled.