Skip to content
Business logic Audit finding Intermediate

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

  1. User locks token X as escrow which takes fee on transfer
  2. For same, he uses lock function 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
    });
...
}
  1. Since token has fee on transfer, the contract receives only amount-fees but the escrow object is created for full amount
  2. Lets say escrow duration is over and claim is made using claimRewards function
function claimRewards(bytes32[] memory escrowIds) external {
...
 uint256 claimable = _getClaimableAmount(escrow);
...
 escrow.token.safeTransfer(escrow.account, claimable);
...
}
  1. Since full duration is over, the claimable amount is amount. But this fails on transfer to account since contract has only amount-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.

RedVeil (Popcorn) confirmed


The original report as published on Code4rena, by csanuragjain. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

  1. A user locks a fee-on-transfer token as escrow using the lock function, which transfers funds from the user to the contract.
  2. The contract receives only the amount minus fees, but the escrow object is created for the full amount.
  3. After the escrow duration ends, the user calls claimRewards to claim the full amount.
  4. 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.

More by Anurag Jain

View all

63 more disclosed reports, best first.

More from Popcorn contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.