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()); + }); });