Approved spender can spend too many tokens
The approve function uses internal shares while transferFrom uses rebalanced amounts, so an approved spender can transfer more tokens than intended as the share price grows. This could let a spender exceed the allowance.
Submitted by cmichel, also found by WatchPug, jonah1005, gzeon, and TomFrench The approve function has not been overridden and therefore uses the internal shares, whereas transfer(From) uses the rebalanced amount.
Impact
The approved spender may spend more tokens than desired. In fact, the approved amount that can be transferred keeps growing with pricePerShare.
Many contracts also use the same amount for the approve call as for the amount they want to have transferred in a subsequent transferFrom call, and in this case, they approve an amount that is too large (as the approved shares amount yields a higher rebalanced amount).
Recommended Mitigation Steps
The _allowances field should track the rebalanced amounts such that the approval value does not grow. (This does not actually require overriding the approve function.) In transferFrom, the approvals should then be subtracted by the transferred amount, not the amountInShares:
// _allowances are in rebalanced amounts such that they don't grow
// need to subtract the transferred amount
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
tabshaikh (Badger) confirmed and resolved:
Fix here: https://github.com/Badger-Finance/rebasing-ibbtc/pull/7
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The approve function was not overridden and stores allowances in shares, while transferFrom deducts from allowances using the rebalanced token amount, causing the effective allowance to grow with pricePerShare.
Impact
An approved spender may transfer more tokens than the owner intended, and the excess grows as pricePerShare increases.
What the attacker needed
Token owner approves a spender; pricePerShare increases
The fix
The allowances should track rebalanced amounts, and transferFrom should subtract the transferred amount rather than the share amount; the project confirmed and resolved this.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
This is a smart contract bug where the approval amount is stored in one unit (shares) but spending is checked in another unit (tokens). Because the value of a share increases over time, the spender can end up moving more tokens than the owner approved.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.