Skip to content
Business logic Audit finding Intermediate

Fee on transfer tokens can lead to incorrect approval

The createBasket function approves a basket contract for the full requested token amount after a transferFrom, but fee-on-transfer tokens deliver less than that amount, so the approval exceeds the actual balance received. This can cause accounting errors or grief the protocol when such tokens are used.

hrkrshnn Follow

Originally disclosed on Code4rena

Submitted by hrkrshnn, also found by itsmeSTYJ

Fee on transfer tokens can lead to incorrect approval

The createBasket function does not account for tokens with fee on transfer.

function createBasket(uint256 idNumber) external override returns (IBasket) {
    // ...
    for (uint256 i = 0; i < bProposal.weights.length; i++) {
        IERC20 token = IERC20(bProposal.tokens[i]);
        token.safeTransferFrom(msg.sender, address(this), bProposal.weights[i]);
        token.safeApprove(address(newBasket), bProposal.weights[i]);
    }
    // ...
}

The function safeTransferFrom may not transfer exactly bProposal.weights[i] amount of tokens, for tokens with a fee on transfer. This means that the safeApprove call in the next line would be approving more tokens than what was received, leading to accounting issues.

Recommended Mitigation Steps

It is recommended to find the balance of the current contract before and after the transferFrom to see how much tokens were received, and approve only what was received.

frank-beard (Kuiper) confirmed:

the protocol for now is only expected to work with defi safe, standard erc-20 tokens.

Alex the Entreprenerd (judge) commented:

This finding is similar to #206 , but in contrast to it, it shows a specific way to brick / grief the protocol, as per the docs:

2 — Med: Assets not at direct risk, but the function of the protocol or its availability could be impacted, or leak value with a hypothetical attack path with stated assumptions, but external requirements.

This is an hypothetical attack with stated assumptions

Will not mark as duplicate and will consider this as a valid finding as it shows a specific vulnerability when paired with feeOnTransfer tokens

Mitigation can be as simple as never using feeOnTransfer tokens

The original report as published on Code4rena, by hrkrshnn. 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

Likely the code assumes transferFrom always delivers exactly the requested amount and approves that same amount without measuring the actual received balance.

Impact

The protocol's accounting could be wrong and its function or availability could be impacted, though the team states it only intends to support standard ERC-20 tokens.

What the attacker needed

Fee-on-transfer token used; protocol accepts such tokens

The fix

The contract should measure its token balance before and after the transfer and approve only the amount actually received.

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 when they are sent, so the receiver gets less than the sender asked to send. This code approves spending based on the amount requested rather than the amount that actually arrived, so the approval can be larger than the tokens the contract holds. That mismatch can break the protocol's accounting.

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 hrkrshnn

View all

2 more disclosed reports, best first.

More from Kuiper 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.