Skip to content
Audit finding Beginner

Unnecessary second hand of if check in calculaterewardswithcheckpointsview

The report points out a redundant condition in an if check inside a view function that calculates staking rewards. The extra comparison does not change behaviour, so an attacker gains nothing from it.

oxrex Follow

Originally disclosed on Immunefi

Informational View original
  • Disclosed after under an hour

51920 sc insight unnecessary second hand of if check in calculaterewardswithcheckpointsview

Submitted on Aug 6th 2025 at 15:40:27 UTC by @oxrex for Attackathon | Plume Network

Description

Brief/Intro

There is a redundant condition in the if check of the calculateRewardsWithCheckpointsView function of the PlumeRewardLogic library.

Vulnerability Details

Relevant snippet:

Solidity
function calculateRewardsWithCheckpointsView(
    PlumeStakingStorage.Layout storage $,
    address user,
    uint16 validatorId,
    address token,
    uint256 userStakedAmount
)
    internal
    view
    returns (uint256 totalUserRewardDelta, uint256 totalCommissionAmountDelta, uint256 effectiveTimeDelta)
{
    // This view function simulates what the state-changing `calculateRewardsWithCheckpoints` does.
    // It must accurately calculate the validator's theoretical cumulative reward per token at the
    // current block timestamp, respecting all historical rate changes.

    // 1. Determine the effective time range for the simulation.
    PlumeStakingStorage.ValidatorInfo storage validator = $.validators[validatorId];

    uint256 effectiveEndTime = block.timestamp;
    uint256 tokenRemovalTime = $.tokenRemovalTimestamps[token];
@>       if (tokenRemovalTime > 0 && tokenRemovalTime < effectiveEndTime) { // @audit insight
        effectiveEndTime = tokenRemovalTime;
    }
    if (validator.slashedAtTimestamp > 0 && validator.slashedAtTimestamp < effectiveEndTime) {
        effectiveEndTime = validator.slashedAtTimestamp;
    }

    ...

    // 4. Now that we have the correctly simulated final cumulative RPT, call the core logic.
    return _calculateRewardsCore($, user, validatorId, token, userStakedAmount, simulatedCumulativeRPT);
}

The second part of the if condition (&& tokenRemovalTime < effectiveEndTime) is redundant because effectiveEndTime was initialized as block.timestamp. The token removal timestamp cannot be in the future relative to block.timestamp. Therefore, checking < effectiveEndTime is unnecessary once you already check tokenRemovalTime > 0.

Suggested minimal change:

Diff
- if (tokenRemovalTime > 0 && tokenRemovalTime < effectiveEndTime) {
+ if (tokenRemovalTime > 0) {
        effectiveEndTime = tokenRemovalTime;
    }

Even if the token removal occurred in the current block, tokenRemovalTime would be equal to block.timestamp, not greater than it, so the extra comparison adds no value.

Impact Details

The && tokenRemovalTime < effectiveEndTime clause is redundant and does not alter behavior given the current initialization of effectiveEndTime. Removing it simplifies the code without changing semantics.

References

https://github.com/immunefi-team/attackathon-plume-network/blob/main/plume/src/lib/PlumeRewardLogic.sol#L884-L886

Proof of Concept

{% stepper %} {% step %}

Step

There are 2 reward tokens pUSD and PLUME {% endstep %}

{% step %}

Step

pUSD gets removed at timestamp 555 {% endstep %}

{% step %}

Step

Functions query calculateRewardsWithCheckpointsView of the PlumeRewardLogic {% endstep %}

{% step %}

Step

The function does an unnecessary second hand check in the if condition whereby it determines the effectiveEndTime that is relevant for use. But since the uint256 effectiveEndTime at the very start above the if check = block.timestamp, it will already be the most recent and cannot be lower than validator.slashedAtTimestamp in the first place {% endstep %} {% endstepper %}

The original report as published on Immunefi, by oxrex. Images and videos are our own copies; raw HTML is shown as text. View it on Immunefi.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely a redundant comparison: effectiveEndTime is initialised to block.timestamp, so tokenRemovalTime < effectiveEndTime is always true once tokenRemovalTime > 0.

Impact

No security impact; the redundant check does not alter behaviour and removing it only simplifies the code.

What the attacker needed

None

The fix

The redundant comparison should be removed so the condition only checks that the token removal timestamp is greater than zero.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

This is a code review note, not an exploitable bug. The function checks whether a token was removed before the current time, but it also compares that removal time against the current time again, which is always true. Removing the extra check makes the code shorter without changing what it does.

More by oxrex

View all

13 more disclosed reports, best first.

More from Plume Network

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.