Skip to content

Commit ee4dfdf

Browse files
committed
feat: receive vk on deployment
1 parent c700281 commit ee4dfdf

File tree

9 files changed

+81
-161
lines changed

9 files changed

+81
-161
lines changed

examples/circom/circuits/circuit.circom

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ template Multiplier(n) {
1515
c <== int[n-1];
1616
}
1717

18-
component main {public [d]} = Multiplier(1000);
18+
component main = Multiplier(1000);

examples/circom/circuits/generate_proof.sh

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,12 @@
22

33
# Reference: https://github.com/iden3/snarkjs?tab=readme-ov-file#10-compile-the-circuit
44

5-
# 10. Compile the circuit
6-
circom --r1cs --wasm --c --sym --inspect circuit.circom
7-
# 11. View information about the circuit
8-
snarkjs r1cs info circuit.r1cs
9-
# 12. Print the constraints [omitted]
10-
# 13. Export r1cs to json
11-
snarkjs r1cs export json circuit.r1cs circuit.r1cs.json
12-
# 14. Calculate the witness
13-
snarkjs wtns calculate circuit_js/circuit.wasm input.json witness.wtns
14-
# 15. Setup. This generates the reference zkey without phase 2 contributions.
15-
#IMPORTANT: Do not use this zkey in production, as it's not safe. It requires at least one contribution.
16-
snarkjs groth16 setup circuit.r1cs pot14_final.ptau circuit_0000.zkey
17-
# 16. Contribute to the phase 2 ceremony
18-
snarkjs zkey contribute circuit_0000.zkey circuit_0001.zkey --name="1st Contributor Name" -v -e="Random entropy"
19-
# 17. Provide a second contribution
20-
snarkjs zkey contribute circuit_0001.zkey circuit_0002.zkey --name="Second contribution Name" -v -e="Another random entropy"
21-
# 18. Provide a third contribution using third-party software
22-
snarkjs zkey export bellman circuit_0002.zkey challenge_phase2_0003
23-
snarkjs zkey bellman contribute bn128 challenge_phase2_0003 response_phase2_0003 -e="some random text"
24-
snarkjs zkey import bellman circuit_0002.zkey response_phase2_0003 circuit_0003.zkey -n="Third contribution name"
25-
# 19. Verify the latest zkey. Expected output: [INFO] snarkJS: ZKey Ok!
26-
snarkjs zkey verify circuit.r1cs pot14_final.ptau circuit_0003.zkey
27-
# 20. Apply a random beacon
28-
snarkjs zkey beacon circuit_0003.zkey circuit_final.zkey 0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f 10 -n="Final Beacon phase2"
29-
# 21. Verify the final zkey. Expected output: [INFO] snarkJS: ZKey Ok!
30-
snarkjs zkey verify circuit.r1cs pot14_final.ptau circuit_final.zkey
31-
# 22. Export the verification key
32-
snarkjs zkey export verificationkey circuit_final.zkey verification_key.json
5+
# cd to the directory of this script so that this can be run from anywhere
6+
parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" || exit 1 ; pwd -P )
7+
8+
cd "$parent_path" || exit 1
9+
10+
3311
# 23a. Calculate the witness and generate the proof in one step
3412
snarkjs groth16 fullprove input.json circuit_js/circuit.wasm circuit_final.zkey proof.json public.json
3513
# 24. Verify the proof

