Vault deposit into Alchemix can suffer slippage depending on outstanding debt in Yearn
Summary
Depending on the outstanding debt in Yearn, a WETH deposit into Alchemix when register_deposit is called upon settling an auction may suffer from slippage.
Vulnerability Detail
Upon an auction settlement, the Vault(self.vault).register_deposit(token_id, winning_amount) call transfers the winning bid amount of WETH from the AuctionHouse to the Vault, then deposits the WETH into the Alchemix ALCX_YVWETH vault.
// Before depositing, the underlying tokens must be wrapped into yield tokens.
uint256 amountYieldTokens = _wrap(yieldToken, amount, minimumAmountOut);
A WETH deposit may not entitle the winner of the auction to a claim of the same value, they may lose in the process due to that initial slippage upon deposit.
Use a higher slippage, perhaps allowing the Vault to compute the expected shares received before a call to IAlchemist(self.alchemist).depositUnderlying()
joestakey
medium
Vault deposit into
Alchemix
can suffer slippage depending on outstanding debt inYearn
Summary
Depending on the outstanding debt in
Yearn
, a WETH deposit into Alchemix whenregister_deposit
is called upon settling an auction may suffer from slippage.Vulnerability Detail
Upon an auction settlement, the
Vault(self.vault).register_deposit(token_id, winning_amount)
call transfers the winning bid amount ofWETH
from theAuctionHouse
to theVault
, then deposits theWETH
into the AlchemixALCX_YVWETH
vault.The call stack of
depositUnderlying()
inAlchemist
is as follows: AlchemistV2.depositUnderlying -> AlchemistV2._wrap() -> AlchemistAdapter.wrap()https://github.com/alchemix-finance/v2-foundry/blob/f4a60d6363ada8b9648ab57df42618a4647fb12d/src/AlchemistV2.sol#L601-L602
https://github.com/alchemix-finance/v2-foundry/blob/f4a60d6363ada8b9648ab57df42618a4647fb12d/src/AlchemistV2.sol#L1348-L1349
https://github.com/alchemix-finance/v2-foundry/blob/f4a60d6363ada8b9648ab57df42618a4647fb12d/src/adapters/yearn/YearnTokenAdapter.sol#L35
The issue is that this function issues shares based on the total outstanding debt of the contract, meaning shares are issued against the total amount that the deposited capital can be given in service of the debt that Strategies assume. This mean that between strategies updates, there can be discrepancies, leading to slippage (see https://github.com/yearn/yearn-vaults/blob/7e0718b709d38769700bd458381e1b19ea8e67ca/contracts/Vault.vy#L878-L892)
Impact
A
WETH
deposit may not entitle the winner of the auction to a claim of the same value, they may lose in the process due to that initial slippage upon deposit.Code Snippet
https://github.com/sherlock-audit/2023-02-fair-funding/blob/main/fair-funding/contracts/AuctionHouse.vy#L212 https://github.com/sherlock-audit/2023-02-fair-funding/blob/main/fair-funding/contracts/Vault.vy#L293-L299
Tool used
Manual Review
Recommendation
Use a higher slippage, perhaps allowing the
Vault
to compute the expected shares received before a call toIAlchemist(self.alchemist).depositUnderlying()