What is static analysis in smart contracts?
Static analysis is checking contract code for problems without running it. An analyzer turns the Solidity or bytecode into structures such as syntax trees and control flow graphs and matches them against known bug patterns (ethereum.org), which makes it fast enough to run on every commit.
What does static analysis catch?
It catches patterns visible in the code itself, such as authorization through tx.origin, unchecked return values of low-level calls, state written after an external call and shadowed variables. The contract below is a textbook case. The Solidity docs say never to use tx.origin for authorization, because a malicious contract the owner calls can relay the call with the owner as origin (Solidity docs).
Authorization through tx.origin, a pattern analyzers flag (illustrative, not audited code) OriginWallet.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
contract OriginWallet {
address public immutable owner;
constructor() {
owner = msg.sender;
}
// tx.origin is the account that started the transaction, not the caller.
// If the owner calls a malicious contract, that contract can call this and pass.
function withdraw(address payable to, uint256 amount) external {
require(tx.origin == owner, "not owner");
to.transfer(amount);
}
receive() external payable {}
}
What does static analysis miss?
It misses anything that depends on what the code is meant to do. An analyzer can see that a function lacks a check, but not that a fee formula is wrong, that a price can be pushed with a flash loan, or that two contracts round in opposite directions. It also raises findings that turn out to be harmless, which someone has to triage.
| Aspect | Static analysis | Dynamic analysis |
|---|---|---|
| How | Reads the structure of the code | Runs the code with inputs |
| Finds | Known patterns, anywhere in the code | Property violations on real executions |
| Misses | Logic and economic bugs | Paths its inputs never reach |
ethereum.org suggests running tools such as Slither and Mythril before merging pull requests (ethereum.org). QuillShield vs Slither compares a static analyzer with an AI audit, and Aderyn alternatives lists replacements, since Cyfrin retired Aderyn in November 2026.
Sources
- Smart contract security, ethereum.org checked 3 December 2026
- Security considerations, Solidity documentation checked 3 December 2026