Unused rewards(because of totalSupply()==0 for some period) will be locked forever in VE3DRewardPool and BaseRewardPool
The reward pool contracts fail to distribute rewards during periods when totalSupply() is zero, because rewardPerToken() returns the stored value without accumulating rewards. As a result, rewards allocated for those periods remain stuck in the contract and are never paid to stakers.
The VE3DRewardPool and BaseRewardPool contract is supposed to distribute rewards to stackers, but if in some period, totalSupply() was equal to 0, then for that time period, rewards will not added to rewardPerTokenStored and those period rewards would not distribute to any address and those rewards will stuck in contract forever.
Proof of Concept
This is notifyRewardAmount() code in BaseRewardPool contract: (VE3DRewardPool code is similar)
As you can see, in the line rewardRate = reward.div(duration); the value of rewardRate has been set to the division of available reward to duration. so if we distribute rewardRate amount in every second between stackers, then all rewards will be used by contract. contract uses updateReward() modifier to update rewardPerTokenStored (this variable keeps track of distributed tokens) and this modifier uses rewardPerToken() to update BaseRewardPool:
function rewardPerToken() public view returns (uint256) {
if (totalSupply() == 0) {
return rewardPerTokenStored;
}
return
rewardPerTokenStored.add(
lastTimeRewardApplicable().sub(lastUpdateTime).mul(rewardRate).mul(1e18).div(
totalSupply()
)
);
}
If for some period totalSupply() was 0 then contract won’t increase rewardPerTokenStored and those periods reward stuck in contract forever, because there is no mechanism to calculate them and withdraw them in contract. For example if operator deploy and initialize the pool immediately before others having a chance of stacking their tokens, and use queueNewRewards() to queue the rewards then The rewards for early period of pool will be locked forever.
Tools Used
VIM
Recommended Mitigation Steps
Add some mechanism to recalculate rewardRate or calculated undistributed rewards(calculated undistributed reward based on rewardRate and when totalSupply() is 0).
The warden has found a valid problem, however a coded POC would have gone a long way.
In order to judge the issue I had to code it for myself to be able to demonstrate the problem.
Anyhow this is a Brownie dump of me setting up the contract (removing transferFrom to get it done rapidly) Showing how skipping 1/3 of reward duration will cause a loss of 1/3 of the yield.
Meaning that the accumulator used for rewards is not redistributing the old rewards
Which means, that the warden has found a valid vulnerability and any time spent with a totalSupply of 0 will cause those rewards to be lost.
Because this is contingent on:
No deposits before adding rewards
Lasts only until a deposit has happened
Is related to loss of yield
I believe Medium Severity to be more appropriate.
The original report as published on Code4rena, by unforgiven. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Root cause
Likely the reward calculation skips accumulation when totalSupply() is zero, and there is no mechanism to redistribute or recover the unallocated rewards.
Impact
Rewards allocated during periods with no staked tokens are permanently locked in the contract and cannot be claimed by anyone, resulting in a loss of yield for stakers.
What the attacker needed
Pool deployed and initialised before any deposits; Rewards queued while totalSupply() is zero; No stakers during that period
The fix
The contract should include a mechanism to recalculate rewardRate or recover undistributed rewards when totalSupply() is zero, as suggested; the text does not state that a fix was applied.
How it was found
Deploy and initialise the pool before any staker deposits tokens.
Queue new rewards using queueNewRewards().
Wait for a period during which totalSupply() remains zero.
Later, when stakers deposit and rewards are claimed, the rewards from the zero-supply period are not distributed.
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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
These contracts pay out rewards over time to people who stake tokens. The amount each staker earns is based on a running total that only increases when there are staked tokens. If nobody has staked yet, that running total does not move, so the rewards for that empty period are never given out and stay locked in the contract.
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.