M-03 YTokenOracle doesn't account for losses when pricing the yToken
The YTokenOracle contract prices Yearn vault tokens as if a full withdrawal always returns the full underlying amount, ignoring that Yearn vaults can incur losses on withdrawal. An attacker could borrow more than the vault can actually liquidate, then self-liquidate to cause a loss and profit.
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2022-08-sentiment-judging/tree/main/204-M
Found by
GalloDaSballo
Summary
Yearn vaults use multiple strategies, some of them can incurr a loss, the loss will be charged to the caller when withdrawing (the caller being the protocol).
The Ytoken.getPrice incorrectly assumes that a withdrawal of 10 ** decimals is equivalent to a bigger withdrawal.
Because of the Yearn V2 codebase, we can see that a loss may happen on withdraw: https://github.com/yearn/yearn-vaults/blob/efb47d8a84fcb13ceebd3ceb11b126b323bcc05d/contracts/Vault.vy#L1074
Meaning that using the 10 ** decimals price for quoting is incorrect as it doesn't represent the total liquidatable assets, which may be very different (especially for tokens that use multiple strategies, especially levered strategies such as Levered AAVE, Levered COMP etc..)
Vulnerability Detail
- Attacker knows vault can only withdraw up to 50% of the underlying before getting rekt
- Attacker borrows 100% of token value, the oracle allows this as the oracle only checks for the price of 10 ** decimals tokens
- Attacker purposefully get's liquidated
- The system withdraws from the yearn vault and incurs a loss
- Attacker has ran away with more value than intended
- Additionally, self-liquidation may be used as if the Yearn Vault is using any liquidity pool to liquidate to token, the imbalance caused by the withdrawal could itself create an opportunity for an arbitrage
Impact
Oracle will allow to borrow more than what is liquidatable from the yVault
Tool used
Manual Review
Recommendation
Refactor getPrice(address) to getPrice(address, amount) and pass in the exact amount to ensure it can be liquidated fully without a loss
Alternatively cap the Yearn tokens to a massively small LTV (35% is probably as high as you should go without simming on a token by token basis)
Sentiment Team
Not fixing since we don't plan to launch with Yearn. We are okay with not including this contract in the coverage scope since it won't be deployed.
Lead Senior Watson
Acknowledged.
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 oracle prices yTokens using a fixed 10**decimals amount without accounting for potential losses on withdrawal from Yearn vaults.
What the attacker needed
Yearn vault tokens used as collateral; Attacker can borrow against them; Attacker can self-liquidate
The fix
The recommendation is to refactor getPrice to accept the exact amount and ensure it can be liquidated fully without loss, or alternatively cap the Yearn tokens to a very low LTV (e.g., 35%).
How it was found
- Attacker knows the vault can only withdraw up to 50% of the underlying before incurring a loss.
- Attacker borrows 100% of the token value, which the oracle permits because it only checks the price of 10**decimals tokens.
- Attacker deliberately gets liquidated.
- The system withdraws from the Yearn vault and incurs a loss.
- Attacker walks away with more value than intended.
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 Yearn vault is like a savings account that invests your money in strategies; sometimes those strategies lose money, so when you withdraw you get back less than you put in. The oracle (a price feed) assumed you always get the full amount back, so it overvalued the vault tokens. An attacker could borrow against that inflated value, then let their position be liquidated, leaving the protocol with the loss.
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.