Skip to content

feat: decoder return l1<->l2 msgs#597

Merged
LHerskind merged 6 commits into
masterfrom
lh/decoder-l1-l2-msgs
May 17, 2023
Merged

feat: decoder return l1<->l2 msgs#597
LHerskind merged 6 commits into
masterfrom
lh/decoder-l1-l2-msgs

Conversation

@LHerskind

@LHerskind LHerskind commented May 16, 2023

Copy link
Copy Markdown
Contributor

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:

  • I have reviewed my diff in github, line by line.
  • Every change is related to the PR description.
  • I have linked this pull request to the issue(s) that it resolves.
  • There are no unexpected formatting changes, superfluous debug logs, or commented-out code.
  • The branch has been merged or rebased against the head of its merge target.
  • I'm happy for the PR to be merged at the reviewer's next convenience.

@LHerskind LHerskind marked this pull request as ready for review May 16, 2023 17:04

@Maddiaa0 Maddiaa0 left a comment

Copy link
Copy Markdown
Member

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

Comment thread l1-contracts/src/core/Decoder.sol Outdated
* @return sha256(header[0x4: 0x23c], diffRoot, l1Tol2MessagesHash)
*/
function _computePublicInputsHash(bytes calldata _l2Block) internal pure returns (bytes32) {
function _computePublicInputsHash(bytes calldata _l2Block)

Copy link
Copy Markdown
Member

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

Comment thread l1-contracts/src/core/Decoder.sol Outdated
function _computePublicInputsHash(bytes calldata _l2Block)
internal
pure
returns (bytes32, bytes32[] memory l2ToL1Msgs, bytes32[] memory l1ToL2Msgs)

Copy link
Copy Markdown
Member

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

Comment thread l1-contracts/src/core/Decoder.sol Outdated
}

return bytes32(uint256(sha256(temp)) % P);
return (bytes32(uint256(sha256(temp)) % P), l2ToL1Msgs, l1ToL2Msgs);

Copy link
Copy Markdown
Member

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?

offsets.l1ToL2MessagesOffset = offsets.contractDataOffset + 0x4 + lengths.contractCount * 0x34;

// load the l2 to l1 msgs
assembly {

Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
Contributor Author

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

understood

Comment thread l1-contracts/src/core/Decoder.sol Outdated
internal
pure
returns (bytes32, bytes32)
returns (bytes32, bytes32[] memory, bytes32[] memory, bytes32)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Comment thread l1-contracts/test/Decoder.t.sol Outdated

for (uint256 i = 0; i < l2ToL1Msgs.length; i++) {
assertEq(
l2ToL1Msgs[i], bytes32(uint256(0x300 + 32 * (1 + i / 2) + i % 2)), "Invalid l2ToL1Msgs"

@Maddiaa0 Maddiaa0 May 16, 2023

Copy link
Copy Markdown
Member

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)

Copy link
Copy Markdown
Contributor Author

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.

Comment thread l1-contracts/src/core/Decoder.sol Outdated
}

return bytes32(uint256(sha256(temp)) % P);
publicInputHash = bytes32(uint256(sha256(temp)) % P);

Copy link
Copy Markdown
Member

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

offsets.l1ToL2MessagesOffset = offsets.contractDataOffset + 0x4 + lengths.contractCount * 0x34;

// load the l2 to l1 msgs
assembly {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

understood

@rahul-kothari rahul-kothari left a comment

Copy link
Copy Markdown
Contributor

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

Comment thread l1-contracts/src/core/Decoder.sol Outdated
bytes32[] memory l1ToL2Messages;
bytes32 messagesHash;
{
uint256 messagesHashPreimageSize = 0x20 * L1_TO_L2_MESSAGES_PER_ROLLUP;

Copy link
Copy Markdown
Contributor

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

@LHerskind LHerskind merged commit 83a0f63 into master May 17, 2023
@LHerskind LHerskind deleted the lh/decoder-l1-l2-msgs branch May 17, 2023 09:48
ludamad pushed a commit that referenced this pull request Jul 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants