Description
uint256 public totalPenaltyFeesCollected;
mapping(address => uint256) public addressTotalSwaps;
mapping(address => uint256) public addressPenaltyCount;
Risk
Likelihood:
Impact:
-
Extra gas cost for storage slot initialization (cold storage access)
-
Misleading public interface - external parties may expect these to contain data
-
Code suggests penalty tracking exists when it doesn't
-
Potential confusion in audits and integrations
Proof of Concept
Execute 5 penalty-triggering swaps - all tracking variables remain 0.
function test_UnusedStateVariables() public {
assertEq(antiBotHook.totalPenaltyFeesCollected(), 0, "Always 0");
vm.deal(bot1, 10 ether);
vm.startPrank(bot1);
SwapParams memory params = SwapParams({
zeroForOne: true,
amountSpecified: -int256(0.001 ether),
sqrtPriceLimitX96: TickMath.MIN_SQRT_PRICE + 1
});
PoolSwapTest.TestSettings memory testSettings =
PoolSwapTest.TestSettings({takeClaims: false, settleUsingBurn: false});
for (uint i = 0; i < 5; i++) {
swapRouter.swap{value: 0.001 ether}(key, params, testSettings, ZERO_BYTES);
}
vm.stopPrank();
assertEq(antiBotHook.totalPenaltyFeesCollected(), 0, "Still 0 after penalties");
assertEq(antiBotHook.addressTotalSwaps(address(swapRouter)), 0, "Never tracked");
assertEq(antiBotHook.addressPenaltyCount(address(swapRouter)), 0, "Never tracked");
}
Recommended Mitigation
Remove unused variables or implement actual tracking.
Option 1: Remove unused variables
- uint256 public totalPenaltyFeesCollected;
- mapping(address => uint256) public addressTotalSwaps;
- mapping(address => uint256) public addressPenaltyCount;
Option 2: Implement the tracking (if intended)
function _beforeSwap(...) internal override returns (...) {
// ... existing logic ...
+ addressTotalSwaps[sender] += 1;
if (applyPenalty) {
feeOverride = uint24((phasePenaltyBps * 100));
+ addressPenaltyCount[sender] += 1;
+ // Note: tracking actual fee amount collected would require afterSwap hook
}
// ...
}