Skip to content

Add BatchDomain::batch_ka_agree_dec, a per-viewing-key batched agreement hook - #13

Merged
nuttycom merged 1 commit into
zcash:mainfrom
LukasKorba:batch-ka-agree-dec
Jul 11, 2026
Merged

Add BatchDomain::batch_ka_agree_dec, a per-viewing-key batched agreement hook#13
nuttycom merged 1 commit into
zcash:mainfrom
LukasKorba:batch-ka-agree-dec

Conversation

@LukasKorba

Copy link
Copy Markdown
Contributor

Trial decryption computes ka_agree_dec for many ephemeral keys against the same incoming viewing key, and those scalar multiplications dominate the cost of batched trial decryption. The per-item Domain::ka_agree_dec interface gives implementations no opportunity to exploit the shared scalar — the batch module even notes "The scalar multiplications cannot benefit from batching", which is true for the current interface but not for the underlying math: same-scalar multiplications can share work (e.g. lockstep affine ladders amortizing one field inversion per ladder step across the whole batch, on curves like Pallas).

This PR adds BatchDomain::batch_ka_agree_dec: a provided method computing the agreements for a whole batch of prepared ephemeral keys against one viewing key. The default implementation is exactly the per-item computation, so existing BatchDomain implementations are unaffected. The batch module's shared-secret derivation now routes through it — one call per viewing key — reassembling results in the output-major order the downstream batch KDF expects.

Context: this interface comes from a production wallet sync engine, where an Orchard implementation of the hook (a batched same-scalar kernel) measured a +15% wall-clock improvement on full-history restores on some hardware; we're preparing the corresponding orchard PR that implements the override. The pair has been running in production behind a runtime toggle with the output KAT-gated byte-identical to the per-item path.

One question for the maintainers: orchard (both main and the released 0.15) and sapling-crypto currently target zcash_note_encryption 0.4, while this repo's main is the unreleased breaking 0.5 line. The method is additive and applies cleanly to the 0.4 code as well — if you'd take a 0.4.2 patch release, I'm happy to open the corresponding backport PR so implementations on the 0.4 line can adopt it without waiting for the 0.5 migration.

…ent hook

Trial decryption computes ka_agree_dec for many ephemeral keys against
the same incoming viewing key. For domains where same-scalar
multiplications can share work (for example, lockstep ladders over a
shared batched field inversion), this dominates the cost of batched
trial decryption, but the per-item Domain::ka_agree_dec interface gives
implementations no opportunity to exploit it.

This adds a provided BatchDomain method that computes the agreements
for a whole batch against one viewing key, defaulting to the per-item
computation, and routes the batch module's shared-secret derivation
through it (one call per viewing key, preserving the output-major
order the downstream batch KDF expects). Existing BatchDomain
implementations are unaffected.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@nuttycom

Copy link
Copy Markdown
Contributor

@LukasKorba yes, please prepare those backport PRs for orchard and sapling-crypto.

@nuttycom nuttycom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

@nuttycom
nuttycom merged commit 1e6b52e into zcash:main Jul 11, 2026
11 checks passed
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.

2 participants