Skip to content
Audit finding Advanced

Adversary can sandwich oracle updates to exploit vault

The vault's mitigation against price manipulation could be bypassed by sandwiching oracle updates. An attacker could profit by manipulating the pool price before an oracle update and then withdrawing after the update, causing repeated losses to the vault.

0x52 Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-03-olympus-judging/issues/1

Found by

0x52

Summary

BLVaultLido added a mechanism to siphon off all wstETH obtained from mismatched pool and oracle prices. This was implemented to fix the problem that the vault could be manipulated to the attackers gain. This mitigation however does not fully address the issue and the same issue is still exploitable by sandwiching oracle update.

Vulnerability Detail

BLVaultLido.sol#L232-L240

    uint256 wstethOhmPrice = manager.getTknOhmPrice();
    uint256 expectedWstethAmountOut = (ohmAmountOut * wstethOhmPrice) / _OHM_DECIMALS;

    // Take any arbs relative to the oracle price for the Treasury and return the rest to the owner
    uint256 wstethToReturn = wstethAmountOut > expectedWstethAmountOut
        ? expectedWstethAmountOut
        : wstethAmountOut;
    if (wstethAmountOut > wstethToReturn)
        wsteth.safeTransfer(TRSRY(), wstethAmountOut - wstethToReturn);

In the above lines we can see that the current oracle price is used to calculate the expected amount of wstETH to return to the user. In theory this should prevent the attack but an attacker can side step this sandwiching the oracle update.

Example:

The POC is very similar to before except now it's composed of two transactions sandwiching the oracle update. Chainlink oracles have a tolerance threshold of 0.5% before updating so we will use that as our example value. The current price is assumed to be 0.995 wstETH/OHM. The oracle price (which is about to be updated) is currently 1:1

Transaction 1:

Balances before attack (0.995:1)
Liquidity: 79.8 OHM 80.2 wstETH
Adversary: 20 wstETH

Swap OHM so that pool price matches pre-update oracle price:
Liquidity: 80 OHM 80 wstETH
Adversary: -0.2 OHM 20.2 wstETH

Balances after adversary has deposited to the pool:
Liquidity: 100 OHM 100 wstETH
Adversary: -0.2 OHM 0.2 wstETH

Balances after adversary sells wstETH for OHM (0.5% movement in price):
Liquidity: 99.748 OHM 100.252 wstETH
Adversary: 0.052 OHM -0.052 wstETH

Sandwiched Oracle Update:

Oracle updates price of wstETH to 0.995 OHM. Since the attacker already sold wstETH to balance 
the pool to the post-update price they will be able to withdraw the full amount of wstETH.

Transaction 2:

Balances after adversary removes their liquidity:
Liquidity: 79.798 OHM 80.202 wstETH
Adversary: 0.052 OHM 19.998 wstETH

Balances after selling profited OHM:
Liquidity: 79.849 OHM 80.152 wstETH
Adversary: 20.05 wstETH

As shown above it's still profitable to exploit the vault by sandwiching the oracle updates. With each oracle update the pool can be repeatedly attacked causing large losses.

Impact

Vault will be attacked repeatedly for large losses

Code Snippet

https://github.com/sherlock-audit/2023-03-olympus/blob/main/sherlock-olympus/src/policies/BoostedLiquidity/BLVaultLido.sol#L203-L256

Tool used

Manual Review

Recommendation

To prevent this I would recommend locking the user into the vault for some minimum amount of time (i.e. 24 hours)

Discussion

0xLienid

This is kind of similar to #029 in terms of underlying cause (knowledge of oracle update price)

0xLienid

Fix Implementation: https://github.com/0xLienid/sherlock-olympus/pull/3/files

Discussion

0xLienid

This is kind of similar to #029 in terms of underlying cause (knowledge of oracle update price)

0xLienid

Fix Implementation: https://github.com/0xLienid/sherlock-olympus/pull/3/files

IAm0x52

Fix looks good. Contract now enforces delay between deposit and withdrawal

The original report as published on Sherlock, by 0x52. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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 vault calculates the expected return using the current oracle price, but an attacker can manipulate the pool price to match the pre-update oracle price and then profit when the oracle updates.

Impact

The vault could be attacked repeatedly for large losses.

What the attacker needed

Attacker can trade in the pool; oracle updates are predictable

The fix

The fix enforces a delay between deposit and withdrawal, as confirmed by the auditor.

How it was found

  1. Swap OHM so that pool price matches pre-update oracle price
  2. Deposit to the pool
  3. Sell wstETH for OHM to move price by 0.5%
  4. Oracle updates price of wstETH to 0.995 OHM
  5. Remove liquidity
  6. Sell profited OHM

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 uses an oracle to set a fair price for swapping tokens. An attacker can trade just before the oracle updates to make the vault give them more tokens than they should get, and then trade back after the update to profit. This means the vault loses money each time the oracle updates.

More by 0x52

View all

211 more disclosed reports, best first.

More from Olympus RBS 2.0

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.