Kevin in the Wild / On stage
Boba Network 🛠 Understanding Hybrid Compute - Kevin Riedl
Recorded in English 28:01
Recording published
Transcribed from audio with Whisper and reconciled with the platform’s automatic captions using AI. Brackets mark unclear speech. Original language, without speaker labels; errors may remain and the recording is authoritative.
Introduction to Boba
Watch this part · 0:000:05 Hi everyone, I’m Kevin from Boba. Not sure if you have heard about Boba Network yet. It’s an optimistic rollup that allows you to make off-chain calls within one single atomic transaction. And that’s called hybrid compute, formerly Turing. That’s what I’m super grateful today that I’m allowed to present you today.
0:28 To give a little bit of backstory of why we started with hybrid compute. Basically we have all seen the craze last year with the play to earn games, right? Axie Infinity and all those copycats and comparable play to earn games which unfortunately weren’t that sustainable, right?
0:53 And we don’t have a solution for that unfortunately too. But we at Boba believe that it’s time for great games. And great games, what have all of them in common? Great UX. They have an 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 whatsoever.
1:32 And that’s what hybrid compute for. And before I get too deep into the technicalities,
Oracles vs. hybrid compute
Watch this part · 1:361:40 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, 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.
2:07 I’m not sure if everyone here ever used Chainlink, UMA Optimistic Oracle that’s also here today. All of them have amazing solutions. Don’t get me wrong. They have their use case. They do incredible work with requesting data in a decentralized secure manner. But when looking at GameFi, do we always need that async, fully decentralized way of collecting data into our smart contract?
2:47 I’m a smart contract developer myself. I love decentralization. So why are we talking about centralization now? In the whole blockchain space, we always have that trade-off between scalability, security, decentralization. And when we go back one step and think about GameFi, UX is still a great gameplay, still the most important aspect in the whole GameFi space.
3:21 And then almost all Web3 games incredibly, unfortunately, fail at this. And we need to change that. So in comparison to all these oracles that we have now, as a different use case where we need to wait several transactions, minutes, hours, or even longer, depending on the sensitivity of the data, there might be the need at some point that you can actually request data on time within the same transaction.
3:55 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 some personal data that you have on your central as back end, want to have that within your NFT in an autonomous and trustless manner, as much as possible, right?
4:25 So what you can do now, you can have within your smart contract, you 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. As said, different use case than oracles.
4:50 And that’s what we’re going to do today. So basically, to give you some understanding how
Technical architecture
Watch this part · 4:575:02 that in general works, Boba is, as I said, a layer 2 solution. So what we basically did, we modified layer 2 Geth. 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 call and save both of them to layer 1, which is in our case Ethereum.
5:40 And that enables us to do that in the same transaction. So to give you some understanding, let me get that to the other screen to give you some understanding before you get shocked away by code. The whole Turing landscape, which is, as I said, the old name for hybrid compute, you will see that now and then on some places because everyone who has ever run a company knows that replacing a name is unfortunately a really difficult task.
6:23 In general, we have three core components. Actually, it’s four. We have your own smart contract that triggers the API call. Makes sense, right? Then we have your back end itself that understands or needs to understand some way that needs to understand what kind of information you are sending from your smart contract to the back end because it will be or needs to be ABI encoded.
6:55 It just can’t be plain text or something like that. And the same way all the way around. If you return data from your back end to the smart contract, it also needs to be in an understandable format. And now we are coming to two other smart contracts
Core components overview
Watch this part · 7:097:12 that we might need to know or think about. And that’s on one hand, the so-called Turing helper or hybrid compute helper, as you wish, and the Turing credit. And both of them have a really close interplay. One of them, the Turing helper, is a smart contract that every project needs to deploy themselves.
7:38 That contract basically is nothing else than your personal, let’s say, key to your backend. Let’s put it that way. And the Turing Credit contract basically keeps track of your Turing helper, your smart contract. But why am I saying this? As with every oracle, you need to pay for each transaction.
8:05 For each API call, you need to make a small deposit. In our case, it’s a prepay. So you need to prepay your, if you basically deploy your project, you need to prepay the amount of Boba tokens that you want to fund in advance so that your users can actually trigger those smart contract functions.
8:31 So every time you call your smart contract, there will be 0.01 Boba token which is around a few cents currently deducted from your prepaid balance. And the Turing credit contract is deployed by us, the Boba team, which keeps track of your balance basically and the Turing helper contract is some kind of authorization, right?
9:02 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. I want to show you a little bit.
9:26 What you
Hands-on implementation
Watch this part · 9:209:27 see here is really a quite minimalistic example that I want to implement with you today. And what it basically does, it calculates the time dilation 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.
9:57 And that’s why I chose that for today. If you want to do that with me, I have prepared a starter repository that I would ask you to clone, then we could actually do that. Basically, it’s on our official organization. And it’s called hybrid compute underscore tutorial.
10:28 That default branch is already the one that you can use to implement that with me today. and yeah there’s basically everything is already set up and we will go through every step that it’s actually needed to perform your Turing call. To give you first insights on what we are talking about at all I want to show you how does such a API call actually look like?
11:06 The most... Let me look here. That’s a more beautiful example. You can see it here. Basically, it’s really just a one-liner. You can actually call your smart contract by calling a method on the so-called Turing helper.
11:33 As I said, your project needs to deploy themselves. But you don’t need to change a single line there. It’s really just fully prepared, already ready to deploy a smart contract that you can use. You just need to actually keep track of your balance. To get back to the repository, to give you a little bit of overview, we have said we have a couple of components here.
12:08 We have our own custom smart contract that we will implement today. We have our so-called Turing 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.
12:42 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 Turing random function which gives you a super strong pseudo random number directly from layer 2 Geth. And we have the so-called Turing Tx function where you can call any endpoint with any call data you want.
13:12 That’s where you can actually do your off-chain calculations or call further APIs, such as Twitter or whatever. 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 that understands the data you’re sending to and data that you’re returning from.
13:44 In our case, we just used 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 the API encoded data and encodes the result as well. So nothing super complicated or magic here.
14:13 But as said that’s already deployed. So if you have cloned that for yourself, what you can do
Setting up the environment
Watch this part · 14:1614:22 now is as always if we deploy on testnet we will need some kind of testnet tokens. Otherwise it’s going to be hard to actually deploy anything. We have a nice little faucet for that on our gateway. You can find it if you type on the search bar gateway [unclear].boba.network and as you can imagine right now that’s the faucet basically this faucet itself actually uses hybrid compute itself.
15:06 What it does is it asks you to copy your so-called Boba tag which is nothing else than the Boba prefix with md5 hash of your public key and post that on Twitter, just like I did here.
15:36 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 Twitter API and checks if you have posted that and then sends you the Boba and [unclear]. So that’s what you would need to follow the workshop today.
16:08 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. For that very same reason, I wrote a simple test that actually checks if you did it right.
16:39 So nothing to be done here. But basically, what this test does is it returns, it checks the event that I’m emitting in the smart contract, which we need to do. Right now it’s undefined, undeclared variable. And then basically it just checks if the value within the event is the one that we are expecting to.
17:15 And yeah, small hint, not to confuse it 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, the floating number with one trillion. And here I’m just dividing it back to a value that makes sense.
17:41 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. We’re very close 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 as a person actually feel like it is.
18:11 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 basically the speed of your aircraft stretches the time is true. So let’s get hands on.
Integrating the logic
Watch this part · 18:3018:31 I have prepared some setters on top here which you don’t necessarily need. 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. That’s the contract that we need to deploy ourselves. That’s the one that we had a look at before, right?
19:00 Run with the error codes and with the Turing TX function, with the Turing random function, and so on. So that’s basically just deployed by us. 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.
19:28 The second would be, what’s your actual back end? What’s your actual back end 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 tests. If you look here, it’s on top. It’s here.
19:56 That’s already live. 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 a one-liner, but I want to make it simple.
20:31 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 a bytes value. I’m just calling it right now params and we basically just encode our two parameters that we get from this function.
21:13 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 an understandable format. So the next thing that we need to do is to actually do our synchronous API request. So that works in a quite similar way with the TuringTx method that we saw before.
21:50 What we get from the API itself is again a bytes value. So it’s really, 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 REST B for now. I know that’s not best practice. And now our so-called hybrid compute helper comes into play.
22:21 And we see now that we have our Turing TX and Turing random function that we can use. The Turing TX function basically, let me see if we see that even here, yeah. Requests that we send the URL, that’s our HC endpoint in this case. Just a regular string.
22:48 And our already encoded parameters, the ones above. That’s it basically. That simple line sends an 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.
23:14 I want to have some kind of proper value, right? I want to have a number, I want to have a string, whatsoever. Now it would be great if you know what your backend returns, right? Otherwise you get some random value out of it. In our case, I know that it’s an integer value. So what I’m doing now is defining that the first value of my tuple is just a number.
23:44 And I decode the usb value that we just got into uint. It’s always great to develop onto this place.
24:09 So that should be it. 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, as said, I hope I didn’t confuse you too much. It’s always a little bit difficult to go from zero to 100, but basically this enables you to do a lot of crazy new things.
24:38 Things that you couldn’t do that easily before, but everything is possible right now. We have oracles, we [unclear] do everything. But we all know, we all went through callback hell in Web2. And it also can exist in Web3. As said, Chainlink, UMA, all oracles are great. They have the use case.
25:03 This is a different one. So now I’m going to do the most risky part of my presentation.
Testing and deployment
Watch this part · 25:0725:11 I’m trying to run the tests. Let me see if everything works. So what these tests now do, they basically deploy our Turing helper. Let me show you. They deploy Turing helper here.
25:38 I said it’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, as said, 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 my Turing helper, my endpoint, for which smart contract I’m willing to pay for.
26:19 Otherwise, as I said, I could deploy a smart contract and one of you needs to pay for it. Wouldn’t be so cool. That’s this line, basically a white listing to protect your funds. When we are talking about funds, we also need to basically fund, fund the Turing credit contract, which keeps track over your funds by actually knowing your Turing helper contract address.
26:51 Because your Turing 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 Turing Credit contract and the rest is just some basic checking if we get the correct address back and so on.
27:20 So that’s basically it. I’m super happy that this works and I hope you learned something. Maybe you 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. If there are any questions, I’m happy to answer. Thank you.