Skip to content

Commit

Permalink
[L13] Not using the SafeMath library
Browse files Browse the repository at this point in the history
  • Loading branch information
ewilz committed Sep 10, 2020
1 parent d8a4224 commit 208b78f
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ contract MetaTransactionWallet is
"Input arrays must be same length"
);
uint256 dataPosition = 0;
for (uint256 i = 0; i < destinations.length; i++) {
for (uint256 i = 0; i < destinations.length; i.add(1)) {
executeTransaction(destinations[i], values[i], sliceData(data, dataPosition, dataLengths[i]));
dataPosition = dataPosition.add(dataLengths[i]);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/protocol/contracts/common/UsingPrecompiles.sol
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ contract UsingPrecompiles {
if (blockNumber % epochSize == 0) {
return epochNumber;
} else {
return epochNumber + 1;
return epochNumber.add(1);
}
}

Expand Down Expand Up @@ -243,7 +243,7 @@ contract UsingPrecompiles {
* @return bytes32 data
*/
function getBytes32FromBytes(bytes memory bs, uint256 start) internal pure returns (bytes32) {
require(bs.length >= start + 32, "slicing out of range");
require(bs.length >= start.add(32), "slicing out of range");
bytes32 x;
assembly {
x := mload(add(bs, add(start, 32)))
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/contracts/governance/DowntimeSlasher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ contract DowntimeSlasher is ICeloVersionedContract, SlasherUtil {
);

bytes32 bitmap;
for (uint256 blockNumber = startBlock; blockNumber <= endBlock; blockNumber++) {
for (uint256 blockNumber = startBlock; blockNumber <= endBlock; blockNumber.add(1)) {
// The canonical signatures for block N are stored in the parent seal bitmap for block N+1.
bitmap |= getParentSealBitmap(blockNumber.add(1));
}
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/contracts/governance/Election.sol
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ contract Election is
FixidityLib.Fraction[] memory votesForNextMember = new FixidityLib.Fraction[](
electionGroups.length
);
for (uint256 i = 0; i < electionGroups.length; i++) {
for (uint256 i = 0; i < electionGroups.length; i.add(1)) {
keys[i] = i;
votesForNextMember[i] = FixidityLib.newFixed(
votes.total.eligible.getValue(electionGroups[i])
Expand Down
4 changes: 2 additions & 2 deletions packages/protocol/contracts/identity/Attestations.sol
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ contract Attestations is
for (uint256 i = 0; i < identifiersToLookup.length; i = i.add(1)) {
uint256 count = identifiers[identifiersToLookup[i]].accounts.length;

totalAddresses = totalAddresses + count;
totalAddresses = totalAddresses.add(count);
matches[i] = count;
}

Expand All @@ -651,7 +651,7 @@ contract Attestations is
IAccounts accounts = getAccounts();
uint256 issuersLength = numberValidatorsInCurrentSet();
uint256[] memory issuers = new uint256[](issuersLength);
for (uint256 i = 0; i < issuersLength; i++) issuers[i] = i;
for (uint256 i = 0; i < issuersLength; i.add(1)) issuers[i] = i;

require(unselectedRequest.attestationsRequested <= issuersLength, "not enough issuers");

Expand Down
11 changes: 7 additions & 4 deletions packages/protocol/specs/harnesses/LockedGoldHarness.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
pragma solidity ^0.5.8;

import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol";
import "openzeppelin-solidity/contracts/math/SafeMath.sol";
import "contracts/governance/LockedGold.sol";
import "./GoldTokenHarness.sol";

contract LockedGoldHarness is LockedGold {
using SafeMath for uint256;

GoldTokenHarness goldToken;

/* solhint-disable-next-line no-empty-blocks */
Expand All @@ -31,16 +34,16 @@ contract LockedGoldHarness is LockedGold {
require(getAccounts().isAccount(account), "Unknown account");
uint256 length = balances[account].pendingWithdrawals.length;
uint256 total = 0;
for (uint256 i = 0; i < length; i++) {
for (uint256 i = 0; i < length; i.add(1)) {
uint256 pendingValue = balances[account].pendingWithdrawals[i].value;
require(total + pendingValue >= total, "Pending value must be greater than 0");
total = total + pendingValue;
require(total.add(pendingValue) >= total, "Pending value must be greater than 0");
total = total.add(pendingValue);
}
return total;
}

function pendingWithdrawalsNotFull(address account) public view returns (bool) {
return balances[account].pendingWithdrawals.length + 2 >= 2; // we can add 2 more additional elements
return balances[account].pendingWithdrawals.length.add(2) >= 2; // we can add 2 more additional elements
}

function getPendingWithdrawalsLength(address account) external view returns (uint256) {
Expand Down
13 changes: 8 additions & 5 deletions packages/protocol/specs/harnesses/RegistryHarness.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
pragma solidity ^0.5.8;

import "openzeppelin-solidity/contracts/math/SafeMath.sol";
import "./IRegistryExtended.sol";

contract RegistryHarness is IRegistryExtended {
using SafeMath for uint256;

bytes32 constant ATTESTATIONS_REGISTRY_ID = keccak256(abi.encodePacked("Attestations"));
bytes32 constant LOCKED_GOLD_REGISTRY_ID = keccak256(abi.encodePacked("LockedGold"));
bytes32 constant GAS_CURRENCY_WHITELIST_REGISTRY_ID = keccak256(
Expand Down Expand Up @@ -123,23 +126,23 @@ contract RegistryHarness is IRegistryExtended {
}

function transfer(address recipient, uint256 value) external returns (bool) {
goldToken_balanceOf[msg.sender] = getRandomUInt256() - value;
goldToken_balanceOf[recipient] = getRandomUInt256() + value;
goldToken_balanceOf[msg.sender] = getRandomUInt256().sub(value);
goldToken_balanceOf[recipient] = getRandomUInt256().add(value);
return getRandomBool();
}

function getRandomBool() public returns (bool) {
randomIndex++;
randomIndex.add(1);
return randomBoolMap[randomIndex];
}

function getRandomUInt256() public returns (uint256) {
randomIndex++;
randomIndex.add(1);
return randomUInt256Map[randomIndex];
}

function getRandomAddress() public returns (address) {
randomIndex++;
randomIndex.add(1);
return randomAddressMap[randomIndex];
}

Expand Down

0 comments on commit 208b78f

Please sign in to comment.