Skip to content
Business logic Audit finding Intermediate

Migration::withdrawContribution falsely assumes that user should get exactly his original contribution back

The withdrawContribution function returns each user's original contribution, but after a failed migration the contract may hold a different amount of ETH and tokens. This can cause some users to be unable to withdraw and others to withdraw funds belonging to others.

kenzo Follow

Originally disclosed on Code4rena

Submitted by kenzo, also found by 0x52, ElKu, hansfriese, hyh, and panprog

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

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

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

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

Vulnerability Details

When a user calls withdrawContribution, it will try to send him back his original contribution for the proposal.

But if the proposal has been committed, and other users have interacted with the buyout, Migration will receive back a different amount of ETH and tokens.

Therefore it shouldn’t send the user back his original contribution, but should send whatever his share is of whatever was received back from Buyout.

Impact

Loss of funds for users. Some users might not be able to withdraw their contribution at all, and other users might withdraw funds that belong to other users. (This can also be done as a purposeful attack.)

Proof of Concept

A summary is described at the top.

It’s probably not needed, but here’s the flow in detail. When a user joins a proposal, Migration saves his contribution:

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

Later when the user would want to withdraw his contribution from a failed migration, Migration would refer to these same variables to decide how much to send to the user:

        uint256 userFractions = userProposalFractions[_proposalId][msg.sender];
        IFERC1155(token).safeTransferFrom(address(this), msg.sender, id, userFractions, "");
        uint256 userEth = userProposalEth[_proposalId][msg.sender];
        payable(msg.sender).transfer(userEth);

But if the proposal was committed, and other users interacted with the buyout, then the amount of ETH and tokens that Buyout sends back is not the same contribution.

For example, if another user called buyFractions for the buyout, it will decrease the amount of tokens in the pool:

        IERC1155(token).safeTransferFrom(address(this), msg.sender, id, _amount, "");

And when the proposal will end, if it has failed, Buyout will send back to Migration the amount of tokens in the pool:

        uint256 tokenBalance = IERC1155(token).balanceOf(address(this), id);
        ...
        IERC1155(token).safeTransferFrom(address(this), proposer, id, tokenBalance, "");

(**Same will happen for the ETH amount)

Therefore, Migration will receive back less tokens than the original contribution. When the user will try to call withdrawContribution to withdraw his contribution from the pool, Migration would try to send the user’s original contribution. But there’s a deficit of that. If other users have contributed the same token, then it will transfer their tokens to the user. If not, then the withdrawal will simply revert for insufficient balance.

Recommended Mitigation Steps

I am not sure, but I think that the correct solution would be that upon a failed proposal’s end, there should be a hook call from Buyout to the proposer - in our situation, Migration. Migration would then see(/receive as parameter) how much ETH/tokens were received, and update the proposal with the change needed. eg. send to each user 0.5 his tokens and 1.5 his ETH.

In another issue I submitted, “User can’t withdraw assets from failed migration if another buyout is going on/succeeded”, I described for a different reason why such a callback to Migration might be needed. Please see there for more implementation suggestions.

I think this issue shows that indeed it is needed.

stevennevins (Fractional) confirmed

HardlyDifficult (judge) commented:

After an unsuccessful migration, some users will be unable to recover their funds due to a deficit in the contract. 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

Likely the withdrawal logic assumes the contract's balance equals the sum of original contributions, ignoring changes from buyout interactions.

Impact

Some users may be unable to withdraw their contribution, while others could withdraw funds belonging to other users.

What the attacker needed

Proposal is committed; other users interact with buyout; proposal fails

The fix

A callback from Buyout to Migration on a failed proposal should update the proposal with the actual amounts received, so withdrawals reflect each user's share.

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 people put money into a project, the contract records how much each person gave. If the project fails, they should get back what is left, not necessarily the exact amount they put in. Here the contract tries to return the original amount, but the pot may be smaller, so some people cannot get their money and others may take more than their share.

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.