Skip to content
Audit finding Advanced

Migration Module: Re-enter commit using custom token

The migration module's commit function updates state after making external calls, allowing a malicious ERC1155 token to reenter and drain ETH. An attacker could repeatedly reenter to steal funds from the migration module.

zzzitron Follow

Originally disclosed on Code4rena

Submitted by zzzitron, also found by 0x29A

HIGH - Assets can be compromised directly.

One can drain eth out from migration module to buyout module using custom made FERC1155 token.

Proof of Concept

The proof of concept shows a scenario where Alice is draining migration module using custom made FERC1155 token.

  1. Setup: other people are using migration module and they deposited some eth. (using Alice and Bob just to simplify the set up process)
  2. Alice prepared the custom FERC1155 (let’s say evil_token)
  3. Alice create a vault with the evil_token
  4. Alice proposes and joins with 0.5 ether
  5. When Alice calls commit, the evil_token will reenter commit and send money to buyout module

Note: For simplicity, the evil_token reenters for a fixed number of times. But one can adjust to drain all the eth in the migration module. Note2: For now the eth is in the buyout module, but given the current implementation of buyout module, the same actor can drain eth from buyout.

The commit function is not written in Checks, Effects, Interactions (CEI) patterns.

// modules/Migration.sol::commit
// proposal.isCommited and started are set after the out going calls (i.e. start, setApprovalFor)
// Mitigation idea: set the values before the out going calls

206         if (currentPrice > proposal.targetPrice) {
207             // Sets token approval to the buyout contract
208             IFERC1155(token).setApprovalFor(address(buyout), id, true);
209             // Starts the buyout process
210             IBuyout(buyout).start{value: proposal.totalEth}(_vault);
211             proposal.isCommited = true;
212             started = true;
213         }

Tools Used

Foundry

Recommended Mitigation Steps

Follow Checks, Effects, Interactions patterns. One can also consider adding reentrancy guard.

stevennevins (Fractional) confirmed

HardlyDifficult (judge) commented:

The 1155 callback could be used to reentrancy and steal funds. Agree this is high risk.


The original report as published on Code4rena, by zzzitron. 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 commit function performs external calls (setApprovalFor and start) before updating its own state variables (isCommited and started), violating the checks-effects-interactions pattern.

Impact

An attacker could drain ETH from the migration module, and potentially from the buyout module as well.

What the attacker needed

Ability to deploy a malicious ERC1155 token; ETH deposited in migration module; attacker can create a vault and join

The fix

The commit function should follow the checks-effects-interactions pattern by setting state variables before external calls, and a reentrancy guard should be considered.

How it was found

  1. Other users deposit ETH into the migration module.
  2. Alice creates a custom malicious ERC1155 token.
  3. Alice creates a vault using the malicious token.
  4. Alice proposes and joins the vault with 0.5 ether.
  5. When Alice calls commit, the malicious token reenters commit and sends money to the buyout module.

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 reentrancy attack happens when a contract calls another contract before finishing its own bookkeeping, letting the called contract call back in and exploit the unfinished state. Here, the migration module sent ETH and set approvals before marking the proposal as committed, so a malicious token could call commit again and again to take more money.

More by zzzitron

View all

21 more disclosed reports, best first.

More from Fractional v2 contest

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.