@@ -9,12 +9,9 @@ pragma solidity 0.8.24;
9
9
10
10
import {IArbitrableV2, IArbitratorV2} from "./interfaces/IArbitrableV2.sol " ;
11
11
import "./interfaces/IDisputeTemplateRegistry.sol " ;
12
- import "../libraries/CappedMath.sol " ;
13
12
14
13
/// @title KlerosGovernor for V2. Note that appeal functionality and evidence submission will be handled by the court.
15
14
contract KlerosGovernor is IArbitrableV2 {
16
- using CappedMath for uint256 ;
17
-
18
15
// ************************************* //
19
16
// * Enums / Structs * //
20
17
// ************************************* //
@@ -74,16 +71,13 @@ contract KlerosGovernor is IArbitrableV2 {
74
71
75
72
modifier duringSubmissionPeriod () {
76
73
uint256 offset = sessions[sessions.length - 1 ].durationOffset;
77
- require (block .timestamp - lastApprovalTime <= submissionTimeout. addCap ( offset) , "Submission time has ended. " );
74
+ require (block .timestamp - lastApprovalTime <= submissionTimeout + offset, "Submission time has ended. " );
78
75
_;
79
76
}
80
77
81
78
modifier duringApprovalPeriod () {
82
79
uint256 offset = sessions[sessions.length - 1 ].durationOffset;
83
- require (
84
- block .timestamp - lastApprovalTime > submissionTimeout.addCap (offset),
85
- "Approval time not started yet. "
86
- );
80
+ require (block .timestamp - lastApprovalTime > submissionTimeout + offset, "Approval time not started yet. " );
87
81
_;
88
82
}
89
83
@@ -200,7 +194,6 @@ contract KlerosGovernor is IArbitrableV2 {
200
194
// ************************************* //
201
195
202
196
/// @dev Creates transaction list based on input parameters and submits it for potential approval and execution.
203
- /// Transactions must be ordered by their hash.
204
197
/// @param _target List of addresses to call.
205
198
/// @param _value List of values required for respective addresses.
206
199
/// @param _data Concatenated calldata of all transactions of this list.
@@ -221,11 +214,9 @@ contract KlerosGovernor is IArbitrableV2 {
221
214
// Do the assignment first to avoid creating a new variable and bypass a 'stack too deep' error.
222
215
submission.deposit = submissionBaseDeposit + arbitrator.arbitrationCost (arbitratorExtraData);
223
216
require (msg .value >= submission.deposit, "Not enough ETH to cover deposit " );
224
- // Using an array to get around the stack limit.
225
- // 0 - List hash.
226
- // 1 - Previous transaction hash.
227
- // 2 - Current transaction hash.
228
- bytes32 [3 ] memory hashes;
217
+
218
+ bytes32 listHash;
219
+ bytes32 currentTxHash;
229
220
uint256 readingPosition;
230
221
for (uint256 i = 0 ; i < _target.length ; i++ ) {
231
222
bytes memory readData = new bytes (_dataSize[i]);
@@ -237,18 +228,16 @@ contract KlerosGovernor is IArbitrableV2 {
237
228
}
238
229
transaction.data = readData;
239
230
readingPosition += _dataSize[i];
240
- hashes[2 ] = keccak256 (abi.encodePacked (transaction.target, transaction.value, transaction.data));
241
- require (uint256 (hashes[2 ]) >= uint256 (hashes[1 ]), "Incorrect tx order " );
242
- hashes[0 ] = keccak256 (abi.encodePacked (hashes[2 ], hashes[0 ]));
243
- hashes[1 ] = hashes[2 ];
231
+ currentTxHash = keccak256 (abi.encodePacked (transaction.target, transaction.value, transaction.data));
232
+ listHash = keccak256 (abi.encodePacked (currentTxHash, listHash));
244
233
}
245
- require (! session.alreadySubmitted[hashes[ 0 ] ], "List already submitted " );
246
- session.alreadySubmitted[hashes[ 0 ] ] = true ;
247
- submission.listHash = hashes[ 0 ] ;
234
+ require (! session.alreadySubmitted[listHash ], "List already submitted " );
235
+ session.alreadySubmitted[listHash ] = true ;
236
+ submission.listHash = listHash ;
248
237
submission.submissionTime = block .timestamp ;
249
238
session.sumDeposit += submission.deposit;
250
239
session.submittedLists.push (submissions.length - 1 );
251
- if (session.submittedLists.length == 1 ) session.durationOffset = block .timestamp . subCap ( lastApprovalTime) ;
240
+ if (session.submittedLists.length == 1 ) session.durationOffset = block .timestamp - lastApprovalTime;
252
241
253
242
emit ListSubmitted (submissions.length - 1 , msg .sender , sessions.length - 1 , _description);
254
243
@@ -273,10 +262,9 @@ contract KlerosGovernor is IArbitrableV2 {
273
262
session.submittedLists[_submissionID] = session.submittedLists[session.submittedLists.length - 1 ];
274
263
session.alreadySubmitted[_listHash] = false ;
275
264
session.submittedLists.pop ();
276
- session.sumDeposit = session.sumDeposit.subCap (submission.deposit);
265
+ session.sumDeposit -= submission.deposit;
266
+ reservedETH -= submission.deposit;
277
267
payable (msg .sender ).transfer (submission.deposit);
278
-
279
- reservedETH = reservedETH.subCap (submission.deposit);
280
268
}
281
269
282
270
/// @dev Approves a transaction list or creates a dispute if more than one list was submitted.
@@ -299,17 +287,17 @@ contract KlerosGovernor is IArbitrableV2 {
299
287
session.status = Status.Resolved;
300
288
sessions.push ();
301
289
302
- reservedETH = reservedETH. subCap ( sumDeposit) ;
290
+ reservedETH -= sumDeposit;
303
291
} else {
304
292
session.status = Status.DisputeCreated;
305
293
uint256 arbitrationCost = arbitrator.arbitrationCost (arbitratorExtraData);
306
294
session.disputeID = arbitrator.createDispute {value: arbitrationCost}(
307
295
session.submittedLists.length ,
308
296
arbitratorExtraData
309
297
);
310
- session.sumDeposit = session.sumDeposit. subCap (arbitrationCost);
311
-
312
- reservedETH = reservedETH. subCap ( arbitrationCost) ;
298
+ // Check in case arbitration cost increased after the submission. It's unlikely that its increase won't be covered by the base deposit, but technically possible.
299
+ session.sumDeposit = session.sumDeposit > arbitrationCost ? session.sumDeposit - arbitrationCost : 0 ;
300
+ reservedETH = reservedETH > arbitrationCost ? reservedETH - arbitrationCost : 0 ;
313
301
emit DisputeRequest (arbitrator, session.disputeID, sessions.length - 1 , templateId, "" );
314
302
}
315
303
}
@@ -331,7 +319,7 @@ contract KlerosGovernor is IArbitrableV2 {
331
319
submission.submitter.send (session.sumDeposit);
332
320
}
333
321
// If the ruling is "0" the reserved funds of this session become expendable.
334
- reservedETH = reservedETH. subCap ( session.sumDeposit) ;
322
+ reservedETH -= session.sumDeposit;
335
323
336
324
session.sumDeposit = 0 ;
337
325
lastApprovalTime = block .timestamp ;
@@ -370,7 +358,7 @@ contract KlerosGovernor is IArbitrableV2 {
370
358
/// @dev Gets the sum of contract funds that are used for the execution of transactions.
371
359
/// @return Contract balance without reserved ETH.
372
360
function getExpendableFunds () public view returns (uint256 ) {
373
- return address (this ).balance. subCap ( reservedETH) ;
361
+ return address (this ).balance - reservedETH;
374
362
}
375
363
376
364
/// @dev Gets the info of the specific transaction in the specific list.
0 commit comments