From 96921b7e0847f1b4770625c5e1c6a603033d1dfd Mon Sep 17 00:00:00 2001 From: nftpoetrist <264138787+nftpoetrist@users.noreply.github.com> Date: Thu, 29 Oct 2026 03:02:01 +0300 Subject: [PATCH] fix: reject a zero unitsToFill instead of filling the whole order 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. --- src/seaport.ts | 7 ++++++ src/utils/fulfill.ts | 15 ++++++++++++ test/partial-fulfill.spec.ts | 44 ++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+) diff --git a/src/seaport.ts b/src/seaport.ts index 25225cf5..1539dff9 100644 --- a/src/seaport.ts +++ b/src/seaport.ts @@ -55,6 +55,7 @@ import { } from "./utils/balanceAndApprovalCheck" import { getBulkOrderTree } from "./utils/eip712/bulk-orders" import { + assertUnitsToFillIsPositive, type FulfillOrdersMetadata, fulfillAvailableOrders, fulfillBasicOrder, @@ -910,6 +911,8 @@ export class Seaport { throw new Error("Order is missing signature") } + assertUnitsToFillIsPositive(unitsToFill) + const { parameters: orderParameters } = order const { offerer, offer, consideration } = orderParameters @@ -1083,6 +1086,10 @@ export class Seaport { throw new Error("All orders must include signatures") } + for (const { unitsToFill } of fulfillOrderDetails) { + assertUnitsToFillIsPositive(unitsToFill) + } + const fulfiller = await this._getSigner(accountAddress) const fulfillerAddress = await fulfiller.getAddress() diff --git a/src/utils/fulfill.ts b/src/utils/fulfill.ts index a66536a0..2a7ed778 100644 --- a/src/utils/fulfill.ts +++ b/src/utils/fulfill.ts @@ -1103,6 +1103,21 @@ export function assertNoCriteriaTips(tips: ConsiderationItem[]) { } } +/** + * Rejects a requested fill of zero or fewer units. + * + * Leaving `unitsToFill` out fills whatever is left of the order, and the fill + * paths tell the two apart by whether it is truthy. A zero written as a number + * or a bigint is falsy, so it was read as "not set" and filled the whole + * order, while the same zero as a string reached the "must be greater than 0" + * check in mapOrderAmountsFromUnitsToFill. Settle it before any of that runs. + */ +export const assertUnitsToFillIsPositive = (unitsToFill?: BigNumberish) => { + if (unitsToFill != null && BigInt(unitsToFill) <= 0n) { + throw new Error("Units to fill must be greater than 0") + } +} + /** * Caps a requested fill at what is left of a partially filled order. * diff --git a/test/partial-fulfill.spec.ts b/test/partial-fulfill.spec.ts index bfb1bff7..ac82d455 100644 --- a/test/partial-fulfill.spec.ts +++ b/test/partial-fulfill.spec.ts @@ -132,6 +132,50 @@ describeWithFixture( }) }) + it("rejects a zero unitsToFill written as a number or bigint instead of filling the whole order", async () => { + const { seaport } = fixture + + const { executeAllActions } = await seaport.createOrder( + standardCreateOrderInput, + ) + const order = await executeAllActions() + const accountAddress = await fulfiller.getAddress() + + for (const unitsToFill of [0, 0n]) { + await expect( + seaport.fulfillOrder({ order, unitsToFill, accountAddress }), + ).to.be.rejectedWith("Units to fill must be greater than 0") + + await expect( + seaport.fulfillOrders({ + fulfillOrderDetails: [{ order, unitsToFill }], + accountAddress, + }), + ).to.be.rejectedWith("Units to fill must be greater than 0") + } + }) + + it("rejects a zero unitsToFill written as a string, as before", async () => { + const { seaport } = fixture + + const { executeAllActions } = await seaport.createOrder( + standardCreateOrderInput, + ) + const order = await executeAllActions() + const accountAddress = await fulfiller.getAddress() + + await expect( + seaport.fulfillOrder({ order, unitsToFill: "0", accountAddress }), + ).to.be.rejectedWith("Units to fill must be greater than 0") + + await expect( + seaport.fulfillOrders({ + fulfillOrderDetails: [{ order, unitsToFill: "0" }], + accountAddress, + }), + ).to.be.rejectedWith("Units to fill must be greater than 0") + }) + it("ERC1155 <=> ETH adjust tips correctly", async () => { // Note: For simplicity in this test, tips are returned to the fulfiller. const tips = [