Unstaking before reward token removal leads to incorrect reward accrual on re addition
A user who fully unstakes before a reward token is removed and later restakes after removal keeps stale reward pointers for that token. If the token is re-added, the user can claim rewards for a period when they had no stake, inflating their payout.
Plume Network
Originally disclosed on Immunefi
52084 sc high unstaking before reward token removal leads to incorrect reward accrual on re addition
- Report ID: #52084
- Report Type: Smart Contract
- Report severity: High
- Target: https://github.com/immunefi-team/attackathon-plume-network/blob/main/plume/src/facets/StakingFacet.sol
- Impacts:
- Theft of unclaimed yield
- Protocol insolvency
- Submitted on Aug 7th 2025 at 19:59:16 UTC by @light279 for Attackathon | Plume Network (https://immunefi.com/audit-competition/plume-network-attackathon)
#52084 [SC-High] Unstaking Before Reward Token Removal Leads to Incorrect Reward Accrual on Re-addition
Description
Brief / Intro
In the Plume staking system, if a user fully unstakes from a validator before a reward token is removed and later restakes after the token has been removed, user reward pointers are not correctly reinitialized for that historical token. If the removed token is re-added later, the stale user reward pointers cause rewards from the period when the user had no stake to be included in their claim, resulting in incorrect and inflated reward claims.
Vulnerability Details
When a user calls StakingFacet::unstake, the system updates their reward data via PlumeRewardLogic.updateRewardsForValidator, setting:
- $.userValidatorRewardPerTokenPaid
- $.userValidatorRewardPerTokenPaidTimestamp
for all historical reward tokens (including those active at the time of unstake, T1). If a reward token is removed at T2, it is removed from the rewardTokens array but user metadata for that token is preserved (no deletion). When the user restakes at T3, _initializeRewardStateForNewStake() iterates only over the current rewardTokens array and does not initialize state for removed (historical) tokens. Thus the user's stored pointers for the removed token remain those set at T1.
If the token is re-added at T4 and the user later claims at T5, reward calculation uses the stale pointers (from T1) and includes rewards accrued from T1→T2, during which the user had no stake.
Functional call flow for claiming (simplified): RewardsFacet::claim(token,validatorId) => RewardsFacet::_processValidatorRewards(user, validatorId) => PlumeRewardLogic.updateRewardsForValidatorAndToken($, user, validatorId, token) => calculateRewardsWithCheckpoints(...) => _calculateRewardsCore(...)
Excerpt from _calculateRewardsCore(...) showing use of stale user pointers:
function _calculateRewardsCore(
PlumeStakingStorage.Layout storage $,
address user,
uint16 validatorId,
address token,
uint256 userStakedAmount,
uint256 currentCumulativeRewardPerToken
)
internal
view
returns (
uint256 totalUserRewardDelta,
uint256 totalCommissionAmountDelta,
uint256 effectiveTimeDelta
)
{
uint256 lastUserPaidCumulativeRewardPerToken = $
.userValidatorRewardPerTokenPaid[user][validatorId][token];
uint256 lastUserRewardUpdateTime = $
.userValidatorRewardPerTokenPaidTimestamp[user][validatorId][token];
...
Impact Details
- Reward Overpayment: Users can claim unearned rewards for removed tokens corresponding to the period between their full unstake (T1) and the token removal (T2), despite having no stake during that time.
Proof of Concept
{% stepper %} {% step %}
User stakes and earns some rewards
- At time T0, user stakes 100 tokens on validator 1. {% endstep %}
{% step %}
User fully unstakes at time T1
This triggers updateRewardsForValidator(), which sets:
- userValidatorRewardPerTokenPaid[0xUser][1][tokenA] to latest cumulative RPT.
- userValidatorRewardPerTokenPaidTimestamp[0xUser][1][tokenA] = T1 {% endstep %}
{% step %}
tokenA is removed at time T2
- rewardRates[tokenA] = 0
- tokenA is removed from rewardTokens array
- A final checkpoint with rate 0 is written {% endstep %}
{% step %}
User restakes at time T3 (after tokenA was removed)
- User calls stake/restake which calls _performStakeSetup.
- Because the user's stake is zero, _initializeRewardStateForNewStake is called.
- _initializeRewardStateForNewStake iterates only over current rewardTokens; tokenA is not present.
- Therefore:
- userValidatorRewardPerTokenPaid[0xUser][1][tokenA] remains unchanged (still set at T1).
- userValidatorRewardPerTokenPaidTimestamp[0xUser][1][tokenA] remains unchanged (still T1).
Relevant code:
function _initializeRewardStateForNewStake(
address user,
uint16 validatorId
) internal {
PlumeStakingStorage.Layout storage $ = PlumeStakingStorage.layout();
$.userValidatorStakeStartTime[user][validatorId] = block.timestamp;
address[] memory rewardTokens = $.rewardTokens;
for (uint256 i = 0; i < rewardTokens.length; i++) {
address token = rewardTokens[i];
if ($.isRewardToken[token]) {
PlumeRewardLogic.updateRewardPerTokenForValidator(
$,
token,
validatorId
);
$.userValidatorRewardPerTokenPaid[user][validatorId][token] = $
.validatorRewardPerTokenCumulative[validatorId][token];
$.userValidatorRewardPerTokenPaidTimestamp[user][validatorId][
token
] = block.timestamp;
}
}
}
{% endstep %}
{% step %}
tokenA is re-added at time T4
- tokenA is pushed back into rewardTokens. {% endstep %}
{% step %}
User claims rewards at time T5
- updateRewardsForValidatorAndToken(tokenA) is called.
- calculateRewardsWithCheckpoints() -> _calculateRewardsCore() uses:
- userValidatorRewardPerTokenPaidTimestamp = T1
- userValidatorRewardPerTokenPaid = value at T1
Result: reward calculation includes T1 → T2 period even though user had no stake then, causing overpayment. {% endstep %} {% endstepper %}
Unstaking Before Reward Token Removal Leads to Incorrect Reward Accrual on Re-addition
Context
Plume Network runs a staking system in which users stake tokens on validators and accrue rewards paid in one or more reward tokens. The staking logic lives in StakingFacet.sol, and the reward accounting is shared with RewardsFacet and PlumeRewardLogic. The report targets the staking facet:
https://github.com/immunefi-team/attackathon-plume-network/blob/main/plume/src/facets/StakingFacet.sol
The feature that matters here is the reward-token lifecycle. The protocol keeps a rewardTokens array and a per-token isRewardToken flag, and it can add a reward token, remove it (setting its rate to zero and dropping it from the array), and later re-add it. Per user, per validator and per token, the system stores two pointers that record how much reward the user has already been credited with:
userValidatorRewardPerTokenPaiduserValidatorRewardPerTokenPaidTimestamp
Reward claims are computed from the difference between the current cumulative reward per token and these stored pointers. The correctness of the whole scheme depends on those pointers being reset whenever a user's stake changes, including when a user goes from zero stake back to a positive stake.
Setup
The report is a smart contract finding submitted to the Plume Network Attackathon on Immunefi. It is rated High, with the listed impacts "Theft of unclaimed yield" and "Protocol insolvency". No specific tooling, fork configuration or test harness is described; the proof of concept is a timeline of state transitions rather than an executed script.
The preconditions that matter are all protocol states, not attacker capabilities:
- A user has staked on a validator and accrued rewards in a reward token (call it
tokenA). - The user fully unstakes while
tokenAis still an active reward token. tokenAis removed from the reward token set.- The user stakes again while
tokenAis absent. tokenAis re-added.- The user claims.
Any user who can stake and unstake can reach this sequence; no privileged role is needed for the staking side. The removal and re-addition of a reward token are protocol actions.
Finding it
The researcher looked at what happens to a user's reward pointers when they fully unstake. StakingFacet::unstake calls PlumeRewardLogic.updateRewardsForValidator, which writes userValidatorRewardPerTokenPaid and userValidatorRewardPerTokenPaidTimestamp for all historical reward tokens, including those active at the time of unstake (T1).
When a reward token is later removed at T2, it is dropped from the rewardTokens array, but the per-user metadata for that token is preserved: nothing deletes it. When the user restakes at T3, _initializeRewardStateForNewStake() iterates only over the current rewardTokens array. A removed token is not in that array, so its pointers are never reinitialised and remain at their T1 values.
That looked wrong because the pointers are supposed to mark the point up to which the user has been credited. If the token comes back at T4 and the user claims at T5, the calculation uses pointers from T1 and therefore counts the T1 to T2 window, during which the user held no stake at all.
The claim path that reaches the vulnerable calculation is:
RewardsFacet::claim(token,validatorId) => RewardsFacet::_processValidatorRewards(user, validatorId) => PlumeRewardLogic.updateRewardsForValidatorAndToken($, user, validatorId, token) => calculateRewardsWithCheckpoints(...) => _calculateRewardsCore(...)
Exploitation
Step 1: stake and accrue
At time T0 the user stakes 100 tokens on validator 1 and begins earning rewards.
Step 2: full unstake at T1
The user fully unstakes. This triggers updateRewardsForValidator(), which sets:
userValidatorRewardPerTokenPaid[0xUser][1][tokenA]to the latest cumulative reward per token.userValidatorRewardPerTokenPaidTimestamp[0xUser][1][tokenA]to T1.
Step 3: tokenA removed at T2
The protocol removes tokenA:
rewardRates[tokenA] = 0tokenAis removed from therewardTokensarray- A final checkpoint with rate 0 is written
The user's stored pointers for tokenA are left in place.
Step 4: restake at T3
The user calls stake or restake, which calls _performStakeSetup. Because the user's stake is zero, _initializeRewardStateForNewStake is called. That function iterates only over the current rewardTokens, and tokenA is not present. As a result:
userValidatorRewardPerTokenPaid[0xUser][1][tokenA]remains unchanged (still set at T1).userValidatorRewardPerTokenPaidTimestamp[0xUser][1][tokenA]remains unchanged (still T1).
The function responsible, as quoted in the report:
function _initializeRewardStateForNewStake(
address user,
uint16 validatorId
) internal {
PlumeStakingStorage.Layout storage $ = PlumeStakingStorage.layout();
$.userValidatorStakeStartTime[user][validatorId] = block.timestamp;
address[] memory rewardTokens = $.rewardTokens;
for (uint256 i = 0; i < rewardTokens.length; i++) {
address token = rewardTokens[i];
if ($.isRewardToken[token]) {
PlumeRewardLogic.updateRewardPerTokenForValidator(
$,
token,
validatorId
);
$.userValidatorRewardPerTokenPaid[user][validatorId][token] = $
.validatorRewardPerTokenCumulative[validatorId][token];
$.userValidatorRewardPerTokenPaidTimestamp[user][validatorId][
token
] = block.timestamp;
}
}
}
The loop body only touches tokens that are currently in rewardTokens and flagged in isRewardToken. A token removed at T2 satisfies neither condition, so its pointers survive untouched.
Step 5: tokenA re-added at T4
tokenA is pushed back into rewardTokens. The user's stale pointers are still those from T1.
Step 6: claim at T5
The user claims. updateRewardsForValidatorAndToken(tokenA) runs, then calculateRewardsWithCheckpoints() calls _calculateRewardsCore(), which reads:
userValidatorRewardPerTokenPaidTimestamp = T1userValidatorRewardPerTokenPaid = value at T1
The calculation therefore includes the T1 to T2 period even though the user had no stake then, and the user is overpaid.
The excerpt from _calculateRewardsCore(...) that shows the stale pointers being read:
function _calculateRewardsCore(
PlumeStakingStorage.Layout storage $,
address user,
uint16 validatorId,
address token,
uint256 userStakedAmount,
uint256 currentCumulativeRewardPerToken
)
internal
view
returns (
uint256 totalUserRewardDelta,
uint256 totalCommissionAmountDelta,
uint256 effectiveTimeDelta
)
{
uint256 lastUserPaidCumulativeRewardPerToken = $
.userValidatorRewardPerTokenPaid[user][validatorId][token];
uint256 lastUserRewardUpdateTime = $
.userValidatorRewardPerTokenPaidTimestamp[user][validatorId][token];
...
Root cause
The reward accounting assumes that a user's pointers are refreshed for every token that could ever pay them. That assumption breaks when a token is removed from rewardTokens and later re-added. _initializeRewardStateForNewStake only walks the current array, so historical tokens are skipped, and nothing else clears the per-user metadata when a token is removed. The pointers from the last full unstake (T1) therefore survive the removal window and are used again after re-addition.
In effect, the system treats the user as having been credited up to T1, but the reward stream for tokenA continued to accrue between T1 and T2 while the user had no stake. When the token returns, the delta between the current cumulative reward per token and the T1 pointer includes that window.
Impact
A user can claim unearned rewards for a removed token, corresponding to the period between their full unstake (T1) and the token's removal (T2), despite having no stake during that time. The report lists the impacts as theft of unclaimed yield and protocol insolvency.
The report does not quantify the overpayment, give a bound on how large it can get, or state whether the issue was confirmed on a fork or testnet.
Fix
The report does not describe a patch. The change implied by the analysis is to make the pointer reset cover historical tokens as well as current ones, either by iterating over every token the user has a stored pointer for during _initializeRewardStateForNewStake, or by clearing or resetting the per-user pointers for a token at the moment it is removed. Either approach ensures that a re-added token starts from a pointer that reflects the user's actual stake history.
Variants to test
- Partial unstake instead of full unstake. Check whether a user who reduces stake to a small non-zero amount and then restakes after a token removal ends up with the same stale-pointer condition. A positive result is a claim that includes reward from a window in which the user's stake was lower than the pointer implies.
- Multiple remove and re-add cycles. Remove and re-add the same token more than once while the user is unstaked. A positive result is a claim that counts several windows in which the user had no stake.
- Several tokens removed at once. Remove more than one reward token before the user restakes. A positive result is overpayment on each re-added token, showing the bug is not specific to a single token.
- Validator migration. Unstake from one validator, restake on another, and check whether pointers for removed tokens follow the user across validators. A positive result is a claim on the new validator that includes the old validator's pre-removal window.
- Removal without a zero-rate checkpoint. If a token can be removed without the final zero-rate checkpoint being written, check whether the cumulative reward per token keeps moving during the removal window. A positive result is a larger overpayment than the standard sequence produces.
Hunting notes
This class of bug hides in accounting code where a per-user checkpoint is refreshed by iterating over a dynamic list. The signal during review is a loop over a storage array such as rewardTokens combined with per-user mappings keyed by token, where the array can shrink. Any place that removes an element from such an array while leaving the per-user mapping entries in place is a candidate.
The second signal is the re-addition path: if a token can be pushed back into the array, ask what the user's pointers were at the moment it left. If they were not reset, the delta calculation will span the gap.
The researcher showed impact by walking the full lifecycle, stake, unstake, removal, restake, re-addition, claim, and pointing at the exact function that skips the removed token and the exact lines in _calculateRewardsCore that consume the stale pointers. That trace, tied to the claim call path from RewardsFacet::claim down to _calculateRewardsCore, is what makes the overpayment concrete rather than hypothetical.
What happened, in plain words
Plume Network is a blockchain project that lets people lock up (stake) their tokens with a validator and earn rewards for doing so. Think of it like a savings account: you put money in, you leave it there, and the bank pays you interest. In Plume's case the "interest" is paid in one or more separate reward tokens, and the system keeps a careful record of how much each person has already been credited so it never pays twice for the same period.
The bug is about what happens to that record when a reward token is switched off and later switched back on. If a user takes all their stake out while a reward token is still active, then the token is removed, then the user puts their stake back in, then the token is re-added, the system forgets to update the user's record for that token. When the user finally claims, the maths counts a stretch of time during which the user had nothing staked at all. The user gets paid rewards they did not earn, and that money comes out of the pool that should have gone to everyone else.
The report rates this High severity and lists two impacts: theft of unclaimed yield and protocol insolvency.
Background you need first
A few ideas come up again and again, so here they are from zero.
Smart contract. A program that lives on a blockchain. Once deployed it runs exactly as written, and anyone can call its functions. Plume's staking system is a set of smart contracts.
Staking. Locking tokens into a contract for a period in exchange for rewards. You give up the ability to spend them for a while; the protocol pays you for that.
Validator. An entity users stake on, with rewards tracked per validator.
Reward token. A separate token used to pay the staking rewards. The protocol can have several reward tokens active at once, and it can add one, remove one, and later add it back.
Reward per token (RPT). A running total kept by the contract: "how much reward has been generated per unit of stake since the beginning." It only ever goes up. To work out what one user is owed, the contract subtracts the value the user was last credited at from the current value, then multiplies by how much they have staked. It is like a taxi meter: the fare owed is the current reading minus the reading when you last paid.
Pointer / checkpoint. The stored "reading when you last paid" for one user, one validator and one token. The report calls the two stored values pointers:
userValidatorRewardPerTokenPaidis the reward-per-token reading the user was last credited at.userValidatorRewardPerTokenPaidTimestampis the time of that last credit.
If a pointer is too old, the user gets paid for time they should not be paid for. That is the whole bug in one sentence.
Facet. A module of a larger contract. Plume splits its staking system into facets such as StakingFacet (staking and unstaking) and RewardsFacet (claiming). They share one storage layout, so a value written by one facet is read by another.
Array and mapping. Two ways to store lists in a contract. An array is an ordered list you can loop over, like rewardTokens. A mapping is a lookup table keyed by something, like userValidatorRewardPerTokenPaid[user][validatorId][token]. The bug lives exactly where these two meet: a loop over an array that can shrink, writing into a mapping that is never cleaned up.
Checkpoint. A saved snapshot of the reward rate at a moment in time. When a token is removed, the protocol writes a final checkpoint with rate zero so the meter stops moving for that token.
The target
The finding is a smart contract report submitted to the Plume Network Attackathon on Immunefi. The contract in scope is the staking facet:
https://github.com/immunefi-team/attackathon-plume-network/blob/main/plume/src/facets/StakingFacet.sol
That URL is just the public source code of the contract on GitHub. You do not need to run anything to follow the report: the proof of concept is a timeline of six moments in the life of one user's stake, not an executed script. No tooling, test setup or fork configuration is described.
The feature that breaks
The protocol keeps a list called rewardTokens and, for each token, a yes/no flag isRewardToken. It can:
- Add a reward token.
- Remove one, by setting its rate to zero and dropping it from the
rewardTokensarray. - Later push it back into the array.
For every user, validator and token, it stores the two pointers described above. Claims are calculated as the difference between the current cumulative reward per token and those pointers. The whole scheme is only correct if the pointers are refreshed every time the user's stake changes, including the change from zero stake back to a positive stake.
What you need to be true for this to happen
None of these are attacker skills. They are states of the protocol:
- A user has staked on a validator and earned rewards in a token, call it
tokenA. - The user fully unstakes while
tokenAis still an active reward token. tokenAis removed from the reward token set.- The user stakes again while
tokenAis absent. tokenAis re-added.- The user claims.
Any ordinary user who can stake and unstake can reach this sequence. Removing and re-adding a reward token are actions the protocol itself performs.
Finding it: the reasoning
The researcher asked a simple question: what happens to a user's pointers when they fully unstake?
When a user calls StakingFacet::unstake, the contract calls PlumeRewardLogic.updateRewardsForValidator. That writes both pointers for all historical reward tokens, including the ones active at that moment (time T1). So far, correct.
Then the token is removed at T2. It is dropped from the rewardTokens array, but the per-user record for that token is left alone. Nothing deletes it.
Then the user restakes at T3. The contract calls _initializeRewardStateForNewStake(), which loops over the current rewardTokens array. A removed token is not in that array, so its pointers are never refreshed and stay at their T1 values.
That is the flaw. The pointers are supposed to mark "the user has been credited up to here". If the token comes back at T4 and the user claims at T5, the calculation uses the T1 pointers and therefore counts the T1 to T2 window, during which the user held no stake at all.
The claim path that reaches the faulty calculation is:
RewardsFacet::claim(token,validatorId) => RewardsFacet::_processValidatorRewards(user, validatorId) => PlumeRewardLogic.updateRewardsForValidatorAndToken($, user, validatorId, token) => calculateRewardsWithCheckpoints(...) => _calculateRewardsCore(...)
Read that as a chain of hand-offs: the user calls claim with a token and a validator; claim passes the job to _processValidatorRewards; that calls updateRewardsForValidatorAndToken; that calls calculateRewardsWithCheckpoints; and finally _calculateRewardsCore does the arithmetic. The last function is where the stale pointers are read.
The proof of concept, step by step
Step 1: stake and earn
At time T0 the user stakes 100 tokens on validator 1 and starts earning rewards. This is the ordinary case: the meter starts running for this user.
Step 2: full unstake at T1
The user takes everything out. This triggers updateRewardsForValidator(), which sets:
userValidatorRewardPerTokenPaid[0xUser][1][tokenA]to the latest cumulative reward per token.userValidatorRewardPerTokenPaidTimestamp[0xUser][1][tokenA]to T1.
In plain words: "this user has been paid up to the meter reading at T1, at time T1". 0xUser is just a placeholder for the user's blockchain address.
Step 3: tokenA removed at T2
The protocol removes tokenA:
rewardRates[tokenA] = 0tokenAis removed from therewardTokensarray- A final checkpoint with rate 0 is written
The rate is set to zero so the meter stops moving for that token, and the token is taken out of the list. The user's stored pointers for tokenA are left in place. This is the seed of the bug: the record survives, but the list entry does not.
Step 4: restake at T3
The user calls stake or restake, which calls _performStakeSetup. Because the user's stake is zero, _initializeRewardStateForNewStake is called. That function loops only over the current rewardTokens, and tokenA is not there. As a result:
userValidatorRewardPerTokenPaid[0xUser][1][tokenA]remains unchanged (still set at T1).userValidatorRewardPerTokenPaidTimestamp[0xUser][1][tokenA]remains unchanged (still T1).
Here is the function as quoted in the report:
function _initializeRewardStateForNewStake(
address user,
uint16 validatorId
) internal {
PlumeStakingStorage.Layout storage $ = PlumeStakingStorage.layout();
$.userValidatorStakeStartTime[user][validatorId] = block.timestamp;
address[] memory rewardTokens = $.rewardTokens;
for (uint256 i = 0; i < rewardTokens.length; i++) {
address token = rewardTokens[i];
if ($.isRewardToken[token]) {
PlumeRewardLogic.updateRewardPerTokenForValidator(
$,
token,
validatorId
);
$.userValidatorRewardPerTokenPaid[user][validatorId][token] = $
.validatorRewardPerTokenCumulative[validatorId][token];
$.userValidatorRewardPerTokenPaidTimestamp[user][validatorId][
token
] = block.timestamp;
}
}
}
Line by line:
function _initializeRewardStateForNewStake(address user, uint16 validatorId) internal {declares a function that takes a user address and a validator number, and can only be called from inside the contract (internal).PlumeStakingStorage.Layout storage $ = PlumeStakingStorage.layout();fetches the shared storage. The$is just a variable name; it points at the contract's saved data.$.userValidatorStakeStartTime[user][validatorId] = block.timestamp;records that this user's stake on this validator starts now.block.timestampis the current time on the blockchain.address[] memory rewardTokens = $.rewardTokens;copies the current list of reward tokens into memory so it can be looped over.for (uint256 i = 0; i < rewardTokens.length; i++) {walks the list from the first entry to the last.address token = rewardTokens[i];picks out the token at positioni.if ($.isRewardToken[token]) {checks the yes/no flag. Only tokens currently flagged as reward tokens are processed.PlumeRewardLogic.updateRewardPerTokenForValidator($, token, validatorId);brings the meter up to date for this token and validator.$.userValidatorRewardPerTokenPaid[user][validatorId][token] = $.validatorRewardPerTokenCumulative[validatorId][token];sets the user's pointer to the current meter reading.$.userValidatorRewardPerTokenPaidTimestamp[user][validatorId][token] = block.timestamp;sets the pointer's timestamp to now.
The key point: the loop body only touches tokens that are currently in rewardTokens and flagged in isRewardToken. A token removed at T2 satisfies neither condition, so its pointers survive untouched.
Step 5: tokenA re-added at T4
tokenA is pushed back into rewardTokens. The user's pointers are still the ones from T1, because nothing has changed them.
Step 6: claim at T5
The user claims. updateRewardsForValidatorAndToken(tokenA) runs, then calculateRewardsWithCheckpoints() calls _calculateRewardsCore(), which reads:
userValidatorRewardPerTokenPaidTimestamp = T1userValidatorRewardPerTokenPaid = value at T1
The calculation therefore includes the T1 to T2 period even though the user had no stake then, and the user is overpaid.
Here is the excerpt from _calculateRewardsCore(...) that shows the stale pointers being read:
function _calculateRewardsCore(
PlumeStakingStorage.Layout storage $,
address user,
uint16 validatorId,
address token,
uint256 userStakedAmount,
uint256 currentCumulativeRewardPerToken
)
internal
view
returns (
uint256 totalUserRewardDelta,
uint256 totalCommissionAmountDelta,
uint256 effectiveTimeDelta
)
{
uint256 lastUserPaidCumulativeRewardPerToken = $
.userValidatorRewardPerTokenPaid[user][validatorId][token];
uint256 lastUserRewardUpdateTime = $
.userValidatorRewardPerTokenPaidTimestamp[user][validatorId][token];
...
Line by line:
function _calculateRewardsCore(...) internal view returns (...)declares the function that does the reward arithmetic.viewmeans it only reads data and does not change anything.- The parameters are the shared storage
$, the user, the validator, the token, how much the user has staked, and the current cumulative reward per token. uint256 lastUserPaidCumulativeRewardPerToken = $.userValidatorRewardPerTokenPaid[user][validatorId][token];reads the user's stored pointer: the meter reading they were last credited at.uint256 lastUserRewardUpdateTime = $.userValidatorRewardPerTokenPaidTimestamp[user][validatorId][token];reads the timestamp of that credit....means the rest of the function is omitted. What matters is that these two values are the starting point of the calculation, and in our scenario they are from T1.
Root cause
The reward accounting assumes that a user's pointers are refreshed for every token that could ever pay them. That assumption breaks when a token is removed from rewardTokens and later re-added. _initializeRewardStateForNewStake only walks the current array, so historical tokens are skipped, and nothing else clears the per-user record when a token is removed. The pointers from the last full unstake (T1) therefore survive the removal window and are used again after re-addition.
In effect, the system treats the user as having been credited up to T1, but the reward stream for tokenA kept accruing between T1 and T2 while the user had no stake. When the token returns, the difference between the current meter reading and the T1 pointer includes that window.
Impact
A user can claim unearned rewards for a removed token, corresponding to the period between their full unstake (T1) and the token's removal (T2), despite having no stake during that time. The report lists the impacts as theft of unclaimed yield and protocol insolvency.
The report does not quantify the overpayment, give a bound on how large it can get, or state whether the issue was confirmed on a fork or testnet.
Fix
The report does not describe a patch. The change implied by the analysis is to make the pointer reset cover historical tokens as well as current ones, either by looping over every token the user has a stored pointer for during _initializeRewardStateForNewStake, or by clearing or resetting the per-user pointers for a token at the moment it is removed. Either approach ensures that a re-added token starts from a pointer that reflects the user's actual stake history.
Variants to test
- Partial unstake instead of full unstake. Check whether a user who reduces stake to a small non-zero amount and then restakes after a token removal ends up with the same stale-pointer condition. A positive result is a claim that includes reward from a window in which the user's stake was lower than the pointer implies.
- Multiple remove and re-add cycles. Remove and re-add the same token more than once while the user is unstaked. A positive result is a claim that counts several windows in which the user had no stake.
- Several tokens removed at once. Remove more than one reward token before the user restakes. A positive result is overpayment on each re-added token, showing the bug is not specific to a single token.
- Validator migration. Unstake from one validator, restake on another, and check whether pointers for removed tokens follow the user across validators. A positive result is a claim on the new validator that includes the old validator's pre-removal window.
- Removal without a zero-rate checkpoint. If a token can be removed without the final zero-rate checkpoint being written, check whether the cumulative reward per token keeps moving during the removal window. A positive result is a larger overpayment than the standard sequence produces.
Hunting notes
This class of bug hides in accounting code where a per-user checkpoint is refreshed by looping over a dynamic list. The signal during review is a loop over a storage array such as rewardTokens combined with per-user mappings keyed by token, where the array can shrink. Any place that removes an element from such an array while leaving the per-user mapping entries in place is a candidate.
The second signal is the re-addition path: if a token can be pushed back into the array, ask what the user's pointers were at the moment it left. If they were not reset, the difference calculation will span the gap.
The researcher showed impact by walking the full lifecycle, stake, unstake, removal, restake, re-addition, claim, and pointing at the exact function that skips the removed token and the exact lines in _calculateRewardsCore that consume the stale pointers. That trace, tied to the claim call path from RewardsFacet::claim down to _calculateRewardsCore, is what makes the overpayment concrete rather than hypothetical.
Glossary
- Smart contract: a program deployed on a blockchain that runs exactly as written and can be called by anyone.
- Staking: locking tokens in a contract for a period in exchange for rewards.
- Validator: an operator that users stake on, with rewards tracked per validator.
- Reward token: a separate token used to pay staking rewards; the protocol can add, remove and re-add it.
- Reward per token (RPT): a running total of reward generated per unit of stake since the beginning; it only increases.
- Pointer / checkpoint: the stored record of the meter reading and time a user was last credited, per user, validator and token.
userValidatorRewardPerTokenPaid: the reward-per-token reading a user was last credited at.userValidatorRewardPerTokenPaidTimestamp: the time of that last credit.- Facet: a module of a larger contract;
StakingFacethandles staking,RewardsFacethandles claims, and they share storage. - Array: an ordered list you can loop over, such as
rewardTokens. - Mapping: a lookup table keyed by values, such as
userValidatorRewardPerTokenPaid[user][validatorId][token]. - Checkpoint: a saved snapshot of the reward rate at a moment in time; a zero-rate checkpoint stops the meter for a removed token.
rewardTokens: the array holding the currently active reward tokens.isRewardToken: a yes/no flag saying whether a token is currently a reward token.rewardRates[tokenA] = 0: setting a token's reward rate to zero, which stops new rewards accruing for it.block.timestamp: the current time on the blockchain.internal: a function visibility meaning it can only be called from inside the contract.view: a function that only reads data and changes nothing.uint256: an unsigned whole number of up to 256 bits, the usual number type in Solidity.address: a blockchain account identifier, such as a user's wallet.uint16: a small unsigned whole number, used here for the validator number.0xUser: a placeholder for a user's blockchain address in the report.- T0, T1, T2, T3, T4, T5: the six moments in the timeline: stake, unstake, token removal, restake, token re-addition, claim.
- Theft of unclaimed yield: taking rewards that were meant for other participants.
- Protocol insolvency: the protocol's reward pool being drained beyond what it can pay.
- Attackathon: a time-boxed bug-hunting competition run on a bug bounty platform.
- Immunefi: the bug bounty platform where this report was submitted.
- Proof of concept (PoC): a demonstration that the bug is real, here a timeline of state changes rather than a script.
- Fork / testnet: a copy of the blockchain or a test network used to try things without touching real funds.