lastFeeOperationTime is not modified correctly in function _updateLastFeeOpTime() , resulting a much slower decay model for borrowing base rate
The function that updates the last fee operation time sets it to the current block timestamp instead of advancing it by the whole minutes actually used for decay, so the borrowing base rate decays more slowly than intended. An attacker could exploit this to keep borrowing fees artificially low, though the text does not describe an active attack.
Submitted by chaduke, also found by d3e4
lastFeeOperationTime is not modified correctly in function _updateLastFeeOpTime(). As a result, decayBaseRateFromBorrowing() will decay the base rate more slowly than expected (worst case half slower).
Since borrowing base rate is so fundamental to the protocol, I would rate this finding as High.
Proof of Concept
We show how decayBaseRateFromBorrowing() will decay the base rate more slowly than expected because of the wrong modification of lastFeeOperationTime in _updateLastFeeOpTime():
decayBaseRateFromBorrowing()calls_calcDecayedBaseRate()to calculate the decayed base rate based how many minutes elapsed since last recordedlastFeeOperationTime.
function decayBaseRateFromBorrowing() external override {
_requireCallerIsBorrowerOperations();
uint decayedBaseRate = _calcDecayedBaseRate();
assert(decayedBaseRate <= DECIMAL_PRECISION); // The baseRate can decay to 0
baseRate = decayedBaseRate;
emit BaseRateUpdated(decayedBaseRate);
_updateLastFeeOpTime();
}
function _calcDecayedBaseRate() internal view returns (uint) {
uint minutesPassed = _minutesPassedSinceLastFeeOp();
uint decayFactor = LiquityMath._decPow(MINUTE_DECAY_FACTOR, minutesPassed);
return baseRate.mul(decayFactor).div(DECIMAL_PRECISION);
}
function _minutesPassedSinceLastFeeOp() internal view returns (uint) {
return (block.timestamp.sub(lastFeeOperationTime)).div(SECONDS_IN_ONE_MINUTE);
}
decayBaseRateFromBorrowing()then calls_updateLastFeeOpTime()to setlastFeeOperationTimeto the current time if at least 1 minute pass.
function _updateLastFeeOpTime() internal {
uint timePassed = block.timestamp.sub(lastFeeOperationTime);
if (timePassed >= SECONDS_IN_ONE_MINUTE) {
lastFeeOperationTime = block.timestamp;
emit LastFeeOpTimeUpdated(block.timestamp);
}
}
- The problem with such an update of
lastFeeOperationTimeis, if 1.999 minutes had passed, the base rate will only decay for 1 minute, at the same time, 1.999 minutes will be added onlastFeeOperationTime. In other words, in a worst scenario, for every 1.999 minutes, the base rate will only decay for 1 minute. Therefore, the base rate will decay more slowly then expected. - The borrowing base rate is very fundamental to the whole protocol. Any small deviation is accumulative. In the worse case, the decay speed will slow down by half; on average, it will be 0.75 slower.
Tools Used
VSCode
Recommended Mitigation Steps
Using the effective elapsed time that is consumed by the model so far to revise lastFeeOperationTime.
function _updateLastFeeOpTime() internal {
uint timePassed = block.timestamp.sub(lastFeeOperationTime);
if (timePassed >= SECONDS_IN_ONE_MINUTE) {
- lastFeeOperationTime = block.timestamp;
+ lastFeeOperationTime += _minutesPassedSinceLastFeeOp()*SECONDS_IN_ONE_MINUTE;
emit LastFeeOpTimeUpdated(block.timestamp);
}
}
Trust (judge) decreased severity to Medium
tess3rac7 (Ethos Reserve) disputed via duplicate issue #850
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 update sets lastFeeOperationTime to block.timestamp instead of adding only the whole minutes consumed by the decay calculation, discarding the remainder.
Impact
The borrowing base rate could decay up to half as fast in the worst case, and about 0.75 times as fast on average, keeping fees higher than intended; the judge reduced severity to Medium and the project disputed the finding.
What the attacker needed
Protocol uses the borrowing base rate; time passes between fee operations
The fix
The update should advance lastFeeOperationTime by the whole minutes actually consumed by the decay calculation rather than setting it to the current timestamp.
How it was found
- Call decayBaseRateFromBorrowing, which computes the decayed base rate from whole minutes since lastFeeOperationTime.
- The same function then calls _updateLastFeeOpTime, which sets lastFeeOperationTime to the current block timestamp.
- If 1.999 minutes had passed, only 1 minute of decay is applied but the full 1.999 minutes are added to the clock.
- Repeating this loses the fractional minutes each time, so the base rate decays more slowly than expected.
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 tracks a 'base rate' that should slowly fall over time when no one borrows. To do this it counts how many whole minutes have passed since the last update. The bug is that after counting those minutes it resets the clock to 'now' rather than moving it forward by only the minutes it counted, so leftover seconds are lost and the rate falls more slowly than designed.
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.