-
Notifications
You must be signed in to change notification settings - Fork 310
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
refactor: pad when needed and not sooner #5482
Changes from all commits
3f78401
778a977
25986f3
694d507
ed13e73
f901a5c
216b70e
7913422
54e0a7d
bf8d4d0
2b552d6
8fce6f2
f50220e
aa5fbd9
f8f448a
dea124e
f21ef79
de29584
ad6ef9f
363d8b0
2163c9f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ pragma solidity >=0.8.18; | |
import {DecoderBase} from "./decoders/Base.sol"; | ||
|
||
import {DataStructures} from "../src/core/libraries/DataStructures.sol"; | ||
import {Constants} from "../src/core/libraries/ConstantsGen.sol"; | ||
|
||
import {Registry} from "../src/core/messagebridge/Registry.sol"; | ||
import {Inbox} from "../src/core/messagebridge/Inbox.sol"; | ||
|
@@ -15,6 +16,8 @@ import {AvailabilityOracle} from "../src/core/availability_oracle/AvailabilityOr | |
import {NaiveMerkle} from "./merkle/Naive.sol"; | ||
import {MerkleTestUtil} from "./merkle/TestUtil.sol"; | ||
|
||
import {TxsDecoderHelper} from "./decoders/helpers/TxsDecoderHelper.sol"; | ||
|
||
/** | ||
* Blocks are generated using the `integration_l1_publisher.test.ts` tests. | ||
* Main use of these test is shorter cycles when updating the decoder contract. | ||
|
@@ -25,6 +28,7 @@ contract RollupTest is DecoderBase { | |
Outbox internal outbox; | ||
Rollup internal rollup; | ||
MerkleTestUtil internal merkleTestUtil; | ||
TxsDecoderHelper internal txsHelper; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added the helper here because I needed the |
||
|
||
AvailabilityOracle internal availabilityOracle; | ||
|
||
|
@@ -38,6 +42,7 @@ contract RollupTest is DecoderBase { | |
registry.upgrade(address(rollup), address(inbox), address(outbox)); | ||
|
||
merkleTestUtil = new MerkleTestUtil(); | ||
txsHelper = new TxsDecoderHelper(); | ||
} | ||
|
||
function testMixedBlock() public { | ||
|
@@ -128,6 +133,7 @@ contract RollupTest is DecoderBase { | |
bytes memory header = full.block.header; | ||
bytes32 archive = full.block.archive; | ||
bytes memory body = full.block.body; | ||
uint32 numTxs = full.block.numTxs; | ||
|
||
// We jump to the time of the block. | ||
vm.warp(full.block.decodedHeader.globalVariables.timestamp); | ||
|
@@ -145,19 +151,25 @@ contract RollupTest is DecoderBase { | |
|
||
bytes32 l2ToL1MessageTreeRoot; | ||
{ | ||
uint256 treeHeight = | ||
merkleTestUtil.calculateTreeHeightFromSize(full.messages.l2ToL1Messages.length); | ||
uint256 numTxsWithPadding = txsHelper.computeNumTxEffectsToPad(numTxs) + numTxs; | ||
uint256 numMessagesWithPadding = numTxsWithPadding * Constants.MAX_NEW_L2_TO_L1_MSGS_PER_TX; | ||
|
||
uint256 treeHeight = merkleTestUtil.calculateTreeHeightFromSize(numMessagesWithPadding); | ||
NaiveMerkle tree = new NaiveMerkle(treeHeight); | ||
for (uint256 i = 0; i < full.messages.l2ToL1Messages.length; i++) { | ||
tree.insertLeaf(full.messages.l2ToL1Messages[i]); | ||
for (uint256 i = 0; i < numMessagesWithPadding; i++) { | ||
if (i < full.messages.l2ToL1Messages.length) { | ||
tree.insertLeaf(full.messages.l2ToL1Messages[i]); | ||
} else { | ||
tree.insertLeaf(bytes32(0)); | ||
} | ||
} | ||
|
||
l2ToL1MessageTreeRoot = tree.computeRoot(); | ||
} | ||
|
||
(bytes32 root,) = outbox.roots(full.block.decodedHeader.globalVariables.blockNumber); | ||
|
||
assertEq(l2ToL1MessageTreeRoot, root); | ||
assertEq(l2ToL1MessageTreeRoot, root, "Invalid l2 to l1 message tree root"); | ||
|
||
assertEq(rollup.archive(), archive, "Invalid archive"); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,35 +5,26 @@ | |
"sender": "0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc" | ||
}, | ||
"messages": { | ||
"l2ToL1Messages": [ | ||
"0x0000000000000000000000000000000000000000000000000000000000000000", | ||
"0x0000000000000000000000000000000000000000000000000000000000000000", | ||
"0x0000000000000000000000000000000000000000000000000000000000000000", | ||
"0x0000000000000000000000000000000000000000000000000000000000000000", | ||
"0x0000000000000000000000000000000000000000000000000000000000000000", | ||
"0x0000000000000000000000000000000000000000000000000000000000000000", | ||
"0x0000000000000000000000000000000000000000000000000000000000000000", | ||
"0x0000000000000000000000000000000000000000000000000000000000000000" | ||
] | ||
"l2ToL1Messages": [] | ||
}, | ||
"block": { | ||
"archive": "0x29598370fa40a50b7fbb99e501f11527a69e104a43c8eefbfe66888f137e7e49", | ||
"body": "0x0000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", | ||
"txsEffectsHash": "0x008194e3dd375d5d878dcf9546bb5c2c77e165c6b1bef9aead8ceb35c3762bd5", | ||
"archive": "0x122e56310a16134c202e94b3ba9cb74de123f7ec493e601d2f0b6da00cf57a4a", | ||
"body": "0x00000000", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Body is now even smaller because empty tx effects are not included. We could shrink this value even more because we will probably never need 4 bytes for num tx effects but that's not so important now. |
||
"txsEffectsHash": "0x00df6b1c97b9e01113fa0363d9ff71c85addc74e92b22d433b2fb082d2493896", | ||
"decodedHeader": { | ||
"contentCommitment": { | ||
"inHash": "0x00089a9d421a82c4a25f7acbebe69e638d5b064fa8a60e018793dcb0be53752c", | ||
"outHash": "0x00efcbdb79553ae6863646bf36441755bc344a9a4af335fadc6659594faa4316", | ||
"txTreeHeight": 2, | ||
"txsEffectsHash": "0x008194e3dd375d5d878dcf9546bb5c2c77e165c6b1bef9aead8ceb35c3762bd5" | ||
"outHash": "0x0007638bb56b6dda2b64b8f76841114ac3a87a1820030e2e16772c4d294879c3", | ||
"txTreeHeight": 1, | ||
"txsEffectsHash": "0x00df6b1c97b9e01113fa0363d9ff71c85addc74e92b22d433b2fb082d2493896" | ||
}, | ||
"globalVariables": { | ||
"blockNumber": 1, | ||
"chainId": 31337, | ||
"timestamp": 0, | ||
"version": 1, | ||
"coinbase": "0x5e65711eaf5606f1f42dd36579261833e54595ee", | ||
"feeRecipient": "0x00eafbad09eab548a89726e2a735bdcadc37aa4c318ed7a12d9be6a7542e517e" | ||
"coinbase": "0x66440eb666440eb666440eb666440eb666440eb6", | ||
"feeRecipient": "0x061ca689507c7f1ccc68c2ad086c9d5d94f50869cb1b718c6a46aaf77a4500ba" | ||
}, | ||
"lastArchive": { | ||
"nextAvailableLeafIndex": 1, | ||
|
@@ -46,21 +37,22 @@ | |
}, | ||
"partialStateReference": { | ||
"noteHashTree": { | ||
"nextAvailableLeafIndex": 256, | ||
"nextAvailableLeafIndex": 128, | ||
"root": "0x16642d9ccd8346c403aa4c3fa451178b22534a27035cdaa6ec34ae53b29c50cb" | ||
}, | ||
"nullifierTree": { | ||
"nextAvailableLeafIndex": 384, | ||
"nextAvailableLeafIndex": 256, | ||
"root": "0x0bcfa3e9f1a8922ee92c6dc964d6595907c1804a86753774322b468f69d4f278" | ||
}, | ||
"publicDataTree": { | ||
"nextAvailableLeafIndex": 192, | ||
"nextAvailableLeafIndex": 128, | ||
"root": "0x0572c8db882674dd026b8877fbba1b700a4407da3ae9ce5fa43215a28163362b" | ||
} | ||
} | ||
} | ||
}, | ||
"header": "0x1e3523d3bd50ae6204e1ec2ee1bdf8af4c6217ec80900052d2cf4259379dd130000000010000000000000000000000000000000000000000000000000000000000000002008194e3dd375d5d878dcf9546bb5c2c77e165c6b1bef9aead8ceb35c3762bd500089a9d421a82c4a25f7acbebe69e638d5b064fa8a60e018793dcb0be53752c00efcbdb79553ae6863646bf36441755bc344a9a4af335fadc6659594faa43161864fcdaa80ff2719154fa7c8a9050662972707168d69eac9db6fd3110829f800000001016642d9ccd8346c403aa4c3fa451178b22534a27035cdaa6ec34ae53b29c50cb000001000bcfa3e9f1a8922ee92c6dc964d6595907c1804a86753774322b468f69d4f278000001800572c8db882674dd026b8877fbba1b700a4407da3ae9ce5fa43215a28163362b000000c00000000000000000000000000000000000000000000000000000000000007a690000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000005e65711eaf5606f1f42dd36579261833e54595ee00eafbad09eab548a89726e2a735bdcadc37aa4c318ed7a12d9be6a7542e517e", | ||
"publicInputsHash": "0x009e67eb54715bba61c94f475f6d4bf81b775da316c2c9a6a12506851f760bf0" | ||
"header": "0x1e3523d3bd50ae6204e1ec2ee1bdf8af4c6217ec80900052d2cf4259379dd13000000001000000000000000000000000000000000000000000000000000000000000000100df6b1c97b9e01113fa0363d9ff71c85addc74e92b22d433b2fb082d249389600089a9d421a82c4a25f7acbebe69e638d5b064fa8a60e018793dcb0be53752c0007638bb56b6dda2b64b8f76841114ac3a87a1820030e2e16772c4d294879c31864fcdaa80ff2719154fa7c8a9050662972707168d69eac9db6fd3110829f800000001016642d9ccd8346c403aa4c3fa451178b22534a27035cdaa6ec34ae53b29c50cb000000800bcfa3e9f1a8922ee92c6dc964d6595907c1804a86753774322b468f69d4f278000001000572c8db882674dd026b8877fbba1b700a4407da3ae9ce5fa43215a28163362b000000800000000000000000000000000000000000000000000000000000000000007a6900000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000066440eb666440eb666440eb666440eb666440eb6061ca689507c7f1ccc68c2ad086c9d5d94f50869cb1b718c6a46aaf77a4500ba", | ||
"publicInputsHash": "0x00b833c76dd93572e83879eeb4085a3cd71f24831384fb4d3fe531ed87b859e3", | ||
"numTxs": 0 | ||
} | ||
} |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was all outdated so I sneaked the fix in.