Skip to content

Commit 7c7616f

Browse files
committed
feat(gateway): implement disputeID mapping
1 parent 8d95e33 commit 7c7616f

File tree

4 files changed

+51
-29
lines changed

4 files changed

+51
-29
lines changed

contracts/src/gateway/IForeignGateway.sol

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import "../arbitration/IArbitrator.sol";
77
interface IForeignGateway is IArbitrator {
88
/**
99
* Relay the rule call from the home gateway to the arbitrable.
10-
*
11-
* @param _data The calldata to relay
1210
*/
13-
function relayRule(bytes memory _data) external;
11+
function relayRule(bytes32 _disputeHash, uint256 _ruling) external;
1412
}

contracts/src/gateway/IHomeGateway.sol

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import "../arbitration/IArbitrable.sol";
77
interface IHomeGateway is IArbitrable {
88
/**
99
* Relay the createDispute call from the foreign gateway to the arbitrator.
10-
*
11-
* @param _data The calldata to relay
1210
*/
13-
function relayCreateDispute(bytes memory _data) external;
11+
function relayCreateDispute(
12+
bytes32 _disputeHash,
13+
uint256 _choices,
14+
bytes calldata _extraData
15+
) external;
1416
}

contracts/src/gateway/arbitrum/ArbitrumGateway.sol

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,24 @@ contract ArbitrumGateway is IHomeGateway {
1212
// L2 bridge with the ForeignGateway as the l1target
1313

1414
L2Bridge internal l2bridge;
15-
address public arbitrator;
15+
IArbitrator public arbitrator;
16+
mapping(uint256 => bytes32) disputeIDtoHash;
1617

1718
modifier onlyFromL1() {
1819
l2bridge.onlyAuthorized(msg.sender);
1920
_;
2021
}
2122

22-
constructor(address _arbitrator, L2Bridge _l2bridge) {
23+
constructor(IArbitrator _arbitrator, L2Bridge _l2bridge) {
2324
arbitrator = _arbitrator;
2425
l2bridge = _l2bridge;
2526
}
2627

27-
function rule(uint256, uint256) external {
28-
require(msg.sender == arbitrator, "Only Arbitrator");
28+
function rule(uint256 _disputeID, uint256 _ruling) external {
29+
require(msg.sender == address(arbitrator), "Only Arbitrator");
2930

3031
bytes4 methodSelector = IForeignGateway.relayRule.selector;
31-
bytes memory data = abi.encodeWithSelector(methodSelector, msg.data);
32+
bytes memory data = abi.encodeWithSelector(methodSelector, disputeIDtoHash[_disputeID], _ruling);
3233

3334
l2bridge.sendCrossDomainMessage(data);
3435
}
@@ -37,13 +38,13 @@ contract ArbitrumGateway is IHomeGateway {
3738
* Relay the createDispute call from the foreign gateway to the arbitrator.
3839
*
3940
* // TODO: Implement the evidence redirection from the Evidence v2 standard.
40-
* // TODO: Return the actual disputeId from the court to the ForeignGateway
41-
* for it to maintain it's internal mapping.
42-
* @param _data The calldata to relay
4341
*/
44-
function relayCreateDispute(bytes memory _data) external onlyFromL1 {
45-
// solhint-disable-next-line avoid-low-level-calls
46-
(bool success, ) = arbitrator.call(_data);
47-
require(success, "Failed to call contract");
42+
function relayCreateDispute(
43+
bytes32 _disputeHash,
44+
uint256 _choices,
45+
bytes calldata _extraData
46+
) external onlyFromL1 {
47+
uint256 disputeID = arbitrator.createDispute(_choices, _extraData);
48+
disputeIDtoHash[disputeID] = _disputeHash;
4849
}
4950
}

contracts/src/gateway/arbitrum/EthereumGateway.sol

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,20 @@ import "../IForeignGateway.sol";
1111
contract EthereumGateway is IForeignGateway {
1212
// L1 bridge with the HomeGateway as the l2target
1313
L1Bridge internal l1bridge;
14+
uint256 localDisputeID;
15+
uint256 chainID;
1416

1517
// For now this is just a constant, but we'd probably need to
1618
// implement the same arbitrationCost calculation code we'll have
1719
// in the V2 court.
1820
uint256 internal internalArbitrationCost;
1921

22+
struct Dispute {
23+
uint256 id;
24+
address arbitrable;
25+
}
26+
mapping(bytes32 => Dispute) disputeHashtoDisputeData;
27+
2028
modifier onlyFromL2() {
2129
l1bridge.onlyAuthorized(msg.sender);
2230
_;
@@ -25,13 +33,31 @@ contract EthereumGateway is IForeignGateway {
2533
constructor(uint256 _arbitrationCost, L1Bridge _l1bridge) {
2634
internalArbitrationCost = _arbitrationCost;
2735
l1bridge = _l1bridge;
36+
uint256 id;
37+
assembly {
38+
id := chainid()
39+
}
40+
chainID = id;
2841
}
2942

3043
function createDispute(uint256 _choices, bytes calldata _extraData) external payable returns (uint256 disputeID) {
3144
require(msg.value >= arbitrationCost(_extraData), "Not paid enough for arbitration");
3245

46+
disputeID = localDisputeID++;
47+
bytes32 disputeHash = keccak256(
48+
abi.encodePacked(
49+
chainID,
50+
blockhash(block.number - 1),
51+
"createDispute",
52+
disputeID,
53+
arbitrationCost(_extraData),
54+
_extraData
55+
)
56+
);
57+
disputeHashtoDisputeData[disputeHash] = Dispute({id: disputeID, arbitrable: msg.sender});
58+
3359
bytes4 methodSelector = IHomeGateway.relayCreateDispute.selector;
34-
bytes memory data = abi.encodeWithSelector(methodSelector, msg.data);
60+
bytes memory data = abi.encodeWithSelector(methodSelector, disputeHash, _choices, _extraData);
3561

3662
uint256 bridgeCost = l1bridge.getSubmissionPrice(data.length);
3763
// We only pay for the submissionPrice gas cost
@@ -44,13 +70,11 @@ contract EthereumGateway is IForeignGateway {
4470
// For more details, see:
4571
// https://developer.offchainlabs.com/docs/l1_l2_messages#retryable-tickets-contract-api
4672
//
47-
// We do NOT forward the arbitrationCost to the HomeGateway yet,
73+
// We do NOT forward the arbitrationCost ETH funds to the HomeGateway yet,
4874
// only the calldata.
4975
l1bridge.sendCrossDomainMessage{value: bridgeCost}(data, 0, 0);
5076

51-
disputeID = 0; // TODO: map to the actual disputeID we get from the V2 court
5277
emit DisputeCreation(disputeID, IArbitrable(msg.sender));
53-
return disputeID;
5478
}
5579

5680
function arbitrationCost(bytes calldata _extraData) public view returns (uint256 cost) {
@@ -68,14 +92,11 @@ contract EthereumGateway is IForeignGateway {
6892

6993
/**
7094
* Relay the rule call from the home gateway to the arbitrable.
71-
*
72-
* @param _data The calldata to relay
7395
*/
74-
function relayRule(bytes memory _data) external onlyFromL2 {
75-
address arbitrable = address(0); // see the TODO above about the disputeId
96+
function relayRule(bytes32 _disputeHash, uint256 _ruling) external onlyFromL2 {
97+
Dispute memory dispute = disputeHashtoDisputeData[_disputeHash];
7698

77-
// solhint-disable-next-line avoid-low-level-calls
78-
(bool success, ) = arbitrable.call(_data);
79-
require(success, "Failed to call contract");
99+
IArbitrable arbitrable = IArbitrable(dispute.arbitrable);
100+
arbitrable.rule(dispute.id, _ruling);
80101
}
81102
}

0 commit comments

Comments
 (0)