Skip to content

fix: do not credit a forwarded offer to the batch balance check - #986

Merged
ryanio merged 1 commit into
mainfrom
fix/batch-forwarded-offer-credit
Aug 22, 2026
Merged

ryanio merged 1 commit into
mainfrom
fix/batch-forwarded-offer-credit

Conversation

@ryanio

@ryanio ryanio commented Aug 22, 2026

Copy link
Copy Markdown
Collaborator

Found while verifying main after #984 and #985 merged, 18 seconds apart. Both are correct on their own; this is the gap between them.

What is wrong

#978 (in #985) stopped validateStandardFulfillBalancesAndApprovals crediting the fulfiller with offer items that recipientAddress forwards to someone else. When the offer lands elsewhere, every consideration item has to come out of what the fulfiller already holds.

#984 added validateCumulativeFulfillerBalances so a batch is checked against its total rather than order by order. It builds cumulativeReceivedAmounts from each order's offer unconditionally, with no knowledge of recipientAddress, so the batch path still credits an offer the fulfiller never receives.

The two branches of the same function now disagree about whether a forwarded offer funds the fulfiller.

It is reachable

A fulfiller holding 0.3 ERC20 accepts two bids of 10 ERC20, each carrying a 250 bp fee. Each fee is 0.25, so the batch costs them 0.5.

Either bid alone, forwarded 0.25 owed against 0.3 held, accepted, correctly
Both bids, forwarded 0.5 owed against 0.3 held, accepted, reverts on transfer

The per-order check passes each order because 0.25 fits inside 0.3, so it never fires. The batch check then clears 0.5 against a credit of 20 ERC20 that goes to the recipient rather than the fulfiller. Measured on main at 4fdd176 before this change:

PROBE single order (0.25 owed, 0.3 held): accepted, as expected
PROBE batch (0.5 owed, 0.3 held, forwarded): rejected=false

This is not a regression from #985. Before #978 the single-order path had the same hole, and #984's batch credit is right for the ordinary case where proceeds are kept. Nothing on main is broken today: lint, tests and coverage are all green, and this is a fulfillment the SDK accepts that the chain will reject.

Change

Hoist offerItemsLandWithFulfiller(recipientAddress, fulfillerAddress) to the top of fulfillAvailableOrders and accumulate cumulativeReceivedAmounts only when it holds. The per-order call site reuses the same value rather than recomputing it, so the two checks cannot drift apart again.

The credit stays batch-wide when the proceeds are kept, so #984's reasoning about offer-fulfillment batches is untouched.

Tests

test/fulfill-orders-forwarded-offer.spec.ts, three cases. Reverting only src/utils/fulfill.ts fails one of them, on its own assertion:

1) reports the shortfall when the batch's proceeds go elsewhere:
   AssertionError: expected promise to be rejected with an error including
   'The fulfiller does not have the balan…' but it was fulfilled with
   { actions: [ { …(6) }, …(2) ], …(2) }

The other two are controls and pass either way: a kept-proceeds batch still funds its own fees and settles at 19.8, and a single forwarded order the fulfiller can cover alone is still accepted.

npm run lint clean, npm test 242 passing 0 failing, up from 239 on main.

#978 stopped the per-order check crediting the fulfiller with offer items
that recipientAddress sends elsewhere. #984 added a batch-wide check in the
same release, and it credits the batch's whole offer unconditionally, so the
same class of shortfall is still accepted on the batch path.

A fulfiller holding 0.3 ERC20 who accepts two bids with a 250bp fee each
owes 0.5 with the proceeds forwarded away. Each order passes the per-order
check alone, and the batch check clears the total against a credit for
20 ERC20 the fulfiller never receives. It reverts on transfer.
@ryanio
ryanio merged commit dae3c15 into main Aug 22, 2026
8 checks passed
@ryanio
ryanio deleted the fix/batch-forwarded-offer-credit branch August 22, 2026 19:51
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.

1 participant