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.
Submitted by Lambda, also found by 0x29A
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.
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
- Bob joins the migration proposal with half the supply.
- Alice joins the migration proposal with the other half, so all tokens are joined.
- Time advances past the proposal period.
- 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.