Average APR s might be calculated wrongly after calling populateFromPreviousThrottle() .
The admin function populateFromPreviousThrottle() copies epoch data from a previous throttle contract and advances activeEpoch, but if the new epoch is less than the smoothing period ahead of the old one, the average APR calculation mixes cumulative values from different epochs. This could cause targetAPR to be adjusted incorrectly.
Originally disclosed on Code4rena
Submitted by hansfriese
https://github.com/code-423n4/2023-02-malt/blob/main/contracts/RewardSystem/RewardThrottle.sol#L660
https://github.com/code-423n4/2023-02-malt/blob/main/contracts/RewardSystem/RewardThrottle.sol#L139
Impact
Average APRs might be calculated wrongly after calling populateFromPreviousThrottle() and targetAPR might be changed unexpectedly.
Proof of Concept
The epoch state struct contains cumulativeCashflowApr element and cashflowAverageApr is used to adjust targetAPR in updateDesiredAPR() function.
And populateFromPreviousThrottle() is an admin function to change activeEpoch and the relevant epoch state using the previous throttle.
And the activeEpoch is likely to be increased inside this function.
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;
}
The problem might occur when epoch < _activeEpoch + smoothingPeriod because state[epoch].cumulativeCashflowAprand state[epoch - smoothingPeriod].cumulativeCashflowApr will be used for cashflowAverageApr calculation.
So cumulativeCashflowApr of the original epoch and the newly added epoch will be used together and cashflowAverageApr might be calculated wrongly.
As a result, targetAPR might be changed unexpectedly.
Recommended Mitigation Steps
Recommend checking epoch - _activeEpoch > smoothingPeriod in populateFromPreviousThrottle().
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 populateFromPreviousThrottle() function does not ensure that the new epoch is at least smoothingPeriod ahead of the current activeEpoch, so the average APR calculation reads cumulative values from mismatched epochs.
Impact
The average APR and targetAPR could be calculated incorrectly, potentially changing reward rates unexpectedly.
What the attacker needed
Admin role; previous throttle contract
The fix
The function should check that the new epoch is more than smoothingPeriod ahead of the current activeEpoch before copying data.
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 smart contract keeps track of rewards over time in 'epochs'. An admin function is meant to copy old epoch data into a new contract, but if it jumps forward by less than a fixed smoothing window, the average reward rate is computed from a mix of old and new data. That can make the contract set the wrong target reward rate.
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.