feat(evm): add shielded payment mechanism (privacy pool unshield)#1956
Open
mmchougule wants to merge 3 commits intox402-foundation:mainfrom
Open
feat(evm): add shielded payment mechanism (privacy pool unshield)#1956mmchougule wants to merge 3 commits intox402-foundation:mainfrom
mmchougule wants to merge 3 commits intox402-foundation:mainfrom
Conversation
Adds `specs/schemes/exact/scheme_exact_evm_shielded.md` — the specification for a new `assetTransferMethod: "shielded"` under the existing `exact` scheme on EVM chains. This enables privacy-preserving x402 payments where the payer's identity is hidden behind a ZK proof verified by an on-chain privacy pool (e.g., Railgun). The facilitator verifies payments by inspecting the standard ERC-20 Transfer event emitted during unshield — no viewing keys or trial decryption required. Key properties: - Settlement: Client-driven (unshield on-chain before verification) - Verification: ERC-20 Transfer event from registered pool contract - Privacy: Sender hidden via ZK proof; amount visible to facilitator - Token: Any ERC-20 supported by the privacy pool (USDC, USDT, DAI) - Gas: Client pays, or gasless via ERC-4337 This is designed to be general — works with any privacy pool that emits standard ERC-20 Transfer events, not tied to a specific implementation. Relates to x402-foundation#1633
Implements SchemeNetworkClient, SchemeNetworkFacilitator, and SchemeNetworkServer for assetTransferMethod: "shielded" on EVM. Client calls an injected UnshieldFn (SDK-agnostic) to withdraw tokens from a privacy pool to the payTo address. Facilitator verifies the resulting ERC-20 Transfer event: from must be a registered pool contract, to must match payTo, value must meet the required amount. Settlement is client-driven — facilitator is verify-only. Verification flow: - Validate txHash format and check replay store - Fetch tx receipt (non-reverted = pool accepted the ZK proof) - Parse Transfer event logs against pool contract allowlist - Track txHash + nullifiers in replay store for double-spend prevention - Settle re-verifies before confirming (follows EVM/SVM pattern) 26 unit tests covering: valid payment, invalid hash, reverted tx, wrong pool, wrong recipient, wrong amount, wrong token, txHash replay, nullifier replay, settle re-verification, settle failure, server price parsing, requirement enhancement, client payload creation. Relates to x402-foundation#1953
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
ShieldedEvmClient,ShieldedEvmFacilitator, andShieldedEvmServerimplementingassetTransferMethod: "shielded"for theexactscheme on EVM.Agents withdraw tokens from an on-chain privacy pool (e.g., Railgun) directly to the merchant's
payToaddress. The pool contract verifies the ZK proof and checks nullifiers on-chain. The facilitator confirms the resulting ERC-20 Transfer event matches the payment requirements.Reference implementation uses a deployed privacy pool on Base (Railgun) with on-chain nullifier tracking for double-spend prevention.
Implementation
Client (
ShieldedEvmClient): Takes an injectedUnshieldFn— SDK-agnostic, any privacy pool works. Calls unshield and returns{ txHash }.Facilitator (
ShieldedEvmFacilitator):frommust be a registered pool contract,tomust matchpayTo,value>= requiredServer (
ShieldedEvmServer): Parses prices, enhances requirements withassetTransferMethod: "shielded"andpoolContracts.Tests
26 unit tests covering:
All 365 existing tests still pass.
Files
Spec: #1951
Closes #1953