Having no deposits in `StakedEXA` will lead to stuck rewards when harvesting
The StakedEXA contract's reward index does not increase when total supply is zero, so rewards distributed during periods with no deposits become stuck. An attacker could cause this by harvesting rewards or withdrawing all deposits while rewards are ongoing, leading to permanent loss of those rewards.
0x73696d616f Follow with KupiaSec
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-07-exactly-stacking-contracts-judging/issues/48
Found by
0x73696d616f, KupiaSec
Summary
The provider in StakedEXA is free to distributed rewards as it pleases and there is an automated way to distribute via StakedEXA::harvest(). The harvest setup may be started but no actual deposits have been made to StakedEXA or users may withdraw from StakedEXA while automated ongoing rewards are happening, which will lead to stuck rewards inside StakedEXA.
Root Cause
In StakedEXA::globalIndex() it returns a stale index if the totalSupply() is null (no deposits), but it should instead calculate the amount (rate x deltaTime) and send it to savings. This way rewards will never be stuck.
Internal pre-conditions
- No deposits are present in
StakedEXA.
External pre-conditions
None.
Attack Path
- Deposits were not yet made and rewards are harvested or users withdraw all deposits while rewards are rolling out.
Impact
Stuck rewards as the index is not increased but rewardData.updatedAt increases.
PoC
In StakedEXA::updateIndex(), the index is updated to globalIndex(reward); and rewardData.updatedAt to the current block.timestamp or rewardData.finishAt.
function updateIndex(IERC20 reward) internal {
RewardData storage rewardData = rewards[reward];
rewardData.index = globalIndex(reward);
rewardData.updatedAt = uint40(lastTimeRewardApplicable(rewardData.finishAt));
}
In StakedEXA::globalIndex(), the index is not increased if the total supply is null:
function globalIndex(IERC20 reward) public view returns (uint256) {
RewardData storage rewardData = rewards[reward];
if (totalSupply() == 0) return rewardData.index;
return
rewardData.index +
(rewardData.rate * (lastTimeRewardApplicable(rewardData.finishAt) - rewardData.updatedAt)).divWadDown(
totalSupply()
);
}
Thus, as can be seen, the index will not be updated by rewardData.updatedAt is increased, losing these rewards forever.
Mitigation
If the total supply is null the amount not distributed can be calculated by doing rate x deltaTime and send to savings.
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/exactly/protocol/pull/752
sherlock-admin2
The Lead Senior Watson signed off on the fix.
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
Impact
Rewards become permanently stuck because the index is not increased while updatedAt advances, leading to loss of those rewards.
What the attacker needed
No deposits in StakedEXA; Rewards are being distributed
The fix
The issue was fixed by calculating the undistributed amount (rate times deltaTime) and sending it to savings when total supply is zero.
How it was found
- Ensure no deposits are present in StakedEXA.
- Harvest rewards or have users withdraw all deposits while rewards are still being distributed.
- Observe that the reward index does not increase but updatedAt does, causing rewards to be stuck.
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.
StakedEXA is a contract where people deposit tokens and earn rewards over time. The contract tracks rewards using an index that should grow as time passes, but if nobody has deposited anything, the index stays the same while the timestamp updates, so those rewards are lost forever. This means rewards meant for depositors can get stuck if the contract is empty when rewards are being distributed.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.