← Back to Pull requests

feat(stealth-keygen): add HKDF and account-scoped confidential keys #1

Closed
unknown closed this pull request without merging on Sep 30, 2026 12:30 UTC
View on GitHub
unknown unknown commented on Sep 28, 2026 17:29 UTC
Author

What this PR brings in

This PR brings in the latest cryptographic features from stealth-keygen:

  • HKDF-SHA256 key derivation: Replaces the previous direct SHA-256 construction with separate derivation labels for discovery tags and spending tweaks.

  • ElGamal keypair derivation: Allows the payer and recipient to independently derive matching Solana-compatible encryption keys from their shared secret.

  • Symmetric balance-key derivation: Adds derive_balance_key(&context) to both payment types, returning the SDK’s AeKey for encrypting and decrypting the available-balance copy.

  • Account-specific encryption keys: Binds both encryption-key derivations to the chain, application program, mint, and token account through ElGamalContext.

  • Tests and documentation: Adds independent derivation vectors and coverage for key agreement, context separation, encryption round trips, and tamper rejection. The standalone library’s 37 tests pass.
  • Only the recipient can reconstruct the payment signing key. Both parties can derive the initial account’s encryption keys. This PR adds the off-chain cryptographic functionality; it does not implement confidential-account setup or transaction submission.

    Differences from Scope’s original design

    The implementation differs from the target described in Scope’s docs/crypto.md:

    | Area | Scope’s documented target | Current implementation |
    |---|---|---|
    | Key derivation | HKDF-SHA512 | HKDF-SHA256 |
    | Protocol salt | stealth-conf/v1 | stealth-keygen-v2 |
    | Discovery and spending inputs | Purpose labels combined with ephemeral public key E and payment index k | Separate discovery-tag and spend-tweak labels over the shared-secret-derived root, without explicit E or k fields |
    | Confidential-key derivation | Derive ct_ikm, then pass it to the SDK to obtain ElGamal and authenticated-encryption keys | Derive ElGamal scalar material and symmetric-key bytes directly through separate HKDF branches |
    | Encryption context | E and k in the confidential-key-material derivation | Chain ID, application program ID, mint, and token-account address |
    | Crate boundary | stealth-keygen exports secret bytes and has no Solana dependencies; scope-client constructs SDK keys | stealth-keygen directly returns SDK ElGamalKeypair and AeKey types |
    | SDK version | Workspace-managed solana-zk-sdk 7.0.1 | Standalone library pins solana-zk-sdk 6.0.1 |
    | Disclosure interface | Receipts carry ct_ikm, from which the verifier derives both encryption keys | No ct_ikm export or Scope receipt integration yet |

    These differences require an explicit decision before merging. The current implementation does not produce the same derived keys as Scope’s documented schedule and cannot directly satisfy its planned ct_ikm receipt interface.

    This PR does not complete Q14. Recipient-only destination derivation, the remaining Scope API changes, and external cryptographic review remain separate work. Standalone test results also do not replace Scope’s workspace and CI checks.

    Diff: 388 lines (+291 / -97) across 4 files Reviewer: valentynkit Review duration: 2580m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 388 lines diff across 4 files
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.357
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #1"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 43.1% (MEDIUM) · Higher = larger blast radius
    43.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17% · Safe to merge
    17%