Skip to content

fix(sdk): keep PublicKey unchanged when the inner setter rejects a key - #5979

Merged
lklimek merged 1 commit into
chore/crypto-core-consumersfrom
fix/wasm-dpp2-public-key-set-inner
Nov 26, 2026
Merged

lklimek merged 1 commit into
chore/crypto-core-consumersfrom
fix/wasm-dpp2-public-key-set-inner

Conversation

@Claudius-Maginificent

Copy link
Copy Markdown
Collaborator

TL;DR

Setting an invalid key on a JavaScript PublicKey object no longer leaves the object half-updated.

User story

As a JavaScript developer using the Dash Platform WASM bindings, I can retry after a rejected publicKey.inner = … assignment and trust that the object still holds its previous, consistent key.

Scenario

Actual behavior

Assigning invalid key bytes to inner throws, but the object has already switched its compressed flag. It reports the new format while still holding the old key, so the bytes it returns are the wrong form for the key it stores.

Expected behavior

A rejected assignment throws and leaves the object exactly as it was.

Detailed discussion

Stacked on #5519 (base chore/crypto-core-consumers). Merge #5519 first, then retarget this PR to v5.2-dev. The fix was split out so #5519 stays a mechanical refactor. The defect also exists on v5.2-dev; it was raised in a #5519 review thread.

Issue being fixed or feature implemented

PublicKeyWasm::set_inner (packages/wasm-dpp2/src/public_key.rs) set compressed before the fallible key parse.

What was done?

  • Parse the key first, then update inner and compressed.
  • Add should_leave_public_key_unchanged_when_setter_rejects_key. It covers an invalid 33-byte key on an uncompressed wrapper and an invalid 65-byte key on a compressed wrapper. It failed before the fix.

How Has This Been Tested?

cargo test -p wasm-dpp2 --lib public_key (run natively): 2 passed. cargo clippy -p wasm-dpp2 --all-targets -- -D warnings is clean.

Breaking Changes

None.

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

🤖 Generated with Claude Code

https://claude.ai/code/session_01WunYYijwZNbw3EjHtdMAHC

🤖 Co-authored by Claudius the Magnificent AI Agent

@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Caution

Review failed

The pull request is closed.

  • 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

@lklimek lklimek mentioned this pull request Nov 18, 2026
11 of 19 tasks
@thepastaclaw

thepastaclaw commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Final review complete — no blockers (commit 4b8e075) · triage: low

@lklimek
lklimek marked this pull request as ready for review November 18, 2026 09:36
@Claudius-Maginificent Claudius-Maginificent changed the title fix(wasm-dpp2): keep PublicKey unchanged when the inner setter rejects a key fix(sdk): keep PublicKey unchanged when the inner setter rejects a key Nov 18, 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 1 + Phase 2

The fix correctly makes rejected set_inner assignments atomic: parsing completes before either the key or compression flag changes. One non-blocking test-coverage gap remains: the new test covers rejected assignments but does not verify that successful cross-format assignments update the compression flag and serialized bytes together.

