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

L1<>L2 basic contracts - Inbox, outbox, message bridge #540

Merged
merged 8 commits into from
May 16, 2023
Merged

Conversation

rahul-kothari
Copy link
Contributor

@rahul-kothari rahul-kothari commented May 10, 2023

Description

Closes #517
Closes #516

TODO: Add tests

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.

@rahul-kothari rahul-kothari force-pushed the rk/inbox branch 2 times, most recently from 9b5fc05 to e11e2a3 Compare May 10, 2023 16:02
Copy link
Contributor

@LHerskind LHerskind left a comment

Choose a reason for hiding this comment

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

Added a few comments

l1-contracts/src/core/messagebridge/Outbox.sol Outdated Show resolved Hide resolved
l1-contracts/src/core/messagebridge/Outbox.sol Outdated Show resolved Hide resolved
l1-contracts/src/core/messagebridge/Outbox.sol Outdated Show resolved Hide resolved
l1-contracts/src/core/messagebridge/Outbox.sol Outdated Show resolved Hide resolved
l1-contracts/src/core/messagebridge/MessageBox.sol Outdated Show resolved Hide resolved
l1-contracts/src/core/messagebridge/MessageBox.sol Outdated Show resolved Hide resolved
l1-contracts/src/core/messagebridge/Inbox.sol Outdated Show resolved Hide resolved
l1-contracts/src/core/messagebridge/Inbox.sol Outdated Show resolved Hide resolved
l1-contracts/src/core/messagebridge/Inbox.sol Outdated Show resolved Hide resolved
l1-contracts/src/core/messagebridge/Outbox.sol Outdated Show resolved Hide resolved
@rahul-kothari rahul-kothari force-pushed the rk/inbox branch 4 times, most recently from 88687a4 to 293acc3 Compare May 15, 2023 10:28
l1-contracts/src/core/messagebridge/MessageBox.sol Outdated Show resolved Hide resolved
l1-contracts/src/core/messagebridge/MessageBox.sol Outdated Show resolved Hide resolved
l1-contracts/src/core/messagebridge/Outbox.sol Outdated Show resolved Hide resolved
l1-contracts/src/core/messagebridge/Outbox.sol Outdated Show resolved Hide resolved
l1-contracts/src/core/messagebridge/Inbox.sol Outdated Show resolved Hide resolved
function batchConsume(bytes32[] memory entryKeys, address _feeCollector) external onlyRollup {
uint256 totalFee = 0;
for (uint256 i = 0; i < entryKeys.length; i++) {
// TODO: Combine these to optimise for gas.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this todo still active? Or is this referring to the storage packing?

l1-contracts/src/core/messagebridge/Inbox.sol Outdated Show resolved Hide resolved
l1-contracts/src/core/messagebridge/MessageBox.sol Outdated Show resolved Hide resolved
l1-contracts/src/core/messagebridge/MessageBox.sol Outdated Show resolved Hide resolved
@LHerskind
Copy link
Contributor

When passing in structs to functions e.g., sendL2Message(L2Actor memory _recipient it often becomes more cumbersome to use as you need to import or define the struct, with foundry sometimes being unhappy about same struct defined multiple places if simply copying. Think it would be better if we don't have structs as the inputs for functions that are used externally or at least create a data structures library that can easily be imported for usage.

@LHerskind
Copy link
Contributor

LHerskind commented May 16, 2023

For the registry. Also useful to support fetching just one of the values. For portals doing an exit they don't need to know of the inbox so it wastes gas to fetch it if only supporting getL1L2Addresses.

Similar for the message box, your onlyRollup() modifier is pulling unused values from registry.

@Maddiaa0
Copy link
Member

Maddiaa0 commented May 16, 2023

For the registry. Also useful to support fetching just one of the values. For portals doing an exit they don't need to know of the inbox so it wastes gas to fetch it if only supporting getL1L2Addresses.

Similar for the message box, your onlyRollup() modifier is pulling unused values from registry.

I've implemented this with interfaces for moving the structs about on my branch if you wanna yoink it @rahul-kothari md/scaffold-l1-l2-e2e

@rahul-kothari rahul-kothari marked this pull request as ready for review May 16, 2023 14:05
@rahul-kothari rahul-kothari changed the title WIP: inbox and message box contracts L1<>L2 basic contracts - Inbox, outbox, message bridge May 16, 2023
* fix: data structure library

* fix: forge fmt
Copy link
Contributor

@LHerskind LHerskind left a comment

Choose a reason for hiding this comment

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

I think its fine to get in, then the last comments here which is more nits can be fixed in a separate pr such that we can move along.

bytes32 _secretHash
) external payable returns (bytes32) {
if (_deadline <= block.timestamp) revert Inbox__DeadlineBeforeNow();
uint64 fee = uint64(msg.value);
Copy link
Contributor

Choose a reason for hiding this comment

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

This cast is unsafe, if paying more than 2**64 wei, some will simply be lost. If this is desired approach, add a note why.

l1-contracts/test/Inbox.t.sol Show resolved Hide resolved
l1-contracts/test/Inbox.t.sol Show resolved Hide resolved
l1-contracts/test/Outbox.t.sol Show resolved Hide resolved
@LHerskind LHerskind merged commit a866823 into master May 16, 2023
@LHerskind LHerskind deleted the rk/inbox branch May 16, 2023 15:40
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.

Build contract for input side of L1 -> L2 message box Build contract for output side of L2 -> L1 message box
3 participants