Skip to content

Commit 8d89897

Browse files
authored
Add arbitration cost forwarding and feeForJuror param
* refactor(gateway): add RAB pragma and use internal functions for the bridge * feat(gateway): add forwarding for arbitrationCost * feat(gateway): add and use feeForJuror param by governor * fix(gateway): update disputeHash calculation * refactor(gateway): rename some functions * refactor(gateway): rename xdai -> gnosis * refactor(gateway): getSubmissionPrice -> bridgingCost * refactor(gateway): reorder struct members * refactor: rename gateways
1 parent 9cad8de commit 8d89897

15 files changed

+257
-80
lines changed

contracts/src/bridge/IL1Bridge.sol

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
pragma solidity ^0.8.0;
44

5-
interface IL1Bridge {
5+
/**
6+
* This is essentially an interface but defined as an abstract contract
7+
* to declare functions as internal instead of as external
8+
*/
9+
abstract contract IL1Bridge {
610
/**
711
* Sends an arbitrary message from one domain to another.
812
*
@@ -24,9 +28,9 @@ interface IL1Bridge {
2428
bytes memory _calldata,
2529
uint256 _maxGas,
2630
uint256 _gasPriceBid
27-
) external payable returns (uint256);
31+
) internal virtual returns (uint256);
2832

29-
function getSubmissionPrice(uint256 _calldatasize) external view returns (uint256);
33+
function bridgingCost(uint256 _calldatasize) internal view virtual returns (uint256);
3034

31-
function onlyAuthorized() external;
35+
function onlyCrossChainSender() internal virtual;
3236
}

contracts/src/bridge/IL2Bridge.sol

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22

33
pragma solidity ^0.8.0;
44

5-
interface IL2Bridge {
5+
/**
6+
* This is essentially an interface but defined as an abstract contract
7+
* to declare functions as internal instead of as external
8+
*/
9+
abstract contract IL2Bridge {
610
/**
711
* Sends an arbitrary message from one domain to another.
812
*
913
* @param _calldata The L1 encoded message data.
1014
* @return Unique id to track the message request/transaction.
1115
*/
12-
function sendCrossDomainMessage(bytes memory _calldata) external returns (uint256);
16+
function sendCrossDomainMessage(bytes memory _calldata) internal virtual returns (uint256);
1317

14-
function onlyAuthorized() external;
18+
function onlyCrossChainSender() internal virtual;
1519
}

contracts/src/bridge/arbitrum/ArbL1Bridge.sol

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
// SPDX-License-Identifier: MIT
22

3+
/**
4+
* @authors: [@shalzz]
5+
* @reviewers: []
6+
* @auditors: []
7+
* @bounties: []
8+
* @deployments: []
9+
*/
10+
311
pragma solidity ^0.8.0;
412

513
import "./interfaces/IInbox.sol";
@@ -41,8 +49,8 @@ contract ArbL1Bridge is IL1Bridge {
4149
bytes memory _calldata,
4250
uint256 _maxGas,
4351
uint256 _gasPriceBid
44-
) external payable returns (uint256) {
45-
uint256 baseSubmissionCost = getSubmissionPrice(_calldata.length);
52+
) internal override returns (uint256) {
53+
uint256 baseSubmissionCost = bridgingCost(_calldata.length);
4654
require(msg.value >= baseSubmissionCost + (_maxGas * _gasPriceBid));
4755

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

63-
function getSubmissionPrice(uint256 _calldatasize) public view returns (uint256) {
71+
function bridgingCost(uint256 _calldatasize) internal view override returns (uint256) {
6472
(uint256 submissionCost, ) = arbRetryableTx.getSubmissionPrice(_calldatasize);
6573
return submissionCost;
6674
}
6775

68-
function onlyAuthorized() external {
76+
function onlyCrossChainSender() internal override {
6977
IOutbox outbox = IOutbox(inbox.bridge().activeOutbox());
7078
address l2Sender = outbox.l2ToL1Sender();
7179
require(l2Sender == l2Target, "Only L2 target");

contracts/src/bridge/arbitrum/ArbL2Bridge.sol

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
// SPDX-License-Identifier: MIT
22

3+
/**
4+
* @authors: [@shalzz]
5+
* @reviewers: []
6+
* @auditors: []
7+
* @bounties: []
8+
* @deployments: []
9+
*/
10+
311
pragma solidity ^0.8.0;
412

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

2937
emit L2ToL1TxCreated(withdrawalId);
3038
return withdrawalId;
3139
}
3240

33-
function onlyAuthorized() external {
41+
function onlyCrossChainSender() internal override {
3442
require(msg.sender == AddressAliasHelper.applyL1ToL2Alias(l1Target), "Only L1 target");
3543
}
3644
}

contracts/src/bridge/xdai/xDaiL1Bridge.sol renamed to contracts/src/bridge/gnosis-chain/GnosisL1Bridge.sol

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
// SPDX-License-Identifier: MIT
22

3+
/**
4+
* @authors: [@shalzz]
5+
* @reviewers: []
6+
* @auditors: []
7+
* @bounties: []
8+
* @deployments: []
9+
*/
10+
311
pragma solidity ^0.8.0;
412

513
import "./interfaces/IAMB.sol";
614

715
import "../IL1Bridge.sol";
816

9-
contract xDaiL1Bridge is IL1Bridge {
17+
contract GnosisL1Bridge is IL1Bridge {
1018
address public l2Target;
1119
IAMB amb;
1220

@@ -19,7 +27,7 @@ contract xDaiL1Bridge is IL1Bridge {
1927
bytes memory _calldata,
2028
uint256 _maxGas,
2129
uint256 _gasPriceBid
22-
) external payable returns (uint256) {
30+
) internal override returns (uint256) {
2331
bytes32 id = amb.requireToPassMessage(l2Target, _calldata, amb.maxGasPerTx());
2432
return uint256(id);
2533
}
@@ -28,13 +36,13 @@ contract xDaiL1Bridge is IL1Bridge {
2836
* @dev The xDai bridge gas cost doesn't depend on the calldata size
2937
*
3038
*/
31-
function getSubmissionPrice(
39+
function bridgingCost(
3240
uint256 /* _calldatasize */
33-
) public view returns (uint256) {
41+
) internal view override returns (uint256) {
3442
return 0;
3543
}
3644

37-
function onlyAuthorized() external {
45+
function onlyCrossChainSender() internal override {
3846
require(msg.sender == address(amb), "Only AMB allowed");
3947
// require(amb.messageSourceChainId() == foreignChainId, "Only foreign chain allowed");
4048
require(amb.messageSender() == l2Target, "Only foreign gateway allowed");

contracts/src/bridge/xdai/xDaiL2Bridge.sol renamed to contracts/src/bridge/gnosis-chain/GnosisL2Bridge.sol

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
// SPDX-License-Identifier: MIT
22

3+
/**
4+
* @authors: [@shalzz]
5+
* @reviewers: []
6+
* @auditors: []
7+
* @bounties: []
8+
* @deployments: []
9+
*/
10+
311
pragma solidity ^0.8.0;
412

513
import "./interfaces/IAMB.sol";
614

715
import "../IL2Bridge.sol";
816

9-
contract xDaiL2Bridge is IL2Bridge {
17+
contract GnosisL2Bridge is IL2Bridge {
1018
address public l1Target;
1119
IAMB amb;
1220

@@ -15,12 +23,12 @@ contract xDaiL2Bridge is IL2Bridge {
1523
amb = _amb;
1624
}
1725

18-
function sendCrossDomainMessage(bytes memory _calldata) external returns (uint256) {
26+
function sendCrossDomainMessage(bytes memory _calldata) internal override returns (uint256) {
1927
bytes32 id = amb.requireToPassMessage(l1Target, _calldata, amb.maxGasPerTx());
2028
return uint256(id);
2129
}
2230

23-
function onlyAuthorized() external {
31+
function onlyCrossChainSender() internal override {
2432
require(msg.sender == address(amb), "Only AMB allowed");
2533
// require(amb.messageSourceChainId() == homeChainId, "Only home chain allowed");
2634
require(amb.messageSender() == l1Target, "Only home gateway allowed");

0 commit comments

Comments
 (0)