Skip to content

test: generate test key material at runtime instead of committing it - #1163

Merged
lklimek merged 18 commits into
v1.0-devfrom
test/runtime-generated-key-material
Nov 3, 2026
Merged

lklimek merged 18 commits into
v1.0-devfrom
test/runtime-generated-key-material

Conversation

@Claudius-Maginificent

@Claudius-Maginificent Claudius-Maginificent commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

TL;DR: Tests used to build wallets and keys from fixed byte patterns like [0x42; 64] or [0x2B; 32]. Those patterns are valid private keys, so the repository effectively held hundreds of committed keys. Tests now generate seeds, private keys, WIFs and mnemonics when they run, through one shared helper. Fixed bytes remain only in published compatibility vectors and in golden vectors that pin DET's own formats, and AGENTS.md now says so.

Detailed discussion

Follow-up to a review finding on #1151: a fixed pattern is still a valid key, even when it is only meant as a placeholder.

Helper: test_support::keys

Compiled only for unit tests and the testing/bench features. Release builds don't contain it: the release library's metadata has no labelled_secret symbol. Kittest, backend-e2e and the bench reach it as dash_evo_tool::test_support::keys.

  • seed(), secret_bytes(), secret_key(), private_key(net), wif(net) and mnemonic(words) return fresh random material on every call. secret_bytes() rejection-samples, so the result is always a valid secp256k1 scalar.
  • labelled_seed, labelled_secret and labelled_wif(domain, index) are for helpers whose contract is "the same index gives the same key", such as addr(n) and known_wif(). They hash a random per-process salt, so a label gives the same key within a run and a different key on every run. Each test thread prints the salt to stderr, so it appears in a failing test's captured output. To replay a run, set DET_TEST_KEY_SALT=<hex>.

Call sites

About 700 lines across model, wallet_backend, context, backend_task, ui/mcp/app/database, kittest, backend-e2e and benches.

  • When a test needs the same key twice (stage an identity, then check its stored bytes, or two wallets meant to collide), it generates the key once into a local variable and reuses it.
  • Fixed constants and byte-parameterised helpers (TEST_SEED, known_wif(), [seed_byte; 64], [key_byte; 32]) became labelled helpers.

Kept on purpose (compatibility and golden vectors)

Each site is commented "exempt from runtime key generation".

  • DIP-14 test vector 1 (model/dashpay_derivation/dip14.rs).
  • RFC 8032 §7.1 TEST 1 Ed25519 key (backend_task/grovestark.rs).
  • DIP-15 AES interop known-answer tests (backend_task/dashpay/contact_info.rs, contacts.rs), and the DIP-15 ECDH shared-key pin (ecdh_shared_key_matches_pinned_vector).
  • DET's at-rest seed envelope golden (model/wallet/encryption.rs, Argon2id + AES-GCM), which pins our on-disk format.
  • BLS signature parity golden (model/qualified_identity/mod.rs).
  • BIP-32 derivation pin: one test only, hd_derivation_matches_pinned_vector (wallet_backend/det_signer.rs). The parity tests use random seeds.
  • DIP-15 contact-derivation pins: only the two F3 pinned-value tests in wallet_backend/dashpay.rs use the fixed TEST_SEED/TEST_SECRET.
  • Negative tests that use invalid scalars ([0; 32], [0xff; 32]) or a phrase with a bad checksum (["abandon"; 12]).
  • The public BIP-39 "abandon … about" vector mentioned in the docs.
  • Migration fixtures and the sanctioned IMPORTED_PRIVATE_KEY, untouched.

Docs

  • AGENTS.md "Never commit secrets" now states the runtime-generation rule.
  • The secret-storage test spec describes runtime keys.
  • A historical QA note no longer quotes a committed WIF.
  • The password-input wireframe uses obvious placeholder WIFs.

Risk

Values that used to be fixed now differ on every run. Keys stay distinct and valid by construction, and equality contracts hold through locals or labels. No assertion compares against a value derived from a fixed seed, except the golden vectors above, which keep their fixed inputs.

Testing

  • cargo test --all-features --workspace passes:
    • lib: 3905;
    • kittest: 540;
    • migration-matrix: 64;
    • e2e: 10;
    • backend-e2e: 18, plus 81 network tests that are ignored.
  • After the review follow-ups, the touched modules pass again (264 tests).
  • cargo clippy --all-features --all-targets -- -D warnings is clean.
  • A feature-less release check passes, and cargo fmt is clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01WunYYhY7P2FJqHVgkHiXtT

🤖 Co-authored by Claudius the Magnificent AI Agent

