Vanguard

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

[L-02] Unused State Variables

Author Revealed upon completion

Root + Impact

Description

addressTotalSwaps and addressPenaltyCount are declared but never written to.

Location: src/TokenLaunchHook.sol:55-56

mapping(address => uint256) public addressTotalSwaps; // Never written
mapping(address => uint256) public addressPenaltyCount; // Never written

Risk

Likelihood: Always present in deployed bytecode.

Impact:

  • Wasted contract storage space

  • Misleading API for integrators

  • Dead code

Proof of Concept

function test_PoC_L02_UnusedStateVariables() public {
// Do multiple swaps
_swap(user1, 0.001 ether);
_swap(user1, 0.001 ether);
_swap(user2, 0.001 ether);
// These mappings exist but are never written to
uint256 user1TotalSwaps = hook.addressTotalSwaps(user1);
uint256 user1PenaltyCount = hook.addressPenaltyCount(user1);
uint256 routerTotalSwaps = hook.addressTotalSwaps(address(swapRouter));
uint256 routerPenaltyCount = hook.addressPenaltyCount(address(swapRouter));
// All remain at default value (0) despite swaps occurring
assertEq(user1TotalSwaps, 0, "addressTotalSwaps never written");
assertEq(user1PenaltyCount, 0, "addressPenaltyCount never written");
assertEq(routerTotalSwaps, 0, "addressTotalSwaps never written");
assertEq(routerPenaltyCount, 0, "addressPenaltyCount never written");
}

Recommendations

Either implement the tracking or remove the variables.

Support

FAQs

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

Give us feedback!