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/merkle_tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface MerkleTree extends SiblingPathSource {
* @param includeUncommitted - Set to true to include uncommitted updates in the returned value
*/
getNumLeaves(includeUncommitted: boolean): bigint;

/**
* Appends a set of leaf values to the tree
* @param leaves - The set of leaves to be appended
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import { Simulator } from '../simulator/index.js';
import { WasmCircuitSimulator } from '../simulator/wasm.js';
import { CircuitBlockBuilder } from './circuit_block_builder.js';
import { computeContractLeaf } from '@aztec/circuits.js/abis';
import { buffer } from 'stream/consumers';
import { toBufferBE } from '@aztec/foundation';

/* eslint-disable @typescript-eslint/ban-ts-comment */
Expand Down Expand Up @@ -181,6 +180,36 @@ describe('sequencer/circuit_block_builder', () => {
expect(contractTreeAfter.size).toEqual(4n);
});

it('build edge case test', async () => {
// Regression test - this recreates the edge case

const simulator = await WasmCircuitSimulator.new();
const prover = new EmptyProver();
builder = new TestSubject(builderDb, vks, simulator, prover);
// update the starting tree
const updateVals = Array(16).fill(0n);
updateVals[0] = 19777494491628650244807463906174285795660759352776418619064841306523677458742n;
updateVals[1] = 10246291467305176436335175657884940686778521321101740385288169037814567547848n;

await builder.updateRootTrees();
await builderDb.appendLeaves(
MerkleTreeId.NULLIFIER_TREE,
updateVals.map(v => toBufferBE(v, 32)),
);

// new added values
const tx = makeEmptyTx();
tx.data.end.newNullifiers[0] = new Fr(
10336601644835972678500657502133589897705389664587188571002640950065546264856n,
);
tx.data.end.newNullifiers[1] = new Fr(
17490072961923661940560522096125238013953043065748521735636170028491723851741n,
);

const [l2Block] = await builder.buildL2Block(blockNumber, tx);
expect(l2Block.number).toEqual(blockNumber);
});

it('builds an L2 block with a contract deployment tx using wasm circuits', async () => {
const simulator = await WasmCircuitSimulator.new();
const prover = new EmptyProver();
Expand Down Expand Up @@ -241,6 +270,19 @@ describe('sequencer/circuit_block_builder', () => {
const buildSnapshot = await builderDb.getTreeInfo(MerkleTreeId.NULLIFIER_TREE);
expect(buildSnapshot).toEqual(expectsSnapshot);
});

it('test nullifier tree impl, inserting arbitrary random values #2', async () => {
const leaves = [97, 98, 10, 0, 99999, 88, 100001, 9000000].map(i => toBufferBE(BigInt(i), 32));
await expectsDb.appendLeaves(MerkleTreeId.NULLIFIER_TREE, leaves);
builder = new TestSubject(builderDb, vks, simulator, prover);

await builder.performBaseRollupBatchInsertionProofs(leaves);

// assert snapshots
const expectsSnapshot = await expectsDb.getTreeInfo(MerkleTreeId.NULLIFIER_TREE);
const buildSnapshot = await builderDb.getTreeInfo(MerkleTreeId.NULLIFIER_TREE);
expect(buildSnapshot).toEqual(expectsSnapshot);
});
});

// Test subject class that exposes internal functions for testing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export class L1Publisher implements L2BlockReceiver {
public async processL2Block(l2BlockData: L2Block): Promise<boolean> {
const proof = Buffer.alloc(0);
const txData = { proof, inputs: l2BlockData.encode() };
//this.log(`Publishing L2 block: ${l2BlockData.inspect()}`);

while (!this.interrupted) {
if (!(await this.checkFeeDistributorBalance())) {
Expand Down