I'm having trouble to understand where the allowance is checked in the "transferFrom" function - IMHO the allowed amount is deducted but never checked weather it is sufficient to allow the transactions - what am I getting wrong here?

function transferFrom(address from, address to, uint tokens) public returns (bool success) {

    balances[from] = balances[from].sub(tokens);

    allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);

    balances[to] = balances[to].add(tokens);

    Transfer(from, to, tokens);

    return true;

  • Where did you found this "default" implementation? It is incorrect without prerequisites require that checks for availability of amount in allowed. – Alex G.P. May 2 '18 at 5:36

Does the contract by any chance contain the line using SafeMath for uint256? SafeMath checks the output of subtraction (sub) for underflow. Inside the sub function of SafeMath, when the output becomes less than 0, it throws.

That's how the balances and allowances are checked in this contract: whenever more than their balance is being deducted, SafeMath's sub function will throw.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.