Incompatability with deflationary / fee-on-transfer tokens
The vault recorded the nominal amount of an incoming ERC20 transfer rather than the amount actually received, so with fee-on-transfer tokens the ledger overstated balances. A user withdrawing could drain more than their real share, leaving later users unable to withdraw.
Lambda Follow with cccz, hansfriese and 12 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2022-09-harpie-judging/tree/main/005-M
Found by
Lambda, cccz, hansfriese, IEatBabyCarrots, rbserver, JohnSmith, minhquanym, Tomo, leastwood, dipp, defsec, HonorLt, IllIllI, saian, csanuragjain
Summary
In case ERC20 token is fee-on-transfer, Vault can loss funds when users withdraw
Vulnerability Detail
In Transfer.transferERC20() function, this function called logIncomingERC20() with the exact amount used when it called safeTransferFrom(). In case ERC20 token is fee-on-transfer, the actual amount that Vault received may be less than the amount is recorded in logIncomingERC20().
The result is when a user withdraws his funds from Vault, Vault can be lost and it may make unable for later users to withdraw their funds.
Proof of Concept
Consider the scenario
- Token X is fee-on-transfer and it took 10% for each transfer. Alice has 1000 token X and Bob has 2000 token X
- Assume that both Alice and Bob are attacked. Harpie transfers all token of Alice and Bob to Vault. It recorded that the amount stored for token X of Alice is 1000 and Bob is 2000. But since token X has 10% fee, Vault only receives 2700 token X.
- Now Bob withdraw his funds back. With
amountStored = 2000, he will transfer 2000 token X out of the Vault and received 1800. - Now the Vault only has 700 token X left and obviously it's unable for Alice to withdraw
Tool used
Manual Review
Recommendation
Consider calculating the actual amount Vault received to call logIncomingERC20()
Transfer the tokens first and compare pre-/after token balances to compute the actual transferred amount.
Harpie Team
Using difference in balance in vault rather than token transfer amount. Fix here.
Lead Senior Watson
While it's true the fix does allow for compatabiliy with fee-on-transfer tokens, it does not correctly handle rebasing tokens. Might be useful to explicily note that rebasing tokens are not supported or instead you could adopt mint shares to represent the ownership over the vault's tokens.
Harpie Team
On rebasing tokens, we just won't be able to support them for now.
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 code logged the requested transfer amount instead of measuring the vault's balance change, so it never accounted for tokens that deduct a fee in transit.
Impact
The vault could lose funds and later users may be unable to withdraw; the team fixed the fee-on-transfer case, but rebasing tokens remain unsupported.
What the attacker needed
Vault holds a fee-on-transfer token; attacker deposits such a token; another user also deposits
The fix
The team changed the code to record the vault's balance difference instead of the transfer amount, which was fixed, though rebasing tokens are still not supported.
How it was found
- A fee-on-transfer token is used, taking a cut on each transfer.
- The vault receives the attacker's tokens and records the full nominal amount for each user.
- The vault holds less than the recorded total because of the transfer fees.
- One user withdraws their recorded amount, receiving less after fees but removing too much from the vault.
- The remaining balance is too small for the other user to withdraw.
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.
Some tokens take a small cut every time they move between wallets, so the receiver gets less than the sender sent. This vault wrote down the full sent amount as if it had all arrived, so the numbers no longer matched the real coins held. When one person withdrew, they took more than their fair share and the last person could not get their money back.
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.