Skip to content
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
1 change: 1 addition & 0 deletions yarn-project/merkle-tree/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export * from './interfaces/merkle_tree.js';
export * from './interfaces/update_only_tree.js';
export * from './pedersen.js';
export * from './sibling_path/sibling_path.js';
export * from './sparse_tree/sparse_tree.js';
export * from './standard_indexed_tree/standard_indexed_tree.js';
export * from './standard_tree/standard_tree.js';
export { INITIAL_LEAF } from './tree_base.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ export class PublicProcessor {
for (const stateTransition of stateTransitions) {
const index = getLeafIndex(stateTransition.storageSlot);
transitionsHashPaths.push(await this.getMembershipWitness(index));
// TODO: Update tree once we got the interface for it
// this.db.updateLeaf(MerkleTreeId.PUBLIC_DATA_TREE, stateTransition.newValue, index);
await this.db.updateLeaf(MerkleTreeId.PUBLIC_DATA_TREE, stateTransition.newValue.toBuffer(), index);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks :-)

}

return { readsHashPaths, transitionsHashPaths };
Expand Down
3 changes: 2 additions & 1 deletion yarn-project/world-state/src/world-state-db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export enum MerkleTreeId {
}

export type IndexedTreeId = MerkleTreeId.NULLIFIER_TREE;
export type PublicTreeId = MerkleTreeId.PUBLIC_DATA_TREE;

/**
* The nullifier tree must be pre filled with the number of leaves that are added by one rollup.
Expand Down Expand Up @@ -104,7 +105,7 @@ export interface MerkleTreeOperations {
* @param leaf - The updated leaf value
* @param index - The index of the leaf to be updated
*/
updateLeaf(treeId: IndexedTreeId, leaf: LeafData, index: bigint): Promise<void>;
updateLeaf(treeId: IndexedTreeId | PublicTreeId, leaf: LeafData | Buffer, index: bigint): Promise<void>;
/**
* Returns the index containing a leaf value
* @param treeId - The tree for which the index should be returned
Expand Down
25 changes: 21 additions & 4 deletions yarn-project/world-state/src/world-state-db/merkle_trees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
NULLIFIER_TREE_HEIGHT,
PRIVATE_DATA_TREE_HEIGHT,
PRIVATE_DATA_TREE_ROOTS_TREE_HEIGHT,
PUBLIC_DATA_TREE_HEIGHT,
} from '@aztec/circuits.js';
import { SerialQueue } from '@aztec/foundation';
import { WasmWrapper } from '@aztec/foundation/wasm';
Expand All @@ -18,6 +19,7 @@ import {
UpdateOnlyTree,
IndexedTree,
newTree,
SparseTree,
} from '@aztec/merkle-tree';
import { default as levelup } from 'levelup';
import { MerkleTreeOperationsFacade } from '../merkle-tree/merkle_tree_operations_facade.js';
Expand All @@ -27,6 +29,7 @@ import {
MerkleTreeDb,
MerkleTreeId,
MerkleTreeOperations,
PublicTreeId,
TreeInfo,
} from './index.js';

Expand Down Expand Up @@ -67,21 +70,35 @@ export class MerkleTrees implements MerkleTreeDb {
NULLIFIER_TREE_HEIGHT,
INITIAL_NULLIFIER_TREE_SIZE,
);
const dataTree: AppendOnlyTree = await newTree(
const privateDataTree: AppendOnlyTree = await newTree(
StandardTree,
this.db,
hasher,
`${MerkleTreeId[MerkleTreeId.DATA_TREE]}`,
PRIVATE_DATA_TREE_HEIGHT,
);
const dataTreeRootsTree: AppendOnlyTree = await newTree(
const privateDataTreeRootsTree: AppendOnlyTree = await newTree(
StandardTree,
this.db,
hasher,
`${MerkleTreeId[MerkleTreeId.DATA_TREE_ROOTS_TREE]}`,
PRIVATE_DATA_TREE_ROOTS_TREE_HEIGHT,
);
this.trees = [contractTree, contractTreeRootsTree, nullifierTree, dataTree, dataTreeRootsTree];
const publicDataTree: UpdateOnlyTree = await newTree(
SparseTree,
this.db,
hasher,
`${MerkleTreeId[MerkleTreeId.PUBLIC_DATA_TREE]}`,
PUBLIC_DATA_TREE_HEIGHT,
);
this.trees = [
contractTree,
contractTreeRootsTree,
nullifierTree,
privateDataTree,
privateDataTreeRootsTree,
publicDataTree,
];
this.jobQueue.start();
}

Expand Down Expand Up @@ -221,7 +238,7 @@ export class MerkleTrees implements MerkleTreeDb {
* @param leaf - The new leaf value
* @param index - The index to insert into
*/
public async updateLeaf(treeId: IndexedTreeId, leaf: LeafData, index: bigint): Promise<void> {
public async updateLeaf(treeId: IndexedTreeId | PublicTreeId, leaf: LeafData | Buffer, index: bigint): Promise<void> {
const tree = this.trees[treeId];
if (!('updateLeaf' in tree)) {
throw new Error('Tree does not support `updateLeaf` method');
Expand Down