Skip to content

Commit

Permalink
fix: historic tree + filled blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
LHerskind committed May 4, 2023
1 parent 32eed8a commit 89aefe2
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import {
NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
RootRollupPublicInputs,
UInt8Vector,
KERNEL_NEW_COMMITMENTS_LENGTH,
range,
KERNEL_NEW_NULLIFIERS_LENGTH,
KERNEL_NEW_L2_TO_L1_MSGS_LENGTH,
STATE_TRANSITIONS_LENGTH,
} from '@aztec/circuits.js';
import { computeContractLeaf } from '@aztec/circuits.js/abis';
import {
Expand Down Expand Up @@ -278,6 +283,24 @@ describe('sequencer/solo_block_builder', () => {
return await makeProcessedTx(publicTx, kernelOutput, makeProof());
};

const makeBloatedProcessedTx = async (seed = 0x1) => {
const publicTx = makePublicTx(seed);
const kernelOutput = KernelCircuitPublicInputs.empty();
kernelOutput.constants.historicTreeRoots = await getCombinedHistoricTreeRoots(builderDb);
kernelOutput.end.stateTransitions = range(STATE_TRANSITIONS_LENGTH, seed + 0x500).map(
i => new PublicDataTransition(fr(i), fr(0), fr(i + 10)),
);

const tx = await makeProcessedTx(publicTx, kernelOutput, makeProof());

tx.data.end.newCommitments = range(KERNEL_NEW_COMMITMENTS_LENGTH, seed + 0x100).map(fr);
tx.data.end.newNullifiers = range(KERNEL_NEW_NULLIFIERS_LENGTH, seed + 0x200).map(fr);
tx.data.end.newL2ToL1Msgs = range(KERNEL_NEW_L2_TO_L1_MSGS_LENGTH, seed + 0x300).map(fr);
tx.data.end.newContracts = [makeNewContractData(seed + 0x1000)];

return tx;
};

it.each([
[0, 4],
[1, 4],
Expand Down Expand Up @@ -311,6 +334,50 @@ describe('sequencer/solo_block_builder', () => {
10000,
);

it('builds an empty L2 block', async () => {
const txs = await Promise.all([
makeEmptyProcessedTx(),
makeEmptyProcessedTx(),
makeEmptyProcessedTx(),
makeEmptyProcessedTx(),
]);

const [l2Block] = await builder.buildL2Block(1, txs, mockL1ToL2Messages);
expect(l2Block.number).toEqual(1);
/*
Useful for sol generation
const encoded = l2Block.encode();
console.log(`Size (${encoded.length}): ${encoded.toString('hex')}`);
console.log(`calldata hash: 0x${l2Block.getCalldataHash().toString('hex')}`);
console.log(`l1 to l2 message hash: 0x${l2Block.getL1ToL2MessagesHash().toString('hex')}`);
console.log(`start state hash: 0x${l2Block.getStartStateHash().toString('hex')}`);
console.log(`end state hash: 0x${l2Block.getEndStateHash().toString('hex')}`);
console.log(`public data hash: 0x${l2Block.getPublicInputsHash().toBuffer().toString('hex')}`);*/
}, 10_000);

it('builds a mixed L2 block', async () => {
const txs = await Promise.all([
makeBloatedProcessedTx(32),
makeBloatedProcessedTx(64),
makeBloatedProcessedTx(96),
makeBloatedProcessedTx(128),
]);

const l1ToL2Messages = range(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, 1 + 0x400).map(fr);

const [l2Block] = await builder.buildL2Block(1, txs, l1ToL2Messages);
expect(l2Block.number).toEqual(1);
/*
Useful for sol generation
const encoded = l2Block.encode();
console.log(`Size (${encoded.length}): ${encoded.toString('hex')}`);
console.log(`calldata hash: 0x${l2Block.getCalldataHash().toString('hex')}`);
console.log(`l1 to l2 message hash: 0x${l2Block.getL1ToL2MessagesHash().toString('hex')}`);
console.log(`start state hash: 0x${l2Block.getStartStateHash().toString('hex')}`);
console.log(`end state hash: 0x${l2Block.getEndStateHash().toString('hex')}`);
console.log(`public data hash: 0x${l2Block.getPublicInputsHash().toBuffer().toString('hex')}`);*/
}, 20_000);

it('builds an L2 block with private and public txs', async () => {
const txs = await Promise.all([
makePublicCallProcessedTx(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ export class SoloBlockBuilder implements BlockBuilder {
startTreeOfHistoricPrivateDataTreeRootsSnapshot: await this.getTreeSnapshot(
MerkleTreeId.PRIVATE_DATA_TREE_ROOTS_TREE,
),
treeOfHistoricL1ToL2MsgTreeRootsSnapshot: new AppendOnlyTreeSnapshot(DELETE_FR, DELETE_NUM),
treeOfHistoricL1ToL2MsgTreeRootsSnapshot: await this.getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGES_ROOTS_TREE),
});
}

Expand Down

0 comments on commit 89aefe2

Please sign in to comment.