Skip to content
DoS Audit finding Intermediate

New strategy can not work due to insufficient allowance

When a new strategy is added to MultiStrategyVault, it is not approved to spend the vault's asset. Any function that calls the new strategy's deploy() may revert, causing a denial of service for the vault.

0xpiken Follow with 0xlemon, klau5 and 1 other

Originally disclosed on Code4rena

Submitted by 0xpiken, also found by 0xlemon, klau5, and shaflow2

When a new strategy is added through MultiStrategy#addStrategy(), it was not approved to spend the asset in MultiStrategyVault. Any functions that call newStrategy#deploy() may revert and result in MultiStrategyVault being DoS’ed.

Proof of Concept

MultiStrategyVault is used to manage multiple investment strategies. A new strategy can be added through MultiStrategy#addStrategy():

107:    function addStrategy(IStrategy strategy) external onlyRole(VAULT_MANAGER_ROLE) {
108:        if (address(strategy) == address(0)) revert InvalidStrategy();
109:        _strategies.push(strategy);
110:        _weights.push(0);
111:        emit AddStrategy(address(strategy));
112:    }

However, the new strategy was not approved to spend the asset in MultiStrategyVault, resulting MultiStrategyVault being DoS’ed.

Copy below codes to VaultMultiStrategy.ts and run npm run test:

  it.only('Add Strategy - no allowance', async () => {
    const { vault, usdc, owner, otherAccount } = await loadFixture(deployMultiStrategyVaultFixture);

    //@audit-info deploy a new strategy
    const Strategy = await ethers.getContractFactory('StrategySupplyAAVEv3');
    const strategy = await Strategy.deploy(
      owner.address,
      await usdc.getAddress(),
      otherAccount.address,
    );
    await strategy.waitForDeployment();
    //@audit-info add the new strategy to vault
    await vault.addStrategy(await strategy.getAddress());
    //@audit-info the new strategy has been added
    expect(await vault.strategies()).to.include(await strategy.getAddress());
    expect(await vault.asset()).to.equal(await usdc.getAddress());
    //@audit-info however, the new strategy was not approved to spend asset of vault
    expect(await usdc.allowance(vault.target, strategy.target)).to.equal(0);
  });

As we can see, the new strategy has zero allowance.

Recommended mitigation steps

The new strategy should be approved with max allowance when added:

    function addStrategy(IStrategy strategy) external onlyRole(VAULT_MANAGER_ROLE) {
        if (address(strategy) == address(0)) revert InvalidStrategy();
        _strategies.push(strategy);
        _weights.push(0);
+       IERC20(strategy.asset()).approve(address(strategy), type(uint256).max);
        emit AddStrategy(address(strategy));
    }

chefkenji (BakerFi) confirmed

BakerFi mitigated:

PR-13

Status: Mitigation confirmed. Full details in reports from 0xlemon and shaflow2.


The original report as published on Code4rena, by 0xpiken. 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 addStrategy function does not approve the new strategy to spend the vault's asset.

Impact

Functions that call the new strategy's deploy() may revert, causing a denial of service for the vault.

What the attacker needed

Vault manager role

The fix

The addStrategy function should approve the new strategy to spend the vault's asset with maximum allowance.

How it was found

  1. Deploy a new strategy contract.
  2. Call addStrategy on the vault with the new strategy's address.
  3. Observe that the strategy is added but the vault's asset allowance for the strategy is zero.

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 holds money and lets different strategies invest it. For a strategy to take money from the vault, the vault must first give it permission, called an allowance. The vault forgot to give this permission when adding a new strategy, so the strategy cannot take the money and any attempt to use it 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 0xpiken

View all

29 more disclosed reports, best first.

More from BakerFi Invitational

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.