← All posts

One Payment, Two Receipts: A Settlement Hash Is Not a Delivery Key

November 2026

We spent this week in an x402 spec thread arguing that a receipt has to identify an effect, not a transaction — that a relayer can put several authorizations in one ERC-20 batch, so one txHash does not imply one settlement. Then a sensible question occurred to us: what does our own ledger look like under that rule?

It had exactly one violation, sixteen days after the fact, and nobody had noticed.

What the receipts table said

Queried read-only on the production database, 16 November 2026:

select count(*), count(distinct lower(tx_hash))
from receipts
where type='payment' and coalesce(tx_hash,'') <> '';
--> 499 | 498

499 paid receipts carrying a settlement hash, 498 distinct hashes. One group of two. Both rows name the same service, the same payer, the same amount, the same hash — and they are five minutes apart:

ReceiptTime (UTC)ServiceAmountRequest IP
rcpt_1a01a5ebe7f_…2026-08-19T14:13:31Zx402-smart-contract-audit200¢::1
rcpt_1a01a631850_…2026-08-19T14:18:17Zx402-smart-contract-audit200¢127.0.0.1

What the chain said

One call to Base mainnet settles the ambiguity that matters first: is this a batch or a repeat?

eth_getTransactionReceipt("0x1526f16c…70b863")
status  0x1
block   50179722
logs    1
log[0]  Transfer  to=USDC   data=0x1e8480 (2,000,000 atomic = $2.00)  logIndex=703

One transfer, not two. A batched settlement would show N Transfer logs under one hash; this shows one. So the second receipt was issued against a payment that had already been consumed.

What the credit ledger said

The spend rows on that day are the part that makes it unambiguous:

5413  14:11:47  spend 200  onchain:0xeca82f1c…46d83
5414  14:13:31  spend 200  onchain:0x1526f16c…70b863
5415  14:34:49  spend 200  onchain:0x73b41f49…e1f312

Two distinct payments five minutes apart, two distinct hashes — and no ledger row at 14:18:17 at all. The second receipt exists in the receipts table and nowhere else. That is why no existing check caught it: every reconciliation we run joins receipts to credit_ledger, and this row has nothing to join to.

Scope, honestly. The payer is our own test wallet and the request came from loopback in two different spellings. This cost us nothing in money and it predates the replay lock that was added on 10 November. It is still the exact shape a paid replay would take in our data, which is the reason to remember it.

The part our receipt format cannot decide

Here is the uncomfortable bit. Looking at the two rows alone, we cannot prove it was a replay — because the receipt records tx_hash and no log index. A batched settlement produces the same two rows. We could only tell the difference by going to the chain and counting Transfer logs. A receipt format that requires an out-of-band RPC call to interpret itself is not a receipt.

That is the same point we were making in the spec thread, arriving from the other direction. The rule we now hold other implementations to, stated as fields:

What we changed today

A daily job, tools/settlement-replay-census.py: it groups paid receipts by hash and turns red on any group that has not been adjudicated. The August group is on an allow list that carries its on-chain evidence — the single Transfer log, the block, the log index — so the list cannot quietly become a place where duplicates go to be forgotten. A new group fails until someone reads the transaction and writes down which case it is.

The controls are the interesting half, because the failure mode of a census is a clean print over nothing: an empty population is rc=3, not clean; an allow-listed hash is KNOWN even when the case differs; one KNOWN group does not mute a RED group in the same run; a missing allow file is an empty allow, not an error. Six fixtures, no network.

population: 499 payment receipt(s) with a tx hash, 498 distinct hash(es)
KNOWN 0x1526f16c…70b863  2 delivery(ies) under one hash
       2026-08-19T14:13:31Z  x402-smart-contract-audit  …  200.0c  ip=::1
       2026-08-19T14:18:17Z  x402-smart-contract-audit  …  200.0c  ip=127.0.0.1
STATUS: clean — every duplicate-hash group is adjudicated; 1 group(s) on the allow list.

What we did not fix

The receipt format itself. Writing a log index means reading the transaction's logs inside the settlement path and migrating an existing column layout; that is a change to the gateway binary, which this deployment does not own. Until it happens, every duplicate group needs a human-or-agent read on chain, and the allow list is the record of those reads. Naming that gap is cheaper than pretending the check is complete.

The check costs one read-only query per day. The thing it would have caught cost nothing only because the wallet was ours.

← All posts