PR Hygiene · d897bfe

  • Bots — coderabbitai skipped after its own rate limit · thepastaclaw ✓
  • Self-review — not asked of a bot author
  • Build green
  • Approvals
    • files with no dedicated owner (AGENTS.md, benches/wallet_hydration.rs, docs/ai-design/2026-03-09-password-input/wireframe.html and 101 more) — approved by lklimek

When every merge requirement is met, the PR Hygiene check passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.

lklimek and others added 13 commits October 28, 2026 16:59
Add test_support::keys (seed, secret_bytes, secret_key, private_key, wif,
mnemonic, plus process-stable labelled_* variants keyed by a per-process
salt; DET_TEST_KEY_SALT replays it). The module is compiled only for unit
tests and the testing/bench features. The shared leak-test secrets now come
from it, and AGENTS.md states that test key material is generated at
runtime.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Golden vectors that pin DET's own formats (at-rest seed envelope, BLS
signature bytes) keep their fixed inputs, now marked as exempt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The pinned DIP-15 contact vectors and the BIP-32 parity vector keep their
fixed inputs, now marked as exempt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… database tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
testnet_core_address, seed_hd_wallet, the top-up wallet fixture and both
auth_pubkey_cache pubkey helpers derive from labelled keys; the DIP-15
ECDH key-pair helper draws a random key. The ECDH pinned vector keeps its
fixed inputs, now marked as exempt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The HD signer parity tests use a random seed; only
hd_derivation_matches_pinned_vector keeps the fixed seed. In dashpay.rs,
TEST_SEED and TEST_SECRET remain only in the two F3 pinned-value tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…placeholders

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Split the runtime-key rule into two sentences and name test_support::keys,
labelled_* and DET_TEST_KEY_SALT. Document why the salt prints once per
thread: libtest shows only a failing test's captured output, so a single
process-wide print would miss the test that failed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Too many files!

This PR contains 104 files, which is 4 over the limit of 100.

To get a review, reduce the PR to 100 files or fewer by splitting it into smaller PRs or changing its base branch.

Upgrade to a paid plan to raise the limit.

This review couldn't start because sufficient usage credits or metered capacity aren't available. Add credits or update usage-based reviews in the billing tab, then retry.

Run configuration
Commits

Reviewing files that changed from the base of the PR and between 19747b8 and d897bfe.

