Vanguard

First Flight #56
Beginner FriendlyDeFiFoundry
0 EXP
Submission Details
Impact: low
Likelihood: high

lastPhaseUpdateBlock State Variable Written But Never Read - Dead State

Author Revealed upon completion

Root + Impact

Description

Normal Behavior: State variables should be both written and read to serve a purpose in the contract logic.

Issue: The state variable lastPhaseUpdateBlock is written to in two places but is NEVER read anywhere in the contract:

// Written in _afterInitialize:
lastPhaseUpdateBlock = block.number;
// Written in _beforeSwap during phase transitions:
if (newPhase != currentPhase) {
_resetPerAddressTracking();
currentPhase = newPhase;
lastPhaseUpdateBlock = block.number; // @> Written but never read
}

The variable is never used in any condition, calculation, or view function. This indicates either:

  1. Incomplete implementation of planned functionality

  2. Abandoned feature that was never cleaned up

  3. Potential logic that should exist but is missing

Root Cause: State variable declared and written but never read:

uint256 public lastPhaseUpdateBlock; // Declared
// ... never used in any read operation

Impact:

  • Wasted gas on every phase transition (SSTORE costs ~20,000 gas)

  • Suggests incomplete implementation - may indicate missing time-based phase enforcement logic

  • Code quality issue that could mask intended but missing functionality

  • Makes the contract harder to audit due to dead code

Proof of Concept

// Search the entire contract for reads of lastPhaseUpdateBlock:
// 1. grep "lastPhaseUpdateBlock" src/TokenLaunchHook.sol
//
// Results show ONLY writes:
// - Line 51: uint256 public lastPhaseUpdateBlock; (declaration)
// - Line 80: lastPhaseUpdateBlock = block.number; (write in _afterInitialize)
// - Line 108: lastPhaseUpdateBlock = block.number; (write in _beforeSwap)
//
// NO reads found - variable is completely unused after being written

Recommended Mitigation

Either remove the unused variable or implement the intended functionality:

// Option 1: Remove if not needed
- uint256 public lastPhaseUpdateBlock;
- lastPhaseUpdateBlock = block.number;
// Option 2: Use it for intended purpose (e.g., minimum phase duration)
+ require(block.number >= lastPhaseUpdateBlock + MIN_PHASE_BLOCKS, "Phase too short");

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.

Give us feedback!