RewardThrottle: If an epoch does not have any profit, then there may not be rewards for that epoch at the start of the next epoch.
The RewardThrottle contract has two functions that fill in past epochs without profit, but only one of them requests and distributes the missing reward from the overflow pool. If the other function is called first, the epoch is marked as filled and the reward is permanently lost.
cccz Follow with hansfriese
Originally disclosed on Code4rena
Submitted by cccz, also found by hansfriese
In RewardThrottle, both checkRewardUnderflow and fillInEpochGaps call \_fillInEpochGaps to fill the state of the previous epoch without profit, the difference being that checkRewardUnderflow will request the reward from the overflowPool and distribute the reward, whereas fillInEpochGaps does not.
function checkRewardUnderflow() public onlyActive {
uint256 epoch = timekeeper.epoch();
uint256 _activeEpoch = activeEpoch; // gas
// Fill in gaps so we have a fresh foundation to calculate from
_fillInEpochGaps(epoch);
if (epoch > _activeEpoch) {
for (uint256 i = _activeEpoch; i < epoch; ++i) {
uint256 underflow = _getRewardUnderflow(i);
if (underflow > 0) {
uint256 balance = overflowPool.requestCapital(underflow);
_sendToDistributor(balance, i);
}
}
}
}
function fillInEpochGaps() external {
uint256 epoch = timekeeper.epoch();
_fillInEpochGaps(epoch);
}
This results in that when an epoch does not have any profit, then at the start of the next epoch that epoch will have a reward if checkRewardUnderflow is called, and no reward if fillInEpochGaps is called.
According to the documentation, when an epoch is not profitable enough, the reward should be requested from the overflowPool, so checkRewardUnderflow should be called. And if fillInEpochGaps is called first, the epoch will lose its reward.
Note: populateFromPreviousThrottle will also cause epochs without any profit to lose their rewards
function populateFromPreviousThrottle(address previousThrottle, uint256 epoch)
external
onlyRoleMalt(ADMIN_ROLE, "Only admin role")
{
RewardThrottle previous = RewardThrottle(previousThrottle);
uint256 _activeEpoch = activeEpoch; // gas
for (uint256 i = _activeEpoch; i < epoch; ++i) {
(
uint256 profit,
uint256 rewarded,
uint256 bondedValue,
uint256 desiredAPR,
uint256 epochsPerYear,
uint256 cumulativeCashflowApr,
uint256 cumulativeApr
) = previous.epochData(i);
state[i].bondedValue = bondedValue;
state[i].profit = profit;
state[i].rewarded = rewarded;
state[i].epochsPerYear = epochsPerYear;
state[i].desiredAPR = desiredAPR;
state[i].cumulativeCashflowApr = cumulativeCashflowApr;
state[i].cumulativeApr = cumulativeApr;
}
activeEpoch = epoch;
}
Proof of Concept
Recommended Mitigation Steps
Consider removing the fillInEpochGaps function, or only allowing it to be called when the contract is not active.
0xScotch (Malt) confirmed and commented:
We will be removing both implementations of
fillInEpochGaps.
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 two functions share the same gap-filling logic, but only one of them includes the step that requests and sends the reward from the overflow pool, so calling the other first marks the epoch as handled and prevents the reward from ever being paid.
Impact
An epoch without profit may lose its reward if fillInEpochGaps is called before checkRewardUnderflow, and the same loss can occur when populateFromPreviousThrottle is used.
What the attacker needed
FillInEpochGaps called before checkRewardUnderflow; epoch without profit
The fix
The team said they will remove both implementations of fillInEpochGaps.
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.
This is a smart contract that pays rewards for each time period (epoch). If a period made no profit, the contract is supposed to borrow from a savings pool to still pay a reward. But there are two ways to mark a period as 'done', and one of them skips the borrowing step. If that wrong way is used first, the reward for that period can never be paid.
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.