@@ -17,14 +17,15 @@ import "./interfaces/IHomeGateway.sol";
17
17
import "./interfaces/IForeignGateway.sol " ;
18
18
19
19
abstract contract BaseForeignGateway is IL1Bridge , IForeignGateway {
20
+ // The global default minimum number of jurors in a dispute.
21
+ uint256 public constant MIN_JURORS = 3 ;
22
+
20
23
// @dev Note the disputeID needs to start from one as
21
24
// the KlerosV1 proxy governor depends on this implementation.
22
25
uint256 internal localDisputeID = 1 ;
23
26
24
- // For now this is just a constant, but we'd probably need to
25
- // implement the same arbitrationCost calculation code we'll have
26
- // in the V2 court.
27
- uint256 internal internalArbitrationCost;
27
+ // feeForJuror by subcourtID
28
+ uint256 [] internal feeForJuror;
28
29
29
30
struct DisputeData {
30
31
uint256 id;
@@ -38,15 +39,26 @@ abstract contract BaseForeignGateway is IL1Bridge, IForeignGateway {
38
39
39
40
IHomeGateway public homeGateway;
40
41
uint256 public chainID;
42
+ address public governor;
41
43
42
44
modifier onlyFromL2 () {
43
45
onlyAuthorized ();
44
46
_;
45
47
}
46
48
47
- constructor (uint256 _arbitrationCost , IHomeGateway _homeGateway ) {
48
- internalArbitrationCost = _arbitrationCost;
49
+ modifier onlyByGovernor () {
50
+ require (governor == msg .sender , "Access not allowed: Governor only. " );
51
+ _;
52
+ }
53
+
54
+ constructor (
55
+ address _governor ,
56
+ IHomeGateway _homeGateway ,
57
+ uint256 [] memory _feeForJuror
58
+ ) {
59
+ governor = _governor;
49
60
homeGateway = _homeGateway;
61
+ feeForJuror = _feeForJuror;
50
62
51
63
uint256 id;
52
64
assembly {
@@ -55,9 +67,20 @@ abstract contract BaseForeignGateway is IL1Bridge, IForeignGateway {
55
67
chainID = id;
56
68
}
57
69
70
+ /** @dev Changes the `feeForJuror` property value of a specified subcourt.
71
+ * @param _subcourtID The ID of the subcourt.
72
+ * @param _feeForJuror The new value for the `feeForJuror` property value.
73
+ */
74
+ function changeSubcourtJurorFee (uint96 _subcourtID , uint256 _feeForJuror ) external onlyByGovernor {
75
+ feeForJuror[_subcourtID] = _feeForJuror;
76
+ }
77
+
58
78
function createDispute (uint256 _choices , bytes calldata _extraData ) external payable returns (uint256 disputeID ) {
59
79
require (msg .value >= arbitrationCost (_extraData), "Not paid enough for arbitration " );
60
80
81
+ (uint96 subcourtID , ) = extraDataToSubcourtIDMinJurors (_extraData);
82
+ uint256 nbVotes = msg .value / feeForJuror[subcourtID];
83
+
61
84
disputeID = localDisputeID++ ;
62
85
bytes32 disputeHash = keccak256 (
63
86
abi.encodePacked (
@@ -71,6 +94,7 @@ abstract contract BaseForeignGateway is IL1Bridge, IForeignGateway {
71
94
)
72
95
);
73
96
disputeIDtoHash[disputeID] = disputeHash;
97
+
74
98
disputeHashtoDisputeData[disputeHash] = DisputeData ({
75
99
id: disputeID,
76
100
arbitrable: msg .sender ,
@@ -80,7 +104,13 @@ abstract contract BaseForeignGateway is IL1Bridge, IForeignGateway {
80
104
});
81
105
82
106
bytes4 methodSelector = IHomeGateway.relayCreateDispute.selector ;
83
- bytes memory data = abi.encodeWithSelector (methodSelector, disputeHash, _choices, _extraData);
107
+ bytes memory data = abi.encodeWithSelector (
108
+ methodSelector,
109
+ disputeHash,
110
+ _choices,
111
+ _extraData,
112
+ nbVotes * feeForJuror[subcourtID] // we calculate the min amount required for nbVotes
113
+ );
84
114
85
115
// We only pay for the submissionPrice gas cost
86
116
// which is minimum gas cost required for submitting a
@@ -100,16 +130,19 @@ abstract contract BaseForeignGateway is IL1Bridge, IForeignGateway {
100
130
}
101
131
102
132
function arbitrationCost (bytes calldata _extraData ) public view returns (uint256 cost ) {
133
+ (uint96 subcourtID , uint256 minJurors ) = extraDataToSubcourtIDMinJurors (_extraData);
134
+
103
135
// Calculate the size of calldata that will be passed to the L2 bridge
104
136
// as that is a factor for the bridging cost.
105
137
// Calldata size of relayCreateDispute:
106
- // relayCreateDispute methodId +
107
- // (createDispute methodId + bytes32 disputeHash + uint256 _choices + bytes _extraData)
108
- // 4 + 4 + 32 + 32 + dynamic
109
- uint256 calldatasize = 82 + _extraData.length ;
138
+ // relayCreateDispute methodId + bytes32 disputeHash + uint256 _choices + bytes _extraData + uint256 _arbitrationCost)
139
+ // 4 + 32 + 32 + dynamic + 32
140
+ uint256 calldatasize = 100 + _extraData.length ;
110
141
111
142
uint256 bridgeCost = getSubmissionPrice (calldatasize);
112
- return bridgeCost + internalArbitrationCost;
143
+ uint256 arbCost = feeForJuror[subcourtID] * minJurors;
144
+
145
+ return bridgeCost + arbCost;
113
146
}
114
147
115
148
/**
@@ -157,4 +190,24 @@ abstract contract BaseForeignGateway is IL1Bridge, IForeignGateway {
157
190
function homeBridge (uint256 _disputeID ) external view returns (address ) {
158
191
return address (homeGateway);
159
192
}
193
+
194
+ function extraDataToSubcourtIDMinJurors (bytes memory _extraData )
195
+ internal
196
+ view
197
+ returns (uint96 subcourtID , uint256 minJurors )
198
+ {
199
+ // Note that here we ignore DisputeKitID
200
+ if (_extraData.length >= 64 ) {
201
+ assembly {
202
+ // solium-disable-line security/no-inline-assembly
203
+ subcourtID := mload (add (_extraData, 0x20 ))
204
+ minJurors := mload (add (_extraData, 0x40 ))
205
+ }
206
+ if (subcourtID >= feeForJuror.length ) subcourtID = 0 ;
207
+ if (minJurors == 0 ) minJurors = MIN_JURORS;
208
+ } else {
209
+ subcourtID = 0 ;
210
+ minJurors = MIN_JURORS;
211
+ }
212
+ }
160
213
}
0 commit comments