Staking: rebase() does not rebase according to the status of the current epoch.
The rebase function in the staking contract applies the current epoch's reward distribution before recalculating it, so the rewards used for an epoch are stale. This can cause rewards to be updated incorrectly and lead to an incorrect distribution of user rewards.
Submitted by cccz
In the staking contract, the rebase function can only be called once per epoch.
In the rebase function, the rewards of the current epoch are used in the next epoch, which can cause the rewards to be updated incorrectly and lead to incorrect distribution of user rewards.
function rebase() public {
// we know about the issues surrounding block.timestamp, using it here will not cause any problems
if (epoch.endTime <= block.timestamp) {
IYieldy(YIELDY_TOKEN).rebase(epoch.distribute, epoch.number); // 懒更新
epoch.endTime = epoch.endTime + epoch.duration;
epoch.timestamp = block.timestamp;
epoch.number++;
uint256 balance = contractBalance();
uint256 staked = IYieldy(YIELDY_TOKEN).totalSupply();
if (balance <= staked) {
epoch.distribute = 0;
} else {
epoch.distribute = balance - staked;
}
}
}
Proof of Concept
Recommended Mitigation Steps
Put IYieldy(YIELDY_TOKEN).rebase after epoch.distribute update
function rebase() public {
// we know about the issues surrounding block.timestamp, using it here will not cause any problems
if (epoch.endTime <= block.timestamp) {
uint256 balance = contractBalance();
uint256 staked = IYieldy(YIELDY_TOKEN).totalSupply();
if (balance <= staked) {
epoch.distribute = 0;
} else {
epoch.distribute = balance - staked;
}
IYieldy(YIELDY_TOKEN).rebase(epoch.distribute, epoch.number);
epoch.endTime = epoch.endTime + epoch.duration;
epoch.timestamp = block.timestamp;
epoch.number++;
}
}
toshiSat (Yieldy) acknowledged and commented:
This is how the system is designed.
JasoonS (judge) decreased severity to Medium and commented:
Changing to Medium. It makes sense that the rebase happens after rewards so that those who enter later don’t affect the distribution of rewards before they joined.
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 the rebase call is made before the epoch's distribute value is recalculated, so the token receives the previous epoch's reward figure.
Impact
Rewards could be distributed incorrectly to users; the project said this is by design and the judge rated it Medium.
What the attacker needed
None
The fix
The rebase call should be moved after the epoch.distribute value is updated, as the report recommends.
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.
A staking contract hands out rewards in rounds called epochs. The function that starts a new round was passing the old reward amount to the token before working out the new amount, so the numbers were one round out of date. That means users could be paid the wrong share of rewards.
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.