Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update example to show how to split public inputs in bash #6472

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Loading