Skip to content

Commit 68634f4

Browse files
refactor (zkquiz): use aligned sdk (#554)
Co-authored-by: Mariano A. Nicolini <mariano.nicolini.91@gmail.com>
1 parent e122fdd commit 68634f4

9 files changed

Lines changed: 1261 additions & 216 deletions

File tree

examples/zkquiz/Makefile

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,12 @@
1-
deps: venv
2-
3-
venv: venv/touchfile
4-
5-
venv/touchfile: requirements.txt
6-
@python3 -m venv venv
7-
@. venv/bin/activate && pip install -r requirements.txt
8-
@touch venv/touchfile
9-
101
deploy_verifier:
11-
@./contracts/deploy.sh
12-
13-
answer_quiz:
14-
@cd quiz/script && cargo run -r
15-
16-
ADDRESS=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
17-
18-
submit_proof:
19-
@aligned submit \
20-
--proving_system SP1 \
21-
--proof quiz/script/proof-with-io.json \
22-
--vm_program quiz/program/elf/riscv32im-succinct-zkvm-elf \
23-
--proof_generator_addr $(ADDRESS) \
24-
--conn wss://batcher.alignedlayer.com
2+
@. ./contracts/.env && . ./contracts/deploy.sh
253

264
CONTRACT_ADDRESS=0x8dB9e6f1393c3486F30181d606312ec632189621
275
RPC_URL=https://ethereum-holesky-rpc.publicnode.com
286
VERIFICATION_DATA=./aligned_verification_data/0a1fab5df88a71e48633cbdeedc8d1a234b790d15a8a2fd04cd6a03c1e05b5ef_212.json
29-
PRIVATE_KEY=ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
307

31-
encode_verification_data: venv
32-
@. venv/bin/activate; python3 encode_verification_data.py --aligned-verification-data $(VERIFICATION_DATA)
33-
34-
verify_and_get_reward: venv
35-
@cast send \
36-
--rpc-url $(RPC_URL) \
37-
--private-key $(PRIVATE_KEY) \
38-
$(CONTRACT_ADDRESS) \
39-
$(shell source venv/bin/activate && python3 encode_verification_data.py --aligned-verification-data $(VERIFICATION_DATA))
8+
answer_quiz:
9+
@cd quiz/script && cargo run -r -- \
10+
--keystore-path $(KEYSTORE_PATH) \
11+
--rpc-url $(RPC_URL) \
12+
--verifier-contract-address $(CONTRACT_ADDRESS)

examples/zkquiz/README.md

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,40 @@
33
## Requirements
44

55
1. [Rust](https://www.rust-lang.org/tools/install)
6-
2. [Python](https://www.python.org/downloads/)
7-
3. [Aligned](https://github.com/yetanotherco/aligned_layer)
8-
4. [Foundry](https://getfoundry.sh)
6+
2. [Foundry](https://getfoundry.sh)
97

108
## Usage
119

12-
First, install dependencies by running:
13-
```bash
14-
make deps
15-
```
16-
This will create a virtual environment and install python dependencies.
10+
### 1 - Create Keystore
11+
12+
You can use cast to create a local keystore.
13+
If you already have one you can skip this step.
1714

18-
To answer quiz and generate proof run:
1915
```bash
20-
make answer_quiz
16+
cast wallet new-mnemonic
2117
```
2218

23-
This will ask questions and generate a proof if you answer correctly.
19+
Then you can import your created keystore using:
2420

25-
To submit the proof to aligned for verification run:
2621
```bash
27-
make submit_proof ADDRESS=<your_address>
22+
cast wallet import --interactive <path_to_keystore.json>
2823
```
2924

30-
Make sure to use your own address as this is the address that will receive the reward.
25+
Then you need to obtain some funds to pay for gas and proof verification.
26+
You can do this by using this [faucet](https://cloud.google.com/application/web3/faucet/ethereum/holesky)
3127

32-
Head to [Aligned Explorer](https://explorer.alignedlayer.com/batches) and wait for the batch to be verified.
28+
### 2 - Answer Quiz
29+
30+
To answer quiz questions run:
3331

34-
Then to verify the proof was verified on aligned, and mint your nft run:
3532
```bash
36-
make verify_and_get_reward VERIFICATION_DATA=<path_to_aligned_verification_data> PRIVATE_KEY=<your_private_key>
33+
make answer_quiz KEYSTORE_PATH=<path_to_keystore.json>
3734
```
38-
Note that the path to your proof verification data will be printed out when you submit the proof.
3935

40-
This will verify the proof and mint your nft.
41-
You can check your nft on the [Chainlens Explorer](https://holesky.chainlens.com/nfts/0x8dB9e6f1393c3486F30181d606312ec632189621).
36+
This will:
37+
38+
1. Ask quiz questions
39+
2. Generate ZK proof
40+
3. Pay & submit proof to aligned for verification
41+
4. Wait for proof to be verified in aligned
42+
5. Claim NFT if proof is verified

examples/zkquiz/contracts/deploy.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" || exit 1 ; pwd -P )
66
# At this point we are in examples/zkquiz
77
cd "$parent_path" || exit 1
88

9-
source .env
10-
119
if [ -z "$ALIGNED_SERVICE_MANAGER_ADDRESS" ]; then
1210
echo "ALIGNED_SERVICE_MANAGER_ADDRESS is not set. Please set it in .env"
1311
exit 1
@@ -29,7 +27,5 @@ forge script script/Deployer.s.sol \
2927
"$ALIGNED_SERVICE_MANAGER_ADDRESS" \
3028
--rpc-url "$RPC_URL" \
3129
--private-key "$PRIVATE_KEY" \
32-
--verify \
33-
--etherscan-api-key "$ETHERSCAN_API_KEY" \
3430
--broadcast \
3531
--sig "run(address _alignedServiceManager)"

examples/zkquiz/encode_verification_data.py

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)