From 09b3f3f3c81af89d35d95023e27f8852b9d6646f Mon Sep 17 00:00:00 2001 From: PhilWindle <60546371+PhilWindle@users.noreply.github.com> Date: Fri, 5 May 2023 10:50:51 +0100 Subject: [PATCH] L1 to L2 messaging fixes (#471) * L1 to L2 messaging fixes * Fixes * Fixes * Reverted tree height change * Test fix --- .../circuits/rollup/root/native_root_rollup_circuit.cpp | 2 +- yarn-project/circuits.js/src/structs/constants.ts | 6 +++--- yarn-project/circuits.js/src/structs/rollup/root_rollup.ts | 4 ++-- yarn-project/circuits.js/src/tests/factories.ts | 4 ++-- yarn-project/end-to-end/package.json | 2 +- .../src/block_builder/solo_block_builder.ts | 4 ++-- .../synchroniser/server_world_state_synchroniser.test.ts | 4 ++-- .../src/synchroniser/server_world_state_synchroniser.ts | 6 ++++++ 8 files changed, 19 insertions(+), 13 deletions(-) diff --git a/circuits/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.cpp b/circuits/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.cpp index 536f805f70a..8fb79210f07 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.cpp @@ -124,7 +124,7 @@ RootRollupPublicInputs root_rollup_circuit(DummyComposer& composer, RootRollupIn rootRollupInputs.new_l1_to_l2_message_tree_root_sibling_path, empty_l1_to_l2_subtree_root, l1_to_l2_subtree_root, - L1_TO_L2_MSG_SUBTREE_INCLUSION_CHECK_DEPTH, + L1_TO_L2_MSG_SUBTREE_DEPTH, "l1 to l2 message tree insertion"); // Update the historic l1 to l2 data tree diff --git a/yarn-project/circuits.js/src/structs/constants.ts b/yarn-project/circuits.js/src/structs/constants.ts index 8c06c37b2bb..d825f7d2138 100644 --- a/yarn-project/circuits.js/src/structs/constants.ts +++ b/yarn-project/circuits.js/src/structs/constants.ts @@ -29,14 +29,14 @@ export const CONTRACT_TREE_HEIGHT = 4; export const PRIVATE_DATA_TREE_HEIGHT = 8; export const PUBLIC_DATA_TREE_HEIGHT = 254; export const NULLIFIER_TREE_HEIGHT = 8; +export const NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP = 16; export const L1_TO_L2_MESSAGES_TREE_HEIGHT = 8; export const L1_TO_L2_MESSAGES_ROOTS_TREE_HEIGHT = 8; -export const L1_TO_L2_MESSAGES_SUBTREE_INSERTION_HEIGHT = 4; +export const L1_TO_L2_MESSAGES_SUBTREE_HEIGHT = Math.ceil(Math.log2(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP)); +export const L1_TO_L2_MESSAGES_SIBLING_PATH_LENGTH = L1_TO_L2_MESSAGES_TREE_HEIGHT - L1_TO_L2_MESSAGES_SUBTREE_HEIGHT; export const PRIVATE_DATA_TREE_ROOTS_TREE_HEIGHT = 8; export const CONTRACT_TREE_ROOTS_TREE_HEIGHT = 8; export const ROLLUP_VK_TREE_HEIGHT = 8; export const FUNCTION_SELECTOR_NUM_BYTES = 4; - -export const NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP = 16; diff --git a/yarn-project/circuits.js/src/structs/rollup/root_rollup.ts b/yarn-project/circuits.js/src/structs/rollup/root_rollup.ts index a097948888f..6541b23e664 100644 --- a/yarn-project/circuits.js/src/structs/rollup/root_rollup.ts +++ b/yarn-project/circuits.js/src/structs/rollup/root_rollup.ts @@ -4,7 +4,7 @@ import { AppendOnlyTreeSnapshot } from './append_only_tree_snapshot.js'; import { CONTRACT_TREE_ROOTS_TREE_HEIGHT, L1_TO_L2_MESSAGES_ROOTS_TREE_HEIGHT, - L1_TO_L2_MESSAGES_SUBTREE_INSERTION_HEIGHT, + L1_TO_L2_MESSAGES_SIBLING_PATH_LENGTH, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, PRIVATE_DATA_TREE_ROOTS_TREE_HEIGHT, } from '../constants.js'; @@ -27,7 +27,7 @@ export class RootRollupInputs { ) { assertLength(this, 'newHistoricPrivateDataTreeRootSiblingPath', PRIVATE_DATA_TREE_ROOTS_TREE_HEIGHT); assertLength(this, 'newHistoricContractDataTreeRootSiblingPath', CONTRACT_TREE_ROOTS_TREE_HEIGHT); - assertLength(this, 'newL1ToL2MessageTreeRootSiblingPath', L1_TO_L2_MESSAGES_SUBTREE_INSERTION_HEIGHT); + assertLength(this, 'newL1ToL2MessageTreeRootSiblingPath', L1_TO_L2_MESSAGES_SIBLING_PATH_LENGTH); assertLength(this, 'newHistoricL1ToL2MessageTreeRootSiblingPath', L1_TO_L2_MESSAGES_ROOTS_TREE_HEIGHT); assertLength(this, 'newL1ToL2Messages', NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP); } diff --git a/yarn-project/circuits.js/src/tests/factories.ts b/yarn-project/circuits.js/src/tests/factories.ts index e855ad38f05..7c733d7d6ae 100644 --- a/yarn-project/circuits.js/src/tests/factories.ts +++ b/yarn-project/circuits.js/src/tests/factories.ts @@ -51,7 +51,6 @@ import { KERNEL_PRIVATE_CALL_STACK_LENGTH, KERNEL_PUBLIC_CALL_STACK_LENGTH, L1_TO_L2_MESSAGES_ROOTS_TREE_HEIGHT, - L1_TO_L2_MESSAGES_SUBTREE_INSERTION_HEIGHT, NEW_L2_TO_L1_MSGS_LENGTH, NEW_COMMITMENTS_LENGTH, NEW_NULLIFIERS_LENGTH, @@ -67,6 +66,7 @@ import { STATE_READS_LENGTH, STATE_TRANSITIONS_LENGTH, VK_TREE_HEIGHT, + L1_TO_L2_MESSAGES_SIBLING_PATH_LENGTH, } from '../structs/constants.js'; import { FunctionData } from '../structs/function_data.js'; import { MembershipWitness } from '../structs/membership_witness.js'; @@ -468,7 +468,7 @@ export function makeRootRollupInputs(seed = 0) { range(PRIVATE_DATA_TREE_ROOTS_TREE_HEIGHT, 0x2000).map(fr), range(CONTRACT_TREE_ROOTS_TREE_HEIGHT, 0x2100).map(fr), range(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, 0x2100).map(fr), - range(L1_TO_L2_MESSAGES_SUBTREE_INSERTION_HEIGHT, 0x2100).map(fr), + range(L1_TO_L2_MESSAGES_SIBLING_PATH_LENGTH, 0x2100).map(fr), range(L1_TO_L2_MESSAGES_ROOTS_TREE_HEIGHT, 0x2100).map(fr), makeAppendOnlyTreeSnapshot(seed + 0x2200), makeAppendOnlyTreeSnapshot(seed + 0x2300), diff --git a/yarn-project/end-to-end/package.json b/yarn-project/end-to-end/package.json index 1b72718bdfc..487a5ba3517 100644 --- a/yarn-project/end-to-end/package.json +++ b/yarn-project/end-to-end/package.json @@ -11,7 +11,7 @@ "clean": "rm -rf ./dest .tsbuildinfo", "formatting": "run -T prettier --check ./src && run -T eslint ./src", "formatting:fix": "run -T prettier -w ./src", - "test": "DEBUG='aztec:' NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --runInBand --passWithNoTests --testTimeout=15000", + "test": "DEBUG='aztec:*' NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --runInBand --passWithNoTests --testTimeout=15000", "test:integration": "concurrently -k -s first -c reset,dim -n test,anvil \"yarn test:integration:run\" \"anvil\"", "test:integration:run": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --no-cache --runInBand --config jest.integration.config.json" }, diff --git a/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts b/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts index 7b396f07fd6..6ae9b1d7159 100644 --- a/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts +++ b/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts @@ -5,7 +5,7 @@ import { CONTRACT_TREE_ROOTS_TREE_HEIGHT, CircuitsWasm, ConstantBaseRollupData, - L1_TO_L2_MESSAGES_SUBTREE_INSERTION_HEIGHT, + L1_TO_L2_MESSAGES_SUBTREE_HEIGHT, MembershipWitness, MergeRollupInputs, NULLIFIER_TREE_HEIGHT, @@ -425,7 +425,7 @@ export class SoloBlockBuilder implements BlockBuilder { ); const newL1ToL2MessageTreeRootSiblingPath = await this.getSubtreeSiblingPath( MerkleTreeId.L1_TO_L2_MESSAGES_TREE, - L1_TO_L2_MESSAGES_SUBTREE_INSERTION_HEIGHT, + L1_TO_L2_MESSAGES_SUBTREE_HEIGHT, ); // Get tree snapshots diff --git a/yarn-project/world-state/src/synchroniser/server_world_state_synchroniser.test.ts b/yarn-project/world-state/src/synchroniser/server_world_state_synchroniser.test.ts index 08378bf4147..eaa5fabc371 100644 --- a/yarn-project/world-state/src/synchroniser/server_world_state_synchroniser.test.ts +++ b/yarn-project/world-state/src/synchroniser/server_world_state_synchroniser.test.ts @@ -250,8 +250,8 @@ describe('server_world_state_synchroniser', () => { .map((_, index) => getMockBlock(index, [Buffer.alloc(32, index)])); // sync the server await server.start(); - // there are 3 data trees updated - expect(merkleTreeDb.appendLeaves).toHaveBeenCalledTimes(totalBlocks * 3); + // there are 4 data trees updated + expect(merkleTreeDb.appendLeaves).toHaveBeenCalledTimes(totalBlocks * 4); // and 2 root trees expect(merkleTreeDb.updateHistoricRootsTrees).toHaveBeenCalledTimes(totalBlocks); // there should be a call to append to the contract tree for each block diff --git a/yarn-project/world-state/src/synchroniser/server_world_state_synchroniser.ts b/yarn-project/world-state/src/synchroniser/server_world_state_synchroniser.ts index 08aae232917..5b5634923a8 100644 --- a/yarn-project/world-state/src/synchroniser/server_world_state_synchroniser.ts +++ b/yarn-project/world-state/src/synchroniser/server_world_state_synchroniser.ts @@ -142,6 +142,11 @@ export class ServerWorldStateSynchroniser implements WorldStateSynchroniser { l2Block.endTreeOfHistoricPrivateDataTreeRootsSnapshot.root, MerkleTreeId.PRIVATE_DATA_TREE_ROOTS_TREE, ), + compareRoot(l2Block.endL1ToL2MessageTreeSnapshot.root, MerkleTreeId.L1_TO_L2_MESSAGES_TREE), + compareRoot( + l2Block.endTreeOfHistoricL1ToL2MessageTreeRootsSnapshot.root, + MerkleTreeId.L1_TO_L2_MESSAGES_ROOTS_TREE, + ), ]); const ourBlock = rootChecks.every(x => x); if (ourBlock) { @@ -155,6 +160,7 @@ export class ServerWorldStateSynchroniser implements WorldStateSynchroniser { [MerkleTreeId.CONTRACT_TREE, l2Block.newContracts], [MerkleTreeId.NULLIFIER_TREE, l2Block.newNullifiers], [MerkleTreeId.PRIVATE_DATA_TREE, l2Block.newCommitments], + [MerkleTreeId.L1_TO_L2_MESSAGES_TREE, l2Block.newL1ToL2Messages], ] as const) { await this.merkleTreeDb.appendLeaves( tree,