r/ethdev • u/Mysterious-Day-9896 • 10d ago
Question I built on-chain spending limits + passkey approvals for AI agents (ERC-7710 delegations, open source,feedback wanted)
I've been working on a problem I think more of us will hit soon: AI agents that can spend money.
The usual options are bad: give the agent a key (unbounded loss on the first prompt injection), or use a custodial agent wallet whose policy engine runs on someone else's servers.
cyphos-guard takes a different route, using the MetaMask Delegation Framework:
- The owner has a Hybrid DeleGator smart account (passkey owner via RIP-7212, optional EOA recovery).
- The agent gets one delegation per permission, with caveats: recipient allowlist, per-period caps (NativeTokenPeriodTransfer / ERC20PeriodTransfer), allowed methods, expiry.
- ERC-20 per-tx caps can't be expressed with stock enforcers, so I wrote a small CosignerEnforcer: a policy service co-signs each redemption (EIP-712, single-use, 5-min deadline). It can only block, never move funds.
- Over the limit → approval request → the owner signs a one-shot delegation (ExactExecution + LimitedCalls(1) + Timestamp) with a passkey on their phone.
- For x402 APIs: an ERC-1271 "vault" is the payer and only approves EIP-3009 TransferWithAuthorization to listed sellers. Verified against the official x402 facilitator on a fork, then live on Base Sepolia.
- A static recovery page lets the recovery EOA sign a UserOp (EIP-712) and self-submit via EntryPoint.handleOps: no bundler, no backend.
Status: testnet only, not audited; I published an internal security review (3 findings fixed). Live runs with Basescan links are in the README.
Questions I'd love input on:
- Anyone found a clean way to express ERC-20 per-tx caps without a co-signer?
- Would you trust an ERC-1271 vault as an x402 payer, or wait for ERC-7710 support in facilitators?
Links: https://github.com/Phosse136/cyphos-guard · https://cyphosguard.com · npm: @cyphos-guard/sdk
1
u/Bloqarl 9d ago
for the per-tx cap, you can drop the co-signer with a small stateless enforcer: decode the amount from the execution calldata in beforeHook and check it against the terms, basically ERC20TransferAmountEnforcer without the running total. pin the selector to transfer and single-call mode in the same enforcer too, or an approve or a batch walks around the cap.
1
u/Mysterious-Day-9896 8d ago
Update, mostly thanks to this thread:
Per-payment cap is on-chain now. The gap someone pointed out here (an agent redeeming directly could spend the whole period budget in one transfer) is closed by a new
ERC20PerTransferCapEnforcer; details in my reply to that comment and in the design note.I attacked it on a live grant. A test agent with a stolen key ran 25 known attacks straight against the DelegationManager on Base Sepolia, skipping my SDK and service: one unit over the cap, paying itself, approve/permit/transferFrom, batch and try mode, re-delegating to itself without caveats, editing the signed caveats, forged x402 vault payments. 25/25 reverted, each with the expected reason, and a payment of exactly the cap still went through. Transactions.
The same catalog runs on a fork on every push, plus Halmos proofs and a mutation test (26 planted bugs, all caught).
If you can think of attack #26, there's an issue template for it, and a good one becomes a test.
1
u/Productiverobot 5d ago
Really clean architecture — moving the per-tx ERC-20 cap into a stateless enforcer instead of relying purely on a cosigner is a huge trust-model upgrade.
One complementary pattern worth considering specifically for your x402 API path when an agent runs tight loops (e.g., hundreds of $0.001–$0.01 tool calls):
Instead of having the agent trigger an ERC-1271 / EIP-3009 transfer authorization on every single HTTP request, your Hybrid DeleGator passkey vault can open a single pre-capped SHA-256 PayWord hash-chain channel once (locking
maxSteps * unitAmountUSDC againstw_0 = SHA256^N(w_N)for a specificrecipient+expiry), and hand the agent only the 32-byte hash chain seed — no EVM private key at all.Why it composes nicely with ERC-7710:
maxSteps * unitAmount, and strictly to the committed seller address.w_k(1 SHA-256 hash on the server, $0 gas), and unused USDC returns to the vault viarefund()after expiry orcloseAndRefund().We just deployed an ownerless, 0%-fee reference contract for this on Base Mainnet (
0x971BA814Df91c20DcA3aDd870C2B55d643965C50, Sourcify exact_match) and proposed it as abatch-settlementx402 extension (https://github.com/x402-foundation/x402/issues/4494). Could be an easy caveat-target to whitelist alongside direct EIP-3009 sellers.1
u/[deleted] 10d ago
[removed] — view removed comment