Skip to content
Smart contracts Audit finding Intermediate

Migration fails when all tokens are joined

When all token holders join a migration proposal, the total fractions equal the total supply, causing a division by zero in the _calculateTotal function. This prevents the migration from proceeding, whereas a buyout in the same situation would not make sense.

Lambda Follow

Originally disclosed on Code4rena

Submitted by Lambda, also found by 0x29A

https://github.com/code-423n4/2022-07-fractional/blob/f862c14f86adf7de232cd4e9cca6b611e6023b98/src/modules/Migration.sol#L202

https://github.com/code-423n4/2022-07-fractional/blob/f862c14f86adf7de232cd4e9cca6b611e6023b98/src/modules/Migration.sol#L528

Impact

When proposal.totalFractions is equal to the total supply (meaning that all token holders want to participate in a migration), there is a division by zero in _calculateTotal.

In contrast to a buyout, where it does not make sense to initiate a buyout if all tokens are held (because there is a dedicated method for that), it does make sense to have a migration that all token holders join. Therefore, this case should be handled.

Proof Of Concept

--- a/test/Migration.t.sol
+++ b/test/Migration.t.sol
@@ -238,7 +238,7 @@ contract MigrationTest is TestUtil {
         // Bob joins the proposal
         bob.migrationModule.join{value: 1 ether}(vault, 1, HALF_SUPPLY);
         // Alice joins the proposal
-        alice.migrationModule.join{value: 1 ether}(vault, 1, 1000);
+        alice.migrationModule.join{value: 1 ether}(vault, 1, HALF_SUPPLY);

         vm.warp(proposalPeriod + 1);
         // bob calls commit to kickoff the buyout process

Recommended Mitigation Steps

In such a case, redeem can be used instead of starting a buyout.

Ferret-san (Fractional) confirmed

HardlyDifficult (judge) commented:

When a migration is supported by all fractions, it fails with a div by 0 error. Agree with severity.


The original report as published on Code4rena, by Lambda. 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 code divides by the remaining unjoined token supply without checking if it is zero, which happens when all tokens have joined.

Impact

The migration fails with a division by zero error when all token holders participate, blocking the process.

What the attacker needed

All token holders join the migration

The fix

The code should handle the case where all tokens have joined, for example by allowing redeem instead of starting a buyout.

How it was found

  1. Bob joins the migration proposal with half the supply.
  2. Alice joins the migration proposal with the other half, so all tokens are joined.
  3. Time advances past the proposal period.
  4. Bob calls commit to start the buyout process, which triggers the division by zero.

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.

In this smart contract, a migration lets token holders pool their tokens to move to a new version. The code calculates a share by dividing by the number of tokens not yet joined. If everyone joins, that number becomes zero, and dividing by zero crashes the process, so the migration cannot complete.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by Lambda

View all

64 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.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.