Repository navigation
feat(platform)!: add hashed ML-DSA-65 identity keys (PV16) - #6504
QuantumExplorer wants to merge 9 commits into
Conversation
|
📖 Book Preview built successfully. Download the preview from the workflow artifacts. Updated at 2026-12-04T12:16:02.818Z |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
|
🔍 Review in progress (commit a672e85) · live progress · priority |
ML_DSA_65_HASH256 (key type 9) stores the 32 byte SHA-256 of an ML-DSA-65 public key on the identity in place of the 1,952 byte key, from protocol version 16. A transition signed with the key carries the public key in front of the signature (5,261 bytes): the key is hashed and compared with the stored hash, then the signature is verified by the ML_DSA_65 code already there. Like the other hash key types it is not unique to an identity and is registered without a proof of possession. It is found by RIPEMD160(SHA256(data)), which is not the hash the ML_DSA_65 key of the same key pair is found by, so the two forms never share an entry of the key hash tables. It is refused for ENCRYPTION and DECRYPTION as ML_DSA_65 is. Checking a signature costs verify_signature_ml_dsa_65_hash256, 105,000 credits. The key type has its own emergency switch, KeyTypeMlDsa65Hash256, id 13. A transition registering the key type is not active before protocol version 16, which is unreleased, so its tables and generations are edited in place. Bindings: wasm-dpp, wasm-dpp2, wasm-sdk, rs-sdk-ffi, the Swift SDK and the Kotlin SDK know the key type; the Swift signer refuses it as it refuses ML_DSA_65. Wallet derivation and signing stay with issue #6394. Co-Authored-By: Claude Fable 5.2 <[email protected]>
a65a6ef to
bcb9a23
Compare
thepastaclaw
left a comment
There was a problem hiding this comment.
Final validation — Phase 1 + Phase 2
Changes requested: 6 blockers
- A signed batch can be attributed to the other registration of the same ML-DSA key —
packages/rs-dpp/src/util/ml_dsa_65.rs:176-179(new)
Impact: At PV16, an identity that registers both forms of a key pair can have a pending batch executed under a different key's budget or expiry than the signer selected. - The public message verifier accepts unsigned messages for hashed ML-DSA keys —
packages/rs-dpp/src/signing.rs:175-184(new)
Impact: A Rust application usingPlatformMessageSignable::verify_signatureto authenticate a type-9 key holder can accept a message without proof that the holder signed it. - The private-key registration builder returns a hashed key that Platform rejects —
packages/rs-dpp/src/signing.rs:226-231(new)
Impact: A DPP caller usingIdentityPublicKeyInCreation::from_public_key_signed_with_private_keygetsOk, but submitting the result reveals the full public key to the recipient and fails registration. - Registering a hashed ML-DSA key charges for a signature check that never runs —
packages/rs-platform-version/src/version/fee/signature/v1.rs:20-23(new)
Impact: An identity owner pays a base 105,000-credit verification charge per added type-9 key even when the key carries no proof and a different key authorizes the transition. - Swift validates type-9 seed length against a second copy of the Rust rule —
packages/swift-sdk/Sources/SwiftDashSDK/Utils/PrivateKeyUtils.swift:257-258(new)
Impact: Swift callers ofKeySizeValidator.isValidSizereceive a verdict from a host-side size table rather than the rule used to parse the seed in DPP. - iOS refuses stored type-9 seeds while Android offers them to its ECDSA signer —
packages/swift-sdk/Sources/SwiftDashSDK/FFI/KeychainSigner.swift:497-499(new)
Impact: An Android SDK caller with a decryptable type-9 seed stored under its public-key hash can pass signing preflight and, if the seed parses as an ECDSA scalar, receive a signature that Platform rejects.
PR #6504 adds a PV16 identity key that stores an ML-DSA-65 public-key hash and carries the full public key only when signing. The Kotlin SDK build and tests and the book preview passed; the Rust workspace tests, wasm32 tests, and Swift SDK build were skipped, and no code checks failed. One verified suggestion is omitted under the ten-comment limit.
🔴 6 blocking | 🟡 4 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: architecture-layering); reviewer 5: gpt-6.2-astra (agent: phase2-reviewer, role: ffi-engineer); reviewer 6: gpt-6.2-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 7: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 8: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); reviewer 9: gpt-6.2-astra (agent: phase2-reviewer, role: tenderdash-consensus-security); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.2-sol(effort low) — This is a large cross-cutting change that modifies consensus-visible identity-key serialization and validation, cryptographic signature verification, and key-handling paths, including ML-DSA public-key hashing and transition signature parsing in packages/rs-dpp/src/state_transition/mod.rs and packages/rs-dpp/src/util/ml_dsa_65.rs. - 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— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— ffi-engineer (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— platform-versioning (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,gpt-6.2-astra— tenderdash-consensus-security (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 `packages/rs-dpp/src/util/ml_dsa_65.rs`:
- [BLOCKING] packages/rs-dpp/src/util/ml_dsa_65.rs:176-179: A signed batch can be attributed to the other registration of the same ML-DSA key
Impact: At PV16, an identity that registers both forms of a key pair can have a pending batch executed under a different key's budget or expiry than the signer selected.
A batch signed with a budgeted key can be accepted under its eligible, unbudgeted counterpart. `BatchTransitionV1` excludes `signature_public_key_id` from the signed bytes, and this verifier supplies the same message and underlying key to the full-key verifier. The PR permits both forms on one identity, and Drive-ABCI loads the authorization record and remaining budget by the submitted key ID. The hash check binds the signature to the key pair, not to the selected registration. Give type 9 a distinct signing context in DPP and use it consistently in its signers and verifiers. Test that a batch signed for one form does not authenticate under the other; the stored public-key hash need not change.
- [SUGGESTION] packages/rs-dpp/src/util/ml_dsa_65.rs:128-130: The public hash helper accepts incorrectly encoded keys and returns registrable data
Impact: An SDK caller passing container-encoded or truncated bytes to `public_key_hash` can register the resulting digest but cannot use it with the intended key.
The helper returns a 32-byte digest for any slice, so it does not catch inputs such as a DER-wrapped key passed in place of the raw 1,952-byte key. Registration sees only the resulting digest and intentionally does not verify possession; the mismatch surfaces when the caller first tries to sign. Require the fixed-size raw encoding at the helper boundary, or return `InvalidPublicKeySize` for a slice of the wrong length. The digest of a valid raw key stays the same.
In `packages/rs-dpp/src/signing.rs`:
- [BLOCKING] packages/rs-dpp/src/signing.rs:175-184: The public message verifier accepts unsigned messages for hashed ML-DSA keys
Impact: A Rust application using `PlatformMessageSignable::verify_signature` to authenticate a type-9 key holder can accept a message without proof that the holder signed it.
`verify_signature` returns a valid result for an empty signature without inspecting the message or registered hash. The new test also confirms that it rejects the genuine signature returned by the same trait's `sign_by_private_key`. This is the right rule for the registration witness, not for message authentication. The node's outer transition verifier is separate and does verify the signature. Give registration callers an explicit proof-of-possession check that preserves their verdicts, and route type-9 message verification through DPP's cryptographic verifier.
- [BLOCKING] packages/rs-dpp/src/signing.rs:226-231: The private-key registration builder returns a hashed key that Platform rejects
Impact: A DPP caller using `IdentityPublicKeyInCreation::from_public_key_signed_with_private_key` gets `Ok`, but submitting the result reveals the full public key to the recipient and fails registration.
The private-key constructor unconditionally signs and stores the returned bytes as the registration witness. The new signing arm returns the 5,261-byte public-key-plus-signature envelope, so PV16 rejects that witness with `SignatureShouldNotBePresentError` after the recipient has already received the full key. The external-signer constructor correctly leaves the witness empty. Have both registration constructors use the same DPP proof-of-possession rule, without changing how the key signs messages or outer transitions.
In `packages/rs-platform-version/src/version/fee/signature/v1.rs`:
- [BLOCKING] packages/rs-platform-version/src/version/fee/signature/v1.rs:20-23: Registering a hashed ML-DSA key charges for a signature check that never runs
Impact: An identity owner pays a base 105,000-credit verification charge per added type-9 key even when the key carries no proof and a different key authorizes the transition.
A successful registration is charged the rate benchmarked for hashing a 1,952-byte key and verifying an ML-DSA signature, although its witness check only tests whether the field is empty. Identity update and the three identity-create paths all record `SignatureVerificationOperation::new(key.key_type())` for the added key, so fee accounting cannot distinguish the absence check from actual signature verification. Meter the two operations separately in PV16 estimation and execution. Preserve the full rate for real type-9 signature checks and leave shipped fees for other key types unchanged.
In `packages/swift-sdk/Sources/SwiftDashSDK/Utils/PrivateKeyUtils.swift`:
- [BLOCKING] packages/swift-sdk/Sources/SwiftDashSDK/Utils/PrivateKeyUtils.swift:257-258: Swift validates type-9 seed length against a second copy of the Rust rule
Impact: Swift callers of `KeySizeValidator.isValidSize` receive a verdict from a host-side size table rather than the rule used to parse the seed in DPP.
`isValidSize` accepts or rejects the input by comparing its length to this new literal, independently of `ml_dsa_65::seed_from_private_key` and `SEED_SIZE`. The two agree today, but the book's “Where code goes” rule assigns pure-data invariants to DPP and leaves mobile bindings to marshal them. Preserve the Swift API and have it read the key type's expected private-key size from DPP through a thin FFI call.
In `packages/swift-sdk/Sources/SwiftDashSDK/FFI/KeychainSigner.swift`:
- [BLOCKING] packages/swift-sdk/Sources/SwiftDashSDK/FFI/KeychainSigner.swift:497-499: iOS refuses stored type-9 seeds while Android offers them to its ECDSA signer
Impact: An Android SDK caller with a decryptable type-9 seed stored under its public-key hash can pass signing preflight and, if the seed parses as an ECDSA scalar, receive a signature that Platform rejects.
`KeystoreSigner.canSignWith` checks whether the stored bytes are decryptable, but `dispatchSign` drops the key type on the stored-key path. Its JNI helper reaches `dash_sdk_signer_sign`, which supplies a dummy ECDSA key, so it cannot produce the requested ML-DSA signature. Public-key sync alone does not trigger this. The PR prevents the same mistake on iOS by extending a Swift refusal list, putting a capability decision in the binding rather than in the Rust signer that owns it. Carry the actual identity key type through the stored-key sign call and use the raw Rust signer's capability for both mobile preflights. This requires rejecting unsupported requests, not implementing the wallet derivation and signing tracked in dashpay/platform#6394 or restricting custom signers.
In `packages/rs-dpp/src/state_transition/mod.rs`:
- [SUGGESTION] packages/rs-dpp/src/state_transition/mod.rs:1174-1177: Default-feature DPP decodes type-9 registrations as active at PV15
Impact: A client using either version-aware untrusted decoder with DPP's default features gets `Ok` for a type-9 identity registration that a PV15 node refuses.
The activation range is correct, but with the default `state-transitions` feature and without `validation`, `decode_untrusted_in_version` checks the range only for transitions that carry a data contract. None of the four key-registration transitions carries one, so the new discriminant decodes successfully and the function returns `Ok`. Before this change, the unknown discriminant caused decoding to fail. Apply the type-9 activation rule in both feature configurations without changing lightweight decoding of unrelated historical transitions.
In `packages/wasm-dpp2/src/enums/keys/key_type.rs`:
- [SUGGESTION] packages/wasm-dpp2/src/enums/keys/key_type.rs:50: wasm-dpp2 rejects valid ML-DSA seeds that are not secp256k1 scalars
Impact: A JavaScript client can validate a type-9 key against its seed but cannot use `StateTransition.sign` or `signByPrivateKey` with that seed if it falls outside the secp256k1 scalar range.
Both signing methods require `PrivateKeyWasm`, whose constructors use Dash Core's ECDSA private-key parser. That rejects some 32-byte inputs that DPP accepts as ML-DSA seeds, including an all-`0xff` seed. `IdentityPublicKey.validatePrivateKey` already accepts raw bytes and does not impose this scalar restriction. Let both signing methods also accept raw seed bytes and pass them to DPP, while preserving the existing `PrivateKey` input for callers that use it.
In `packages/wasm-sdk/src/document_create_cost.rs`:
- [SUGGESTION] packages/wasm-sdk/src/document_create_cost.rs:181: The document cost estimator quotes a type-9 signing fee for PV14 and PV15
Impact: A caller asking for a historical document-create quote gets an exact signature-fee component for a key type the requested network version cannot register.
`documentCreateCost` accepts the new signature key type independently of its explicit platform-version argument. Drive's `processing_costs` then reads the shared 105,000-credit rate and marks the component `exact: true`, even for PV14 or PV15. Check the signature key type's activation in the Rust estimator before pricing it, so native and WASM callers get the same result.
Out-of-scope follow-up suggestions (1)
These are valid observations, but they are outside this PR's scope and should be handled in separate issues or author/maintainer-requested PRs rather than blocking this review.
- An unproven non-unique key claim can block a later unique-key registration — Drive already rejects a unique-key insertion when the lookup hash exists in the non-unique tree. Existing 20-byte hash-key types can create such a claim without proving possession. This predates type 9 and is distinct from whether the full and hashed ML-DSA forms of one key share a lookup entry.
- Follow-up: Review the cross-tree reservation policy in a separate issue alongside #3396, which tracks the existing disagreement between validation and insertion.
… feat/ml-dsa-65-hash-identity-keys # Conflicts: # packages/rs-dpp/src/state_transition/mod.rs
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 1 + Phase 2
Changes requested: 6 blockers
- A signed batch can be attributed to the other registration of the same ML-DSA key —
packages/rs-dpp/src/util/ml_dsa_65.rs:176-179(thread, carried)
Impact: A PV16 identity that keeps both forms of one key pair active can have a signed batch evaluated against the other registration's budget or contract bounds. - The public message verifier accepts unsigned messages for hashed ML-DSA keys —
packages/rs-dpp/src/signing.rs:175-184(thread, carried)
Impact: An application usingPlatformMessageSignable::verify_signatureto authenticate a type-9 message gets success without a signature and rejection for a genuine signature. - The private-key registration builder returns a hashed key that Platform rejects —
packages/rs-dpp/src/signing.rs:226-231(thread, carried)
Impact: A caller adding a type-9 key withfrom_public_key_signed_with_private_keygets a successful builder result that fails registration withSignatureShouldNotBePresentError. - Registering a hashed ML-DSA key charges for a signature check that never runs —
packages/rs-platform-version/src/version/fee/signature/v1.rs:20-23(thread, carried)
Impact: At PV16, a valid identity update incurs a 105,000-credit base verification charge per added type-9 key, separate from the charge for authenticating the update. - iOS refuses stored type-9 seeds while Android offers them to its ECDSA signer —
packages/swift-sdk/Sources/SwiftDashSDK/FFI/KeychainSigner.swift:497-499(thread, carried)
Impact: An Android SDK caller that imports a type-9 seed into wallet storage can get a positive signing-capability result followed by an unusable ECDSA signature. - Swift validates type-9 seed length against a second copy of the Rust rule —
packages/swift-sdk/Sources/SwiftDashSDK/Utils/PrivateKeyUtils.swift:257-258(thread, carried)
Impact: Swift callers ofKeySizeValidator.isValidSizeget a type-9 seed-length verdict from a separate rule rather than the DPP rule that consumes the seed.
New on this head: This revision merges the SLH-DSA base updates, centralizes key-type activation in DPP, and applies the PV16 registration gate to type 9 in the default-feature decoder. The Kotlin SDK build and emulator tests and the book preview passed; the review check is still pending.
🔴 6 blocking | 🟡 4 suggestion(s)
1 finding(s) not shown inline (the lines are not part of this PR's diff)
🟡 Suggestion: Type-9 registration decoding is untested with DPP's default features
Impact: A regression in the default-feature decoder could let a client decode a type-9 registration as active at PV15 without failing the existing type-9 decoder test.
packages/rs-dpp/src/state_transition/mod.rs:1341-1349
The merge changes the public untrusted decoder used by default-feature consumers, but DPP's own tests enable validation through its dev-dependency and exercise the other decoder branch. The external default-feature check described here omitted type 9. Add a type-9 identity update to that check and retain it as a regression test: the same serialized update should be refused at PV15 and decoded at PV16.
source: muse-spark-1.3-contributor (phase1-reviewer: general, rust-quality)
Still open from earlier rounds (9)
- 🔴 Blocking: A signed batch can be attributed to the other registration of the same ML-DSA key —
packages/rs-dpp/src/util/ml_dsa_65.rs:176-179(thread) - 🔴 Blocking: The public message verifier accepts unsigned messages for hashed ML-DSA keys —
packages/rs-dpp/src/signing.rs:175-184(thread) - 🔴 Blocking: The private-key registration builder returns a hashed key that Platform rejects —
packages/rs-dpp/src/signing.rs:226-231(thread) - 🔴 Blocking: Registering a hashed ML-DSA key charges for a signature check that never runs —
packages/rs-platform-version/src/version/fee/signature/v1.rs:20-23(thread) - 🔴 Blocking: iOS refuses stored type-9 seeds while Android offers them to its ECDSA signer —
packages/swift-sdk/Sources/SwiftDashSDK/FFI/KeychainSigner.swift:497-499(thread) - 🔴 Blocking: Swift validates type-9 seed length against a second copy of the Rust rule —
packages/swift-sdk/Sources/SwiftDashSDK/Utils/PrivateKeyUtils.swift:257-258(thread) - 🟡 Suggestion: The document cost estimator quotes a type-9 signing fee for PV14 and PV15 —
packages/wasm-sdk/src/document_create_cost.rs:181(thread) - 🟡 Suggestion: wasm-dpp2 rejects valid ML-DSA seeds that are not secp256k1 scalars —
packages/wasm-dpp2/src/enums/keys/key_type.rs:50(thread) - 🟡 Suggestion: The public hash helper accepts incorrectly encoded keys and returns registrable data —
packages/rs-dpp/src/util/ml_dsa_65.rs:128-130(thread)
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: architecture-layering); reviewer 5: gpt-6.2-astra (agent: phase2-reviewer, role: ffi-engineer); reviewer 6: gpt-6.2-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 7: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 8: 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) — This is a large cross-cutting change that modifies consensus-visible identity key types, signature encoding and verification, cryptographic key handling, and protocol-versioned validation in files such as packages/rs-dpp/src/state_transition/mod.rs and packages/rs-dpp/src/util/ml_dsa_65.rs. - 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— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— ffi-engineer (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— platform-versioning (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 `packages/rs-dpp/src/state_transition/mod.rs`:
- [SUGGESTION] packages/rs-dpp/src/state_transition/mod.rs:1341-1349: Type-9 registration decoding is untested with DPP's default features
Impact: A regression in the default-feature decoder could let a client decode a type-9 registration as active at PV15 without failing the existing type-9 decoder test.
The merge changes the public untrusted decoder used by default-feature consumers, but DPP's own tests enable `validation` through its dev-dependency and exercise the other decoder branch. The external default-feature check described here omitted type 9. Add a type-9 identity update to that check and retain it as a regression test: the same serialized update should be refused at PV15 and decoded at PV16.
In `packages/rs-dpp/src/util/ml_dsa_65.rs`:
- [BLOCKING] packages/rs-dpp/src/util/ml_dsa_65.rs:176-179: A signed batch can be attributed to the other registration of the same ML-DSA key
(carried; thread: https://github.com/dashpay/platform/pull/6504#discussion_r4798892117)
- [SUGGESTION] packages/rs-dpp/src/util/ml_dsa_65.rs:128-130: The public hash helper accepts incorrectly encoded keys and returns registrable data
(carried; thread: https://github.com/dashpay/platform/pull/6504#discussion_r4798892180)
In `packages/rs-dpp/src/signing.rs`:
- [BLOCKING] packages/rs-dpp/src/signing.rs:175-184: The public message verifier accepts unsigned messages for hashed ML-DSA keys
(carried; thread: https://github.com/dashpay/platform/pull/6504#discussion_r4798892129)
- [BLOCKING] packages/rs-dpp/src/signing.rs:226-231: The private-key registration builder returns a hashed key that Platform rejects
(carried; thread: https://github.com/dashpay/platform/pull/6504#discussion_r4798892131)
In `packages/rs-platform-version/src/version/fee/signature/v1.rs`:
- [BLOCKING] packages/rs-platform-version/src/version/fee/signature/v1.rs:20-23: Registering a hashed ML-DSA key charges for a signature check that never runs
(carried; thread: https://github.com/dashpay/platform/pull/6504#discussion_r4798892141)
In `packages/swift-sdk/Sources/SwiftDashSDK/FFI/KeychainSigner.swift`:
- [BLOCKING] packages/swift-sdk/Sources/SwiftDashSDK/FFI/KeychainSigner.swift:497-499: iOS refuses stored type-9 seeds while Android offers them to its ECDSA signer
(carried; thread: https://github.com/dashpay/platform/pull/6504#discussion_r4798892149)
In `packages/swift-sdk/Sources/SwiftDashSDK/Utils/PrivateKeyUtils.swift`:
- [BLOCKING] packages/swift-sdk/Sources/SwiftDashSDK/Utils/PrivateKeyUtils.swift:257-258: Swift validates type-9 seed length against a second copy of the Rust rule
(carried; thread: https://github.com/dashpay/platform/pull/6504#discussion_r4798892145)
In `packages/wasm-sdk/src/document_create_cost.rs`:
- [SUGGESTION] packages/wasm-sdk/src/document_create_cost.rs:181: The document cost estimator quotes a type-9 signing fee for PV14 and PV15
(carried; thread: https://github.com/dashpay/platform/pull/6504#discussion_r4798892171)
In `packages/wasm-dpp2/src/enums/keys/key_type.rs`:
- [SUGGESTION] packages/wasm-dpp2/src/enums/keys/key_type.rs:50: wasm-dpp2 rejects valid ML-DSA seeds that are not secp256k1 scalars
(carried; thread: https://github.com/dashpay/platform/pull/6504#discussion_r4798892164)
An ML_DSA_65_HASH256 key signs under the FIPS 204 context string `ML_DSA_65_HASH256`, where an ML_DSA_65 key signs under the empty one. One identity can hold a key pair in both forms, and a transition does not sign the id of its signing key, so a signature made for one form could be handed in under the other. It now verifies for the form it was made for only. Adding a key of the type is charged no signature check: it carries no proof of possession, so nothing is hashed or verified. The proof of possession of an added key is metered as its own operation, which costs what a signature check costs for every other key type, as before. `from_public_key_signed_with_private_key` attaches a proof of possession to a key of a unique type only, the rule `from_public_key_signed_external` follows, instead of signing for a hash key whose registration Platform then refuses. `ml_dsa_65::public_key_hash` refuses bytes that are not an encoded public key. Co-Authored-By: Claude Fable 5.2 <[email protected]>
… feat/ml-dsa-65-hash-identity-keys
… feat/ml-dsa-65-hash-identity-keys Besides the conflict in the Swift key size table, the merge places the ML_DSA_65_HASH256 key type in what the layer below added: - `SingleKeySigner::signs_key_type` answers false for it: that signer signs ECDSA only. The Kotlin signer's tests name type 9 among the refused ones. - `KeySizeValidator` reads the size of its private key from Rust, through the new `dash_sdk_ml_dsa_65_hash256_private_key_size` (dpp's `ml_dsa_65::SEED_SIZE`), as the SLH_DSA_SHA2_128S arm does. Co-Authored-By: Claude Fable 5.2 <[email protected]>
… feat/ml-dsa-65-hash-identity-keys Places the ML_DSA_65_HASH256 key type in what the layers below added: `KeyType::private_key_size` (32 bytes), the documentation of the proof of possession check on `PlatformMessageSignable::verify_signature`, and the wallet's rule for which keys are stored with a derivation breadcrumb (none for a key type the wallet does not derive). Co-Authored-By: Claude Fable 5.2 <[email protected]>
… feat/ml-dsa-65-hash-identity-keys The layers below now give the size of a key type's private key through one export, `dash_sdk_key_type_private_key_size`. The one-type export this branch had added for ML_DSA_65_HASH256 is gone, and the Swift `KeySizeValidator` arm of the key type asks the general one. Co-Authored-By: Claude Fable 5.2 <[email protected]>
… feat/ml-dsa-65-hash-identity-keys The FFI now reads a key type through dpp's conversion, so the per-number arms this branch had added for ML_DSA_65_HASH256 are gone with the lists. Co-Authored-By: Claude Fable 5.2 <[email protected]>
… feat/ml-dsa-65-hash-identity-keys
Basic explanation
Stacked on #6510 (SLH-DSA-SHA2-128s keys), which is stacked on #6507 (ML-KEM keys). This pull request is the top of the three and shows only its own commit.
What this does: Identities can register a second form of the post-quantum
ML_DSA_65key,ML_DSA_65_HASH256(key type 9), from protocol version 16. The identity stores only the 32 byte SHA-256 of the ML-DSA-65 public key instead of the 1,952 byte key. When the key signs a state transition, the transition carries the public key in front of the signature, and Platform checks the key against the stored hash before it verifies the signature.Value: A key that seldom signs costs 32 bytes on the identity instead of 1,952, as
ECDSA_HASH160does for an ECDSA key. It is also the form masternode owner and voting keys could map to later; that mapping is not part of this pull request.Risks: Low to medium. No new scheme: the signature is ML-DSA-65, verified with the library
ML_DSA_65already uses in protocol version 16, after one SHA-256 and under a context string of its own. A transition signed this way is 1,952 bytes larger than one signed with the full key. The key type has its own emergency switch. Nothing changes for protocol versions up to 15, where a transition carrying the key type is refused as before. Seven choices in this pull request are consensus-visible and are listed under "Decisions to confirm".Issue being fixed or feature implemented
#6354 added
ML_DSA_65identity keys, which store the whole 1,952 byte public key. The classical key types already have hashed forms (ECDSA_HASH160,EDDSA_25519_HASH160,BIP13_SCRIPT_HASH) for keys that are stored cheaply and shown only when used. The post-quantum key type had none.What was done?
The key type
KeyType::ML_DSA_65_HASH256 = 9inpackages/rs-dpp/src/identity/identity_public_key/key_type.rs, after the key types 6 to 8 of the two pull requests below this one. It is the tenth variant, so its position and its number agree, which is what the derived bincode encoding writes.SHA256(public key), the encoded 1,952 byte ML-DSA-65 public key hashed once.ML_DSA_65key has.openssl dgst -sha256gives for the raw key, so a wallet, a hardware signer or Dash Core can compute it without a Platform constant. The value is pinned in a test against OpenSSL 4.1.0.Signing and verification
StateTransition::verify_identity_signed_signature, throughml_dsa_65::verify_data_signature_with_public_key):ML_DSA_65_HASH256.packages/rs-dpp/src/util/ml_dsa_65.rsshare the decoding of the key and the signature with the existing verifier.ML_DSA_65key signs under the empty context string of FIPS 204; anML_DSA_65_HASH256key signs under the bytes ofML_DSA_65_HASH256. One identity can hold the same key pair in both forms, each with its own security level, budget and expiry, and no transition signs the id of the key that signed it. Without the context, the full key's signature with the public key put in front would verify as the hashed key's, and the hashed key's signature with the public key taken off would verify as the full key's, so anyone relaying a transition could move it to the other key. With it, a signature verifies for the form it was made for and no other. The value is pinned against OpenSSL 4.1.0 (-pkeyopt context-string:ML_DSA_65_HASH256).InvalidStateTransitionSignatureError(20002), refused by check_tx and unpaid in a block. No path panics.ECDSA_HASH160, the type is in drive-abci's list of key types that sign transitions.EDDSA_25519_HASH160andBIP13_SCRIPT_HASHstay out of it and sign nothing, as before.Uniqueness and proof of possession
SignatureShouldNotBePresentError(20008), as forECDSA_HASH160. A proof of possession would put the public key on the chain at registration, which is what the hash is there to avoid.RIPEMD160(SHA256(data)), the rule of every key type whose data is not already 20 bytes. This is not the hash theML_DSA_65key of the same key pair is found by (RIPEMD160(SHA256(public key))), so the full key in the unique table and its hash in the non-unique table never share an entry, and neither registration can keep the other out. A test registers both forms of one key pair on two identities, in both orders.Activation
ML_DSA_65_HASH256_KEY_INITIAL_PROTOCOL_VERSION = 16.v5.2-dev. So its tables and the generations only it selects are edited in place; no new protocol number and no newvN.active_version_range_for_keys_in_creationmakes a transition that registers such a key inactive before 16: refused while decoding, unpaid, forIdentityCreate,IdentityUpdate,IdentityCreateFromAddressesandIdentityCreateFromShieldedPool.Validation
InvalidIdentityPublicKeyDataError(10511).ENCRYPTIONorDECRYPTION:IdentityPublicKeyTypeNotAllowedForPurposeError(10540), the ruleML_DSA_65has. The hash of a signing key serves the purposes the key serves.RIPEMD160(SHA256(data))of anML_DSA_65_HASH256key of the same set isDuplicatedIdentityPublicKeyBasicError. The fullML_DSA_65key and its hash in one set are two entries and are accepted.AUTHENTICATIONat every security level, master included, and forTRANSFER.Sizes and limits
max_state_transition_size(20,480) is the only limit a 5,261 byte signature field meets, and it bounds the whole transition.max_field_value_size(5,120) is read only for document field values and never for a signature field. The untrusted decoder's budget is 100,000 bytes.SystemLimits: 5,261 is the sum of two sizes of the scheme,ml_dsa_65::PUBLIC_KEY_SIZE + ml_dsa_65::SIGNATURE_SIZE.ML_DSA_65_HASH256key has room to add twoML_DSA_65keys (5,261 bytes each with their proof of possession), where one signed with anML_DSA_65key has room for three.Fee
verify_signature_ml_dsa_65_hash256in the signature fee table (FEE_SIGNATURE_VERSION1, which everyFEE_VERSION*schedule names, asverify_signature_ml_dsa_65is): 105,000 credits per check, against 100,000 forML_DSA_65.ML_DSA_65check. Measured on one machine with the pinnedml-dsa0.1.2, the hash takes 4.4 microseconds and the verification 125, so the hash adds about 3.5%, rounded up.SignatureVerificationOperation::for_proof_of_possession, priced byKeyType::proof_of_possession_verify_cost): 0 forML_DSA_65_HASH256, and for every other key type exactly what it was charged before, the cost of one signature check of the type.Emergency switch
EmergencySwitch::KeyTypeMlDsa65Hash256, id 13, in the switches of protocol version 16: the next free id after the three switches (10 to 12) of the two pull requests below this one.ML_DSA_65_HASH256key, and one adding such a key, is refused without a fee, through the same code as the other key type switches. It is separate fromKeyTypeMlDsa65: each gates only its own key type.Clients
simple-signersigns with the key type (public key in front of the signature).rs-sdk-ffi,wasm-dpp,wasm-dpp2andwasm-sdkaccept the value 9 and the nameML_DSA_65_HASH256.KeyTypegainsmlDsa65Hash256(9).KeychainSignerrefuses to sign with one, as it refusesmlDsa65: every path there signs ECDSA secp256k1.KeyTypegainsML_DSA_65_HASH256(9), and the example app names it "ML-DSA-65 Hash256".KeystoreSignerrefuses a stored key of the type through the rule feat(platform)!: add SLH-DSA-SHA2-128s identity keys (PV16) #6510 added (SingleKeySigner::signs_key_type, where this pull request places the type as not signable).rs-platform-walletreturns an error when asked to derive such a key, as forML_DSA_65, and stores a key of the type an update added without a derivation breadcrumb, as it does anSLH_DSA_SHA2_128Sor an ML-KEM key: the key can only have come from outside the wallet.Before and after
An identity update adding the key:
StateTransitionNotActiveError(10603)StateTransitionNotActiveError(10603)SignatureShouldNotBePresentError(20008), unpaidENCRYPTIONorDECRYPTIONStateTransitionNotActiveError(10603)IdentityPublicKeyTypeNotAllowedForPurposeError(10540), unpaidThe same key pair registered in each form, and a transition signed with it:
ML_DSA_65(type 5)ML_DSA_65_HASH256(type 9)ML_DSA_65_HASH256KeyTypeMlDsa65(9)KeyTypeMlDsa65Hash256(13)In-place changes to shipped generations
Every edit below adds an arm for a key type that no identity can hold before protocol version 16: a transition registering one is not active there and is refused while it is decoded, and a transition is the only way a key reaches an identity. So no shipped protocol version reaches the new code. This is the argument #6354 made for
ML_DSA_65, in the same places.validate_state_transition_identity_signed0 (run by generations 1 and 2),SUPPORTED_KEY_TYPESverify_identity_signed_signature0 (run by 1)validate_identity_public_keys_structure1KeyType::signature_verify_cost0FEE_SIGNATURE_VERSION1from_public_key_signed_external0 andfrom_public_key_signed_with_private_key0added_key_proofs_of_possession0 andadvanced_structure0, identity createidentity_and_signatures0, identity create from addressespublic_key_signatures0, identity create from shielded pooltransform_into_action0for_proof_of_possession, which costs the same as before for every key type that can exist before 16Not in this pull request
ML_DSA_65: there is no agreed derivation path for the seed, and the wallet's signers sign ECDSA only.Decisions to confirm
These are consensus-visible and were not settled before the work. Protocol version 16 is unreleased, so each can still change in place.
ML_DSA_65_HASH256.RIPEMD160(SHA256(data)), which keeps the two forms of one key pair apart in the key hash tables. The alternative,RIPEMD160(data), would equal the hash of the full key, the way anECDSA_HASH160key shares the hash of itsECDSA_SECP256K1key.ENCRYPTIONandDECRYPTION, asML_DSA_65is. The classical hashed types have no such rule.ML_DSA_65_HASH256on signatures of the type (added after review). The alternative is to refuse one identity holding both forms of a key pair, which needs state reads on every key registration.Public interface changes
platform-versionfeature_initial_protocol_versions::ML_DSA_65_HASH256_KEY_INITIAL_PROTOCOL_VERSION.FeeSignatureVersiongains a field, so a struct literal of it no longer compiles without it:FeeSignatureVersionFieldsBeforeVersion4is unchanged, so the bytes of platform states saved before 1.4 read as before.dppKeyTypegainsML_DSA_65_HASH256 = 9. An exhaustivematchonKeyTypeoutside the workspace needs an arm for it.KeyType::try_from(9u8)now succeeds.KeyType::all_key_types()changes its return type:dpp::util::ml_dsa_65gains:public_key_hashrefuses bytes that are not the 1,952 of an encoded public key (InvalidPublicKeySize), so a key still in a DER wrapper or a truncated one does not yield a hash that registers and can never sign.MlDsa65ErrorgainsInvalidPublicKeyHashSize(usize),InvalidSignatureWithPublicKeySize(usize)andPublicKeyHashMismatch. An exhaustivematchon it needs arms for them.KeyTypegainsproof_of_possession_verify_cost(&self, platform_version). Itsinitial_protocol_version()answers 16 and itsprivate_key_size()32 for the new type.IdentityPublicKeyInCreation::from_public_key_signed_with_private_key: it attaches a proof of possession only to a key of a unique type, asfrom_public_key_signed_externaldoes. Before, it signed for every key type: anECDSA_HASH160key came back with a signature Platform refuses, and aBIP13_SCRIPT_HASH,EDDSA_25519_HASH160or ML-KEM key gave an error. All of those now come back without a signature, which is what Platform admits.EmergencySwitchgainsKeyTypeMlDsa65Hash256 = 13, appended last; its name as JSON and as a plain object is"keyTypeMlDsa65Hash256".EmergencySwitch::existingreturns fourteen switches at protocol version 16, so the queries that list the switches and their statuses return one more entry.StateTransition::sign,sign_by_private_key,PlatformMessageSignable::sign_by_private_keyandverify_signature,KeyType::public_key_data_from_private_key_data,IdentityPublicKey::validate_private_key_bytesandpublic_key_hashhandle the new type. A signature made for it is 5,261 bytes. A private key that is not 32 bytes givesProtocolError::PrivateKeySizeError.wasm-dpp,wasm-dpp2,wasm-sdkKeyType.ML_DSA_65_HASH256(9) in both binding crates.KeyTypeLikeinwasm-dpp2also accepts"ml_dsa_65_hash256"and9.EmergencySwitchNameinwasm-dpp2gains"keyTypeMlDsa65Hash256".DocumentCreateCostOptions.signatureKeyTypeaccepts'ML_DSA_65_HASH256'.rs-sdk-ffidash_sdk_identity_create_from_componentsanddash_sdk_identity_public_key_create_from_dataaccept key type 9, through dpp's conversion of the key type byte (feat(platform)!: add SLH-DSA-SHA2-128s identity keys (PV16) #6510). No signature or struct layout changes.dash_sdk_key_type_private_key_size(9)is 32 anddash_sdk_signer_from_private_key_supports_key_type(9)isfalse. Both exports come from the layers below; this pull request adds the key type to the dpp andsimple-signerrules they read."keyTypeMlDsa65Hash256"is accepted with no change to them.drive-abciSignatureVerificationOperationgainsfor_proof_of_possession(key_type)and a private field that tells the two apart, so two operations of one key type compare equal only when they are the same kind.rs-sdkidentity_carries_keys) recognises an identity as the claimant's own only through a key of a unique type.ML_DSA_65_HASH256is not unique and proves no possession, so a key set made only of such keys never matches, as with the other hash key types.simple-signerSimpleSigner::signsigns for the new key type.sign_create_witnessrefuses it, as it refusesML_DSA_65.SingleKeySigner::signs_key_type(KeyType::ML_DSA_65_HASH256)isfalse: that signer signs ECDSA only.Swift SDK
KeyTypegainscase mlDsa65Hash256 = 9(name "ML-DSA-65 Hash256"). An exhaustiveswitchonKeyTypein an app needs an arm for it.KeyType(rawValue: 9)now succeeds, so the readers that dropped or refused a type 9 key now return it.KeychainSigner: it reports that it cannot sign with anML_DSA_65_HASH256key and fails a sign request for one withunsupportedKeyType, whether the caller passes key type 9 or the stored row says so.KeySizeValidator.expectedPrivateKeySize(for: .mlDsa65Hash256)is 32, read from Rust (dash_sdk_key_type_private_key_size).KeyValidation.validatePrivateKeyForPublicKeypasses key type 9 to Rust.Kotlin SDK
KeyTypegainsML_DSA_65_HASH256(9). An exhaustivewhenonKeyTypein an app needs a branch for it. A key of type 9 read from a state transition now maps to it instead of to no key type.How Has This Been Tested?
Run locally on macOS (aarch64), on top of
feat/slh-dsa-identity-keysatb655ea6d4d. While this pull request is stacked on a feature branch, CI runs neither the Rust suites nor the Swift build on it, so these local runs are the only Rust signal until it is retargeted. Targeted runs of every touched crate, not the full suites:cargo test -p dpp --all-features --lib -- ml_dsa key_type emergency_switch signing:: public_key_in_creation identity_public_key slh_dsa ml_kem should_only_admit should_sign_with: 350 passed.cargo test -p drive-abci --all-features --lib -- ml_dsa_65 identity_create::tests validate_state_transition_identity_signed hash_key_data slh_dsa ml_kem proofs_of_possession signature_verification_operation identity_create_from identity_update: 364 passed.cargo test -p platform-version --all-features -- signature,cargo test -p simple-signer --all-features,cargo test -p rs-sdk-ffi --all-features --lib -- signer crypto identity::keys identity::create(79 passed),cargo test -p platform-wallet --all-features --lib -- derivation_breadcrumb(3 passed),cargo test -p wasm-dpp2 --all-features --lib -- vote key_type: all passed.cargo clippy -p dpp -p drive-abci -p platform-version -p simple-signer -p rs-sdk-ffi -p platform-wallet -p wasm-dpp -p wasm-dpp2 -p wasm-sdk -p dash-sdk --all-targets --all-features --locked -- --no-deps -D warnings: clean.cargo check --workspace --all-targets --all-features: clean.cargo fmt --all -- --check: clean.What the new tests show:
rs-dpp/src/util/ml_dsa_65.rs): the hash of a seed's public key and the key followed by its signature under the context string are pinned to the values OpenSSL 4.1.0 gives; a signature made for one form does not verify as the other, in both directions; bytes that are not a 1,952 byte key are not hashed; a key with another hash, a spliced signature, another message, a signature that is not canonically encoded and every other size are refused, each with its own error.rs-dpp/src/state_transition/mod.rs): a transfer signed with the key carries 5,261 bytes whose tail is not the signature the full key makes; twelve malformed signature fields, the full key's signature behind the public key among them, are eachInvalidStateTransitionSignatureError, and the hashed key's signature is refused under the full key; a private key that is not the hashed key's own is refused before signing; a transition adding the key decodes at protocol version 16 with a 5,261 byte signature field and is refused at 15.rs-drive-abci, throughcheck_txandprocess_raw_state_transitions):ENCRYPTIONorDECRYPTIONare refused unpaid;ML_DSA_65while another holds its hash, registered in either order;ML_DSA_65key records one that costs 100,000 credits.ML_DSA_65.ML_DSA_65_HASH256key of the same set is refused in either order, and the full key beside its own hash is accepted.Not run locally:
DashSDKFFI.xcframeworkis not built in this checkout, so the Swift SDK, the example app and the XCTests were not compiled or run. The touched files passswiftc -parse, and theKeyTypeenum with its exhaustive switches was compiled and exercised on its own. The call todash_sdk_key_type_private_key_sizein the arm of the key type has not been compiled against a generated header. The Swift build in CI, once it runs, is the first full compile.wasm-dpp2mocha spec added here needs a wasm build and was not run.Breaking Changes
Consensus: protocol version 16 accepts a key type, a signature form and an emergency switch that it did not. Protocol version 16 is unreleased, and protocol versions up to 15 behave as before. Nodes built from
v5.2-devbefore and after this change do not agree at protocol version 16.Source:
KeyType,EmergencySwitchandMlDsa65Errorgain variants,FeeSignatureVersiongains a field, andKeyType::all_key_types()returns ten key types (see "Public interface changes").Checklist:
structure.rs, regeneratedgrovedb-structure.json, and checked the structure viewer link posted on this pull requestFor repository code-owners and collaborators only
🤖 Generated with Claude Code