Fee on transfer token not supported
The escrow contract records the full requested amount when a fee-on-transfer token is locked, but it actually receives less because the token deducts a fee. When the user later claims, the transfer fails due to insufficient funds, and one user may unknowingly take the missing fees from another user's escrow.
Anurag Jain Follow with rbserver, 0xSmartContract and 16 others
Originally disclosed on Code4rena
Submitted by csanuragjain, also found by rbserver, 0xSmartContract, btk, joestakey, Josiah, Viktor_Cortess, rvi0x, RaymondFam, Deivitto, KIntern_NA, 0xNazgul, 0xdeadbeef0x, koxuan, 0xNineDec, pavankv, Rolezn, Bauer, and UdarTeam
If you are making a Lock fund for escrow using a fee on transfer token then contract will receive less amount (X-fees) but will record full amount (X). This becomes a problem as when claim is made then call will fail due to lack of funds. Worse, one user will unknowingly take the missing fees part from another user deposited escrow fund.
Proof of Concept
- User locks token X as escrow which takes fee on transfer
- For same, he uses
lockfunction which transfers funds from user to contract
function lock(
IERC20 token,
address account,
uint256 amount,
uint32 duration,
uint32 offset
) external {
...
token.safeTransferFrom(msg.sender, address(this), amount);
...
escrows[id] = Escrow({
token: token,
start: start,
end: start + duration,
lastUpdateTime: start,
initialBalance: amount,
balance: amount,
account: account
});
...
}
- Since token has fee on transfer, the contract receives only
amount-feesbut the escrow object is created for fullamount - Lets say escrow duration is over and claim is made using
claimRewardsfunction
function claimRewards(bytes32[] memory escrowIds) external {
...
uint256 claimable = _getClaimableAmount(escrow);
...
escrow.token.safeTransfer(escrow.account, claimable);
...
}
- Since full duration is over, the claimable amount is
amount. But this fails on transfer to account since contract has onlyamount-fees
Recommended Mitigation Steps
Compute the balance before and after transfer and subtract them to get the real amount. Also use nonReentrant while using this to prevent from reentrancy in ERC777 tokens.
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 contract records the requested transfer amount as the escrow balance without checking the actual balance change, so fee-on-transfer tokens leave the recorded balance higher than the real holdings.
Impact
Claims could fail due to insufficient funds, and one user could unknowingly take the missing fees from another user's deposited escrow fund.
What the attacker needed
A fee-on-transfer token is used; user locks funds via the lock function; escrow duration ends and claim is made
The fix
The contract should compute the balance before and after the transfer and use the difference as the real amount, and use a nonReentrant modifier to prevent reentrancy with ERC777 tokens.
How it was found
- A user locks a fee-on-transfer token as escrow using the lock function, which transfers funds from the user to the contract.
- The contract receives only the amount minus fees, but the escrow object is created for the full amount.
- After the escrow duration ends, the user calls claimRewards to claim the full amount.
- The claim fails because the contract holds only the amount minus fees, and one user may take the missing fees from another user's escrow.
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 fee each time they are transferred, so the receiver gets less than the sender sent. This contract assumed the full amount arrived and wrote that full amount into its records. Later, when paying out, it did not have enough tokens, so the payment failed and could even dip into other users' funds.
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.