fix(dash): normalize PlatformNodeId to canonical byte order at consensus boundary#889
Conversation
…sus boundary PlatformNodeId held bytes in two different orders depending on how it was constructed: consensus_decode kept the wire bytes as-is (Dash Core serializes the field as a uint160, whose internal blob order is reversed), while from_ed25519_public_key produced the canonical forward Tenderdash node id (SHA256(pubkey)[0..20]). Ids from the two paths never compared equal, so wallet-owned platform node ids could never be recognized from a decoded ProRegTx, and Display of a decoded id showed the reversed form that matches neither dashmate nor explorers. Normalize at the consensus boundary so the newtype always holds canonical forward bytes: consensus_decode reverses the wire bytes into canonical order and consensus_encode reverses back to wire order. from_ed25519_public_key, Display, FromHex, and the bincode layout are unchanged. Fixes #887 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthrough
ChangesPlatformNodeId normalization
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #889 +/- ##
=======================================
Coverage 74.37% 74.37%
=======================================
Files 327 327
Lines 74747 74771 +24
=======================================
+ Hits 55590 55610 +20
- Misses 19157 19161 +4
|
Fixes #887
Problem
PlatformNodeId(#885) held bytes in two different orders depending on construction path, so values from the two paths never compared equal:consensus_decode(ProRegTx / ProUpServTx / SML entryplatformNodeID) kept the wire bytes as-is — Dash Core serializes the field as auint160, whose internal blob order is reversed relative to the canonical id.from_ed25519_public_key(fix(key-wallet): platform node id is the Tenderdash node ID (SHA256[0..20]), not hash160 #884) produces the canonical forward Tenderdash node id (SHA256(pubkey)[0..20]).Consequences: key-wallet's provider matching (
account_checker.rs) could never recognize a wallet-owned platform node id from a decoded ProRegTx, andDisplayof a decoded id showed the reversed form matching neither dashmate, Tenderdash, nor explorers.Fix
Normalize at the consensus boundary so the newtype always holds canonical forward bytes:
consensus_decodereverses the wire bytes into canonical order.consensus_encodereverses back to wire order, so re-encoding is byte-identical to the original wire bytes (payload hashes, SML entry hashes, and merkle roots are unaffected).from_ed25519_public_key,Display,FromHex, serde, and the bincode layout are unchanged.Tests
consensus_round_tripnow uses asymmetric bytes and asserts wire order is the byte-reversal of canonical order.consensus_decode_yields_canonical_orderuses the mainnet evonode vector from the issue: wire8cb97997…7968decodes to canonical68794393…b98cand re-encodes byte-identically.decoded_wire_id_matches_derived_idasserts a wire-decoded id equals the id derived from the matching Ed25519 public key — the exact mismatch from the issue.test_payload_version_2_encoding_and_decoding): the decoded id is now the canonical (reversed) form; the existing re-encode assertion confirms wire bytes are unchanged.Ran:
cargo test -p dashcore --all-features,cargo test -p key-wallet --all-features,cargo test -p dash-spvandcargo test -p dash-spv-ffi --test dashd_syncwith dashd regtest integration tests — all green.cargo fmt --checkandcargo clippy -p dashcore --all-features --all-targetsclean.Note for downstream
🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests