Skip to content

feat(platform-wallet): check a masternode key by its hash without its secret - #6024

Merged
lklimek merged 4 commits into
v5.2-devfrom
feat/mn-key-id-check
Dec 1, 2026
Merged

lklimek merged 4 commits into
v5.2-devfrom
feat/mn-key-id-check

Conversation

@lklimek

@lklimek lklimek commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: A wallet can now check whether a masternode key belongs to a node using only the key's hash, without needing the key's secret.

User story

As a wallet app developer, I want to check a masternode owner, voting, payout or platform-node key against a node's registered keys from its hash alone, to achieve key matching for keys the wallet does not hold the secret for (watch-only or hardware-held keys).

Scenario

Base flow

A wallet app knows the hash of a key (for example from a list entry or a host keystore) and wants to know whether it is the key a masternode has registered for a given role.

Actual behavior

verify_masternode_key needs the key's secret. With only the hash, the app has to re-implement the comparison.

Expected behavior

verify_masternode_key_id returns the same verdict from the key's 20-byte id as verify_masternode_key returns from its secret: a match, a mismatch, or unverifiable.

Detailed discussion

Issue being fixed or feature implemented

Stacked atop #5889 (feat/masternode-key-rotation); first PR of the stack that builds masternode withdrawals on it.

What was done?

  • New masternode::verify_masternode_key_id (rs-platform-wallet/src/masternode/locator.rs): compares a key's 20-byte id against a MasternodeKeyReference: hash160 for the secp256k1 roles (owner, voting, payout), the Tenderdash node id for PlatformNode. An operator key is a 48-byte BLS key with no 20-byte id, so it is always Unverifiable by id.
  • verify_masternode_key now maps each role to its reference id and compares through the same rule, so the secret path and the hash path cannot disagree. Its existing results are unchanged.
  • KeyVerification::Unverifiable docs cover the operator-by-id case.

How Has This Been Tested?

Unit tests in locator.rs: every role with a 20-byte id gets the same verdict from its id as from its secret (match, mismatch, unknown reference); each role reads only its own reference field; an operator key is never verified by id; a secp256k1 secret outside the curve order never matches.

Breaking Changes

None. The change is additive; no FFI change.

Checklist:

  • I have performed a self-review of my own code
  • My Rust, FFI, WASM, Swift or Kotlin changes follow the coding conventions
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed
  • If I added or changed GroveDB structure, I described it in the area's structure.rs, regenerated grovedb-structure.json, and checked the structure viewer link posted on this pull request
  • If I added or changed a system contract's document schemas, I checked the contract viewer link posted on this pull request

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Generated with Claude Code

https://claude.ai/code/session_01WunYYk4eUkHuGstPtj83j4

🤖 Co-authored by Claudius the Magnificent AI Agent

PR Hygiene · 18f90bb

  • Bots — thepastaclaw ✓
  • Self-review — posted; again after any push
  • Build green
  • Approvals
    • rs-platform-wallet (packages/rs-platform-wallet/src/masternode/locator.rs, packages/rs-platform-wallet/src/masternode/mod.rs) — approved by llbartekll

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 3 commits November 21, 2026 00:42
… secret

Add verify_masternode_key_id: compares a key's 20-byte id (hash160 for the
secp256k1 roles, the Tenderdash node id for PlatformNode) against a
MasternodeKeyReference. Operator has no 20-byte id and stays Unverifiable.
verify_masternode_key now maps each role to its reference id and compares
through the same rule, so the secret and the hash paths cannot disagree.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WunYYhpfoE88XJoyRt4hcR
…ts of masternode key checks

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… a known operator key

KeyVerification::Unverifiable also covers a role that cannot be checked by
its 20-byte id: verify_masternode_key_id returns it for an operator key,
whose reference is the whole BLS key.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WunYYhpfoE88XJoyRt4hcR
@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

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

Use the checkbox below for a quick retry:

  • Trigger review
  • 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

@thepastaclaw

thepastaclaw commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Final review complete — no blockers (commit 18f90bb)

Check both ECDSA encodings with independent public-key ids and distinct
role fields. Cover operator exclusion with populated references, direct
curve mismatches, and zero scalars. Specify public id encodings in rustdoc.

Co-Authored-By: Codex <[email protected]>

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>
@lklimek
lklimek marked this pull request as ready for review November 24, 2026 09:55
@lklimek
lklimek added this pull request to stack #6211 November 24, 2026 09:56
@github-actions

Copy link
Copy Markdown
Contributor

Waiting for bot review — 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 the waiting-bots Waiting for the review bots to report on this head label Nov 24, 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 (queue backlog)

This PR adds a wallet API for checking a masternode key by its public ID without the secret, while preserving the existing secret-based verdicts. The head commit strengthens tests for role isolation and invalid or wrong-curve secrets. The latest GitHub check status showed no failures; the Linux Rust wallet tests and Kotlin SDK emulator build and tests were still pending.

🟡 1 suggestion(s)

Approved: nothing here blocks the merge. The non-blocking findings are optional: fix them forward, in this PR or a follow-up, without waiting for another review round.

Review provenance

