Skip to content
Business logic Audit finding Intermediate

_deployedAmount not updated on StrategySupplyBase.undeploy , preventing performance fees from being collected

The undeploy function in StrategySupplyBase fails to reduce the tracked deployed amount when funds are withdrawn. As a result, after a withdrawal the harvest logic can misreport a loss even when interest was earned, preventing performance fees from being collected.

klau5 Follow with 0xlemon, 0xpiken and 3 others

Originally disclosed on Code4rena

Submitted by klau5, also found by 0xlemon, 0xpiken, MrPotatoMagic, pfapostol, and shaflow2

https://github.com/code-423n4/2024-12-bakerfi/blob/0daf8a0547b6245faed5b6cd3f5daf44d2ea7c9a/contracts/core/strategies/StrategySupplyBase.sol#L110

Finding description and impact

StrategySupplyBase.undeploy does not update _deployedAmount. As a result, if a withdrawal occurs, even if interest is generated, the protocol cannot collect performance fees through rebalance.

Proof of Concept

StrategySupplyBase.undeploy does not update _deployedAmount. It should subtract the amount of withdrawn asset tokens.

function undeploy(uint256 amount) external nonReentrant onlyOwner returns (uint256 undeployedAmount) {
    if (amount == 0) revert ZeroAmount();

    // Get Balance
    uint256 balance = getBalance();
    if (amount > balance) revert InsufficientBalance();

    // Transfer assets back to caller
    uint256 withdrawalValue = _undeploy(amount);

    // Check withdrawal value matches the initial amount
    // Transfer assets to user
    ERC20(_asset).safeTransfer(msg.sender, withdrawalValue);

    balance -= amount;
    emit StrategyUndeploy(msg.sender, withdrawalValue);
    emit StrategyAmountUpdate(balance);

    return amount;
}

As a result, if a withdrawal occurs, even if interest is generated, the protocol cannot collect performance fees through rebalance. This is because if the withdrawal amount is greater than the interest earned, the Strategy is considered to have a loss and no fee is taken.

  • _deployedAmount: A

  • Interest generated, getBalance returns A + profit

  • Request to withdraw amount B

    • _deployedAmount is still A
    • getBalance returns A + profit - B
  • During rebalance, balanceChange is (A + profit - B) - A

    • That is, if profit <= B, the Strategy is considered to have a loss.
function harvest() external returns (int256 balanceChange) {
    // Get Balance
    uint256 newBalance = getBalance();

@>  balanceChange = int256(newBalance) - int256(_deployedAmount);

    if (balanceChange > 0) {
        emit StrategyProfit(uint256(balanceChange));
    } else if (balanceChange < 0) {
        emit StrategyLoss(uint256(-balanceChange));
    }
    if (balanceChange != 0) {
        emit StrategyAmountUpdate(newBalance);
    }
    _deployedAmount = newBalance;
}

This is PoC. This shows that when harvested after withdrawal, the Strategy is considered to have a loss. This can be executed by adding it to the StrategySupplyAAVEv3.ts file.

it('PoC - harvest returns loss after undeloy', async () => {
  const { owner, strategySupply, stETH, aave3Pool, otherAccount } = await loadFixture(
    deployStrategySupplyFixture,
  );
  const deployAmount = ethers.parseEther('10');
  await stETH.approve(await strategySupply.getAddress(), deployAmount);
  await strategySupply.deploy(deployAmount);

  //artificial profit
  const profit = ethers.parseEther('1');
  await aave3Pool.mintAtokensArbitrarily(await strategySupply.getAddress(), profit);

  // Undeploy
  const undeployAmount = ethers.parseEther('2');
  await strategySupply.undeploy(undeployAmount);

  await expect(strategySupply.harvest())
    .to.emit(strategySupply, 'StrategyLoss')
    .to.emit(strategySupply, 'StrategyAmountUpdate');
});

Recommended Mitigation Steps

Update _deployedAmount by the withdrawal amount in StrategySupplyBase.undeploy.

chefkenji (BakerFi) confirmed

BakerFi mitigated:

PR-12

Status: Mitigation confirmed. Full details in reports from shaflow2 and 0xlemon.


The original report as published on Code4rena, by klau5. 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

The undeploy function transfers assets out but does not subtract the withdrawn amount from the _deployedAmount state variable.

Impact

If the withdrawal amount is greater than the interest earned, the strategy is treated as having a loss and no performance fee is taken, so the protocol may lose fee revenue.

What the attacker needed

Strategy has deployed assets; a withdrawal occurs; withdrawal amount exceeds interest earned

The fix

The undeploy function should subtract the withdrawn amount from _deployedAmount.

How it was found

  1. Deploy a strategy with a known amount of assets.
  2. Simulate profit by minting extra aTokens to the strategy.
  3. Call undeploy to withdraw part of the assets.
  4. Call harvest and observe that it emits a loss event instead of a profit event.

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 keeps a record of how much money it has put to work. When some money is taken out, that record is not updated, so later the contract compares the new smaller balance with the old larger record and thinks it lost money. Because it thinks there is a loss, it does not charge the performance fee it normally would.

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 klau5

View all

21 more disclosed reports, best first.

More from BakerFi Invitational

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.