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

Adding zksync relay support #13

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions script/input/5/integration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"domains": {
"root": {
"rpc": "ETH_RPC_URL",
"chainlog": "0xdA0Ab1e0017DEbCd72Be8599041a2aa3bA7e740F"
},
"optimism": {
"rpc": "OPT_RPC_URL",
"l1Messenger": "0x5086d1eEF304eb5284A0f6720f79403b4e9bE294",
"l2Messenger": "0x4200000000000000000000000000000000000007"
},
"arbitrum": {
"rpc": "ARB_RPC_URL",
"inbox": "0x6BEbC4925716945D46F0Ec336D5C2564F419682C",
"arbSys": "0x0000000000000000000000000000000000000064"
},
"zkSync": {
"rpc": "ZKSYNC_RPC_URL",
"zkSyncMailbox": "0xcB3D5008e03Bf569dcdf17259Fa30726ED646931",
"l1MessengerContract": "0x0000000000000000000000000000000000008008"
}
}
}
73 changes: 73 additions & 0 deletions src/domains/ZKSyncDomain.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// Copyright (C) 2022 Dai Foundation
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
pragma solidity >=0.8.0;

import "forge-std/Vm.sol";

import { Domain, BridgedDomain } from "./BridgedDomain.sol";

contract ZKSyncDomain is BridgedDomain {

address public immutable zkSyncMailbox;
address public immutable l1MessengerContract;

bytes32 constant SENT_MESSAGE_TOPIC = keccak256("SentMessage(address,address,bytes,uint256,uint256)");

constructor(string memory _config, string memory _name, Domain _hostDomain) Domain(_config, _name) BridgedDomain(_hostDomain) {
zkSyncMailbox = MessengerLike(readConfigAddress("zkSyncMailbox"));
l1MessengerContract = MessengerLike(readConfigAddress("l1MessengerContract"));
vm.recordLogs();
}

function relayFromHost(bool switchToGuest) external override {
selectFork();
address malias;
unchecked {
malias = address(uint160(address(l1Messenger)) + OFFSET);
}

// Read all L1 -> L2 messages and relay them this fork
Vm.Log[] memory logs = vm.getRecordedLogs();
for (uint256 i = 0; i < logs.length; i++) {
Vm.Log memory log = logs[i];
if (log.topics[0] == SENT_MESSAGE_TOPIC) {
// TODO
}
}

if (!switchToGuest) {
hostDomain.selectFork();
}
}

function relayToHost(bool switchToHost) external override {
hostDomain.selectFork();

// Read all L2 -> L1 messages and relay them under host fork
Vm.Log[] memory logs = vm.getRecordedLogs();
for (uint256 i = 0; i < logs.length; i++) {
Vm.Log memory log = logs[i];
if (log.topics[0] == SENT_MESSAGE_TOPIC) {
// TODO
}
}

if (!switchToHost) {
selectFork();
}
}

}