Skip to content

Commit 352a08c

Browse files
committed
feat(gateway): implement cross-chain evidence standard
1 parent 7c7616f commit 352a08c

File tree

6 files changed

+116
-14
lines changed

6 files changed

+116
-14
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8.0;
4+
5+
interface IForeignEvidence {
6+
function disputeID(uint256 _foreignDisputeID) external view returns (uint256);
7+
8+
function homeChainID(uint256 _disputeID) external view returns (uint256);
9+
10+
function homeBridge(uint256 _disputeID) external view returns (address);
11+
}

contracts/src/gateway/IForeignGateway.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ pragma solidity ^0.8.0;
55
import "../arbitration/IArbitrator.sol";
66

77
interface IForeignGateway is IArbitrator {
8+
function chainID() external view returns (uint256);
9+
10+
function foreignDisputeHashToID(bytes32 _disputeHash) external view returns (uint256);
11+
812
/**
913
* Relay the rule call from the home gateway to the arbitrable.
1014
*/
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8.0;
4+
5+
import "../evidence/IEvidence.sol";
6+
7+
interface IHomeEvidence is IEvidence {
8+
function homeToForeignDisputeID(uint256 _homeDisputeID) external view returns (uint256);
9+
10+
function foreignChainID(uint256 _homeDisputeID) external view returns (uint256);
11+
12+
function foreignBridge(uint256 _homeDisputeID) external view returns (address);
13+
}

contracts/src/gateway/IHomeGateway.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ pragma solidity ^0.8.0;
55
import "../arbitration/IArbitrable.sol";
66

77
interface IHomeGateway is IArbitrable {
8+
function chainID() external view returns (uint256);
9+
10+
function homeDisputeHashToID(bytes32 _disputeHash) external view returns (uint256);
11+
812
/**
913
* Relay the createDispute call from the foreign gateway to the arbitrator.
1014
*/

contracts/src/gateway/arbitrum/ArbitrumGateway.sol

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,40 @@ import "../../bridge/arbitrum/L2Bridge.sol";
88
import "../IHomeGateway.sol";
99
import "../IForeignGateway.sol";
1010

11-
contract ArbitrumGateway is IHomeGateway {
12-
// L2 bridge with the ForeignGateway as the l1target
11+
import "../IHomeEvidence.sol";
1312

13+
contract ArbitrumGateway is IHomeGateway, IHomeEvidence {
14+
// L2 bridge with the ForeignGateway as the l1target
1415
L2Bridge internal l2bridge;
16+
17+
mapping(uint256 => bytes32) public disputeIDtoHash;
18+
mapping(bytes32 => uint256) public disputeHashtoID;
19+
20+
IForeignGateway public foreignGateway;
1521
IArbitrator public arbitrator;
16-
mapping(uint256 => bytes32) disputeIDtoHash;
22+
uint256 public chainID;
1723

1824
modifier onlyFromL1() {
1925
l2bridge.onlyAuthorized(msg.sender);
2026
_;
2127
}
2228

23-
constructor(IArbitrator _arbitrator, L2Bridge _l2bridge) {
29+
constructor(
30+
IArbitrator _arbitrator,
31+
L2Bridge _l2bridge,
32+
IForeignGateway _foreignGateway
33+
) {
2434
arbitrator = _arbitrator;
2535
l2bridge = _l2bridge;
36+
foreignGateway = _foreignGateway;
37+
38+
uint256 id;
39+
assembly {
40+
id := chainid()
41+
}
42+
chainID = id;
43+
44+
emit MetaEvidence(0, "BRIDGE");
2645
}
2746

2847
function rule(uint256 _disputeID, uint256 _ruling) external {
@@ -36,8 +55,6 @@ contract ArbitrumGateway is IHomeGateway {
3655

3756
/**
3857
* Relay the createDispute call from the foreign gateway to the arbitrator.
39-
*
40-
* // TODO: Implement the evidence redirection from the Evidence v2 standard.
4158
*/
4259
function relayCreateDispute(
4360
bytes32 _disputeHash,
@@ -46,5 +63,27 @@ contract ArbitrumGateway is IHomeGateway {
4663
) external onlyFromL1 {
4764
uint256 disputeID = arbitrator.createDispute(_choices, _extraData);
4865
disputeIDtoHash[disputeID] = _disputeHash;
66+
disputeHashtoID[_disputeHash] = disputeID;
67+
68+
emit Dispute(arbitrator, disputeID, 0, 0);
69+
}
70+
71+
function homeDisputeHashToID(bytes32 _disputeHash) external view returns (uint256) {
72+
return disputeHashtoID[_disputeHash];
73+
}
74+
75+
function homeToForeignDisputeID(uint256 _homeDisputeID) external view returns (uint256) {
76+
bytes32 disputeHash = disputeIDtoHash[_homeDisputeID];
77+
require(disputeHash != 0, "Dispute does not exist");
78+
79+
return foreignGateway.foreignDisputeHashToID(disputeHash);
80+
}
81+
82+
function foreignChainID(uint256 _homeDisputeID) external view returns (uint256) {
83+
return foreignGateway.chainID();
84+
}
85+
86+
function foreignBridge(uint256 _homeDisputeID) external view returns (address) {
87+
return address(foreignGateway);
4988
}
5089
}

contracts/src/gateway/arbitrum/EthereumGateway.sol

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,42 @@ import "../../bridge/arbitrum/L1Bridge.sol";
88
import "../IHomeGateway.sol";
99
import "../IForeignGateway.sol";
1010

11-
contract EthereumGateway is IForeignGateway {
11+
import "../IForeignEvidence.sol";
12+
13+
contract EthereumGateway is IForeignGateway, IForeignEvidence {
1214
// L1 bridge with the HomeGateway as the l2target
1315
L1Bridge internal l1bridge;
14-
uint256 localDisputeID;
15-
uint256 chainID;
16+
uint256 internal localDisputeID;
1617

1718
// For now this is just a constant, but we'd probably need to
1819
// implement the same arbitrationCost calculation code we'll have
1920
// in the V2 court.
2021
uint256 internal internalArbitrationCost;
2122

22-
struct Dispute {
23+
struct DisputeData {
2324
uint256 id;
2425
address arbitrable;
2526
}
26-
mapping(bytes32 => Dispute) disputeHashtoDisputeData;
27+
mapping(uint256 => bytes32) public disputeIDtoHash;
28+
mapping(bytes32 => DisputeData) public disputeHashtoDisputeData;
29+
30+
IHomeGateway public homeGateway;
31+
uint256 public chainID;
2732

2833
modifier onlyFromL2() {
2934
l1bridge.onlyAuthorized(msg.sender);
3035
_;
3136
}
3237

33-
constructor(uint256 _arbitrationCost, L1Bridge _l1bridge) {
38+
constructor(
39+
uint256 _arbitrationCost,
40+
L1Bridge _l1bridge,
41+
IHomeGateway _homeGateway
42+
) {
3443
internalArbitrationCost = _arbitrationCost;
3544
l1bridge = _l1bridge;
45+
homeGateway = _homeGateway;
46+
3647
uint256 id;
3748
assembly {
3849
id := chainid()
@@ -54,7 +65,8 @@ contract EthereumGateway is IForeignGateway {
5465
_extraData
5566
)
5667
);
57-
disputeHashtoDisputeData[disputeHash] = Dispute({id: disputeID, arbitrable: msg.sender});
68+
disputeIDtoHash[disputeID] = disputeHash;
69+
disputeHashtoDisputeData[disputeHash] = DisputeData({id: disputeID, arbitrable: msg.sender});
5870

5971
bytes4 methodSelector = IHomeGateway.relayCreateDispute.selector;
6072
bytes memory data = abi.encodeWithSelector(methodSelector, disputeHash, _choices, _extraData);
@@ -94,9 +106,28 @@ contract EthereumGateway is IForeignGateway {
94106
* Relay the rule call from the home gateway to the arbitrable.
95107
*/
96108
function relayRule(bytes32 _disputeHash, uint256 _ruling) external onlyFromL2 {
97-
Dispute memory dispute = disputeHashtoDisputeData[_disputeHash];
109+
DisputeData memory dispute = disputeHashtoDisputeData[_disputeHash];
98110

99111
IArbitrable arbitrable = IArbitrable(dispute.arbitrable);
100112
arbitrable.rule(dispute.id, _ruling);
101113
}
114+
115+
function foreignDisputeHashToID(bytes32 _disputeHash) external view returns (uint256) {
116+
return disputeHashtoDisputeData[_disputeHash].id;
117+
}
118+
119+
function disputeID(uint256 _foreignDisputeID) external view returns (uint256) {
120+
bytes32 disputeHash = disputeIDtoHash[_foreignDisputeID];
121+
require(disputeHash != 0, "Dispute does not exist");
122+
123+
return homeGateway.homeDisputeHashToID(disputeHash);
124+
}
125+
126+
function homeChainID(uint256 _disputeID) external view returns (uint256) {
127+
return homeGateway.chainID();
128+
}
129+
130+
function homeBridge(uint256 _disputeID) external view returns (address) {
131+
return address(homeGateway);
132+
}
102133
}

0 commit comments

Comments
 (0)