Background ECDH precomputation (#497)#489
Closed
elliottdehn wants to merge 1 commit into
Closed
Conversation
Add EcdhPrecomputeCache: a background thread precomputes ECDH shared secrets with all known participant public keys. When encryptFor is called, it checks the cache — if the ECDH is already computed, only KDF + AES remains on the critical path (~0.03ms instead of ~0.4ms per recipient). Each precomputed entry is consumed exactly once (forward secrecy) and automatically refilled in the background. The output format is unchanged — existing decrypt code works without modification. For the Global Synchronizer with 20 SVs, after the cache warms up (~50ms), every CC transfer's encryption drops from ~8ms to ~0.6ms per view. The ECDH work still happens, but off the transaction's critical path. Implementation: - EcdhPrecomputeCache.scala: background precompute + consume cache with auto-refill. Uses BouncyCastle's ECDHBasicAgreement directly. - JcePureCrypto.scala: encryptWithPrecomputedEcdh using IESEngine with precomputed shared secret. ecdhPrecomputeCache field with periodic refill thread. - SyncCryptoApiParticipantProvider.scala: encryptFor checks precompute cache before falling back to full ECIES. Registers recipient keys for background precomputation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
Author
|
I have hereby read the Digital Asset CLA and agree to its terms |
This was referenced Apr 16, 2026
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Closes #497
Summary
Precompute ECDH shared secrets with known participants in a background thread. When a transaction needs to encrypt views, the expensive ECDH key agreement (~0.36ms per recipient, 77% of ECIES cost) is already done — only KDF + AES remains on the critical path (~0.03ms).
Impact
Encrypt-side latency (submitter, warm cache):
Total CPU unchanged — the ECDH work still happens, just in a background thread between transactions instead of on the critical path. Cache warmup takes ~50ms (one background refill cycle).
Each precomputed entry is consumed exactly once (forward secrecy) and automatically refilled in the background.
Relation to other PRs
Test plan
SimplestPingIntegrationTestpasses🤖 Generated with Claude Code