Medium: Consider alternative price feed + ensure _minLockPeriod > 0 to prevent flash loan attacks
The vault's minimum lock period could be set to zero, and the strategy used a manipulatable spot price from a Curve pool. An attacker could use a flash loan to manipulate the pool price, deposit funds to receive more shares than deserved, then withdraw for a profit.
Submitted by hickuphh3, also found by 0x1f8b
It is critical to ensure that _minLockPeriod > 0 because it is immutable and cannot be changed once set. A zero minLockPeriod will allow for flash loan attacks to occur. Vaults utilising the nonUST strategy are especially susceptible to this attack vector since the strategy utilises the spot price of the pool to calculate the total asset value.
Proof of Concept
Assume the vault’s underlying token is MIM, and the curve pool to be used is the MIM-UST pool. Further assume that both the vault and the strategy holds substantial funds in MIM and UST respectively.
- Flash loan MIM from the Uniswap V3 MIM-USDC pool (currently has ~$3.5M in MIM at the time of writing).
- Convert half of the loaned MIM to UST to inflate and deflate their prices respectively.
- Deposit the other half of the loaned MIM into the vault. We expect
curvePool.get_dy_underlying(ustI, underlyingI, ustAssets);to return a smaller amount than expected because of the previous step. As a result, the attacker is allocated more shares than expected. - Exchange UST back to MIM, bringing back the spot price of MIM-UST to a normal level.
- Withdraw funds from the vault. The number of shares to be deducted is lower as a result of (4), with the profit being accounted for as yield.
- Claim yield and repay the flash loan.
Recommended Mitigation Steps
Ensure that _minLockPeriod is non-zero in the constructor. Also, given how manipulatable the spot price of the pool can be, it would be wise to consider an alternative price feed.
// in Vault#constructor
require(_minLockPeriod > 0, 'zero minLockPeriod');
ryuheimat (Sandclock) disputed:
we don’t think it’s an issue.
This does potentially open assets up to flash loan risk. It is probably a good idea to have this variable guarded.
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 allowed a zero minimum lock period and relied on a spot price that can be manipulated within a single transaction.
Impact
An attacker could steal funds from the vault by manipulating the pool price, though the report notes this is especially relevant for the nonUST strategy and the project disputed the issue.
What the attacker needed
Vault uses nonUST strategy; minLockPeriod set to zero; attacker can flash loan MIM
The fix
The minimum lock period should be required to be greater than zero in the constructor, and an alternative price feed should be considered.
How it was found
- Flash loan MIM from the Uniswap V3 MIM-USDC pool.
- Convert half of the loaned MIM to UST to inflate and deflate their prices respectively.
- Deposit the other half of the loaned MIM into the vault, expecting to receive more shares than normal due to the manipulated price.
- Exchange UST back to MIM to restore the normal spot price.
- Withdraw funds from the vault, with the profit accounted for as yield.
- Claim yield and repay the flash loan.
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 flash loan lets someone borrow a huge amount of cryptocurrency for a very short time, as long as they return it in the same transaction. Here, the attacker could use that borrowed money to temporarily change the price of a trading pool, tricking the vault into giving them more shares than they should get. Then they undo the price change and cash out at a profit.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.