diff --git a/yarn-project/aztec-nr/aztec/src/history/nullifier_inclusion.nr b/yarn-project/aztec-nr/aztec/src/history/nullifier_inclusion.nr index f6f5185cace..43976dbd92c 100644 --- a/yarn-project/aztec-nr/aztec/src/history/nullifier_inclusion.nr +++ b/yarn-project/aztec-nr/aztec/src/history/nullifier_inclusion.nr @@ -17,17 +17,16 @@ pub fn prove_nullifier_inclusion( let witness = get_nullifier_membership_witness(block_number, nullifier); // 3) Check that the witness we obtained matches the nullifier - assert(witness.leaf_data.value == nullifier, "Nullifier does not match value in witness"); + assert(witness.leaf_preimage.nullifier == nullifier, "Nullifier does not match value in witness"); // 4) Compute the nullifier tree leaf - let nullifier_leaf = witness.leaf_data.hash(); + let nullifier_leaf = witness.leaf_preimage.hash(); // 5) Prove that the nullifier is in the nullifier tree assert( - block_header.nullifier_tree_root == compute_merkle_root(nullifier_leaf, witness.index, witness.path), - "Proving nullifier inclusion failed" + block_header.nullifier_tree_root + == compute_merkle_root(nullifier_leaf, witness.index, witness.path), "Proving nullifier inclusion failed" ); - // --> Now we have traversed the trees all the way up to archive root and verified that the nullifier // was not yet included in the nullifier tree. -} \ No newline at end of file +} diff --git a/yarn-project/aztec-nr/aztec/src/history/nullifier_non_inclusion.nr b/yarn-project/aztec-nr/aztec/src/history/nullifier_non_inclusion.nr index f491e55a2c1..47036d2f9f3 100644 --- a/yarn-project/aztec-nr/aztec/src/history/nullifier_non_inclusion.nr +++ b/yarn-project/aztec-nr/aztec/src/history/nullifier_non_inclusion.nr @@ -28,25 +28,23 @@ pub fn prove_nullifier_non_inclusion( // 3) Prove that the nullifier is not included in the nullifier tree // 3.a) Compute the low nullifier leaf and prove that it is in the nullifier tree - let low_nullifier_leaf = witness.leaf_data.hash(); + let low_nullifier_leaf = witness.leaf_preimage.hash(); assert( - block_header.nullifier_tree_root == compute_merkle_root(low_nullifier_leaf, witness.index, witness.path), - "Proving nullifier non-inclusion failed: Could not prove low nullifier inclusion" + block_header.nullifier_tree_root + == compute_merkle_root(low_nullifier_leaf, witness.index, witness.path), "Proving nullifier non-inclusion failed: Could not prove low nullifier inclusion" ); // 3.b) Prove that the low nullifier is smaller than the nullifier assert( - full_field_less_than(witness.leaf_data.value, nullifier), - "Proving nullifier non-inclusion failed: low_nullifier.value < nullifier.value check failed" + full_field_less_than(witness.leaf_preimage.nullifier, nullifier), "Proving nullifier non-inclusion failed: low_nullifier.value < nullifier.value check failed" ); // 3.c) Prove that the low nullifier is pointing "over" the nullifier to prove that the nullifier is not // included in the nullifier tree (or to 0 if the to-be-inserted nullifier is the largest of all) assert( - full_field_greater_than(witness.leaf_data.next_value, nullifier) | (witness.leaf_data.next_index == 0), - "Proving nullifier non-inclusion failed: low_nullifier.next_value > nullifier.value check failed" + full_field_greater_than(witness.leaf_preimage.next_nullifier, nullifier) + | (witness.leaf_preimage.next_index == 0), "Proving nullifier non-inclusion failed: low_nullifier.next_value > nullifier.value check failed" ); - // --> Now we have traversed the trees all the way up to archive root and verified that the nullifier // was not yet included in the nullifier tree. } @@ -60,4 +58,4 @@ pub fn prove_note_not_nullified( let nullifier = compute_siloed_nullifier(note_interface, note_with_header); prove_nullifier_non_inclusion(nullifier, block_number, context); -} \ No newline at end of file +} diff --git a/yarn-project/aztec-nr/aztec/src/oracle/get_nullifier_membership_witness.nr b/yarn-project/aztec-nr/aztec/src/oracle/get_nullifier_membership_witness.nr index 1ec413874cd..21138a3ecf1 100644 --- a/yarn-project/aztec-nr/aztec/src/oracle/get_nullifier_membership_witness.nr +++ b/yarn-project/aztec-nr/aztec/src/oracle/get_nullifier_membership_witness.nr @@ -1,50 +1,44 @@ use dep::protocol_types::{ + abis::nullifier_leaf_preimage::{ + NullifierLeafPreimage, + NULLIFIER_LEAF_PREIMAGE_LENGTH, + }, constants::NULLIFIER_TREE_HEIGHT, hash::pedersen_hash, }; use crate::utils::arr_copy_slice; -global LEAF_DATA_LENGTH: Field = 3; -// TODO: move this to constants.hpp so that it gets computed as INDEX_LENGTH + LEAF_DATA_LENGTH + NULLIFIER_TREE_HEIGHT +// INDEX_LENGTH + NULLIFIER_LEAF_PREIMAGE_LENGTH + NULLIFIER_TREE_HEIGHT global NULLIFIER_MEMBERSHIP_WITNESS: Field = 24; -// Noir version of LeafData interface from indexed merkle tree. -// TODO(#3470) replace with /mnt/user-data/jan/aztec-packages/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/abis/nullifier_leaf_preimage.nr -struct LeafData { - value: Field, - next_index: Field, - next_value: Field, -} - -impl LeafData { - fn serialize(self) -> [Field; LEAF_DATA_LENGTH] { - [self.value, self.next_index, self.next_value] - } - - fn hash(self) -> Field { - // Performs the same hashing as StandardIndexedTree::encodeLeaf(...) - pedersen_hash(self.serialize(), 0) - } -} - struct NullifierMembershipWitness { index: Field, - leaf_data: LeafData, + leaf_preimage: NullifierLeafPreimage, path: [Field; NULLIFIER_TREE_HEIGHT], } +impl NullifierMembershipWitness { + pub fn deserialize(fields: [Field; NULLIFIER_MEMBERSHIP_WITNESS]) -> Self { + let leaf_preimage_fields = arr_copy_slice(fields, [0; NULLIFIER_LEAF_PREIMAGE_LENGTH], 1); + Self { + index: fields[0], + leaf_preimage: NullifierLeafPreimage::deserialize(leaf_preimage_fields), + path: arr_copy_slice(fields, [0; NULLIFIER_TREE_HEIGHT], 1 + NULLIFIER_LEAF_PREIMAGE_LENGTH) + } + } +} + #[oracle(getLowNullifierMembershipWitness)] -fn get_low_nullifier_membership_witness_oracle(_block_number: u32, _nullifier: Field) -> [Field; NULLIFIER_MEMBERSHIP_WITNESS] {} +fn get_low_nullifier_membership_witness_oracle( + _block_number: u32, + _nullifier: Field +) -> [Field; NULLIFIER_MEMBERSHIP_WITNESS] {} // Nullifier here refers to the nullifier we are looking to get non-inclusion proof for (by proving that a lower // nullifier's next_value is bigger than the nullifier) unconstrained pub fn get_low_nullifier_membership_witness(block_number: u32, nullifier: Field) -> NullifierMembershipWitness { let fields = get_low_nullifier_membership_witness_oracle(block_number, nullifier); - NullifierMembershipWitness { - index: fields[0], - leaf_data: LeafData { value: fields[1], next_index: fields[2], next_value: fields[3] }, - path: arr_copy_slice(fields, [0; NULLIFIER_TREE_HEIGHT], 1 + LEAF_DATA_LENGTH) - } + NullifierMembershipWitness::deserialize(fields) } #[oracle(getNullifierMembershipWitness)] @@ -54,9 +48,5 @@ fn get_nullifier_membership_witness_oracle(_block_number: u32, _nullifier: Field // nullifier's next_value is bigger than the nullifier) unconstrained pub fn get_nullifier_membership_witness(block_number: u32, nullifier: Field) -> NullifierMembershipWitness { let fields = get_nullifier_membership_witness_oracle(block_number, nullifier); - NullifierMembershipWitness { - index: fields[0], - leaf_data: LeafData { value: fields[1], next_index: fields[2], next_value: fields[3] }, - path: arr_copy_slice(fields, [0; NULLIFIER_TREE_HEIGHT], 1 + LEAF_DATA_LENGTH) - } -} \ No newline at end of file + NullifierMembershipWitness::deserialize(fields) +} diff --git a/yarn-project/circuits.js/src/structs/rollup/nullifier_leaf/index.ts b/yarn-project/circuits.js/src/structs/rollup/nullifier_leaf/index.ts index b6bdba72e51..e3546794f19 100644 --- a/yarn-project/circuits.js/src/structs/rollup/nullifier_leaf/index.ts +++ b/yarn-project/circuits.js/src/structs/rollup/nullifier_leaf/index.ts @@ -45,11 +45,15 @@ export class NullifierLeafPreimage implements IndexedTreeLeafPreimage { toHashInputs(): Buffer[] { return [ Buffer.from(this.nullifier.toBuffer()), - Buffer.from(toBufferBE(this.nextIndex, 32)), Buffer.from(this.nextNullifier.toBuffer()), + Buffer.from(toBufferBE(this.nextIndex, 32)), ]; } + toFieldArray(): Fr[] { + return this.toHashInputs().map(buf => Fr.fromBuffer(buf)); + } + clone(): NullifierLeafPreimage { return new NullifierLeafPreimage(this.nullifier, this.nextNullifier, this.nextIndex); } @@ -60,8 +64,8 @@ export class NullifierLeafPreimage implements IndexedTreeLeafPreimage { static fromBuffer(buf: Buffer): NullifierLeafPreimage { const nullifier = Fr.fromBuffer(buf.subarray(0, 32)); - const nextIndex = toBigIntBE(buf.subarray(32, 64)); - const nextNullifier = Fr.fromBuffer(buf.subarray(64, 96)); + const nextNullifier = Fr.fromBuffer(buf.subarray(32, 64)); + const nextIndex = toBigIntBE(buf.subarray(64, 96)); return new NullifierLeafPreimage(nullifier, nextNullifier, nextIndex); } diff --git a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/abis.nr b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/abis.nr index e8a3e182b10..e1de429f5e5 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/abis.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/abis.nr @@ -1,4 +1,3 @@ -mod nullifier_leaf_preimage; mod public_data_tree_leaf; mod append_only_tree_snapshot; mod global_variables; diff --git a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/abis/nullifier_leaf_preimage.nr b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/abis/nullifier_leaf_preimage.nr deleted file mode 100644 index b55f943f25c..00000000000 --- a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/abis/nullifier_leaf_preimage.nr +++ /dev/null @@ -1,27 +0,0 @@ -struct NullifierLeafPreimage { - leaf_value : Field, - next_value :Field, - next_index : u32, -} - -impl NullifierLeafPreimage { - pub fn default() -> Self { - Self { - leaf_value : 0, - next_value : 0, - next_index : 0, - } - } - - pub fn is_empty(self) -> bool { - (self.leaf_value == 0) & (self.next_index == 0) & (self.next_value == 0) - } - - pub fn hash(self) -> Field { - if self.is_empty() { - 0 - } else { - dep::std::hash::pedersen_hash([self.leaf_value, (self.next_index as Field), self.next_value]) - } - } -} \ No newline at end of file diff --git a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/base/base_rollup_inputs.nr b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/base/base_rollup_inputs.nr index 270f7b5fce7..edcedf846b0 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/base/base_rollup_inputs.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/base/base_rollup_inputs.nr @@ -1,4 +1,3 @@ -use crate::abis::nullifier_leaf_preimage::NullifierLeafPreimage; use crate::abis::public_data_tree_leaf::{PublicDataTreeLeaf, PublicDataTreeLeafPreimage}; use crate::abis::append_only_tree_snapshot::AppendOnlyTreeSnapshot; use crate::abis::constant_rollup_data::ConstantRollupData; @@ -33,6 +32,7 @@ use dep::types::constants::{ use dep::types::abis::previous_kernel_data::PreviousKernelData; use dep::types::abis::membership_witness::{NullifierMembershipWitness, PublicDataMembershipWitness, MembershipWitness}; use dep::types::abis::membership_witness::ArchiveRootMembershipWitness; +use dep::types::abis::nullifier_leaf_preimage::NullifierLeafPreimage; struct BaseRollupInputs { kernel_data: PreviousKernelData, @@ -187,25 +187,25 @@ impl BaseRollupInputs { |nullifier: Field| {nullifier == 0}, // Nullifier is zero |leaf: NullifierLeafPreimage| {leaf.hash()}, // Hash leaf |low_leaf: NullifierLeafPreimage, nullifier: Field| { // Is valid low leaf - let is_less_than_nullifier = full_field_less_than(low_leaf.leaf_value, nullifier); - let is_next_greater_than = full_field_less_than(nullifier, low_leaf.next_value); + let is_less_than_nullifier = full_field_less_than(low_leaf.nullifier, nullifier); + let is_next_greater_than = full_field_less_than(nullifier, low_leaf.next_nullifier); (!low_leaf.is_empty()) & is_less_than_nullifier & ( is_next_greater_than | - ((low_leaf.next_index == 0) & (low_leaf.next_value == 0)) + ((low_leaf.next_index == 0) & (low_leaf.next_nullifier == 0)) ) }, |low_leaf: NullifierLeafPreimage, nullifier: Field, nullifier_index: u32| { // Update low leaf NullifierLeafPreimage{ - leaf_value : low_leaf.leaf_value, - next_value : nullifier, + nullifier : low_leaf.nullifier, + next_nullifier : nullifier, next_index : nullifier_index, } }, |nullifier: Field, low_leaf: NullifierLeafPreimage| { // Build insertion leaf NullifierLeafPreimage { - leaf_value : nullifier, - next_value : low_leaf.next_value, + nullifier : nullifier, + next_nullifier : low_leaf.next_nullifier, next_index : low_leaf.next_index, } }, @@ -567,7 +567,6 @@ mod tests { merkle_tree::{calculate_subtree, calculate_empty_tree_root}, abis::append_only_tree_snapshot::AppendOnlyTreeSnapshot, abis::base_or_merge_rollup_public_inputs::BaseOrMergeRollupPublicInputs, - abis::nullifier_leaf_preimage::NullifierLeafPreimage, abis::public_data_tree_leaf::{PublicDataTreeLeafPreimage, PublicDataTreeLeaf}, abis::constant_rollup_data::ConstantRollupData, tests::merkle_tree_utils::{NonEmptyMerkleTree, compute_zero_hashes}, @@ -598,6 +597,7 @@ mod tests { abis::membership_witness::ArchiveRootMembershipWitness, abis::membership_witness::{NullifierMembershipWitness, PublicDataMembershipWitness}, abis::new_contract_data::NewContractData, + abis::nullifier_leaf_preimage::NullifierLeafPreimage, abis::public_data_read::PublicDataRead, abis::public_data_update_request::PublicDataUpdateRequest, abis::previous_kernel_data::PreviousKernelData, @@ -804,7 +804,7 @@ mod tests { sibling_path: nullifier_tree.get_sibling_path(low_index as Field) }; - low_preimage.next_value = new_nullifier; + low_preimage.next_nullifier = new_nullifier; low_preimage.next_index = start_nullifier_tree_snapshot.next_available_leaf_index + original_index; pre_existing_nullifiers[low_index] = low_preimage; @@ -1058,13 +1058,13 @@ mod tests { let mut builder = BaseRollupInputsBuilder::new(); builder.pre_existing_nullifiers[0] = NullifierLeafPreimage { - leaf_value : 0, - next_value : 7, + nullifier : 0, + next_nullifier : 7, next_index : 1, }; builder.pre_existing_nullifiers[1] = NullifierLeafPreimage { - leaf_value : 7, - next_value : 0, + nullifier : 7, + next_nullifier : 0, next_index : 0, }; @@ -1076,27 +1076,27 @@ mod tests { let mut builder = BaseRollupInputsBuilder::new(); builder.pre_existing_nullifiers[0] = NullifierLeafPreimage { - leaf_value : 0, - next_value : 7, + nullifier : 0, + next_nullifier : 7, next_index : 1, }; builder.pre_existing_nullifiers[1] = NullifierLeafPreimage { - leaf_value : 7, - next_value : 0, + nullifier : 7, + next_nullifier : 0, next_index : 0, }; builder.new_nullifiers.push(NullifierInsertion { existing_index: 0, value: 1 }); let mut tree_nullifiers = [NullifierLeafPreimage::default(); MAX_NEW_NULLIFIERS_PER_TX * 2]; tree_nullifiers[0] = NullifierLeafPreimage { - leaf_value : 0, - next_value : 1, + nullifier : 0, + next_nullifier : 1, next_index : MAX_NEW_NULLIFIERS_PER_TX as u32, }; tree_nullifiers[1] = builder.pre_existing_nullifiers[1]; tree_nullifiers[MAX_NEW_NULLIFIERS_PER_TX] = NullifierLeafPreimage { - leaf_value : 1, - next_value : 7, + nullifier : 1, + next_nullifier : 7, next_index : 1, }; @@ -1121,13 +1121,13 @@ mod tests { let mut builder = BaseRollupInputsBuilder::new(); builder.pre_existing_nullifiers[0] = NullifierLeafPreimage { - leaf_value : 0, - next_value : 7, + nullifier : 0, + next_nullifier : 7, next_index : 1, }; builder.pre_existing_nullifiers[1] = NullifierLeafPreimage { - leaf_value : 7, - next_value : 0, + nullifier : 7, + next_nullifier : 0, next_index : 0, }; @@ -1141,22 +1141,22 @@ mod tests { tree_nullifiers[0] = builder.pre_existing_nullifiers[0]; tree_nullifiers[1] = NullifierLeafPreimage { - leaf_value : 7, - next_value : 8, + nullifier : 7, + next_nullifier : 8, next_index : MAX_NEW_NULLIFIERS_PER_TX as u32, }; let last_index = builder.new_nullifiers.max_len() - 1; for i in 0..last_index { tree_nullifiers[MAX_NEW_NULLIFIERS_PER_TX + i] = NullifierLeafPreimage { - leaf_value : (8 + i) as Field, - next_value : (8 + i + 1) as Field, + nullifier : (8 + i) as Field, + next_nullifier : (8 + i + 1) as Field, next_index : (MAX_NEW_NULLIFIERS_PER_TX + i) as u32 + 1, }; } tree_nullifiers[MAX_NEW_NULLIFIERS_PER_TX+last_index] = NullifierLeafPreimage { - leaf_value : (8 + last_index) as Field, - next_value : 0, + nullifier : (8 + last_index) as Field, + next_nullifier : 0, next_index : 0, }; @@ -1179,13 +1179,13 @@ mod tests { let mut builder = BaseRollupInputsBuilder::new(); builder.pre_existing_nullifiers[0] = NullifierLeafPreimage { - leaf_value : 0, - next_value : 7, + nullifier : 0, + next_nullifier : 7, next_index : 1, }; builder.pre_existing_nullifiers[1] = NullifierLeafPreimage { - leaf_value : 7, - next_value : 0, + nullifier : 7, + next_nullifier : 0, next_index : 0, }; @@ -1200,13 +1200,13 @@ mod tests { let mut builder = BaseRollupInputsBuilder::new(); builder.pre_existing_nullifiers[0] = NullifierLeafPreimage { - leaf_value : 0, - next_value : 7, + nullifier : 0, + next_nullifier : 7, next_index : 1, }; builder.pre_existing_nullifiers[1] = NullifierLeafPreimage { - leaf_value : 7, - next_value : 0, + nullifier : 7, + next_nullifier : 0, next_index : 0, }; diff --git a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/root/root_rollup_inputs.nr b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/root/root_rollup_inputs.nr index 37f64928e8b..7426e7dc4bd 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/root/root_rollup_inputs.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/root/root_rollup_inputs.nr @@ -1,12 +1,14 @@ -use crate::abis::nullifier_leaf_preimage::NullifierLeafPreimage; use crate::abis::previous_rollup_data::PreviousRollupData; use crate::abis::append_only_tree_snapshot::AppendOnlyTreeSnapshot; use crate::abis::constant_rollup_data::ConstantRollupData; -use dep::types::constants::{ - NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, - L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH, - ARCHIVE_HEIGHT +use dep::types::{ + abis::nullifier_leaf_preimage::NullifierLeafPreimage, + constants::{ + NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, + L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH, + ARCHIVE_HEIGHT + }, }; struct RootRollupInputs { diff --git a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/root/root_rollup_public_inputs.nr b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/root/root_rollup_public_inputs.nr index 55f658a0eb4..dda2dd7737f 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/root/root_rollup_public_inputs.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/root/root_rollup_public_inputs.nr @@ -1,9 +1,11 @@ -use crate::abis::nullifier_leaf_preimage::NullifierLeafPreimage; use crate::abis::append_only_tree_snapshot::AppendOnlyTreeSnapshot; use crate::abis::constant_rollup_data::ConstantRollupData; use crate::abis::global_variables::GlobalVariables; -use dep::types::constants::{ - NUM_FIELDS_PER_SHA256 +use dep::types::{ + abis::nullifier_leaf_preimage::NullifierLeafPreimage, + constants::{ + NUM_FIELDS_PER_SHA256 + }, }; use dep::types::mocked::AggregationObject; diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/abis.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/abis.nr index dd2b52402df..be0cef73ae8 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/abis.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/abis.nr @@ -5,6 +5,7 @@ mod function_leaf_preimage; mod membership_witness; mod new_contract_data; +mod nullifier_leaf_preimage; mod contract_leaf_preimage; mod block_header; diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/nullifier_leaf_preimage.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/nullifier_leaf_preimage.nr new file mode 100644 index 00000000000..681bd115686 --- /dev/null +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/nullifier_leaf_preimage.nr @@ -0,0 +1,41 @@ +global NULLIFIER_LEAF_PREIMAGE_LENGTH: Field = 3; + +struct NullifierLeafPreimage { + nullifier : Field, + next_nullifier :Field, + next_index : u32, +} + +impl NullifierLeafPreimage { + pub fn default() -> Self { + Self { + nullifier : 0, + next_nullifier : 0, + next_index : 0, + } + } + + pub fn is_empty(self) -> bool { + (self.nullifier == 0) & (self.next_nullifier == 0) & (self.next_index == 0) + } + + pub fn hash(self) -> Field { + if self.is_empty() { + 0 + } else { + dep::std::hash::pedersen_hash(self.serialize()) + } + } + + pub fn serialize(self) -> [Field; NULLIFIER_LEAF_PREIMAGE_LENGTH] { + [self.nullifier, self.next_nullifier, self.next_index as Field] + } + + pub fn deserialize(fields: [Field; NULLIFIER_LEAF_PREIMAGE_LENGTH]) -> Self { + Self { + nullifier: fields[0], + next_nullifier: fields[1], + next_index: fields[2] as u32, + } + } +} diff --git a/yarn-project/noir-protocol-circuits/src/type_conversion.ts b/yarn-project/noir-protocol-circuits/src/type_conversion.ts index 07f54666801..ebdbc3164c4 100644 --- a/yarn-project/noir-protocol-circuits/src/type_conversion.ts +++ b/yarn-project/noir-protocol-circuits/src/type_conversion.ts @@ -1300,8 +1300,8 @@ export function mapNullifierLeafPreimageToNoir( nullifierLeafPreimage: NullifierLeafPreimage, ): NullifierLeafPreimageNoir { return { - leaf_value: mapFieldToNoir(nullifierLeafPreimage.nullifier), - next_value: mapFieldToNoir(nullifierLeafPreimage.nextNullifier), + nullifier: mapFieldToNoir(nullifierLeafPreimage.nullifier), + next_nullifier: mapFieldToNoir(nullifierLeafPreimage.nextNullifier), next_index: mapNumberToNoir(Number(nullifierLeafPreimage.nextIndex)), }; } diff --git a/yarn-project/noir-protocol-circuits/src/types/rollup_base_types.ts b/yarn-project/noir-protocol-circuits/src/types/rollup_base_types.ts index 2363aa4b6e4..6bf79227a05 100644 --- a/yarn-project/noir-protocol-circuits/src/types/rollup_base_types.ts +++ b/yarn-project/noir-protocol-circuits/src/types/rollup_base_types.ts @@ -148,8 +148,8 @@ export interface AppendOnlyTreeSnapshot { } export interface NullifierLeafPreimage { - leaf_value: Field; - next_value: Field; + nullifier: Field; + next_nullifier: Field; next_index: u32; } diff --git a/yarn-project/types/src/interfaces/nullifier_tree.ts b/yarn-project/types/src/interfaces/nullifier_tree.ts index 14fdf426b8d..b9f5af3df34 100644 --- a/yarn-project/types/src/interfaces/nullifier_tree.ts +++ b/yarn-project/types/src/interfaces/nullifier_tree.ts @@ -29,12 +29,6 @@ export class NullifierMembershipWitness { * @returns A field array representation of a nullifier witness. */ public toFieldArray(): Fr[] { - return [ - new Fr(this.index), - new Fr(this.leafPreimage.nullifier), - new Fr(this.leafPreimage.nextIndex), - new Fr(this.leafPreimage.nextNullifier), - ...this.siblingPath.toFieldArray(), - ]; + return [new Fr(this.index), ...this.leafPreimage.toFieldArray(), ...this.siblingPath.toFieldArray()]; } }