Merge pull request #219 from TokenMarketNet/feat/approve-mitigation

approve() race condition mitigation
pull/223/head
Manuel Aráoz 8 years ago committed by GitHub
commit 5c491987f3
  1. 7
      contracts/token/StandardToken.sol

@ -29,6 +29,13 @@ contract StandardToken is BasicToken, ERC20 {
} }
function approve(address _spender, uint _value) { function approve(address _spender, uint _value) {
// To change the approve amount you first have to reduce the addresses`
// allowance to zero by calling `approve(_spender, 0)` if it is not
// already 0 to mitigate the race condition described here:
// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
if ((_value != 0) && (allowed[msg.sender][_spender] != 0)) throw;
allowed[msg.sender][_spender] = _value; allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value); Approval(msg.sender, _spender, _value);
} }

Loading…
Cancel
Save