From 0021a3e4ec55074f5f84d6654995a1e02594ea8e Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Thu, 18 Apr 2024 19:41:42 -0300 Subject: [PATCH 1/2] fix: Temporarily exclude bytecode from class id computation This should allow us to sidestep any issues with bytecode differences between different environments, but needs to be reverted since it's a security risk. --- l1-contracts/src/core/libraries/ConstantsGen.sol | 2 +- .../noir-protocol-circuits/crates/types/src/constants.nr | 2 +- yarn-project/circuits.js/src/constants.gen.ts | 2 +- yarn-project/circuits.js/src/contract/artifact_hash.ts | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/l1-contracts/src/core/libraries/ConstantsGen.sol b/l1-contracts/src/core/libraries/ConstantsGen.sol index 6661fc67443..586ce6be731 100644 --- a/l1-contracts/src/core/libraries/ConstantsGen.sol +++ b/l1-contracts/src/core/libraries/ConstantsGen.sol @@ -89,7 +89,7 @@ library Constants { uint256 internal constant DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE = 0x85864497636cf755ae7bde03f267ce01a520981c21c3682aaf82a631; uint256 internal constant DEPLOYER_CONTRACT_ADDRESS = - 0x1b5ecf3d26907648cf737f4304759b8c5850478e839e72f8ce1f5791b286e8f2; + 0x161b653b72ac5aa2982ce485b242b5c1e09afcbf27b89696f5a4e3151be37245; uint256 internal constant AZTEC_ADDRESS_LENGTH = 1; uint256 internal constant DIMENSION_GAS_SETTINGS_LENGTH = 3; uint256 internal constant GAS_FEES_LENGTH = 3; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr index e8e5f1cf2ee..cd982b40f1f 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr @@ -126,7 +126,7 @@ global REGISTERER_UNCONSTRAINED_FUNCTION_BROADCASTED_MAGIC_VALUE = 0xe7af8166354 // CONTRACT INSTANCE CONSTANTS // sha224sum 'struct ContractInstanceDeployed' global DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE = 0x85864497636cf755ae7bde03f267ce01a520981c21c3682aaf82a631; -global DEPLOYER_CONTRACT_ADDRESS = 0x1b5ecf3d26907648cf737f4304759b8c5850478e839e72f8ce1f5791b286e8f2; +global DEPLOYER_CONTRACT_ADDRESS = 0x161b653b72ac5aa2982ce485b242b5c1e09afcbf27b89696f5a4e3151be37245; // LENGTH OF STRUCTS SERIALIZED TO FIELDS global AZTEC_ADDRESS_LENGTH = 1; diff --git a/yarn-project/circuits.js/src/constants.gen.ts b/yarn-project/circuits.js/src/constants.gen.ts index 6441113ed89..de9c6e4cc0e 100644 --- a/yarn-project/circuits.js/src/constants.gen.ts +++ b/yarn-project/circuits.js/src/constants.gen.ts @@ -74,7 +74,7 @@ export const REGISTERER_UNCONSTRAINED_FUNCTION_BROADCASTED_MAGIC_VALUE = 0xe7af816635466f128568edb04c9fa024f6c87fb9010fdbffa68b3d99n; export const DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE = 0x85864497636cf755ae7bde03f267ce01a520981c21c3682aaf82a631n; -export const DEPLOYER_CONTRACT_ADDRESS = 0x1b5ecf3d26907648cf737f4304759b8c5850478e839e72f8ce1f5791b286e8f2n; +export const DEPLOYER_CONTRACT_ADDRESS = 0x161b653b72ac5aa2982ce485b242b5c1e09afcbf27b89696f5a4e3151be37245n; export const AZTEC_ADDRESS_LENGTH = 1; export const DIMENSION_GAS_SETTINGS_LENGTH = 3; export const GAS_FEES_LENGTH = 3; diff --git a/yarn-project/circuits.js/src/contract/artifact_hash.ts b/yarn-project/circuits.js/src/contract/artifact_hash.ts index efad51e999c..b1d8b0daae2 100644 --- a/yarn-project/circuits.js/src/contract/artifact_hash.ts +++ b/yarn-project/circuits.js/src/contract/artifact_hash.ts @@ -94,9 +94,9 @@ export function computeFunctionArtifactHash( | (Pick & { functionMetadataHash: Fr; selector: FunctionSelector }), ) { const selector = 'selector' in fn ? fn.selector : FunctionSelector.fromNameAndParameters(fn); - 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])); + const _bytecodeHash = sha256Fr(fn.bytecode).toBuffer(); + const _metadataHash = 'functionMetadataHash' in fn ? fn.functionMetadataHash : computeFunctionMetadataHash(fn); + return sha256Fr(Buffer.concat([numToUInt8(VERSION), selector.toBuffer()])); } export function computeFunctionMetadataHash(fn: FunctionArtifact) { From 9ee762256d839b6f48b88797852ababc5c0cf7cd Mon Sep 17 00:00:00 2001 From: benesjan Date: Fri, 19 Apr 2024 08:18:36 +0000 Subject: [PATCH 2/2] fixes --- yarn-project/circuits.js/src/contract/artifact_hash.ts | 6 ++++-- .../src/contract/private_function_membership_proof.test.ts | 3 ++- .../unconstrained_function_membership_proof.test.ts | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/yarn-project/circuits.js/src/contract/artifact_hash.ts b/yarn-project/circuits.js/src/contract/artifact_hash.ts index b1d8b0daae2..58be0f2437f 100644 --- a/yarn-project/circuits.js/src/contract/artifact_hash.ts +++ b/yarn-project/circuits.js/src/contract/artifact_hash.ts @@ -94,8 +94,10 @@ export function computeFunctionArtifactHash( | (Pick & { functionMetadataHash: Fr; selector: FunctionSelector }), ) { const selector = 'selector' in fn ? fn.selector : FunctionSelector.fromNameAndParameters(fn); - const _bytecodeHash = sha256Fr(fn.bytecode).toBuffer(); - const _metadataHash = 'functionMetadataHash' in fn ? fn.functionMetadataHash : computeFunctionMetadataHash(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()])); } diff --git a/yarn-project/circuits.js/src/contract/private_function_membership_proof.test.ts b/yarn-project/circuits.js/src/contract/private_function_membership_proof.test.ts index 19b85857f26..6909cd68c30 100644 --- a/yarn-project/circuits.js/src/contract/private_function_membership_proof.test.ts +++ b/yarn-project/circuits.js/src/contract/private_function_membership_proof.test.ts @@ -31,7 +31,8 @@ describe('private_function_membership_proof', () => { expect(isValidPrivateFunctionMembershipProof(fn, contractClass)).toBeTruthy(); }); - test.each([ + // TODO(#5860): Re-enable this test once noir non-determinism is addressed + test.skip.each([ 'artifactTreeSiblingPath', 'artifactMetadataHash', 'functionMetadataHash', diff --git a/yarn-project/circuits.js/src/contract/unconstrained_function_membership_proof.test.ts b/yarn-project/circuits.js/src/contract/unconstrained_function_membership_proof.test.ts index 35b983e08e2..e128aa7abb0 100644 --- a/yarn-project/circuits.js/src/contract/unconstrained_function_membership_proof.test.ts +++ b/yarn-project/circuits.js/src/contract/unconstrained_function_membership_proof.test.ts @@ -48,7 +48,8 @@ describe('unconstrained_function_membership_proof', () => { expect(isValidUnconstrainedFunctionMembershipProof(fn, contractClass)).toBeTruthy(); }); - test.each(['artifactTreeSiblingPath', 'artifactMetadataHash', 'functionMetadataHash'] as const)( + // TODO(#5860): Re-enable this test once noir non-determinism is addressed + test.skip.each(['artifactTreeSiblingPath', 'artifactMetadataHash', 'functionMetadataHash'] as const)( 'fails proof if %s is mangled', field => { const proof = createUnconstrainedFunctionMembershipProof(selector, artifact);