Skip to content
Business logic Audit finding Advanced

Controller does not raise an error when there’s insufficient liquidity

The vault's controller failed to revert when it could not obtain enough liquidity to satisfy a withdrawal, so a user's shares were burned while they received nothing. An MEV searcher could sandwich a pending withdrawal to drain the available liquidity, causing the victim to lose their shares and pushing up the share price.

jonah1005 Follow

Originally disclosed on Code4rena

Submitted by jonah1005, also found by 0xRajeev and WatchPug

Impact

When a user tries to withdraw the token from the vault, the vault would withdraw the token from the controller if there’s insufficient liquidity in the vault. However, the controller does not raise an error when there’s insufficient liquidity in the controller/ strategies. The user would lose his shares while getting nothing.

An MEV searcher could apply this attack on any withdrawal. When an attacker found an unconfirmed tx that tries to withdraw 1M dai, he can do such sandwich attack.

  1. Deposits USDC into the vault.
  2. Withdraw all dai left in the vault/controller/strategy.
  3. Place the vitims tx here. The victim would get zero dai while burning 1 M share. This would pump the share price.
  4. Withdraw all liquidity.

All users would be vulnerable to MEV attackers. I consider this is a high-risk issue.

Proof of Concept

Here’s web3.py script to reproduce the issue.

deposit_amount = 100000 * 10**18
user = w3.eth.accounts[0]
get_token(dai, user, deposit_amount)
dai.functions.approve(vault.address, deposit_amount + margin_deposit).transact()
vault.functions.deposit(dai.address, deposit_amount).transact()
vault.functions.withdrawAll(usdt.address).transact()

#
print("usdt amount: ", usdt.functions.balanceOf(user).call())

Recommended Mitigation Steps

There are two issues involved. First, users pay the slippage when they try to withdraw. I do not find this fair. Users have to pay extra gas to withdraw liquidity from strategy, convert the token, and still paying the slippage. I recommend writing a view function for the frontend to display how much slippage the user has to pay (Controler.sol L448-L479).

Second, the controller does not revert the transaction there’s insufficient liquidity (Controller.sol#L577-L622).

Recommend to revert the transaction when _amount is not equal to zero after the loop finishes.

GainsGoblin (yAxis) acknowledged

GalloDaSballo (judge) commented:

Agree with warden finding, this shows the path for an attack that is based on the Vault treating all tokens equally Since the finding shows a specific attack, the finding is unique

Recommend the sponsor mitigates Single Sided Exposure risks to avoid this attack

BobbyYaxis (yAxis) noted:

We have mitigated by deploying vaults that only accept the Curve LP token itself used in the strategy. There is no longer an array of tokens accepted. E.g Instead of a wBTC vault, we have a renCrv vault. Or instead of 3CRV vault, we have a mimCrv vault. The strategy want token = the vault token.

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

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 controller's withdrawal loop does not check that the requested amount was fully satisfied and does not revert when a remainder is left.

Impact

Any user withdrawing could lose their shares and receive nothing, and an MEV attacker could deliberately trigger this to profit from the resulting share price increase.

What the attacker needed

Victim submits a withdrawal transaction; attacker can front-run and back-run it

The fix

The transaction should revert when the requested amount is not fully satisfied after the withdrawal loop, and the sponsor later mitigated by deploying vaults that only accept the strategy's own LP token.

How it was found

  1. Deposit USDC into the vault.
  2. Withdraw all dai left in the vault, controller and strategy.
  3. Let the victim's withdrawal transaction execute, burning their shares for zero dai.
  4. Withdraw all liquidity afterwards.

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 is a contract that pools users' tokens and gives them shares in return. When someone withdraws, the vault asks a controller to fetch the tokens, but here the controller silently returned fewer tokens than needed instead of stopping with an error, so the user's shares were destroyed for no payout.

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.

More by jonah1005

View all

39 more disclosed reports, best first.

More from yAxis contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.