Skip to content
Race condition Audit finding Advanced

Reorg attack on user’s Vault deployment and deposit may lead to theft of funds

The Vault contract is deployed using CREATE, so its address depends on the deployer's nonce. If a chain reorganisation removes the victim's deployment and deposit, an attacker can front-run the deployment to take control of the Vault at that address, then steal the victim's deposit.

ljmanini Follow

Originally disclosed on Code4rena

Submitted by ljmanini

VaultDeployer deploys instances of the Vault contract using create, where the address derivation depends on the sender’s address (= VaultDeployer) and its nonce.

Although the system is intended to be deployed on Ethereum, there still have been instances of chain reorgs in its PoS era : ref.

The frequency and depth of reorgs only increases in alternative L1s and L2s such as polygon and optimism, where reorgs have reached 100+ block depth : ref.

Proof of Concept

In a scenario in which a user’s Vault deplyoment and deposit is included fully within a reorg, an attacker is able to frontrun the user’s Vault deployment, effectively stealing the Vault instance at that particular address, include the user’s deployment (which will deploy a new Vault at a new, unrelated address) and his deposit to the originally deployed Vault, and finally backrun the user’s deposit by pulling funds from the Vault.

In order to pull off this attack successfully, the attacker needs to take care of some details:

  1. When frontrunning the Vault deployment, he must call VaultDeployer.deployVault() through a malicious contract under his control which implements the minimal interface to allow calls the Vault makes to the VaultController to not revert. Notice that this malicious VaultController could allow only deposits to go through in the Vault, but disallow withdrawals by returning false when Vault attempts to call CONTROLLER.checkVault within Vault.withdrawERC20.
  2. When frontrunning the Vault deployment, the attacker must set the Vault’s minter to the victim’s address, in order for the deposit to successfully go through within the Vault.

Once the victim’s deposit has been executed, the attacker can chose to pull the user’s funds from the compromised Vault by calling Vault.controllerTransfer through his malicious VaultController

Given the high impact of this finding but its low likelihood, I’m submitting this as a medium severity issue.

Recommended Mitigation Steps

Deployments of Vault instances should be done employing create2 with a salt calculated based on id, minter and msg.sender.


The original report as published on Code4rena, by ljmanini. 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 use of CREATE for vault deployment, which makes the address depend on the deployer's nonce and therefore predictable and reusable after a reorg.

Impact

An attacker could steal a victim's deposit if a reorg fully removes the victim's vault deployment and deposit, though the report notes this is unlikely.

What the attacker needed

A chain reorg removes the victim's deployment and deposit; attacker can front-run transactions; attacker deploys a malicious contract

The fix

Vault instances should be deployed using create2 with a salt derived from the id, minter and msg.sender.

How it was found

  1. Wait for a reorg that removes the victim's vault deployment and deposit.
  2. Front-run the victim's deployment by calling deployVault through a malicious contract that implements a minimal VaultController interface.
  3. Set the vault's minter to the victim's address so the victim's deposit succeeds.
  4. Let the victim's deposit go through to the attacker-controlled vault.
  5. Call controllerTransfer through the malicious controller to pull the victim's 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 blockchain reorganisation (reorg) can undo recent transactions. This report shows that if a user's vault creation and deposit are undone, an attacker can quickly create the vault first at the same address and then take the user's deposit.

What is Race condition?

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.

More from Amphora Protocol

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Race conditions

The lesson behind this report.

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.