Checkout our latest Litepaper here:
https://mirror.xyz/hyperoracleblog.eth/FKvpIGI7fiuNr5rnTlFWAdxk4QCNFIR9rmqDPxWLc2w
As we approach EthCC, we were giving away one ticket to the lucky winner of our raffle.
At the same time, we realized that this was a great opportunity to show what a builder can do with Hyper Oracle.
In this post, we will demonstrate the full application flow that draws one raffle winner based on Hyper Oracle’s stack, featuring Ethereum smart contracts and Hyper Oracle zkGraph.
You can check out the source code and links shown in the explorer here: https://gist.github.com/fewwwww/472a08039680bf6c79d5379c8533a2fd.
In order for zkGraph to implement the random number generation computation, we need to first place the data on chain.
We start by developing a basic smart contract. The core component of the contract emits an event, containing the seed of the random number we have just entered.
We then deploy the contract directly to Ethereum mainnet (0x65747849E7033cd1da6bF5Aeb753460F61743B18). Once deployed, we seed the random number (in our case, we input the number of retweets) into the smart contract by calling a function on the smart contract.
This transaction emits the number we entered as event data. You can see the data of the event of the transaction we just sent in the blockchain explorer.
Since we now know the transaction hash of the event on the Ethereum chain, we need to write a handleEvent function in zkGraph to process the event data.
In our handleEvent code, there are three main sections:
Get the data from the blockchain event
Randomize the data
Output the randomized result
For data randomization, we add a layer of complexity by throwing today’s date and time into the mix. Throughout the zkGraph development process, developers are free to program more complex and sophisticated operations: indexing, automation, and even machine learning!
Take this example as a simple form of demonstration of what you can do with zkGraph. In the final stage, we deploy this zkGraph, make it executable, and generate zero-knowledge proofs!
Hyper Oracle's MVP is a straightforward studio for developers to write zkGraph code with libraries and deploy it, among other things.
For using the MVP, you can check out our MVP testing guide.
We paste the zkGraph code we just wrote into the code editor in the MVP, and enter the appropriate Source Contract Address, and Source Event Name on the right side.
Next, we use the code editor to generate the compiled WASM code and click "SET UP" to deploy it to our node.
After entering the correct transaction hash (the one we emitted the event with), we can perform the computation of zkGraph and generate a zero-knowledge proof for its computation!
We can see that we have arrived at the final winner of the drawing, which is the 9th member shown in the Output State data.
As the last step, we deploy an on-chain verifier smart contract to verify the zero-knowledge proofs. This is to attest the execution is correct and therefore the raffle output is drawn according to the code in the zkGraph.
This is the entire process of building an application with Hyper Oracle and zkGraph.
In a real world example, the entire development process might be:
Simpler: Because you probably don't need to build a new smart contract or a new zkGraph, but rather take advantage of the blockchain and the ecosystem and open source nature of the Hyper Oracle network.
More complex: You can build more complex computations (including machine learning) without worrying about the security and integrity of the computation, because all computations can be flexibly generated with zero-knowledge proofs.
Start building zkGraph now!
We'd love to hear how you are currently automating smart contracts and what features you'd like to use. Therefore we have created a short dev survey to better understand your needs and how we can tailor our product to suit your requirements.
Follow us on Twitter and join our Discord to stay up to date with Hyper Oracle. Learn more about Hyper Oracle on our website.