Skip to content

Commit 5143a3e

Browse files
authored
Merge testnet 14 oct (#1248)
2 parents ae8d8f3 + ab37cfc commit 5143a3e

File tree

4 files changed

+94
-1
lines changed

4 files changed

+94
-1
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Modify ZkQuiz Questions
2+
3+
In [Build your first Aligned Application](2_build_your_first_aligned_application.md), 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.
4+
5+
In this guide, we will show you how to replace those questions with your own custom ones.
6+
7+
{% hint style="warning" %}
8+
This guide assumes you have already read [Build your first Aligned Application](2_build_your_first_aligned_application.md)
9+
{% endhint %}
10+
11+
## 1. Modify the Questions Asked
12+
13+
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:
14+
15+
```Rust
16+
let mut user_answers = "".to_string();
17+
18+
let question1 = "What is the capital of France?";
19+
let answers1 = ["Berlin", "Paris", "Madrid"];
20+
user_answers.push(ask_question(question1, &answers1));
21+
22+
let question2 = "What is the chemical symbol for gold?";
23+
let answers2 = ["Au", "Ag", "Fe"];
24+
user_answers.push(ask_question(question2, &answers2));
25+
26+
let question3 = "What is the native cryptocurrency of Ethereum?";
27+
let answers3 = ["Bitcoin", "Ether", "Litecoin"];
28+
user_answers.push(ask_question(question3, &answers3));
29+
```
30+
31+
## 2. Update the Program
32+
33+
Next, we need to update the program to be proven with the new correct answers. As described in [Build your first Aligned Application](2_build_your_first_aligned_application.md), 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.
34+
35+
If we concatenate the correct answers to the questions above, we get `bab`, so we need to calculate the SHA3-256 hash of that:
36+
37+
```
38+
SHA3-256(bab)
39+
```
40+
41+
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:
42+
```python
43+
import hashlib
44+
45+
correct_answers = "bab"
46+
47+
# Calculate SHA3-256 hash
48+
hash_object = hashlib.sha3_256(correct_answers.encode())
49+
50+
# Get the hash as a list of integers (byte values)
51+
hash_bytes = list(hash_object.digest())
52+
53+
print(hash_bytes)
54+
```
55+
56+
After executing the script, we get:
57+
```python
58+
[216, 11, 193, 177, 136, 178, 254, 150, 59, 128, 97, 103, 97, 128, 55, 57, 22, 242, 26, 1, 186, 223, 215, 118, 206, 47, 12, 206, 114, 118, 220, 93]
59+
```
60+
61+
Now we can update it in `examples/zkquiz/quiz/program/src/main.rs` as follows:
62+
63+
```Rust
64+
if output
65+
!= [
66+
216, 11, 193, 177, 136, 178, 254, 150, 59, 128, 97, 103, 97, 128, 55, 57, 22, 242, 26,
67+
1, 186, 223, 215, 118, 206, 47, 12, 206, 114, 118, 220, 93,
68+
]
69+
{
70+
panic!("Answers do not match");
71+
}
72+
```
73+
74+
## 3. Compile the Program
75+
76+
Now we need to compile the updated Program, generating the binary file that will be run by the zkVM (ELF).
77+
For this, ensure that the [SP1 Rust toolchain](https://docs.succinct.xyz/introduction.html) is installed. Run:
78+
79+
```
80+
make compile_elf
81+
```
82+
83+
which will output the compiled ELF to the file program/elf/riscv32im-succinct-zkvm-elf.
84+
85+
## 4. Run the new ZkQuiz
86+
87+
We are ready to run our new version of ZkQuiz.
88+
89+
To do this, follow the same instructions as in the original [Build your first Aligned Application](2_build_your_first_aligned_application.md)

docs/3_guides/2_build_your_first_aligned_application.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ pub fn main() {
132132
}
133133
```
134134

135-
The program takes the user answers as inputs and checks that the hash of the inputs matches with the expected output. This is the program that will be compiled generati ng a binary file that will be ran by the zkVm and used later in the application side. In our case this file is already generated and is located on `/quiz/program/elf/riscv32im-succinct-zkvm-elf`.
135+
The program takes the user answers as inputs and checks that the hash of the inputs matches with the expected output. This is the program that will be compiled generating a binary file that will be ran by the zkVm and used later in the application side. In our case this file is already generated and is located on `/quiz/program/elf/riscv32im-succinct-zkvm-elf`.
136136

137137
### Verifier Contract
138138

docs/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
* [Submitting proofs](3_guides/0_submitting_proofs.md)
2727
* [Build your first Aligned Application](3_guides/2_build_your_first_aligned_application.md)
28+
* [Modify ZkQuiz Questions](3_guides/2.2_modify_zkquiz_questions.md)
2829
* [Validating public input](3_guides/3_validating_public_input.md)
2930
* [SDK Intro](3_guides/1_SDK_how_to.md)
3031
* [SDK API Reference](3_guides/1.2_SDK_api_reference.md)

examples/zkquiz/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ answer_quiz_local:
2020
--batcher-url ws://localhost:8080 \
2121
--network devnet \
2222
--verifier-contract-address $(CONTRACT_ADDRESS)
23+
24+
compile_elf:
25+
cd quiz/program && cargo prove build

0 commit comments

Comments
 (0)