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.
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.
- Setup: other people are using migration module and they deposited some eth. (using Alice and Bob just to simplify the set up process)
- Alice prepared the custom FERC1155 (let’s say
evil_token) - Alice create a vault with the
evil_token - Alice proposes and joins with 0.5 ether
- When Alice calls
commit, theevil_tokenwill reentercommitand 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.
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
- Other users deposit ETH into the migration module.
- Alice creates a custom malicious ERC1155 token.
- Alice creates a vault using the malicious token.
- Alice proposes and joins the vault with 0.5 ether.
- 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.