← Back to Pull requests

build(crypto): add benchmarks and the HPK1 baseline (P73, part 1) #226

Closed
unknown closed this pull request without merging on Nov 16, 2026 23:46 UTC
View on GitHub
unknown unknown commented on Nov 13, 2026 05:28 UTC
Author

What and why

Part of #185 (P73). #187 can't merge until the HPK1 (X25519) cost is recorded (ADR 0001, ADR 0007 "Consequences"). This adds a criterion harness in platform-crypto that times HPK1 key generation and envelope seal and open at 32 B, 4 KiB and 4 MiB, a unit test that pins the 52-byte envelope overhead, and a bench workflow that runs on pull requests touching backend/ or rust-toolchain.toml and only reports; pull requests restore the build cache that pushes to main save, and save none of their own. cargo test runs each benchmark once, so scripts/check.sh fails on a broken one. docs/BENCHMARKS.md has the method, how #187 compares against it, and the baseline from this PR's CI run.

The benchmarks refuse to run on any suite but HPK1, so the hpk1 IDs stay the baseline after #187 changes the default suite.

@AxolDad: #185 says the targets and the regression threshold are agreed with you. docs/BENCHMARKS.md proposes no absolute targets until the hybrid numbers exist, and a base-vs-head check in one job that flags a significant change over 10 %. Shared runners vary more than that between runs, so it never compares against recorded numbers.

Still to come in later PRs, so #185 stays open: engine query latency, the encryptPayload Vitest bench, #171's bundle and load figures, and the regression check.

How it was tested

  • hpk1_envelope_overhead_is_52_bytes fails at 51 and passes at 52.

  • cargo bench -p platform-crypto --bench hpke --locked -- --test runs all seven. With a wrong info on open it now panics (open: OpenFailed); before, it reported success.

  • --save-baseline / --baseline-lenient / --baseline behave as the doc says (strict fails on a missing baseline).

  • cargo test --workspace doesn't run the benches; cargo deny check passes; all new crates are MIT or Apache-2.0.
  • Checklist

  • scripts/check.sh passes locally

  • Every new refusal has a negative test: n/a, no new refusals

  • Every new security decision emits a SECURITY_AUDIT_EVENT covered by audit_coverage.rs: n/a

  • Fails closed on missing configuration, key material, or attestation: n/a, dev-only benchmarks

  • No new cryptographic primitives; suites stay behind their type aliases

  • Synthetic or public data only (docs/DATA_POLICY.md)

  • Docs and CHANGELOG.md updated for user-visible changes

  • Architectural decision recorded in docs/adr/ if one was made: n/a
  • Diff: 307 lines (+230 / -77) across 3 files Reviewer: abendrothj Review duration: 5417m
    All Vouch review confidence checks passed
    Residual risk 0.27 = Change Risk (0.63) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.63 · 307 lines diff across 3 files
    0.63
    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%
    56%
    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.343
    Shallow Review Depth shallow_review_depth
    0.289
    Sensitive Paths sensitive_paths
    0.063
    Real PR Conversation Timeline
    1 comments
    "Review active on #226"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed sensitive_module
    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: 63.4% (MEDIUM) · Higher = larger blast radius
    63.4%
    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: 56.8% · Lower = rushed or shallow review
    56.8%
    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: 27.4% · Safe to merge
    27.4%