Skip to content

Commit b80d098

Browse files
taturosatientropidelicMauroToscano
authored
feat: example full flow of using aligned (#482)
Co-authored-by: Mariano A. Nicolini <[email protected]> Co-authored-by: Mauro Toscano <[email protected]>
1 parent 9a3358e commit b80d098

24 files changed

+6991
-0
lines changed

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,9 @@
77
[submodule "examples/verify/lib/forge-std"]
88
path = examples/verify/lib/forge-std
99
url = https://github.com/foundry-rs/forge-std
10+
[submodule "examples/zkquiz/contracts/lib/forge-std"]
11+
path = examples/zkquiz/contracts/lib/forge-std
12+
url = https://github.com/foundry-rs/forge-std
13+
[submodule "examples/zkquiz/contracts/lib/openzeppelin-contracts"]
14+
path = examples/zkquiz/contracts/lib/openzeppelin-contracts
15+
url = https://github.com/OpenZeppelin/openzeppelin-contracts

examples/zkquiz/.gitignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Compiler files
2+
cache/
3+
out/
4+
5+
# Ignores development broadcast logs
6+
!/broadcast
7+
/broadcast/*/31337/
8+
/broadcast/**/dry-run/
9+
10+
# Docs
11+
docs/
12+
13+
# Dotenv file
14+
.env
15+
16+
# Python
17+
venv
18+
__pycache__

examples/zkquiz/Makefile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
10+
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
25+
26+
CONTRACT_ADDRESS=0x8dB9e6f1393c3486F30181d606312ec632189621
27+
RPC_URL=https://ethereum-holesky-rpc.publicnode.com
28+
VERIFICATION_DATA=./aligned_verification_data/0a1fab5df88a71e48633cbdeedc8d1a234b790d15a8a2fd04cd6a03c1e05b5ef_212.json
29+
PRIVATE_KEY=ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
30+
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))

examples/zkquiz/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# ZK Aligned Quiz
2+
3+
## Requirements
4+
5+
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)
9+
10+
## Usage
11+
12+
First, install dependencies by running:
13+
```bash
14+
make deps
15+
```
16+
This will create a virtual environment and install python dependencies.
17+
18+
To answer quiz and generate proof run:
19+
```bash
20+
make answer_quiz
21+
```
22+
23+
This will ask questions and generate a proof if you answer correctly.
24+
25+
To submit the proof to aligned for verification run:
26+
```bash
27+
make submit_proof ADDRESS=<your_address>
28+
```
29+
30+
Make sure to use your own address as this is the address that will receive the reward.
31+
32+
Head to [Aligned Explorer](https://explorer.alignedlayer.com/batches) and wait for the batch to be verified.
33+
34+
Then to verify the proof was verified on aligned, and mint your nft run:
35+
```bash
36+
make verify_and_get_reward VERIFICATION_DATA=<path_to_aligned_verification_data> PRIVATE_KEY=<your_private_key>
37+
```
38+
Note that the path to your proof verification data will be printed out when you submit the proof.
39+
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).
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
RPC_URL=<rpc_url>
2+
PRIVATE_KEY=<private_key>
3+
ALIGNED_SERVICE_MANAGER_ADDRESS=<aligned_service_manager_addr># 0x58F280BeBE9B34c9939C3C39e0890C81f163B623 for Holesky
4+
ETHERSCAN_API_KEY=<etherscan_api_key>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Compiler files
2+
cache/
3+
out/
4+
5+
# Ignores development broadcast logs
6+
broadcast
7+
8+
# Docs
9+
docs/
10+
11+
# Dotenv file
12+
.env
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
# cd to the directory of this script so that this can be run from anywhere
4+
parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" || exit 1 ; pwd -P )
5+
6+
# At this point we are in examples/zkquiz
7+
cd "$parent_path" || exit 1
8+
9+
source .env
10+
11+
if [ -z "$ALIGNED_SERVICE_MANAGER_ADDRESS" ]; then
12+
echo "ALIGNED_SERVICE_MANAGER_ADDRESS is not set. Please set it in .env"
13+
exit 1
14+
fi
15+
16+
if [ -z "$RPC_URL" ]; then
17+
echo "RPC_URL is not set. Please set it in .env"
18+
exit 1
19+
fi
20+
21+
if [ -z "$PRIVATE_KEY" ]; then
22+
echo "PRIVATE_KEY is not set. Please set it in .env"
23+
exit 1
24+
fi
25+
26+
forge install
27+
28+
forge script script/Deployer.s.sol \
29+
"$ALIGNED_SERVICE_MANAGER_ADDRESS" \
30+
--rpc-url "$RPC_URL" \
31+
--private-key "$PRIVATE_KEY" \
32+
--verify \
33+
--etherscan-api-key "$ETHERSCAN_API_KEY" \
34+
--broadcast \
35+
--sig "run(address _alignedServiceManager)"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[profile.default]
2+
src = "src"
3+
out = "out"
4+
libs = ["lib"]
5+
remappings = ["@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/"]
6+
7+
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
Submodule forge-std added at 978ac6f
Submodule openzeppelin-contracts added at dbb6104

0 commit comments

Comments
 (0)