HTTP 402 Machine-to-Machine Challenge-Receipt Wire Protocol (x402)HTTP 402 机器间挑战—回执报文传输协议标准(x402)
W3AI Open Standards Steering Group · Machine Micropayments Working GroupW3AI 开放标准指导委员会 · 机器微支付协议工作组
Defines a vendor-neutral, four-state deterministic wire protocol over RFC 9110 Section 15.5.3 (HTTP 402 Payment Required) enabling autonomous software agents to negotiate metered compute, data, and verification calls with zero protocol rake (0 bps), bounded 32 KB anti-flood framing, and single-slot finality verification.基于 RFC 9110 第 15.5.3 节(HTTP 402 Payment Required)定义厂商中立的四态确定性机器微支付传输协议,支持自主智能体以零协议抽成(0 bps)、32 KB 防泛洪报文上限与单槽确定性终局核验完成算力与接口按次原子清算。
Normative Specification规范协议定义
1. Normative Scope & RFC 2119 Conventions
This specification standardizes the x402 challenge-receipt wire protocol over HTTP/1.1, HTTP/2, and HTTP/3. The key words MUST, MUST NOT, REQUIRED, SHALL, and SHOULD are to be interpreted as described in IETF RFC 2119. A conformant gateway MUST reject any request body or receipt envelope exceeding 32,768 bytes (32 KB) with HTTP 413 Content Too Large prior to cryptographic parsing.
2. Four-State Deterministic Automaton
- State S0 (
REQUEST_RESOURCE): Client agent issues an idempotent request carryingX-Agent-IdentityandX-Preferred-Unitheaders without pre-spending settlement units. - State S1 (
PAYMENT_REQUIRED_402): Gateway responds with status402 Payment Required, returningWWW-Authenticate: x402challenge parameters includingchainId,verifyingContract,amountUnits,nonceLanein[0, 31],validBeforeUNIX timestamp, and a domain-boundchallengeDigest. - State S2 (
SUBMIT_SIGNED_RECEIPT): Client verifies challenge bounds inside an isolated policy engine, signs an EIP-712 typed receipt over its assigned 2D nonce lane, and resubmits withAuthorization: x402 <base64url-receipt>; gateway acknowledges in-flight verification via202 Acceptedor proceeds synchronously. - State S3 (
VERIFIED_FULFILLMENT): Gateway confirms deterministic single-slot finality (p_reorg = 0), pre-commit policy authorization, and exact conservation before returning200 OKwithX-Settlement-TxHash.
3. Conservation & Rake-Free Split Invariant
Conformant escrow contracts MUST enforce zero protocol extraction (0 bps) so off-band Sybil collusion yields strictly negative net utility after base execution gas.
1. 规范适用范围与 RFC 2119 术语约定
本标准定义运行于 HTTP/1.1、HTTP/2 与 HTTP/3 之上的 x402 机器间挑战—回执报文传输协议。规范中的 必须(MUST)、严禁(MUST NOT) 与 应当(SHALL) 严格遵循 IETF RFC 2119 语义。合规网关在密码学解析前必须拦截超过 32,768 字节(32 KB)的负载并返回 HTTP 413 Content Too Large。
2. 四态确定性状态自动机
- 状态 S0(
REQUEST_RESOURCE):客户端智能体携带X-Agent-Identity与X-Preferred-Unit标头发起资源请求,前置零扣款。 - 状态 S1(
PAYMENT_REQUIRED_402):服务端返回402 Payment Required及WWW-Authenticate: x402挑战头,给定chainId、验证合约、整数微单位金额、分配的并行车道nonceLane in [0, 31]、截止时间戳与域绑定摘要challengeDigest。 - 状态 S2(
SUBMIT_SIGNED_RECEIPT):客户端在隔离策略防火墙内校验限额后,在指定二维 Nonce 车道签发 EIP-712 结构化回执并通过Authorization: x402提交。 - 状态 S3(
VERIFIED_FULFILLMENT):网关确认单槽确定性终局(p_reorg = 0)、内核策略放行与分账守恒后返回200 OK与链上交割哈希。
3. 零协议抽成与原子分账守恒律
合规结算托管实现必须锁死零协议抽成(0 bps),从机制设计根源消除链下女巫绕行激励。
Canonical Wire JSON Schema标准报文 JSON Schema
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://research.web3.capital/schemas/w3ai-rfc-001.schema.json",
"title": "W3AI-RFC-001 x402 Challenge-Receipt Envelope",
"type": "object",
"required": [
"protocol",
"chainId",
"challengeDigest",
"escrowContract",
"grossUnits",
"authorUnits",
"payeeUnits",
"protocolRakeBps",
"nonceLane",
"validBefore",
"payloadBytes"
],
"properties": {
"protocol": {
"const": "x402/1.0"
},
"chainId": {
"type": "integer",
"minimum": 1
},
"challengeDigest": {
"type": "string",
"pattern": "^0x[0-9a-f]{64}$"
},
"escrowContract": {
"type": "string",
"pattern": "^0x[0-9a-fA-F]{40}$"
},
"grossUnits": {
"type": "integer",
"minimum": 1
},
"authorUnits": {
"type": "integer",
"minimum": 0
},
"payeeUnits": {
"type": "integer",
"minimum": 1
},
"protocolRakeBps": {
"const": 0
},
"nonceLane": {
"type": "integer",
"minimum": 0,
"maximum": 31
},
"validBefore": {
"type": "integer",
"minimum": 1700000000
},
"payloadBytes": {
"type": "integer",
"minimum": 1,
"maximum": 32768
}
},
"additionalProperties": false
}
Clean-Room & Open-Source Reference Implementations独立洁净室验证器与开源参考实现
W3AI-RFC-001 Clean-Room State-Machine VerifierW3AI-RFC-001 洁净室四态协议验证器
Web3 Capital Research (Republic of Singapore) · Apache-2.0
Vendor-neutral conformance harness (250 x402 test vectors)厂商中立开放一致性测试套件(250 组 x402 向量)
https://research.web3.capital/vectors/w3ai-conformance-v1.json
MYRILUM Linghe Chain x402 Gateway & ERC-8004 ValidationEscrowMYRILUM 灵核公链 x402 清算网关与 ERC-8004 托管合约
MYRILUM LIMITED (HK UBI 80912065 · COPE Disclosed R&D Reference) · MIT
Independent open-protocol reference implementation (0x8004...0003, ChainID 88888)独立开源协议参考实现(0x8004...0003,ChainID 88888,披露研发协同关联)
Normative References规范性引用文件
- [RFC9110] R. Fielding, M. Nottingham, J. Reschke (2022). HTTP Semantics — Section 15.5.3 (402 Payment Required). https://www.rfc-editor.org/rfc/rfc9110
- [EIP712] R. Bloemen, L. Logvinov, J. Evans (2017). EIP-712: Typed structured data hashing and signing. https://eips.ethereum.org/EIPS/eip-712