_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.
Submitted by klau5, also found by 0xlemon, 0xpiken, MrPotatoMagic, pfapostol, and shaflow2
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,
getBalancereturns A + profit -
Request to withdraw amount B
_deployedAmountis still AgetBalancereturns A + profit - B
-
During rebalance,
balanceChangeis (A + profit - B) - A- That is, if
profit <= B, the Strategy is considered to have a loss.
- That is, if
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
Status: Mitigation confirmed. Full details in reports from shaflow2 and 0xlemon.
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
- Deploy a strategy with a known amount of assets.
- Simulate profit by minting extra aTokens to the strategy.
- Call undeploy to withdraw part of the assets.
- 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.