Skip to content
Business logic Audit finding Advanced

Truncation in OrderValidator can lead to resetting the fill and selling more tokens

A partial order's fill fraction could be truncated to zero due to a uint120 overflow, allowing an attacker to reset the fill state and repeatedly fill the order, selling more tokens than intended.

Spearbit Follow

Originally disclosed on Code4rena

Submitted by Spearbit, also found by 0xsanson, broccoli, cmichel, hyh, ming, OriDabush, Saw-mon_and_Natalie, and Yarpo

OrderValidator.sol#L228 OrderValidator.sol#L231 OrderValidator.sol#L237 OrderValidator.sol#L238

A partial order’s fractions (numerator and denominator) can be reset to 0 due to a truncation. This can be used to craft malicious orders:

  1. Consider user Alice, who has 100 ERC1155 tokens, who approved all of their tokens to the marketplaceContract.

  2. Alice places a PARTIAL_OPEN order with 10 ERC1155 tokens and consideration of ETH.

  3. Malory tries to fill the order in the following way:

    1. Malory tries to fill 50% of the order, but instead of providing the fraction 1 / 2, Bob provides 2**118 / 2**119. This sets the totalFilled to 2**118 and totalSize to 2**119.
    2. Malory tries to fill 10% of the order, by providing 1 / 10. The computation 2**118 / 2**119 + 1 / 10 is done by “cross multiplying” the denominators, leading to the acutal fraction being numerator = (2**118 * 10 + 2**119) and denominator = 2**119 * 10.
    3. Because of the uint120 truncation in OrderValidator.sol#L228-L248, the numerator and denominator are truncated to 0 and 0 respectively.
    4. Bob can now continue filling the order and draining any approved (1000 tokens in total) of the above ERC1155 tokens, for the same consideration amount!

Proof of Concept

View full POC.

The following change would make the above POC fail:

modified   contracts/lib/OrderValidator.sol
@@ -225,6 +225,8 @@ contract OrderValidator is Executor, ZoneInteraction {
                 // Update order status and fill amount, packing struct values.
                 _orderStatus[orderHash].isValidated = true;
                 _orderStatus[orderHash].isCancelled = false;
+                require(filledNumerator + numerator <= type(uint120).max, "overflow");
+                require(denominator <= type(uint120).max, "overflow");
                 _orderStatus[orderHash].numerator = uint120(
                     filledNumerator + numerator
                 );
@@ -234,6 +236,8 @@ contract OrderValidator is Executor, ZoneInteraction {
             // Update order status and fill amount, packing struct values.
             _orderStatus[orderHash].isValidated = true;
             _orderStatus[orderHash].isCancelled = false;
+            require(numerator <= type(uint120).max, "overflow");
+            require(denominator <= type(uint120).max, "overflow");
             _orderStatus[orderHash].numerator = uint120(numerator);
             _orderStatus[orderHash].denominator = uint120(denominator);
         }

Recommended Mitigation Steps

A basic fix for this would involve adding the above checks for overflow / truncation and reverting in that case. However, we think the mechanism is still flawed in some respects and requires more changes to fully fix it. See a related issue: “A malicious filler can fill a partial order in such a way that the rest cannot be filled by anyone” that points out a related but a more fundamental issue with the mechanism.

0age (OpenSea) confirmed

0xleastwood (judge) commented:

I’ve identified that this issue and all of its duplicates clearly outline how an attacker might overflow an order to continually fulfill an order at the same market price.

An instance where this issue might cause issues is during a restricted token sale. A relevant scenario is detailed as follows:

  • A new token is created and the owner wishes to sell 50% of the token supply to the public.
  • Because of an edge case in OrderValidator, the order fulfillment can be reset to allow the public to more than 50% of the total token supply.
  • As a result, allocations intended to be distributed to investors and the team, will no longer be available.
  • It is important to note, that additional tokens will be sold at the intended market price listed by the original order.

For these reasons, I believe this issue to be of high severity because it breaks certain trust assumptions made by the protocol and its userbase. By intentionally forcing a user to sell additional tokens, you are effectively altering the allocation of their wallet holdings, potentially leading to further funds loss as they may incur slippage when they have to sell these tokens back.

A great finding from all involved!

0age (OpenSea) resolved:

PR: ProjectOpenSea/seaport#319


The original report as published on Code4rena, by Spearbit. 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 contract stores the fill fraction in a uint120 without checking that the numerator and denominator fit, so large values are truncated to zero.

Impact

An attacker could reset the fill state and repeatedly fill a partial order, causing the seller to sell more tokens than intended at the same price; the judge noted this could break trust assumptions in restricted token sales.

What the attacker needed

Victim has approved tokens to the marketplace; victim has placed a partial order; attacker can fill orders

The fix

The issue was fixed by adding overflow checks before storing the numerator and denominator, reverting if they exceed uint120.

How it was found

  1. Alice approves 100 ERC1155 tokens to the marketplace contract.
  2. Alice places a PARTIAL_OPEN order for 10 ERC1155 tokens with ETH consideration.
  3. Malory fills 50% of the order using a fraction with large numerator and denominator (2**118 / 2**119).
  4. Malory fills 10% of the order using 1/10, causing the combined fraction to overflow uint120 and truncate to 0/0.
  5. Malory continues filling the order, draining all 1000 approved ERC1155 tokens for the same consideration.

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 you partially fill an order, the contract records how much you've filled as a fraction. If the numbers in that fraction get too large, they are cut off and become zero, so the contract forgets that any filling happened. An attacker can then fill the order again and again, getting more tokens than the seller intended to sell.

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 Spearbit

View all

1 more disclosed report, best first.

More from OpenSea Seaport 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.