Skip to content
Business logic Audit finding Intermediate

In ReaperVaultV2 , we should update lockedProfit and lastReport before changing lockedProfitDegradation

The contract's locked profit calculation uses the current degradation rate over the entire period since the last report, so changing that rate retroactively alters how much profit is considered unlocked. A malicious depositor could front-run the admin's rate change with a large deposit to capture extra yield that was not previously available.

hansfriese Follow

Originally disclosed on Code4rena

Submitted by hansfriese

The locked profit degradation for the past will be changed with the new lockedProfitDegradation.

As a result, malicious users can steal others’ rewards by frontrunning.

Proof of Concept

setLockedProfitDegradation() is used to change lockedProfitDegradation by admin.

    function setLockedProfitDegradation(uint256 degradation) external {
        _atLeastRole(ADMIN);
        require(degradation <= DEGRADATION_COEFFICIENT, "Degradation cannot be more than 100%");
        lockedProfitDegradation = degradation;
        emit LockedProfitDegradationUpdated(degradation);
    }

And lockedProfitDegradation is used to calculate the locked profit.

    function _calculateLockedProfit() internal view returns (uint256) {
        uint256 lockedFundsRatio = (block.timestamp - lastReport) * lockedProfitDegradation;
        if (lockedFundsRatio < DEGRADATION_COEFFICIENT) {
            return lockedProfit - ((lockedFundsRatio * lockedProfit) / DEGRADATION_COEFFICIENT);
        }

        return 0;
    }

But it doesn’t update lockedProfit and lastReport before changing lockedProfitDegradation so the below scenario would be possible.

  1. Let’s assume lockedProfit = 200, lastReport = block.timestamp after calling report(), lockedProfitDegradation are 6 hours in blocks.
  2. 3 hours later, 100 tokens of lockedProfit are released and added to the free funds. We can assume report() wasn’t called for 3 hours.
  3. At that time, lockedProfitDegradation is changed to 4 hours in blocks and it means 200 * 3 / 4 = 150 tokens are released. As a result, free funds are increased by 50 inside the same block.
  4. So a malicious user(it should be a pool) can front run deposit() with huge amounts before lockedProfitDegradation is changed and charge most of the new rewards(=50).

Similarly, already unlocked funds will be treated as locked again if lockedProfitDegradation is decreased.

Even if there is no front run as all depositors are pools, it’s not fair to change locked/unlocked amounts that are confirmed already.

Recommended Mitigation Steps

We should modify setLockedProfitDegradation() like below.

    function setLockedProfitDegradation(uint256 degradation) external {
        _atLeastRole(ADMIN);
        require(degradation <= DEGRADATION_COEFFICIENT, "Degradation cannot be more than 100%");

        // update lockedProfit and lastReport
        lockedProfit = _calculateLockedProfit();
        lastReport = block.timestamp;

        lockedProfitDegradation = degradation;
        emit LockedProfitDegradationUpdated(degradation);
    }

Trust (judge) increased severity to High

tess3rac7 (Ethos Reserve) disagreed with severity and commented:

I don’t think this qualifies as a “high”. It relies on a large harvest, followed by no harvests for a considerable amount of time, followed by the ADMIN (multisig) calling setLockedProfitDegradation() to set the degradation to a smaller value and being front-run by a malicious user calling deposit().

  • depositors are whitelisted via the DEPOSITOR role, so in this case they are trusted
  • the ADMIN multisig wouldn’t randomly change the degradation value without a really good reason to do so
  • even if a whitelisted depositor turns malicious, and the ADMIN multisig ends up invoking setLockedProfitDegradation(), and ADMIN’s TX gets front-run by said malicious depositor, it would, at best, result in some extra yield being squeezed by the malicious depositor—ONLY IF they have enough capital to overshadow the vault’s TVL. There would be no loss of principal assets whatsoever for any depositor.

There is slim chance for favorable conditions for this type of attack to succeed, and the capital requirements for the attacker would be quite high. And even after doing all this, they would at best earn a few more tokens out of the locked yield without impact any other user’s deposits. It’s not even a repeatable attack because ADMIN won’t keep calling setLockedProfitDegradation() over and over. Very low risk in my opinion.

Trust (judge) decreased severity to Medium


The original report as published on Code4rena, by hansfriese. 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 setter changes the degradation rate without first checkpointing the locked profit and last report time, so the new rate is applied retroactively to the whole elapsed period.

Impact

A malicious depositor could capture extra yield, but only if they have enough capital to overshadow the vault's total value locked, and there is no loss of principal; the project argued the conditions are unlikely and the admin would not change the rate often.

What the attacker needed

Admin changes the degradation rate; attacker is a whitelisted depositor; attacker front-runs the admin transaction; attacker has large capital

The fix

The setter should first update the locked profit and last report time using the old rate, then apply the new degradation rate.

How it was found

  1. A report sets locked profit and last report time with a six-hour degradation rate.
  2. Three hours pass without another report, so part of the locked profit is considered unlocked.
  3. The admin changes the degradation rate to four hours, which recalculates the whole three-hour period and releases more profit.
  4. A malicious depositor front-runs the admin's transaction with a large deposit to capture most of the newly released profit.

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 vault holds profit that unlocks gradually over time. The speed of unlocking is set by an admin. If the admin changes that speed, the contract recalculates the whole past period at the new speed, which can suddenly release more profit. Someone who sees the admin's change coming can deposit just before it and take a share of that extra profit.

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 hansfriese

View all

65 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.