In a standard ERC20 token, the transferFrom function allows an approved spender to transfer tokens on behalf of the token owner. The allowance should only be decremented when the token transfer is successfully completed.
The transferFrom function calls _spendAllowance before _transfer, which means the allowance is decremented before verifying the transfer succeeds. When _transfer returns false without reverting, the transaction completes but no tokens are moved, yet the allowance is permanently reduced.
A DEX or smart contract calls transferFrom to execute a swap on behalf of a user who has granted an allowance.
User must re-approve: Requires a new transaction and gas costs to restore the allowance
Protocol integration breaks: Any protocol relying on transferFrom may enter inconsistent states
The recipient contract has hooks that reject incoming transfers, causing _transfer to return false without reverting.
The spender's allowance is permanently reduced to zero even though no tokens were transferred.
The DEX can no longer pull the approved funds, locking the user's intended operation until a new manual approval is granted.
when we run the etst we have
}
Move _spendAllowance after _transfer to ensure allowance is only consumed on successful transfers:
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.
The contest is complete and the rewards are being distributed.