Skip to content

Commit

Permalink
add L1ERC20Bridge and fix solhint problems
Browse files Browse the repository at this point in the history
  • Loading branch information
zkbenny committed Feb 5, 2024
1 parent 243891d commit 14bf42f
Show file tree
Hide file tree
Showing 27 changed files with 790 additions and 51 deletions.
3 changes: 2 additions & 1 deletion .solhintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules/
artifacts/
artifacts-zk/
cache/
cache-zk/
cache-zk/
contracts/zksync/
6 changes: 3 additions & 3 deletions contracts/gateway/L1BaseGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {IL1Gateway} from "../interfaces/IL1Gateway.sol";

abstract contract L1BaseGateway is IL1Gateway {
/// @notice The arbitrator to confirm synchronization
IArbitrator public immutable arbitrator;
IArbitrator public immutable ARBITRATOR;

/**
* @dev This empty reserved space is put in place to allow future versions to add new
Expand All @@ -17,11 +17,11 @@ abstract contract L1BaseGateway is IL1Gateway {

/// @dev Modifier to make sure the caller is the known arbitrator.
modifier onlyArbitrator() {
require(msg.sender == address(arbitrator), "Not arbitrator");
require(msg.sender == address(ARBITRATOR), "Not arbitrator");
_;
}

constructor(IArbitrator _arbitrator) {
arbitrator = _arbitrator;
ARBITRATOR = _arbitrator;
}
}
6 changes: 3 additions & 3 deletions contracts/gateway/L2BaseGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {IL2Gateway} from "../interfaces/IL2Gateway.sol";

abstract contract L2BaseGateway is IL2Gateway {
/// @notice The zkLink contract
address public immutable zkLink;
address public immutable ZKLINK;

/**
* @dev This empty reserved space is put in place to allow future versions to add new
Expand All @@ -16,11 +16,11 @@ abstract contract L2BaseGateway is IL2Gateway {

/// @dev Ensure withdraw come from zkLink
modifier onlyZkLink() {
require(msg.sender == zkLink, "Not zkLink contract");
require(msg.sender == ZKLINK, "Not zkLink contract");
_;
}

constructor(address _zkLink) {
zkLink = _zkLink;
ZKLINK = _zkLink;
}
}
10 changes: 5 additions & 5 deletions contracts/gateway/arbitrum/ArbitrumL1Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import {IArbitrumGateway} from "../../interfaces/arbitrum/IArbitrumGateway.sol";

contract ArbitrumL1Gateway is IArbitrumGateway, L1BaseGateway, BaseGateway {
/// @notice Arbitrum inbox on local chain
Inbox public immutable inbox;
Inbox public immutable INBOX;

/// @dev Modifier to make sure the original sender is gateway on remote chain.
modifier onlyRemoteGateway() {
IBridge bridge = inbox.bridge();
IBridge bridge = INBOX.bridge();
require(msg.sender == address(bridge), "Not bridge");
IOutbox outbox = IOutbox(bridge.activeOutbox());
address l2Sender = outbox.l2ToL1Sender();
Expand All @@ -23,7 +23,7 @@ contract ArbitrumL1Gateway is IArbitrumGateway, L1BaseGateway, BaseGateway {
}

constructor(IArbitrator _arbitrator, Inbox _inbox) L1BaseGateway(_arbitrator) {
inbox = _inbox;
INBOX = _inbox;
}

function initialize() external initializer {
Expand All @@ -40,7 +40,7 @@ contract ArbitrumL1Gateway is IArbitrumGateway, L1BaseGateway, BaseGateway {
(uint256, uint256, uint256)
);
bytes memory data = abi.encodeCall(IArbitrumGateway.claimMessageCallback, (_value, _callData));
inbox.createRetryableTicket{value: msg.value}(
INBOX.createRetryableTicket{value: msg.value}(
remoteGateway,
_value,
maxSubmissionCost,
Expand All @@ -56,6 +56,6 @@ contract ArbitrumL1Gateway is IArbitrumGateway, L1BaseGateway, BaseGateway {
function claimMessageCallback(uint256 _value, bytes memory _callData) external payable onlyRemoteGateway {
require(msg.value == _value, "Invalid value");
// Forward message to arbitrator
arbitrator.receiveMessage{value: _value}(_value, _callData);
ARBITRATOR.receiveMessage{value: _value}(_value, _callData);
}
}
2 changes: 1 addition & 1 deletion contracts/gateway/arbitrum/ArbitrumL2Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ contract ArbitrumL2Gateway is IArbitrumGateway, L2BaseGateway, BaseGateway {
require(msg.value == _value, "Invalid value");

// solhint-disable-next-line avoid-low-level-calls
(bool success, ) = zkLink.call{value: _value}(_callData);
(bool success, ) = ZKLINK.call{value: _value}(_callData);
require(success, "Call zkLink failed");
}
}
4 changes: 2 additions & 2 deletions contracts/gateway/ethereum/EthereumGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ contract EthereumGateway is
require(msg.value == _value, "Invalid value");

// solhint-disable-next-line avoid-low-level-calls
(bool success, ) = zkLink.call{value: _value}(_callData);
(bool success, ) = ZKLINK.call{value: _value}(_callData);
require(success, "Call zkLink failed");
}

function sendMessage(uint256 _value, bytes memory _callData) external payable override onlyZkLink {
require(msg.value == _value, "Invalid value");
// Forward message to arbitrator
arbitrator.receiveMessage{value: _value}(_value, _callData);
ARBITRATOR.receiveMessage{value: _value}(_value, _callData);
}
}
10 changes: 5 additions & 5 deletions contracts/gateway/linea/LineaGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {ILineaGateway} from "../../interfaces/linea/ILineaGateway.sol";

abstract contract LineaGateway is BaseGateway, ILineaGateway {
/// @notice Linea message service on local chain
IMessageService public immutable messageService;
IMessageService public immutable MESSAGE_SERVICE;

/**
* @dev This empty reserved space is put in place to allow future versions to add new
Expand All @@ -18,18 +18,18 @@ abstract contract LineaGateway is BaseGateway, ILineaGateway {

/// @dev Modifier to make sure the caller is the known message service.
modifier onlyMessageService() {
require(msg.sender == address(messageService), "Not message service");
require(msg.sender == address(MESSAGE_SERVICE), "Not message service");
_;
}

/// @dev Modifier to make sure the original sender is gateway on remote chain.
modifier onlyRemoteGateway() {
require(messageService.sender() == remoteGateway, "Not remote gateway");
require(MESSAGE_SERVICE.sender() == remoteGateway, "Not remote gateway");
_;
}

constructor(IMessageService _messageService) {
messageService = _messageService;
MESSAGE_SERVICE = _messageService;
}

function __LineaGateway_init() internal onlyInitializing {
Expand All @@ -39,6 +39,6 @@ abstract contract LineaGateway is BaseGateway, ILineaGateway {
function claimMessage(uint256 _value, bytes calldata _callData, uint256 _nonce) external nonReentrant {
// `claimMessageCallback` will be called within `claimMessage`
// no fee on remote chain
messageService.claimMessage(remoteGateway, address(this), 0, _value, payable(msg.sender), _callData, _nonce);
MESSAGE_SERVICE.claimMessage(remoteGateway, address(this), 0, _value, payable(msg.sender), _callData, _nonce);
}
}
4 changes: 2 additions & 2 deletions contracts/gateway/linea/LineaL1Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ contract LineaL1Gateway is L1BaseGateway, LineaGateway {
function sendMessage(uint256 _value, bytes memory _callData, bytes memory) external payable onlyArbitrator {
// transfer no fee to Linea
bytes memory message = abi.encodeCall(ILineaGateway.claimMessageCallback, (_value, _callData));
messageService.sendMessage{value: _value}(remoteGateway, 0, message);
MESSAGE_SERVICE.sendMessage{value: _value}(remoteGateway, 0, message);
}

function claimMessageCallback(
Expand All @@ -29,6 +29,6 @@ contract LineaL1Gateway is L1BaseGateway, LineaGateway {
) external payable onlyMessageService onlyRemoteGateway {
require(msg.value == _value, "Invalid value");
// Forward message to arbitrator
arbitrator.receiveMessage{value: _value}(_value, _callData);
ARBITRATOR.receiveMessage{value: _value}(_value, _callData);
}
}
6 changes: 3 additions & 3 deletions contracts/gateway/linea/LineaL2Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ contract LineaL2Gateway is L2BaseGateway, LineaGateway {

function sendMessage(uint256 value, bytes memory callData) external payable override onlyZkLink {
// msg value should include fee
uint256 coinbaseFee = messageService.minimumFeeInWei();
uint256 coinbaseFee = MESSAGE_SERVICE.minimumFeeInWei();
require(msg.value == value + coinbaseFee, "Invalid fee");

bytes memory message = abi.encodeCall(ILineaGateway.claimMessageCallback, (value, callData));
messageService.sendMessage{value: msg.value}(address(remoteGateway), coinbaseFee, message);
MESSAGE_SERVICE.sendMessage{value: msg.value}(address(remoteGateway), coinbaseFee, message);
}

function claimMessageCallback(
Expand All @@ -32,7 +32,7 @@ contract LineaL2Gateway is L2BaseGateway, LineaGateway {
require(msg.value == _value, "Invalid value");

// solhint-disable-next-line avoid-low-level-calls
(bool success, ) = zkLink.call{value: _value}(_callData);
(bool success, ) = ZKLINK.call{value: _value}(_callData);
require(success, "Call zkLink failed");
}
}
6 changes: 3 additions & 3 deletions contracts/gateway/scroll/ScrollGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {BaseGateway} from "../BaseGateway.sol";

abstract contract ScrollGateway is BaseGateway, IScrollGateway {
/// @notice Linea message service on local chain
IScrollMessenger public immutable messageService;
IScrollMessenger public immutable MESSAGE_SERVICE;

/**
* @dev This empty reserved space is put in place to allow future versions to add new
Expand All @@ -18,12 +18,12 @@ abstract contract ScrollGateway is BaseGateway, IScrollGateway {

/// @dev Modifier to make sure the caller is the known message service.
modifier onlyMessageService() {
require(msg.sender == address(messageService), "Not message service");
require(msg.sender == address(MESSAGE_SERVICE), "Not message service");
_;
}

constructor(IScrollMessenger _messageService) {
messageService = _messageService;
MESSAGE_SERVICE = _messageService;
}

function __ScrollGateway_init() internal onlyInitializing {
Expand Down
4 changes: 2 additions & 2 deletions contracts/gateway/scroll/ScrollL1Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ contract ScrollL1Gateway is ScrollGateway, L1BaseGateway {
uint256 _finalizeMessageGasLimit = abi.decode(_adapterParams, (uint256));

bytes memory executeData = abi.encodeCall(IScrollGateway.claimMessageCallback, (_value, _callData));
messageService.sendMessage{value: msg.value}(
MESSAGE_SERVICE.sendMessage{value: msg.value}(
remoteGateway,
_value,
executeData,
Expand All @@ -40,6 +40,6 @@ contract ScrollL1Gateway is ScrollGateway, L1BaseGateway {
require(msg.value == _value, "Invalid value");

// Forward message to arbitrator
arbitrator.receiveMessage{value: msg.value}(_value, _callData);
ARBITRATOR.receiveMessage{value: msg.value}(_value, _callData);
}
}
4 changes: 2 additions & 2 deletions contracts/gateway/scroll/ScrollL2Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ contract ScrollL2Gateway is L2BaseGateway, ScrollGateway {

bytes memory callData = abi.encodeCall(IScrollGateway.claimMessageCallback, (_value, _callData));
// transfer no fee to L1
messageService.sendMessage{value: _value}(
MESSAGE_SERVICE.sendMessage{value: _value}(
remoteGateway,
_value,
callData,
Expand All @@ -34,7 +34,7 @@ contract ScrollL2Gateway is L2BaseGateway, ScrollGateway {
require(msg.value == _value, "Invalid value");

// solhint-disable-next-line avoid-low-level-calls
(bool success, ) = zkLink.call{value: _value}(_callData);
(bool success, ) = ZKLINK.call{value: _value}(_callData);
require(success, "Call zkLink failed");
}
}
10 changes: 5 additions & 5 deletions contracts/gateway/zkpolygon/ZkPolygonL1Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import {BaseGateway} from "../BaseGateway.sol";

contract ZkPolygonL1Gateway is IZkPolygonGateway, L1BaseGateway, BaseGateway {
/// @notice ZkPolygon message service on local chain
IZkPolygon public immutable messageService;
IZkPolygon public immutable MESSAGE_SERVICE;

uint32 public constant ETH_NETWORK_ID = 1;
// Default to true
bool public constant FORCE_UPDATE_GLOBAL_EXIT_ROOT = true;

modifier onlyMessageService() {
require(msg.sender == address(messageService), "Not remote gateway");
require(msg.sender == address(MESSAGE_SERVICE), "Not remote gateway");
_;
}

Expand All @@ -25,7 +25,7 @@ contract ZkPolygonL1Gateway is IZkPolygonGateway, L1BaseGateway, BaseGateway {
mapping(uint256 => mapping(uint256 => bool)) public isMessageFinalized;

constructor(IArbitrator _arbitrator, IZkPolygon _messageService) L1BaseGateway(_arbitrator) {
messageService = _messageService;
MESSAGE_SERVICE = _messageService;
}

function initialize() external initializer {
Expand All @@ -34,7 +34,7 @@ contract ZkPolygonL1Gateway is IZkPolygonGateway, L1BaseGateway, BaseGateway {

function sendMessage(uint256 _value, bytes memory _callData, bytes memory) external payable onlyArbitrator {
bytes memory executeData = abi.encodeCall(IZkPolygonGateway.claimMessageCallback, (_value, _callData));
messageService.bridgeMessage{value: msg.value}(
MESSAGE_SERVICE.bridgeMessage{value: msg.value}(
ETH_NETWORK_ID,
remoteGateway,
FORCE_UPDATE_GLOBAL_EXIT_ROOT,
Expand All @@ -44,6 +44,6 @@ contract ZkPolygonL1Gateway is IZkPolygonGateway, L1BaseGateway, BaseGateway {

function claimMessageCallback(uint256 _value, bytes memory _callData) external payable override onlyMessageService {
require(msg.value == _value, "Invalid value");
arbitrator.receiveMessage{value: _value}(_value, _callData);
ARBITRATOR.receiveMessage{value: _value}(_value, _callData);
}
}
10 changes: 5 additions & 5 deletions contracts/gateway/zkpolygon/ZkPolygonL2Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ import {BaseGateway} from "../BaseGateway.sol";

contract ZkPolygonL2Gateway is IZkPolygonGateway, L2BaseGateway, BaseGateway {
/// @notice ZkPolygon message service on local chain
IZkPolygon public immutable messageService;
IZkPolygon public immutable MESSAGE_SERVICE;

uint32 public constant ETH_NETWORK_ID = 0;
// Default to true
bool public constant FORCE_UPDATE_GLOBAL_EXIT_ROOT = true;

/// @dev Modifier to make sure the original sender is messageService on remote chain.
modifier onlyMessageService() {
require(msg.sender == address(messageService), "Not remote gateway");
require(msg.sender == address(MESSAGE_SERVICE), "Not remote gateway");
_;
}

constructor(address _zkLink, IZkPolygon _messageService) L2BaseGateway(_zkLink) {
messageService = _messageService;
MESSAGE_SERVICE = _messageService;
}

function initialize() external initializer {
Expand All @@ -30,7 +30,7 @@ contract ZkPolygonL2Gateway is IZkPolygonGateway, L2BaseGateway, BaseGateway {

function sendMessage(uint256 _value, bytes memory _callData) external payable onlyZkLink {
bytes memory executeData = abi.encodeCall(IZkPolygonGateway.claimMessageCallback, (_value, _callData));
messageService.bridgeMessage{value: msg.value}(
MESSAGE_SERVICE.bridgeMessage{value: msg.value}(
ETH_NETWORK_ID,
remoteGateway,
FORCE_UPDATE_GLOBAL_EXIT_ROOT,
Expand All @@ -40,7 +40,7 @@ contract ZkPolygonL2Gateway is IZkPolygonGateway, L2BaseGateway, BaseGateway {

function claimMessageCallback(uint256 _value, bytes memory _callData) external payable onlyMessageService {
require(msg.value == _value, "Invalid value");
(bool success, ) = zkLink.call{value: _value}(_callData);
(bool success, ) = ZKLINK.call{value: _value}(_callData);
require(success, "Call zkLink failed");
}
}
10 changes: 5 additions & 5 deletions contracts/gateway/zksync/ZkSyncL1Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import {L2Message} from "../../zksync/l1-contracts/zksync/Storage.sol";

contract ZkSyncL1Gateway is IZkSyncL1Gateway, L1BaseGateway, BaseGateway {
/// @notice ZkSync message service on local chain
IMailbox public immutable messageService;
IMailbox public immutable MESSAGE_SERVICE;

/// @dev A mapping L2 batch number => message number => flag
/// @dev Used to indicate that zkSync L2 -> L1 message was already processed
mapping(uint256 => mapping(uint256 => bool)) public isMessageFinalized;

constructor(IArbitrator _arbitrator, IMailbox _messageService) L1BaseGateway(_arbitrator) {
messageService = _messageService;
MESSAGE_SERVICE = _messageService;
}

/// @dev Receive eth from zkSync canonical bridge
Expand All @@ -35,7 +35,7 @@ contract ZkSyncL1Gateway is IZkSyncL1Gateway, L1BaseGateway, BaseGateway {
) external payable onlyArbitrator {
(uint256 _l2GasLimit, uint256 _l2GasPerPubdataByteLimit) = abi.decode(_adapterParams, (uint256, uint256));
bytes memory executeData = abi.encodeCall(IZkSyncL2Gateway.claimMessage, (_value, _callData));
messageService.requestL2Transaction{value: msg.value}(
MESSAGE_SERVICE.requestL2Transaction{value: msg.value}(
remoteGateway,
_value,
executeData,
Expand All @@ -62,7 +62,7 @@ contract ZkSyncL1Gateway is IZkSyncL1Gateway, L1BaseGateway, BaseGateway {
data: _message
});

bool success = messageService.proveL2MessageInclusion(
bool success = MESSAGE_SERVICE.proveL2MessageInclusion(
_l2BatchNumber,
_l2MessageIndex,
l2ToL1Message,
Expand All @@ -75,6 +75,6 @@ contract ZkSyncL1Gateway is IZkSyncL1Gateway, L1BaseGateway, BaseGateway {

// Forward message to arbitrator
(uint256 value, bytes memory callData) = abi.decode(_message, (uint256, bytes));
arbitrator.receiveMessage{value: value}(value, callData);
ARBITRATOR.receiveMessage{value: value}(value, callData);
}
}
2 changes: 1 addition & 1 deletion contracts/gateway/zksync/ZkSyncL2Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ contract ZkSyncL2Gateway is IZkSyncL2Gateway, L2BaseGateway, BaseGateway {
require(msg.value == _value, "Invalid value");

// solhint-disable-next-line avoid-low-level-calls
(bool success, ) = zkLink.call{value: _value}(_callData);
(bool success, ) = ZKLINK.call{value: _value}(_callData);
require(success, "Call zkLink failed");
}
}
Loading

0 comments on commit 14bf42f

Please sign in to comment.