Repository navigation
fix(security)!: sign with the self-erasing EcdsaSecretKey - #1127
Conversation
Pin dash-sdk, rs-sdk-trusted-context-provider, platform-wallet and platform-wallet-storage to dashpay/platform v5.1-dev 063589bf (5.0.0-rc.8). The lockfile moves only the Platform packages. The upstream V019 wallet-storage migration adds a nullable asset-lock operation id; V001-V018 are unchanged. The compatibility bridge gets the 033ecae destination snapshot it compares against, and the pin guard records the new revision with an unchanged migration fingerprint. BREAKING CHANGE: the wallet storage upgrade to V019 is forward only. An older build cannot open upgraded storage; going back needs a copy of the data directory taken before the upgrade. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
The new rust-dashcore wraps secp256k1 keys in EcdsaSecretKey and EcdsaPublicKey, returns secret bytes as Zeroizing, and drops the Secp256k1 context argument. Signers, single-key wallets, DashPay derivation, address and QR handling, migrations and their tests follow the new types. Signing stays on the non-grinding dpp::secp256k1 path, and a parity test pins the BLS signature bytes the previous SDK made. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
Handle the dpp and SDK types the new pin adds, keeping today's behaviour: - Document replace keeps moderated_at and moderated_by; new documents start without them. - The document editor refuses typed-array fields instead of dropping their contents, and keeps referenced key ids as numbers. - Shielded token events show read-only in group actions, and the shielded pool token settings are refused before anything is signed. - Contested document creation states the protocol's base contest fund, so the SDK never auto-quotes a larger one. - Masternode vote reads use ResourceVoteWithCount, the SDK's new vote type; the vote count is not used yet. - New query fields, wallet events, wallet error variants and asset-lock funding modes are handled where the SDK now requires them. - Entropy-only document ids are documented as placeholders from protocol 14, and deferred upstream features link to their issues. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
The SDK was pinned to the protocol 13 table, so it could not build any protocol 14 transition or follow the versioned identity lookup. It now starts at upstream's per-network minimum and ratchets to what proven responses report. - System contracts are cached per protocol version and served through accessors. The context provider serves them at the version the proof verifier asks for and fails rather than serve another version's. - A proved epoch sets the fee multiplier and raises the protocol version. An older epoch than the adopted one is ignored. - Rebuilding the connection resets the protocol version, fee multiplier and adopted epoch under one lock before the new SDK is published, and drops reads begun on the old connection. - Capabilities read the network's version through a helper that stays closed for a version this build does not define. - Contest timing reads the live version; retired vote schedules keep the protocol 13 notice window they were created under. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
Compare the protocol 13 client tables with a recorded snapshot, so an upstream change to them is reviewed, and check that keys and documents DET builds on a protocol 13 network use encodings protocol 13 decodes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
Map the refusals the new protocol adds to flows DET already offers to dedicated TaskError variants: a full username contest, a vote choice the contest does not allow, a name someone else asked for first, a token that cannot be moved, a changed immutable document field, a reference to a document type that cannot be deleted, and a moderators' fee on a contract without moderation. Names supplied by the node stay in the typed source only, never in the message. Token operations that fail inside the wallet runtime keep their SDK cause, so they are classified like any SDK error; an unclassified one names the operation that did not complete. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
Add a dated design note for the pin, the protocol version sources, the connection state rules and the protocol 13 guards, and point AGENTS.md at From<SdkError> for TaskError as the SDK error reference. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
…it refusals Protocol version 14 refusals that flows already in DET can hit get dedicated, actionable messages, each keeping the SDK error as its source: - an identity banned or suspended (until when) on a moderated contract; - a gas sponsor short of credits, a gas payer the document type does not offer, and mixed gas payers in one batch; - pre-programmed token distributions of one time over the limit. An overflowing shielded note total is logged at warn: it means corrupt or hostile sync data, not routine noise. Tests cover contracts saved at protocol 12 loading unchanged at 13 and 14, and contracts saved at 14 decoding at 13 and in full again at 14. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
A lookup at another version, as the proof verifier makes at a response's version, swapped out the app's set, so each such lookup reloaded the system contracts and the next app read reloaded them again. Each version now keeps its own set; the app's reads keep the set they last got for a failed reload. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
…poch When the epoch cannot be read, the proved DPNS fallback confirmed the SDK's version, which starts at the network's upstream minimum (14 on devnet), as the network's. It now confirms the version of the responses the SDK verified, and nothing before any. Restores the completed-withdrawal status list with the reason sending FAILED to a protocol 13 network is safe, and its test, now comparing the protocol 13 schema with the latest one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
The derived key DET signs with is copied into secp256k1's own type, which keeps its bytes after use. Wrap it so it is erased on drop, as the derived key it comes from would be; signatures stay byte-identical. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
… protocol 13 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
The new refusals sent users to another document editor or token client. They now say the app cannot edit this field type, sign this action or change this token setting yet, in one wording, and the shielded setting refusal sits with the token contract errors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
Also corrects the platform compatibility fixtures README: no code reads e3cd7cf.sql any more; it is the V001-V018 checksum reference. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
The protocol version fallback takes only a version the SDK verified, and a mock expectation's metadata is never recorded as verified, so the three headless refresh tests saw the version stay unconfirmed. The mock now has the SDK accept the version from metadata treated as proved, as after a live network's signed response, and a new test pins that a response the SDK never verified leaves the version unconfirmed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
The SDK picks each transition's encoding from the platform version DET passes in, so these tests checked dpp's version tables rather than DET. The mainnet start version and the contest fund cap stay covered by the platform_info and fee_estimation tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
The SDK at this pin already tracks the version the network has proven: it records the version of every response whose proof and quorum signature it verified, and a rebuilt connection is a new SDK that starts from nothing. DET's own copy, raised from proved epochs and DPNS reads and reset on every rebuild, duplicated that state. The app now reads the current SDK's verified version; capabilities still stay closed before a version is proven and for one this build does not define, and network info shows the proven number or says none is confirmed. Proved epochs still set the fee multiplier, in epoch order and only on the current connection. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
A connection rebuild never changes the chain, the multiplier changes once per epoch and feeds only fee estimates, so ordering epoch reads and dropping those begun before a rebuild guarded against nothing worth the machinery. A proved epoch read sets the multiplier directly again; an unavailable epoch still keeps the last known value and labels it as such. A rebuild still reads the epoch, so the new SDK proves the network's version again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
A released protocol's tables and each network's minimum version are upstream's to keep fixed; DET's start is covered by platform_version_starts_at_the_network_minimum. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
The proof verifier asks for contracts at the version it verifies with, which can be newer than the SDK's. System contracts were already served at that version; a saved user contract was decoded at the SDK's version instead, dropping newer-protocol settings such as action fees. The fallback now decodes it at the version asked for. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
…king Building the recoverable-signature envelope returns an error upstream; it is now reported as the existing message-signing failure, with the detail logged, instead of aborting the signing path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
secp256k1 0.33's `SecretKey` is `Copy` with no `Drop`, so each plain copy DET built from its self-zeroizing key material outlived the operation in freed memory. Move `DetSigner`'s `ErasedSecretKey` into `model::erased_secret_key` and use it wherever DET turns key bytes into a `secp256k1::SecretKey`: wallet- and identity-key message signing, local key signing on the key info screen, the HASH160 key check, auto-accept proof signing, DashPay ECDH, and the DIP-14 tweak validation. `with_identity_secret_key` lends the key to its closure as `&SecretKey` so the closure can no longer take an un-erased copy. Signatures and ECDH output are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 57 minutes. View limit details
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. Comment |
|
✅ Final review complete — no blockers (commit 116b1b1) · triage: critical · Phase 2 only (no Phase 1 for this repository) |
…y-copies The squash commit's tree equals #1114's final head, which this branch already contains, so the tree is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
Replace DET's local `ErasedSecretKey` with the upstream `EcdsaSecretKey` (dash-pkc via dashcore), which erases its scalar on drop, at every site that signs, derives a public key, or range-checks a scalar. HD signing in `DetSigner` and wallet-key message signing now sign with the derived key itself, so no copy is made at all. DIP-15 ECDH is the one site `EcdsaSecretKey` cannot serve, so it keeps a private `EcdhSecretKey` wrapper in the encryption module. The shared `model::erased_secret_key` module and the now-unused `DerivationError::Secp256k1` variant are removed. `EcdsaSecretKey::sign` grinds a low R as Dash Core does, so non-recoverable signatures (Core transactions, single-key signing, auto-accept proofs) change bytes for about half of all digests. They stay valid, low-S and deterministic. Recoverable message signatures and ECDH output are byte-identical. The DetSigner parity reference now signs with `sign_low_r`, and new tests check that signatures verify and are in standard low-S, low-R form. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
|
Waiting for bot review — coderabbitai not yet · thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
…4's I_L in Zeroizing Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
…into fix/erase-secp256k1-key-copies Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
|
Waiting for bot review — coderabbitai not yet · thepastaclaw requested changes — dismiss the review or push a fix, 1 thread unresolved — resolve it. Wait for the missing reviews, or a writer can post |
thepastaclaw
left a comment
There was a problem hiding this comment.
Final validation — Phase 2 only (no Phase 1 for this repository)
The PR's ECDH wrapper still leaves one non-erasing secp256k1::SecretKey copy behind during construction. Because the wrapper is intended to close the exact residual-key gap addressed by this change, the constructor must explicitly erase the source copy after initializing the wrapper. The Test Suite check was still in progress in the supplied CI snapshot.
🔴 1 blocking
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); reviewer 3: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 4: gpt-6-astra (agent: phase2-reviewer, role: rust-quality); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.1-sol(effort low) — The diff is intricate and directly changes cryptographic signing, ECDH key handling, and private-key material lifetime in src/wallet_backend/det_signer.rs and src/backend_task/dashpay/encryption.rs. - Phase 1 reviewers: not run (disabled for this repository)
- Fresh verifier:
gpt-6.1-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.1-sol— general (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— rust-quality (completed, effort xhigh); agentphase2-reviewer,gpt-6-astra— general (completed, effort xhigh); agentphase2-reviewer,gpt-6-astra— rust-quality (completed, effort xhigh); agentphase2-reviewer - Model comparison: every Phase-2 reviewer also ran on
gpt-6-astra; the verifier weighed both sets without knowing which model wrote which
🤖 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/backend_task/dashpay/encryption.rs`:
- [BLOCKING] src/backend_task/dashpay/encryption.rs:27: ECDH constructor leaves the source SecretKey copy unerased
`secp256k1::SecretKey` is `Copy` and has no `Drop`, so `map(Self)` copies the scalar into `EcdhSecretKey` while the source value passed through the `Result` remains an ordinary non-erasing copy. `EcdhSecretKey::Drop` only erases its tuple field; the source copy is discarded without calling `non_secure_erase`, leaving residual key material in memory. This contradicts the PR's defense-in-depth goal of erasing the raw ECDH key. Construct the wrapper explicitly, then erase the source `SecretKey` copy before returning it.
secp256k1::SecretKey is Copy, so wrapping it left the source copy unerased. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
|
Waiting for bot review — coderabbitai not yet · thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
|
Waiting for bot review — coderabbitai not yet · thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 2 only (no Phase 1 for this repository)
The current head consistently routes production signing and key-construction paths through self-erasing EcdsaSecretKey values, while the ECDH exception explicitly erases both the wrapped key and the constructor-local SecretKey copy. The reviewed changes preserve recoverable message-signature bytes, produce valid low-R signatures where intended, and the supplied Test Suite and Clippy checks passed for this exact head.
🔴 0 blocking | 🟡 0 suggestion(s) | 💬 0 nitpick(s)
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); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.1-sol(effort low) — This is an intricate cryptographic and key-handling change affecting ECDSA signing, recoverable signatures, ECDH, identity keys, and transaction-signing behavior in files including src/wallet_backend/det_signer.rs and src/backend_task/dashpay/encryption.rs. - Phase 1 reviewers: not run (disabled for this repository)
- Fresh final gate: an independent Phase-2 review ran after iterative findings were reconciled
- Fresh verifier:
gpt-6.1-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.1-sol— general (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— rust-quality (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— general (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— rust-quality (completed, effort xhigh); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify the current code and confirm that no unresolved issues remain.
No unresolved findings remain from the prior review on this head.
|
Policy satisfied — this can merge. |
TL;DR
Every place DET built a plain
secp256k1::SecretKeyfrom its self-zeroizing key material now uses the upstream self-erasingEcdsaSecretKey(dash-pkc, re-exported asdashcore::ecdsa::EcdsaSecretKey). DIP-15 ECDH is the one exception:EcdsaSecretKeyhas no ECDH API, so that site uses a small private wrapper that erases the key on drop. This is defense in depth. Message signatures and ECDH output keep their exact bytes. Non-recoverable signatures (Core transactions, single-key signing, auto-accept proofs) are now low-R. They are still valid and deterministic, but their bytes differ from earlier builds (see below).User story / Scenario
Not applicable. This is internal hardening with no user-visible change.
Detailed discussion
Stacked atop #1114 (Platform pin bump). That PR moves DET to the new rust-dashcore crypto stack with secp256k1 0.33. In that version
SecretKeyisCopyand has noDrop. DET's key sources (EcdsaSecretKey,Zeroizing<[u8; 32]>, the JIT vault plaintext) wipe themselves. Thesecp256k1::SecretKeycopies built from them did not, so those copies stayed in freed stack memory after each operation.EcdsaSecretKeyerases its scalar on drop. It covers signing (sign,sign_recoverable),public_keyandadd_tweak, so most sites switch to it directly:wallet_backend/det_signer.rsExtendedPrivKey's ownEcdsaSecretKey, with no copy at all. Single-key signing parses the held bytes into anEcdsaSecretKey.DetSignerError::Signnow carriesEcdsaErrorbackend_task/wallet/mod.rs(dash_signed_message)&EcdsaSecretKeyand usessign_recoverable. The envelope is rebuilt with the caller's compression flagbackend_task/wallet/mod.rs(with_identity_secret_key)&EcdsaSecretKeyto its closurebackend_task/wallet/sign_message_with_key.rsPrivateKey's own key, with no copybackend_task/wallet/derive_identity_key_for_display.rsui/identity/keys/key_info_screen.rsmodel/qualified_identity/mod.rsbackend_task/dashpay/auto_accept_proof.rsmodel/dashpay_derivation/dip14.rsI_Ltweak. TheDerivationError::Secp256k1variant was used only here, so it is removedbackend_task/dashpay/encryption.rsEcdhSecretKeywrapper, because dash-pkc has no ECDH. It implementsZeroize(secp256k1's volatilenon_secure_erase) andZeroizeOnDrop, and is deliberately notClone/CopyAll other
SecretKey::from_secret_bytescalls are in#[cfg(test)]code.Signature bytes: low R
EcdsaSecretKey::signgrinds the nonce until R is low, as Dash Core and Bitcoin Core do, so DER signatures are at most 70 bytes. Plain RFC 6979secp256k1::ecdsa::signgives a high R about half the time. As a result, these signatures now differ from earlier builds for roughly half of all digests:DetSigner::sign_ecdsa. Low-R, low-S signatures are standard and relayed by Dash Core.DetSigner::sign_single_key_ecdsa). This path has no production caller yet.Signatures stay deterministic for a given key and digest. Recoverable signatures are not ground, so signed-message envelopes stay byte-identical.
The erase is best effort: the compiler may already have moved the bytes elsewhere before the erase runs.
DIP-14's HMAC output, which holds
I_L, is kept inZeroizing.Testing
det_signer::hd_signer_parity_with_reference: the independent reference now signs withsecp256k1::ecdsa::sign_low_rinstead ofecdsa::sign, because the signer grinds a low R. The comment in the test says why. The pinned public-key vector is unchanged.det_signer::hd_signer_signatures_are_valid_and_standard: signs 32 digests and checks that each signature verifies against the reported public key, is low-S, has a low R, and has a DER encoding of at most 70 bytes. Before the switch it failed on the second digest (high R).det_signer::single_key_signer_signs_raw_and_rejects_pathnow also checks that the single-key signature is valid and standard.auto_accept_proof::proof_signature_verifies_and_has_low_r: checks the proof layout, and checks that the signature verifies the wayverify_auto_accept_proofchecks it and is low-S and low-R, for 32 account references.encryption::ecdh_secret_key_zeroize_overwrites_the_keyandecdh_secret_key_rejects_invalid_scalarcover the ECDH wrapper. The first runs thezeroize()thatDropcalls, because reading a value after its drop has run is UB.the_envelope_keeps_its_byte_layout(the reference uses raw secp256k1 recoverable signing),recovers_signer_pubkey_*,ecdh_shared_key_matches_pinned_vector, the DashPay golden-blob decrypt tests, and the DIP-14 test vectors.det_signer,backend_task::dashpay,backend_task::wallet,key_info_screen,qualified_identity,dashpay_derivation): 288 passed.cargo clippy --all-features --all-targets -- -D warningsis clean, andcargo fmt --allhas been run.🤖 Co-authored by Claudius the Magnificent AI Agent
🤖 Generated with Claude Code
https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
PR Hygiene ·
116b1b1src/backend_task/dashpay/auto_accept_proof.rs,src/backend_task/dashpay/encryption.rs,src/backend_task/wallet/derive_identity_key_for_display.rsand 8 more) — approved by lklimekWhen every merge requirement is met, the
PR Hygienecheck passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.