Source: reviewer 1: gpt-6.2-sol (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.2-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 3: gpt-6.2-sol (agent: phase2-reviewer, role: rust-quality); reviewer 4: gpt-6.2-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)

  • Triage: low by gpt-6.2-sol (effort low) — The production change is a small, contained refactor that shares role-specific identifier comparisons without changing key derivation or signing, and most of the diff is targeted tests.
  • Phase 1 reviewers: not run (skipped for throughput: 14 PRs queued, above the 10 limit)
  • Fresh verifier: gpt-6.2-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.2-sol — general (completed, effort medium); agent phase2-reviewer, gpt-6.2-sol — architecture-layering (completed, effort medium); agent phase2-reviewer, gpt-6.2-sol — rust-quality (completed, effort medium); agent phase2-reviewer, gpt-6.2-sol — security-auditor (completed, effort medium); agent phase2-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-platform-wallet/src/masternode/locator.rs`:
- [SUGGESTION] packages/rs-platform-wallet/src/masternode/locator.rs:948-953: A registered Platform node ID looks like the wrong key in Core wire order
  Impact: A wallet developer who passes the raw node ID bytes from a Core provider transaction gets `DoesNotMatch` for a registered key whenever reversing the bytes changes their order.
  The returned verdict does not distinguish a byte-order mistake from a different key. The API accepts either representation as `&[u8; 20]` and compares it directly against canonical Tenderdash bytes, but Core serializes the field in reverse order. The rustdoc names the canonical order without showing how to obtain it from a provider transaction. Point callers to `PlatformNodeId::as_byte_array()` on the decoded field so they can use the existing conversion.

@github-actions

Copy link
Copy Markdown
Contributor

Bots are done — your move: post /self-reviewed.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed and removed waiting-bots Waiting for the review bots to report on this head labels Nov 24, 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.

CI failed after approval — commit 8805511

The standing review approved this commit; this follow-up moves the verdict to COMMENT: checks that failed after the review may relate to this change, and the evidence does not rule it out.

Failing checks:

Why it is unclear: The Swift test run ended with an xcodebuild abort (exit 134), but the log does not identify what triggered it or connect it to masternode key verification. The wasm32 job compiled successfully and was canceled after the runner received a shutdown signal, with no test failure reported.

Nothing was re-reviewed: the findings of the standing review are unchanged. The next push gets a full review; a re-run that passes does not restore the approval.

Review provenance

Source: CI-check lane gpt-6.2-sol (agent: triage); no reviewer or verifier lanes ran for this follow-up

  • Verdict moved because CI failed on this commit after the review; failure logs read: 2 GitHub Actions job(s)

@lklimek
lklimek force-pushed the feat/mn-key-id-check branch from 8805511 to 18f90bb Compare November 24, 2026 11:15
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Bots are done — your move: post /self-reviewed.
Full checklist in the description.

@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.

Re-review — Final validation — Phase 2 only (queue backlog)

Updated after discussion: 1 finding(s) of this review were settled in the inline threads.

  • ✅ Withdrawn: 🟡 A registered Platform node ID looks like the wrong key in Core wire order

New on this head: The rebase leaves all four feature commits unchanged: the Rust wallet can check a masternode key by its public identifier without needing the secret. Rust wallet tests and Swift and Kotlin SDK checks passed; PR Hygiene and the review check are still pending.

🟡 1 0 suggestion(s)

Approved: nothing here blocks the merge. The non-blocking findings are optional: fix them forward, in this PR or a follow-up, without waiting for another review round.

Still open from earlier rounds (1)

  • 🟡 Suggestion: A registered Platform node ID looks like the wrong key in Core wire order — packages/rs-platform-wallet/src/masternode/locator.rs:948-953 (thread) — settled: ✅ Withdrawn
Review provenance

Source: reviewer 1: gpt-6.2-sol (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.2-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 3: gpt-6.2-sol (agent: phase2-reviewer, role: rust-quality); reviewer 4: gpt-6.2-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)

  • Triage: low by gpt-6.2-sol (effort low) — The diff adds a straightforward role-specific ID comparison and reuses it in the existing secret-based verifier, with most of the added lines devoted to tests.
  • Phase 1 reviewers: not run (skipped for throughput: 12 PRs queued, above the 10 limit)
  • Fresh verifier: gpt-6.2-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.2-sol — general (completed, effort medium); agent phase2-reviewer, gpt-6.2-sol — architecture-layering (completed, effort medium); agent phase2-reviewer, gpt-6.2-sol — rust-quality (completed, effort medium); agent phase2-reviewer, gpt-6.2-sol — security-auditor (completed, effort medium); agent phase2-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-platform-wallet/src/masternode/locator.rs`:
- [SUGGESTION → WITHDRAWN in discussion; do not fix] packages/rs-platform-wallet/src/masternode/locator.rs:948-953: A registered Platform node ID looks like the wrong key in Core wire order
  (carried; thread: https://github.com/dashpay/platform/pull/6024#discussion_r4678327181)

@lklimek lklimek left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

/self-reviewed

@github-actions

Copy link
Copy Markdown
Contributor

Ready for review — rs-platform-wallet: HashEngineering or ZocoLini or llbartekll or romchornyi.
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-self-review Waiting for the author to post /self-reviewed labels Nov 30, 2026

@llbartekll llbartekll left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed the diff: the refactor keeps every existing verdict of verify_masternode_key, each role reads only its own reference field, and the operator role is correctly Unverifiable by id. No issues found.

@github-actions

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 30, 2026
@lklimek
lklimek merged commit f4b9745 into v5.2-dev Dec 1, 2026
32 checks passed
@lklimek
lklimek deleted the feat/mn-key-id-check branch December 1, 2026 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants