From b8f0719bb6c7df93517088503f1bc216ec4cafaa Mon Sep 17 00:00:00 2001 From: benesjan Date: Wed, 21 Feb 2024 16:22:12 +0000 Subject: [PATCH 1/5] test: more interop tests --- .../types/src/abis/new_contract_data.nr | 42 +++++++ .../private_call_stack_item.test.ts.snap | 62 +++++------ ...private_circuit_public_inputs.test.ts.snap | 60 +++++----- .../public_call_stack_item.test.ts.snap | 64 +++++------ .../public_circuit_public_inputs.test.ts.snap | 64 +++++------ .../new_contract_data.test.ts.snap | 103 +++++++++++++----- .../structs/kernel/new_contract_data.test.ts | 23 +++- .../src/structs/kernel/new_contract_data.ts | 6 +- .../circuits.js/src/tests/factories.ts | 4 +- 9 files changed, 266 insertions(+), 162 deletions(-) diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/new_contract_data.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/new_contract_data.nr index e58de4329ce..735d7329776 100644 --- a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/new_contract_data.nr +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/new_contract_data.nr @@ -66,3 +66,45 @@ impl NewContractData { & (self.contract_class_id.to_field() == 0) } } + +mod tests { + use crate::{ + abis::new_contract_data::NewContractData, address::{AztecAddress, EthAddress}, + contract_class_id::ContractClassId + }; + + // Matches makeNewContractData in factories.ts + fn make_new_contract_data(seed: Field) -> NewContractData { + NewContractData { + contract_address: AztecAddress::from_field(seed), + portal_contract_address: EthAddress::from_field(seed + 1), + contract_class_id: ContractClassId::from_field(seed + 2) + } + } + + #[test] + fn serialization_of_empty() { + let data: NewContractData = dep::std::unsafe::zeroed(); + let serialized = data.serialize(); + let deserialized = NewContractData::deserialize(serialized); + assert(data.eq(deserialized)); + } + + #[test] + fn empty_hash_is_zero() { + let data: NewContractData = dep::std::unsafe::zeroed(); + let hash = data.hash(); + + // Value from new_contract_data.test.ts "computes empty hash" test + assert_eq(hash, 0x0000000000000000000000000000000000000000000000000000000000000000); + } + + #[test] + fn hash_matches() { + let data = make_new_contract_data(5); + let hash = data.hash(); + + // Value from new_contract_data.test.ts "hash matches" test + assert_eq(hash, 0x2359862482fb58cf5a5ddab56eb6d49908bc811353f3fd6fe9fd057c525cbf0b); + } +} diff --git a/yarn-project/circuits.js/src/structs/__snapshots__/private_call_stack_item.test.ts.snap b/yarn-project/circuits.js/src/structs/__snapshots__/private_call_stack_item.test.ts.snap index 63a535826bf..9bddcf8cd11 100644 --- a/yarn-project/circuits.js/src/structs/__snapshots__/private_call_stack_item.test.ts.snap +++ b/yarn-project/circuits.js/src/structs/__snapshots__/private_call_stack_item.test.ts.snap @@ -45,41 +45,41 @@ Fr { exports[`PrivateCallStackItem computes hash 1`] = ` Fr { - "asBigInt": 11565536952143192473504073828804565815449488047909506244379565719931597217633n, + "asBigInt": 19520755359745729990898807497202224879281656008242555374727476866221326621394n, "asBuffer": { "data": [ - 25, - 145, - 220, - 167, - 253, - 41, - 251, - 22, - 195, - 73, - 198, - 253, - 74, - 238, - 27, - 1, - 171, - 191, - 73, - 109, - 110, - 169, - 231, + 43, + 40, 91, - 39, - 46, + 34, + 118, + 222, + 136, + 132, + 51, + 136, 163, - 110, - 144, - 193, - 223, - 97, + 211, + 132, + 203, + 127, + 229, + 225, + 28, + 122, + 184, + 120, + 133, + 89, + 26, + 226, + 241, + 118, + 82, + 53, + 74, + 90, + 210, ], "type": "Buffer", }, diff --git a/yarn-project/circuits.js/src/structs/__snapshots__/private_circuit_public_inputs.test.ts.snap b/yarn-project/circuits.js/src/structs/__snapshots__/private_circuit_public_inputs.test.ts.snap index 182d027db02..3bc4ae7f916 100644 --- a/yarn-project/circuits.js/src/structs/__snapshots__/private_circuit_public_inputs.test.ts.snap +++ b/yarn-project/circuits.js/src/structs/__snapshots__/private_circuit_public_inputs.test.ts.snap @@ -45,41 +45,41 @@ Fr { exports[`PrivateCircuitPublicInputs hash matches snapshot 1`] = ` Fr { - "asBigInt": 11925579675304601364925432965932196876646472170983258942947411041202598868288n, + "asBigInt": 6671264872232661673666397250079986319923878807400079138828282845489852465897n, "asBuffer": { "data": [ - 26, + 14, + 191, + 205, + 86, + 248, + 49, 93, - 163, - 142, - 210, - 79, - 156, - 203, - 215, - 178, - 165, - 209, - 152, + 28, + 135, + 224, + 68, + 149, + 177, 20, + 255, + 85, + 169, + 178, + 61, + 226, + 248, + 224, + 142, + 19, + 90, + 100, + 30, 159, - 96, - 242, - 223, - 34, - 230, - 123, - 44, - 109, - 146, - 35, - 127, - 210, - 50, - 198, - 160, - 117, - 64, + 205, + 170, + 66, + 233, ], "type": "Buffer", }, diff --git a/yarn-project/circuits.js/src/structs/__snapshots__/public_call_stack_item.test.ts.snap b/yarn-project/circuits.js/src/structs/__snapshots__/public_call_stack_item.test.ts.snap index 00287829d25..735f7ea94fd 100644 --- a/yarn-project/circuits.js/src/structs/__snapshots__/public_call_stack_item.test.ts.snap +++ b/yarn-project/circuits.js/src/structs/__snapshots__/public_call_stack_item.test.ts.snap @@ -6,41 +6,41 @@ exports[`PublicCallStackItem Computes a callstack item request hash 1`] = `"0x28 exports[`PublicCallStackItem computes hash 1`] = ` Fr { - "asBigInt": 4979549560117705258967782015110547148437372289877391678586990786489996140757n, + "asBigInt": 5564031247356020353810998760199482863796790393190610135965142067359455090525n, "asBuffer": { "data": [ - 11, - 2, - 83, - 62, - 143, - 119, - 80, - 193, - 96, - 62, - 38, - 197, - 196, - 184, - 30, - 166, - 192, - 92, - 156, - 202, - 205, - 88, - 204, - 136, - 76, - 190, - 16, - 58, - 230, + 12, + 77, + 33, + 77, + 64, + 203, 33, - 224, - 213, + 253, + 25, + 21, + 66, + 225, + 22, + 94, + 25, + 36, + 156, + 159, + 227, + 54, + 40, + 115, + 108, + 155, + 82, + 234, + 144, + 55, + 50, + 211, + 151, + 93, ], "type": "Buffer", }, diff --git a/yarn-project/circuits.js/src/structs/__snapshots__/public_circuit_public_inputs.test.ts.snap b/yarn-project/circuits.js/src/structs/__snapshots__/public_circuit_public_inputs.test.ts.snap index 614c9dc7d58..67cd5e64828 100644 --- a/yarn-project/circuits.js/src/structs/__snapshots__/public_circuit_public_inputs.test.ts.snap +++ b/yarn-project/circuits.js/src/structs/__snapshots__/public_circuit_public_inputs.test.ts.snap @@ -2,41 +2,41 @@ exports[`PublicCircuitPublicInputs hash matches snapshot 1`] = ` Fr { - "asBigInt": 15149617471671820122934202259826883269771542279475628262820830794638374376729n, + "asBigInt": 888846281962498247810067532853731271075966629879817122598695403485138176580n, "asBuffer": { "data": [ - 33, - 126, - 97, - 47, - 16, - 155, - 37, - 225, - 121, - 41, - 213, - 83, - 147, - 9, - 243, - 214, - 163, + 1, + 247, + 17, + 180, 245, - 15, - 2, - 176, - 172, - 94, - 246, - 47, - 135, - 242, - 97, - 149, - 170, - 149, - 25, + 241, + 13, + 223, + 202, + 143, + 57, + 70, + 74, + 0, + 106, + 174, + 207, + 10, + 115, + 35, + 110, + 39, + 45, + 164, + 201, + 195, + 236, + 184, + 208, + 18, + 202, + 68, ], "type": "Buffer", }, diff --git a/yarn-project/circuits.js/src/structs/kernel/__snapshots__/new_contract_data.test.ts.snap b/yarn-project/circuits.js/src/structs/kernel/__snapshots__/new_contract_data.test.ts.snap index 3b575df1b03..1166a008d9e 100644 --- a/yarn-project/circuits.js/src/structs/kernel/__snapshots__/new_contract_data.test.ts.snap +++ b/yarn-project/circuits.js/src/structs/kernel/__snapshots__/new_contract_data.test.ts.snap @@ -2,41 +2,84 @@ exports[`NewContractData computes contract leaf 1`] = ` Fr { - "asBigInt": 5986263944919688269259252379860004722838901933221811337668199393213435390630n, + "asBigInt": 1205669559362216690501113071754010899122564402260118295790326203728712063609n, "asBuffer": { "data": [ - 13, - 60, - 26, - 246, - 112, - 251, - 244, - 209, - 174, - 13, - 247, - 16, - 244, - 142, - 50, - 157, - 199, - 41, - 183, + 2, + 170, 98, - 240, - 188, - 131, - 153, - 186, - 217, - 255, - 3, - 166, + 129, + 115, + 236, + 158, + 132, + 183, 0, + 14, + 176, 170, - 166, + 124, + 64, + 104, + 64, + 24, + 101, + 95, + 230, + 204, + 70, + 89, + 105, + 38, + 142, + 94, + 141, + 66, + 90, + 121, + ], + "type": "Buffer", + }, +} +`; + +exports[`NewContractData hash matches 1`] = ` +Fr { + "asBigInt": 15989124907542145791377884953407893320840303158499919884975910897341668572939n, + "asBuffer": { + "data": [ + 35, + 89, + 134, + 36, + 130, + 251, + 88, + 207, + 90, + 93, + 218, + 181, + 110, + 182, + 212, + 153, + 8, + 188, + 129, + 19, + 83, + 243, + 253, + 111, + 233, + 253, + 5, + 124, + 82, + 92, + 191, + 11, ], "type": "Buffer", }, diff --git a/yarn-project/circuits.js/src/structs/kernel/new_contract_data.test.ts b/yarn-project/circuits.js/src/structs/kernel/new_contract_data.test.ts index df66eee7041..73dc20f8e67 100644 --- a/yarn-project/circuits.js/src/structs/kernel/new_contract_data.test.ts +++ b/yarn-project/circuits.js/src/structs/kernel/new_contract_data.test.ts @@ -1,3 +1,5 @@ +import { Fr } from '@aztec/foundation/fields'; + import { NEW_CONTRACT_DATA_LENGTH } from '../../constants.gen.js'; import { makeNewContractData } from '../../tests/factories.js'; import { NewContractData } from './new_contract_data.js'; @@ -23,7 +25,24 @@ describe('NewContractData', () => { it('computes contract leaf', () => { const cd = makeNewContractData(12); - const res = cd.computeLeaf(); - expect(res).toMatchSnapshot(); + const hash = cd.hash(); + expect(hash).toMatchSnapshot(); + }); + + it('empty "hash" is zero', () => { + const cd = NewContractData.empty(); + expect(cd.isEmpty()).toBe(true); + + const hash = cd.hash(); + expect(hash).toEqual(Fr.ZERO); + }); + + it('hash matches', () => { + const cd = makeNewContractData(5); + const hash = cd.hash(); + expect(hash).toMatchSnapshot(); + + // Value used in hash_matches test in new_contract_data.nr + // console.log("hash", hash.toString()); }); }); diff --git a/yarn-project/circuits.js/src/structs/kernel/new_contract_data.ts b/yarn-project/circuits.js/src/structs/kernel/new_contract_data.ts index 33332732ccb..94203ddfad2 100644 --- a/yarn-project/circuits.js/src/structs/kernel/new_contract_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/new_contract_data.ts @@ -47,11 +47,11 @@ export class NewContractData { } /** - * Computes a contract leaf of the given contract. + * Computes a hash of contract data which is a leaf in the contracts tree. * @param cd - The contract data of the deployed contract. - * @returns The contract leaf. + * @returns The contract data hash/contract tree leaf. */ - computeLeaf(): Fr { + hash(): Fr { if (this.isEmpty()) { return new Fr(0); } diff --git a/yarn-project/circuits.js/src/tests/factories.ts b/yarn-project/circuits.js/src/tests/factories.ts index 6e87936d6b5..3bd6887749b 100644 --- a/yarn-project/circuits.js/src/tests/factories.ts +++ b/yarn-project/circuits.js/src/tests/factories.ts @@ -916,7 +916,7 @@ export function makeAppendOnlyTreeSnapshot(seed = 1): AppendOnlyTreeSnapshot { * @returns An eth address. */ export function makeEthAddress(seed = 1): EthAddress { - return new EthAddress(Buffer.alloc(20, seed)); + return EthAddress.fromField(fr(seed)); } /** @@ -935,7 +935,7 @@ export function makeBytes(size = 32, fill = 1): Buffer { * @returns An aztec address. */ export function makeAztecAddress(seed = 1): AztecAddress { - return new AztecAddress(fr(seed).toBuffer()); + return AztecAddress.fromField(fr(seed)); } /** From d8ad2a93f0977c7be7103a9c80107f375bfd6e4a Mon Sep 17 00:00:00 2001 From: benesjan Date: Wed, 21 Feb 2024 16:26:28 +0000 Subject: [PATCH 2/5] nuking comments --- .../src/crates/types/src/abis/function_data.nr | 1 - .../src/crates/types/src/abis/private_call_stack_item.nr | 1 - .../src/crates/types/src/abis/private_circuit_public_inputs.nr | 1 - .../src/crates/types/src/contrakt/contract_deployment_data.nr | 1 - .../src/crates/types/src/transaction/tx_context.nr | 1 - 5 files changed, 5 deletions(-) diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/function_data.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/function_data.nr index d185979b20a..ac042d74b31 100644 --- a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/function_data.nr +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/function_data.nr @@ -61,7 +61,6 @@ fn serialization_of_empty() { assert(data.eq(deserialized)); } -// TODO(#4619): Hash non-empty #[test] fn empty_hash() { let data: FunctionData = dep::std::unsafe::zeroed(); diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/private_call_stack_item.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/private_call_stack_item.nr index 2fe2f373b44..4afd285dd64 100644 --- a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/private_call_stack_item.nr +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/private_call_stack_item.nr @@ -68,7 +68,6 @@ fn serialization_of_empty() { assert(item.eq(deserialized)); } -// TODO(#4619): Hash non-empty #[test] fn empty_hash() { let mut item: PrivateCallStackItem = dep::std::unsafe::zeroed(); diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/private_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/private_circuit_public_inputs.nr index 692e4e30b2f..064b4d1977e 100644 --- a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/private_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/private_circuit_public_inputs.nr @@ -165,7 +165,6 @@ fn serialization_of_empty() { assert(pcpi.eq(deserialized)); } -// TODO(#4619): Hash non-empty #[test] fn empty_hash() { let inputs: PrivateCircuitPublicInputs = dep::std::unsafe::zeroed(); diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/contrakt/contract_deployment_data.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/contrakt/contract_deployment_data.nr index 57c67f036d0..29e87193e9a 100644 --- a/noir-projects/noir-protocol-circuits/src/crates/types/src/contrakt/contract_deployment_data.nr +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/contrakt/contract_deployment_data.nr @@ -76,7 +76,6 @@ fn serialization_of_empty() { assert(data.eq(deserialized)); } -// TODO(#4619): Hash non-empty #[test] fn empty_hash() { let data: ContractDeploymentData = dep::std::unsafe::zeroed(); diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/transaction/tx_context.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/transaction/tx_context.nr index 7ab20bc125b..2534e047535 100644 --- a/noir-projects/noir-protocol-circuits/src/crates/types/src/transaction/tx_context.nr +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/transaction/tx_context.nr @@ -76,7 +76,6 @@ fn serialization_of_empty() { assert(context.eq(deserialized)); } -// TODO(#4619): Hash non-empty #[test] fn empty_hash() { let inputs: TxContext = dep::std::unsafe::zeroed(); From 520f2e68a84a0429323aecd064d05aeea82803b2 Mon Sep 17 00:00:00 2001 From: benesjan Date: Wed, 21 Feb 2024 16:32:46 +0000 Subject: [PATCH 3/5] interop test header hash --- .../src/crates/types/src/header.nr | 23 +++++++--- .../structs/__snapshots__/header.test.ts.snap | 43 +++++++++++++++++++ .../circuits.js/src/structs/header.test.ts | 9 ++++ 3 files changed, 69 insertions(+), 6 deletions(-) diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/header.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/header.nr index 0ffa7505c3f..ec0d66df868 100644 --- a/noir-projects/noir-protocol-circuits/src/crates/types/src/header.nr +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/header.nr @@ -1,12 +1,14 @@ use crate::{ abis::{ - append_only_tree_snapshot::{AppendOnlyTreeSnapshot, APPEND_ONLY_TREE_SNAPSHOT_LENGTH}, - global_variables::{GlobalVariables, GLOBAL_VARIABLES_LENGTH} - }, - constants::{GENERATOR_INDEX__BLOCK_HASH, HEADER_LENGTH, NUM_FIELDS_PER_SHA256, STATE_REFERENCE_LENGTH, CONTENT_COMMITMENT_LENGTH}, + append_only_tree_snapshot::{AppendOnlyTreeSnapshot, APPEND_ONLY_TREE_SNAPSHOT_LENGTH}, + global_variables::{GlobalVariables, GLOBAL_VARIABLES_LENGTH} +}, + constants::{ + GENERATOR_INDEX__BLOCK_HASH, HEADER_LENGTH, NUM_FIELDS_PER_SHA256, STATE_REFERENCE_LENGTH, + CONTENT_COMMITMENT_LENGTH +}, hash::pedersen_hash, state_reference::StateReference, traits::{Deserialize, Empty, Hash, Serialize}, - utils::{arr_copy_slice}, - content_commitment::ContentCommitment + utils::{arr_copy_slice}, content_commitment::ContentCommitment }; // docs:start:header @@ -94,3 +96,12 @@ fn hash_smoke() { let header: Header = dep::std::unsafe::zeroed(); let _hashed = header.hash(); } + +#[test] +fn empty_hash_is_zero() { + let header: Header = dep::std::unsafe::zeroed(); + let hash = header.hash(); + + // Value from new_contract_data.test.ts "computes empty hash" test + assert_eq(hash, 0x2df930cc7b9fc763e82ade72f7c4618834692b2a3d0936aff8d7bbfb27f59d6e); +} diff --git a/yarn-project/circuits.js/src/structs/__snapshots__/header.test.ts.snap b/yarn-project/circuits.js/src/structs/__snapshots__/header.test.ts.snap index 156d2abdf00..501bd971e54 100644 --- a/yarn-project/circuits.js/src/structs/__snapshots__/header.test.ts.snap +++ b/yarn-project/circuits.js/src/structs/__snapshots__/header.test.ts.snap @@ -1,5 +1,48 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Header computes empty hash 1`] = ` +Fr { + "asBigInt": 20794359902049712309840803989537372971066838126069955186305683313093334375790n, + "asBuffer": { + "data": [ + 45, + 249, + 48, + 204, + 123, + 159, + 199, + 99, + 232, + 42, + 222, + 114, + 247, + 196, + 97, + 136, + 52, + 105, + 43, + 42, + 61, + 9, + 54, + 175, + 248, + 215, + 187, + 251, + 39, + 245, + 157, + 110, + ], + "type": "Buffer", + }, +} +`; + exports[`Header computes hash 1`] = ` Fr { "asBigInt": 17965313985247589544372198735324565090920557482351371957268170919526618141863n, diff --git a/yarn-project/circuits.js/src/structs/header.test.ts b/yarn-project/circuits.js/src/structs/header.test.ts index 716c0a660b5..0cdd77ea8c8 100644 --- a/yarn-project/circuits.js/src/structs/header.test.ts +++ b/yarn-project/circuits.js/src/structs/header.test.ts @@ -33,4 +33,13 @@ describe('Header', () => { const fields = header.toFields(); expect(fields.length).toBe(HEADER_LENGTH); }); + + it('computes empty hash', () => { + const header = Header.empty(); + const hash = header.hash(); + expect(hash).toMatchSnapshot(); + + // Value used in empty_hash test in header.nr + // console.log("hash", hash.toString()); + }); }); From af0b1d537bfa03a6a0853b5b30923cd00e9aeff1 Mon Sep 17 00:00:00 2001 From: benesjan Date: Wed, 21 Feb 2024 16:43:45 +0000 Subject: [PATCH 4/5] WIP --- .../src/abis/public_circuit_public_inputs.nr | 9 ++-- .../public_circuit_public_inputs.test.ts.snap | 43 +++++++++++++++++++ .../public_circuit_public_inputs.test.ts | 9 ++++ 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/public_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/public_circuit_public_inputs.nr index 6862e3f5e79..87229aecac6 100644 --- a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/public_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/public_circuit_public_inputs.nr @@ -117,7 +117,10 @@ fn serialization_of_empty() { } #[test] -fn hash_smoke() { - let pcpi: PublicCircuitPublicInputs = dep::std::unsafe::zeroed(); - let _hashed = pcpi.hash(); +fn empty_hash() { + let inputs: PublicCircuitPublicInputs = dep::std::unsafe::zeroed(); + let hash = inputs.hash(); + + // Value from public_circuit_public_inputs.test.ts "computes empty item hash" test + assert_eq(hash, 0x0d43290c164ebc3d80d4d17f1939482d9d01ad503cebceb8c665d2bd96597a68); } diff --git a/yarn-project/circuits.js/src/structs/__snapshots__/public_circuit_public_inputs.test.ts.snap b/yarn-project/circuits.js/src/structs/__snapshots__/public_circuit_public_inputs.test.ts.snap index 67cd5e64828..87eca1e4dd2 100644 --- a/yarn-project/circuits.js/src/structs/__snapshots__/public_circuit_public_inputs.test.ts.snap +++ b/yarn-project/circuits.js/src/structs/__snapshots__/public_circuit_public_inputs.test.ts.snap @@ -1,5 +1,48 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`PublicCircuitPublicInputs computes empty item hash 1`] = ` +Fr { + "asBigInt": 5998729082391453463848740365500417056769011535294882115251337368669961943656n, + "asBuffer": { + "data": [ + 13, + 67, + 41, + 12, + 22, + 78, + 188, + 61, + 128, + 212, + 209, + 127, + 25, + 57, + 72, + 45, + 157, + 1, + 173, + 80, + 60, + 235, + 206, + 184, + 198, + 101, + 210, + 189, + 150, + 89, + 122, + 104, + ], + "type": "Buffer", + }, +} +`; + exports[`PublicCircuitPublicInputs hash matches snapshot 1`] = ` Fr { "asBigInt": 888846281962498247810067532853731271075966629879817122598695403485138176580n, diff --git a/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.test.ts b/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.test.ts index c72c462f8f0..1030dfec73e 100644 --- a/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.test.ts +++ b/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.test.ts @@ -28,4 +28,13 @@ describe('PublicCircuitPublicInputs', () => { const hash = target.hash(); expect(hash).toMatchSnapshot(); }); + + it('computes empty item hash', () => { + const item = PublicCircuitPublicInputs.empty(); + const hash = item.hash(); + expect(hash).toMatchSnapshot(); + + // Value used in empty_hash test in public_circuit_public_inputs.nr + // console.log("hash", hash.toString()); + }); }); From b86a4b1641f5777b783b659494cbcc4b5aff4c80 Mon Sep 17 00:00:00 2001 From: benesjan Date: Wed, 21 Feb 2024 17:05:31 +0000 Subject: [PATCH 5/5] fix --- .../end-to-end/src/e2e_inclusion_proofs_contract.test.ts | 2 +- .../src/block_builder/solo_block_builder.test.ts | 4 ++-- .../sequencer-client/src/block_builder/solo_block_builder.ts | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/yarn-project/end-to-end/src/e2e_inclusion_proofs_contract.test.ts b/yarn-project/end-to-end/src/e2e_inclusion_proofs_contract.test.ts index 94ec0016808..0fe30e0b8af 100644 --- a/yarn-project/end-to-end/src/e2e_inclusion_proofs_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_inclusion_proofs_contract.test.ts @@ -293,7 +293,7 @@ describe('e2e_inclusion_proofs_contract', () => { // This should fail because we choose a block number before the contract was deployed const blockNumber = deploymentBlockNumber - 1; const contractData = new NewContractData(contract.address, portalContractAddress, contractClassId); - const leaf = contractData.computeLeaf(); + const leaf = contractData.hash(); await expect( contract.methods diff --git a/yarn-project/sequencer-client/src/block_builder/solo_block_builder.test.ts b/yarn-project/sequencer-client/src/block_builder/solo_block_builder.test.ts index 20723f8299b..6196bc52879 100644 --- a/yarn-project/sequencer-client/src/block_builder/solo_block_builder.test.ts +++ b/yarn-project/sequencer-client/src/block_builder/solo_block_builder.test.ts @@ -136,7 +136,7 @@ describe('sequencer/solo_block_builder', () => { // Updates the expectedDb trees based on the new commitments, contracts, and nullifiers from these txs const updateExpectedTreesFromTxs = async (txs: ProcessedTx[]) => { - const newContracts = txs.flatMap(tx => tx.data.end.newContracts.map(cd => cd.computeLeaf())); + const newContracts = txs.flatMap(tx => tx.data.end.newContracts.map(cd => cd.hash())); for (const [tree, leaves] of [ [ MerkleTreeId.NOTE_HASH_TREE, @@ -235,7 +235,7 @@ describe('sequencer/solo_block_builder', () => { tx.data.combinedData.newNullifiers.map((n: SideEffectLinkedToNoteHash) => n.value), tx.data.combinedData.newL2ToL1Msgs, tx.data.combinedData.publicDataUpdateRequests.map(t => new PublicDataWrite(t.leafSlot, t.newValue)), - tx.data.combinedData.newContracts.map(cd => cd.computeLeaf()), + tx.data.combinedData.newContracts.map(cd => cd.hash()), tx.data.combinedData.newContracts.map(cd => new ContractData(cd.contractAddress, cd.portalContractAddress)), tx.encryptedLogs || new TxL2Logs([]), tx.unencryptedLogs || new TxL2Logs([]), diff --git a/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts b/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts index d65ce1bda9c..903b51a40d6 100644 --- a/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts +++ b/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts @@ -108,7 +108,7 @@ export class SoloBlockBuilder implements BlockBuilder { tx.data.combinedData.newNullifiers.map((n: SideEffectLinkedToNoteHash) => n.value), tx.data.combinedData.newL2ToL1Msgs, tx.data.combinedData.publicDataUpdateRequests.map(t => new PublicDataWrite(t.leafSlot, t.newValue)), - tx.data.combinedData.newContracts.map(cd => cd.computeLeaf()), + tx.data.combinedData.newContracts.map(cd => cd.hash()), tx.data.combinedData.newContracts.map(cd => new ContractData(cd.contractAddress, cd.portalContractAddress)), tx.encryptedLogs || new TxL2Logs([]), tx.unencryptedLogs || new TxL2Logs([]), @@ -602,7 +602,7 @@ export class SoloBlockBuilder implements BlockBuilder { // Update the contract and note hash trees with the new items being inserted to get the new roots // that will be used by the next iteration of the base rollup circuit, skipping the empty ones - const newContracts = tx.data.combinedData.newContracts.map(cd => cd.computeLeaf()); + const newContracts = tx.data.combinedData.newContracts.map(cd => cd.hash()); const newCommitments = tx.data.combinedData.newCommitments.map(x => x.value.toBuffer()); await this.db.appendLeaves(