Use safeTransfer/safeTransferFrom consistently instead of transfer/transferFrom
The contract uses transfer/transferFrom without checking the return value, so tokens that return false on failure (like ZRX) can cause silent failures. In the clear function, a lender could clear a request without providing any debt tokens if the debt token is ZRX.
tsvetanovv Follow with 0x52, polthedev and 47 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-01-cooler-judging/issues/335
Found by
tsvetanovv, 0x52, polthedev, wagmi, enckrish, ak1, IllIllI, yongkiws, ctrlc03, zaskoh, Trumpero, TrungOre, Breeje, imare, jonatascm, cccz, Metadev, Nyx, neumo, Atarpara, serial-coder, yixxas, Tricko, 8olidity, Qeew, ahmedovv, libratus, usmannk, MohanVarma, psy4n0n, 0x4non, kiki_dev, peanuts, 0xhacksmithh, eyexploit, 0xSmartContract, supernova, Zarf, thekmj, ltyu, ck, sach1r0, hansfriese, John, HollaDieWaldfee, HonorLt, rvierdiiev, zaevlad, 0xAgro, Avci, gjaldon, Madalad, ch0bu, bin2chen, Bahurum, seyni, 0xadrii, Deivitto
Summary
Use safeTransfer/safeTransferFrom consistently instead of transfer/transferFrom
Vulnerability Detail
Some tokens do not revert on failure, but instead return false (e.g. ZRX). https://github.com/d-xo/weird-erc20/#no-revert-on-failure tranfser/transferfrom is directly used to send tokens in many places in the contract and the return value is not checked. If the token send fails, it will cause a lot of serious problems. For example, in the clear function, if debt token is ZRX, the lender can clear request without providing any debt token.
function clear (uint256 reqID) external returns (uint256 loanID) {
Request storage req = requests[reqID];
factory.newEvent(reqID, CoolerFactory.Events.Clear);
if (!req.active)
revert Deactivated();
else req.active = false;
uint256 interest = interestFor(req.amount, req.interest, req.duration);
uint256 collat = collateralFor(req.amount, req.loanToCollateral);
uint256 expiration = block.timestamp + req.duration;
loanID = loans.length;
loans.push(
Loan(req, req.amount + interest, collat, expiration, true, msg.sender)
);
debt.transferFrom(msg.sender, owner, req.amount);
}
Impact
If the token send fails, it will cause a lot of serious problems. For example, in the clear function, if debt token is ZRX, the lender can clear request without providing any debt token.
Code Snippet
https://github.com/sherlock-audit/2023-01-cooler/blob/main/src/Cooler.sol#L85-L86 https://github.com/sherlock-audit/2023-01-cooler/blob/main/src/Cooler.sol#L122-L123 https://github.com/sherlock-audit/2023-01-cooler/blob/main/src/Cooler.sol#L146-L147 https://github.com/sherlock-audit/2023-01-cooler/blob/main/src/Cooler.sol#L179-L180 https://github.com/sherlock-audit/2023-01-cooler/blob/main/src/Cooler.sol#L205-L206 https://github.com/sherlock-audit/2023-01-cooler/blob/main/src/Cooler.sol#L102-L103
Tool used
Manual Review
Recommendation
Consider using safeTransfer/safeTransferFrom consistently.
Discussion
hrishibhat
Sponsor comment:
Good spot. Niche case.
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 contract uses transfer/transferFrom without checking the boolean return value, so tokens that return false on failure do not revert.
Impact
If the token send fails, it could cause serious problems, such as a lender clearing a request without providing debt tokens when the debt token is ZRX.
What the attacker needed
Debt token is ZRX or similar; lender calls clear function
The fix
The recommendation is to use safeTransfer/safeTransferFrom consistently.
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 don't stop the program when a transfer fails; they just return false. The contract ignores that false, so it thinks the transfer worked when it didn't. This lets someone complete an action without actually sending the tokens.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.