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.
Tools Used
Manual Review
Recommended Mitigation Steps
Recommend checking epoch - _activeEpoch > smoothingPeriod in populateFromPreviousThrottle().
Lines of code
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
Vulnerability details
Impact
Average
APR
s might be calculated wrongly after callingpopulateFromPreviousThrottle()
andtargetAPR
might be changed unexpectedly.Proof of Concept
The epoch state struct contains
cumulativeCashflowApr
element andcashflowAverageApr
is used to adjusttargetAPR
inupdateDesiredAPR()
function.And
populateFromPreviousThrottle()
is an admin function to changeactiveEpoch
and the relevant epoch state using the previous throttle.And the
activeEpoch
is likely to be increased inside this function.The problem might occur when
epoch < _activeEpoch + smoothingPeriod
becausestate[epoch].cumulativeCashflowApr
andstate[epoch - smoothingPeriod].cumulativeCashflowApr
will be used forcashflowAverageApr
calculation.So
cumulativeCashflowApr
of the original epoch and the newly added epoch will be used together andcashflowAverageApr
might be calculated wrongly.As a result,
targetAPR
might be changed unexpectedly.Tools Used
Manual Review
Recommended Mitigation Steps
Recommend checking
epoch - _activeEpoch > smoothingPeriod
inpopulateFromPreviousThrottle()
.