Unchecked low-level call returns
A .call returns (bool ok, bytes data) and never reverts on failure — ignoring ok (or the bool from send) turns a failed transfer into a silent state divergence.
Procedure
- Find all low-level calls:
grep -nE '\.call\(|\.delegatecall\(|\.staticcall\(|\.send\(|address\(.*\)\.transfer' -r src/. - For each, require the success flag to be checked and revert:
(bool ok, bytes memory ret) = target.call(data);
require(ok, "call failed");
if (ret.length > 0) { /* decode */ }
- Replace
address(x).transfer(y)and.send(y)with.call{value: y}("")+ a success check, orpayable(x).transferonly for trusted EOAs;transfer/sendforward 2300 gas and can fail silently on contracts. - For
.delegatecall, verify the target is a trusted, immutable address — a user-supplied delegatecall target executes arbitrary code in your storage. - Check ERC-20
transfer/transferFromreturns the same way: useSafeERC20.safeTransfer(grep -c 'safeTransfer' src/should cover all token moves). - Confirm decode of returned data is length-checked:
abi.decode(ret, (uint256))reverts on a short return; a manualret.length < 32guard is explicit. - Check multicall/loop patterns: one failing leg in a
forloop must revert the whole batch, not continue. - Verify
try/catchusage:catchmust not swallow the error without state rollback where the caller assumes success. - Test the failure branch: point the call at a contract that returns
falseor reverts, and assert the tx reverts. - Re-grep after fixes:
grep -nE '\.call\(' src/should show every site with arequire(ok.
Pitfalls
token.transfer(a, b);with the return ignored — a token that returnsfalse(some proxies) leaves accounting updated but funds unmoved.require(token.transfer(...))reverting on USDT because the call has no return data; usesafeTransfer.payable(to).send(amount)returning false and the code proceeding, so the ETH stays in the contract but the ledger says paid.delegatecallin a loop over user-supplied targets — one entry canselfdestructthe implementation.try target.f() { } catch { }with an empty catch: the outer function returns success while the inner action failed.
Verification
forge test --match-test "testCallFailure|testSafeTransfer" -vvvv
Pass: pointing the call at a failing target reverts the whole transaction, and grep -nE '\.(call|send)\(' src/ shows no site lacking a success check.
Report each low-level call, whether the return is checked, and the delegatecall target trust level.