Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Commit

Permalink
Merge pull request #2254 from 0xProject/fix/t14
Browse files Browse the repository at this point in the history
Add SafeMath to Multisig
  • Loading branch information
jalextowle authored Oct 15, 2019
2 parents 17faeae + 523bc3f commit 2319817
Show file tree
Hide file tree
Showing 23 changed files with 112 additions and 173 deletions.
4 changes: 4 additions & 0 deletions contracts/asset-proxy/CHANGELOG.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
{
"note": "Add `UniswapBridge`",
"pr": 2233
},
{
"note": "Replaced `SafeMath` with `LibSafeMath`",
"pr": 2254
}
],
"timestamp": 1570135330
Expand Down
6 changes: 3 additions & 3 deletions contracts/asset-proxy/contracts/src/ERC1155Proxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@
pragma solidity ^0.5.9;

import "@0x/contracts-utils/contracts/src/LibBytes.sol";
import "@0x/contracts-utils/contracts/src/SafeMath.sol";
import "@0x/contracts-utils/contracts/src/LibSafeMath.sol";
import "@0x/contracts-erc1155/contracts/src/interfaces/IERC1155.sol";
import "../archive/MixinAuthorizable.sol";
import "./interfaces/IAssetProxy.sol";


contract ERC1155Proxy is
MixinAuthorizable,
SafeMath,
IAssetProxy
{
using LibBytes for bytes;
using LibSafeMath for uint256;

// Id of this proxy.
bytes4 constant internal PROXY_ID = bytes4(keccak256("ERC1155Assets(address,uint256[],uint256[],bytes)"));
Expand Down Expand Up @@ -71,7 +71,7 @@ contract ERC1155Proxy is
// to avoid copying over `ids` or `data`. This is possible if they are
// identical to `values` and the offsets for each are pointing to the
// same location in the ABI encoded calldata.
scaledValues[i] = _safeMul(values[i], amount);
scaledValues[i] = values[i].safeMul(amount);
}

// Execute `safeBatchTransferFrom` call
Expand Down
4 changes: 4 additions & 0 deletions contracts/erc1155/CHANGELOG.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
{
"note": "Add `mintKnownFungibleTokensAsync()`, `isNonFungibleItemAsync()`, `isFungibleItemAsync()`, `getOwnerOfAsync()`, `getBalanceAsync()` to `Erc1155Wrapper`.",
"pr": 1819
},
{
"note": "Replaced `SafeMath` with `LibSafeMath`",
"pr": 2254
}
],
"timestamp": 1570135330
Expand Down
16 changes: 8 additions & 8 deletions contracts/erc1155/contracts/src/ERC1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@

pragma solidity ^0.5.9;

import "@0x/contracts-utils/contracts/src/SafeMath.sol";
import "@0x/contracts-utils/contracts/src/LibSafeMath.sol";
import "@0x/contracts-utils/contracts/src/LibAddress.sol";
import "./interfaces/IERC1155.sol";
import "./interfaces/IERC1155Receiver.sol";
import "./MixinNonFungibleToken.sol";


contract ERC1155 is
SafeMath,
IERC1155,
MixinNonFungibleToken
{
using LibAddress for address;
using LibSafeMath for uint256;

// selectors for receiver callbacks
bytes4 constant public ERC1155_RECEIVED = 0xf23a6e61;
Expand Down Expand Up @@ -88,11 +88,11 @@ contract ERC1155 is
nfOwners[id] = to;
// You could keep balance of NF type in base type id like so:
// uint256 baseType = getNonFungibleBaseType(_id);
// balances[baseType][_from] = balances[baseType][_from]._safeSub(_value);
// balances[baseType][_to] = balances[baseType][_to]._safeAdd(_value);
// balances[baseType][_from] = balances[baseType][_from].safeSub(_value);
// balances[baseType][_to] = balances[baseType][_to].safeAdd(_value);
} else {
balances[id][from] = _safeSub(balances[id][from], value);
balances[id][to] = _safeAdd(balances[id][to], value);
balances[id][from] = balances[id][from].safeSub(value);
balances[id][to] = balances[id][to].safeAdd(value);
}
emit TransferSingle(msg.sender, from, to, id, value);

Expand Down Expand Up @@ -170,8 +170,8 @@ contract ERC1155 is
);
nfOwners[id] = to;
} else {
balances[id][from] = _safeSub(balances[id][from], value);
balances[id][to] = _safeAdd(balances[id][to], value);
balances[id][from] = balances[id][from].safeSub(value);
balances[id][to] = balances[id][to].safeAdd(value);
}
}
emit TransferBatch(msg.sender, from, to, ids, values);
Expand Down
11 changes: 6 additions & 5 deletions contracts/erc1155/contracts/src/ERC1155Mintable.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pragma solidity ^0.5.9;

