Skip to content

feat(rules): spending limits, approved automatically - #39

Merged
USCMig merged 14 commits into
mainfrom
feat/spending-limits
Oct 26, 2026
Merged

USCMig merged 14 commits into
mainfrom
feat/spending-limits

Conversation

@USCMig

@USCMig USCMig commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #38 (delay with veto), and through it on the earlier PRs. Merge those first; until then this diff also shows their changes.

Summary

Spending limits: routine payments can be approved automatically. Under a new group rule, members' apps may approve payments to trusted payees by themselves while the wallet has sent less than an amount in a period, for example 1 ZEC a week.

  • Each member opts in for their own app. Under Rules, Approve automatically on this device turns it on, and shows how much of the limit the wallet has used. The others approve as they choose.
  • An app approves by itself only when all of these hold:
    • every payment goes to a trusted payee;
    • no other rule needs more approvals or a wait;
    • the fee is usual;
    • the payment and its fee fit in what's left of the limit.
  • Every other check runs first. The app still verifies the transaction and checks every other rule, and it tells the member when it approves.

Why the limit holds

  • It counts everything the wallet sent in the period, however it was approved. So it holds however many members turn automatic approval on.
  • That total comes from two sources:
    • History: the wallet's history since the height that long ago. The period is counted by block spacing because a chain's block times needn't be current; on the devnet they aren't, which is how this surfaced.
    • In flight: what this device approved automatically in the last 70 minutes that may not be in the history yet. A payment can count twice for up to an hour, never too little.
  • No fresh sync, no automatic approval. Without a sync in the last 15 minutes, the app approves nothing by itself.
  • One charge per transaction. An automatic approval is remembered by sighash like a manual one, so the transaction's later rounds go through and the limit counts it once.

Changes

  • Core (rules.rs): SpendingLimit, may_approve_automatically, NotAutomatic with readable reasons, usual_fee, and validity limits on the period.
  • App
    • rules.rs: spent_in_period, automatic_approval, record_automatic_approval, and the commands auto_approval_status and set_auto_approve.
    • private.rs: auto_approve added to private settings.
    • state.rs: the in-flight record of automatic approvals.
    • signing.rs: the gate decides and records automatic approvals, and adds an auto_limit annotation. The verdict's poll and limit reports are boxed to stay within clippy's size limit.
  • Frontend
    • The toggle and the usage line on the Rules card.
    • The limit option in Propose rules.
    • In Approvals, "Approved automatically by your app … the wallet has now sent X of Y", or "Not approved automatically: why".
    • A notification when the app approves by itself.
  • Docs: user guide (Rules), README, CHANGELOG, TODO.md.

Testing

  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo test --workspace
  • tsc, then vitest (47 tests)
  • Core test: an_app_approves_routine_payments_to_trusted_payees_by_itself_within_the_limit, covering trusted payees, large payments, the fee, exactly up to the limit, and over it. Plus validity limits.
  • Devnet (NU7), tests/devnet_send.rs, which passed:
    1. Bob's app syncs the wallet.
    2. A limit just above what the run has sent is adopted by poll, and Bob turns automatic approval on.
    3. A 0.05 payment to the trusted auditor is approved by Bob's app with no action from Bob.
    4. The next payment, which would go over the limit, is left to Bob, with "over the limit".
    5. Send-all completes the run.
  • Frontend tests:
    • The toggle and its usage line.
    • Proposing a limit.
    • Approvals showing an automatic approval, and a request that wasn't approved automatically, with the reason.

🤖 Generated with Claude Code

USCMig and others added 14 commits October 25, 2026 22:59
Payees are a group's shared list of the addresses it pays, by name. They
travel as group records alongside polls (core/src/payees.rs works them
out). A payee belongs to the member who added it: only their records can
change or remove it, so one member can't swap the address behind a name
another saved. The app also refuses a second payee with the same name or
address, and only shows payees valid on the configured network.

