Skip to content

Commit

Permalink
chore: update example to show how to split public inputs in bash (noi…
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench authored Nov 7, 2024
1 parent b8654f7 commit b74b4ea
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
13 changes: 9 additions & 4 deletions examples/codegen_verifier/codegen_verifier.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 &

Expand All @@ -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 %-
kill %-
4 changes: 2 additions & 2 deletions examples/codegen_verifier/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fn main(x: Field, y: pub Field) {
fn main(x: pub Field, y: pub Field) {
assert(x != y);
}
}

0 comments on commit b74b4ea

Please sign in to comment.