0

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;

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

1 Answer 1

4

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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