An approver's app names a payment from its own copy of the list, by the
address the transaction verifiably pays. verify::address_forms gives a
payee's address both as given and in the Orchard-only form a verified
payment shows, so a unified address with several receivers still matches.

A reason says what a payment is for, for the group only. It goes to
approvers in SigningContext.reason (older apps ignore the field) and,
once the payment is broadcast, into a PaymentReason record keyed by txid,
so every member's history shows it. Any member can add theirs to any
transaction. Try sending again records it after a successful rebroadcast.

The interface: a payee picker and "Save as a group payee" in the send
form, a Reason field, payee names and reasons in the review, the
approval and Activity, and a Payees card on Home.

SigningContext is boxed in ParticipantEvent::AwaitingApproval, which the
new field pushed over clippy's large-variant limit; it serializes the same.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
User guide section, README features and security model, CHANGELOG,
PRIVACY.md, and the rest of the Safe-style list in TODO.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Up to 20 payments in one transaction, for payroll, grants and invoices.
The send form's "Pay several at once" takes rows (recipient or saved
payee, amount, memo) or a pasted list, with one reason for the lot.

wallet::prepare_payments builds them with propose_transfer and a ZIP 321
request; prepare_send is now a batch of one through the same path (the
one-payment wrapper it used is exactly that). A memo too long to encode
is an error instead of being dropped, and memos are trimmed, as they
read back. Within a batch, the group's own address is refused: it would
read as change to co-signers.

Co-signers get every payment in SigningContext.payments (without memos,
which they read from the transaction). check_coordinator_claims matches
them to the verified payments as an unordered set, since Orchard
shuffles outputs: each described payment matches a different one, and
there are no others.

Signing requests are now sized to fit one frostd message. The context
travels hex-encoded inside the signing package, which the old 48 KiB
limit on the attached PCZT didn't count, so a large enough transaction
failed with "cryptography error from snow: input error".
signing::signer_context_budget gives the real room for the chosen
signers (tested against a serialized SendSigningPackageArgs for 2 to 40
signers), and the PCZT gets what the rest of the context leaves. One that
can't fit is refused at review, saying to make fewer payments.

History lists a send's external payments (TxRecord.payments). The wallet
learns of its own sends only by scanning, without their fee or outputs,
so the sending device shows its sends as it built them; recording them
in the wallet is in TODO.md.

Tested on an NU7 devnet: 20 payments, three with memos, approved and
mined; 20 with full memos refused at review.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A group poll can propose payments (Poll.payments, up to 20), answered
"Pay" or "Don't pay". Once Pay is agreed, the member who proposed it
sends them with Send payment: wallet_send with poll_id builds the
transaction from the poll itself, refusing unless this member asked it,
the group agreed to pay, and it hasn't been paid. After broadcast, a
PollPaid record (only the poll's author's counts) marks it paid, so it
can't be sent twice, and the poll's question becomes the reason.

Each approver's app checks a request naming a poll (SigningContext.poll_id)
against its own copy of the poll and refuses one sent by a member other
than its author, one that doesn't make exactly the proposed payments (an
unordered match on address, amount and memo), or one already paid. It
shows whether the group agreed, or warns that it hasn't, or that it
doesn't have the poll yet. The coordinator's key, which the request's
encryption authenticates, now comes with the approval event for this.

Members who chose Pay are asked to approve by default. Approving
automatically for them is left for the spending-limit rules.

Tested on an NU7 devnet: refused before agreement and for Bob, sent by
Alice and checked by Bob's app, then shown paid on both and refused a
second time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A group can adopt rules for its payments, which the sender's app and each
approver's app apply when deciding whether to sign (core/src/rules.rs):

- Pay only trusted payees. A payee is trusted once threshold members
  trust its current address: its author, and others who said so in a
  PayeeTrust record. Changing the address leaves only the author's trust.
