Skip to content

Add arbitration cost forwarding and feeForJuror param set by governor #30

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

Merged
merged 9 commits into from
Feb 3, 2022
12 changes: 8 additions & 4 deletions contracts/src/bridge/IL1Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

pragma solidity ^0.8.0;

interface IL1Bridge {
/**
* This is essentially an interface but defined as an abstract contract
* to declare functions as internal instead of as external
*/
abstract contract IL1Bridge {
/**
* Sends an arbitrary message from one domain to another.
*
Expand All @@ -24,9 +28,9 @@ interface IL1Bridge {
bytes memory _calldata,
uint256 _maxGas,
uint256 _gasPriceBid
) external payable returns (uint256);
) internal virtual returns (uint256);

function getSubmissionPrice(uint256 _calldatasize) external view returns (uint256);
function bridgingCost(uint256 _calldatasize) internal view virtual returns (uint256);

function onlyAuthorized() external;
function onlyCrossChainSender() internal virtual;
}
10 changes: 7 additions & 3 deletions contracts/src/bridge/IL2Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

pragma solidity ^0.8.0;

interface IL2Bridge {
/**
* This is essentially an interface but defined as an abstract contract
* to declare functions as internal instead of as external
*/
abstract contract IL2Bridge {
/**
* Sends an arbitrary message from one domain to another.
*
* @param _calldata The L1 encoded message data.
* @return Unique id to track the message request/transaction.
*/
function sendCrossDomainMessage(bytes memory _calldata) external returns (uint256);
function sendCrossDomainMessage(bytes memory _calldata) internal virtual returns (uint256);

function onlyAuthorized() external;
function onlyCrossChainSender() internal virtual;
}
16 changes: 12 additions & 4 deletions contracts/src/bridge/arbitrum/ArbL1Bridge.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
// SPDX-License-Identifier: MIT

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

pragma solidity ^0.8.0;

import "./interfaces/IInbox.sol";
Expand Down Expand Up @@ -41,8 +49,8 @@ contract ArbL1Bridge is IL1Bridge {
bytes memory _calldata,
uint256 _maxGas,
uint256 _gasPriceBid
) external payable returns (uint256) {
uint256 baseSubmissionCost = getSubmissionPrice(_calldata.length);
) internal override returns (uint256) {
uint256 baseSubmissionCost = bridgingCost(_calldata.length);
require(msg.value >= baseSubmissionCost + (_maxGas * _gasPriceBid));

uint256 ticketID = inbox.createRetryableTicket{value: msg.value}(
Expand All @@ -60,12 +68,12 @@ contract ArbL1Bridge is IL1Bridge {
return ticketID;
}

function getSubmissionPrice(uint256 _calldatasize) public view returns (uint256) {
function bridgingCost(uint256 _calldatasize) internal view override returns (uint256) {
(uint256 submissionCost, ) = arbRetryableTx.getSubmissionPrice(_calldatasize);
return submissionCost;
}

function onlyAuthorized() external {
function onlyCrossChainSender() internal override {
IOutbox outbox = IOutbox(inbox.bridge().activeOutbox());
address l2Sender = outbox.l2ToL1Sender();
require(l2Sender == l2Target, "Only L2 target");
Expand Down
12 changes: 10 additions & 2 deletions contracts/src/bridge/arbitrum/ArbL2Bridge.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
// SPDX-License-Identifier: MIT

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

pragma solidity ^0.8.0;

import "./interfaces/IArbSys.sol";
Expand All @@ -23,14 +31,14 @@ contract ArbL2Bridge is IL2Bridge {
* @param _calldata The L1 encoded message data.
* @return Unique id to track the message request/transaction.
*/
function sendCrossDomainMessage(bytes memory _calldata) external returns (uint256) {
function sendCrossDomainMessage(bytes memory _calldata) internal override returns (uint256) {
uint256 withdrawalId = arbsys.sendTxToL1(l1Target, _calldata);

emit L2ToL1TxCreated(withdrawalId);
return withdrawalId;
}

function onlyAuthorized() external {
function onlyCrossChainSender() internal override {
require(msg.sender == AddressAliasHelper.applyL1ToL2Alias(l1Target), "Only L1 target");
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
// SPDX-License-Identifier: MIT

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

pragma solidity ^0.8.0;

import "./interfaces/IAMB.sol";

import "../IL1Bridge.sol";

contract xDaiL1Bridge is IL1Bridge {
contract GnosisL1Bridge is IL1Bridge {
address public l2Target;
IAMB amb;

Expand All @@ -19,7 +27,7 @@ contract xDaiL1Bridge is IL1Bridge {
bytes memory _calldata,
uint256 _maxGas,
uint256 _gasPriceBid
) external payable returns (uint256) {
) internal override returns (uint256) {
bytes32 id = amb.requireToPassMessage(l2Target, _calldata, amb.maxGasPerTx());
return uint256(id);
}
Expand All @@ -28,13 +36,13 @@ contract xDaiL1Bridge is IL1Bridge {
* @dev The xDai bridge gas cost doesn't depend on the calldata size
*
*/
function getSubmissionPrice(
function bridgingCost(
uint256 /* _calldatasize */
) public view returns (uint256) {
) internal view override returns (uint256) {
return 0;
}

function onlyAuthorized() external {
function onlyCrossChainSender() internal override {
require(msg.sender == address(amb), "Only AMB allowed");
// require(amb.messageSourceChainId() == foreignChainId, "Only foreign chain allowed");
require(amb.messageSender() == l2Target, "Only foreign gateway allowed");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
// SPDX-License-Identifier: MIT

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

pragma solidity ^0.8.0;

import "./interfaces/IAMB.sol";

import "../IL2Bridge.sol";

contract xDaiL2Bridge is IL2Bridge {
contract GnosisL2Bridge is IL2Bridge {
address public l1Target;
IAMB amb;

Expand All @@ -15,12 +23,12 @@ contract xDaiL2Bridge is IL2Bridge {
amb = _amb;
}

function sendCrossDomainMessage(bytes memory _calldata) external returns (uint256) {
function sendCrossDomainMessage(bytes memory _calldata) internal override returns (uint256) {
bytes32 id = amb.requireToPassMessage(l1Target, _calldata, amb.maxGasPerTx());
return uint256(id);
}

function onlyAuthorized() external {
function onlyCrossChainSender() internal override {
require(msg.sender == address(amb), "Only AMB allowed");
// require(amb.messageSourceChainId() == homeChainId, "Only home chain allowed");
require(amb.messageSender() == l1Target, "Only home gateway allowed");
Expand Down
Loading