Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Approved spender can spend too many tokens #43

Open
code423n4 opened this issue Oct 30, 2021 · 2 comments
Open

Approved spender can spend too many tokens #43

code423n4 opened this issue Oct 30, 2021 · 2 comments
Labels
3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")

Comments

@code423n4
Copy link
Contributor

Handle

cmichel

Vulnerability details

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"));
@code423n4 code423n4 added 3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working labels Oct 30, 2021
code423n4 added a commit that referenced this issue Oct 30, 2021
@tabshaikh tabshaikh added the sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") label Nov 2, 2021
@tabshaikh
Copy link
Collaborator

will fix

@tabshaikh
Copy link
Collaborator

Fix here: Badger-Finance/rebasing-ibbtc#7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Projects
None yet
Development

No branches or pull requests

3 participants