Skip to content
Business logic Audit finding Advanced

_aggregateValidFulfillmentOfferItems() can be tricked to accept invalid inputs

The function that validates offer items used a bitwise error buffer that could hold the value 3 when both a zero amount and an overflow occurred, and the switch statement only handled 1 and 2, so the order was accepted. An attacker could fulfil an order with a much lower consideration than expected, potentially buying an NFT for almost nothing.

Spearbit Follow

Originally disclosed on Code4rena

Submitted by Spearbit, also found by Saw-mon_and_Natalie

FulfillmentApplier.sol#L406

The _aggregateValidFulfillmentOfferItems() function aims to revert on orders with zero value or where a total consideration amount overflows. Internally this is accomplished by having a temporary variable errorBuffer, accumulating issues found, and only reverting once all the items are processed in case there was a problem found. This code is optimistic for valid inputs.

Note: there is a similar issue in _aggregateValidFulfillmentConsiderationItems(), which is reported separately.

The problem lies in how this errorBuffer is updated:

                // Update error buffer (1 = zero amount, 2 = overflow).
                errorBuffer := or(
                  errorBuffer,
                  or(
                    shl(1, lt(newAmount, amount)),
                    iszero(mload(amountPtr))
                  )
                )

The final error handling code:

            // Determine if an error code is contained in the error buffer.
            switch errorBuffer
            case 1 {
                // Store the MissingItemAmount error signature.
                mstore(0, MissingItemAmount_error_signature)

                // Return, supplying MissingItemAmount signature.
                revert(0, MissingItemAmount_error_len)
            }
            case 2 {
                // If the sum overflowed, panic.
                throwOverflow()
            }

While the expected value is 0 (success), 1 or 2 (failure), it is possible to set it to 3, which is unhandled and considered as a “success”. This can be easily accomplished by having both an overflowing item and a zero item in the order list.

This validation error could lead to fulfilling an order with a consideration (potentially ~0) lower than expected.

Proof of Concept

Craft an offer containing two errors (e.g. with zero amount and overflow). Call matchOrders(). Via calls to _matchAdvancedOrders(), _fulfillAdvancedOrders(), _applyFulfillment(), _aggregateValidFulfillmentOfferItems() will be called. The errorBuffer will get a value of 3 (the or of 1 and 2). As the value of 3 is not detected, no error will be thrown and the order will be executed, including the mal formed values.

Recommended Mitigation Steps

  1. Change the check on FulfillmentApplier.sol#L465 to consider case 3.
  2. Potential option: Introduce an early abort in case errorBuffer != 0 on FulfillmentApplier.sol#L338

0age (OpenSea) confirmed

HardlyDifficult (judge) decreased severity to Medium

cmichel (warden) commented:

This validation error could lead to fulfilling an order with a consideration (potentially ~0) lower than expected.

That’s correct, you can use this to fulfill an order essentially for free, that’s why I’d consider this high severity. They could have done a better job demonstrating it with a POC test case but this sentence imo shows that they were aware of the impact.

See this test case showing how to buy an NFT for 1 DAI instead of 1000 DAI.

0age (OpenSea) disagreed with Medium severity:

This is the highest-severity finding. If it were me, I’d switch this to high.

HardlyDifficult (judge) increased severity to High

0xleastwood (judge) commented:

After further consideration and discussion with @HardlyDifficult, we agree with @cmichel that this should be of high severity. As the protocol allows for invalid orders to be created, users aware of this vulnerability will be able to fulfill an order at a considerable discount. This fits the criteria of a high severity issue as it directly leads to lost funds.

0age (OpenSea) resolved:

PR: ProjectOpenSea/seaport#320


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

The error buffer combined two error flags with a bitwise OR, producing an unhandled value of 3, and the switch statement only reverted for 1 and 2.

Impact

An attacker could fulfil an order with a consideration far lower than expected, potentially buying an NFT for a tiny fraction of its price.

What the attacker needed

Ability to create a malformed order; ability to call matchOrders()

The fix

The check was fixed to handle the value 3, and an early abort when the error buffer is non-zero was suggested.

How it was found

  1. Craft an offer containing two errors, such as a zero amount and an overflow.
  2. Call matchOrders(), which reaches _aggregateValidFulfillmentOfferItems().
  3. The errorBuffer becomes 3 from the OR of 1 and 2.
  4. Because 3 is not detected, no error is thrown and the order executes with the malformed values.

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 checks orders before filling them. It collects problems in a number, expecting 0 for fine, 1 for a zero amount, and 2 for an overflow. If an order has both problems, the number becomes 3, which the code does not check, so it treats the order as valid. That lets someone pay far less than the seller asked.

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.