Modify ZkQuiz Questions
In Build your first Aligned Application, we show how to build a trivia application, called ZkQuiz. ZKQuiz asks the user three questions, and if answered correctly, generates a ZK Proof of the correct answers, posts the proof on Aligned, and upon verification, mints an NFT via a smart contract.
In this guide, we will show you how to replace those questions with your own custom ones.
This guide assumes you have already read Build your first Aligned Application
1. Modify the Questions Asked
First, we need to modify the questions presented to the user. To do this, navigate to our example in examples/zkquiz/quiz/script/src/main.rs
and change the questions as needed. Here’s a new set of questions with their respective answers:
2. Update the Program
Next, we need to update the program to be proven with the new correct answers. As described in Build your first Aligned Application, the program in examples/zkquiz/quiz/program/src/main.rs
takes the user answers as inputs and checks that the SHA3-256 hash of these inputs matches the expected output. Therefore, we need to update the expected output with the hash of our new correct answers.
If we concatenate the correct answers to the questions above, we get bab
, so we need to calculate the SHA3-256 hash of that:
You can use any SHA3-256 Rust library or even online tools for this purpose. Here we provide a python script that calculates it for you:
After executing the script, we get:
Now we can update it in examples/zkquiz/quiz/program/src/main.rs
as follows:
3. Compile the Program
Now we need to compile the updated Program, generating the binary file that will be run by the zkVM (ELF). For this, ensure that the SP1 Rust toolchain is installed. Run:
which will output the compiled ELF to the file program/elf/riscv32im-succinct-zkvm-elf.
4. Run the new ZkQuiz
We are ready to run our new version of ZkQuiz.
To do this, follow the same instructions as in the original Build your first Aligned Application
Last updated