@@ -6,38 +6,46 @@ BACKEND=${BACKEND:-bb}
6
6
nargo compile
7
7
8
8
# TODO: backend should automatically generate vk if necessary.
9
- $BACKEND OLD_API write_vk -b ./target/hello_world.json
10
- $BACKEND OLD_API contract -o ./src/contract.sol
9
+ $BACKEND write_vk -b ./target/hello_world.json -o ./target --oracle_hash keccak
10
+ $BACKEND write_solidity_verifier -k ./target/vk -o ./src/contract.sol
11
11
12
12
# We now generate a proof and check whether the verifier contract will verify it.
13
-
14
13
nargo execute --pedantic-solving witness
15
14
16
15
PROOF_PATH=./target/proof
17
- $BACKEND OLD_API prove -b ./target/hello_world.json -w ./target/witness.gz -o $PROOF_PATH
16
+ $BACKEND prove -b ./target/hello_world.json -w ./target/witness.gz --oracle_hash keccak -o ./target
18
17
19
18
# Sanity check that proof is valid.
20
- $BACKEND OLD_API verify -k ./target/vk -p ./target/proof
19
+ $BACKEND verify -k ./target/vk -p ./target/proof --oracle_hash keccak
20
+
21
+ # Prepare proof and public inputs for solidity verifier
22
+ PROOF_HEX=$( cat $PROOF_PATH | od -An -v -t x1 | tr -d $' \n ' | sed ' s/^.\{8\}//' )
21
23
22
24
NUM_PUBLIC_INPUTS=2
23
- PUBLIC_INPUT_BYTES=$(( 32 * $NUM_PUBLIC_INPUTS ))
24
- HEX_PUBLIC_INPUTS=$( head -c $PUBLIC_INPUT_BYTES $PROOF_PATH | od -An -v -t x1 | tr -d $' \n ' )
25
- HEX_PROOF=$( tail -c +$(( $PUBLIC_INPUT_BYTES + 1 )) $PROOF_PATH | od -An -v -t x1 | tr -d $' \n ' )
25
+ PUBLIC_INPUT_HEX_CHARS=$(( 32 * $NUM_PUBLIC_INPUTS * 2 )) # Each public input is 32 bytes, 2 chars per byte
26
+ PUBLIC_INPUT_OFFSET_CHARS=$(( 96 * 2 )) # First 96 bytes are the proof header
26
27
28
+ # Extract public inputs from proof - from 96th byte to 96 + 32 * NUM_PUBLIC_INPUTS bytes
29
+ HEX_PUBLIC_INPUTS=${PROOF_HEX: $PUBLIC_INPUT_OFFSET_CHARS : $PUBLIC_INPUT_HEX_CHARS }
27
30
# Split public inputs into strings where each string represents a `bytes32`.
28
31
SPLIT_HEX_PUBLIC_INPUTS=$( sed -e ' s/.\{64\}/0x&,/g' <<< $HEX_PUBLIC_INPUTS )
29
32
33
+ # Extract proof without public inputs - from 0 to 96 bytes + the part after public inputs
34
+ PROOF_WITHOUT_PUBLIC_INPUTS_START=${PROOF_HEX: 0: $PUBLIC_INPUT_OFFSET_CHARS }
35
+ PROOF_WITHOUT_PUBLIC_INPUTS_END=${PROOF_HEX: $(($PUBLIC_INPUT_OFFSET_CHARS + $PUBLIC_INPUT_HEX_CHARS ))}
36
+ PROOF_WITHOUT_PUBLIC_INPUTS=" ${PROOF_WITHOUT_PUBLIC_INPUTS_START}${PROOF_WITHOUT_PUBLIC_INPUTS_END} "
37
+
30
38
# Spin up an anvil node to deploy the contract to
31
39
anvil &
32
40
33
- DEPLOY_INFO=$( forge create UltraVerifier \
41
+ DEPLOY_INFO=$( forge create HonkVerifier \
34
42
--rpc-url " 127.0.0.1:8545" \
35
43
--private-key " 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" \
36
44
--json)
37
45
VERIFIER_ADDRESS=$( echo $DEPLOY_INFO | jq -r ' .deployedTo' )
38
46
39
47
# Call the verifier contract with our proof.
40
- cast call $VERIFIER_ADDRESS " verify(bytes, bytes32[])(bool)" " 0x $HEX_PROOF " " [$SPLIT_HEX_PUBLIC_INPUTS ]"
48
+ cast call $VERIFIER_ADDRESS " verify(bytes, bytes32[])(bool)" " $PROOF_WITHOUT_PUBLIC_INPUTS " " [$SPLIT_HEX_PUBLIC_INPUTS ]"
41
49
42
50
# Stop anvil node again
43
51
kill %-
0 commit comments