Repository navigation
fix(sdk): keep PublicKey unchanged when the inner setter rejects a key - #5979
Conversation
|
Caution Review failedThe pull request is closed.
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. |
|
✅ Final review complete — no blockers (commit 4b8e075) · triage: low |
thepastaclaw
left a comment
There was a problem hiding this comment.
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:
lowbygpt-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); agentphase1-reviewer,glm-5.3-flash— rust-quality (completed, effort high); agentphase1-reviewer - Phase 1 model:
glm-5.3-flash— zai quota: 5h 99% left, weekly 92% left; passed overgemini-3.8-flash-high(antigravity quota lookup failed) - Fresh verifier:
gpt-6.2-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.2-sol— general (completed, effort medium); agentphase2-reviewer,gpt-6.2-sol— architecture-layering (completed, effort medium); agentphase2-reviewer,gpt-6.2-sol— ffi-engineer (completed, effort medium); agentphase2-reviewer,gpt-6.2-sol— rust-quality (completed, effort medium); 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/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.
| 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()); |
There was a problem hiding this comment.
🟡 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.
| 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]>
77b280d to
4b8e075
Compare
2fb8e0f to
57ceca0
Compare
thepastaclaw
left a comment
There was a problem hiding this comment.
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:
lowbygpt-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); agentphase1-reviewer,glm-5.3-flash— rust-quality (completed, effort high); agentphase1-reviewer - Phase 1 model:
glm-5.3-flash— zai quota: 5h 99% left, weekly 59% left; passed overgemini-3.8-flash-high(lane failed) - Fresh verifier:
gpt-6.2-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.2-sol— general (completed, effort medium); agentphase2-reviewer,gpt-6.2-sol— architecture-layering (completed, effort medium); agentphase2-reviewer,gpt-6.2-sol— ffi-engineer (completed, effort medium); agentphase2-reviewer,gpt-6.2-sol— rust-quality (completed, effort medium); 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/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)
TL;DR
Setting an invalid key on a JavaScript
PublicKeyobject 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
innerthrows, but the object has already switched itscompressedflag. 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 tov5.2-dev. The fix was split out so #5519 stays a mechanical refactor. The defect also exists onv5.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) setcompressedbefore the fallible key parse.What was done?
innerandcompressed.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 warningsis clean.Breaking Changes
None.
Checklist:
structure.rs, regeneratedgrovedb-structure.json, and checked the structure 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