Skip to content
Business logic Audit finding Intermediate

**Harvest()** may not be executed when changing a Vault adapter

When a vault owner changes the vault's adapter, the harvest function may not run if it is in cooldown or reverts, so unclaimed rewards from the strategy are lost. This can cause a loss of user funds.

0xBeirao Follow

Originally disclosed on Code4rena

Submitted by 0xBeirao

https://github.com/code-423n4/2023-01-popcorn/blob/d95fc31449c260901811196d617366d6352258cd/src/vault/Vault.sol#L594-L613

https://github.com/code-423n4/2023-01-popcorn/blob/d95fc31449c260901811196d617366d6352258cd/src/vault/adapter/abstracts/AdapterBase.sol#L162

Impact

Changing the adapter (that uses a strategy) of an already credited vault can result in a loss of user funds.

Proof of Concept

Scenario:

Issue scenario 1 : the **harvest()** function is in cooldown.

Issue scenario 2 : the **harvest()** function revert.

In both cases, the **harvest()** function will not execute. The adapter will change without harvesting from the Strategy causing the loss of unclaimed rewards.

Recommended Mitigation Steps

Change the harvest() function from :

function harvest() public takeFees {
    if (
        address(strategy) != address(0) &&
        ((lastHarvest + harvestCooldown) < block.timestamp)
    ) {
        // solhint-disable
        address(strategy).delegatecall(
            abi.encodeWithSignature("harvest()")
        );
    }

    emit Harvested();
}

to :

function harvest() public takeFees {
    if (
        address(strategy) == address(0) ||
        ((lastHarvest + harvestCooldown) > block.timestamp)
    ) {
        revert();  // Fixing the "Issue senario 1"
    }

    (bool success, ) = address(strategy).delegatecall(
        abi.encodeWithSignature("harvest()")
    );

    if (!success) revert(); // Fixing the "Issue senario 2"

    emit Harvested();
}

RedVeil (Popcorn) confirmed, but disagreed with severity

LSDan (judge) decreased severity to Medium


The original report as published on Code4rena, by 0xBeirao. 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 harvest function silently skips harvesting when the strategy is unset, the cooldown has not elapsed, or the delegatecall fails, instead of reverting to block the adapter change.

Impact

Changing the adapter can result in a loss of user funds because unclaimed rewards are not harvested.

What the attacker needed

Vault owner changes adapter; strategy has unclaimed rewards; harvest in cooldown or reverts

The fix

The harvest function should revert when there is no strategy, when the cooldown has not elapsed, or when the delegatecall fails, so the adapter change cannot proceed without harvesting.

How it was found

  1. The vault owner proposes a new adapter and then calls changeAdapter, which calls redeem on the old adapter.
  2. The redeem function is meant to empty the strategy and adapter, but it does not force a harvest.
  3. If harvest is in cooldown or reverts, it does not run and the adapter is changed anyway.
  4. Unclaimed rewards from the strategy are lost.

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 user money and uses an adapter to put that money into a strategy that earns rewards. Before swapping the adapter, the code should collect those rewards, but if the collection step is on a cooldown or fails, it is skipped and the rewards are left behind. That means users lose value that should have been theirs.

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 0xBeirao

View all

2 more disclosed reports, best first.

More from Popcorn 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.