Unused Variables
Detects state variables and local variables that are declared but never read, indicating dead state or incomplete logic.
Unused Variables
Overview
The unused variables detector identifies state variables that are written but never read, and local variables assigned but never consumed. Unused state variables waste storage gas on writes. Unused local variables may indicate logic errors where a computed value was intended to be used in a condition or return statement.
Detection Methodology
- Write tracking: Identifies all SSTORE operations (state) and MSTORE operations (local).
- Read tracking: Identifies all SLOAD and MLOAD operations.
- Cross-reference: Reports variables that are written but never read anywhere in the contract.
Examples
Sample Sigvex Output
{
"detector_id": "unused-variables",
"severity": "low",
"confidence": 0.88,
"description": "Storage slot 5 is written in function setConfig() but never read by any function. This wastes gas on every write and may indicate missing validation logic.",
"location": { "function": "setConfig(uint256)", "offset": 36 }
}
Related Detectors
- Dead Code — unreachable code
- Gas Optimization — gas waste