Rules › Solidity
ecrecover result not checked for address(0)
ecrecover returns the zero address for invalid signatures; comparing it to an unset signer accepts garbage.
Why it matters
ecrecover returns address(0) for an invalid signature instead of reverting. If the expected signer is unset (also address(0)), any garbage signature passes. Raw ecrecover also accepts malleable signatures (two valid s values), which matters if signatures are used as identifiers. OpenZeppelin's ECDSA.recover rejects both.
Vulnerable
function verify(bytes32 h, uint8 v, bytes32 r, bytes32 s) public view returns (bool) {
return ecrecover(h, v, r, s) == signer;
}
Fixed
function verify(bytes32 digest, bytes calldata sig) public view returns (bool) {
(address recovered, ECDSA.RecoverError err, ) = ECDSA.tryRecover(digest, sig);
return err == ECDSA.RecoverError.NoError && recovered == signer && signer != address(0);
}
What other tools call it
| Tool | Detector or reference |
|---|---|
| Aderyn | ecrecover |
| SWC registry | SWC-117, SWC-122 |
Check your code
Paste a contract into the in-browser checker, or let the Claude Code plugin scan before every deploy. The quick check for this rule is a pattern match: treat a hit as "look here", and a miss as no guarantee.
Related rules
- tx.origin used for authorization
- State written after an external call (reentrancy)
- Return value of a low-level call is ignored
- delegatecall to an address the caller controls
- Initializer anyone can call
- Privileged function without access control
Static analysis finds known bug classes; it can't prove code is safe and isn't an audit. Get a professional audit before deploying code that will hold value.