Skip to content

Commit

Permalink
Remove anys in getSnapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
spalladino authored and alexghr committed Mar 25, 2024
1 parent f4742af commit 26ca197
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 15 deletions.
11 changes: 9 additions & 2 deletions yarn-project/end-to-end/src/integration_l1_publisher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,15 @@ describe('L1Publisher integration', () => {

const treeHeight = Math.ceil(Math.log2(newL2ToL1MsgsArray.length));

const tree = new StandardTree(openTmpStore(true), new SHA256Trunc(), 'temp_outhash_sibling_path', treeHeight);
await tree.appendLeaves(newL2ToL1MsgsArray.map(l2ToL1Msg => l2ToL1Msg.toBuffer()));
const tree = new StandardTree(
openTmpStore(true),
new SHA256Trunc(),
'temp_outhash_sibling_path',
treeHeight,
0n,
Fr,
);
await tree.appendLeaves(newL2ToL1MsgsArray);

const expectedRoot = tree.getRoot(true);
const [actualRoot] = await outbox.read.roots([block.header.globalVariables.blockNumber.toBigInt()]);
Expand Down
7 changes: 6 additions & 1 deletion yarn-project/merkle-tree/src/interfaces/indexed_tree.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { SiblingPath } from '@aztec/circuit-types';
import { IndexedTreeLeaf, IndexedTreeLeafPreimage } from '@aztec/foundation/trees';

import { IndexedTreeSnapshot, TreeSnapshot, TreeSnapshotBuilder } from '../snapshots/snapshot_builder.js';
import { AppendOnlyTree } from './append_only_tree.js';
import { MerkleTree } from './merkle_tree.js';

/**
* Factory for creating leaf preimages.
Expand Down Expand Up @@ -73,7 +75,10 @@ export interface BatchInsertionResult<TreeHeight extends number, SubtreeSiblingP
/**
* Indexed merkle tree.
*/
export interface IndexedTree extends AppendOnlyTree<Buffer> {
export interface IndexedTree
extends MerkleTree<Buffer>,
TreeSnapshotBuilder<IndexedTreeSnapshot>,
Omit<AppendOnlyTree<Buffer>, keyof TreeSnapshotBuilder<TreeSnapshot<Buffer>>> {
/**
* Finds the index of the largest leaf whose value is less than or equal to the provided value.
* @param newValue - The new value to be inserted into the tree.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export async function buildBaseRollupInput(

// Update the note hash 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
const newNoteHashes = tx.data.combinedData.newNoteHashes.map(x => x.value.toBuffer());
const newNoteHashes = tx.data.combinedData.newNoteHashes.map(x => x.value);
await db.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, newNoteHashes);

// The read witnesses for a given TX should be generated before the writes of the same TX are applied.
Expand Down Expand Up @@ -214,10 +214,7 @@ export async function executeRootRollupCircuit(
const rootInput = await getRootRollupInput(...left, ...right, l1ToL2Roots, newL1ToL2Messages, db);

// Update the local trees to include the new l1 to l2 messages
await db.appendLeaves(
MerkleTreeId.L1_TO_L2_MESSAGE_TREE,
newL1ToL2Messages.map(m => m.toBuffer()),
);
await db.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, newL1ToL2Messages);

// Simulate and get proof for the root circuit
const rootOutput = await simulator.rootRollupCircuit(rootInput);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ describe('prover/tx-prover', () => {
.sort(sideEffectCmp),
SideEffect.empty(),
MAX_NEW_NOTE_HASHES_PER_TX,
).map(l => l.value.toBuffer()),
).map(l => l.value),
),
);
await expectsDb.batchInsert(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,10 @@ describe('server_world_state_synchronizer', () => {
new SHA256Trunc(),
'empty_subtree_in_hash',
L1_TO_L2_MSG_SUBTREE_HEIGHT,
0n,
Fr,
);
await tree.appendLeaves(l1ToL2Messages.map(msg => msg.toBuffer()));
await tree.appendLeaves(l1ToL2Messages);
inHash = tree.getRoot(true);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,10 @@ export class ServerWorldStateSynchronizer implements WorldStateSynchronizer {
new SHA256Trunc(),
'temp_in_hash_check',
L1_TO_L2_MSG_SUBTREE_HEIGHT,
0n,
Fr,
);
await tree.appendLeaves(l1ToL2Messages.map(msg => msg.toBuffer()));
await tree.appendLeaves(l1ToL2Messages);

if (!tree.getRoot(true).equals(inHash)) {
throw new Error('Obtained L1 to L2 messages failed to be hashed to the block inHash');
Expand Down
6 changes: 2 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 @@ -503,11 +503,9 @@ export class MerkleTrees implements MerkleTreeDb {

public async getSnapshot(blockNumber: number): Promise<TreeSnapshots> {
return {
[MerkleTreeId.NULLIFIER_TREE]: (await this.trees[MerkleTreeId.NULLIFIER_TREE].getSnapshot(blockNumber)) as any,
[MerkleTreeId.NULLIFIER_TREE]: await this.trees[MerkleTreeId.NULLIFIER_TREE].getSnapshot(blockNumber),
[MerkleTreeId.NOTE_HASH_TREE]: await this.trees[MerkleTreeId.NOTE_HASH_TREE].getSnapshot(blockNumber),
[MerkleTreeId.PUBLIC_DATA_TREE]: (await this.trees[MerkleTreeId.PUBLIC_DATA_TREE].getSnapshot(
blockNumber,
)) as any,
[MerkleTreeId.PUBLIC_DATA_TREE]: await this.trees[MerkleTreeId.PUBLIC_DATA_TREE].getSnapshot(blockNumber),
[MerkleTreeId.L1_TO_L2_MESSAGE_TREE]: await this.trees[MerkleTreeId.L1_TO_L2_MESSAGE_TREE].getSnapshot(
blockNumber,
),
Expand Down

0 comments on commit 26ca197

Please sign in to comment.