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.
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.
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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
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.