examples/circom/circuits/generate_setup.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,31 @@ snarkjs powersoftau beacon pot14_0003.ptau pot14_beacon.ptau 0102030405060708090
2020
snarkjs powersoftau prepare phase2 pot14_beacon.ptau pot14_final.ptau -v
2121
# 8. Verify the final ptau. Expected output: [INFO] snarkJS: Powers Of tau file OK!
2222
snarkjs powersoftau verify pot14_final.ptau
23+
# 10. Compile the circuit
24+
circom --r1cs --wasm --c --sym --inspect circuit.circom
25+
# 11. View information about the circuit
26+
snarkjs r1cs info circuit.r1cs
27+
# 12. Print the constraints [omitted]
28+
# 13. Export r1cs to json
29+
snarkjs r1cs export json circuit.r1cs circuit.r1cs.json
30+
# 14. Calculate the witness
31+
snarkjs wtns calculate circuit_js/circuit.wasm input.json witness.wtns
32+
# 15. Setup. This generates the reference zkey without phase 2 contributions.
33+
#IMPORTANT: Do not use this zkey in production, as it's not safe. It requires at least one contribution.
34+
snarkjs groth16 setup circuit.r1cs pot14_final.ptau circuit_0000.zkey
35+
# 16. Contribute to the phase 2 ceremony
36+
snarkjs zkey contribute circuit_0000.zkey circuit_0001.zkey --name="1st Contributor Name" -v -e="Random entropy"
37+
# 17. Provide a second contribution
38+
snarkjs zkey contribute circuit_0001.zkey circuit_0002.zkey --name="Second contribution Name" -v -e="Another random entropy"
39+
# 18. Provide a third contribution using third-party software
40+
snarkjs zkey export bellman circuit_0002.zkey challenge_phase2_0003
41+
snarkjs zkey bellman contribute bn128 challenge_phase2_0003 response_phase2_0003 -e="some random text"
42+
snarkjs zkey import bellman circuit_0002.zkey response_phase2_0003 circuit_0003.zkey -n="Third contribution name"
43+
# 19. Verify the latest zkey. Expected output: [INFO] snarkJS: ZKey Ok!
44+
snarkjs zkey verify circuit.r1cs pot14_final.ptau circuit_0003.zkey
45+
# 20. Apply a random beacon
46+
snarkjs zkey beacon circuit_0003.zkey circuit_final.zkey 0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f 10 -n="Final Beacon phase2"
47+
# 21. Verify the final zkey. Expected output: [INFO] snarkJS: ZKey Ok!
48+
snarkjs zkey verify circuit.r1cs pot14_final.ptau circuit_final.zkey
49+
# 22. Export the verification key
50+
snarkjs zkey export verificationkey circuit_final.zkey verification_key.json

examples/circom/circuits/proof.json

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

examples/circom/circuits/public.json

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

examples/circom/circuits/verification_key.json

Lines changed: 0 additions & 99 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
RPC_URL="http://127.0.0.1:8545"
2+
PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
3+
ALIGNED_SERVICE_MANAGER_ADDRESS=0x1613beB3B2C4f22Ee086B2b38C1476A3cE7f78E8
4+
PAYMENT_SERVICE_ADDRESS=0x7969c5eD335650692Bc04293B07F5BF2e7A673C0
5+
# generate it by running make generate_vk_commitment
6+
VK_COMMITMENT=<THE_GENERATED_VK_COMMITMENT>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
cd "$parent_path" || exit 1
7+
8+
if [ -z "$ALIGNED_SERVICE_MANAGER_ADDRESS" ]; then
9+
echo "ALIGNED_SERVICE_MANAGER_ADDRESS is not set. Please set it in .env"
10+
exit 1
11+
fi
12+
13+
if [ -z "$PAYMENT_SERVICE_ADDRESS" ]; then
14+
echo "PAYMENT_SERVICE_ADDRESS is not set. Please set it in .env"
15+
exit 1
16+
fi
17+
18+
if [ -z "$RPC_URL" ]; then
19+
echo "RPC_URL is not set. Please set it in .env"
20+
exit 1
21+
fi
22+
23+
if [ -z "$PRIVATE_KEY" ]; then
24+
echo "PRIVATE_KEY is not set. Please set it in .env"
25+
exit 1
26+
fi
27+
28+
forge install
29+
30+
forge script script/FibonacciDeployer.s.sol \
31+
"$ALIGNED_SERVICE_MANAGER_ADDRESS" \
32+
"$PAYMENT_SERVICE_ADDRESS" \
33+
"$VK_COMMITMENT" \
34+
--rpc-url "$RPC_URL" \
35+
--private-key "$PRIVATE_KEY" \
36+
--broadcast \
37+
--sig "run(address _alignedServiceManager,address _paymentServiceAddr)"

examples/circom/contracts/src/Fibonacci.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ contract FibonacciValidator {
55
address public alignedServiceManager;
66
address public paymentServiceAddr;
77

8-
bytes32 public fibonacciProgramVk = 0xc91d23fc3b1d24ecb241fbd501162734584f7c9f15ee5c95c712419206797a61;
8+
bytes32 public fibonacciProgramVk;
99

1010
error ProofVerificationFailed();
1111

1212
uint256 fibonacciNumber = 0;
1313

14-
constructor(address _alignedServiceManager, address _paymentServiceAddr) {
14+
constructor(address _alignedServiceManager, address _paymentServiceAddr, bytes32 programVk) {
1515
alignedServiceManager = _alignedServiceManager;
1616
paymentServiceAddr = _paymentServiceAddr;
17+
fibonacciProgramVk = programVk;
1718
}
1819

1920
function setNewNumber(

0 commit comments

Comments
 (0)