Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: increase max L2 to L1 msgs #6959

Merged
merged 8 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 5 additions & 4 deletions l1-contracts/src/core/Rollup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,12 @@ contract Rollup is IRollup {
revert Errors.Rollup__InvalidInHash(inHash, header.contentCommitment.inHash);
}

// We assume here that the number of L2 to L1 messages per tx is 2. Therefore we just need a tree that is one height
// larger (as we can just extend the tree one layer down to hold all the L2 to L1 messages)
uint256 l2ToL1TreeHeight = header.contentCommitment.txTreeHeight + 1;
// Currently trying out storing each tx's L2 to L1 messages in variable height trees (smallest tree required)
// => path lengths will differ and we cannot provide one here
// We can provide a minimum which is the height of the rollup layers (txTreeHeight) and the smallest 'tree' (1 layer)
uint256 l2ToL1TreeMinHeight = header.contentCommitment.txTreeHeight + 1;
OUTBOX.insert(
header.globalVariables.blockNumber, header.contentCommitment.outHash, l2ToL1TreeHeight
header.globalVariables.blockNumber, header.contentCommitment.outHash, l2ToL1TreeMinHeight
);

// pay the coinbase 1 gas token if it is not empty and header.totalFees is not zero
Expand Down
4 changes: 2 additions & 2 deletions l1-contracts/src/core/libraries/ConstantsGen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ library Constants {
uint256 internal constant PROTOCOL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX = 1;
uint256 internal constant MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX = 32;
uint256 internal constant MAX_PUBLIC_DATA_READS_PER_TX = 32;
uint256 internal constant MAX_NEW_L2_TO_L1_MSGS_PER_TX = 2;
uint256 internal constant MAX_NEW_L2_TO_L1_MSGS_PER_TX = 16;
uint256 internal constant MAX_NOTE_HASH_READ_REQUESTS_PER_TX = 128;
uint256 internal constant MAX_NULLIFIER_READ_REQUESTS_PER_TX = 128;
uint256 internal constant MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX = 128;
Expand Down Expand Up @@ -172,7 +172,7 @@ library Constants {
uint256 internal constant CONTRACTS_NUM_BYTES_PER_BASE_ROLLUP = 32;
uint256 internal constant CONTRACT_DATA_NUM_BYTES_PER_BASE_ROLLUP = 64;
uint256 internal constant CONTRACT_DATA_NUM_BYTES_PER_BASE_ROLLUP_UNPADDED = 52;
uint256 internal constant L2_TO_L1_MSGS_NUM_BYTES_PER_BASE_ROLLUP = 64;
uint256 internal constant L2_TO_L1_MSGS_NUM_BYTES_PER_BASE_ROLLUP = 512;
uint256 internal constant LOGS_HASHES_NUM_BYTES_PER_BASE_ROLLUP = 64;
uint256 internal constant NUM_MSGS_PER_BASE_PARITY = 4;
uint256 internal constant NUM_BASE_PARITY_PER_ROOT_PARITY = 4;
Expand Down
2 changes: 1 addition & 1 deletion l1-contracts/src/core/libraries/decoders/TxsDecoder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ library TxsDecoder {
// We pad base leaves with hashes of empty tx effect.
for (uint256 i = numTxEffects; i < vars.baseLeaves.length; i++) {
// Value taken from tx_effect.test.ts "hash of empty tx effect matches snapshot" test case
vars.baseLeaves[i] = hex"003f2c7d671d4a2c210124550cf00f8e21727a0ae1a43e1758982a25725dde2b";
vars.baseLeaves[i] = hex"0071c642b31e5890a15ef92f3cbeba34edfb6e2e9f63079ecbda13a89d426f7d";
}
}

Expand Down
21 changes: 14 additions & 7 deletions l1-contracts/src/core/messagebridge/Outbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ contract Outbox is IOutbox {
struct RootData {
// This is the outhash specified by header.globalvariables.outHash of any given block.
bytes32 root;
uint256 height;
uint256 minHeight;
mapping(uint256 => bool) nullified;
}

Expand All @@ -39,9 +39,9 @@ contract Outbox is IOutbox {
* @dev Emits `RootAdded` upon inserting the root successfully
* @param _l2BlockNumber - The L2 Block Number in which the L2 to L1 messages reside
* @param _root - The merkle root of the tree where all the L2 to L1 messages are leaves
* @param _height - The height of the merkle tree that the root corresponds to
* @param _minHeight - The min height of the merkle tree that the root corresponds to
*/
function insert(uint256 _l2BlockNumber, bytes32 _root, uint256 _height)
function insert(uint256 _l2BlockNumber, bytes32 _root, uint256 _minHeight)
external
override(IOutbox)
{
Expand All @@ -58,9 +58,9 @@ contract Outbox is IOutbox {
}

roots[_l2BlockNumber].root = _root;
roots[_l2BlockNumber].height = _height;
roots[_l2BlockNumber].minHeight = _minHeight;

emit RootAdded(_l2BlockNumber, _root, _height);
emit RootAdded(_l2BlockNumber, _root, _minHeight);
}

/**
Expand Down Expand Up @@ -100,9 +100,16 @@ contract Outbox is IOutbox {
revert Errors.Outbox__AlreadyNullified(_l2BlockNumber, _leafIndex);
}

uint256 treeHeight = rootData.height;
// Min height = height of rollup layers
// The smallest num of messages will require a subtree of height 1
uint256 treeHeight = rootData.minHeight;
if (treeHeight > _path.length) {
revert Errors.Outbox__InvalidPathLength(treeHeight, _path.length);
}

if (treeHeight != _path.length) {
// Max height = height of rollup layers + 4
// The max num of messages (16) will require a subtree of height 4
if (treeHeight + 4 < _path.length) {
MirandaWood marked this conversation as resolved.
Show resolved Hide resolved
revert Errors.Outbox__InvalidPathLength(treeHeight, _path.length);
}

Expand Down
4 changes: 2 additions & 2 deletions l1-contracts/test/Outbox.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,13 @@ contract OutboxTest is Test {
vm.prank(ROLLUP_CONTRACT);
outbox.insert(1, root, DEFAULT_TREE_HEIGHT);

NaiveMerkle biggerTree = new NaiveMerkle(DEFAULT_TREE_HEIGHT + 1);
NaiveMerkle biggerTree = new NaiveMerkle(DEFAULT_TREE_HEIGHT - 1);
tree.insertLeaf(leaf);

(bytes32[] memory path,) = biggerTree.computeSiblingPath(0);
vm.expectRevert(
abi.encodeWithSelector(
Errors.Outbox__InvalidPathLength.selector, DEFAULT_TREE_HEIGHT, DEFAULT_TREE_HEIGHT + 1
Errors.Outbox__InvalidPathLength.selector, DEFAULT_TREE_HEIGHT, DEFAULT_TREE_HEIGHT - 1
)
);
outbox.consume(fakeMessage, 1, 0, path);
Expand Down
12 changes: 11 additions & 1 deletion l1-contracts/test/Rollup.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,20 @@ contract RollupTest is DecoderBase {

bytes32 l2ToL1MessageTreeRoot;
{
// NB: The below works with full blocks because we require the largest possible subtrees
// for L2 to L1 messages - usually we make variable height subtrees, the roots of which
// form a balanced tree
uint256 numTxsWithPadding = txsHelper.computeNumTxEffectsToPad(numTxs) + numTxs;
// The below is a little janky - we know that this test deals with full txs with equal numbers
// of msgs or txs with no messages, so the division works
// TODO edit full.messages t include information about msgs per tx?
uint256 subTreeHeight = merkleTestUtil.calculateTreeHeightFromSize(
full.messages.l2ToL1Messages.length == 0 ? 0 : full.messages.l2ToL1Messages.length / numTxs
);
uint256 outHashTreeHeight = merkleTestUtil.calculateTreeHeightFromSize(numTxsWithPadding);
uint256 numMessagesWithPadding = numTxsWithPadding * Constants.MAX_NEW_L2_TO_L1_MSGS_PER_TX;

uint256 treeHeight = merkleTestUtil.calculateTreeHeightFromSize(numMessagesWithPadding);
uint256 treeHeight = subTreeHeight + outHashTreeHeight;
NaiveMerkle tree = new NaiveMerkle(treeHeight);
for (uint256 i = 0; i < numMessagesWithPadding; i++) {
if (i < full.messages.l2ToL1Messages.length) {
Expand Down
14 changes: 7 additions & 7 deletions l1-contracts/test/fixtures/empty_block_0.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@
"l2ToL1Messages": []
},
"block": {
"archive": "0x0ca6026d7140e6c6796115b226b84254cf06fcc7d57e02eee6f7a141f37f79a2",
"archive": "0x213abd5af447b087d321678ea5a15e09b944eec5722cc83cfe17dfe0967d594d",
"body": "0x00000000",
"txsEffectsHash": "0x008b39a331f763fd73b42ee12d3ed687ad7cf05751869d4bf875eda18c1c94d9",
"txsEffectsHash": "0x00e9b3a0aabc09e4c93146a10b14839b9576b1645792a0389f74bb489872c5c9",
"decodedHeader": {
"contentCommitment": {
"inHash": "0x00089a9d421a82c4a25f7acbebe69e638d5b064fa8a60e018793dcb0be53752c",
"outHash": "0x0007638bb56b6dda2b64b8f76841114ac3a87a1820030e2e16772c4d294879c3",
"txTreeHeight": 1,
"txsEffectsHash": "0x008b39a331f763fd73b42ee12d3ed687ad7cf05751869d4bf875eda18c1c94d9"
"txsEffectsHash": "0x00e9b3a0aabc09e4c93146a10b14839b9576b1645792a0389f74bb489872c5c9"
},
"globalVariables": {
"blockNumber": 1,
"chainId": 31337,
"timestamp": 0,
"version": 1,
"coinbase": "0x4bcfac0542d733e71b510c1907a85d283f02bbd7",
"feeRecipient": "0x052322027092ecfaeb88d75a31d553f791886da288ccedc3c642899c8baf4c6a",
"coinbase": "0x31a0ad6304fd811f35c7a6a4573bede71bac88c4",
"feeRecipient": "0x10e272aee0a08110ff06d7ad7cc974f7b980907d89b57ed3902bd6bcfd1c0be3",
"gasFees": {
"feePerDaGas": 0,
"feePerL2Gas": 0
Expand Down Expand Up @@ -55,8 +55,8 @@
}
}
},
"header": "0x05b0b6df52f1d47d0406318558052c89a174fbc9d615def82b3cc9ccc1937db8000000010000000000000000000000000000000000000000000000000000000000000001008b39a331f763fd73b42ee12d3ed687ad7cf05751869d4bf875eda18c1c94d900089a9d421a82c4a25f7acbebe69e638d5b064fa8a60e018793dcb0be53752c0007638bb56b6dda2b64b8f76841114ac3a87a1820030e2e16772c4d294879c31864fcdaa80ff2719154fa7c8a9050662972707168d69eac9db6fd3110829f800000001016642d9ccd8346c403aa4c3fa451178b22534a27035cdaa6ec34ae53b29c50cb000000800bcfa3e9f1a8922ee92c6dc964d6595907c1804a86753774322b468f69d4f278000001000572c8db882674dd026b8877fbba1b700a4407da3ae9ce5fa43215a28163362b000000800000000000000000000000000000000000000000000000000000000000007a690000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000004bcfac0542d733e71b510c1907a85d283f02bbd7052322027092ecfaeb88d75a31d553f791886da288ccedc3c642899c8baf4c6a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"publicInputsHash": "0x00a63e965b18f145af4be3954bf6918a484c8c02dcd3892e665fb4b0e74f9f39",
"header": "0x05b0b6df52f1d47d0406318558052c89a174fbc9d615def82b3cc9ccc1937db800000001000000000000000000000000000000000000000000000000000000000000000100e9b3a0aabc09e4c93146a10b14839b9576b1645792a0389f74bb489872c5c900089a9d421a82c4a25f7acbebe69e638d5b064fa8a60e018793dcb0be53752c0007638bb56b6dda2b64b8f76841114ac3a87a1820030e2e16772c4d294879c31864fcdaa80ff2719154fa7c8a9050662972707168d69eac9db6fd3110829f800000001016642d9ccd8346c403aa4c3fa451178b22534a27035cdaa6ec34ae53b29c50cb000000800bcfa3e9f1a8922ee92c6dc964d6595907c1804a86753774322b468f69d4f278000001000572c8db882674dd026b8877fbba1b700a4407da3ae9ce5fa43215a28163362b000000800000000000000000000000000000000000000000000000000000000000007a6900000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000031a0ad6304fd811f35c7a6a4573bede71bac88c410e272aee0a08110ff06d7ad7cc974f7b980907d89b57ed3902bd6bcfd1c0be3000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"publicInputsHash": "0x00f70efd61085e8637ab0434ad890e4ad2bbbeef52c3fc2a80e2bca9402d939a",
"numTxs": 0
}
}
18 changes: 9 additions & 9 deletions l1-contracts/test/fixtures/empty_block_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,31 @@
"l2ToL1Messages": []
},
"block": {
"archive": "0x1190dfaeb1e9ceaaac937ff5d38ddc09b989a108d7423dd5c67ad7be379fe4bd",
"archive": "0x2c06b779d31025592239f511294049b8298ab2bea0c3e74333913d7e63ad7fb9",
"body": "0x00000000",
"txsEffectsHash": "0x008b39a331f763fd73b42ee12d3ed687ad7cf05751869d4bf875eda18c1c94d9",
"txsEffectsHash": "0x00e9b3a0aabc09e4c93146a10b14839b9576b1645792a0389f74bb489872c5c9",
"decodedHeader": {
"contentCommitment": {
"inHash": "0x00089a9d421a82c4a25f7acbebe69e638d5b064fa8a60e018793dcb0be53752c",
"outHash": "0x0007638bb56b6dda2b64b8f76841114ac3a87a1820030e2e16772c4d294879c3",
"txTreeHeight": 1,
"txsEffectsHash": "0x008b39a331f763fd73b42ee12d3ed687ad7cf05751869d4bf875eda18c1c94d9"
"txsEffectsHash": "0x00e9b3a0aabc09e4c93146a10b14839b9576b1645792a0389f74bb489872c5c9"
},
"globalVariables": {
"blockNumber": 2,
"chainId": 31337,
"timestamp": 1716370414,
"timestamp": 1717688949,
"version": 1,
"coinbase": "0x4bcfac0542d733e71b510c1907a85d283f02bbd7",
"feeRecipient": "0x052322027092ecfaeb88d75a31d553f791886da288ccedc3c642899c8baf4c6a",
"coinbase": "0x31a0ad6304fd811f35c7a6a4573bede71bac88c4",
"feeRecipient": "0x10e272aee0a08110ff06d7ad7cc974f7b980907d89b57ed3902bd6bcfd1c0be3",
"gasFees": {
"feePerDaGas": 0,
"feePerL2Gas": 0
}
},
"lastArchive": {
"nextAvailableLeafIndex": 2,
"root": "0x0ca6026d7140e6c6796115b226b84254cf06fcc7d57e02eee6f7a141f37f79a2"
"root": "0x213abd5af447b087d321678ea5a15e09b944eec5722cc83cfe17dfe0967d594d"
},
"stateReference": {
"l1ToL2MessageTree": {
Expand All @@ -55,8 +55,8 @@
}
}
},
"header": "0x0ca6026d7140e6c6796115b226b84254cf06fcc7d57e02eee6f7a141f37f79a2000000020000000000000000000000000000000000000000000000000000000000000001008b39a331f763fd73b42ee12d3ed687ad7cf05751869d4bf875eda18c1c94d900089a9d421a82c4a25f7acbebe69e638d5b064fa8a60e018793dcb0be53752c0007638bb56b6dda2b64b8f76841114ac3a87a1820030e2e16772c4d294879c31864fcdaa80ff2719154fa7c8a9050662972707168d69eac9db6fd3110829f800000002016642d9ccd8346c403aa4c3fa451178b22534a27035cdaa6ec34ae53b29c50cb000001000bcfa3e9f1a8922ee92c6dc964d6595907c1804a86753774322b468f69d4f278000001800572c8db882674dd026b8877fbba1b700a4407da3ae9ce5fa43215a28163362b000000c00000000000000000000000000000000000000000000000000000000000007a690000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000664dbbee4bcfac0542d733e71b510c1907a85d283f02bbd7052322027092ecfaeb88d75a31d553f791886da288ccedc3c642899c8baf4c6a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"publicInputsHash": "0x001bf78dec65cc96a53373df46683aecaab0c6df3cca0f724ee8ff546a616338",
"header": "0x213abd5af447b087d321678ea5a15e09b944eec5722cc83cfe17dfe0967d594d00000002000000000000000000000000000000000000000000000000000000000000000100e9b3a0aabc09e4c93146a10b14839b9576b1645792a0389f74bb489872c5c900089a9d421a82c4a25f7acbebe69e638d5b064fa8a60e018793dcb0be53752c0007638bb56b6dda2b64b8f76841114ac3a87a1820030e2e16772c4d294879c31864fcdaa80ff2719154fa7c8a9050662972707168d69eac9db6fd3110829f800000002016642d9ccd8346c403aa4c3fa451178b22534a27035cdaa6ec34ae53b29c50cb000001000bcfa3e9f1a8922ee92c6dc964d6595907c1804a86753774322b468f69d4f278000001800572c8db882674dd026b8877fbba1b700a4407da3ae9ce5fa43215a28163362b000000c00000000000000000000000000000000000000000000000000000000000007a6900000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000006661da7531a0ad6304fd811f35c7a6a4573bede71bac88c410e272aee0a08110ff06d7ad7cc974f7b980907d89b57ed3902bd6bcfd1c0be3000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"publicInputsHash": "0x00db822f4ecc50dea54052616859a453c1333703c36d3cc71d5a11754c65d56f",
"numTxs": 0
}
}
Loading
Loading