🟡 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: glm-5.3-flash (agent: phase1-reviewer, role: general); reviewer 2: glm-5.3-flash (agent: phase1-reviewer, role: rust-quality); reviewer 3: gpt-6.2-sol (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.2-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.2-sol (agent: phase2-reviewer, role: ffi-engineer); reviewer 6: gpt-6.2-sol (agent: phase2-reviewer, role: rust-quality); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)

  • Triage: low by gpt-6.2-sol (effort low) — This is a small, self-contained WASM wrapper fix that parses the key before mutating state, with focused regression tests and straightforward correctness.
  • Phase 1 reviewers: glm-5.3-flash — general (completed, effort high); agent phase1-reviewer, glm-5.3-flash — rust-quality (completed, effort high); agent phase1-reviewer
  • Phase 1 model: glm-5.3-flash — zai quota: 5h 99% left, weekly 92% left; passed over gemini-3.8-flash-high (antigravity quota lookup failed)
  • 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 — ffi-engineer (completed, effort medium); agent phase2-reviewer, gpt-6.2-sol — rust-quality (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/wasm-dpp2/src/public_key.rs`:
- [SUGGESTION] packages/wasm-dpp2/src/public_key.rs:166-180: Add successful cross-format setter coverage
  The regression test verifies that invalid 33-byte and 65-byte inputs leave the wrapper unchanged, but it does not exercise either successful flag transition. The existing parser-contract test only calls `set_inner` on an uncompressed wrapper with 65-byte input, so deleting `self.0.compressed = false` would still pass; it never exercises the `= true` assignment. Add successful compressed-to-uncompressed and uncompressed-to-compressed assignments and assert both the flag and `inner()` bytes, so the full atomic update contract is protected.

Comment on lines +166 to +180
fn should_leave_public_key_unchanged_when_setter_rejects_key() {
let key = EcdsaSecretKey::from_bytes(&[1; 32])
.expect("valid scalar")
.public_key();
let mut uncompressed =
PublicKeyWasm::constructor(false, key.to_uncompressed().to_vec()).expect("SEC1 key");
assert!(uncompressed.set_inner(vec![0xff; 33]).is_err());
assert!(!uncompressed.compressed());
assert_eq!(uncompressed.inner(), key.to_uncompressed());

let mut compressed =
PublicKeyWasm::constructor(true, key.to_compressed().to_vec()).expect("compressed key");
assert!(compressed.set_inner(vec![0xff; 65]).is_err());
assert!(compressed.compressed());
assert_eq!(compressed.inner(), key.to_compressed());

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.

🟡 Suggestion: Add successful cross-format setter coverage

The regression test verifies that invalid 33-byte and 65-byte inputs leave the wrapper unchanged, but it does not exercise either successful flag transition. The existing parser-contract test only calls set_inner on an uncompressed wrapper with 65-byte input, so deleting self.0.compressed = false would still pass; it never exercises the = true assignment. Add successful compressed-to-uncompressed and uncompressed-to-compressed assignments and assert both the flag and inner() bytes, so the full atomic update contract is protected.

Suggested change
fn should_leave_public_key_unchanged_when_setter_rejects_key() {
let key = EcdsaSecretKey::from_bytes(&[1; 32])
.expect("valid scalar")
.public_key();
let mut uncompressed =
PublicKeyWasm::constructor(false, key.to_uncompressed().to_vec()).expect("SEC1 key");
assert!(uncompressed.set_inner(vec![0xff; 33]).is_err());
assert!(!uncompressed.compressed());
assert_eq!(uncompressed.inner(), key.to_uncompressed());
let mut compressed =
PublicKeyWasm::constructor(true, key.to_compressed().to_vec()).expect("compressed key");
assert!(compressed.set_inner(vec![0xff; 65]).is_err());
assert!(compressed.compressed());
assert_eq!(compressed.inner(), key.to_compressed());
let mut to_compressed =
PublicKeyWasm::constructor(false, key.to_uncompressed().to_vec()).expect("SEC1 key");
to_compressed
.set_inner(key.to_compressed().to_vec())
.expect("valid compressed SEC1 key");
assert!(to_compressed.compressed());
assert_eq!(to_compressed.inner(), key.to_compressed());
let mut to_uncompressed =
PublicKeyWasm::constructor(true, key.to_compressed().to_vec()).expect("SEC1 key");
to_uncompressed
.set_inner(key.to_uncompressed().to_vec())
.expect("valid uncompressed SEC1 key");
assert!(!to_uncompressed.compressed());
assert_eq!(to_uncompressed.inner(), key.to_uncompressed());

source: glm-5.3-flash (phase1-reviewer: general, rust-quality)

…o fix/wasm-dpp2-public-key-set-inner

Preserve the final PR scope, including merge resolutions, on the updated native stack.

Co-Authored-By: Codex <[email protected]>
@lklimek
lklimek added this pull request to stack #6213 November 24, 2026 11:21
@lklimek
lklimek force-pushed the fix/wasm-dpp2-public-key-set-inner branch from 77b280d to 4b8e075 Compare November 24, 2026 11:28
@lklimek
lklimek force-pushed the chore/crypto-core-consumers branch from 2fb8e0f to 57ceca0 Compare November 24, 2026 11:28

@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 1 + Phase 2

New on this head: This head merges the updated base without changing the reviewed patch: the WASM setter still parses before updating either field, so a rejected assignment leaves the key and its encoding unchanged. The Rust workspace and wasm-dpp2 JavaScript tests passed; the main platform suite and first browser shard were still pending. Dashmate local-network E2E timed out waiting for Core nodes to reach block height 1392, on a startup path that does not call the WASM setter.

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

Still open from earlier rounds (1)

  • 🟡 Suggestion: Add successful cross-format setter coverage — packages/wasm-dpp2/src/public_key.rs:166-180 (thread)
Review provenance

Source: reviewer 1: glm-5.3-flash (agent: phase1-reviewer, role: general); reviewer 2: glm-5.3-flash (agent: phase1-reviewer, role: rust-quality); reviewer 3: gpt-6.2-sol (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.2-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.2-sol (agent: phase2-reviewer, role: ffi-engineer); reviewer 6: gpt-6.2-sol (agent: phase2-reviewer, role: rust-quality); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)

  • Triage: low by gpt-6.2-sol (effort low) — The setter now parses the key before mutating either field, a contained behavior fix with regression coverage for both key formats.
  • Phase 1 reviewers: glm-5.3-flash — general (completed, effort high); agent phase1-reviewer, glm-5.3-flash — rust-quality (completed, effort high); agent phase1-reviewer
  • Phase 1 model: glm-5.3-flash — zai quota: 5h 99% left, weekly 59% left; passed over gemini-3.8-flash-high (lane failed)
  • 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 — ffi-engineer (completed, effort medium); agent phase2-reviewer, gpt-6.2-sol — rust-quality (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/wasm-dpp2/src/public_key.rs`:
- [SUGGESTION] packages/wasm-dpp2/src/public_key.rs:166-180: Add successful cross-format setter coverage
  (carried; thread: https://github.com/dashpay/platform/pull/5979#discussion_r4615379997)

@Claudius-Maginificent
Claudius-Maginificent marked this pull request as draft November 24, 2026 12:16
@lklimek
lklimek marked this pull request as ready for review November 26, 2026 21:06
@lklimek
lklimek removed this pull request from stack #6213 November 26, 2026 21:07
@lklimek
lklimek merged commit 7665ec4 into chore/crypto-core-consumers Nov 26, 2026
47 of 53 checks passed
@lklimek
lklimek deleted the fix/wasm-dpp2-public-key-set-inner branch November 26, 2026 21:08
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.

3 participants