Skip to content

Commit 5656600

Browse files
committed
fix solidity verifier
1 parent 9f2f819 commit 5656600

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

examples/codegen_verifier/codegen_verifier.sh

+18-10
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,46 @@ BACKEND=${BACKEND:-bb}
66
nargo compile
77

88
# 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
1111

1212
# We now generate a proof and check whether the verifier contract will verify it.
13-
1413
nargo execute --pedantic-solving witness
1514

1615
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
1817

1918
# 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\}//')
2123

2224
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
2627

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}
2730
# Split public inputs into strings where each string represents a `bytes32`.
2831
SPLIT_HEX_PUBLIC_INPUTS=$(sed -e 's/.\{64\}/0x&,/g' <<<$HEX_PUBLIC_INPUTS)
2932

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+
3038
# Spin up an anvil node to deploy the contract to
3139
anvil &
3240

33-
DEPLOY_INFO=$(forge create UltraVerifier \
41+
DEPLOY_INFO=$(forge create HonkVerifier \
3442
--rpc-url "127.0.0.1:8545" \
3543
--private-key "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" \
3644
--json)
3745
VERIFIER_ADDRESS=$(echo $DEPLOY_INFO | jq -r '.deployedTo')
3846

3947
# 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]"
4149

4250
# Stop anvil node again
4351
kill %-

0 commit comments

Comments
 (0)