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

zkSync: L1 & L2 Messenger contracts #1797

Open
GabrielBuragev opened this issue May 11, 2023 · 1 comment · May be fixed by #2195
Open

zkSync: L1 & L2 Messenger contracts #1797

GabrielBuragev opened this issue May 11, 2023 · 1 comment · May be fixed by #2195

Comments

@GabrielBuragev
Copy link
Contributor

GabrielBuragev commented May 11, 2023

Rationale

Messaging in zkSync uses two contracts: one deployed on L2 (implementing the IL2Messenger interface) and one deployed on L1 (implementing the IMailbox interface).

Messages coming in the direction L1 -> L2 are being payed for upon calling the Mailbox contract on L1. Validators take care that this message has been propagated and executed on L2.

Messages coming in the direction L2 -> L1 are only being included in a block and executing them is completely left on us. Their contracts only allow us to prove that a message, by checking against the keccak hash of the message bytes & merkle proof, was really sent from L2 to L1.

Before reading on, please take a look at the documentation of the Mailbox contract here https://era.zksync.io/docs/dev/developer-guides/system-contracts.html#mailboxfacet

Now, lets take a look at all the contracts/functionality we will need.

L1 Messenger Contract

This contract takes care of incoming messages from other rollups. It needs to communicate with the Mailbox contract of zkSync (on L1) in order to bridge a message from L1 to L2 (zkSync).

Here you can find the function (requestL2Transaction) that needs to be called on their Mailbox interface: https://github.com/matter-labs/era-contracts/blob/main/ethereum/contracts/zksync/interfaces/IMailbox.sol#L119-L127

Make sure you go through this documentation in order to understand how to prepare the values that you need to provide to the requestL2Transaction function call inside our contract.

This contract will need to pay for the L1 -> L2 message so make sure you implement a deposit/withdraw mechanism (check our ArbitrumL1Messenger).

L1 Prove & Execute contract

Since their L2 -> L1 messaging system doesn't execute the messages nor does it provide an interface for automatically proving & executing a message coming from L2, we need to take of this on our end.
We will need one more contract that acts as a message executor on L1 (https://era.zksync.io/docs/dev/developer-guides/bridging/l2-l1.html#example). This contract will be called by the relayer when an L1 resolution has been triggered.

L2 Messenger Contract

This contract takes care of messages coming from our FillManager on zkSync to L1. It needs to interact with a contract that implements their IL1Messenger interface. More specifically, it needs to call the sendToL1 function.

msg.sender Aliasing

Provided is an interface for aliasing addresses in both directions (L1 -> L2 & L2 -> L1).
It might be necessary to use this in our contracts in order to ensure the existence of our trusted call chain. Check our other messenger contracts and how they implement our RestrictedCalls interface to understand why this is important.

@andfletcher andfletcher added needs discussion Unclear issue description and needs further discussion before refinement can be done needs refinement Issues that have been align on and now need to go through the refinement process labels May 11, 2023
@andfletcher andfletcher removed needs discussion Unclear issue description and needs further discussion before refinement can be done needs refinement Issues that have been align on and now need to go through the refinement process labels Jul 26, 2023
@manuelwedler manuelwedler self-assigned this Jul 31, 2023
@manuelwedler
Copy link
Contributor

I pushed my current state to here: https://github.com/beamer-bridge/beamer/tree/contracts/zksync-support

It includes the L2Messenger and the execution function on L1. callAllowed and sendMessage of the ZkSyncL1Messenger are still missing.

@manuelwedler manuelwedler linked a pull request Sep 4, 2023 that will close this issue
@manuelwedler manuelwedler removed their assignment Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants