Skip to content
Last updated: March 11, 2025

SCWE-062: Dead Code

Stable Version v0.0.1

This content is in the version-(v0.0.1) and still under active development, so it is subject to change any time (e.g. structure, IDs, content, URLs, etc.).

Send Feedback

Relationships

Description

Code with no effects or Dead Code- refers to segments of a smart contract that are never executed or do not alter the contract's state or output. This can lead to unnecessary gas consumption, complicate the contract’s logic, and potentially confuse developers. Dead code often appears as leftover code from previous iterations or functions that are no longer in use but have not been removed. Removing such code improves contract efficiency and readability.

Remediation

To mitigate this vulnerability, ensure that all functions, variables, and logic in the smart contract have a purpose and contribute to the contract’s behavior. Unused code should be removed to reduce complexity, save gas, and improve maintainability.

Vulnerable Contract Example

contract Vulnerable {
    uint public value;

    // Dead code, never called or used
    function unusedFunction() public {
        uint x = 5;
        uint y = 10;
        uint result = x + y;
    }

    function setValue(uint _value) public {
        value = _value;
    }
}

Fixed Contract Example

contract Fixed {
    uint public value;

    function setValue(uint _value) public {
        value = _value;
    }
}