Skip to content

Commit

Permalink
CHANGELOG updated, custom error messages added to ERC20, ERC721 and E…
Browse files Browse the repository at this point in the history
…RC777 for subtraction related exceptions.
  • Loading branch information
elch-yan committed Jul 24, 2019
1 parent f563e76 commit 3eec22d
Show file tree
Hide file tree
Showing 9 changed files with 1,724 additions and 1,730 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
### Improvements:
* `Address.isContract`: switched from `extcodesize` to `extcodehash` for less gas usage. ([#1802](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1802))

* `SafeMath`: added support for custom error messages. `ERC20`, `ERC721` and `ERC777` updated to throw custom errors on subtraction overflows. ([#1828](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/1828))

### Bugfixes

## 2.3.0 (2019-05-27)
Expand Down
12 changes: 6 additions & 6 deletions contracts/token/ERC20/ERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ contract ERC20 is IERC20 {
*/
function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, msg.sender, _allowances[sender][msg.sender].sub(amount));
_approve(sender, msg.sender, _allowances[sender][msg.sender].sub(amount, "ERC20: transfer of tokens exceeding allowance"));
return true;
}

Expand Down Expand Up @@ -132,7 +132,7 @@ contract ERC20 is IERC20 {
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue, "ERC20: decrease of higher allowance than granted"));
return true;
}

Expand All @@ -154,7 +154,7 @@ contract ERC20 is IERC20 {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");

_balances[sender] = _balances[sender].sub(amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer of tokens exceeding balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
Expand Down Expand Up @@ -190,8 +190,8 @@ contract ERC20 is IERC20 {
function _burn(address account, uint256 value) internal {
require(account != address(0), "ERC20: burn from the zero address");

_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
_totalSupply = _totalSupply.sub(value, "ERC20: burn of tokens exceeding balance");
_balances[account] = _balances[account].sub(value, "ERC20: burn of tokens exceeding balance");
emit Transfer(account, address(0), value);
}

Expand Down Expand Up @@ -224,6 +224,6 @@ contract ERC20 is IERC20 {
*/
function _burnFrom(address account, uint256 amount) internal {
_burn(account, amount);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(amount));
_approve(account, msg.sender, _allowances[account][msg.sender].sub(amount, "ERC20: burn of tokens exceeding allowance"));
}
}
2 changes: 1 addition & 1 deletion contracts/token/ERC20/SafeERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ library SafeERC20 {
}

function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 newAllowance = token.allowance(address(this), spender).sub(value);
uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decrease of higher allowance than granted");
callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}

Expand Down
8 changes: 4 additions & 4 deletions contracts/token/ERC777/ERC777.sol
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ contract ERC777 is IERC777, IERC20 {
_callTokensToSend(spender, holder, recipient, amount, "", "");

_move(spender, holder, recipient, amount, "", "");
_approve(holder, spender, _allowances[holder][spender].sub(amount));
_approve(holder, spender, _allowances[holder][spender].sub(amount, "ERC777: transfer of tokens exceeding allowance"));

_callTokensReceived(spender, holder, recipient, amount, "", "", false);

Expand Down Expand Up @@ -383,8 +383,8 @@ contract ERC777 is IERC777, IERC20 {
_callTokensToSend(operator, from, address(0), amount, data, operatorData);

// Update state variables
_totalSupply = _totalSupply.sub(amount);
_balances[from] = _balances[from].sub(amount);
_totalSupply = _totalSupply.sub(amount, "ERC777: burn of tokens exceeding balance");
_balances[from] = _balances[from].sub(amount, "ERC777: burn of tokens exceeding balance");

emit Burned(operator, from, amount, data, operatorData);
emit Transfer(from, address(0), amount);
Expand All @@ -400,7 +400,7 @@ contract ERC777 is IERC777, IERC20 {
)
private
{
_balances[from] = _balances[from].sub(amount);
_balances[from] = _balances[from].sub(amount, "ERC777: transfer of tokens exceeding balance");
_balances[to] = _balances[to].add(amount);

emit Sent(operator, from, to, amount, userData, operatorData);
Expand Down
Loading

0 comments on commit 3eec22d

Please sign in to comment.