import "@0x/contracts-utils/contracts/src/SafeMath.sol";
import "@0x/contracts-utils/contracts/src/LibSafeMath.sol";
import "./ERC1155.sol";
import "./interfaces/IERC1155Mintable.sol";

Expand All @@ -11,6 +11,7 @@ contract ERC1155Mintable is
IERC1155Mintable,
ERC1155
{
using LibSafeMath for uint256;

/// token nonce
uint256 internal nonce;
Expand All @@ -37,7 +38,7 @@ contract ERC1155Mintable is
)
external
returns (uint256 type_)
{
{
// Store the type in the upper 128 bits
type_ = (++nonce << 128);

Expand Down Expand Up @@ -114,7 +115,7 @@ contract ERC1155Mintable is
uint256 quantity = quantities[i];

// Grant the items to the caller
balances[id][dst] = _safeAdd(quantity, balances[id][dst]);
balances[id][dst] = quantity.safeAdd(balances[id][dst]);

// Emit the Transfer/Mint event.
// the 0x0 source address implies a mint
Expand Down Expand Up @@ -172,7 +173,7 @@ contract ERC1155Mintable is
nfOwners[id] = dst;

// You could use base-type id to store NF type balances if you wish.
// balances[_type][dst] = quantity._safeAdd(balances[_type][dst]);
// balances[_type][dst] = quantity.safeAdd(balances[_type][dst]);

emit TransferSingle(msg.sender, address(0x0), dst, id, 1);

Expand All @@ -194,6 +195,6 @@ contract ERC1155Mintable is

// record the `maxIndex` of this nft type
// this allows us to mint more nft's of this type in a subsequent call.
maxIndex[type_] = _safeAdd(to.length, maxIndex[type_]);
maxIndex[type_] = to.length.safeAdd(maxIndex[type_]);
}
}
4 changes: 4 additions & 0 deletions contracts/erc20/CHANGELOG.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
"changes": [
{
"note": "Dependencies updated"
},
{
"note": "Replaced `SafeMath` with `LibSafeMath`",
"pr": 2254
}
],
"timestamp": 1570135330
Expand Down
15 changes: 8 additions & 7 deletions contracts/erc20/contracts/src/MintableERC20Token.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,23 @@

pragma solidity ^0.5.9;

import "@0x/contracts-utils/contracts/src/SafeMath.sol";
import "@0x/contracts-utils/contracts/src/LibSafeMath.sol";
import "./UnlimitedAllowanceERC20Token.sol";


