Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 399
docs: change zkquiz questions guide#1206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
98b6ea8
docs: change zkquiz questions guide
avilagaston9 8a5463a
fix: typo
avilagaston9 37a3c1f
Update docs/3_guides/2.2_modify_zkquiz_questions.md
avilagaston9 1133894
Update docs/3_guides/2.2_modify_zkquiz_questions.md
avilagaston9 b8c707f
refactor: add explanation of how to get sha3 hash
avilagaston9 6d79688
refactor: add make target to compile the ELF
avilagaston9 f199abd
fix: conflicts
avilagaston9 ef87016
fix: conflicts
avilagaston9 cbfa1c0
refactor: add the new section as a submodule
avilagaston9 5754753
fix: use 4 spaces when tabulating
avilagaston9 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| # Modify ZkQuiz Questions | ||
| 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. | ||
| In this guide, we will show you how to replace those questions with your own custom ones. | ||
| {% hint style="warning" %} | ||
| This guide assumes you have already read [Build your first Aligned Application](2_build_your_first_aligned_application.md) | ||
| {% endhint %} | ||
| ## 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: | ||
| ```Rust | ||
| let mut user_answers = "".to_string(); | ||
| let question1 = "What is the capital of France?"; | ||
| let answers1 = ["Berlin", "Paris", "Madrid"]; | ||
| user_answers.push(ask_question(question1, &answers1)); | ||
| let question2 = "What is the chemical symbol for gold?"; | ||
| let answers2 = ["Au", "Ag", "Fe"]; | ||
| user_answers.push(ask_question(question2, &answers2)); | ||
| let question3 = "What is the native cryptocurrency of Ethereum?"; | ||
| let answers3 = ["Bitcoin", "Ether", "Litecoin"]; | ||
| user_answers.push(ask_question(question3, &answers3)); | ||
| ``` | ||
| ## 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](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. | ||
| If we concatenate the correct answers to the questions above, we get `bab`, so we need to calculate the SHA3-256 hash of that: | ||
| ``` | ||
| SHA3-256(bab) | ||
| ``` | ||
| 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: | ||
| ```python | ||
| import hashlib | ||
| correct_answers = "bab" | ||
| # Calculate SHA3-256 hash | ||
| hash_object = hashlib.sha3_256(correct_answers.encode()) | ||
| # Get the hash as a list of integers (byte values) | ||
| hash_bytes = list(hash_object.digest()) | ||
| print(hash_bytes) | ||
| ``` | ||
| After executing the script, we get: | ||
| ```python | ||
| [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] | ||
| ``` | ||
| Now we can update it in `examples/zkquiz/quiz/program/src/main.rs` as follows: | ||
| ```Rust | ||
| if output | ||
| != [ | ||
| 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, | ||
| ] | ||
| { | ||
| panic!("Answers do not match"); | ||
| } | ||
| ``` | ||
| ## 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](https://docs.succinct.xyz/introduction.html) is installed. Run: | ||
| ``` | ||
| make compile_elf | ||
| ``` | ||
| 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](2_build_your_first_aligned_application.md) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.