Inflation rate can be reduced by half at most if it gets called every 1.99 interval
The inflation calculation rounds down the number of elapsed intervals, but the start time is updated to the current timestamp, so calling inflation just before a full interval elapses causes the protocol to lose the partial interval. An attacker could repeatedly trigger inflation at short intervals to reduce the total inflation applied over time.
wagmi Follow with peritoflores, sces60107 and 7 others
Originally disclosed on Code4rena
Submitted by wagmi, also found by peritoflores, sces60107, 141345, hansfriese, slowmoses, supernova, rvierdiiev, HollaDieWaldfee, and chaduke
When doing inflation, function getInflationAmt() calculated number of intervals elapsed by dividing the duration with interval length.
function getInflationIntervalsElapsed() public view returns (uint256) {
ProtocolDAO dao = ProtocolDAO(getContractAddress("ProtocolDAO"));
uint256 startTime = getInflationIntervalStartTime();
if (startTime == 0) {
revert ContractHasNotBeenInitialized();
}
return (block.timestamp - startTime) / dao.getInflationIntervalSeconds();
}
As we can noticed that, this calculation is rounding down, it means if block.timestamp - startTime = 1.99 intervals, it only account for 1 interval.
However, when updating start time after inflating, it still update to current timestamp while it should only increased by intervalLength * intervalsElapsed instead.
addUint(keccak256("RewardsPool.InflationIntervalStartTime"), inflationIntervalElapsedSeconds);
// @audit should only update to oldStartTime + inverval * numInterval
setUint(keccak256("RewardsPool.RewardsCycleTotalAmt"), newTokens);
Since default value of inflation interval = 1 days and reward cycle length = 14 days, so the impact is reduced. However, these configs can be changed in the future.
Proof of Concept
Consider the scenario:
- Assume last inflation time is
InflationIntervalStartTime = 100.InflationIntervalSeconds = 50. - At
timestamp = 199, functiongetInflationAmt()will calculate
inflationIntervalsElapsed = (199 - 100) / 50 = 1
// Compute inflation for total inflation intervals elapsed
for (uint256 i = 0; i < inflationIntervalsElapsed; i++) {
newTotalSupply = newTotalSupply.mulWadDown(inflationRate);
} // @audit only loop once.
- And then in
inflate()function,InflationIntervalStartTimeis still updated to current timestamp, soInflationIntervalStartTime = 199. - If this sequence of actions are repeatedly used, we can easily see
InflationIntervalStartTime = 199, inflated count = 1
InflationIntervalStartTime = 298, inflated count = 2
InflationIntervalStartTime = 397, inflated count = 3
InflationIntervalStartTime = 496, inflated count = 4
InflationIntervalStartTime = 595, inflated count = 5
While at timestamp = 595, inflated times should be (595 - 100) / 50 = 9 instead.
Recommended Mitigation Steps
Consider only increasing InflationIntervalStartTime by the amount of intervals time interval length.
emersoncloud (GoGoPool) disagreed with severity and commented:
I agree with this issue, but assets can’t be stolen, lost or compromised directly. Medium severity is more appropriate (https://docs.code4rena.com/awarding/judging-criteria#estimating-risk)
Alex the Entreprenerd (judge) decreased severity to Medium and commented:
I have considered a Higher Severity, due to logical flaws.
However, I believe that the finding
- Relies on the Condition of being called less than intended
- Causes an incorrect amount of emissions (logically close to loss of Yield)
For those reasons, I believe Medium Severity to be the most appropriate
emersoncloud (GoGoPool) commented:
Acknowledged, not fixing in this first version of the protocol.
We can and will have rialto call startRewardsCycle if needed, and think it’s unlikely to become delayed.
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
The start time is updated to the current timestamp instead of being advanced by the number of elapsed intervals multiplied by the interval length, so the remainder from rounding down is lost.
Impact
The inflation rate can be reduced by up to half if the function is called every 1.99 intervals, though the default configuration (1-day interval, 14-day cycle) limits the practical impact.
What the attacker needed
Ability to call the inflation function; timing calls just before interval ends
The fix
The start time should be increased by the interval length multiplied by the number of intervals elapsed, not set to the current timestamp.
How it was found
- Set the inflation interval start time to 100 and interval length to 50.
- At timestamp 199, call the inflation function; it calculates one interval elapsed and applies inflation once.
- The start time is updated to 199, discarding the 49 seconds of the partial interval.
- Repeat the same pattern at timestamps 298, 397, 496, and 595, each time applying only one interval of inflation.
- At timestamp 595, the correct number of intervals elapsed since the original start is 9, but only 5 have been applied.
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.
In a blockchain protocol, inflation is applied at set intervals. The code calculates how many full intervals have passed and rounds down, but then resets the start time to now, discarding any leftover time. By calling the inflation function just before each interval ends, someone can make the protocol skip applying inflation for the lost time, reducing the total inflation.
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.