diff --git a/yarn-project/circuits.js/src/abis/__snapshots__/abis.test.ts.snap b/yarn-project/circuits.js/src/abis/__snapshots__/abis.test.ts.snap index ff7582d8b52e..bda0c2a68307 100644 --- a/yarn-project/circuits.js/src/abis/__snapshots__/abis.test.ts.snap +++ b/yarn-project/circuits.js/src/abis/__snapshots__/abis.test.ts.snap @@ -1,6 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`abis Computes an empty call request hash 1`] = `"0x1a3e087582cc1adb9de2e55c7aa289c00afe085942c44951479f5da5f6e5d963"`; +exports[`abis Computes a callstack item hash 1`] = `"0x06dc9c35290e1868f41fc9f45bca49482bf5d5c000c789d6c74e53bce0f686f8"`; + +exports[`abis Computes a callstack item request hash 1`] = `"0x05c5d32c38f3de19dbfa92e25746e1db1a887d5b02b79dd915c0f50e9fc51dcd"`; exports[`abis Computes an empty nullifier hash 1`] = `"0x066e6cdc4a6ba5e4781deda650b0be6c12f975f064fc38df72c1060716759b17"`; diff --git a/yarn-project/circuits.js/src/abis/abis.test.ts b/yarn-project/circuits.js/src/abis/abis.test.ts index ab0132ce8b67..0d3e12d47551 100644 --- a/yarn-project/circuits.js/src/abis/abis.test.ts +++ b/yarn-project/circuits.js/src/abis/abis.test.ts @@ -246,16 +246,39 @@ describe('abis', () => { expect(emptyHash).toMatchSnapshot(); }); - it('Computes an empty call request hash ', () => { - const emptycallstack = PublicCallStackItem.empty(); - const emptyHash = emptycallstack.hash(); - expect(emptyHash.toString()).toMatchSnapshot(); - }); - it('Computes an empty public inputs hash ', () => { const publicInputs = PublicCircuitPublicInputs.empty(); const emptyHash = computePublicInputsHash(publicInputs); expect(Fr.fromBuffer(emptyHash).toString()).toMatchSnapshot(); }); + + it('Computes a callstack item request hash', () => { + const callStack = PublicCallStackItem.empty(); + + callStack.contractAddress = AztecAddress.fromField(new Fr(1)); + callStack.functionData = new FunctionData(new FunctionSelector(2), false, false, false); + callStack.isExecutionRequest = true; + callStack.publicInputs.newCommitments[0] = new SideEffect(new Fr(1), new Fr(0)); + + const hash = callStack.hash(); + expect(hash.toString()).toMatchSnapshot(); + + // Value used in compute_call_stack_item_hash test in noir circuits + // console.log("hash", hash.toString()); + }); + + it('Computes a callstack item hash', () => { + const callStack = PublicCallStackItem.empty(); + + callStack.contractAddress = AztecAddress.fromField(new Fr(1)); + callStack.functionData = new FunctionData(new FunctionSelector(2), false, false, false); + callStack.publicInputs.newCommitments[0] = new SideEffect(new Fr(1), new Fr(0)); + + const hash = callStack.hash(); + expect(hash.toString()).toMatchSnapshot(); + + // Value used in compute_call_stack_item_request_hash test in noir circuits + // console.log("hash", hash.toString()); + }); }); diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/interop_testing.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/interop_testing.nr index 94e363142066..6286fcbeb65a 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/interop_testing.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/interop_testing.nr @@ -96,35 +96,36 @@ fn compute_function_leaf() { assert_eq(leaf.hash(), 0x1ad8ece7f40e63d011ae47c6ce6cdaf31d632a23f5cf35bbeaaf69c8302afdbc); } -// TODO(benesjan): re-enable this -// #[test] -// fn compute_call_stack_item_request() { -// let contract_address = AztecAddress::from_field(1); -// let function_data = FunctionData { selector: FunctionSelector::from_u32(2), is_internal: false, is_private: false, is_constructor: false }; - -// let mut public_inputs: PublicCircuitPublicInputs = dep::std::unsafe::zeroed(); -// public_inputs.new_commitments[0] = SideEffect{ -// value: 1, -// counter: 0, -// }; - -// let call_stack_item = PublicCallStackItem { contract_address, public_inputs, is_execution_request: true, function_data }; - -// assert_eq(call_stack_item.hash(), 0x0edc0b5221e098c129545ba693368cddc0e6950bb11baa4595b310fc1fa24b5f); -// } - -// #[test] -// fn compute_call_stack_item() { -// let contract_address = AztecAddress::from_field(1); -// let function_data = FunctionData { selector: FunctionSelector::from_u32(2), is_internal: false, is_private: false, is_constructor: false }; - -// let mut public_inputs: PublicCircuitPublicInputs = dep::std::unsafe::zeroed(); -// public_inputs.new_commitments[0] = SideEffect{ -// value: 1, -// counter: 0, -// }; - -// let call_stack_item = PublicCallStackItem { contract_address, public_inputs, is_execution_request: false, function_data }; - -// assert_eq(call_stack_item.hash(), 0x10e265bf51be6945c10e526a86a928810429ac2d34c5fcda469245f0bb56abf6); -// } +#[test] +fn compute_call_stack_item_request_hash() { + let contract_address = AztecAddress::from_field(1); + let function_data = FunctionData { selector: FunctionSelector::from_u32(2), is_internal: false, is_private: false, is_constructor: false }; + + let mut public_inputs: PublicCircuitPublicInputs = dep::std::unsafe::zeroed(); + public_inputs.new_commitments[0] = SideEffect{ + value: 1, + counter: 0, + }; + + let call_stack_item = PublicCallStackItem { contract_address, public_inputs, is_execution_request: true, function_data }; + + // Value from abis.test.ts "Computes a callstack item request hash" test + assert_eq(call_stack_item.hash(), 0x05c5d32c38f3de19dbfa92e25746e1db1a887d5b02b79dd915c0f50e9fc51dcd); +} + +#[test] +fn compute_call_stack_item_hash() { + let contract_address = AztecAddress::from_field(1); + let function_data = FunctionData { selector: FunctionSelector::from_u32(2), is_internal: false, is_private: false, is_constructor: false }; + + let mut public_inputs: PublicCircuitPublicInputs = dep::std::unsafe::zeroed(); + public_inputs.new_commitments[0] = SideEffect{ + value: 1, + counter: 0, + }; + + let call_stack_item = PublicCallStackItem { contract_address, public_inputs, is_execution_request: false, function_data }; + + // Value from abis.test.ts "Computes a callstack item hash" test + assert_eq(call_stack_item.hash(), 0x06dc9c35290e1868f41fc9f45bca49482bf5d5c000c789d6c74e53bce0f686f8); +}