Skip to content

fix: reject a zero unitsToFill instead of filling the whole order - #1054

Closed
nftpoetrist wants to merge 1 commit into
ProjectOpenSea:mainfrom
nftpoetrist:fix/reject-zero-units-to-fill
Closed

nftpoetrist wants to merge 1 commit into
ProjectOpenSea:mainfrom
nftpoetrist:fix/reject-zero-units-to-fill

Conversation

@nftpoetrist

Copy link
Copy Markdown
Contributor

Problem

unitsToFill is optional, and leaving it out fills whatever is left of the order. The fill paths tell the two apart by truthiness:

// src/seaport.ts fulfillOrder
if (!unitsToFill && isRecipientSelf && shouldUseBasicFulfill(...)) {
// src/utils/fulfill.ts fulfillStandardOrder / fulfillAvailableOrders / getAdvancedOrderNumeratorDenominator
if (unitsToFill) { ... }

unitsToFill is a BigNumberish, so the result depends on how the zero is written:

unitsToFill Result on main
"0" truthy, reaches mapOrderAmountsFromUnitsToFill, throws Units to fill must be greater than 0
0 or 0n falsy, read as "not set": the whole remaining order is filled (fulfillOrder: basic or standard route; fulfillOrders: numerator/denominator 1/1)

A caller who computes a unit count that comes out at zero buys every unit of the listing instead of getting an error. Measured on main with a partially fillable listing of 10 ERC1155 units for 10 ETH: fulfillOrder({ order, unitsToFill: 0n }) built a transaction with value 10 ETH, and the fulfiller ended up holding all 10 units.

Same falsy-zero class as #948 (value: 0n).

Fix

assertUnitsToFillIsPositive runs at the top of fulfillOrder and for each entry in fulfillOrders. It throws the existing message for any unitsToFill that is set and not greater than zero.

  • An omitted value behaves exactly as today.
  • The internal = 0 defaults are untouched; they mean "not set".

This adds a throw on input that previously returned, so it is a minor change.

Test

test/partial-fulfill.spec.ts, on the partially fillable ERC1155 listing:

  • 0 and 0n are rejected by fulfillOrder and fulfillOrders. On main this fails with expected promise to be rejected with an error including 'Units to fill must be greater than 0' but it was fulfilled with { actions: [ ... ] }.
  • Control: "0" is rejected the same way on main and with the fix. The existing cases with no unitsToFill and with unitsToFill: 2 are unchanged.

Verified failing-first by reverting only src/seaport.ts: the number/bigint case fails, the string control passes. npm run lint (check-types + biome) clean, npm test 281 passing (279 on main), npm run coverage green.

Scope note

Negative values already reached the existing guard and threw; they now throw at the entry point with the same message. Callers in opensea-sdk do not use fulfillOrder or fulfillOrders (they pass unitsToFill as a string to the fulfillment API), so they are unaffected.

The fill paths treat a falsy unitsToFill as "not set" and fill what is
left of the order, so 0 or 0n bought the entire order. The same zero as
the string "0" already threw "Units to fill must be greater than 0" in
mapOrderAmountsFromUnitsToFill. Check it once in fulfillOrder and
fulfillOrders so every zero is rejected the same way.
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.13%. Comparing base (f618d19) to head (96921b7).
⚠️ Report is 425 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1054      +/-   ##
==========================================
+ Coverage   98.27%   99.13%   +0.85%     
==========================================
  Files          35       57      +22     
  Lines       14526    21251    +6725     
  Branches      660     1206     +546     
==========================================
+ Hits        14276    21068    +6792     
+ Misses        245      175      -70     
- Partials        5        8       +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ryanio

ryanio commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

Thanks @nftpoetrist. Confirmed on main: fulfillOrder with unitsToFill: 0n returns actions instead of rejecting, and your test fails with the guard reverted. I also reverted only the fulfillOrders guard to make sure the second half of the loop is covered, and it is.

Since this adds a throw on input that used to return, it shipped as a minor release, v4.5.0. It was stacked with the other open PRs in #1058 with your commit unchanged, so closing this one in favor of it.

@ryanio ryanio closed this Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants