Fee-on-transfer token donations in Shelter break withdrawals
The donate function credits the full transfer amount to savedTokens even for fee-on-transfer tokens, so the contract's recorded balance exceeds its actual token balance. The last person to withdraw cannot claim their share because the calculated amount exceeds the available balance.
Submitted by cmichel, also found by Dravee, IllIllI, and Ruhum
The Sheler.donate function transferFroms _amount and adds the entire _amount to savedTokens[_token].
But the actual received token amount from the transfer can be less for fee-on-transfer tokens.
The last person to withdraw will not be able to as withdraw uses a share computation for the entire savedTokens[_token] amount.
The calculated amount will then be higher than the actual contract balance.
function donate(IERC20 _token, uint256 _amount) external {
require(activated[_token] != 0, "!activated");
savedTokens[_token] += _amount;
// @audit fee-on-transfer. then fails for last person in `withdraw`
_token.safeTransferFrom(msg.sender, address(this), _amount);
}
function withdraw(IERC20 _token, address _to) external override {
// @audit percentage on storage var, not on actual balance
uint256 amount = savedTokens[_token] * client.shareOf(_token, msg.sender) / client.totalShare(_token);
// @audit amount might not be in contract anymore as savedTokens[_token] is over-reported
_token.safeTransfer(_to, amount);
}
Recommended Mitigation Steps
In donate, add only the actual transferred amounts (computed by post-transfer balance - pre-transfer balance) to savedTokens[_token].
Alex the Entreprenerd (judge) commented:
The warden has identified a specific interaction between a
feeOnTransfertoken and the Shelter Contract.Because the Shelter Contract can receive any token, and anyone could claim them based on percentage, and because some people will lose the ability to claim due to the internal accounting being incorrect, I believe that in this instance the finding is valid, and of medium severity.
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 donate function adds the nominal transfer amount to savedTokens instead of the actual received amount, which is lower for fee-on-transfer tokens.
What the attacker needed
Fee-on-transfer token; donation via donate function; multiple users withdraw
The fix
The donate function should add only the actual transferred amount, calculated as the post-transfer balance minus the pre-transfer balance, to savedTokens.
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 records the full amount as if no fee was taken, so its internal balance is too high. When the last person tries to withdraw, there is not enough real token left 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.