FoundrySolidityLayer 2
7.25 ETH
Submission Details
Impact: low
Likelihood: high

Redundant timestamp clamp in `stake()` wastes gas

Author Revealed upon completion

Description

  • Under normal behavior, when a user deposits funds via stake(), the system records their entry timestamp to calculate time-weighted bonus shares. If the pool is already in an active-risk state (riskWindowStart != 0), late deposits are time-weighted from the moment of their entry.

  • In ConfidencePool.stake(), the code assigns newEntry = block.timestamp and then attempts to clamp it using if (start != 0 && newEntry < start) newEntry = start;. However, because riskWindowStart is strictly set to block.timestamp at the moment risk is first observed, and time only moves forward in the EVM, the current block.timestamp can never be less than riskWindowStart. This makes the conditional check entirely redundant dead code.

// Pre-risk deposits use wall clock and get promoted to riskWindowStart later via
// `_clampUserSums`; post-risk deposits go in at wall clock (already ≥ riskWindowStart).
uint256 newEntry = block.timestamp;
uint256 start = riskWindowStart;
// @> Dead code: newEntry (block.timestamp) can never be < start (past timestamp).
if (start != 0 && newEntry < start) newEntry = start;

Risk

Likelihood: High

  • Every single call to stake() evaluates this redundant branch.

Impact: Low

  • Stakers waste a trivial amount of gas evaluating an impossible condition.

Proof of Concept

The riskWindowStart is only ever set to block.timestamp (in _markRiskWindowStart()), meaning any subsequent transaction's block.timestamp will always be ≥ riskWindowStart. The condition newEntry < start will strictly evaluate to false.

Recommended Mitigation

Remove the redundant clamping logic to save gas and improve readability.

// Pre-risk deposits use wall clock and get promoted to riskWindowStart later via
// `_clampUserSums`; post-risk deposits go in at wall clock (already ≥ riskWindowStart).
uint256 newEntry = block.timestamp;
- uint256 start = riskWindowStart;
- if (start != 0 && newEntry < start) newEntry = start;

Support

FAQs

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

Give us feedback!