@@ -11,12 +11,20 @@ import "../IForeignGateway.sol";
1111contract 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