From 2f6cd0025749df7209edcf88801e24980d43bdab Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Wed, 6 Nov 2024 08:32:10 +0000 Subject: [PATCH] init --- noir-projects/noir-contracts/bootstrap.sh | 11 +++++++++++ .../contract_instance_deployer_contract/src/main.nr | 5 +++++ .../circuits.js/src/contract/artifact_hash.ts | 11 +++++------ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/noir-projects/noir-contracts/bootstrap.sh b/noir-projects/noir-contracts/bootstrap.sh index b739b0eb429..90ecfe1a613 100755 --- a/noir-projects/noir-contracts/bootstrap.sh +++ b/noir-projects/noir-contracts/bootstrap.sh @@ -19,6 +19,17 @@ echo "Compiling contracts..." NARGO=${NARGO:-../../noir/noir-repo/target/release/nargo} $NARGO compile --silence-warnings --inliner-aggressiveness 0 +protocol_contracts=$(jq -r '.[]' "./protocol_contracts.json") +for contract in $protocol_contracts; do + artifactPath="./target/$contract.json" + readarray -t fnNames < <(jq -r '.functions[] | select(.custom_attributes | index("private")) | .name' "$artifactPath") + readarray -t fnBytecodes < <(jq -r '.functions[] | select(.custom_attributes | index("private")) | .bytecode' "$artifactPath") + + for i in "${!fnBytecodes[@]}"; do + echo "${fnNames[$i]}, $(echo -n "${fnBytecodes[$i]}" | sha256sum | awk '{print $1}')" + done +done + echo "Generating protocol contract vks..." BB_HASH=${BB_HASH:-$(cd ../../ && git ls-tree -r HEAD | grep 'barretenberg/cpp' | awk '{print $3}' | git hash-object --stdin)} echo Using BB hash $BB_HASH diff --git a/noir-projects/noir-contracts/contracts/contract_instance_deployer_contract/src/main.nr b/noir-projects/noir-contracts/contracts/contract_instance_deployer_contract/src/main.nr index 4ce03ebb6e1..8da7001401d 100644 --- a/noir-projects/noir-contracts/contracts/contract_instance_deployer_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/contract_instance_deployer_contract/src/main.nr @@ -81,6 +81,11 @@ contract ContractInstanceDeployer { } } + #[private] + fn foo_bar(a: Field) -> Field { + a + 1 + } + #[private] fn deploy( salt: Field, diff --git a/yarn-project/circuits.js/src/contract/artifact_hash.ts b/yarn-project/circuits.js/src/contract/artifact_hash.ts index f45e1ef4778..d64ace3f1e3 100644 --- a/yarn-project/circuits.js/src/contract/artifact_hash.ts +++ b/yarn-project/circuits.js/src/contract/artifact_hash.ts @@ -134,15 +134,14 @@ export function computeFunctionArtifactHash( | (Pick & { functionMetadataHash: Fr; selector: FunctionSelector }), ) { const selector = 'selector' in fn ? fn.selector : FunctionSelector.fromNameAndParameters(fn); - // TODO(#5860): make bytecode part of artifact hash preimage again - // const bytecodeHash = sha256Fr(fn.bytecode).toBuffer(); - // const metadataHash = 'functionMetadataHash' in fn ? fn.functionMetadataHash : computeFunctionMetadataHash(fn); - // return sha256Fr(Buffer.concat([numToUInt8(VERSION), selector.toBuffer(), metadataHash.toBuffer(), bytecodeHash])); - return sha256Fr(Buffer.concat([numToUInt8(VERSION), selector.toBuffer()])); + + const bytecodeHash = sha256Fr(fn.bytecode).toBuffer(); + const metadataHash = 'functionMetadataHash' in fn ? fn.functionMetadataHash : computeFunctionMetadataHash(fn); + return sha256Fr(Buffer.concat([numToUInt8(VERSION), selector.toBuffer(), metadataHash.toBuffer(), bytecodeHash])); } export function computeFunctionMetadataHash(fn: FunctionArtifact) { - return sha256Fr(Buffer.from(JSON.stringify(fn.returnTypes), 'utf8')); + return sortHashArtifactMetadata(fn.returnTypes); } function getLogger() {