# Building lots of onchain stuff that is interesting by Small Brain | Devcon SEA

- Speakers: [Small Brain](https://streameth.org/speakers/small-brain)
- Channel: [Devcon](https://streameth.org/devcon)
- Date: 2025-10-09
- Duration: 25:48
- Topics: Science & Technology
- Watch: https://streameth.org/watch/yt-r3TycwvFcdQ
- YouTube: https://www.youtube.com/watch?v=r3TycwvFcdQ

## Description

For the past 1.5 years, I've been building fully onchain games–games where the entire state is onchain for some reason (have launched 7!). 

In this talk, I will share some of my lessons and learning from them.

Speaker(s): Small Brain
Skill level: Intermediate
Track: [CLS] MUD Community-Led Session, by 0xPARC
Keywords: Gaming, Autonomous World, application

Follow us: https://twitter.com/efdevcon, https://twitter.com/ethereum, https://warpcast.com/devcon
Learn more about devcon: https://www.devcon.org/
Learn more about ethereum: https://ethereum.org/ 

Visit the https://archive.devcon.org/ to gain access to the entire library of Devcon talks with the ease of filtering, playlists, personalized suggestions, decentralized access on Swarm, IPFS and more.

Devcon is the Ethereum conference for developers, researchers, thinkers, and makers. 
Devcon SEA was held in Bangkok, Thailand on Nov 12 - Nov 15, 2024.
Devcon is organized and presented by the Ethereum Foundation. To find out more, please visit https://ethereum.foundation/

## Transcript

[Music] hey everyone Hey Okay cool so for this talk I I've given a couple of talks of Devcon and if you listen to my one on Monday you heard some of the crazy weird ideas in my notebook if you listen to the one yesterday you heard about end to end internet games and a couple of new technologies that I think could enable a bunch of insane new uh uh consumer crypto apps um but today I figured for mud day and because this is a classroom we do something a little bit different and I take it in a different direction I figured that today what would be most interesting and useful to like probably this group of people would be if I just went through a couple of kind of hard SL interesting technical challenges I faced uh building random stuff over the past like year and better people can hear me well yeah yeah I figured I'd go through a couple of technical challenges I faced building stuff over the past year um and talk through some problems and what they were and and what I did to fix them and so with that the talk is called what three things from building stuff by small brain and so what we're going to do because this is a classroom is we're going to play a game and the game is is called you smarter than small brain and how it's going to work is I'm going to propose to you one problem that I ran into and and just like for some poetry it's it's really fun that these problems problems exist because the things I build are really simple right like it's not like you're trying to cure cancer and you have a hard math problem it's like you're trying to get people to yell at each other over the internet and you have a math hard math problem um and there some some of there be math problems some they going be like solidity questions and we have very smart people in this room like Dr J and Mr indexer and Paco and David and Frolic and you know our German friend in the back and so maybe this is going to be really lame and you guys are going to get the answers really quickly but hope what's going to happen is you're going to struggle a little bit then get the answer and then it'll be interesting but please participate okay question number one we're going to start easy and we're going to go to harder so question number one is is you is what I want to do is I want to put some money on ethereum in a smart contract and then I want to have a password that I give to somebody and I want anybody with this password to be able to unlock the funds it's like a really really simple like like escrow smart contract I put some money in a smart contract I have a password and then I give this password to somebody and they can unlock the funds how do you do it and while I give you a little bit of time to think um this was useful okay okay amazing what this was useful for for an app I built called yon um which was an app where you can send people voice memos with a little bit of payment attached and if they don't listen to your voice memo in time face ID no headphones um they won't get the money and the longer they wait the less they get um and and and it was used in this app to do invite links so if we have this primitive we can actually send people who don't have wallets yet an invite link with a yon in it but anyways getting back to the question yeah does any one of you want to jump in you want to use your mic yeah what do you think yeah so mine is kind of a Brute Force but what you do is you hash the secret yeah you put it on chain and in order to prove that you the secret you make a simple zkp that you know the pre-image of the hash but it's kind of Brute Force I don't know if it's the best way to do it no no I I think that totally works and I think this is actually a valid solution the solution makes sense to people in the room and and Justin can you explain why it needs to be a zkp yeah so okay so do you guys know what a hash is like you take some some value you can turn into a hash but you can't go from the hash and turn it back into the value so if you put the hash of the password on the blockchain you commit to the password but people cannot recover the password from the hash and now your problem is can someone show that they know the thing behind the hash without revealing to everybody else so if you were to just put the password in a transaction and be like look look blockchain if you hash my password you can get you you you'll get the hash the issue is people can front run you and like see it in the m poool and front run you so what you do instead you make a zero knowledge proof that that you know the preimage of the hash yes so that's exactly right and and I think what's interesting here is this is the solution I also initially came up with and then I was sitting in my room like 4 days before E Denver like you know trying to write circom and being very sad and like I felt in my heart that there had to be a better solution and there actually was Ryan do you have a different was your solution different that it was that one okay yes uh here I'll run over to you with the mic you make a new hash from the uh the address of the sender with the the password okay oh no no never mind that's not going to work okay never mind well well I I think there's something interesting there all right are we ready for the answer to be revealed or does anybody have it okay cool um this is how it works I'm so excited about this one because this is like one of the most elegant pieces of like real world like simple cryptography I've seen um all right so the first thing you do is you generate a new key pair and we are going to call so like a private key and a public key pretty much a new wallet and we're going to call this key an ephemeral wallet okay because like we're just going to use it to make this happen and we're going to throw it away pretty quickly afterward right so the big insight and some of you might be seeing the whole punchline now is oh oh oh is that the the private key from this key pair is going to be the password that we give to people um and so what you do is you Escrow in the smart contract the money you want to put in and the public key associated with that ephemeral wallet then what you do is you take the private key which is the password and you give the password to somebody else you give the private key to somebody else when they want to unlock the payment what they do is they take their own address their own actual address and sign it with the the the private and public key pair from the ephemeral wallet and then they can use that signature to claim the funds on on chain because the smart contract on chain just does a signature check to see that okay cool the person with the password said that this wallet should have the money so we should give them the money and this prevents like front run and all of the problems that the zkp was solving because you are signing exactly which address should get the Mayo yeah so so the signature is a zp like a signature is a zero proof it's not a zik snark so we went too far on the on the on the on the heaviness of the solution that's actually a better way way to think about it it's exactly the same solution but a much smaller proof that shows exactly what you need to versus like you know writing something in cop um this solution not credited to me actually it was deep in the doo code because Doo uses exactly the same thing for invite links so you know big shout out to DC and Nan for doing like extremely elegant piece of piece of cryptography um to do invite links onchain so this is a little trick for fully onchain invite links okay cool little breath um let's move on to question number two which I end up looking at it is a little bit of a mouthful but let me take you through the question and then you can like throw out what what you think will be a good answer to me okay this is the problem and you need to do this again on a blockchain um there's a round all right and the round and during the round people are posting vectors to the chain vectors is like like a long sequence of numbers so a bunch of players are posting vectors to a blockchain during a round and then at some time it's the end of the round at the end of the round an oracle comes and puts another Vector on chain and this is the truth vector and let's say like the players are like me Justin Elena Frolic Ryan Etc what we want at the end is we want the sum of the distance between the Oracle and Justin vectors and the Oracle and elen's vectors and the Oracle and Frolic vectors Etc we want the sum the distances between the truth vector and the players vectors um does does that make sense cool okay any ideas on how you can efficiently calculate this all right I need to give you a second to think while I give you context that's the pattern so don't jump in just yet um oh and the formula we're using for distance between vectors actually we can use anything reasonable we can literally just use ukan distance um but but another valid formula which is a nice little hint for this question is cosine distance which is uh the dot product of the two vectors over the magnitude of the two vectors all right sweet anyways the context for this is uh this app called tomorrow. newws which is a prediction market for tomorrow's New York Times headline and that's TMR do that pays people out based on how close and meaning they are to the truth and we use sentence embeddings to do this so sentence embeddings are a way to turn a sentence into a vector and when two vectors are close to each other when two sentences are close to each other in meaning the vectors are close to each other in distance so we can actually use this to build a prediction Mark Market that's semantic anyways back to the problem um how do you do how do you do this nicely on chain what were you going to say oh I mean I don't have a full answer but but one thing I'm wondering if it's useful is to uh consider the truth Vector to be zero okay so we and then we shift Thing by the truth ve I mean okay so as a first kind of like start just assume truth Vector is zero and then we're going to have to reshift everything that should make a bunch of the distance stuff much simpler at least conceptu uh so this is what I thought too but but it actually doesn't because the truth Vector could end up anywhere and distance from zero is the vector itself okay so it kind of keeps everything exactly the same in your example all right any other thoughts all right should I ruin it give us a hint um the the hint is you have to stare well so do we understand like the core problem with this like I guess a question somebody should ask is like why don't we just sum the distances at the end yeah are you assuming that you don't want to have an O of n exactly because we're on a block I kind of expected somebody to say it and then I would be like no but why we can't just sum the distances at the end is because there might be end play players and then we need to do like you know on the order of end computations it might brick the game unless there's batching so you want a constant time solution we want a constant time solution to this problem all right I'll give it to you can it be an incremental solution what does that mean well every time someone adds a vector they do an incremental amount of computation okay so it would still be o of n it's just you don't pay it in one go at the end exactly great but you don't have the truth Vector until the very end uh is is another hint that is done pairwise what what do you mean by that well you always do it with respect to the previous Vector um I will give you a hint that you just increment one big value as you go on yes yes oh amazing thank you oh thanks uh I wonder if this expression can be factorized yeah how did you factor it uh I see there is the dot product I'm I'm not sure about if the dot product can be factorized but I that you can keep the ones on the side sum the the the factor and then do the operation on the sum that's it that's exactly it oh my God I'm so happy the computer is gone yeah yeah it's coming back um okay cool that's exactly it what's your name bash great job um that's literally what you do so here are all your uh you know these things you need to sum these are everybody's guesses like this is somebody's guess this is somebody's guess this is somebody's guess if you stare at this long enough you're like B over magnitude of B is is the the truth Vector over the magnitude of the truth vector and that's like a common factor in all of these terms so you can just like pull that baby out and also all the ones you can just like you know pull out to the side of the sum and then this thing starts looking like sorry I didn't math script but it starts looking like you know n which is all the ones that you pulled out uh minus the the common factor times like the sum of other stuff and so all you do is you keep track of the of other stuff as people are making their votes and you do a nice little multiplication at the end and you're you're all very happy the problem with this really is that like what we ended up needing to do is we ended up needing to square everything or actually raise anything to a power we wanted to decide because the distances weren't like crazy enough and so the market was like kind of boring and like fundamentally now like this kind of sucks because you can expand this out actually you can use ukan distance here and then because there's a squared and a square root route it like you know ends up being kind of nice but you still can't do it um because high level what you did is you like added nonlinearities to a thing which we were like it was really nice that it happened to be linear um and so to do this there's two things that we aligned on one was you could do a zkp using something like sp1 right to like succinctly verify the sum on chain later and compute it offchain um but it turns out that like the cost of doing that on their approver network is actually more than the cost of literally just Los onchain and doing the sum because the vectors were of such high dimension and so we actually did end up doing the stupidest thing which was looping on chain great all right um okay third question um third question is a really open-ended question and there's not like a a a correct answer to this one um but what it is is I guess first is like are are people here familiar with words three all right like maybe maybe like a fourth of you so I'll go over just the part of the game you need to know to to motivate this question uh words 3 is a game where you're playing Scrabble on chain on like an infinite grid and you have to buy in letters to play and the price of buying letters changes with some formula that formula used to be a VR GDA um that's how that's how the game of the game looked it's a bunch of people playing letters and then letters are on different price curves um the the letters the pricing curve of letters used to be a VR GDA with Target rates per letter set set based on the Rarity of the letter um what that mean what a VR GDA tries to do like kind of reductively is sell a certain amount of things at a certain so might be trying to sell one letter per day at a certain price and if letters are going faster than that rate it rises the price Rises exponentially if letters are going slow slower than that rate the price Falls logistically and so you know you kind of like push use prices to push the rate at which your items are sold to the rate you want the issue with VR gdas was it broke it had two pretty bad properties um both related to memory one thing is like it doesn't sustain a lot of players playing at once because prices Sky really fast and they never come back down and it kind of pushes people out from playing you know going way too fast from the target rate that price is rising exponentially now there are a bunch of people who want to play and they can't the second bad thing is if nobody plays for a really long time prices stay depressed for a really long time because you're like so far off from the target rate that like you're if if if nobody plays for a week and then then people start playing you're so far off from the target rate and you should have sold so much stuff in that time um that you know the price is always going to end up being zero what we want is we want some sort of new pricing function where that allows players to like enter at any time and also like if the game is no activity for a long time does doesn't brick it still maintains that it's fun to play um and so the the open question is like what is a better way to price these letters yes reset daily like don't have like an infinite window have like a floating window for the for the same formula yeah yeah I think that's a very valid answer you could reset the thing daily so it just kind of works oh my god did I knock water over um you could reset the thing daily so so it just kind of works I think I think like I I I I think that's a valid solution I think like my brain personally just like doesn't like it cuz it's like kind of inelegant you can do a rolling window yeah so how I think this is what he was suggesting okay yeah okay okay so you limit the memory of the thing to just the past day yeah yeah and you roll so there's no discontinuity you just roll yeah I I I think that would work actually quite like that get an investment from Paradigm and then they can think about a new yeah exactly they write a new blog post yeah yeah totally any other thoughts this one this one there's lots of valid answers too well yeah what is it um what if um so basically buying other letters affect all the other letters so like you know if there was a lot of A's they keep growing in price but as soon as somebody bought a single b a single c a single D you just see that the part of the ace among of the all the letters in the game diminishes and so the price goes down so then you might not even need a rolling window you just uh like a match every letter against the to total number of all the other letters yeah I I I think that's another good idea and I think like specifically what's going on in that idea and I might have misunderstood you but specifically the underlying thing that's going on in that idea that fixes our problem is like you shifted your notion of time time from actual time to like players buying things like one tick is not like one second it is like one buy and so if there's a bunch of inactivity the game actually doesn't even feel it it's just like it started off when the next player buys something wait but isn't it circularly defined because if you say I want to sell four letters per unit of time if your unit of time is amount of letters sold well it wouldn't work with the V GDA okay I see I see I see see okay yeah yeah I I agree it wouldn't work in that case like it's just always going to be on the line yeah it's just linear right yeah um okay I I have a minute left so I'll I'll give you what I ended up doing I don't think this one's the answer I think it's a answer what I ended up doing is like drawing this little uh drawing this little curve in Desmos and how this curve curve works I'll go point at the screen at this side this time how this little curve works is like this is time this is the price and whatever you buy it just like jumps a fixed amount of X on this curve do that make sense and so why this is really really nice is like and up here right like around $300 this line is straight up and so if like somebody buys at $300 the price is going to like sky like crazy and then and then Fall Down super fast and then like around here like the price is kind of never going to get lower than some amount of T than like what whatever this is I think like around ters like kind of no matter how long the game goes and so what you get is you get like really interesting gameplay in this area um if if the price starts getting pushed up like crazy because a ton of people are playing it like Falls really fast so that people can enter again and if the game's in active for a really long time it still stays somewhere down here and like can jump up the curve pretty fast do you bound it so it doesn't go too far on the right you still have to catch up by you still have the problem of VR GDA which is price has gone too low you have to catch up by buying a ton uh sorry it it didn't move forward by a fixed amount it moved forward by a percentage of how far back it had been okay it makes sense yeah um and it move it moves forward that's linear and the curve is exponential and so you get your difference um yeah good catch right but that's how this works and that's what ended up being deployed one really bad thing well I don't think it's bad but like one criticism of this curve was that like you can't really get letters above like $500 or $600 cuz like literally you can't buy that fast and so it kind of puts like it's like an upper bound on the price of like how high things can go um again which I thought was reasonable but but some people did not react well too anyways that's I hope you learned something this is me and the best way to contact me all right question time so small brain asked questions to you now you can ask questions to small brain you can have your revenge there's one question big brain amazing thank great thanks for your contribution um okay so you can either Poe the question by scanning the QR code or you can raise your hand we'll bring you a mic either works yeah yeah I'd say like the other two it's like really really not important better oh oh the question was how important is it for players to ask these formulas to understand these formulas um specifically the last one uh but so I think like the first two it's actually like really not important for players to understand understand like how how this is done it's like honestly an implementation detail that like makes the thing work on chain for this last one we still didn't really want players to like want like I don't think we like yeah I didn't like want players to have to understand it the idea should just be like you jump in and you buy and you see prices going up and you like they kind of feel the curve um but I think like if you want if you're like a words three power player which they're definitely were you know you you go in and you understand how the curve and the math behind the curve works and that one 's like and I think like if you have a strong understanding of how the curve works it does give you an an advantage in the game in the last case yeah that's another thing too is like there's lots of complicated constructions that are better like you also want your construction to be like as simple as possible for the reason and so you know trade-offs yeah um we have two questions that have to do with past projects yeah so one is what is the next plan plan for Network State and then the other one is what's happening with wor wor three in terms of users currently yeah both are good questions I think words three in terms of users currently is I think they're like two it's not much uh and like words three tend tended have like a bunch of activity the first couple of weeks and then kind of petered out I think like it will come back like there's like clear things to fix um I think like one thing I'm focusing on the next time it has to come back like you know there's like I feel like there's thousand people in crypto who are like excited about the things I make and play them actively I has to be really clear to me how like a larger audience past those people like can get excited and be pulled into it and I think like until I figured those problems out there's there's not going to be a big push to to relaunch it um yeah um one question which is from someone someone that joined late is is any of this stuff implemented yeah all of the stuff is implemented in open source on my GitHub in fact it's not only implemented it's like on mainnet and people have like spent on it and and played the thing so you know it's it's implemented all the way um one question that has received Coe few vote is what's your next project uh the next project is a talking duck which you like will grow up over a month and you can like Pat it on the head to influence its personality that's what it is and there's actually a question related to that which is when can I buy a talking dock uh now if you want to you can find me and like venmo me 30 bucks what about people that don't have venmo uh you can Dao me 30 bucks great um why are you called small brain it's a good question I I mean I think it started off as uh one it was funny David came up with up with the name by the way so big credit to David um I think it was because it was a couple of things I was searching for what to call like the the name that would launch all of these experiments I and one I wanted people to like not take it too seriously right and also like it was a little bit of like the first time I deployed something it was una audited I like tend to take security a lot more seriously now but I was like this was like my last this was like my audit it was like all right it was deploy play by like a small brain pfp like you can't get that mad at me if there's a bug in the contract um you know so that that was like maybe 50% of the reason why the rest of was that I just like really like the name and the and the logo yeah and small brain found a bunch of bunch of bugging mud as well so it's been kind of a massive bug Bounty uh someone is asking what's your demo Doo address what's my Dio address um I don't know if that I think it's like SBG I'll find just literally find me after and I'll confirm [Music] um okay no more questions digitally anyone has a question in the audience raise your hand and we'll bring you a mic nope all right thanks thanks another a round of applause thank you all right
