Use safeTransfer instead of transfer
The contract calls transfer() on an ERC20 token without checking the boolean return value. For tokens that return false instead of reverting on failure, the contract treats the transfer as successful, which could lead to permanent loss of funds.
- Disclosed after under an hour
29322 - [SC - Insight] Use safeTransfer instead of transfer
Submitted on Mar 14th 2024 at 00:40:23 UTC by @bugtester for Boost | ZeroLend
Report ID: #29322
Report type: Smart Contract
Report severity: Insight
Target: https://github.com/zerolend/governance
Impacts:
- Permanent freezing of funds
Description
Brief/Intro
transfer() might return false instead of reverting, in this case, ignoring return value leads to considering it successful.
use safeTransfer() or check the return value if length of returned data is > 0.
Vulnerability Details
A call to transferFrom or transfer is frequently done without checking the results. For certain ERC20 tokens, if insufficient tokens are present, no revert occurs but a result of "false" is returned. So its important to check this. in case, ignoring return value leads to considering it successful. and loss of funds
Impact Details
transfer() might return false instead of reverting, in this case, ignoring return value leads to considering it successful. and cause permanent loss of funds
Fix
Use safeTransfer instead of transfer
Proof of concept
function claimUnvested(uint256 tokenId) external { require(msg.sender == stakingBonus, "!stakingBonus"); uint256 _pending = unclaimed(tokenId); zero.transfer(msg.sender, _pending); }
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 ignores the boolean return value of the ERC20 transfer call.
Impact
For tokens that return false on failure, the contract may consider a failed transfer successful, which could cause permanent loss of funds.
What the attacker needed
Token returns false instead of reverting
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 signal a failed transfer by returning false rather than stopping with an error. If the contract ignores that false value, it thinks the money moved when it did not, so funds can be lost. The fix is to use a helper that checks the result.
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.