-
Notifications
You must be signed in to change notification settings - Fork 284
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: decoder return l1<->l2 msgs #597
Conversation
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.
lgtm, all comments are nits
l1-contracts/src/core/Decoder.sol
Outdated
} | ||
|
||
/** | ||
* Computes a hash of the public inputs from the calldata | ||
* @param _l2Block - The L2 block calldata. | ||
* @return sha256(header[0x4: 0x23c], diffRoot, l1Tol2MessagesHash) | ||
*/ | ||
function _computePublicInputsHash(bytes calldata _l2Block) internal pure returns (bytes32) { | ||
function _computePublicInputsHash(bytes calldata _l2Block) |
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.
The name of this doesnt make sense anymore if its also returning the message arrays. Comment natspec also needs updated
l1-contracts/src/core/Decoder.sol
Outdated
function _computePublicInputsHash(bytes calldata _l2Block) | ||
internal | ||
pure | ||
returns (bytes32, bytes32[] memory l2ToL1Msgs, bytes32[] memory l1ToL2Msgs) |
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.
some named return values while others arent
l1-contracts/src/core/Decoder.sol
Outdated
assembly { | ||
let endOfTreesData := sub(0x23c, 0x04) | ||
mstore(add(temp, add(0x20, endOfTreesData)), diffRoot) | ||
mstore(add(temp, add(0x40, endOfTreesData)), l1ToL2messagesHash) | ||
} | ||
|
||
return bytes32(uint256(sha256(temp)) % P); | ||
return (bytes32(uint256(sha256(temp)) % P), l2ToL1Msgs, l1ToL2Msgs); |
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.
may as well make the mod p variable named on its own then you can spare the return statement. Having a calc in the return statement while others are pre calculated is a bit messy can we be consistent?
@@ -236,6 +250,15 @@ contract Decoder { | |||
offsets.contractDataOffset = offsets.contractOffset + lengths.contractCount * 0x20; | |||
offsets.l1ToL2MessagesOffset = offsets.contractDataOffset + 0x4 + lengths.contractCount * 0x34; | |||
|
|||
// load the l2 to l1 msgs | |||
assembly { |
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.
Can this array copy be moved down to where the other one is performed?
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.
I'm using that we just computer the offset values. We will be updating them every loop so was a nice way to have it right away.
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.
understood
l1-contracts/src/core/Decoder.sol
Outdated
internal | ||
pure | ||
returns (bytes32, bytes32) | ||
returns (bytes32, bytes32[] memory, bytes32[] memory, bytes32) |
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.
returns (bytes32, bytes32[] memory, bytes32[] memory, bytes32) | |
returns (bytes32, bytes32, bytes32[] memory, bytes32[] memory) |
id probably prefer the hashes to be together and the arrays together
l1-contracts/test/Decoder.t.sol
Outdated
@@ -102,6 +121,15 @@ contract DecoderTest is Test { | |||
"Invalid public input hash" | |||
); | |||
|
|||
for (uint256 i = 0; i < l2ToL1Msgs.length; i++) { | |||
assertEq( | |||
l2ToL1Msgs[i], bytes32(uint256(0x300 + 32 * (1 + i / 2) + i % 2)), "Invalid l2ToL1Msgs" |
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.
can you lift the value calc up a line so its a bit more readable
(ps. bruh we gotta automate test generation)
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.
Will be adding the test in the integration test for L1 publisher when adding in rollup, then tested in there for the automatic.
For our use, even if I like foundry more, TS seems like a better fit to have the tests because we will have so much encoding and stuff to deal with 😬 I only really see our foundry tests right now as useful for better debugging when building and for checking stuff without all the encoding/decoding.
l1-contracts/src/core/Decoder.sol
Outdated
let endOfTreesData := sub(0x23c, 0x04) | ||
mstore(add(temp, add(0x20, endOfTreesData)), diffRoot) | ||
mstore(add(temp, add(0x40, endOfTreesData)), l1ToL2messagesHash) | ||
} | ||
|
||
return bytes32(uint256(sha256(temp)) % P); | ||
publicInputHash = bytes32(uint256(sha256(temp)) % P); |
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.
sorry to be annoying again but this asm can be in its own function with the diffRoot and msgHash passed in
@@ -236,6 +250,15 @@ contract Decoder { | |||
offsets.contractDataOffset = offsets.contractOffset + lengths.contractCount * 0x20; | |||
offsets.l1ToL2MessagesOffset = offsets.contractDataOffset + 0x4 + lengths.contractCount * 0x34; | |||
|
|||
// load the l2 to l1 msgs | |||
assembly { |
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.
understood
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.
overall LGTM - 1 nit on naming
l1-contracts/src/core/Decoder.sol
Outdated
@@ -341,25 +351,23 @@ contract Decoder { | |||
} | |||
|
|||
bytes32 diffRoot = _computeRoot(baseLeafs); | |||
|
|||
bytes32[] memory l1ToL2Messages; | |||
bytes32 messagesHash; | |||
{ | |||
uint256 messagesHashPreimageSize = 0x20 * L1_TO_L2_MESSAGES_PER_ROLLUP; |
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.
nit: Should messagesHashPreimageSize
be renamed to L1ToL2MesssagesHashPreimageSize
for consistency?
Same for messagesHash
. It is unclear to me if it is for L1toL2 or L2toL1 or does it also include other kind of messages. In the natspec, you call this L1ToL2MessagesHash
Description
Useful for #523.
The decoder will now return a list of l1 -> l2 and l2 -> l1 messages to the rollup. These can be used for batch insertsion into inbox and outboxes.
Notice that this will be returning zero values for empty messages, so the batch insertion should be altered to skip when "empty" messages are received. This is safe under the assumption that no-one have a preimage that hashes to 0.
Checklist: