Skip to content
Business logic Audit finding Intermediate

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.

chaduke Follow with d3e4

Originally disclosed on Code4rena

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():

  1. decayBaseRateFromBorrowing() calls _calcDecayedBaseRate() to calculate the decayed base rate based how many minutes elapsed since last recorded lastFeeOperationTime.
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);
 }
  1. decayBaseRateFromBorrowing() then calls _updateLastFeeOpTime() to set lastFeeOperationTime to 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);
        }
    }
  1. The problem with such an update of lastFeeOperationTime is, 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.
  2. 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


The original report as published on Code4rena, by chaduke. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

  1. Call decayBaseRateFromBorrowing, which computes the decayed base rate from whole minutes since lastFeeOperationTime.
  2. The same function then calls _updateLastFeeOpTime, which sets lastFeeOperationTime to the current block timestamp.
  3. If 1.999 minutes had passed, only 1 minute of decay is applied but the full 1.999 minutes are added to the clock.
  4. 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.

More by chaduke

View all

21 more disclosed reports, best first.

More from Ethos Reserve contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.