Skip to content

Commit 57dfbd3

Browse files
fix(Governor): remove CappedMath
1 parent aeecb23 commit 57dfbd3

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

contracts/src/arbitration/KlerosGovernor.sol

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@ pragma solidity 0.8.24;
99

1010
import {IArbitrableV2, IArbitratorV2} from "./interfaces/IArbitrableV2.sol";
1111
import "./interfaces/IDisputeTemplateRegistry.sol";
12-
import "../libraries/CappedMath.sol";
1312

1413
/// @title KlerosGovernor for V2. Note that appeal functionality and evidence submission will be handled by the court.
1514
contract KlerosGovernor is IArbitrableV2 {
16-
using CappedMath for uint256;
17-
1815
// ************************************* //
1916
// * Enums / Structs * //
2017
// ************************************* //
@@ -74,16 +71,13 @@ contract KlerosGovernor is IArbitrableV2 {
7471

7572
modifier duringSubmissionPeriod() {
7673
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.");
7875
_;
7976
}
8077

8178
modifier duringApprovalPeriod() {
8279
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.");
8781
_;
8882
}
8983

@@ -248,7 +242,7 @@ contract KlerosGovernor is IArbitrableV2 {
248242
submission.submissionTime = block.timestamp;
249243
session.sumDeposit += submission.deposit;
250244
session.submittedLists.push(submissions.length - 1);
251-
if (session.submittedLists.length == 1) session.durationOffset = block.timestamp.subCap(lastApprovalTime);
245+
if (session.submittedLists.length == 1) session.durationOffset = block.timestamp - lastApprovalTime;
252246

253247
emit ListSubmitted(submissions.length - 1, msg.sender, sessions.length - 1, _description);
254248

@@ -273,10 +267,10 @@ contract KlerosGovernor is IArbitrableV2 {
273267
session.submittedLists[_submissionID] = session.submittedLists[session.submittedLists.length - 1];
274268
session.alreadySubmitted[_listHash] = false;
275269
session.submittedLists.pop();
276-
session.sumDeposit = session.sumDeposit.subCap(submission.deposit);
270+
session.sumDeposit = session.sumDeposit - submission.deposit;
277271
payable(msg.sender).transfer(submission.deposit);
278272

279-
reservedETH = reservedETH.subCap(submission.deposit);
273+
reservedETH = reservedETH - submission.deposit;
280274
}
281275

282276
/// @dev Approves a transaction list or creates a dispute if more than one list was submitted.
@@ -299,17 +293,17 @@ contract KlerosGovernor is IArbitrableV2 {
299293
session.status = Status.Resolved;
300294
sessions.push();
301295

302-
reservedETH = reservedETH.subCap(sumDeposit);
296+
reservedETH = reservedETH - sumDeposit;
303297
} else {
304298
session.status = Status.DisputeCreated;
305299
uint256 arbitrationCost = arbitrator.arbitrationCost(arbitratorExtraData);
306300
session.disputeID = arbitrator.createDispute{value: arbitrationCost}(
307301
session.submittedLists.length,
308302
arbitratorExtraData
309303
);
310-
session.sumDeposit = session.sumDeposit.subCap(arbitrationCost);
311-
312-
reservedETH = reservedETH.subCap(arbitrationCost);
304+
// 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.
305+
session.sumDeposit = session.sumDeposit > arbitrationCost ? session.sumDeposit - arbitrationCost : 0;
306+
reservedETH = reservedETH > arbitrationCost ? reservedETH - arbitrationCost : 0;
313307
emit DisputeRequest(arbitrator, session.disputeID, sessions.length - 1, templateId, "");
314308
}
315309
}
@@ -331,7 +325,7 @@ contract KlerosGovernor is IArbitrableV2 {
331325
submission.submitter.send(session.sumDeposit);
332326
}
333327
// If the ruling is "0" the reserved funds of this session become expendable.
334-
reservedETH = reservedETH.subCap(session.sumDeposit);
328+
reservedETH = reservedETH - session.sumDeposit;
335329

336330
session.sumDeposit = 0;
337331
lastApprovalTime = block.timestamp;
@@ -370,7 +364,7 @@ contract KlerosGovernor is IArbitrableV2 {
370364
/// @dev Gets the sum of contract funds that are used for the execution of transactions.
371365
/// @return Contract balance without reserved ETH.
372366
function getExpendableFunds() public view returns (uint256) {
373-
return address(this).balance.subCap(reservedETH);
367+
return address(this).balance - reservedETH;
374368
}
375369

376370
/// @dev Gets the info of the specific transaction in the specific list.

0 commit comments

Comments
 (0)