Files selected for processing: 104
  • AGENTS.md
  • benches/wallet_hydration.rs
  • docs/ai-design/2026-03-09-password-input/wireframe.html
  • docs/ai-design/2026-06-19-secret-storage-seam/02-test-spec.md
  • docs/ai-design/2026-07-16-pr860-qa-delta/progress.md
  • src/app/shutdown.rs
  • src/backend_task/core/mod.rs
  • src/backend_task/dashpay/auto_accept_proof.rs
  • src/backend_task/dashpay/contact_info.rs
  • src/backend_task/dashpay/encryption.rs
  • src/backend_task/identity/add_key_to_identity.rs
  • src/backend_task/identity/discover_identities.rs
  • src/backend_task/identity/load_identity.rs
  • src/backend_task/identity/load_identity_by_dpns_name.rs
  • src/backend_task/identity/mod.rs
  • src/backend_task/identity/protect_identity_keys.rs
  • src/backend_task/identity/recover_legacy_keys.rs
  • src/backend_task/migration/finish_unwire.rs
  • src/backend_task/migration/legacy_restore.rs
  • src/backend_task/migration/single_key_restore.rs
  • src/backend_task/migration/v093_upgrade.rs
  • src/backend_task/mod.rs
  • src/backend_task/wallet/mod.rs
  • src/backend_task/wallet/rename_wallet.rs
  • src/context/identity_db.rs
  • src/context/wallet_balances.rs
  • src/context/wallet_lifecycle/bootstrap.rs
  • src/context/wallet_lifecycle/tests.rs
  • src/context/wallet_lifecycle/tests/deletion_sentinel.rs
  • src/database/wallet.rs
  • src/lib.rs
  • src/mcp/resolve.rs
  • src/mcp/tests.rs
  • src/mcp/tools/masternode.rs
  • src/mcp/tools/network.rs
  • src/model/address.rs
  • src/model/dashpay_derivation/dip14.rs
  • src/model/dashpay_derivation/hd.rs
  • src/model/derived_identity_key.rs
  • src/model/fee_estimation.rs
  • src/model/key_input.rs
  • src/model/legacy_recovery.rs
  • src/model/qualified_identity/encrypted_key_storage.rs
  • src/model/qualified_identity/mod.rs
  • src/model/qualified_identity/qualified_identity_public_key.rs
  • src/model/wallet/auth_pubkey_cache.rs
  • src/model/wallet/encryption.rs
  • src/model/wallet/mod.rs
  • src/model/wallet/seed_envelope.rs
  • src/model/wallet/single_key.rs
  • src/test_support.rs
  • src/test_support/keys.rs
  • src/ui/components/address_input.rs
  • src/ui/components/wallet_unlock_popup.rs
  • src/ui/identity/add_existing_identity_screen.rs
  • src/ui/identity/add_new_identity_screen/mod.rs
  • src/ui/identity/funding_common.rs
  • src/ui/identity/hub_screen.rs
  • src/ui/identity/keys/add_key_screen.rs
  • src/ui/identity/keys/key_info_screen.rs
  • src/ui/identity/mod.rs
  • src/ui/identity/top_up_identity_screen/mod.rs
  • src/ui/identity/usernames_card.rs
  • src/ui/masternodes/detail_screen.rs
  • src/ui/state/account_summary.rs
  • src/ui/wallets/import_mnemonic_screen.rs
  • src/ui/wallets/import_single_key.rs
  • src/ui/wallets/send_screen.rs
  • src/ui/wallets/single_key_send_screen.rs
  • src/ui/wallets/wallets_screen/address_table.rs
  • src/ui/wallets/wallets_screen/mod.rs
  • src/wallet_backend/auth_pubkey_cache.rs
  • src/wallet_backend/dashpay.rs
  • src/wallet_backend/det_platform_signer.rs
  • src/wallet_backend/det_signer.rs
  • src/wallet_backend/hydration.rs
  • src/wallet_backend/identity_key_store.rs
  • src/wallet_backend/leak_test_support.rs
  • src/wallet_backend/mod.rs
  • src/wallet_backend/payments.rs
  • src/wallet_backend/secret_access.rs
  • src/wallet_backend/secret_seam.rs
  • src/wallet_backend/shielded.rs
  • src/wallet_backend/single_key.rs
  • src/wallet_backend/single_key_entry.rs
  • src/wallet_backend/snapshot.rs
  • src/wallet_backend/wallet_context.rs
  • src/wallet_backend/wallet_seed_store.rs
  • tests/backend-e2e/core_tasks.rs
  • tests/backend-e2e/dashpay_tasks.rs
  • tests/backend-e2e/identity_masternode_withdraw.rs
  • tests/kittest/add_new_wallet_screen.rs
  • tests/kittest/address_input.rs
  • tests/kittest/import_mnemonic_screen.rs
  • tests/kittest/import_single_key.rs
  • tests/kittest/key_info_screen.rs
  • tests/kittest/keys_screen.rs
  • tests/kittest/masternode_tab.rs
  • tests/kittest/migration_gate.rs
  • tests/kittest/progress_overlay.rs
  • tests/kittest/request_routing.rs
  • tests/kittest/secret_prompt.rs
  • tests/kittest/top_up_identity_screen.rs
  • tests/kittest/wallets_screen.rs

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@thepastaclaw

thepastaclaw commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Final review complete — no blockers (commit d897bfe) · triage: critical · Phase 2 only (no Phase 1 for this repository)

lklimek and others added 5 commits October 30, 2026 11:34
The seeds in these tests became random, but the checks still looked for
fixed byte sequences, so a leak could no longer fail them. Build the
forbidden text from the seed under test instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WunYYhY7P2FJqHVgkHiXtT
Move the remaining fixed seeds and secrets in the secret access, legacy key
recovery, wallet rename and new identity tests to test_support::keys.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WunYYhY7P2FJqHVgkHiXtT
The test uses the vector's seed bytes and never read the phrase quoted in
its comment. Refer to the vector by name instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WunYYhY7P2FJqHVgkHiXtT
Move the fixed seeds and secrets in the wallets, send, top-up, MCP resolve
and legacy migration tests to test_support::keys.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WunYYhY7P2FJqHVgkHiXtT
These checks still looked for fixed byte sequences. Three of them could no
longer fail, because their secrets became random. Build the forbidden text
from the secret under test in all four.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WunYYhY7P2FJqHVgkHiXtT
@Claudius-Maginificent
Claudius-Maginificent marked this pull request as ready for review October 30, 2026 14:04
@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — coderabbitai skipped after its own rate limit · thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added waiting-bots Waiting for the review bots to report on this head bot-review-skipped A required review bot did not report; it was skipped by the window or by a person. labels Oct 30, 2026

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Final validation — Phase 2 only (no Phase 1 for this repository)

