51920 sc insight unnecessary second hand of if check in calculaterewardswithcheckpointsview
Description
Brief/Intro
Vulnerability Details
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);
}Impact Details
References
Proof of Concept
Previous50973 sc insight incorrect parameter type in setjackpotprobabilitiesNext52446 sc low withdrawing unsold tokens desynchronizes sale accounting
Was this helpful?