Users can abuse discrepancies between oracle and true asset price to mint more OHM than needed and profit from it
The vault mints OHM based on an on-chain oracle price that can deviate from the true asset price, and then joins a Balancer pool using an exact-tokens-in method that forces a swap at the pool's current ratio. An attacker can time the oracle to mint more OHM than needed and profit when the oracle updates.
Source: https://github.com/sherlock-audit/2023-03-olympus-judging/issues/5
Found by
0x52
Summary
All chainlink oracles have a deviation threshold between the current price of the asset and the on-chain price for that asset. The more oracles used for determining the price the larger the total discrepancy can be. These can be combined and exploited to mint more OHM than expected and profit.
Vulnerability Detail
uint256 ohmWstethPrice = manager.getOhmTknPrice();
uint256 ohmMintAmount = (amount_ * ohmWstethPrice) / _WSTETH_DECIMALS;
// Block scope to avoid stack too deep
{
// Cache OHM-wstETH BPT before
uint256 bptBefore = liquidityPool.balanceOf(address(this));
// Transfer in wstETH
wsteth.safeTransferFrom(msg.sender, address(this), amount_);
// Mint OHM
manager.mintOhmToVault(ohmMintAmount);
// Join Balancer pool
_joinBalancerPool(ohmMintAmount, amount_, minLpAmount_);
The amount of OHM to mint and deposit is determined by the calculated price from the on-chain oracle prices.
uint256[] memory maxAmountsIn = new uint256[](2);
maxAmountsIn[0] = ohmAmount_;
maxAmountsIn[1] = wstethAmount_;
JoinPoolRequest memory joinPoolRequest = JoinPoolRequest({
assets: assets,
maxAmountsIn: maxAmountsIn,
userData: abi.encode(1, maxAmountsIn, minLpAmount_),
fromInternalBalance: false
});
To make the issue worse, _joinBalancerPool use 1 for the join type. This is the EXACT_TOKENS_IN_FOR_BPT_OUT method of joining. What this means is that the join will guaranteed use all input tokens. If the current pool isn't balanced in the same way then the join request will effectively swap one token so that the input tokens match the current pool. Now if the ratio is off then too much OHM will be minted and will effectively traded for wstETH. This allows the user to withdraw at a profit once the oracle has been updated the discrepancy is gone.
Impact
Users can always time oracles so that they enter at an advantageous price and the deficit is paid by Olympus with minted OHM
Code Snippet
Tool used
Manual Review
Recommendation
The vault needs to have withdraw and/or deposit fees to make attacks like this unprofitable.
Discussion
0xLienid
Similar underlying issues to #027 and #051. Solving one should solve all of them.
0xLienid
Fix Implementation: https://github.com/0xLienid/sherlock-olympus/pull/8/files
Discussion
0xLienid
Similar underlying issues to #027 and #051. Solving one should solve all of them.
0xLienid
Fix Implementation: https://github.com/0xLienid/sherlock-olympus/pull/8/files
IAm0x52
Fix looks good. Contract now uses the lesser of pool and oracle price to determine how much OHM to mint
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 relies solely on a manipulable oracle price to determine minting amount and uses an exact-tokens-in join that forces a swap at the pool's ratio, without fees to deter arbitrage.
What the attacker needed
Ability to deposit wstETH into the vault; oracle price deviates from true price
The fix
The vault should use the lesser of the pool price and the oracle price to determine how much OHM to mint, and/or add deposit/withdrawal fees to make such attacks unprofitable.
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 price oracle is a service that reports an asset's price on-chain, but it can be slightly out of date. The vault uses this price to decide how much new currency (OHM) to create when someone deposits another token. Because the vault then forces a trade at the pool's current ratio, an attacker can deposit when the oracle is wrong and later profit when it corrects.