Skip to content
Access control Audit finding Intermediate

Attacker can deploy vaults with a malicious Staking contract

The vault deployment function accepts any staking contract address without checking it against approved templates. An attacker can deploy a vault with a malicious staking contract that has a backdoor to withdraw all deposited funds, leading users to lose funds.

gjaldon Follow with Ch_301, KIntern_NA and 1 other

Originally disclosed on Code4rena

Submitted by gjaldon, also found by Ch_301, KIntern_NA, and mookimgo

https://github.com/code-423n4/2023-01-popcorn/blob/main/src/vault/VaultController.sol#L106-L110

https://github.com/code-423n4/2023-01-popcorn/blob/main/src/vault/VaultRegistry.sol#L44-L53

Impact

Anyone can deploy a Vault with a malicious Staking contract attached. If the Staking contract already exists, we can just pass its address to deployVault and no checks will be applied to see whether the Staking contract matches valid Staking templates in the Template Registry.

An attacker can create malicious Staking contract that acts like a regular ERC-4626 vault but with a backdoor function that allows them to withdraw all the deposited funds in the contract. Users may assume the Staking contract is valid and safe and will deposit their funds into it. This will lead to loss of funds for users and huge loss of credibility for the protocol.

Proof of Concept

The below PoC shows the behavior described above where any Staking contract can be deployed with a Vault. The below lines will need to be added to the VaultController.t.sol file.

  function test__deploy_malicious_staking_contract() public {
    addTemplate("Adapter", templateId, adapterImpl, true, true);
    addTemplate("Strategy", "MockStrategy", strategyImpl, false, true);
    addTemplate("Vault", "V1", vaultImpl, true, true);

    // Pretend this malicious Staking contract allows attacker to withdraw
    // all the funds from it while allowing users to use it like a normal Staking contract
    MultiRewardStaking maliciousStaking = new MultiRewardStaking();

    vm.startPrank(alice);
    address vault = controller.deployVault(
      VaultInitParams({
        asset: iAsset,
        adapter: IERC4626(address(0)),
        fees: VaultFees({
          deposit: 100,
          withdrawal: 200,
          management: 300,
          performance: 400
        }),
        feeRecipient: feeRecipient,
        owner: address(this)
      }),
      DeploymentArgs({ id: templateId, data: abi.encode(uint256(100)) }),
      DeploymentArgs({ id: 0, data: "" }),
      address(maliciousStaking),
      "",
      VaultMetadata({
        vault: address(0),
        staking: address(maliciousStaking),
        creator: alice,
        metadataCID: metadataCid,
        swapTokenAddresses: swapTokenAddresses,
        swapAddress: address(0x5555),
        exchange: uint256(1)
      }),
      0
    );
    vm.stopPrank();

    assertEq(vaultRegistry.getVault(vault).staking, address(maliciousStaking));
  }

The test can be run with the following command: forge test --no-match-contract 'Abstract' --match-test test__deploy_malicious_staking_contract

Tools Used

VS Code, Foundry

Recommended Mitigation Steps

Add checks to verify that the Staking contract being used in deployVault is a Staking contract that was deployed by the system and uses an approved template:

https://github.com/code-423n4/2023-01-popcorn/blob/main/src/vault/VaultController.sol#L106-L110

RedVeil (Popcorn) confirmed


The original report as published on Code4rena, by gjaldon. 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 deployVault function does not verify that the provided staking contract address matches an approved template in the Template Registry.

Impact

Users could lose all funds deposited into the malicious staking contract, and the protocol's credibility may suffer.

What the attacker needed

Attacker can deploy a vault; users deposit into the malicious staking contract

The fix

The deployVault function should verify that the staking contract was deployed by the system and uses an approved template.

How it was found

  1. Create a malicious staking contract that behaves like a normal ERC-4626 vault but includes a backdoor function to withdraw all funds.
  2. Call deployVault with the malicious staking contract address.
  3. The vault is deployed and registered with the malicious staking contract.
  4. Users deposit funds into the staking contract, believing it is legitimate.
  5. The attacker uses the backdoor to withdraw all deposited funds.

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 staking contract is where users lock their tokens to earn rewards. The system lets anyone create a vault and attach any staking contract, even a fake one. The fake contract looks normal but has a secret function that lets the attacker take all the money users put in.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

More by gjaldon

View all

6 more disclosed reports, best first.

More from Popcorn contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.