r/ethdev • u/Productiverobot • 9h ago
My Project We deployed an ownerless O(1) SHA-256 PayWords USDC channel on Base Mainnet (x402 batch-settlement) — 1,000 metered API calls in 0.235 ms/call ($0 gas) settled in 1 tx (783k gas) + Lean 4 proofs
If you are building metered AI APIs, MCP servers, or x402 endpoints on Base, you hit two ugly walls pretty fast:
- Stripe cards (2.9% + $0.30/call) make $0.001–$0.01 per-call billing mathematically impossible ($300+ in fees to settle $1 of micro-calls).
- Per-call on-chain EIP-3009 (x402) works great for single one-off requests, but when an agent calls your API 500–1,000 times in a loop, firing a separate on-chain tx per call adds latency, facilitator overhead, and retry double-spend risk.
We took the classic Rivest–Shamir (1996) PayWords SHA-256 hash-chain idea, implemented it against the EVM native sha256 precompile (0x02), formally proved exact escrow conservation in Lean 4, and deployed it ownerless with 0% protocol fee on Base Mainnet (eip155:8453).
How it works
- Payer locks USDC once: Generates a 32-byte seed
w_N, hashes itNtimes to get public rootw_0 = SHA256^N(w_N), and callsopenChannel(recipient, USDC, w_0, unitAmount, N, expiry)once. - Zero-gas O(1) calls: On call
k, the client sends(channelId, k, w_k)in HTTP headers. The server checks 1 SHA-256 hash (SHA256(w_k) == lastAccepted) and advances a monotonic cursor — zero signatures, zero RPC calls, zero gas per request. Becausekis strictly monotonic, retrying a dropped HTTP call withw_kis idempotent by construction. - 1-tx batch settlement: After 100 or 1,000+ calls, the server submits
claim(channelId, steps, w_k)once on Base. Unused escrow returns cooperatively viacloseAndRefund()or unilaterally to the payer viarefund()afterexpiry.
Live Base Mainnet Proofs & Measured Numbers
- Contract (
NewsatoshiPayWordChannel):0x971BA814Df91c20DcA3aDd870C2B55d643965C50(ownerless, non-upgradeable, fee-on-transfer & reentrancy guarded) - Sourcify
exact_match: https://repo.sourcify.dev/8453/0x971BA814Df91c20DcA3aDd870C2B55d643965C50 Live Base Mainnet USDC test cycle:
openChannel: https://basescan.org/tx/0x8229bb7282f79b819122c40e66e8f8dcec832d30fccb1a5b75f9eb49133be31d (235,233 gas)claim(7, w_7): https://basescan.org/tx/0x122885e1b36aa5b8a62f97f4b4bfb3b235bdebe0055a8cd3a4ed7c52393a5356 (96,449 gas)closeAndRefund: https://basescan.org/tx/0x3a826c82fdaffdbbdb8049db7793a342524e3a74742c9504ef8baad1380c4c0d (62,735 gas)
- Foundry 1,000-step batch gas:
claim(1000)= 783,140 gas (~$0.0196 at 0.01 gwei / $2,500 ETH vs. $300.03 on Stripe). - End-to-end localhost Node HTTP 402 demo (
node examples/paywords-base-demo.mjs): 1,000 SHA-256 links generated in 2.25 ms; 1,000/1,000 HTTP 200 calls in 235.1 ms (0.235 ms/call incl. TCP) + replay guard verified.
Companion Contract: Revenue-Backed Fair Bonding Curves (0% Premine, 0% Platform Cut)
We also deployed an immutable NewsatoshiFairCurveFactory (0xF6bE782819a8eD0D1556A8f5DC3223f9eb13a933, Sourcify exact_match) where an API/agent can pipe its settled PayWords USDC straight into injectRevenue(amount) — distributing dilution-proof pro-rata USDC dividends (REV_PRECISION = 1e30) to existing holders while preserving the exact integer constant-product curve solvency invariant.
Try It / Re-Verify Offline
- Live browser WebCrypto benchmark (runs 1,000 real SHA-256 calls on your CPU) + Cloudflare/Express/FastAPI snippets: https://newsatoshi.org/paywords/
- 1-Click EIP-1193 wallet console (MetaMask/Coinbase/Rabby) + live Base curves reader: https://commons.newsatoshi.org/#launchpad
- Zero-dependency single-file JS & Python SDKs: https://newsatoshi.org/sdk/newsatoshi-402.mjs and https://newsatoshi.org/sdk/newsatoshi-402.py
- GitHub repo + Foundry tests (20/20 incl. 256 fuzz runs) + Lean 4.36.0 proofs (18 theorems, 0 sorry): https://github.com/theguysaccount/newsatoshi-commons
- Linux Foundation x402 proposal: https://github.com/x402-foundation/x402/issues/4494
Honest Trade-Offs & Current Limitations
- Upfront channel open: Costs 1 Base tx (~235k gas) per buyer-seller pair, so per-call EIP-3009 still wins for single one-off requests to new sellers.
- Liveness before expiry: The server must submit
claim()beforeexpiry(enforced by a configurableminRemainingExpirySecbuffer in the SDK gate). - Audits & License: We have 20/20 Foundry tests + 256 fuzz runs + Lean 4 conservation proofs (
0 sorry), but 0 external human security audits so far — treat early usage accordingly. The wire protocol is open (x402#4494); reference repo code is licensedPolyForm-Noncommercial-1.0.0.
Would genuinely appreciate any Solidity/EVM gas-golfing feedback, security review on NewsatoshiPayWordChannel.sol / NewsatoshiFairCurveFactory.sol, or thoughts on integrating batch-settlement into x402.