From b74b4eaf7acf6becd0f98ab25d0d5ccde3affebe Mon Sep 17 00:00:00 2001 From: Tom French <15848336+TomAFrench@users.noreply.github.com> Date: Thu, 7 Nov 2024 14:09:13 +0000 Subject: [PATCH] chore: update example to show how to split public inputs in bash (#6472) --- examples/codegen_verifier/codegen_verifier.sh | 13 +++++++++---- examples/codegen_verifier/src/main.nr | 4 ++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/examples/codegen_verifier/codegen_verifier.sh b/examples/codegen_verifier/codegen_verifier.sh index fabd6235a67..f224f74168f 100755 --- a/examples/codegen_verifier/codegen_verifier.sh +++ b/examples/codegen_verifier/codegen_verifier.sh @@ -16,11 +16,17 @@ nargo execute witness PROOF_PATH=./target/proof $BACKEND prove -b ./target/hello_world.json -w ./target/witness.gz -o $PROOF_PATH -NUM_PUBLIC_INPUTS=1 +# Sanity check that proof is valid. +$BACKEND verify -k ./target/vk -p ./target/proof + +NUM_PUBLIC_INPUTS=2 PUBLIC_INPUT_BYTES=$((32 * $NUM_PUBLIC_INPUTS)) HEX_PUBLIC_INPUTS=$(head -c $PUBLIC_INPUT_BYTES $PROOF_PATH | od -An -v -t x1 | tr -d $' \n') HEX_PROOF=$(tail -c +$(($PUBLIC_INPUT_BYTES + 1)) $PROOF_PATH | od -An -v -t x1 | tr -d $' \n') +# Split public inputs into strings where each string represents a `bytes32`. +SPLIT_HEX_PUBLIC_INPUTS=$(sed -e 's/.\{64\}/0x&,/g' <<< $HEX_PUBLIC_INPUTS) + # Spin up an anvil node to deploy the contract to anvil & @@ -31,8 +37,7 @@ DEPLOY_INFO=$(forge create UltraVerifier \ VERIFIER_ADDRESS=$(echo $DEPLOY_INFO | jq -r '.deployedTo') # Call the verifier contract with our proof. -# Note that we haven't needed to split up `HEX_PUBLIC_INPUTS` as there's only a single public input -cast call $VERIFIER_ADDRESS "verify(bytes, bytes32[])(bool)" "0x$HEX_PROOF" "[0x$HEX_PUBLIC_INPUTS]" +cast call $VERIFIER_ADDRESS "verify(bytes, bytes32[])(bool)" "0x$HEX_PROOF" "[$SPLIT_HEX_PUBLIC_INPUTS]" # Stop anvil node again -kill %- \ No newline at end of file +kill %- diff --git a/examples/codegen_verifier/src/main.nr b/examples/codegen_verifier/src/main.nr index baef0c3786a..93531797744 100644 --- a/examples/codegen_verifier/src/main.nr +++ b/examples/codegen_verifier/src/main.nr @@ -1,3 +1,3 @@ -fn main(x: Field, y: pub Field) { +fn main(x: pub Field, y: pub Field) { assert(x != y); -} \ No newline at end of file +}