How to Build Data Driven dApp with Brevis ZK Coprocessor - ETHGlobal Bangkok 2024
ETHGlobal·Thu, Oct 9, 2025, 12:00 AM
Join us for a workshop with Michael Dong from Brevis titled, "How to Build Data-driven dApp with Brevis ZK Coprocessor." Brevis is a smart ZK Coprocessor that empowers smart contracts to read the full historical on-chain data from any chain and run customizable computations on top at low cost, enabling data-driven dApp UX. We will introduce Brevis SDK, along with how developers can use Brevis SDK to build data-driven dApps. We’ll also share some reference cases. No ZK knowledge is needed. This workshops took place at ETHGlobal Bangkok, a 3-day hackathon held November 15 to 17 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: https://x.com/ethglobal Check us out: https://ethglobal.com/ Email us at: hello@ethglobal.com
Transcript
all right so I guess we can start um wow okay all right hi uh this everyone this is and before we dive into the details of the apis and sdks just want to give you everyone a quick introduction of brevis as a whole so brevis is a Smart offchain verifiable Computing flat platform what do I mean by that is that it is fundamentally a scaling solution so basically you know we have a very limited uh computation capability on blockchain tell you like some examples you can actually use previs to offload this computation to an offchain environment in that offchain environment you can run another computation but not only just the computation itself but also generate a ZK proof of that computation result and we you can then submit both the proof and the computation result back to the blockchain where you can actually simply and cheaply very verify the computation result most of the computation happens but instead it becomes a glue point of verifiable computation resources what this means is that you can actually expand and scale blockchain computation to an infinite level because in fact you can actually itself is a single threaded computer that can only run one application at a time there's no way to parallel processing this and uh we build something called a ZK Co processor as our as our as our first Flagship product so ZK co-processor allows your smart contract to have access to historical onchain data such as event transactions and build using breev one good example is intelligent defi where you can dynamically change the protocol parameters of defi projects for example you can actually run a fee trading volume based fee discount by allowing user to prove on you know incubator programs with Unis swap foundation and Atrium to kind of demonstrate this you can just search online and see some of the examples building with this and you can also do consumer facing applications for example we partner with Euro which is rising star in the stable token space and we power their token launch program so instead of one off airdrop now you can allow user to continuously generate proof of their interaction with the protocol and convert that into a quantitative Matrix where they can use type of a oneoff jrop so thing so this allows you to actually merge and align user incentives with um you know your protocol growth by having this continuous Evergreen program of token drops there are many other things you can do with the brev like pre-confirmation you can essentially um you know prove a 2d blockchain whether a certain blog producer have included your transaction or not in the past and you know you can do slashing and rewarding based on that but using provis uh you know SDK is quite simple you specify what kind of data you want to read what is the computation logic you want to run and finally you have your uh entire computation logic integrated in the smart about a very specific example of how you can build with brevis using a Unis swap V4 hook example but you can General that to other applications as well so Michael all right um thanks everyone for going to do a uh uh summarize the trading volume of a specific user on Unis Swap and uh I'm going to focus Less on the Unis swap V4 hook in this talk uh but more on the brav side of things so uh first of all let's look at how a bravis sa workflow looks like uh so as you can see we have multiple components and we have the uh app service the uh brevis service and the contract associate with it with the app and brevis uh so the first step uh is pretty standard uh you just like use any sort of index or you can just build your own to get the uh blockchain data uh like the historical blockchain data from uh from onchain so basically like use say like the graph or use your own like eum RPC node to create the ethereum blockchain and then you feed all those data to the app service which uh like in the uh rectangular Brew box that you built and um like all those data gets fed into the app circuit which is also like one of the components uh you guys will build and then once you have all those uh data and processed by the circuit like essentially you generate a u like your part of the proof and then you send all those and then brevis is going to like combine the two to generate a uh the final ZK proof to be verified on the brevis contract for the any sort of like post-processing Logic for example like in the UN swap case uh like as soon as you can you get a sum of all the trading volume for the user in the past 30 days you can like assign the user a VIP status based on their trading volume and with Unis swof V4 hook you can like uh lower the uh like transaction fee or lower the swap fee for for that particular user which is quite useful so this is essentially a a simplifi version of uh what I just talked about and uh in this case like we we provide the uh typescript SDK or the or go SDK whichever you prefer and you implement the U uh approver service which we have a template for and you don't have to like write any code essentially and you just to submit your uh proof which like you guys will implement the app circuit which we also have very extensive example okay so uh I think this is based on our typescript SDK we also provide a go DEC as I said and you can pick connection to the uh app prover which was the U the top like blue box and we have a template for and you don't have to actually worry about uh implementing that so like once you establish a connection you uh like instantiate a new proof request and you're going to fill in all the data so in this case um we're going to we're looking at Unis swap swap events right so and for us we only care about it's being a um Unis swap um I think this is from a usdc to AUM to etherum I believe and um in this case like uh it's a little bit technical but you can see that you provide a transaction Hash a swap event and one of them is from the actual um usdc transfer event and the uh the the the data we care about is uh amount zero which is I believe the uh usdc amount and also the the recipient so that we can verify this is the unit swap because they have the uh the way their like router contract set up I think either sender I think actually re recipient is supposed to be the unit swap router and with all those uh we start writing the circuit so that was the the the providing the data part and this is done if you're using typescript this is going to be done in typescript and the actual circuit we still have to use Goan and um it's not too intimidating it's a like pretty simp object is going to um go and you have the allocate and and in this case you you don't need any storage or any transactions you just need the receipts and you can like specify a max number of receipts I'm not going to go into too much um detail like how you're going to use our SDK to to like execute the logic so um like how many of you guys know like map produ basic functions to calculate minimums or calculate sums for like the common I guess statistics use cases but you can also use the for Loops if you choose to um if that makes things easier as well so in this case we first do a map over all the receipts and extract the block number users volume in the past uh month right so we kind of need the minimum block number and also verify that it's like from the past month and for and very simple to uh to implement and once we have the computation done we have um we need to Output the results so that the um the arching contract can make use of it to S like as design VIP status or like give our reward whatever volume and we also need the minimum block number for the onchain verification and we also need to Output the actual user address to make sure it is for that particular user and this is the uh aching contract part of the uh bravis application in in like you require VK hash equals VK hash this is more like technical detail but you can just copy it the idea is that every every brav circuit is going to that this is the correct circuit um because otherwise you can like have some other logic which doesn't match the actual circuit and that would not that will be I'll present in the next slide and in this case like we we don't actually do anything with the output we just emit a trading volume test it but in reality you can just do whatever like you can uh attach you like put all that in a uniso V4 hook so you can like lower the trading fee for the user and this is the actual Deco logic which uh it's little bit intimidating but it's actually quite simple if you just read through it um you basically you match whatever the circuit has like in the comment section you see all those uh API dot So you you're essentially just extracting different bits or like bytes from the uh output and you like return that and here are a few links that can help you get started uh we have a pretty extensive documentation and examples so just go to docs. br. network or check out either one of the to sdks whichever language you prefer and okay question one uh this as I see this is something like a CK as a service but you hidden transactions or hidden data that people shouldn't be able to see yeah uh that's a good question so yeah as you said so in this particular use case right there isn't any like there isn't too much privacy I should say but well like whatever we output is like whatever we care about on chain right so in this case you don't actually have to like publish the uh all the uh individual swaps on chain kind of like aate the actual like swap events and you can still only output these ATT tested like volume as well as the user address okay but they don't have to be public I guess is maybe that's what what you're asking so yeah there is some privacy nature to it but you can make it more private by uh okay I think if not um we can just uh check out those links and uh start hacking and if have any questions just come by our boost and we'll be happy to answer
Automatic transcript — names and jargon may be misspelled.