Inconsistent amount units: `payment.budget.max` read as dollars, `payment.amount_range.max` as cents
Version: e1ea56db72a6385bce3e5c1112b3a56ce60acb43 (v0.2).
The inconsistency
Every amount in a closed Payment Mandate is an integer in minor units:
types/amount.jsonamount: "Amount in minor units, according to the ISO-4217 spec."
The two amount constraints disagree with this, and with each other, across schema, docs and SDK:
Schema (open_payment_mandate.json) |
Doc example (payment_mandate.md) |
SDK (constraints.py) |
|
|---|---|---|---|
payment.amount_range.max |
integer, "Maximum allowed amount in minor (cents) unit of currency." |
"max": 100.50 |
compared directly with the minor-unit amount |
payment.budget.max |
number, "Maximum amount for the budget." |
"max": 1000.00 |
budget_max_cents = int(self.constraint.max * 100) |
So the SDK treats amount_range.max as cents and budget.max as dollars. The documentation
writes both as dollars.
Effect
The same number means two different limits depending on the constraint:
- Budget.
{"type": "payment.budget", "max": 250, "currency": "USD"}with a 19900 (USD 199.00) payment: the SDK accepts it (25000 ≥ 19900). An implementation following the Amount type (max= 250 cents) rejects it. - Amount range.
{"type": "payment.amount_range", "max": 250.0, ...}written in the style of the documentation example: the SDK rejects the same 19900 payment ("Amount 19900 exceeds maximum 250"). A reader of the documentation example expects a USD 250.00 limit, i.e. accept.
A user who approves "budget 250" on a Trusted Surface could get a USD 2.50 or a USD 250.00 limit, depending on the verifier.
Reproduction
These are KYA Bench conformance vectors, run against the SDK at the commit above
(MandateClient.verify + PaymentMandateChain.verify):
ap2-budget-unit-ambiguous: SDK accepts; KYA Bench reportsindeterminate(outcome depends on the unit).ap2-amount-range-decimal-max: SDK rejects; KYA Bench reportsindeterminate(decimal value against an integer schema).ap2-budget-cumulative-exceeded: SDK and KYA Bench both reject; the outcome is the same under either reading.
Suggested resolution
State that every amount-like constraint field is an integer in ISO 4217 minor units. Make
budget.max an integer in the schema, drop the * 100 in BudgetEvaluator, and update both
documentation examples (e.g. "max": 10050, "max": 100000).
Also noted (lower priority)
checkout.allowed_merchants with no revealed entries is "invalid" in AP2 (checkout_mandate.md:
"if the allowed contains no revealed elements, the constraint is invalid"). The equivalent VI
constraint skips the check instead. This doesn't affect AP2 on its own, but anyone translating
AP2 intents into VI-style constraints will get a different verdict for the same probe (KYA Bench
vector xlate-undisclosed-allowlist).
Two measurements on the SDK side at e1ea56d that bear on this, whichever unit is chosen (per CONTRIBUTING the core specification now lives at FIDO; the SDK and samples are here):
- The documentation example
"max": 100.50forpayment.amount_range(docs/ap2/payment_mandate.md:186) does not load:AmountRange.model_validateraises aValidationErroron theintfield.250.0loads and becomes250, which is whyap2-amount-range-decimal-maxreads as 250 minor units. The doc example and the model already disagree, before any unit decision. Budget.maxis afloat:Budget(max=10, currency="USD").model_dump_json()writes"max":10.0. If the schema moves tointeger, whole-number budgets written this way still validate (JSON Schema Validation 2020-12 §6.1.1: any number with a zero fractional part), but Core §6.3 says integers SHOULD NOT carry a fractional part, and a reader that refuses that encoding rejects them (ap2-evidence-pack, which I maintain, does today); a fractional budget such as0.29no longer validates; and if the unit becomes minor units, a10.0written today as USD 10 reads as 10 cents. The type change, the model field (max: int) and a migration note belong together.
Related and not linked here yet: #339 (23 Aug) raised the undocumented unit of budget.max, and #368 / #377 fix the SDK's conversion in the other direction (major units with the ISO 4217 exponent). How an offline verifier grades the 250 / 19900 case while the unit is open is in x402-foundation/x402#2452, not repeated here.
Thanks — both measurements are at the same pinned commit I used (e1ea56d), and they sharpen two points in the issue:
-
The doc example doesn't just disagree with the model — it doesn't load. I hadn't separated the two cases:
"max": 100.50raises aValidationErroron theintfield, while250.0silently coerces to250. The KYA Bench vectorap2-amount-range-decimal-maxuses the250.0form, which is why the SDK run reads it as 250 minor units and rejects the 19900 payment. I'll add the unloadable-example case to the spec-gap entry (AP2-04): a documentation example that the SDK's own model refuses is a stronger form of the same gap. -
Agreed that the type change, the model field, and a migration note belong together. The resolution suggested above (integer in the schema, drop the
* 100, fix the examples) covers writers going forward, but not mandates already written with a floatBudget.max: under minor units a10.0written today as USD 10 would read as 10 cents, and fractional budgets such as0.29would stop validating. The migration note should say both, and state the reader rule explicitly — integers SHOULD NOT carry a fractional part (Core §6.3), so a reader may reject10.0rather than coerce it, as ap2-evidence-pack already does.
On grading while the unit is open: KYA Bench reports the 250 / 19900 case as indeterminate, consistent with the grading described in x402-foundation/x402#2452 — no change needed there.
Linking the related threads for the record: #339 raised the undocumented unit of budget.max, and #368 / #377 fix the SDK's conversion in the major-unit direction.