Skip to content

Commit

Permalink
refactor: separation of the app-agnostic gateway interfaces and the K…
Browse files Browse the repository at this point in the history
…leros-specific gateways
  • Loading branch information
jaybuidl committed Jul 27, 2022
1 parent b8e50b4 commit 45c123d
Show file tree
Hide file tree
Showing 19 changed files with 284 additions and 271 deletions.
5 changes: 2 additions & 3 deletions contracts/src/bridge/FastBridgeSender.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ contract FastBridgeSender is IFastBridgeSender, ISafeBridgeSender {
/**
* @dev Constructor.
* @param _epochPeriod The duration between epochs.
* @param _safeBridgeReceiver The the Safe Bridge Router on Ethereum to the foreign chain.
* @param _safeBridgeReceiver The the Safe Bridge Router on Ethereum to the receiving chain.
*/
constructor(uint256 _epochPeriod, address _safeBridgeReceiver) {
epochPeriod = _epochPeriod;
Expand Down Expand Up @@ -103,8 +103,7 @@ contract FastBridgeSender is IFastBridgeSender, ISafeBridgeSender {
}

/**
* Sends a batch of arbitrary message from one domain to another
* via the fast bridge mechanism.
* Sends a batch of arbitrary message from one domain to another via the fast bridge mechanism.
*/
function sendBatch() external override {
uint256 epoch = block.timestamp / epochPeriod;
Expand Down
21 changes: 21 additions & 0 deletions contracts/src/bridge/interfaces/IReceiverGateway.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: MIT

/**
* @authors: [@jaybuidl, @shotaronowhere]
* @reviewers: []
* @auditors: []
* @bounties: []
* @deployments: []
*/

pragma solidity ^0.8.0;

import "../../bridge/interfaces/IFastBridgeReceiver.sol";

interface IReceiverGateway {
function fastBridgeReceiver() external view returns (IFastBridgeReceiver);

function senderChainID() external view returns (uint256);

function senderGateway() external view returns (address);
}
4 changes: 2 additions & 2 deletions contracts/src/bridge/interfaces/ISafeBridgeSender.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ abstract contract ISafeBridgeSender {
/**
* Sends an arbitrary message from one domain to another.
*
* @param _receiver The foreign chain contract address who will receive the calldata
* @param _calldata The home chain encoded message data.
* @param _receiver The contract address which will receive the calldata on the receiving chain.
* @param _calldata The encoded message data to send.
* @return Unique id to track the message request/transaction.
*/
function _sendSafe(address _receiver, bytes memory _calldata) internal virtual returns (bytes32);
Expand Down
21 changes: 21 additions & 0 deletions contracts/src/bridge/interfaces/ISenderGateway.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: MIT

/**
* @authors: [@jaybuidl, @shotaronowhere]
* @reviewers: []
* @auditors: []
* @bounties: []
* @deployments: []
*/

pragma solidity ^0.8.0;

import "../../bridge/interfaces/IFastBridgeSender.sol";

interface ISenderGateway {
function fastBridgeSender() external view returns (IFastBridgeSender);

function receiverChainID() external view returns (uint256);

function receiverGateway() external view returns (address);
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ contract FastBridgeSenderToEthereum is SafeBridgeSenderToEthereum, IFastBridgeSe

address public governor; // The governor of the contract.
IFastBridgeReceiver public fastBridgeReceiver; // The address of the Fast Bridge on Ethereum.
address public fastBridgeSender; // The address of the Fast Bridge sender on Arbitrum, generally the Home Gateway.
address public fastBridgeSender; // The address of the Fast Bridge sender on Arbitrum, generally the Sender Gateway.
uint256 public currentTicketID = 1; // Zero means not set, start at 1.
mapping(uint256 => Ticket) public tickets; // The tickets by ticketID.

Expand All @@ -52,7 +52,7 @@ contract FastBridgeSenderToEthereum is SafeBridgeSenderToEthereum, IFastBridgeSe
* @dev Constructor.
* @param _governor The governor's address.
* @param _fastBridgeReceiver The address of the Fast Bridge on Ethereum.
* @param _fastBridgeSender The address of the Fast Bridge sender on Arbitrum, generally the Home Gateway.
* @param _fastBridgeSender The address of the Fast Bridge sender on Arbitrum, generally the Sender Gateway.
*/
constructor(
address _governor,
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/bridge/test/FastBridgeSenderMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ contract FastBridgeSenderMock is IFastBridgeSender, ISafeBridgeSender {
/**
* @dev Constructor.
* @param _epochPeriod The duration between epochs.
* @param _safeBridgeReceiver The the Safe Bridge Router on Ethereum to the foreign chain.
* @param _safeBridgeReceiver The the Safe Bridge Router on Ethereum to the receiving chain.
* @param _arbsys The address of the mock ArbSys contract.
*/
constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

pragma solidity ^0.8.0;

import "./IForeignGatewayBase.sol";
import "../../interfaces/IReceiverGateway.sol";

interface IForeignGatewayMock is IForeignGatewayBase {
interface IReceiverGatewayMock is IReceiverGateway {
/**
* Receive the message from the home gateway.
*/
Expand Down
7 changes: 7 additions & 0 deletions contracts/src/bridge/test/gateways/ISenderGatewayMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../../interfaces/ISenderGateway.sol";

interface ISenderGatewayMock is ISenderGateway {}
66 changes: 66 additions & 0 deletions contracts/src/bridge/test/gateways/ReceiverGatewayMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// SPDX-License-Identifier: MIT

/**
* @authors: [@shotaronowhere]
* @reviewers: []
* @auditors: []
* @bounties: []
* @deployments: []
*/

pragma solidity ^0.8.0;

import "./IReceiverGatewayMock.sol";

/**
* Receiver Gateway Mock
* Counterpart of `SenderGatewayMock`
*/
contract ReceiverGatewayMock is IReceiverGateway {
IFastBridgeReceiver public immutable fastBridgeReceiver;
address public immutable override senderGateway;
uint256 public immutable override senderChainID;

uint256 public messageCount;
uint256 public data;

constructor(
IFastBridgeReceiver _fastBridgeReceiver,
address _senderGateway,
uint256 _senderChainID
) {
fastBridgeReceiver = _fastBridgeReceiver;
senderGateway = _senderGateway;
senderChainID = _senderChainID;
}

modifier onlyFromFastBridge() {
require(address(fastBridgeReceiver) == msg.sender, "Fast Bridge only.");
_;
}

/**
* Receive the message from the sender gateway.
*/
function receiveMessage(address _messageSender) external onlyFromFastBridge {
require(_messageSender == senderGateway, "Only the sender gateway is allowed.");
_receiveMessage();
}

/**
* Receive the message from the sender gateway.
*/
function receiveMessage(address _messageSender, uint256 _data) external onlyFromFastBridge {
require(_messageSender == senderGateway, "Only the sender gateway is allowed.");
_receiveMessage(_data);
}

function _receiveMessage() internal {
messageCount++;
}

function _receiveMessage(uint256 _data) internal {
messageCount++;
data = _data;
}
}
47 changes: 47 additions & 0 deletions contracts/src/bridge/test/gateways/SenderGatewayMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// SPDX-License-Identifier: MIT

/**
* @authors: [@shotaronowhere]
* @reviewers: []
* @auditors: []
* @bounties: []
* @deployments: []
*/

pragma solidity ^0.8.0;

import "./IReceiverGatewayMock.sol";
import "../../interfaces/ISenderGateway.sol";

/**
* Sender Gateway
* Counterpart of `ReceiverGatewayMock`
*/
contract SenderGatewayMock is ISenderGateway {
IFastBridgeSender public immutable fastBridgeSender;
address public override receiverGateway;
uint256 public immutable override receiverChainID;

struct RelayedData {
uint256 arbitrationCost;
address relayer;
}
mapping(bytes32 => RelayedData) public disputeHashtoRelayedData;

constructor(
IFastBridgeSender _fastBridgeSender,
address _receiverGateway,
uint256 _receiverChainID
) {
fastBridgeSender = _fastBridgeSender;
receiverGateway = _receiverGateway;
receiverChainID = _receiverChainID;
}

function sendFastMessage(uint256 _data) external {
bytes4 methodSelector = IReceiverGatewayMock.receiveMessage.selector;
bytes memory data = abi.encodeWithSelector(methodSelector, _data);

fastBridgeSender.sendFast(receiverGateway, data);
}
}
Loading

0 comments on commit 45c123d

Please sign in to comment.