NoYield.sol Tokens with fee on transfer are not supported
The contract assumes the full transfer amount is received when locking tokens, but fee-on-transfer tokens reduce the actual amount. Later users may be unable to withdraw their tokens because the contract's balance is insufficient.
Submitted by WatchPug
There are ERC20 tokens that charge fee for every transfer() or transferFrom().
In the current implementation, NoYield.sol#lockTokens() assumes that the received amount is the same as the transfer amount, and uses it to calculate sharesReceived amounts.
As a result, in unlockTokens(), later users may not be able to successfully withdraw their tokens, as it may revert at L141 for insufficient balance.
function lockTokens(
address user,
address asset,
uint256 amount
) external payable override onlySavingsAccount nonReentrant returns (uint256 sharesReceived) {
require(amount != 0, 'Invest: amount');
if (asset != address(0)) {
IERC20(asset).safeTransferFrom(user, address(this), amount);
} else {
require(msg.value == amount, 'Invest: ETH amount');
}
sharesReceived = amount;
emit LockedTokens(user, asset, sharesReceived);
}
function _unlockTokens(address asset, uint256 amount) internal returns (uint256 received) {
require(amount != 0, 'Invest: amount');
received = amount;
if (asset == address(0)) {
(bool success, ) = savingsAccount.call{value: received}('');
require(success, 'Transfer failed');
} else {
IERC20(asset).safeTransfer(savingsAccount, received);
}
emit UnlockedTokens(asset, received);
}
Recommendation
Consider comparing before and after balance to get the actual transferred amount.
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 uses the transfer amount to calculate shares instead of checking the actual balance change, so it overstates received tokens for fee-on-transfer tokens.
What the attacker needed
Fee-on-transfer token used
The fix
The contract should compare the balance before and after the transfer to get the actual received amount.
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 when transferred, so the receiver gets less than the sender sent. The contract here records the full amount as received, which means it thinks it has more tokens than it actually does. When users later try to withdraw, the contract may not have enough tokens to pay them.
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.