From 4e494fab9f644d22dc7c253e009c2501f021d54e Mon Sep 17 00:00:00 2001 From: betterdelta Date: Thu, 8 Mar 2018 22:25:27 +0100 Subject: [PATCH 1/8] Split into separate contract files and contracts subdirectory Updated to SafeMath library --- smart_contract.sol => contracts/ForkDelta.sol | 92 +++++-------------- contracts/SafeMath.sol | 48 ++++++++++ contracts/Token.sol | 38 ++++++++ 3 files changed, 107 insertions(+), 71 deletions(-) rename smart_contract.sol => contracts/ForkDelta.sol (65%) create mode 100644 contracts/SafeMath.sol create mode 100644 contracts/Token.sol diff --git a/smart_contract.sol b/contracts/ForkDelta.sol similarity index 65% rename from smart_contract.sol rename to contracts/ForkDelta.sol index 7ad7c79..81aa684 100644 --- a/smart_contract.sol +++ b/contracts/ForkDelta.sol @@ -1,64 +1,13 @@ pragma solidity ^0.4.20; -contract SafeMath { - function safeMul(uint a, uint b) pure internal returns (uint) { - uint c = a * b; - assert(a == 0 || c / a == b); - return c; - } - - function safeSub(uint a, uint b) pure internal returns (uint) { - assert(b <= a); - return a - b; - } - - function safeAdd(uint a, uint b) pure internal returns (uint) { - uint c = a + b; - assert(c>=a && c>=b); - return c; - } -} - -contract Token { - /// @return total amount of tokens - function totalSupply() public constant returns (uint256 supply) {} - - /// @param _owner The address from which the balance will be retrieved - /// @return The balance - function balanceOf(address _owner) public constant returns (uint256 balance) {} - - /// @notice send `_value` token to `_to` from `msg.sender` - /// @param _to The address of the recipient - /// @param _value The amount of token to be transferred - /// @return Whether the transfer was successful or not - function transfer(address _to, uint256 _value) public returns (bool success) {} - - /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from` - /// @param _from The address of the sender - /// @param _to The address of the recipient - /// @param _value The amount of token to be transferred - /// @return Whether the transfer was successful or not - function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {} - - /// @notice `msg.sender` approves `_addr` to spend `_value` tokens - /// @param _spender The address of the account able to transfer the tokens - /// @param _value The amount of wei to be approved for transfer - /// @return Whether the approval was successful or not - function approve(address _spender, uint256 _value) public returns (bool success) {} - - /// @param _owner The address of the account owning tokens - /// @param _spender The address of the account able to transfer the tokens - /// @return Amount of remaining tokens allowed to spent - function allowance(address _owner, address _spender) public constant returns (uint256 remaining) {} +import "./Token.sol"; +import "./SafeMath.sol"; - event Transfer(address indexed _from, address indexed _to, uint256 _value); - event Approval(address indexed _owner, address indexed _spender, uint256 _value); - uint public decimals; - string public name; -} +contract ForkDelta { + + using SafeMath for uint; -contract ForkDelta is SafeMath { address public admin; //the admin address address public feeAccount; //the account that will receive fees uint public feeMake; //percentage times (1 ether) @@ -115,13 +64,13 @@ contract ForkDelta is SafeMath { } function deposit() public payable { - tokens[0][msg.sender] = safeAdd(tokens[0][msg.sender], msg.value); + tokens[0][msg.sender] = tokens[0][msg.sender].add(msg.value); Deposit(0, msg.sender, msg.value, tokens[0][msg.sender]); } function withdraw(uint amount) public { require(tokens[0][msg.sender] >= amount); - tokens[0][msg.sender] = safeSub(tokens[0][msg.sender], amount); + tokens[0][msg.sender] = tokens[0][msg.sender].sub(amount); require(msg.sender.call.value(amount)()); Withdraw(0, msg.sender, amount, tokens[0][msg.sender]); } @@ -130,14 +79,14 @@ contract ForkDelta is SafeMath { //remember to call Token(address).approve(this, amount) or this contract will not be able to do the transfer on your behalf. require(token!=0); require(Token(token).transferFrom(msg.sender, this, amount)); - tokens[token][msg.sender] = safeAdd(tokens[token][msg.sender], amount); + tokens[token][msg.sender] = tokens[token][msg.sender].add(amount); Deposit(token, msg.sender, amount, tokens[token][msg.sender]); } function withdrawToken(address token, uint amount) public { require(token!=0); require(tokens[token][msg.sender] >= amount); - tokens[token][msg.sender] = safeSub(tokens[token][msg.sender], amount); + tokens[token][msg.sender] = tokens[token][msg.sender].sub(amount); require(Token(token).transfer(msg.sender, amount)); Withdraw(token, msg.sender, amount, tokens[token][msg.sender]); } @@ -163,10 +112,10 @@ contract ForkDelta is SafeMath { require(( (orders[user][hash] || ecrecover(keccak256("\x19Ethereum Signed Message:\n32", hash),v,r,s) == user) && block.number <= expires && - safeAdd(orderFills[user][hash], amount) <= amountGet + orderFills[user][hash].add(amount) <= amountGet )); tradeBalances(tokenGet, amountGet, tokenGive, amountGive, user, amount); - orderFills[user][hash] = safeAdd(orderFills[user][hash], amount); + orderFills[user][hash] = orderFills[user][hash].add(amount); Trade(tokenGet, amount, tokenGive, amountGive * amount / amountGet, user, msg.sender); } @@ -176,15 +125,16 @@ contract ForkDelta is SafeMath { uint feeMakeXfer = 0; uint feeTakeXfer = 0; if (now >= freeUntilDate) { - feeMakeXfer = safeMul(amount, feeMake) / (1 ether); - feeTakeXfer = safeMul(amount, feeTake) / (1 ether); + feeMakeXfer = amount.mul(feeMake) / (1 ether); + feeTakeXfer = amount.mul(feeTake) / (1 ether); } - tokens[tokenGet][msg.sender] = safeSub(tokens[tokenGet][msg.sender], safeAdd(amount, feeTakeXfer)); - tokens[tokenGet][user] = safeAdd(tokens[tokenGet][user], safeSub(amount, feeMakeXfer)); - tokens[tokenGet][feeAccount] = safeAdd(tokens[tokenGet][feeAccount], safeAdd(feeMakeXfer, feeTakeXfer)); - tokens[tokenGive][user] = safeSub(tokens[tokenGive][user], safeMul(amountGive, amount) / amountGet); - tokens[tokenGive][msg.sender] = safeAdd(tokens[tokenGive][msg.sender], safeMul(amountGive, amount) / amountGet); + tokens[tokenGet][msg.sender] = tokens[tokenGet][msg.sender].sub(amount.add(feeTakeXfer)); + tokens[tokenGet][user] = tokens[tokenGet][user].add(amount.sub(feeMakeXfer)); + tokens[tokenGet][feeAccount] = tokens[tokenGet][feeAccount].add(feeMakeXfer.sub(feeTakeXfer)); + tokens[tokenGive][user] = tokens[tokenGive][user].sub(amountGive.mul(amount) / amountGet); + tokens[tokenGive][user] = tokens[tokenGive][user].sub(amountGive.mul(amount) / amountGet); + tokens[tokenGive][msg.sender] = tokens[tokenGive][msg.sender].add(amountGive.mul(amount) / amountGet); } function testTrade(address tokenGet, uint amountGet, address tokenGive, uint amountGive, uint expires, uint nonce, address user, uint8 v, bytes32 r, bytes32 s, uint amount, address sender) public constant returns(bool) { @@ -201,8 +151,8 @@ contract ForkDelta is SafeMath { (orders[user][hash] || ecrecover(keccak256("\x19Ethereum Signed Message:\n32", hash),v,r,s) == user) && block.number <= expires )) return 0; - uint available1 = safeSub(amountGet, orderFills[user][hash]); - uint available2 = safeMul(tokens[tokenGive][user], amountGet) / amountGive; + uint available1 = amountGet.sub(orderFills[user][hash]); + uint available2 = tokens[tokenGive][user].mul(amountGet) / amountGive; if (available1 0); // Solidity automatically throws when dividing by 0 + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + return c; + } + + /** + * @dev Substracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + /** + * @dev Adds two numbers, throws on overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + assert(c >= a); + return c; + } +} \ No newline at end of file diff --git a/contracts/Token.sol b/contracts/Token.sol new file mode 100644 index 0000000..b31279a --- /dev/null +++ b/contracts/Token.sol @@ -0,0 +1,38 @@ +contract Token { + /// @return total amount of tokens + function totalSupply() public constant returns (uint256 supply) {} + + /// @param _owner The address from which the balance will be retrieved + /// @return The balance + function balanceOf(address _owner) public constant returns (uint256 balance) {} + + /// @notice send `_value` token to `_to` from `msg.sender` + /// @param _to The address of the recipient + /// @param _value The amount of token to be transferred + /// @return Whether the transfer was successful or not + function transfer(address _to, uint256 _value) public returns (bool success) {} + + /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from` + /// @param _from The address of the sender + /// @param _to The address of the recipient + /// @param _value The amount of token to be transferred + /// @return Whether the transfer was successful or not + function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {} + + /// @notice `msg.sender` approves `_addr` to spend `_value` tokens + /// @param _spender The address of the account able to transfer the tokens + /// @param _value The amount of wei to be approved for transfer + /// @return Whether the approval was successful or not + function approve(address _spender, uint256 _value) public returns (bool success) {} + + /// @param _owner The address of the account owning tokens + /// @param _spender The address of the account able to transfer the tokens + /// @return Amount of remaining tokens allowed to spent + function allowance(address _owner, address _spender) public constant returns (uint256 remaining) {} + + event Transfer(address indexed _from, address indexed _to, uint256 _value); + event Approval(address indexed _owner, address indexed _spender, uint256 _value); + + uint public decimals; + string public name; +} From b0e96099841511d4efba7819abf28413fbe9775e Mon Sep 17 00:00:00 2001 From: betterdelta Date: Thu, 8 Mar 2018 22:25:41 +0100 Subject: [PATCH 2/8] Replaced call.value with transfer --- contracts/ForkDelta.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/ForkDelta.sol b/contracts/ForkDelta.sol index 81aa684..8640782 100644 --- a/contracts/ForkDelta.sol +++ b/contracts/ForkDelta.sol @@ -71,7 +71,7 @@ contract ForkDelta { function withdraw(uint amount) public { require(tokens[0][msg.sender] >= amount); tokens[0][msg.sender] = tokens[0][msg.sender].sub(amount); - require(msg.sender.call.value(amount)()); + msg.sender.transfer(amount) Withdraw(0, msg.sender, amount, tokens[0][msg.sender]); } From d92f6e4cd3c9355a36eed38728448228f815cefe Mon Sep 17 00:00:00 2001 From: betterdelta Date: Fri, 9 Mar 2018 08:04:56 +0100 Subject: [PATCH 3/8] Fixed typo, adjusted pragmas Fixing stack too deep warning Adding emit for events --- contracts/ForkDelta.sol | 35 +++++++++++++++++++---------------- contracts/SafeMath.sol | 3 +-- contracts/Token.sol | 2 ++ 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/contracts/ForkDelta.sol b/contracts/ForkDelta.sol index 8640782..8800f17 100644 --- a/contracts/ForkDelta.sol +++ b/contracts/ForkDelta.sol @@ -1,9 +1,8 @@ -pragma solidity ^0.4.20; +pragma solidity ^0.4.21; import "./Token.sol"; import "./SafeMath.sol"; - contract ForkDelta { using SafeMath for uint; @@ -65,14 +64,14 @@ contract ForkDelta { function deposit() public payable { tokens[0][msg.sender] = tokens[0][msg.sender].add(msg.value); - Deposit(0, msg.sender, msg.value, tokens[0][msg.sender]); + emit Deposit(0, msg.sender, msg.value, tokens[0][msg.sender]); } function withdraw(uint amount) public { require(tokens[0][msg.sender] >= amount); tokens[0][msg.sender] = tokens[0][msg.sender].sub(amount); - msg.sender.transfer(amount) - Withdraw(0, msg.sender, amount, tokens[0][msg.sender]); + msg.sender.transfer(amount); + emit Withdraw(0, msg.sender, amount, tokens[0][msg.sender]); } function depositToken(address token, uint amount) public { @@ -80,7 +79,7 @@ contract ForkDelta { require(token!=0); require(Token(token).transferFrom(msg.sender, this, amount)); tokens[token][msg.sender] = tokens[token][msg.sender].add(amount); - Deposit(token, msg.sender, amount, tokens[token][msg.sender]); + emit Deposit(token, msg.sender, amount, tokens[token][msg.sender]); } function withdrawToken(address token, uint amount) public { @@ -88,7 +87,7 @@ contract ForkDelta { require(tokens[token][msg.sender] >= amount); tokens[token][msg.sender] = tokens[token][msg.sender].sub(amount); require(Token(token).transfer(msg.sender, amount)); - Withdraw(token, msg.sender, amount, tokens[token][msg.sender]); + emit Withdraw(token, msg.sender, amount, tokens[token][msg.sender]); } //support ERC223 @@ -103,7 +102,7 @@ contract ForkDelta { function order(address tokenGet, uint amountGet, address tokenGive, uint amountGive, uint expires, uint nonce) public { bytes32 hash = sha256(this, tokenGet, amountGet, tokenGive, amountGive, expires, nonce); orders[msg.sender][hash] = true; - Order(tokenGet, amountGet, tokenGive, amountGive, expires, nonce, msg.sender); + emit Order(tokenGet, amountGet, tokenGive, amountGive, expires, nonce, msg.sender); } function trade(address tokenGet, uint amountGet, address tokenGive, uint amountGive, uint expires, uint nonce, address user, uint8 v, bytes32 r, bytes32 s, uint amount) public { @@ -116,7 +115,7 @@ contract ForkDelta { )); tradeBalances(tokenGet, amountGet, tokenGive, amountGive, user, amount); orderFills[user][hash] = orderFills[user][hash].add(amount); - Trade(tokenGet, amount, tokenGive, amountGive * amount / amountGet, user, msg.sender); + emit Trade(tokenGet, amount, tokenGive, amountGive * amount / amountGet, user, msg.sender); } function tradeBalances(address tokenGet, uint amountGet, address tokenGive, uint amountGive, address user, uint amount) private { @@ -141,7 +140,8 @@ contract ForkDelta { if (!( tokens[tokenGet][sender] >= amount && availableVolume(tokenGet, amountGet, tokenGive, amountGive, expires, nonce, user, v, r, s) >= amount - )) return false; + )) + return false; return true; } @@ -150,11 +150,14 @@ contract ForkDelta { if (!( (orders[user][hash] || ecrecover(keccak256("\x19Ethereum Signed Message:\n32", hash),v,r,s) == user) && block.number <= expires - )) return 0; - uint available1 = amountGet.sub(orderFills[user][hash]); - uint available2 = tokens[tokenGive][user].mul(amountGet) / amountGive; - if (available1 Date: Fri, 9 Mar 2018 08:08:31 +0100 Subject: [PATCH 4/8] Code formatting --- contracts/ForkDelta.sol | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/contracts/ForkDelta.sol b/contracts/ForkDelta.sol index 8800f17..b9c8be9 100644 --- a/contracts/ForkDelta.sol +++ b/contracts/ForkDelta.sol @@ -140,9 +140,11 @@ contract ForkDelta { if (!( tokens[tokenGet][sender] >= amount && availableVolume(tokenGet, amountGet, tokenGive, amountGive, expires, nonce, user, v, r, s) >= amount - )) + )) { return false; - return true; + } else { + return true; + } } function availableVolume(address tokenGet, uint amountGet, address tokenGive, uint amountGive, uint expires, uint nonce, address user, uint8 v, bytes32 r, bytes32 s) public constant returns(uint) { @@ -150,14 +152,17 @@ contract ForkDelta { if (!( (orders[user][hash] || ecrecover(keccak256("\x19Ethereum Signed Message:\n32", hash),v,r,s) == user) && block.number <= expires - )) + )) { return 0; + } uint[2] memory available; available[0] = amountGet.sub(orderFills[user][hash]); available[1] = tokens[tokenGive][user].mul(amountGet) / amountGive; - if (available[0] Date: Sun, 11 Mar 2018 22:08:49 +0100 Subject: [PATCH 5/8] Removed dupe line --- contracts/ForkDelta.sol | 1 - 1 file changed, 1 deletion(-) diff --git a/contracts/ForkDelta.sol b/contracts/ForkDelta.sol index b9c8be9..80f2d3c 100644 --- a/contracts/ForkDelta.sol +++ b/contracts/ForkDelta.sol @@ -132,7 +132,6 @@ contract ForkDelta { tokens[tokenGet][user] = tokens[tokenGet][user].add(amount.sub(feeMakeXfer)); tokens[tokenGet][feeAccount] = tokens[tokenGet][feeAccount].add(feeMakeXfer.sub(feeTakeXfer)); tokens[tokenGive][user] = tokens[tokenGive][user].sub(amountGive.mul(amount) / amountGet); - tokens[tokenGive][user] = tokens[tokenGive][user].sub(amountGive.mul(amount) / amountGet); tokens[tokenGive][msg.sender] = tokens[tokenGive][msg.sender].add(amountGive.mul(amount) / amountGet); } From 6b8f429377ffdfb4114bb3f2fcc8918c6fe46b73 Mon Sep 17 00:00:00 2001 From: betterdelta Date: Sun, 11 Mar 2018 22:15:02 +0100 Subject: [PATCH 6/8] Fixes --- contracts/ForkDelta.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/ForkDelta.sol b/contracts/ForkDelta.sol index 80f2d3c..d6e7639 100644 --- a/contracts/ForkDelta.sol +++ b/contracts/ForkDelta.sol @@ -130,7 +130,7 @@ contract ForkDelta { tokens[tokenGet][msg.sender] = tokens[tokenGet][msg.sender].sub(amount.add(feeTakeXfer)); tokens[tokenGet][user] = tokens[tokenGet][user].add(amount.sub(feeMakeXfer)); - tokens[tokenGet][feeAccount] = tokens[tokenGet][feeAccount].add(feeMakeXfer.sub(feeTakeXfer)); + tokens[tokenGet][feeAccount] = tokens[tokenGet][feeAccount].add(feeMakeXfer.add(feeTakeXfer)); tokens[tokenGive][user] = tokens[tokenGive][user].sub(amountGive.mul(amount) / amountGet); tokens[tokenGive][msg.sender] = tokens[tokenGive][msg.sender].add(amountGive.mul(amount) / amountGet); } @@ -157,7 +157,7 @@ contract ForkDelta { uint[2] memory available; available[0] = amountGet.sub(orderFills[user][hash]); available[1] = tokens[tokenGive][user].mul(amountGet) / amountGive; - if (available[0] Date: Mon, 12 Mar 2018 17:04:17 +0100 Subject: [PATCH 7/8] Replaced / with div for consistency Replaced one multiplication with SafeMath.mul Minor formatting --- contracts/ForkDelta.sol | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/contracts/ForkDelta.sol b/contracts/ForkDelta.sol index 3bac4f5..99cfd31 100644 --- a/contracts/ForkDelta.sol +++ b/contracts/ForkDelta.sol @@ -23,7 +23,6 @@ contract ForkDelta { event Deposit(address token, address user, uint amount, uint balance); event Withdraw(address token, address user, uint amount, uint balance); - modifier isAdmin() { require(msg.sender == admin); _; @@ -97,7 +96,6 @@ contract ForkDelta { revert(); } } - function withdrawToken(address token, uint amount) public { require(token!=0); @@ -127,24 +125,23 @@ contract ForkDelta { )); tradeBalances(tokenGet, amountGet, tokenGive, amountGive, user, amount); orderFills[user][hash] = orderFills[user][hash].add(amount); - emit Trade(tokenGet, amount, tokenGive, amountGive * amount / amountGet, user, msg.sender); + emit Trade(tokenGet, amount, tokenGive, amountGive.mul(amount).div(amountGet), user, msg.sender); } function tradeBalances(address tokenGet, uint amountGet, address tokenGive, uint amountGive, address user, uint amount) private { - //trades are free until this date in UNIX timestamp uint feeMakeXfer = 0; uint feeTakeXfer = 0; if (now >= freeUntilDate) { - feeMakeXfer = amount.mul(feeMake) / (1 ether); - feeTakeXfer = amount.mul(feeTake) / (1 ether); + feeMakeXfer = amount.mul(feeMake).div(1 ether); + feeTakeXfer = amount.mul(feeTake).div(1 ether); } tokens[tokenGet][msg.sender] = tokens[tokenGet][msg.sender].sub(amount.add(feeTakeXfer)); tokens[tokenGet][user] = tokens[tokenGet][user].add(amount.sub(feeMakeXfer)); tokens[tokenGet][feeAccount] = tokens[tokenGet][feeAccount].add(feeMakeXfer.add(feeTakeXfer)); - tokens[tokenGive][user] = tokens[tokenGive][user].sub(amountGive.mul(amount) / amountGet); - tokens[tokenGive][msg.sender] = tokens[tokenGive][msg.sender].add(amountGive.mul(amount) / amountGet); + tokens[tokenGive][user] = tokens[tokenGive][user].sub(amountGive.mul(amount).div(amountGet); + tokens[tokenGive][msg.sender] = tokens[tokenGive][msg.sender].add(amountGive.mul(amount).div(amountGet)); } function testTrade(address tokenGet, uint amountGet, address tokenGive, uint amountGive, uint expires, uint nonce, address user, uint8 v, bytes32 r, bytes32 s, uint amount, address sender) public constant returns(bool) { @@ -168,7 +165,7 @@ contract ForkDelta { } uint[2] memory available; available[0] = amountGet.sub(orderFills[user][hash]); - available[1] = tokens[tokenGive][user].mul(amountGet) / amountGive; + available[1] = tokens[tokenGive][user].mul(amountGet).div(amountGive); if (available[0] < available[1]) { return available[0]; } else { @@ -187,4 +184,4 @@ contract ForkDelta { orderFills[msg.sender][hash] = amountGet; emit Cancel(tokenGet, amountGet, tokenGive, amountGive, expires, nonce, msg.sender, v, r, s); } -} +} \ No newline at end of file From 08068fef0ac74915d6d161ccc3d6acf9989f2dda Mon Sep 17 00:00:00 2001 From: Jonathon Dunford Date: Mon, 12 Mar 2018 18:03:46 -0400 Subject: [PATCH 8/8] Change assert to require in SafeMath. Discussion in #12 Added our standard .gitignore --- .gitignore | 112 +++++++++++++++++++++++++++++++++++++++++ contracts/SafeMath.sol | 8 +-- 2 files changed, 116 insertions(+), 4 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..09cdeea --- /dev/null +++ b/.gitignore @@ -0,0 +1,112 @@ +## +# Project-specific +new_tokens.csv + +## +# Pythonic + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# dotenv +.env + +# virtualenv +.venv +venv/ +ENV/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ + +#misc +.pydevproject +.project diff --git a/contracts/SafeMath.sol b/contracts/SafeMath.sol index 3dd2522..83aebeb 100644 --- a/contracts/SafeMath.sol +++ b/contracts/SafeMath.sol @@ -14,7 +14,7 @@ library SafeMath { return 0; } uint256 c = a * b; - assert(c / a == b); + require(c / a == b); return c; } @@ -22,7 +22,7 @@ library SafeMath { * @dev Integer division of two numbers, truncating the quotient. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { - // assert(b > 0); // Solidity automatically throws when dividing by 0 + require(b > 0); // Solidity automatically throws when dividing by 0 uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; @@ -32,7 +32,7 @@ library SafeMath { * @dev Substracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { - assert(b <= a); + require(b <= a); return a - b; } @@ -41,7 +41,7 @@ library SafeMath { */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; - assert(c >= a); + require(c >= a); return c; } } \ No newline at end of file