Skip to content

Bind x402 payment authorizations to the validating wallet and its parents - #111

Open
Agusx1211 wants to merge 2 commits into
x402-sapientfrom
x402-bind-parent-wallets
Open

Agusx1211 wants to merge 2 commits into
x402-sapientfrom
x402-bind-parent-wallets

Conversation

@Agusx1211

Copy link
Copy Markdown
Member

_recoverPaymentSignature had the session key sign hashSessionAuthorization(wallet, policyRoot, payload.digest), where payload.digest is the raw Permit2 digest. That digest carries no owner and the authorization ignored payload.parentWallets, so the tuple the signer saw for a direct payment from a wallet was identical to the tuple it saw when the same wallet was reached as a sapient signer of a parent wallet. The same signature bytes validated for both owners, and since Permit2 nonces are per owner both transfers could settle off one authorization. The bytes are public in calldata after the first settlement, so anyone could do the second one.

The payment path now signs Payload.hashFor(payload, wallet), the same wallet-scoped hash the approval path already used. That commits to the Permit2 digest, the noChainId flag, parentWallets and the wallet domain, so a payment authorized for one wallet no longer validates through a parent that delegates to it, and vice versa. Every other leaf type was already protected because the wallet opHash commits to parentWallets; only this path skipped it.

Ran forge build and forge test --match-path "test/extensions/x402/*" on foundry v1.5.1: 49 passed, 0 failed. That is the 47 existing tests, whose signing helpers now sign the wallet-scoped hash, plus two new ones covering the nesting cases. I confirmed both new tests fail against the old code. I did not run the rest of the suite because it needs an external RPC server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant