Skip to content

Commit d075d9c

Browse files
authored
Merge pull request #515 from AugurProject/low_medium_issues
Low medium issues
2 parents ba3fdec + 14057cf commit d075d9c

21 files changed

+140
-52
lines changed

CRIBBED_CODE.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Licensing inclusion for the following files which were originally taken from the OpenZeppelin Solidity token contracts and later modified by us:
2+
3+
source/libraries/token/BasicToken.sol
4+
source/libraries/token/ERC20.sol
5+
source/libraries/token/ERC20Basic.sol
6+
source/libraries/token/StandardToken.sol
7+
8+
The MIT License (MIT)
9+
10+
Copyright (c) 2016 Smart Contract Solutions, Inc.
11+
12+
Permission is hereby granted, free of charge, to any person obtaining
13+
a copy of this software and associated documentation files (the
14+
"Software"), to deal in the Software without restriction, including
15+
without limitation the rights to use, copy, modify, merge, publish,
16+
distribute, sublicense, and/or sell copies of the Software, and to
17+
permit persons to whom the Software is furnished to do so, subject to
18+
the following conditions:
19+
20+
The above copyright notice and this permission notice shall be included
21+
in all copies or substantial portions of the Software.
22+
23+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
26+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
27+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
28+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
29+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

source/contracts/Augur.sol

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ contract Augur is Controlled, Extractable {
3434
event TokensMinted(address indexed universe, address indexed token, address indexed target, uint256 amount);
3535
event TokensBurned(address indexed universe, address indexed token, address indexed target, uint256 amount);
3636
event FeeWindowCreated(address indexed universe, address feeWindow, uint256 startTime, uint256 endTime, uint256 id);
37+
event WhitelistAddition(address addition);
38+
event RegistryAddition(bytes32 key, address addition, bytes20 commitHash, bytes32 bytecodeHash);
3739

3840
mapping(address => bool) private universes;
3941

@@ -279,6 +281,16 @@ contract Augur is Controlled, Extractable {
279281
return true;
280282
}
281283

284+
function logContractAddedToWhitelist(address _addition) public onlyControllerCaller returns (bool) {
285+
WhitelistAddition(_addition);
286+
return true;
287+
}
288+
289+
function logContractAddedToRegistry(bytes32 _key, address _address, bytes20 _commitHash, bytes32 _bytecodeHash) public onlyControllerCaller returns (bool) {
290+
RegistryAddition(_key, _address, _commitHash, _bytecodeHash);
291+
return true;
292+
}
293+
282294
function getProtectedTokens() internal returns (address[] memory) {
283295
return new address[](0);
284296
}

source/contracts/Controller.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ contract Controller is IController {
6666

6767
function addToWhitelist(address _target) public onlyWhitelistedCallers returns (bool) {
6868
whitelist[_target] = true;
69+
getAugur().logContractAddedToWhitelist(_target);
6970
return true;
7071
}
7172

@@ -85,6 +86,7 @@ contract Controller is IController {
8586

8687
function registerContract(bytes32 _key, address _address, bytes20 _commitHash, bytes32 _bytecodeHash) public onlyOwnerCaller returns (bool) {
8788
registry[_key] = ContractDetails(_key, _address, _commitHash, _bytecodeHash);
89+
getAugur().logContractAddedToRegistry(_key, _address, _commitHash, _bytecodeHash);
8890
return true;
8991
}
9092

source/contracts/libraries/Delegator.sol

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,9 @@ contract Delegator is DelegationTarget {
2323
assembly {
2424
//0x40 is the address where the next free memory slot is stored in Solidity
2525
let _calldataMemoryOffset := mload(0x40)
26+
// new "memory end" including padding. The bitwise operations here ensure we get rounded up to the nearest 32 byte boundary
27+
let _size := and(add(calldatasize, 0x1f), not(0x1f))
2628
// Update the pointer at 0x40 to point at new free memory location so any theoretical allocation doesn't stomp our memory in this call
27-
let _size := 0
28-
switch gt(calldatasize, 32)
29-
case 1 {
30-
_size := calldatasize
31-
} default {
32-
_size := 32
33-
}
3429
mstore(0x40, add(_calldataMemoryOffset, _size))
3530
// Copy method signature and parameters of this call into memory
3631
calldatacopy(_calldataMemoryOffset, 0x0, calldatasize)

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/ReputationToken.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ contract ReputationToken is DelegationTarget, Extractable, ITyped, Initializable
122122

123123
function updateSiblingMigrationTotal(IReputationToken _token) public returns (bool) {
124124
require(_token != this);
125-
IUniverse _supposedUniverse = _token.getUniverse();
126-
require(_token == universe.getParentUniverse().getChildUniverse(_supposedUniverse.getParentPayoutDistributionHash()).getReputationToken());
125+
IUniverse _shadyUniverse = _token.getUniverse();
126+
require(_token == universe.getParentUniverse().getChildUniverse(_shadyUniverse.getParentPayoutDistributionHash()).getReputationToken());
127127
totalTheoreticalSupply += migratedToSibling[_token];
128128
migratedToSibling[_token] = _token.getTotalMigrated();
129129
totalTheoreticalSupply -= migratedToSibling[_token];

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: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@ import 'libraries/Extractable.sol';
2222
contract ClaimTradingProceeds is CashAutoConverter, Extractable, ReentrancyGuard, MarketValidator, IClaimTradingProceeds {
2323
using SafeMathUint256 for uint256;
2424

25-
function claimTradingProceeds(IMarket _market) marketIsLegit(_market) convertToAndFromCash onlyInGoodTimes nonReentrant external returns(bool) {
25+
function claimTradingProceeds(IMarket _market, address _shareHolder) marketIsLegit(_market) onlyInGoodTimes nonReentrant external returns(bool) {
2626
if (!_market.isFinalized()) {
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

3434
for (uint8 _outcome = 0; _outcome < _market.getNumberOfOutcomes(); ++_outcome) {
3535
IShareToken _shareToken = _market.getShareToken(_outcome);
36-
uint256 _numberOfShares = _shareToken.balanceOf(msg.sender);
36+
uint256 _numberOfShares = _shareToken.balanceOf(_shareHolder);
3737
var (_proceeds, _shareHolderShare, _creatorShare, _reporterShare) = divideUpWinnings(_market, _outcome, _numberOfShares);
3838

3939
if (_proceeds > 0) {
@@ -42,11 +42,12 @@ contract ClaimTradingProceeds is CashAutoConverter, Extractable, ReentrancyGuard
4242

4343
// always destroy shares as it gives a minor gas refund and is good for the network
4444
if (_numberOfShares > 0) {
45-
_shareToken.destroyShares(msg.sender, _numberOfShares);
46-
logTradingProceedsClaimed(_market, _shareToken, msg.sender, _numberOfShares, _shareHolderShare);
45+
_shareToken.destroyShares(_shareHolder, _numberOfShares);
46+
logTradingProceedsClaimed(_market, _shareToken, _shareHolder, _numberOfShares, _shareHolderShare);
4747
}
4848
if (_shareHolderShare > 0) {
49-
require(_denominationToken.transferFrom(_market, msg.sender, _shareHolderShare));
49+
require(_denominationToken.transferFrom(_market, this, _shareHolderShare));
50+
_denominationToken.withdrawEtherTo(_shareHolder, _shareHolderShare);
5051
}
5152
if (_creatorShare > 0) {
5253
require(_denominationToken.transferFrom(_market, _market.getMarketCreatorMailbox(), _creatorShare));

source/libraries/ContractDeployer.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ export class ContractDeployer {
3030

3131
public async deploy(): Promise<void> {
3232
this.controller = await this.uploadController();
33+
await this.uploadAugur();
3334
await this.uploadAllContracts();
35+
await this.initializeAllContracts();
3436
await this.whitelistTradingContracts();
35-
await this.initializeAllContracts();
3637

3738
if(this.configuration.createGenesisUniverse) {
3839
this.universe = await this.createGenesisUniverse();
@@ -87,6 +88,19 @@ export class ContractDeployer {
8788
return controller;
8889
}
8990

91+
private async uploadAugur(): Promise<void> {
92+
// We have to upload and initialize Augur first so it can log the registration and whitelisting of other contracts
93+
const contract = await this.contracts.get("Augur");
94+
const address = await this.construct(contract, [], `Uploading ${contract.contractName}`);
95+
const commitHash = await ContractDeployer.getGitCommit();
96+
const bytecodeHash = await ContractDeployer.getBytecodeSha(contract.bytecode);
97+
const augur = new Augur(this.connector, this.accountManager, address, this.configuration.gasPrice);
98+
contract.address = address;
99+
const setControllerTransactionHash = await augur.setController(this.controller.address);
100+
await this.connector.waitForTransactionReceipt(setControllerTransactionHash, `Initializing Augur.`);
101+
await this.controller.registerContract(stringTo32ByteHex("Augur"), address, commitHash, bytecodeHash);
102+
}
103+
90104
private async uploadAllContracts(): Promise<void> {
91105
console.log('Uploading contracts...');
92106
const promises = [...this.contracts].map(contract => this.upload(contract));
@@ -99,6 +113,7 @@ export class ContractDeployer {
99113
if (contractName === 'Controller') return;
100114
if (contractName === 'Delegator') return;
101115
if (contractName === 'TimeControlled') return;
116+
if (contractName === 'Augur') return;
102117
if (contractName === 'Time') contract = this.configuration.useNormalTime ? contract: this.contracts.get('TimeControlled');
103118
if (contract.relativeFilePath.startsWith('legacy_reputation/')) return;
104119
if (contract.relativeFilePath.startsWith('libraries/')) return;
@@ -182,7 +197,7 @@ export class ContractDeployer {
182197

183198
private async initializeAllContracts(): Promise<void> {
184199
console.log('Initializing contracts...');
185-
const contractsToInitialize = ["Augur","CompleteSets","CreateOrder","FillOrder","CancelOrder","Trade","ClaimTradingProceeds","OrdersFetcher","Time"];
200+
const contractsToInitialize = ["CompleteSets","CreateOrder","FillOrder","CancelOrder","Trade","ClaimTradingProceeds","OrdersFetcher","Time"];
186201
const promises: Array<Promise<any>> = [];
187202
for (let contractName of contractsToInitialize) {
188203
promises.push(this.initializeContract(contractName));

0 commit comments

Comments
 (0)