Skip to content

Commit 9f1dff7

Browse files
nuevoalexnuevoalex
authored andcommitted
unsafe math changes for cases that could potentially cause overflow problems
1 parent 0471ff4 commit 9f1dff7

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

source/contracts/reporting/FeeWindow.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ contract FeeWindow is DelegationTarget, VariableSupplyToken, Extractable, Initia
4141
function initialize(IUniverse _universe, uint256 _feeWindowId) public onlyInGoodTimes beforeInitialized returns (bool) {
4242
endInitialization();
4343
universe = _universe;
44-
startTime = _feeWindowId * universe.getDisputeRoundDurationInSeconds();
44+
startTime = _feeWindowId.mul(universe.getDisputeRoundDurationInSeconds());
4545
// Initialize this to some reasonable value to handle the first market ever created without branching code
4646
reportingGasPrice.record(Reporting.getDefaultReportingGasPrice());
4747
feeToken = FeeTokenFactory(controller.lookup("FeeTokenFactory")).createFeeToken(controller, this);
@@ -172,7 +172,7 @@ contract FeeWindow is DelegationTarget, VariableSupplyToken, Extractable, Initia
172172
}
173173

174174
function getEndTime() public afterInitialized view returns (uint256) {
175-
return getStartTime() + Reporting.getDisputeRoundDurationSeconds();
175+
return getStartTime().add(Reporting.getDisputeRoundDurationSeconds());
176176
}
177177

178178
function getFeeToken() public afterInitialized view returns (IFeeToken) {

source/contracts/reporting/Market.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ contract Market is DelegationTarget, Extractable, ITyped, Initializable, Ownable
405405
}
406406

407407
function getDesignatedReportingEndTime() public view returns (uint256) {
408-
return endTime + Reporting.getDesignatedReportingDurationSeconds();
408+
return endTime.add(Reporting.getDesignatedReportingDurationSeconds());
409409
}
410410

411411
function getNumParticipants() public view returns (uint256) {

source/contracts/reporting/Universe.sol

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ contract Universe is DelegationTarget, Extractable, ITyped, Initializable, IUniv
5656
require(forkingMarket == IMarket(0));
5757
require(isContainerForMarket(IMarket(msg.sender)));
5858
forkingMarket = IMarket(msg.sender);
59-
forkEndTime = controller.getTimestamp() + Reporting.getForkDurationSeconds();
59+
forkEndTime = controller.getTimestamp().add(Reporting.getForkDurationSeconds());
6060
controller.getAugur().logUniverseForked();
6161
return true;
6262
}
@@ -65,7 +65,7 @@ contract Universe is DelegationTarget, Extractable, ITyped, Initializable, IUniv
6565
uint256 _totalRepSupply = reputationToken.getTotalTheoreticalSupply();
6666
forkReputationGoal = _totalRepSupply.div(2); // 50% of REP migrating results in a victory in a fork
6767
disputeThresholdForFork = _totalRepSupply.div(80); // 1.25% of the total rep supply
68-
initialReportMinValue = disputeThresholdForFork.div(3).div(2**18) + 1; // This value will result in a maximum 20 round dispute sequence
68+
initialReportMinValue = disputeThresholdForFork.div(3).div(2**18).add(1); // This value will result in a maximum 20 round dispute sequence
6969
return true;
7070
}
7171

@@ -118,7 +118,7 @@ contract Universe is DelegationTarget, Extractable, ITyped, Initializable, IUniv
118118
}
119119

120120
function getFeeWindowId(uint256 _timestamp) public view returns (uint256) {
121-
return _timestamp / getDisputeRoundDurationInSeconds();
121+
return _timestamp.div(getDisputeRoundDurationInSeconds());
122122
}
123123

124124
function getDisputeRoundDurationInSeconds() public view returns (uint256) {
@@ -141,11 +141,11 @@ contract Universe is DelegationTarget, Extractable, ITyped, Initializable, IUniv
141141
}
142142

143143
function getOrCreatePreviousFeeWindow() public onlyInGoodTimes returns (IFeeWindow) {
144-
return getOrCreateFeeWindowByTimestamp(controller.getTimestamp() - getDisputeRoundDurationInSeconds());
144+
return getOrCreateFeeWindowByTimestamp(controller.getTimestamp().sub(getDisputeRoundDurationInSeconds()));
145145
}
146146

147147
function getPreviousFeeWindow() public view onlyInGoodTimes returns (IFeeWindow) {
148-
return getFeeWindowByTimestamp(controller.getTimestamp() - getDisputeRoundDurationInSeconds());
148+
return getFeeWindowByTimestamp(controller.getTimestamp().sub(getDisputeRoundDurationInSeconds()));
149149
}
150150

151151
function getOrCreateCurrentFeeWindow() public onlyInGoodTimes returns (IFeeWindow) {
@@ -157,15 +157,15 @@ contract Universe is DelegationTarget, Extractable, ITyped, Initializable, IUniv
157157
}
158158

159159
function getOrCreateNextFeeWindow() public onlyInGoodTimes returns (IFeeWindow) {
160-
return getOrCreateFeeWindowByTimestamp(controller.getTimestamp() + getDisputeRoundDurationInSeconds());
160+
return getOrCreateFeeWindowByTimestamp(controller.getTimestamp().add(getDisputeRoundDurationInSeconds()));
161161
}
162162

163163
function getNextFeeWindow() public view onlyInGoodTimes returns (IFeeWindow) {
164-
return getFeeWindowByTimestamp(controller.getTimestamp() + getDisputeRoundDurationInSeconds());
164+
return getFeeWindowByTimestamp(controller.getTimestamp().add(getDisputeRoundDurationInSeconds()));
165165
}
166166

167167
function getOrCreateFeeWindowBefore(IFeeWindow _feeWindow) public onlyInGoodTimes returns (IFeeWindow) {
168-
return getOrCreateFeeWindowByTimestamp(_feeWindow.getStartTime() - 2);
168+
return getOrCreateFeeWindowByTimestamp(_feeWindow.getStartTime().sub(2));
169169
}
170170

171171
function createChildUniverse(uint256[] _parentPayoutNumerators, bool _parentInvalid) public returns (IUniverse) {
@@ -426,7 +426,7 @@ contract Universe is DelegationTarget, Extractable, ITyped, Initializable, IUniv
426426
}
427427

428428
function getOrCacheMarketCreationCost() public onlyInGoodTimes returns (uint256) {
429-
return getOrCacheValidityBond() + getOrCacheTargetReporterGasCosts();
429+
return getOrCacheValidityBond().add(getOrCacheTargetReporterGasCosts());
430430
}
431431

432432
function getInitialReportStakeSize() public onlyInGoodTimes returns (uint256) {

source/contracts/trading/ClaimTradingProceeds.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ contract ClaimTradingProceeds is CashAutoConverter, Extractable, ReentrancyGuard
2727
_market.finalize();
2828
}
2929

30-
require(controller.getTimestamp() > _market.getFinalizationTime() + Reporting.getClaimTradingProceedsWaitTime());
30+
require(controller.getTimestamp() > _market.getFinalizationTime().add(Reporting.getClaimTradingProceedsWaitTime()));
3131

3232
ICash _denominationToken = _market.getDenominationToken();
3333

0 commit comments

Comments
 (0)