change safe* to *

pull/184/head
Manuel Araoz 8 years ago
parent 4fad1505c7
commit 609869f087
  1. 8
      contracts/SafeMath.sol
  2. 6
      contracts/payment/PullPayment.sol
  3. 8
      contracts/token/BasicToken.sol
  4. 6
      contracts/token/CrowdsaleToken.sol
  5. 4
      contracts/token/MintableToken.sol
  6. 8
      contracts/token/StandardToken.sol
  7. 16
      contracts/token/VestedToken.sol
  8. 6
      test/helpers/SafeMathMock.sol

@ -5,25 +5,25 @@ pragma solidity ^0.4.8;
* Math operations with safety checks
*/
library SafeMath {
function safeMul(uint a, uint b) internal returns (uint) {
function mul(uint a, uint b) internal returns (uint) {
uint c = a * b;
assert(a == 0 || c / a == b);
return c;
}
function safeDiv(uint a, uint b) internal returns (uint) {
function div(uint a, uint b) internal returns (uint) {
assert(b > 0);
uint c = a / b;
assert(a == b * c + a % b);
return c;
}
function safeSub(uint a, uint b) internal returns (uint) {
function sub(uint a, uint b) internal returns (uint) {
assert(b <= a);
return a - b;
}
function safeAdd(uint a, uint b) internal returns (uint) {
function add(uint a, uint b) internal returns (uint) {
uint c = a + b;
assert(c >= a);
return c;

@ -17,8 +17,8 @@ contract PullPayment {
// store sent amount as credit to be pulled, called by payer
function asyncSend(address dest, uint amount) internal {
payments[dest] = payments[dest].safeAdd(amount);
totalPayments = totalPayments.safeAdd(amount);
payments[dest] = payments[dest].add(amount);
totalPayments = totalPayments.add(amount);
}
// withdraw accumulated balance, called by payee
@ -34,7 +34,7 @@ contract PullPayment {
throw;
}
totalPayments = totalPayments.safeSub(payment);
totalPayments = totalPayments.sub(payment);
payments[payee] = 0;
if (!payee.send(payment)) {

@ -18,13 +18,15 @@ contract BasicToken is ERC20Basic {
* Fix for the ERC20 short address attack
*/
modifier onlyPayloadSize(uint size) {
assert(msg.data.length >= size + 4);
if(msg.data.length < size + 4) {
throw;
}
_;
}
function transfer(address _to, uint _value) onlyPayloadSize(2 * 32) {
balances[msg.sender] = balances[msg.sender].safeSub(_value);
balances[_to] = balances[_to].safeAdd(_value);
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
Transfer(msg.sender, _to, _value);
}

@ -32,10 +32,10 @@ contract CrowdsaleToken is StandardToken {
throw;
}
uint tokens = msg.value.safeMul(getPrice());
totalSupply = totalSupply.safeAdd(tokens);
uint tokens = msg.value.mul(getPrice());
totalSupply = totalSupply.add(tokens);
balances[recipient] = balances[recipient].safeAdd(tokens);
balances[recipient] = balances[recipient].add(tokens);
if (!multisig.send(msg.value)) {
throw;

@ -29,8 +29,8 @@ contract MintableToken is StandardToken, Ownable {
}
function mint(address _to, uint _amount) onlyOwner canMint returns (bool) {
totalSupply = safeAdd(totalSupply, _amount);
balances[_to] = safeAdd(balances[_to], _amount);
totalSupply = totalSupply.add(_amount);
balances[_to] = balances[_to].add(_amount);
Mint(_to, _amount);
return true;
}

@ -19,12 +19,12 @@ contract StandardToken is BasicToken, ERC20 {
function transferFrom(address _from, address _to, uint _value) {
var _allowance = allowed[_from][msg.sender];
// Check is not needed because safeSub(_allowance, _value) will already throw if this condition is not met
// Check is not needed because sub(_allowance, _value) will already throw if this condition is not met
// if (_value > _allowance) throw;
balances[_to] = balances[_to].safeAdd(_value);
balances[_from] = balances[_from].safeSub(_value);
allowed[_from][msg.sender] = _allowance.safeSub(_value);
balances[_to] = balances[_to].add(_value);
balances[_from] = balances[_from].sub(_value);
allowed[_from][msg.sender] = _allowance.sub(_value);
Transfer(_from, _to, _value);
}

@ -52,8 +52,8 @@ contract VestedToken is StandardToken, LimitedTransferToken {
grants[_holder][_grantId] = grants[_holder][grants[_holder].length - 1];
grants[_holder].length -= 1;
balances[msg.sender] = balances[msg.sender].safeAdd(nonVested);
balances[_holder] = balances[_holder].safeSub(nonVested);
balances[msg.sender] = balances[msg.sender].add(nonVested);
balances[_holder] = balances[_holder].sub(nonVested);
Transfer(_holder, msg.sender, nonVested);
}
@ -98,16 +98,16 @@ contract VestedToken is StandardToken, LimitedTransferToken {
return tokens;
}
uint256 cliffTokens = tokens.safeMul(cliff.safeSub(start)).safeDiv(vesting.safeSub(start));
uint256 cliffTokens = tokens.mul(cliff.sub(start)).div(vesting.sub(start));
vestedTokens = cliffTokens;
uint256 vestingTokens = tokens.safeSub(cliffTokens);
uint256 vestingTokens = tokens.sub(cliffTokens);
vestedTokens = vestedTokens.safeAdd(vestingTokens.safeMul(time.safeSub(cliff)).safeDiv(vesting.safeSub(cliff)));
vestedTokens = vestedTokens.add(vestingTokens.mul(time.sub(cliff)).div(vesting.sub(cliff)));
}
function nonVestedTokens(TokenGrant grant, uint64 time) private constant returns (uint256) {
return grant.value.safeSub(vestedTokens(grant, time));
return grant.value.sub(vestedTokens(grant, time));
}
function lastTokenIsTransferableDate(address holder) constant public returns (uint64 date) {
@ -122,9 +122,9 @@ contract VestedToken is StandardToken, LimitedTransferToken {
uint256 grantIndex = grants[holder].length;
for (uint256 i = 0; i < grantIndex; i++) {
uint256 current = nonVestedTokens(grants[holder][i], time);
nonVested = nonVested.safeAdd(current);
nonVested = nonVested.add(current);
}
return SafeMath.min256(balances[holder].safeSub(nonVested), super.transferableTokens(holder, time));
return SafeMath.min256(balances[holder].sub(nonVested), super.transferableTokens(holder, time));
}
}

@ -8,14 +8,14 @@ contract SafeMathMock {
uint public result;
function multiply(uint a, uint b) {
result = SafeMath.safeMul(a, b);
result = SafeMath.mul(a, b);
}
function subtract(uint a, uint b) {
result = SafeMath.safeSub(a, b);
result = SafeMath.sub(a, b);
}
function add(uint a, uint b) {
result = SafeMath.safeAdd(a, b);
result = SafeMath.add(a, b);
}
}

Loading…
Cancel
Save