- Larger payments need more approvals: payments of at least an amount,
  together in one transaction, need more signers than the threshold. An
  approver counts the signers committed in the signing package
  (AwaitingApproval.signers), each of whose shares the signature needs.

Rules are adopted by poll (Poll.rules, options Adopt / Don't adopt), and
the latest set the group agreed to adopt is in effect, so changing them
takes as many members as spending. create_poll refuses rules this group
can't meet (more approvals than members, or no more than the threshold).

commands::rules::check runs the same check on both sides: the sender's
wallet_send verifies its own draft as approvers will and refuses before
asking anyone; the approval gate refuses a request that breaks the rules,
or whose rules it can't read, and tells the approver which rules it met.
A transfer within the group makes no payments, so the rules don't apply.

Interface: a Rules card on Home (in effect, and Propose rules), Trust on
the Payees card, rule polls in Votes, rule errors and approval counts in
the send forms, and the rules a request met in Approvals.

Tested on an NU7 devnet: with "trusted payees only" adopted by poll, a
payment to an untrusted address is refused before anyone is asked, and
one to the trusted auditor goes through with Bob's app checking it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A new rule, GroupRules.delay: payments of at least an amount, together
in one transaction, are announced in a payment poll and can be sent only
once a wait (an hour to 30 days) has passed with no current member
choosing Don't pay. Agreement isn't needed; one member's veto stops it
for as long as they keep that answer.

Each app counts the wait from when it received the announcement: the
group log now records when each record arrived (GroupLog.received), and
PollView.announced_at is the later of that and the time its author put
on it. A backdated announcement gains nothing, and every member has the
whole wait to object.

commands::rules::poll_permits decides whether a poll's payments can be
sent: under the delay, once ready (rules::announcement_ready); otherwise,
once agreed. The sender's wallet_send refuses a poll that isn't, and a
payment over the amount without one (Broken::NotAnnounced). The approval
gate refuses an announcement that isn't ready on its own clock, and an
unannounced large payment, including one whose poll it doesn't have.

The send forms offer "Announce it" instead of review for such a payment;
Votes shows an announcement as waiting, vetoed (and by whom), or ready
for its author to send; Approvals shows how long ago it was announced.

Message::Record's poll grew past clippy's large-variant limit, so its
rules are boxed; serialization is unchanged.

Tested on an NU7 devnet: with a one-hour wait adopted by poll, a large
payment is refused unannounced, too soon after its announcement, and
once Bob vetoes; then rules replacing those take effect.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A new rule, GroupRules.limit: members' apps may approve payments to
trusted payees by themselves while the wallet has sent less than an
amount in a period, the payment and its fee included. Each member turns
it on for their own app ("Approve automatically on this device",
PrivateSettings.auto_approve); the others approve as they choose.

rules::may_approve_automatically decides: every payment to a trusted
payee, none needing more approvals or a wait under the other rules, a
usual fee, and within what's left of the limit. The limit counts
everything the wallet sent in the period, however it was approved, so it
holds however many members turn this on: the wallet's history since the
height that long ago (by block spacing; a chain's block times needn't be
current, and a devnet's aren't), plus what this device approved
automatically in the last 70 minutes that may not be in it yet. Without
a sync in the last 15 minutes it approves nothing by itself.

The approval gate asks only after the transaction verified and every
other rule passed. An automatic approval is remembered by sighash, like
a manual one, so the transaction's later rounds go through and the limit
counts it once. The member is notified, and Approvals shows what it
approved and how much of the limit is used, or why it didn't.

Rules card: the toggle and the wallet's spending against the limit, and
the limit in Propose rules.

Tested on an NU7 devnet: with a limit adopted by poll and automatic
approval on, Bob's app approves a small payment to the trusted auditor
by itself, and leaves the next, over the limit, to Bob, saying why.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@USCMig
USCMig merged commit 69b9180 into main Oct 26, 2026
1 check passed
@USCMig
USCMig deleted the feat/spending-limits branch October 26, 2026 03:47
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