Skip to content
Business logic Audit finding Intermediate

Migration: no check that user-supplied proposalId and vault match

The Migration contract did not verify that the user-supplied proposalId and vault matched the actual vault for that proposal. An attacker could join a proposal with a worthless token from a different vault, then leave using the original vault to withdraw valuable tokens.

kenzo Follow

Originally disclosed on Code4rena

Submitted by kenzo, also found by 0x1f8b, bin2chen, codexploder, dipp, minhtrng, and smiling_heretic

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

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

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

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

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

Vulnerability Details

In Migration, when joining or leaving a migration proposal, Fractional does not check whether the user supplied proposalId and vault match the actual vault that the proposal belongs to.

This allows the user to trick the accounting.

Impact

Loss of funds for users.

Malicious users can withdraw tokens from proposals which have not been committed yet.

Proof of Concept

Let’s say Vault A’s FERC1155 token is called TOKEN. Alice has deposited 100 TOKEN in Migration to Vault A on proposal ID 1.

Now Malaclypse creates Vault B with token ERIS as FERC1155 and mints 100 tokens to himself. He then calls Migration’s join with amount as 100, Vault B as vault, proposal ID as 1. The function will get ERIS as the token to deposit. It will pull the ERIS from Mal. And now for the problem - it will set the following variable:

        userProposalFractions[_proposalId][msg.sender] += _amount;

Notice that this does not correspond to the vault number.

Now, Mal will call the leave function, this time with Vault A address and proposal ID 1. The function will get the token to send from the vault as TOKEN.

It will get the amount to withdraw from userProposalFractions[_proposalId][msg.sender], which as we saw previously will be 100.

It will deduct this amount from migrationInfo[_vault][_proposalId], which won’t revert as Alice deposited 100 to this vault and proposal.

And finally it will send 100 TOKENs to Mal - although he deposited ERIS.

Mal received Alice’s valuable tokens.

Recommended Mitigation Steps

I think that one option would be to save for each proposal which vault it corresponds to. Then you can verify that user supplies a matching vault-proposal pair, or he can even just supply proposal and the contract will get the vault from that.

Another solution would be to have userProposalFractions save the relevant vault also, not just a general proposal id.

stevennevins (Fractional) confirmed

HardlyDifficult (judge) commented:

The warden’s POC shows how an attacker can effectively steal tokens by creating a migration for a new vault with worthless tokens and reusing an existing proposalId, then withdrawing valuable tokens from the original proposal. I agree this is a High risk issue.


The original report as published on Code4rena, by kenzo. 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 contract stored user deposits keyed only by proposal ID, without recording which vault the deposit came from, so join and leave could use different vaults for the same proposal ID.

Impact

A malicious user could steal tokens from other users' uncommitted migration proposals, causing loss of funds.

What the attacker needed

Attacker can create a new vault with a worthless token; victim has deposited tokens in a migration proposal; attacker knows the proposal ID

The fix

The contract should record which vault each proposal belongs to and verify that the supplied vault matches, or store the vault alongside user fractions.

How it was found

  1. Alice deposits 100 TOKEN from Vault A into proposal ID 1.
  2. Malaclypse creates Vault B with a worthless token ERIS and mints 100 to himself.
  3. Malaclypse calls join with amount 100, Vault B as vault, and proposal ID 1, depositing ERIS.
  4. The contract records 100 fractions for Malaclypse under proposal ID 1 without noting the vault.
  5. Malaclypse calls leave with Vault A and proposal ID 1, which sends 100 TOKEN to him.

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 smart contract lets people deposit tokens into a migration proposal, but it tracked how many tokens each person deposited only by proposal number, not by which vault the tokens came from. An attacker could deposit worthless tokens under one vault but use the same proposal number, then withdraw valuable tokens from a different vault. This is like putting a fake receipt in a box and later taking out someone else's expensive item.

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 kenzo

View all

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