**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.
Submitted by 0xBeirao
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:
-
A Vault owner wants to change the underlying
**Adapter** -
Owner calls the
**proposeAdapter()**and then**changeAdapter()**that will call the**redeem()**adapter function : -
Here the goal is to empty the Strategy and Adapter underlying contracts of the Vault to make a safe adapter change.
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
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
- The vault owner proposes a new adapter and then calls changeAdapter, which calls redeem on the old adapter.
- The redeem function is meant to empty the strategy and adapter, but it does not force a harvest.
- If harvest is in cooldown or reverts, it does not run and the adapter is changed anyway.
- 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.