Skip to content

Commit

Permalink
feat: change nullifier tree height to 20 (#2988)
Browse files Browse the repository at this point in the history
Fix #2947.

Note - had to change the nullifier height to 20 instead of 32 since
circuit tests use `NullifierMemoryTreeTestingHarness` which uses BB's
Memory Tree which is limited to a max height of 20. I can't change it to
32 due to bad_alloc.
  • Loading branch information
rahul-kothari authored Oct 24, 2023
1 parent a9678d1 commit 118f9d5
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 141 deletions.
2 changes: 1 addition & 1 deletion circuits/cpp/src/aztec3/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ constexpr size_t FUNCTION_TREE_HEIGHT = 4;
constexpr size_t CONTRACT_TREE_HEIGHT = 16;
constexpr size_t NOTE_HASH_TREE_HEIGHT = 32;
constexpr size_t PUBLIC_DATA_TREE_HEIGHT = 254;
constexpr size_t NULLIFIER_TREE_HEIGHT = 16;
constexpr size_t NULLIFIER_TREE_HEIGHT = 20;
constexpr size_t L1_TO_L2_MSG_TREE_HEIGHT = 16;
constexpr size_t HISTORIC_BLOCKS_TREE_HEIGHT = 16;
constexpr size_t ROLLUP_VK_TREE_HEIGHT = 8; // TODO: update
Expand Down
4 changes: 2 additions & 2 deletions l1-contracts/src/core/libraries/ConstantsGen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ library Constants {
uint256 internal constant CONTRACT_TREE_HEIGHT = 16;
uint256 internal constant NOTE_HASH_TREE_HEIGHT = 32;
uint256 internal constant PUBLIC_DATA_TREE_HEIGHT = 254;
uint256 internal constant NULLIFIER_TREE_HEIGHT = 16;
uint256 internal constant NULLIFIER_TREE_HEIGHT = 20;
uint256 internal constant L1_TO_L2_MSG_TREE_HEIGHT = 16;
uint256 internal constant ROLLUP_VK_TREE_HEIGHT = 8;
uint256 internal constant CONTRACT_SUBTREE_HEIGHT = 1;
Expand All @@ -57,7 +57,7 @@ library Constants {
uint256 internal constant NOTE_HASH_SUBTREE_SIBLING_PATH_LENGTH = 25;
uint256 internal constant NULLIFIER_SUBTREE_HEIGHT = 7;
uint256 internal constant HISTORIC_BLOCKS_TREE_HEIGHT = 16;
uint256 internal constant NULLIFIER_SUBTREE_SIBLING_PATH_LENGTH = 9;
uint256 internal constant NULLIFIER_SUBTREE_SIBLING_PATH_LENGTH = 13;
uint256 internal constant L1_TO_L2_MSG_SUBTREE_HEIGHT = 4;
uint256 internal constant L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH = 12;
uint256 internal constant FUNCTION_SELECTOR_NUM_BYTES = 4;
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/aztec-nr/aztec/src/constants_gen.nr
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ global FUNCTION_TREE_HEIGHT: Field = 4;
global CONTRACT_TREE_HEIGHT: Field = 16;
global NOTE_HASH_TREE_HEIGHT: Field = 32;
global PUBLIC_DATA_TREE_HEIGHT: Field = 254;
global NULLIFIER_TREE_HEIGHT: Field = 16;
global NULLIFIER_TREE_HEIGHT: Field = 20;
global L1_TO_L2_MSG_TREE_HEIGHT: Field = 16;
global ROLLUP_VK_TREE_HEIGHT: Field = 8;
global CONTRACT_SUBTREE_HEIGHT: Field = 1;
Expand All @@ -42,7 +42,7 @@ global NOTE_HASH_SUBTREE_HEIGHT: Field = 7;
global NOTE_HASH_SUBTREE_SIBLING_PATH_LENGTH: Field = 25;
global NULLIFIER_SUBTREE_HEIGHT: Field = 7;
global HISTORIC_BLOCKS_TREE_HEIGHT: Field = 16;
global NULLIFIER_SUBTREE_SIBLING_PATH_LENGTH: Field = 9;
global NULLIFIER_SUBTREE_SIBLING_PATH_LENGTH: Field = 13;
global L1_TO_L2_MSG_SUBTREE_HEIGHT: Field = 4;
global L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH: Field = 12;
global FUNCTION_SELECTOR_NUM_BYTES: Field = 4;
Expand Down
42 changes: 37 additions & 5 deletions yarn-project/circuits.js/src/cbind/circuits.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
MembershipWitness4,
MembershipWitness8,
MembershipWitness16,
MembershipWitness20,
MergeRollupInputs,
NativeAggregationState,
NewContractData,
Expand Down Expand Up @@ -2365,6 +2366,37 @@ export function fromNullifierLeafPreimage(o: NullifierLeafPreimage): MsgpackNull
};
}

interface MsgpackMembershipWitness20 {
leaf_index: Buffer;
sibling_path: Tuple<Buffer, 20>;
}

export function toMembershipWitness20(o: MsgpackMembershipWitness20): MembershipWitness20 {
if (o.leaf_index === undefined) {
throw new Error('Expected leaf_index in MembershipWitness20 deserialization');
}
if (o.sibling_path === undefined) {
throw new Error('Expected sibling_path in MembershipWitness20 deserialization');
}
return new MembershipWitness20(
Fr.fromBuffer(o.leaf_index),
mapTuple(o.sibling_path, (v: Buffer) => Fr.fromBuffer(v)),
);
}

export function fromMembershipWitness20(o: MembershipWitness20): MsgpackMembershipWitness20 {
if (o.leafIndex === undefined) {
throw new Error('Expected leafIndex in MembershipWitness20 serialization');
}
if (o.siblingPath === undefined) {
throw new Error('Expected siblingPath in MembershipWitness20 serialization');
}
return {
leaf_index: toBuffer(o.leafIndex),
sibling_path: mapTuple(o.siblingPath, (v: Fr) => toBuffer(v)),
};
}

interface MsgpackConstantRollupData {
start_historic_blocks_tree_roots_snapshot: MsgpackAppendOnlyTreeSnapshot;
private_kernel_vk_tree_root: Buffer;
Expand Down Expand Up @@ -2440,9 +2472,9 @@ interface MsgpackBaseRollupInputs {
start_public_data_tree_root: Buffer;
start_historic_blocks_tree_snapshot: MsgpackAppendOnlyTreeSnapshot;
low_nullifier_leaf_preimages: Tuple<MsgpackNullifierLeafPreimage, 128>;
low_nullifier_membership_witness: Tuple<MsgpackMembershipWitness16, 128>;
low_nullifier_membership_witness: Tuple<MsgpackMembershipWitness20, 128>;
new_commitments_subtree_sibling_path: Tuple<Buffer, 25>;
new_nullifiers_subtree_sibling_path: Tuple<Buffer, 9>;
new_nullifiers_subtree_sibling_path: Tuple<Buffer, 13>;
new_contracts_subtree_sibling_path: Tuple<Buffer, 15>;
new_public_data_update_requests_sibling_paths: Tuple<Tuple<Buffer, 254>, 32>;
new_public_data_reads_sibling_paths: Tuple<Tuple<Buffer, 254>, 32>;
Expand Down Expand Up @@ -2504,7 +2536,7 @@ export function toBaseRollupInputs(o: MsgpackBaseRollupInputs): BaseRollupInputs
Fr.fromBuffer(o.start_public_data_tree_root),
toAppendOnlyTreeSnapshot(o.start_historic_blocks_tree_snapshot),
mapTuple(o.low_nullifier_leaf_preimages, (v: MsgpackNullifierLeafPreimage) => toNullifierLeafPreimage(v)),
mapTuple(o.low_nullifier_membership_witness, (v: MsgpackMembershipWitness16) => toMembershipWitness16(v)),
mapTuple(o.low_nullifier_membership_witness, (v: MsgpackMembershipWitness20) => toMembershipWitness20(v)),
mapTuple(o.new_commitments_subtree_sibling_path, (v: Buffer) => Fr.fromBuffer(v)),
mapTuple(o.new_nullifiers_subtree_sibling_path, (v: Buffer) => Fr.fromBuffer(v)),
mapTuple(o.new_contracts_subtree_sibling_path, (v: Buffer) => Fr.fromBuffer(v)),
Expand Down Expand Up @@ -2577,8 +2609,8 @@ export function fromBaseRollupInputs(o: BaseRollupInputs): MsgpackBaseRollupInpu
low_nullifier_leaf_preimages: mapTuple(o.lowNullifierLeafPreimages, (v: NullifierLeafPreimage) =>
fromNullifierLeafPreimage(v),
),
low_nullifier_membership_witness: mapTuple(o.lowNullifierMembershipWitness, (v: MembershipWitness16) =>
fromMembershipWitness16(v),
low_nullifier_membership_witness: mapTuple(o.lowNullifierMembershipWitness, (v: MembershipWitness20) =>
fromMembershipWitness20(v),
),
new_commitments_subtree_sibling_path: mapTuple(o.newCommitmentsSubtreeSiblingPath, (v: Fr) => toBuffer(v)),
new_nullifiers_subtree_sibling_path: mapTuple(o.newNullifiersSubtreeSiblingPath, (v: Fr) => toBuffer(v)),
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/circuits.js/src/cbind/constants.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const FUNCTION_TREE_HEIGHT = 4;
export const CONTRACT_TREE_HEIGHT = 16;
export const NOTE_HASH_TREE_HEIGHT = 32;
export const PUBLIC_DATA_TREE_HEIGHT = 254;
export const NULLIFIER_TREE_HEIGHT = 16;
export const NULLIFIER_TREE_HEIGHT = 20;
export const L1_TO_L2_MSG_TREE_HEIGHT = 16;
export const ROLLUP_VK_TREE_HEIGHT = 8;
export const CONTRACT_SUBTREE_HEIGHT = 1;
Expand All @@ -43,7 +43,7 @@ export const NOTE_HASH_SUBTREE_HEIGHT = 7;
export const NOTE_HASH_SUBTREE_SIBLING_PATH_LENGTH = 25;
export const NULLIFIER_SUBTREE_HEIGHT = 7;
export const HISTORIC_BLOCKS_TREE_HEIGHT = 16;
export const NULLIFIER_SUBTREE_SIBLING_PATH_LENGTH = 9;
export const NULLIFIER_SUBTREE_SIBLING_PATH_LENGTH = 13;
export const L1_TO_L2_MSG_SUBTREE_HEIGHT = 4;
export const L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH = 12;
export const FUNCTION_SELECTOR_NUM_BYTES = 4;
Expand Down
18 changes: 18 additions & 0 deletions yarn-project/circuits.js/src/cbind/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@ import { Tuple } from '@aztec/foundation/serialize';

import { MembershipWitness } from '../structs/membership_witness.js';

/**
* Alias for msgpack which expects a MembershipWitness + N name.
*/
export class MembershipWitness20 extends MembershipWitness<20> {
constructor(
/**
* Index of a leaf in the Merkle tree.
*/
leafIndex: Fr,
/**
* Sibling path of the leaf in the Merkle tree.
*/
siblingPath: Tuple<Fr, 20>,
) {
super(20, leafIndex.toBigInt(), siblingPath);
}
}

/**
* Alias for msgpack which expects a MembershipWitness + N name.
*/
Expand Down
Loading

0 comments on commit 118f9d5

Please sign in to comment.