feat(scanner): add unchecked-return value detection plugin - #107
Open
TaiYang-cs wants to merge 1 commit into
Open
feat(scanner): add unchecked-return value detection plugin#107TaiYang-cs wants to merge 1 commit into
TaiYang-cs wants to merge 1 commit into
Conversation
Implements the unchecked-return scanner plugin (SWC-104) that detects low-level calls (.call/.send/.delegatecall/.staticcall) and ERC-20 transfers whose boolean return value is discarded. - Add plugins/unchecked-return with IRulePlugin implementation and 31 tests - Register the plugin in scanner-core via a lazy built-in plugin loader - Declare the new workspace package in scanner-core deps and pnpm-lock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #16
What this adds
A new scanner plugin,
unchecked-return, that catches the class of bug behindSWC-104: a call that reports failure by returning
falseinstead of reverting,where the return value is then thrown away.
That failure mode is quiet and expensive.
address.send()andaddress.call()do not revert when the callee fails — they hand back a boolean. If nobody checks
it, a payout that never happened looks exactly like one that did, and the books
drift with no transaction to point at. The same applies to ERC-20
transfer/transferFrom/approve, where returning a boolean is part of theinterface but plenty of tokens return
falserather than reverting.How it decides
For every call site the plugin asks one question: is the returned boolean
actually consumed?
.call,.send,.delegatecall,.staticcall) arereported as
HIGHwith 0.9 confidence when the result is not wrapped inrequire/assert/if/while/for, not returned to the caller, andnot assigned to a variable that is verified later.
MEDIUMwith 0.65 confidence. That family isheuristic by nature, so it does not pretend to the same certainty.
Detection runs against a copy of the source in which comments and string
literals are blanked out while character offsets are preserved. Line numbers stay
exact, and commented-out code or
"to.call(...)"inside a string can neverproduce a finding. Multi-line statements and expression receivers such as
IERC20(token).transfer(...)are handled, not just plaintoken.transfer(...).Two decisions worth flagging
.transfer()is ambiguous, so it is disambiguated by argument count.payable(x).transfer(1 ether)is a native ETH transfer and reverts on failure —flagging it would be a false positive.
token.transfer(to, amount)returns aboolean that is routinely ignored. Rather than guess from the receiver's name,
the plugin counts arguments: one means native and is skipped, two means ERC-20
and is checked.
SafeERC20'ssafe*helpers never match at all.Built-in plugins are loaded dynamically rather than imported. A static import
in
plugin-registry.tswould pullplugins/unchecked-return/src/index.tsintoscanner-core's compilation, which fails underrootDir: ./src(TS6059) — and itwould contradict the note in
ARCHITECTURE.mdthat scanner-core has zeroknowledge of individual plugins. So
BUILTIN_PLUGIN_SPECIFIERSmaps plugin idsto module specifiers,
loadBuiltinPlugins()imports each one and instantiateswhatever satisfies
IRulePlugin, andregisterBuiltins()registers them. Aplugin package that cannot be resolved is logged and skipped instead of throwing,
so the registry stays usable in a partial install.
Verification
31 tests cover the plugin — positive, negative and edge cases — plus 7 for the
registry.
tsc --noEmit,eslint --max-warnings 0andprettier --checkareall clean.