The runtime key-generation helper is well-factored, and the CI snapshot shows successful Test Suite and Clippy checks for the reviewed head. Three in-scope test-maintenance gaps remain: redaction checks only cover the first eight bytes, and two valid fixed private-key fixtures are still committed. These are non-production suggestions, so the appropriate action is COMMENT.

🟡 3 suggestion(s)

2 finding(s) not shown inline (the lines are not part of this PR's diff)

🟡 Suggestion: Remove the remaining fixed private-key bytes from the identity test
src/backend_task/identity/load_identity.rs:1561

PrivateKeyData::Clear([id as u8; 32]) still embeds the valid secp256k1 scalars [8; 32] and [9; 32] in repository test code. These are private-key values rather than identifiers, so they remain committed key material contrary to this PR's runtime-generation objective. Use a labelled runtime secret so each key remains distinct and replayable.

PrivateKeyData::Clear(crate::test_support::keys::labelled_secret(
    "backend_task::identity::load_identity::protected_merge_retains_keys_after_failed_write_and_removal_cleans_them",
    id as u64,
)),

source: gpt-6.1-sol (phase2-reviewer: rust-quality)

🟡 Suggestion: Replace the fixed masternode test private keys
src/context/wallet_lifecycle/tests.rs:2541

PrivateKeyData::Clear([0x70 + key_id as u8; 32]) stores three valid secp256k1 private scalars in test source. Although this fixture exercises a failure path, the values remain committed key material and violate the runtime-generation rule established by the PR. A labelled runtime secret preserves per-key distinction and makes failures replayable.

PrivateKeyData::Clear(crate::test_support::keys::labelled_secret(
    "context::wallet_lifecycle::tests::clear_network_database_reports_incomplete_when_masternode_key_delete_fails",
    key_id as u64,
)),

source: gpt-6.1-sol (phase2-reviewer: rust-quality)

Review provenance

Source: reviewer 1: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.1-sol (effort low) — This is a large cross-cutting diff that changes cryptographic key and secret generation across wallet, identity, signing, encryption, and key-storage tests, including files such as src/test_support/keys.rs and src/wallet_backend/secret_seam.rs.
  • Phase 1 reviewers: not run (disabled for this repository)
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort xhigh); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `src/test_support/keys.rs`:
- [SUGGESTION] src/test_support/keys.rs:106-111: Check complete secret representations in redaction tests
  `rendered_forms` only returns the hex and decimal representations of the first eight bytes. The redaction tests using this helper can therefore pass if a `Debug` implementation leaks only a suffix or another portion after those bytes. This weakens the previous full-hex assertion in the wallet redaction test; the complete runtime-generated secret can be checked without committing key material.

In `src/backend_task/identity/load_identity.rs`:
- [SUGGESTION] src/backend_task/identity/load_identity.rs:1561: Remove the remaining fixed private-key bytes from the identity test
  `PrivateKeyData::Clear([id as u8; 32])` still embeds the valid secp256k1 scalars `[8; 32]` and `[9; 32]` in repository test code. These are private-key values rather than identifiers, so they remain committed key material contrary to this PR's runtime-generation objective. Use a labelled runtime secret so each key remains distinct and replayable.

In `src/context/wallet_lifecycle/tests.rs`:
- [SUGGESTION] src/context/wallet_lifecycle/tests.rs:2541: Replace the fixed masternode test private keys
  `PrivateKeyData::Clear([0x70 + key_id as u8; 32])` stores three valid secp256k1 private scalars in test source. Although this fixture exercises a failure path, the values remain committed key material and violate the runtime-generation rule established by the PR. A labelled runtime secret preserves per-key distinction and makes failures replayable.

Comment thread src/test_support/keys.rs Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Ready for review — files with no dedicated owner: lklimek.
Full checklist in the description.

@github-actions github-actions Bot added ready-for-human Bots have reported, the author has self-reviewed, and the build is green: this needs a human. and removed waiting-bots Waiting for the review bots to report on this head labels Oct 30, 2026
@github-actions
github-actions Bot requested a review from lklimek October 30, 2026 16:18
@lklimek
lklimek enabled auto-merge (squash) November 3, 2026 14:56
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Policy satisfied — this can merge.
Full checklist in the description.

@github-actions github-actions Bot removed the ready-for-human Bots have reported, the author has self-reviewed, and the build is green: this needs a human. label Nov 3, 2026
@lklimek
lklimek merged commit 55ccec3 into v1.0-dev Nov 3, 2026
20 checks passed
@lklimek
lklimek deleted the test/runtime-generated-key-material branch November 3, 2026 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot-review-skipped A required review bot did not report; it was skipped by the window or by a person.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants