Repository navigation
Conversation
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
|
Note This pull request has no conflicts! 🎊 🎉 🎊 |
|
⛔ Final review complete — 1 blocking finding(s) (commit b983106) · triage: critical |
17b35d3 to
e608324
Compare
`EcdsaSecretKey` gains `ecdh_shared_secret`, the hashed 32-byte secret, and `ecdh_shared_point`, the raw 64-byte point, so Platform no longer exports the secret scalar into raw `secp256k1` types.
e608324 to
b983106
Compare
|
Steward: this one waits for the maintainer. He is away, and the steward reviews and merges in his place under the rules in #131. Those rules do not let me merge this PR. Nothing is wrong with the code as far as I have read it; this is about who decides.
It is question 5 in #131, so he sees it first on his return. The PR stays open, and I will not close it. If you want to prepare it for his review, his closest code is 🤖 Posted autonomously by Claude (claude-opus-5-5) on behalf of pasta. |
thepastaclaw
left a comment
There was a problem hiding this comment.
Final validation — Phase 1 + Phase 2
The typed ECDH methods use the correct libsecp256k1 operations and the relevant CI checks succeeded. The hashed-secret method nevertheless leaves a copy of the shared secret in a backend SharedSecret value that is not erased on drop, and the raw-point API needs an explicit key-derivation warning. The unit test verifies symmetry and the internal hash relationship but lacks an independent compatibility vector.
🔴 1 blocking | 🟡 2 suggestion(s)
Review provenance
Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); reviewer 3: gpt-6.2-astra (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 5: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.2-sol(effort low) — The change adds ECDH shared-secret and shared-point derivation to typed secp256k1 secret keys in pkgs/pkc/src/ecdsa/secret_ops.rs, directly modifying cryptographic key-handling behavior. - Phase 1 reviewers:
muse-spark-1.3-contributor— general (completed, effort xhigh); agentphase1-reviewer,muse-spark-1.3-contributor— rust-quality (completed, effort xhigh); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-3.8-flash-high(antigravity quota lookup failed),glm-5.3-flash(not used above high effort; tier asks max) - Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
- Fresh verifier:
gpt-6.2-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.2-astra— general (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— rust-quality (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— security-auditor (completed, effort high); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.
In `pkgs/pkc/src/ecdsa/secret_ops.rs`:
- [BLOCKING] pkgs/pkc/src/ecdsa/secret_ops.rs:309-311: Erase the temporary backend SharedSecret
`SharedSecret::new(...).to_secret_bytes()` copies the derived secret into the returned array, then drops the backend `SharedSecret`. In the pinned secp256k1 implementation, `SharedSecret` is `Copy` and provides `non_secure_erase()` but has no zeroizing `Drop` implementation. Therefore, wrapping only the copied array in `Zeroizing` leaves another shared-secret copy in the function's storage after return, undermining the secret-zeroization guarantees used throughout this module. Keep the backend value in a mutable local, copy its bytes, explicitly erase it, and then wrap the copied bytes.
- [SUGGESTION] pkgs/pkc/src/ecdsa/secret_ops.rs:313-316: Warn that the raw ECDH point must be hashed
The public method exposes the unhashed `x || y` coordinates, but its documentation only describes the layout. Callers can mistake this output for ready-to-use key material even though the upstream API warns that a strong hash or KDF may be critical. Document the security requirement and direct callers to `ecdh_shared_secret` unless they intentionally need a custom KDF.
- [SUGGESTION] pkgs/pkc/src/ecdsa/secret_ops.rs:426-436: Add an independent ECDH compatibility vector
The test checks symmetry and recomputes the hashed secret from `ecdh_shared_point()`, but both values are produced by the same backend and the expected hash is derived from the result under test. A consistently wrong coordinate convention or compatibility choice could therefore remain undetected. Add a fixed scalar/public-key known-answer vector with independently sourced `x || y` and SHA-256 values; this should also cover the alternate shared-point Y-parity branch.
| pub fn ecdh_shared_secret(&self, peer: &EcdsaPublicKey) -> Zeroizing<[u8; 32]> { | ||
| Zeroizing::new(SharedSecret::new(peer.as_inner(), &self.inner).to_secret_bytes()) | ||
| } |
There was a problem hiding this comment.
🔴 Blocking: Erase the temporary backend SharedSecret
SharedSecret::new(...).to_secret_bytes() copies the derived secret into the returned array, then drops the backend SharedSecret. In the pinned secp256k1 implementation, SharedSecret is Copy and provides non_secure_erase() but has no zeroizing Drop implementation. Therefore, wrapping only the copied array in Zeroizing leaves another shared-secret copy in the function's storage after return, undermining the secret-zeroization guarantees used throughout this module. Keep the backend value in a mutable local, copy its bytes, explicitly erase it, and then wrap the copied bytes.
| pub fn ecdh_shared_secret(&self, peer: &EcdsaPublicKey) -> Zeroizing<[u8; 32]> { | |
| Zeroizing::new(SharedSecret::new(peer.as_inner(), &self.inner).to_secret_bytes()) | |
| } | |
| pub fn ecdh_shared_secret(&self, peer: &EcdsaPublicKey) -> Zeroizing<[u8; 32]> { | |
| let mut shared = SharedSecret::new(peer.as_inner(), &self.inner); | |
| let bytes = shared.to_secret_bytes(); | |
| shared.non_secure_erase(); | |
| Zeroizing::new(bytes) | |
| } |
source: muse-spark-1.3-contributor (phase1-reviewer: general, rust-quality); gpt-6.2-astra (phase2-reviewer: general, rust-quality, security-auditor)
| /// ECDH shared point with `peer`, as the unhashed `x || y` coordinates. | ||
| pub fn ecdh_shared_point(&self, peer: &EcdsaPublicKey) -> Zeroizing<[u8; 64]> { | ||
| Zeroizing::new(shared_secret_point(peer.as_inner(), &self.inner)) | ||
| } |
There was a problem hiding this comment.
🟡 Suggestion: Warn that the raw ECDH point must be hashed
The public method exposes the unhashed x || y coordinates, but its documentation only describes the layout. Callers can mistake this output for ready-to-use key material even though the upstream API warns that a strong hash or KDF may be critical. Document the security requirement and direct callers to ecdh_shared_secret unless they intentionally need a custom KDF.
| /// ECDH shared point with `peer`, as the unhashed `x || y` coordinates. | |
| pub fn ecdh_shared_point(&self, peer: &EcdsaPublicKey) -> Zeroizing<[u8; 64]> { | |
| Zeroizing::new(shared_secret_point(peer.as_inner(), &self.inner)) | |
| } | |
| /// ECDH shared point with `peer`, as the unhashed `x || y` coordinates. | |
| /// | |
| /// # Security | |
| /// | |
| /// Hash this point before using it as key material. The raw coordinates | |
| /// must not be used directly as a secret; prefer | |
| /// [`ecdh_shared_secret`](Self::ecdh_shared_secret) unless a custom KDF | |
| /// over the point is required. | |
| pub fn ecdh_shared_point(&self, peer: &EcdsaPublicKey) -> Zeroizing<[u8; 64]> { | |
| Zeroizing::new(shared_secret_point(peer.as_inner(), &self.inner)) | |
| } |
source: muse-spark-1.3-contributor (phase1-reviewer: general, rust-quality)
| fn ecdh_is_symmetric_and_hashes_the_point(alice_sk: EcdsaSecretKey, bob_sk: EcdsaSecretKey) { | ||
| let point = alice_sk.ecdh_shared_point(&bob_sk.public_key()); | ||
| assert_eq!(*point, *bob_sk.ecdh_shared_point(&alice_sk.public_key())); | ||
|
|
||
| let secret = alice_sk.ecdh_shared_secret(&bob_sk.public_key()); | ||
| assert_eq!(*secret, *bob_sk.ecdh_shared_secret(&alice_sk.public_key())); | ||
|
|
||
| let mut prefixed = [0x02 | (point[63] & 1); 33]; | ||
| prefixed[1..].copy_from_slice(&point[..32]); | ||
| assert_eq!(*secret, sha256::Hash::hash(&prefixed).to_byte_array()); | ||
| } |
There was a problem hiding this comment.
🟡 Suggestion: Add an independent ECDH compatibility vector
The test checks symmetry and recomputes the hashed secret from ecdh_shared_point(), but both values are produced by the same backend and the expected hash is derived from the result under test. A consistently wrong coordinate convention or compatibility choice could therefore remain undetected. Add a fixed scalar/public-key known-answer vector with independently sourced x || y and SHA-256 values; this should also cover the alternate shared-point Y-parity branch.
source: muse-spark-1.3-contributor (phase1-reviewer: general, rust-quality); gpt-6.2-astra (phase2-reviewer: general)
Motivation
The typed secp256k1 keys in
pkccannot compute an ECDH shared secret, so Platform exports the secret scalar into rawsecp256k1types to encrypt DashPay contact data and for DashConnect.Closes #137.
Additional Information
EcdsaSecretKeygainsecdh_shared_secret, the hashed 32-byte secret (SHA256(0x02 | (y & 1) || x), assecp256k1::ecdh::SharedSecret::new), andecdh_shared_point, the raw 64-bytex || ypoint. Both use the constant-time ECDH of libsecp256k1 and returnZeroizingbuffers.dashpay/rust-dashcore#1446 exposes them through
dashcore::crypto::ecdsaonce this is released.How Has This Been Tested?
A unit test checks that both sides derive the same point and secret, and that the secret is the SHA256 of the prefixed X coordinate.
Checklist
comments and concerns without said assistance. I assume authorship of the code submitted.
Agent disclosure
May be assisted by Opus 5.5, medium effort.