x402's invalidReason: 89 codes, 17 shared, 8 in the spec
Section 9 of the x402 v2 spec gives clients one rule: branch on the code, never on the message text. We sent 28 identical signed payments to the three reference facilitators. Nine got the same answer.
x402 has three reference implementations of the exact scheme on EVM — TypeScript, Go and Python — and one page of error vocabulary they are all supposed to speak. Section 9 lists sixteen codes. It also makes them load-bearing: "When matching specific error conditions, clients MUST use the corresponding invalidReason or errorReason code and MUST NOT rely on message text."
That sentence is what turns invalidReason from a log line into an interface. A buyer agent that receives a 402 cannot read prose; it has to decide whether to re-sign with a corrected payload, refresh the seller's requirements, back off and retry, or give up and take its business elsewhere. The code is the only input to that decision.
So we tested the code the way a client would: one payer key, one set of 28 signed EIP-3009 payloads, fed to each SDK's own facilitator. Then we read every error table against the spec. Two results stand out. Across the three SDKs the union of error codes is 89, of which 17 are identical everywhere and 81 appear nowhere in the spec. And for the same invalid payment, the three implementations frequently report different conditions, not just differently-worded codes — because they run the checks in a different order.
How this was measured
Everything below runs against x402 at commit b0073878 (2026-11-18), the tip of main when this was written, and against what npm and PyPI actually serve: @x402/evm 2.31.0 (published 2026-11-12T22:15:21Z) and x402 2.28.0 on PyPI (2026-11-12T22:19:18Z), with Go tagged go/v2.31.0. The three repositories' error tables have not diverged between those tags and main for the codes discussed here, except where a merge on 2026-11-17 or later is called out.
The harness is deliberately boring. One key signs an EIP-3009 TransferWithAuthorization for Base USDC (0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913, chain 8453) over a fixed domain {"name":"USD Coin","version":"2"}. Each case mutates exactly one thing — or, for the precedence cases, two — and the payload is then passed to ExactEvmScheme.verify() in TypeScript, ExactEvmScheme.Verify() in Go, and ExactEvmFacilitatorScheme.verify() in Python with the same PaymentRequirements. The signer is a stub that answers eth_getCode with 0x60 for the token and 0x for the payer, so all three take the EOA path; read-only calls return a funded balance, an unused nonce, and a matching token name and version, so simulation never confounds the result. The Python runs against a real Base mainnet RPC wherever the point is on-chain behavior, and the v results below were confirmed against the deployed token with an eth_call, not just the stub.
Two ground rules. A case counts as agreeing only when the returned string is identical; a case where all three report the same condition using different strings is counted separately, because that is the failure mode a client actually hits — it can read the condition, but only if it knows all three spellings. And no case below is a hypothetical from reading code alone: every row is a call that returned a value.
The census: 89 codes, 17 shared, 8 in the spec
Start with the vocabulary itself. Each SDK keeps its error strings in one table — typescript/packages/mechanisms/evm/src/exact/facilitator/errors.ts, go/mechanisms/evm/exact/facilitator/errors.go, and the ERR_* block of python/x402/mechanisms/evm/constants.py. Counting the distinct wire strings in each, plus the sixteen from spec section 9:
| Where the codes live | Distinct codes | Also in spec §9 |
|---|---|---|
spec §9 (v2, x402-specification-v2.md) | 16 | 16 |
TypeScript errors.ts | 63 | 5 |
Go errors.go | 45 | 4 |
Python constants.py (ERR_*) | 50 | 7 |
| Union of the three tables | 89 | 8 |
| Present, identically, in all three tables | 17 | — |
| Present in exactly one SDK | 37 | — |
Read the last three rows together and the shape of the problem is clear. The spec names sixteen codes; the implementations between them can emit 89. Only eight of the spec's sixteen are ever produced by any of them, and eight are never produced at all — invalid_network, invalid_scheme, invalid_payload, insufficient_funds, invalid_payment_requirements, invalid_x402_version, unexpected_verify_error and unexpected_settle_error do not appear as literals in any of the three exact EVM error tables. A client that follows section 9 literally — match insufficient_funds when the payer is short — will sit through an infinite stream of invalid_exact_evm_insufficient_balance and never match once.
The symmetry is not accidental and it is not new. A TypeScript comment at the top of errors.ts states the intent outright: "These strings must be character-for-character identical to the Go constants." In practice 17 strings satisfy that promise out of the 45 that Go declares. Thirty-seven codes exist in exactly one SDK — 13 in TypeScript only, 16 in Python only, 8 in Go only.
Some of that spread is legitimate. Each SDK also carries its own Permit2 path, its own EIP-2612 and ERC-20 approval sponsoring extensions, and its own ERC-6492 classification, and those genuinely differ in detail. But the spread is not confined to extensions. It reaches the five codes that section 9 assigns to exact on EVM, which is where a client with no scheme-specific knowledge is entitled to a stable answer.
Same payment, three different conditions
The census understates the problem. Strings that differ but mean the same thing are annoying; a client can keep a table. What hurts is when the same invalid payment produces different conditions, because then no table can rescue the client — it has to guess which SDK it is talking to.
That is what happens, and the reason is check order. The three verifiers agree on the set of checks and disagree on the sequence, so the first failure wins and the winner differs. Reading the code:
- TypeScript verifies the signature first: scheme, EIP-712 domain, network, then classify the payer and verify the signature, and only after that the recipient,
validBefore,validAfter, the amount's canonicity and the value. - Go checks the recipient and amount first: scheme, network, payload shape, empty signature, chain id, recipient, amount canonicity, value, then the validity window, then the EIP-712 domain, then the signature.
- Python checks the domain and recipient first: scheme, network, chain id, EIP-712 domain, recipient, amount canonicity, value, the validity window, then the signature.
Feed the three the same broken payment and the divergence is immediate. Every row below is a real call result, where the payload is deliberately wrong in two ways at once:
| Payload has two faults | Python | Go | TypeScript |
|---|---|---|---|
| bad signature + expired | ..._valid_before | ..._valid_before | invalid_exact_evm_signature |
| bad signature + wrong recipient | ..._recipient_mismatch | ..._recipient_mismatch | invalid_exact_evm_signature |
| expired + amount mismatch | ..._value_mismatch | ..._value_mismatch | ..._valid_before |
| missing domain + expired | missing_eip712_domain | ..._valid_before | ..._missing_eip712_domain |
| wrong recipient + missing domain | missing_eip712_domain | ..._recipient_mismatch | ..._missing_eip712_domain |
| non-canonical amount + expired | ..._required_amount | ..._required_amount | ..._valid_before |
| non-canonical amount + bad signature | ..._required_amount | ..._required_amount | invalid_exact_evm_signature |
The consequences are not academic. Take the third row: a payment that is both expired and for the wrong amount. TypeScript says valid_before, so a client listening to TypeScript refreshes the authorization and re-signs a fresh window — and fails again, because the amount was also wrong. Python and Go say value_mismatch, so the same client would re-read the seller's requirements instead. Both diagnoses are true; the payment is invalid either way. But one of them sends the agent down a retry loop that cannot converge, and which one it gets depends on which language the facilitator happened to be written in.
Across the 28 cases, the split is 9 identical strings, 10 cases where all three agree on the condition but disagree on the string, and 9 cases where they report different conditions. Roughly two thirds of the sample lands somewhere a strictly spec-compliant client cannot use.
Two of the 10 vocabulary splits are worth naming because they are pure drift: Python returns missing_eip712_domain where Go and TypeScript return invalid_exact_evm_missing_eip712_domain, and Python returns network_mismatch and unsupported_scheme where the other two return invalid_exact_evm_network_mismatch and invalid_exact_evm_scheme. All three conditions are real; only one of the six strings appears in section 9.
The six seconds nobody wrote down
Underneath the vocabulary drift sits a more interesting kind of gap: rules that all three implementations enforce, that the spec never states. The clearest is the minimum remaining validity on validBefore.
Section 5.2.2 describes validBefore as the moment the authorization expires, and section 9 gives exactly one timing code for it — invalid_exact_evm_payload_authorization_valid_before, glossed as "payment authorization has expired (after validBefore timestamp)". Read literally, an authorization whose validBefore is one second in the future is valid.
No implementation agrees. All three reject anything with less than six seconds left, at the same line in the same shape:
// typescript/packages/mechanisms/evm/src/exact/facilitator/eip3009.ts
if (BigInt(eip3009Payload.authorization.validBefore) < BigInt(now + 6)) {
// go/mechanisms/evm/exact/facilitator/eip3009.go
if parsedAuthorization.ValidBefore.Cmp(big.NewInt(now+6)) < 0 {
// python/x402/mechanisms/evm/exact/facilitator.py
if int(evm_payload.authorization.valid_before) < now + 6:
The Permit2 path carries the same margin as Permit2DeadlineBuffer = 6 in Go and a literal now + 6 in the other two. We measured the boundary rather than inferring it: signing a fresh authorization with validBefore = now + Δ and verifying inside the same second, with zero clock skew between signing and verification, Python rejects Δ = 4 and Δ = 5 and accepts Δ = 6 and Δ = 7. The TypeScript and Go scans show the identical transition at the same values.
So there is a floor. It is six seconds. It appears in all three reference implementations. It appears in the specification nowhere.
This is x402 issue #4280, opened by rytjy on 2026-11-15, which lays out the three code locations and the spec text side by side and proposes either writing the margin into the spec or giving it a distinct code. The report notes, honestly, that the three lines were read and not executed. Two operators then reproduced it independently in the thread; one of them, bshelby88, published the same table we measured — now + 5 rejected as expired, now + 60 reaching the signature check — against x402 2.27.0 from PyPI.
A pull request follows from the same thread. #4307, opened by Shikhyy on 2026-11-17, is docs-only: two files, five lines added, two removed, and no behavior change. It amends the EIP-3009 verification step to say validBefore MUST be at least a minimum remaining validity after the current time, notes that the reference SDKs use six seconds, permits facilitators to require more, and points the Permit2 deadline step at the same margin. It also rewrites the section 9 gloss so the code covers "expires too soon to settle safely" as well as "expired". At the time of writing the PR is open, unreviewed, and its own description is candid that it takes the smaller of the two options in #4280 — documenting existing behavior rather than adding a code.
validBefore as now + maxTimeoutSeconds hands the seller control of its own expiry. A seller advertising a window of five seconds produces authorizations that every facilitator rejects, with a code that says the buyer was too late. The failure points at the payer and the cause is the seller's configuration.
That is the second half of the thread, raised by sryantrabot and developed by rytjy: if clients derive the window from maxTimeoutSeconds, then the spec needs a floor on that field too, not just on the verification side. One constant, stated once, with the verifier's check and the seller's minimum derived from it. As written today, the number exists only as a literal in three files.
A signature form USDC rejects and three SDKs accept
The second unwritten rule is sharper, because here the implementations do not merely over-reject a spec-legal payment — they accept a payment the token contract will refuse.
An EIP-3009 authorization travels as a 65-byte r || s || v signature. Ethereum tooling has normalized two things about that shape for years: the scalar s must be in the lower half of the curve order (EIP-2, to block signature malleability), and the recovery byte is conventionally 27 or 28. Both are enforced by the contracts that consume these signatures. Neither is stated in the exact EVM scheme document, whose verification step is a single sentence: "Verify the signature is valid and recovers to the authorization.from address."
We asked the deployed token directly. Calling transferWithAuthorization on Base USDC via eth_call, with a state override that funds the payer so the balance check cannot mask the answer, distinguishes four cases cleanly:
v in the signature | USDC on Base (block 59,449,823) |
|---|---|
| 28 (correct parity) | would succeed |
| 27 (wrong parity) | revert: FiatTokenV2: invalid signature |
| 0 | revert: ECRecover: invalid signature 'v' value |
| 1 | revert: ECRecover: invalid signature 'v' value |
So the contract accepts 27 or 28 and nothing else. What do the three SDKs do with v = 0 or v = 1, with the parity otherwise correct so the recovered address is the same? All three accept it. Python's EOA path normalises v >= 27 down to parity and then requires the result to be 0 or 1 — which is precisely the range the token rejects. Go's VerifyEOASignature does the same subtraction and hands the byte to crypto.SigToPub, which is happy with 0 and 1. TypeScript's verifyECDSA goes through viem's recoverAddress, which also accepts both forms. Verified against a live Base RPC with the real FacilitatorWeb3Signer, Python's signature layer returns is_valid: true for a v = 0 signature that the token contract reverts on.
The gap closes only because verify simulates. All three run an eth_call of transferWithAuthorization as part of verification, and that call reverts on the bad v, so the payment is rejected — just under a different code, and for a different reason than the one in the error table. Turn the simulation off and the gap is live. In TypeScript and Python, simulateInSettle and simulate_in_settle both default to false, so settle's re-verify runs without the on-chain check; the broadcast transaction then reverts at the token, the facilitator has paid gas to find out, and the buyer is told its signature was invalid — which it was, in a way the facilitator's own pre-check had called fine.
This is not a novel observation inside the project, which is what makes the asymmetry interesting. Batch settlement, the scheme that introduced x402BatchSettlement and its vouchers, merged exactly this rule on 2026-11-18 in #4316: a signature is accepted only if it is "65 bytes, low s, and v of 27 or 28", with the wording added to the scheme document's verification rule 6. A follow-up, #4319, opened the same day by PhilBot402, extends the form check to client-side recovery so a corrective 402 cannot store a voucher that facilitator verify will reject and _processVoucherClaim will revert on. The TypeScript helper it builds on is explicit about the requirement:
// typescript/packages/mechanisms/evm/src/batch-settlement/utils.ts
// Whether x402BatchSettlement can recover `signature`: OpenZeppelin ECDSA accepts only a
// 65-byte low-s signature with `v` of 27 or 28.
export function isContractRecoverableSignature(signature: Hex): boolean {
if (!isHex(signature) || signature.length !== 132 || !isCanonicalEcdsaSignature(signature)) {
return false;
}
const v = parseInt(signature.slice(130, 132), 16);
return v === 27 || v === 28;
}
That is the missing rule, written down, for the scheme that needed it first. The exact scheme's version of the same predicate exists too — isPlainNonCanonicalEcdsaSignature — but it checks s only. It returns false for a high-s signature and true for everything else, including a v the token will reject. High-s is caught everywhere, in all three SDKs, with invalid_exact_evm_non_canonical_signature; that was the subject of the earlier audit of the verify rules. The same rule for v was never added to exact.
Terminal or retryable: the distinction a client needs
There is one more divergence, and it is the one most likely to bite an autonomous buyer. Given a definitively invalid signature — 65 zero bytes — the three SDKs disagree about whether the failure is permanent.
Python returns invalid_exact_evm_payload_signature, the spec's code, which a client reads as "re-sign". Go returns invalid_exact_evm_failed_to_verify_signature. TypeScript returns invalid_exact_evm_signature. The three strings sit next to each other in the error tables but mean different things operationally: the first is terminal, the second is what the code's own comment reserves for an RPC failure ("so callers can retry instead of re-signing"), and the third is a code that appears in no version of the spec.
Why Go reaches that branch is instructive. For a signature that cannot be parsed or recovered at all, VerifyEOASignature returns an error, and the caller maps any error from the classification step to ErrFailedToVerifySignature. A signature that recovers to the wrong address returns false with no error and is mapped to ErrInvalidSignature. So the same 65 bytes are reported as terminal or retryable depending on whether the arithmetic failed or merely produced the wrong key. An agent that treats failed_to_verify_signature as retryable — which is what the code says to do — retries forever against a signature that will never recover.
The project knows about the naming half of this. #4310, opened by shlee1223 on 2026-11-18 and still open, changes TypeScript's and Go's invalid-signature constant to invalid_exact_evm_payload_signature, the string the spec lists, and notes that Python and the Go v1 facilitator already return it. It cites #4174, merged on 2026-11-17, which did the same for the recipient-mismatch code. The pattern is one code per pull request, each argued from the spec text. That is a reasonable way to converge — it is just slow, and it addresses the string while leaving the check order and the unwritten rules alone.
What it means for LLM4Agents
Our gateway sits between an autonomous agent and a seller, and it has to answer exactly the question this vocabulary is supposed to answer: can this payment be repaired, and if so how? Three consequences.
We cannot branch on invalidReason alone. If a retry decision depends on the string, the same agent behaves differently against three sellers running three official SDKs. A payment that is expired and mispriced is repairable by refreshing the window in one facilitator and by re-reading requirements in another; the agent picks the wrong repair half the time. The safer architecture is to treat every invalid_exact_evm_* as "the payload was rejected; re-derive it from the current 402 and re-sign once", and to reserve genuine retry semantics for the codes that describe transport — unexpected_verify_error, failed_to_get_network_config, and invalid_exact_evm_failed_to_verify_signature when the message says the lookup failed rather than the signature.
We must carry our own minimum window. Six seconds is a floor we now know exists, and it is not the whole story: the window also has to cover the round trip from signing to settlement, which is a network property, not a constant. Building validBefore as now + maxTimeoutSeconds is only safe if maxTimeoutSeconds is comfortably above the floor and above our measured p99 signing-to-settle latency. Where a seller advertises less, the correct move is to treat the offer as unpayable rather than to sign something that will be rejected as expired.
We should verify the form before we sign, not after we are told. Our own client should emit v in {27, 28} and low s unconditionally, and reject a facilitator response or a replay of a stored payload whose v is 0 or 1. The check costs a byte comparison; discovering it at settle costs gas and a failed request. The batch-settlement rule that merged this week is the model, and there is no reason for our buyer to wait for exact to adopt it.
None of this is a reason to distrust x402. It is a reason to treat the error vocabulary as what it currently is: three dialects of one protocol, each internally consistent, converging one pull request at a time. Building against the intersection of the three, rather than against the spec alone, is the difference between an agent that self-corrects and one that loops.
Staying on the frontier
First, pin the vocabulary. Generate a table of the three SDKs' error constants at build time — the tables are plain source, so this is a parser, not an integration — and fail CI when a code we branch on disappears or changes spelling. The 17-string intersection is small enough to assert in a test, and it makes every SDK bump a reviewable diff instead of a runtime surprise.
Second, contribute the check-order findings to #4280 and #4307. The remaining-validity thread has the constant and the three call sites; it does not have a table of what a two-fault payload returns in each SDK, and the seven rows above show that the code a client receives depends on the language the facilitator was written in. That is a concrete argument for stating the verification order in the spec, or for making the diagnostics independent of order.
Third, open the v gap as its own issue against exact. The batch-settlement text merged on 2026-11-18 states the rule in one sentence — "65 bytes, low s, and v of 27 or 28" — and the same sentence belongs in the EIP-3009 and Permit2 verification steps. Until it lands, run the simulation.
Fourth, never disable simulation on the settle path without a reason you can write down. All three SDKs default simulateInSettle to false. For a facilitator whose verify already simulated a moment earlier that is a defensible optimization; for a facilitator accepting a payload it has not simulated, it is the difference between rejecting a bad signature and paying gas to broadcast it.
Fifth, publish our own reason-code mapping, in the gateway docs, with the terminal/retryable bit attached to each code. Every buyer that talks to us through an OpenAI-compatible endpoint inherits our interpretation of these strings; making it explicit is cheaper than having each agent guess.
Sixth, keep the numbers we measured as regression fixtures. A 28-vector suite that runs the same signed payloads against all three implementations is an afternoon of work and it is the only thing that will catch the next precedence change — the kind of change that no single SDK's test suite can see.
Pay per call, on rails that report honestly.
LLM4Agents is an OpenAI-compatible gateway where autonomous agents pay per request in stablecoins over x402, and we treat the reason code as an interface we have to get right.
Register an agent