Skip to content

Adds "real" L1 and L2 message passing contracts.#236

Merged
karlfloersch merged 11 commits intomasterfrom
YAS-581/contracts/Messenger
Sep 15, 2020
Merged

Adds "real" L1 and L2 message passing contracts.#236
karlfloersch merged 11 commits intomasterfrom
YAS-581/contracts/Messenger

Conversation

@smartcontracts
Copy link
Contributor

Description

Helloooo. This PR adds the "real" L1CrossDomainMessenger and L2CrossDomainMessenger contracts, along with interfaces and mocks for both. We'll have to make sure to update optimism-devex to account for these changes.

I think I've hit all of the necessary logic here (including checking inclusion proofs on the L1 side). Only thing left is to check that the state batch header timestamp is sufficiently old (requires a larger set of changes to various contracts).

Metadata

Fixes

Contributing Agreement

Copy link
Contributor

@karlfloersch karlfloersch left a comment

Choose a reason for hiding this comment

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

Alright this LG(reat)TM! Left one comment on standardizing the L1 / L2 interfaces & how this can allow us to keep the old mock-ed contracts based on the assumption that some of the inner workings of replay & verification happen in the background and can be unit-tested elsewhere / don't need to be in the mocks.

*/
function sendMessage(
address _target,
bytes memory _message
Copy link
Contributor

Choose a reason for hiding this comment

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

As we discussed in person, I think it makes sense to add a gasLimit to this function and this way we can actually keep the old mocks. As long as we assume that the "relay message" on L1 & the "replay" functionality is handled in some standardized way, then developers building for L1 / L2 shouldn't have to unit test that functionality. It should just "happen" in the background.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmm, interesting. After the Synthetix call today, I feel like having the full interface is probably useful for developers. We can always add a wrapper that ignores these extra parameters later if it seems to be useful.

/**
* @title MockL1CrossDomainMessenger
*/
contract MockL1CrossDomainMessenger is L1CrossDomainMessenger {
Copy link
Contributor

Choose a reason for hiding this comment

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

So is it possible to just have a MockCrossDomainMessenger like before and not have them inherit from the more complete L1 / L2 messengers?

Basically we don't mock whole async 'relay' functionality in the mock version of the tests because that is all handled in the background for users / dapps

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So these mocks bypass the proof checks within the complete contracts. It keeps the interface the same and does minimal verification so that developers can sanity check for common cases (e.g., attempting to send the same message twice). I feel like it's a good middle ground for now.

Copy link
Contributor

@karlfloersch karlfloersch Sep 2, 2020

Choose a reason for hiding this comment

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

so that developers can sanity check for common cases (e.g., attempting to send the same message twice).

Do you think that developers should write unit tests which call replayMessage(...) ? My guess would be that this is not really required in the same way that developers normally don't add tests for users who send a tx with under-priced gas & then use a replace tx with higher gas price.

Generally down to keep this interface but I just want to make sure that we're on the same page wrt what makes sense to put in unit tests

Copy link
Contributor

@karlfloersch karlfloersch Sep 2, 2020

Choose a reason for hiding this comment

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

To me the biggest thing missing in our mocks is a helper function which you can import called waitForCrossDomainMessage(txHash) which can be used something like this:

// Do something which sends a message to L2
const txHash = await myL1Contract.sendDepositToL2()
// Wait for the L1->L2 message to be processed
await waitForCrossDomainMessage(txHash)
// Do another thing on L2 like spend the deposit
await myL2Contract.spendMyMoney()

This way we can (in both L1->L2 direction & L2->L1 direction) just wait for the transaction to be "mined" / applied. And then when we build the "real" version we add a little util which is used for waiting for the same behavior.

I still am into to keeping the L1XDomainMessenger & L2XDomainMessenger separate--that way we can figure out a better way to mock out the fact that L2->L1 messages take a week. But other than that I feel like this is a solid abstraction.

Copy link
Contributor

@karlfloersch karlfloersch left a comment

Choose a reason for hiding this comment

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

I want to get this merged but there are a few updates we need to make:

  1. Update the MockL1/MockL2CrossDomainMessengers to use the same sendMessage(...) interface which includes gasLimit for the L2CrossDomainMessenger.
  2. Add a waitForCrossDomainMessage(txHash) function which can be used in the mock. This is a standin for what we will need when we implement these unit tests against the real backend. (described here)
  3. Update https://github.com/ethereum-optimism/Buidler-Deposit-Withdraw-Example to reflect these changes.

Once the mocks are set up this should be good for a merge!

Copy link
Contributor

@karlfloersch karlfloersch left a comment

Choose a reason for hiding this comment

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

Dope this looks great! I remember you said that you updated the deposit / withdrawal example & it worked - is that pushed somewhere I can take a look at?

Anyway, hype! Excited to get this merged

);

return EthMerkleTrie.proveAccountStorageSlotValue(
0x4200000000000000000000000000000000000000,
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a ovm specific precompile address? Maybe a good idea to turn it into a constant so its not a magic number

@karlfloersch karlfloersch merged commit cb2de09 into master Sep 15, 2020
/**
* @title MockL1CrossDomainMessenger
*/
contract MockL1CrossDomainMessenger is BaseMockCrossDomainMessenger, L1CrossDomainMessenger {
Copy link

Choose a reason for hiding this comment

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

this contract misses the constructor call for the super class

/**
* @title MockL2CrossDomainMessenger
*/
contract MockL2CrossDomainMessenger is BaseMockCrossDomainMessenger, L2CrossDomainMessenger {
Copy link

Choose a reason for hiding this comment

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

ditto. This contract misses the super constructor call as well

@karlfloersch karlfloersch deleted the YAS-581/contracts/Messenger branch November 3, 2020 15:47
snario pushed a commit that referenced this pull request Apr 14, 2021
bap2pecs pushed a commit to babylonlabs-io/optimism that referenced this pull request Jul 31, 2024
xibao-nr pushed a commit to node-real/combo-optimism that referenced this pull request Feb 19, 2025
shenkeyao referenced this pull request in EspressoSystems/optimism-espresso-integration Mar 1, 2025
* migration: Update to UnreleasedTreasury contract

* Update op-chain-ops/cmd/celo-migrate/state.go

Co-authored-by: Karl Bartel <karl@karl.berlin>

* Update op-chain-ops/cmd/celo-migrate/state.go

Co-authored-by: Karl Bartel <karl@karl.berlin>

---------

Co-authored-by: Karl Bartel <karl@karl.berlin>
QuentinI referenced this pull request in EspressoSystems/optimism-espresso-integration Mar 7, 2025
* migration: Update to UnreleasedTreasury contract

* Update op-chain-ops/cmd/celo-migrate/state.go

Co-authored-by: Karl Bartel <karl@karl.berlin>

* Update op-chain-ops/cmd/celo-migrate/state.go

Co-authored-by: Karl Bartel <karl@karl.berlin>

---------

Co-authored-by: Karl Bartel <karl@karl.berlin>
theochap pushed a commit that referenced this pull request Dec 10, 2025
* feat(ci): Dependabot config

## Overview

Introduces jonhoo's dependabot config, which notifies on outdated github
actions as well as outdated crate dependencies.

* chore: Bump dependencies

## Overview

Bumps dependencies in the workspace, before dependabot gets to them.
Zena-park added a commit to tokamak-network/optimism that referenced this pull request Dec 30, 2025
theochap pushed a commit that referenced this pull request Jan 15, 2026
emhane pushed a commit that referenced this pull request Feb 3, 2026
This PR separates storage and account cursors which makes sense because
these two cursors may have very different seek/next implementations. In
the case of in-memory, a single cursor impl can still handle both, but
for MDBX, it makes sense to implement separate cursors.

Closes #236

---------

Co-authored-by: Arun Dhyani <dhyaniarun7@gmail.com>
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.

4 participants