Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarified tree ids #310

Merged
merged 1 commit into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion yarn-project/aztec-node/src/aztec-node/aztec-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,6 @@ export class AztecNode {
}

public getDataTreePath(leafIndex: bigint): Promise<SiblingPath> {
return this.merkleTreeDB.getSiblingPath(MerkleTreeId.DATA_TREE, leafIndex, false);
return this.merkleTreeDB.getSiblingPath(MerkleTreeId.PRIVATE_DATA_TREE, leafIndex, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe('sequencer/circuit_block_builder', () => {

const updateRootTrees = async () => {
for (const [newTree, rootTree] of [
[MerkleTreeId.DATA_TREE, MerkleTreeId.DATA_TREE_ROOTS_TREE],
[MerkleTreeId.PRIVATE_DATA_TREE, MerkleTreeId.PRIVATE_DATA_TREE_ROOTS_TREE],
[MerkleTreeId.CONTRACT_TREE, MerkleTreeId.CONTRACT_TREE_ROOTS_TREE],
] as const) {
const newTreeInfo = await expectsDb.getTreeInfo(newTree);
Expand All @@ -95,7 +95,7 @@ describe('sequencer/circuit_block_builder', () => {
const updateExpectedTreesFromTxs = async (txs: PrivateTx[]) => {
const newContracts = flatMap(txs, tx => tx.data.end.newContracts.map(n => computeContractLeaf(wasm, n)));
for (const [tree, leaves] of [
[MerkleTreeId.DATA_TREE, flatMap(txs, tx => tx.data.end.newCommitments.map(l => l.toBuffer()))],
[MerkleTreeId.PRIVATE_DATA_TREE, flatMap(txs, tx => tx.data.end.newCommitments.map(l => l.toBuffer()))],
[MerkleTreeId.CONTRACT_TREE, newContracts.map(x => x.toBuffer())],
[MerkleTreeId.NULLIFIER_TREE, flatMap(txs, tx => tx.data.end.newNullifiers.map(l => l.toBuffer()))],
] as const) {
Expand All @@ -110,7 +110,7 @@ describe('sequencer/circuit_block_builder', () => {

const setTxHistoricTreeRoots = async (tx: PrivateTx) => {
for (const [name, id] of [
['privateDataTreeRoot', MerkleTreeId.DATA_TREE],
['privateDataTreeRoot', MerkleTreeId.PRIVATE_DATA_TREE],
['contractTreeRoot', MerkleTreeId.CONTRACT_TREE],
['nullifierTreeRoot', MerkleTreeId.NULLIFIER_TREE],
] as const) {
Expand All @@ -136,24 +136,24 @@ describe('sequencer/circuit_block_builder', () => {
await updateExpectedTreesFromTxs(txsLeft);
baseRollupOutputLeft.endContractTreeSnapshot = await getTreeSnapshot(MerkleTreeId.CONTRACT_TREE);
baseRollupOutputLeft.endNullifierTreeSnapshot = await getTreeSnapshot(MerkleTreeId.NULLIFIER_TREE);
baseRollupOutputLeft.endPrivateDataTreeSnapshot = await getTreeSnapshot(MerkleTreeId.DATA_TREE);
baseRollupOutputLeft.endPrivateDataTreeSnapshot = await getTreeSnapshot(MerkleTreeId.PRIVATE_DATA_TREE);

// Same for the two txs on the right
await updateExpectedTreesFromTxs(txsRight);
baseRollupOutputRight.endContractTreeSnapshot = await getTreeSnapshot(MerkleTreeId.CONTRACT_TREE);
baseRollupOutputRight.endNullifierTreeSnapshot = await getTreeSnapshot(MerkleTreeId.NULLIFIER_TREE);
baseRollupOutputRight.endPrivateDataTreeSnapshot = await getTreeSnapshot(MerkleTreeId.DATA_TREE);
baseRollupOutputRight.endPrivateDataTreeSnapshot = await getTreeSnapshot(MerkleTreeId.PRIVATE_DATA_TREE);

// And update the root trees now to create proper output to the root rollup circuit
await updateRootTrees();
rootRollupOutput.endContractTreeSnapshot = await getTreeSnapshot(MerkleTreeId.CONTRACT_TREE);
rootRollupOutput.endNullifierTreeSnapshot = await getTreeSnapshot(MerkleTreeId.NULLIFIER_TREE);
rootRollupOutput.endPrivateDataTreeSnapshot = await getTreeSnapshot(MerkleTreeId.DATA_TREE);
rootRollupOutput.endPrivateDataTreeSnapshot = await getTreeSnapshot(MerkleTreeId.PRIVATE_DATA_TREE);
rootRollupOutput.endTreeOfHistoricContractTreeRootsSnapshot = await getTreeSnapshot(
MerkleTreeId.CONTRACT_TREE_ROOTS_TREE,
);
rootRollupOutput.endTreeOfHistoricPrivateDataTreeRootsSnapshot = await getTreeSnapshot(
MerkleTreeId.DATA_TREE_ROOTS_TREE,
MerkleTreeId.PRIVATE_DATA_TREE_ROOTS_TREE,
);

// Actually build a block!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ export class CircuitBlockBuilder implements BlockBuilder {
startTreeOfHistoricContractTreeRootsSnapshot,
] = await Promise.all(
[
MerkleTreeId.DATA_TREE,
MerkleTreeId.PRIVATE_DATA_TREE,
MerkleTreeId.NULLIFIER_TREE,
MerkleTreeId.CONTRACT_TREE,
MerkleTreeId.DATA_TREE_ROOTS_TREE,
MerkleTreeId.PRIVATE_DATA_TREE_ROOTS_TREE,
MerkleTreeId.CONTRACT_TREE_ROOTS_TREE,
].map(tree => this.getTreeSnapshot(tree)),
);
Expand Down Expand Up @@ -235,7 +235,7 @@ export class CircuitBlockBuilder implements BlockBuilder {
// Updates our roots trees with the new generated trees after the rollup updates
protected async updateRootTrees() {
for (const [newTree, rootTree] of [
[MerkleTreeId.DATA_TREE, MerkleTreeId.DATA_TREE_ROOTS_TREE],
[MerkleTreeId.PRIVATE_DATA_TREE, MerkleTreeId.PRIVATE_DATA_TREE_ROOTS_TREE],
[MerkleTreeId.CONTRACT_TREE, MerkleTreeId.CONTRACT_TREE_ROOTS_TREE],
] as const) {
const newTreeInfo = await this.db.getTreeInfo(newTree);
Expand All @@ -247,7 +247,7 @@ export class CircuitBlockBuilder implements BlockBuilder {
protected async validateTrees(rollupOutput: BaseOrMergeRollupPublicInputs | RootRollupPublicInputs) {
await Promise.all([
this.validateTree(rollupOutput, MerkleTreeId.CONTRACT_TREE, 'Contract'),
this.validateTree(rollupOutput, MerkleTreeId.DATA_TREE, 'PrivateData'),
this.validateTree(rollupOutput, MerkleTreeId.PRIVATE_DATA_TREE, 'PrivateData'),
this.validateTree(rollupOutput, MerkleTreeId.NULLIFIER_TREE, 'Nullifier'),
]);
}
Expand All @@ -257,7 +257,7 @@ export class CircuitBlockBuilder implements BlockBuilder {
await Promise.all([
this.validateTrees(rootOutput),
this.validateRootTree(rootOutput, MerkleTreeId.CONTRACT_TREE_ROOTS_TREE, 'Contract'),
this.validateRootTree(rootOutput, MerkleTreeId.DATA_TREE_ROOTS_TREE, 'PrivateData'),
this.validateRootTree(rootOutput, MerkleTreeId.PRIVATE_DATA_TREE_ROOTS_TREE, 'PrivateData'),
]);
}

Expand Down Expand Up @@ -326,7 +326,9 @@ export class CircuitBlockBuilder implements BlockBuilder {
const newHistoricContractDataTreeRootSiblingPath = await getRootTreeSiblingPath(
MerkleTreeId.CONTRACT_TREE_ROOTS_TREE,
);
const newHistoricPrivateDataTreeRootSiblingPath = await getRootTreeSiblingPath(MerkleTreeId.DATA_TREE_ROOTS_TREE);
const newHistoricPrivateDataTreeRootSiblingPath = await getRootTreeSiblingPath(
MerkleTreeId.PRIVATE_DATA_TREE_ROOTS_TREE,
);

return RootRollupInputs.from({
previousRollupData,
Expand Down Expand Up @@ -398,7 +400,7 @@ export class CircuitBlockBuilder implements BlockBuilder {
protected getDataMembershipWitnessFor(tx: PrivateTx) {
return this.getMembershipWitnessFor(
tx.data.constants.historicTreeRoots.privateDataTreeRoot,
MerkleTreeId.DATA_TREE_ROOTS_TREE,
MerkleTreeId.PRIVATE_DATA_TREE_ROOTS_TREE,
PRIVATE_DATA_TREE_ROOTS_TREE_HEIGHT,
);
}
Expand All @@ -410,7 +412,9 @@ export class CircuitBlockBuilder implements BlockBuilder {
privateKernelVkTreeRoot: FUTURE_FR,
publicKernelVkTreeRoot: FUTURE_FR,
startTreeOfHistoricContractTreeRootsSnapshot: await this.getTreeSnapshot(MerkleTreeId.CONTRACT_TREE_ROOTS_TREE),
startTreeOfHistoricPrivateDataTreeRootsSnapshot: await this.getTreeSnapshot(MerkleTreeId.DATA_TREE_ROOTS_TREE),
startTreeOfHistoricPrivateDataTreeRootsSnapshot: await this.getTreeSnapshot(
MerkleTreeId.PRIVATE_DATA_TREE_ROOTS_TREE,
),
treeOfHistoricL1ToL2MsgTreeRootsSnapshot: new AppendOnlyTreeSnapshot(DELETE_FR, DELETE_NUM),
});
}
Expand Down Expand Up @@ -685,7 +689,7 @@ export class CircuitBlockBuilder implements BlockBuilder {
const constants = await this.getConstantBaseRollupData();
const startNullifierTreeSnapshot = await this.getTreeSnapshot(MerkleTreeId.NULLIFIER_TREE);
const startContractTreeSnapshot = await this.getTreeSnapshot(MerkleTreeId.CONTRACT_TREE);
const startPrivateDataTreeSnapshot = await this.getTreeSnapshot(MerkleTreeId.DATA_TREE);
const startPrivateDataTreeSnapshot = await this.getTreeSnapshot(MerkleTreeId.PRIVATE_DATA_TREE);

// Update the contract and data 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
Expand All @@ -697,7 +701,7 @@ export class CircuitBlockBuilder implements BlockBuilder {
newContracts.map(x => x.toBuffer()),
);

await this.db.appendLeaves(MerkleTreeId.DATA_TREE, newCommitments);
await this.db.appendLeaves(MerkleTreeId.PRIVATE_DATA_TREE, newCommitments);

// Update the nullifier tree, capturing the low nullifier info for each individual operation
const newNullifiers = [...tx1.data.end.newNullifiers, ...tx2.data.end.newNullifiers];
Expand All @@ -713,7 +717,7 @@ export class CircuitBlockBuilder implements BlockBuilder {

// Get the subtree sibling paths for the circuit
const newCommitmentsSubtreeSiblingPath = await this.getSubtreeSiblingPath(
MerkleTreeId.DATA_TREE,
MerkleTreeId.PRIVATE_DATA_TREE,
BaseRollupInputs.PRIVATE_DATA_SUBTREE_HEIGHT,
);
const newContractsSubtreeSiblingPath = await this.getSubtreeSiblingPath(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ export class StandaloneBlockBuilder implements BlockBuilder {
constructor(private db: MerkleTreeOperations, private log = createDebugLogger('aztec:block_builder')) {}

async buildL2Block(blockNumber: number, txs: PrivateTx[]): Promise<[L2Block, Proof]> {
const startPrivateDataTreeSnapshot = await this.getTreeSnapshot(MerkleTreeId.DATA_TREE);
const startPrivateDataTreeSnapshot = await this.getTreeSnapshot(MerkleTreeId.PRIVATE_DATA_TREE);
const startNullifierTreeSnapshot = await this.getTreeSnapshot(MerkleTreeId.NULLIFIER_TREE);
const startContractTreeSnapshot = await this.getTreeSnapshot(MerkleTreeId.CONTRACT_TREE);
const startTreeOfHistoricPrivateDataTreeRootsSnapshot = await this.getTreeSnapshot(
MerkleTreeId.DATA_TREE_ROOTS_TREE,
MerkleTreeId.PRIVATE_DATA_TREE_ROOTS_TREE,
);
const startTreeOfHistoricContractTreeRootsSnapshot = await this.getTreeSnapshot(
MerkleTreeId.CONTRACT_TREE_ROOTS_TREE,
Expand All @@ -47,10 +47,12 @@ export class StandaloneBlockBuilder implements BlockBuilder {

await this.updateRootTrees();

const endPrivateDataTreeSnapshot = await this.getTreeSnapshot(MerkleTreeId.DATA_TREE);
const endPrivateDataTreeSnapshot = await this.getTreeSnapshot(MerkleTreeId.PRIVATE_DATA_TREE);
const endNullifierTreeSnapshot = await this.getTreeSnapshot(MerkleTreeId.NULLIFIER_TREE);
const endContractTreeSnapshot = await this.getTreeSnapshot(MerkleTreeId.CONTRACT_TREE);
const endTreeOfHistoricPrivateDataTreeRootsSnapshot = await this.getTreeSnapshot(MerkleTreeId.DATA_TREE_ROOTS_TREE);
const endTreeOfHistoricPrivateDataTreeRootsSnapshot = await this.getTreeSnapshot(
MerkleTreeId.PRIVATE_DATA_TREE_ROOTS_TREE,
);
const endTreeOfHistoricContractTreeRootsSnapshot = await this.getTreeSnapshot(
MerkleTreeId.CONTRACT_TREE_ROOTS_TREE,
);
Expand Down Expand Up @@ -89,7 +91,7 @@ export class StandaloneBlockBuilder implements BlockBuilder {
);

for (let i = 0; i < KERNEL_NEW_COMMITMENTS_LENGTH; i++) {
await this.db.appendLeaves(MerkleTreeId.DATA_TREE, [dataTreeLeaves[i]]);
await this.db.appendLeaves(MerkleTreeId.PRIVATE_DATA_TREE, [dataTreeLeaves[i]]);
}
for (let i = 0; i < KERNEL_NEW_NULLIFIERS_LENGTH; i++) {
await this.db.appendLeaves(MerkleTreeId.NULLIFIER_TREE, [nullifierTreeLeaves[i]]);
Expand All @@ -100,9 +102,9 @@ export class StandaloneBlockBuilder implements BlockBuilder {
}

private async updateRootTrees() {
const newDataTreeInfo = await this.getTreeSnapshot(MerkleTreeId.DATA_TREE);
const newDataTreeInfo = await this.getTreeSnapshot(MerkleTreeId.PRIVATE_DATA_TREE);
const newContractsTreeInfo = await this.getTreeSnapshot(MerkleTreeId.CONTRACT_TREE);
await this.db.appendLeaves(MerkleTreeId.CONTRACT_TREE_ROOTS_TREE, [newContractsTreeInfo.root.toBuffer()]);
await this.db.appendLeaves(MerkleTreeId.DATA_TREE_ROOTS_TREE, [newDataTreeInfo.root.toBuffer()]);
await this.db.appendLeaves(MerkleTreeId.PRIVATE_DATA_TREE_ROOTS_TREE, [newDataTreeInfo.root.toBuffer()]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@ export class ServerWorldStateSynchroniser implements WorldStateSynchroniser {
const rootChecks = await Promise.all([
compareRoot(l2Block.endContractTreeSnapshot.root.toBuffer(), MerkleTreeId.CONTRACT_TREE),
compareRoot(l2Block.endNullifierTreeSnapshot.root.toBuffer(), MerkleTreeId.NULLIFIER_TREE),
compareRoot(l2Block.endPrivateDataTreeSnapshot.root.toBuffer(), MerkleTreeId.DATA_TREE),
compareRoot(l2Block.endPrivateDataTreeSnapshot.root.toBuffer(), MerkleTreeId.PRIVATE_DATA_TREE),
compareRoot(
l2Block.endTreeOfHistoricContractTreeRootsSnapshot.root.toBuffer(),
MerkleTreeId.CONTRACT_TREE_ROOTS_TREE,
),
compareRoot(
l2Block.endTreeOfHistoricPrivateDataTreeRootsSnapshot.root.toBuffer(),
MerkleTreeId.DATA_TREE_ROOTS_TREE,
MerkleTreeId.PRIVATE_DATA_TREE_ROOTS_TREE,
),
]);
const ourBlock = rootChecks.every(x => x);
Expand All @@ -147,7 +147,7 @@ export class ServerWorldStateSynchroniser implements WorldStateSynchroniser {
for (const [tree, leaves] of [
[MerkleTreeId.CONTRACT_TREE, l2Block.newContracts],
[MerkleTreeId.NULLIFIER_TREE, l2Block.newNullifiers],
[MerkleTreeId.DATA_TREE, l2Block.newCommitments],
[MerkleTreeId.PRIVATE_DATA_TREE, l2Block.newCommitments],
] as const) {
await this.merkleTreeDb.appendLeaves(
tree,
Expand All @@ -156,7 +156,7 @@ export class ServerWorldStateSynchroniser implements WorldStateSynchroniser {
}

for (const [newTree, rootTree] of [
[MerkleTreeId.DATA_TREE, MerkleTreeId.DATA_TREE_ROOTS_TREE],
[MerkleTreeId.PRIVATE_DATA_TREE, MerkleTreeId.PRIVATE_DATA_TREE_ROOTS_TREE],
[MerkleTreeId.CONTRACT_TREE, MerkleTreeId.CONTRACT_TREE_ROOTS_TREE],
] as const) {
const newTreeInfo = await this.merkleTreeDb.getTreeInfo(newTree, true);
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/world-state/src/world-state-db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export enum MerkleTreeId {
CONTRACT_TREE = 0,
CONTRACT_TREE_ROOTS_TREE = 1,
NULLIFIER_TREE = 2,
DATA_TREE = 3,
DATA_TREE_ROOTS_TREE = 4,
PRIVATE_DATA_TREE = 3,
PRIVATE_DATA_TREE_ROOTS_TREE = 4,
PUBLIC_DATA_TREE = 5,
}

Expand Down
4 changes: 2 additions & 2 deletions yarn-project/world-state/src/world-state-db/merkle_trees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ export class MerkleTrees implements MerkleTreeDb {
StandardTree,
this.db,
hasher,
`${MerkleTreeId[MerkleTreeId.DATA_TREE]}`,
`${MerkleTreeId[MerkleTreeId.PRIVATE_DATA_TREE]}`,
PRIVATE_DATA_TREE_HEIGHT,
);
const privateDataTreeRootsTree: AppendOnlyTree = await newTree(
StandardTree,
this.db,
hasher,
`${MerkleTreeId[MerkleTreeId.DATA_TREE_ROOTS_TREE]}`,
`${MerkleTreeId[MerkleTreeId.PRIVATE_DATA_TREE_ROOTS_TREE]}`,
PRIVATE_DATA_TREE_ROOTS_TREE_HEIGHT,
);
const publicDataTree: UpdateOnlyTree = await newTree(
Expand Down