Skip to content

Commit 1df75a9

Browse files
committed
Merge pull request #446 from jakub-wojciechowski/master
Make approve method compliant with ERC20
2 parents e906885 + adfd8fb commit 1df75a9

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

contracts/token/StandardToken.sol

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,15 @@ contract StandardToken is ERC20, BasicToken {
4040

4141
/**
4242
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
43+
*
44+
* Beware that changing an allowance with this method brings the risk that someone may use both the old
45+
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
46+
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
47+
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
4348
* @param _spender The address which will spend the funds.
4449
* @param _value The amount of tokens to be spent.
4550
*/
4651
function approve(address _spender, uint256 _value) public returns (bool) {
47-
48-
// To change the approve amount you first have to reduce the addresses`
49-
// allowance to zero by calling `approve(_spender, 0)` if it is not
50-
// already 0 to mitigate the race condition described here:
51-
// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
52-
// require((_value == 0) || (allowed[msg.sender][_spender] == 0));
53-
5452
allowed[msg.sender][_spender] = _value;
5553
Approval(msg.sender, _spender, _value);
5654
return true;

0 commit comments

Comments
 (0)