contract MintableERC20Token is
SafeMath,
contract MintableERC20Token is
UnlimitedAllowanceERC20Token
{
using LibSafeMath for uint256;

/// @dev Mints new tokens
/// @param _to Address of the beneficiary that will own the minted token
/// @param _value Amount of tokens to mint
function _mint(address _to, uint256 _value)
internal
{
balances[_to] = _safeAdd(_value, balances[_to]);
_totalSupply = _safeAdd(_totalSupply, _value);
balances[_to] = _value.safeAdd(balances[_to]);
_totalSupply = _totalSupply.safeAdd(_value);

emit Transfer(
address(0),
Expand All @@ -48,8 +49,8 @@ contract MintableERC20Token is
function _burn(address _owner, uint256 _value)
internal
{
balances[_owner] = _safeSub(balances[_owner], _value);
_totalSupply = _safeSub(_totalSupply, _value);
balances[_owner] = balances[_owner].safeSub(_value);
_totalSupply = _totalSupply.safeSub(_value);

emit Transfer(
_owner,
Expand Down
9 changes: 6 additions & 3 deletions contracts/erc20/contracts/test/DummyERC20Token.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@

pragma solidity ^0.5.5;

import "@0x/contracts-utils/contracts/src/LibSafeMath.sol";
import "@0x/contracts-utils/contracts/src/Ownable.sol";
import "../src/MintableERC20Token.sol";


contract DummyERC20Token is
contract DummyERC20Token is
Ownable,
MintableERC20Token
{
using LibSafeMath for uint256;

string public name;
string public symbol;
uint256 public decimals;
Expand Down Expand Up @@ -55,9 +58,9 @@ contract DummyERC20Token is
{
uint256 currBalance = balances[_target];
if (_value < currBalance) {
_totalSupply = _safeSub(_totalSupply, _safeSub(currBalance, _value));
_totalSupply = _totalSupply.safeSub(currBalance.safeSub(_value));
} else {
_totalSupply = _safeAdd(_totalSupply, _safeSub(_value, currBalance));
_totalSupply = _totalSupply.safeAdd(_value.safeSub(currBalance));
}
balances[_target] = _value;
}
Expand Down
4 changes: 4 additions & 0 deletions contracts/erc721/CHANGELOG.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
"changes": [
{
"note": "Dependencies updated"
},
{
"note": "Replaced `SafeMath` with `LibSafeMath`",
"pr": 2254
}
],
"timestamp": 1570135330
Expand Down
15 changes: 8 additions & 7 deletions contracts/erc721/contracts/src/ERC721Token.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ pragma solidity ^0.5.9;

import "./interfaces/IERC721Token.sol";
import "./interfaces/IERC721Receiver.sol";
import "@0x/contracts-utils/contracts/src/SafeMath.sol";
import "@0x/contracts-utils/contracts/src/LibSafeMath.sol";


contract ERC721Token is
IERC721Token,
SafeMath
IERC721Token
{
using LibSafeMath for uint256;

// Function selector for ERC721Receiver.onERC721Received
// 0x150b7a02
bytes4 constant internal ERC721_RECEIVED = bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"));
Expand Down Expand Up @@ -163,7 +164,7 @@ contract ERC721Token is
_approved
);
}

/// @notice Count all NFTs assigned to an owner
/// @dev NFTs assigned to the zero address are considered invalid, and this
/// function throws for queries about the zero address.
Expand Down Expand Up @@ -223,9 +224,9 @@ contract ERC721Token is
}

owners[_tokenId] = _to;
balances[_from] = _safeSub(balances[_from], 1);
balances[_to] = _safeAdd(balances[_to], 1);
balances[_from] = balances[_from].safeSub(1);
balances[_to] = balances[_to].safeAdd(1);

emit Transfer(
_from,
_to,
Expand Down
9 changes: 6 additions & 3 deletions contracts/erc721/contracts/src/MintableERC721Token.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@

pragma solidity ^0.5.9;

import "@0x/contracts-utils/contracts/src/LibSafeMath.sol";
import "./ERC721Token.sol";


contract MintableERC721Token is
ERC721Token
{
using LibSafeMath for uint256;

/// @dev Function to mint a new token
/// Reverts if the given token ID already exists
/// @param _to Address of the beneficiary that will own the minted token
/// @param _tokenId ID of the token to be minted by the msg.sender
/// @param _tokenId ID of the token to be minted by the msg.sender
function _mint(address _to, uint256 _tokenId)
internal
{
Expand All @@ -43,7 +46,7 @@ contract MintableERC721Token is
);

owners[_tokenId] = _to;
balances[_to] = _safeAdd(balances[_to], 1);
balances[_to] = balances[_to].safeAdd(1);

emit Transfer(
address(0),
Expand Down Expand Up @@ -71,7 +74,7 @@ contract MintableERC721Token is
);

owners[_tokenId] = address(0);
balances[_owner] = _safeSub(balances[_owner], 1);
balances[_owner] = balances[_owner].safeSub(1);

emit Transfer(
_owner,
Expand Down
8 changes: 4 additions & 4 deletions contracts/exchange-libs/contracts/src/LibMath.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ library LibMath {
));
}

// _safeDiv computes `floor(a / b)`. We use the identity (a, b integer):
// safeDiv computes `floor(a / b)`. We use the identity (a, b integer):
// ceil(a / b) = floor((a + b - 1) / b)
// To implement `ceil(a / b)` using _safeDiv.
// To implement `ceil(a / b)` using safeDiv.
partialAmount = numerator.safeMul(target)
.safeAdd(denominator.safeSub(1))
.safeDiv(denominator);
Expand Down Expand Up @@ -127,9 +127,9 @@ library LibMath {
pure
returns (uint256 partialAmount)
{
// _safeDiv computes `floor(a / b)`. We use the identity (a, b integer):
// safeDiv computes `floor(a / b)`. We use the identity (a, b integer):
// ceil(a / b) = floor((a + b - 1) / b)
// To implement `ceil(a / b)` using _safeDiv.
// To implement `ceil(a / b)` using safeDiv.
partialAmount = numerator.safeMul(target)
.safeAdd(denominator.safeSub(1))
.safeDiv(denominator);
Expand Down
4 changes: 4 additions & 0 deletions contracts/extensions/CHANGELOG.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
"changes": [
{
"note": "Dependencies updated"
},
{
"note": "Replaced the use of `SafeMath` with `LibSafeMath`",
"pr": 2254
}
],
"timestamp": 1570135330
Expand Down
Loading

0 comments on commit 2319817

Please sign in to comment.