Skip to content

sdk%feat(codec): define Hashable trait, impl_hash helper for typical cases, Codec to validate impl of subtraits, TypeId for name-stable u32 identifier with uniqueness test#16

Open
kwvg wants to merge 15 commits into
dashpay:developfrom
kwvg:hash

Conversation

@kwvg

@kwvg kwvg commented Jun 28, 2026

Copy link
Copy Markdown
Collaborator

Additional Information

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional tests
  • I have made corresponding changes to the documentation
  • I have assigned this pull request to a milestone (for repository code-owners and collaborators only)

@kwvg kwvg added this to the 0.1 milestone Jun 28, 2026
@kwvg kwvg self-assigned this Jun 28, 2026
@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: e4237b0b-59b2-4bcb-b508-b3e779ffe9ba

📥 Commits

Reviewing files that changed from the base of the PR and between 99709ca and afb0251.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (61)
  • Cargo.toml
  • contrib/codeql/attrib.ql
  • contrib/codeql/decl.ql
  • contrib/codeql/lib/filters.qll
  • contrib/codeql/lib/imports.qll
  • contrib/codeql/lib/policy.qll
  • contrib/lint/lint_codeql.py
  • contrib/samples/solver/solver.rs
  • pkgs/dev/Cargo.toml
  • pkgs/dev/build.rs
  • pkgs/num/src/util.rs
  • pkgs/p2p_core/src/error.rs
  • pkgs/p2p_core/src/msg/addr.rs
  • pkgs/p2p_core/src/msg/compact_filters.rs
  • pkgs/p2p_core/src/msg/gov.rs
  • pkgs/p2p_core/src/msg/headers.rs
  • pkgs/p2p_core/src/msg/headers2.rs
  • pkgs/p2p_core/src/msg/inv.rs
  • pkgs/p2p_core/src/msg/mod.rs
  • pkgs/p2p_core/src/msg/ping.rs
  • pkgs/p2p_core/src/msg/version.rs
  • pkgs/p2p_core/src/primitives/command.rs
  • pkgs/p2p_core/src/primitives/compressed_header.rs
  • pkgs/p2p_core/src/primitives/inventory.rs
  • pkgs/p2p_core/src/primitives/mn_list.rs
  • pkgs/p2p_core/src/primitives/short_id.rs
  • pkgs/p2p_core/src/primitives/user_agent.rs
  • pkgs/params/Cargo.toml
  • pkgs/params/src/mainnet.rs
  • pkgs/params/src/regtest.rs
  • pkgs/params/src/test3.rs
  • pkgs/params/tests/genesis_valid.rs
  • pkgs/primitives/src/block.rs
  • pkgs/primitives/src/codec.rs
  • pkgs/primitives/src/gov.rs
  • pkgs/primitives/src/hash.rs
  • pkgs/primitives/src/lib.rs
  • pkgs/primitives/src/payload/assetlock.rs
  • pkgs/primitives/src/payload/assetunlock.rs
  • pkgs/primitives/src/payload/cbtx.rs
  • pkgs/primitives/src/payload/mnhftx.rs
  • pkgs/primitives/src/payload/mod.rs
  • pkgs/primitives/src/payload/proregtx.rs
  • pkgs/primitives/src/payload/proupregtx.rs
  • pkgs/primitives/src/payload/prouprevtx.rs
  • pkgs/primitives/src/payload/proupservtx.rs
  • pkgs/primitives/src/payload/quorum.rs
  • pkgs/primitives/src/script.rs
  • pkgs/primitives/src/support.rs
  • pkgs/primitives/src/transaction.rs
  • pkgs/primitives/src/types/addrv1.rs
  • pkgs/primitives/src/types/addrv2.rs
  • pkgs/primitives/src/types/netaddr.rs
  • pkgs/primitives/src/types/netinfo.rs
  • pkgs/types/Cargo.toml
  • pkgs/types/marker/Cargo.toml
  • pkgs/types/marker/src/lib.rs
  • pkgs/types/src/codec.rs
  • pkgs/types/src/hex.rs
  • pkgs/types/src/lib.rs
  • pkgs/types/src/uint.rs
💤 Files with no reviewable changes (2)
  • pkgs/primitives/src/hash.rs
  • pkgs/params/Cargo.toml
✅ Files skipped from review due to trivial changes (2)
  • pkgs/types/src/lib.rs
  • pkgs/types/Cargo.toml
🚧 Files skipped from review as they are similar to previous changes (56)
  • pkgs/primitives/src/payload/prouprevtx.rs
  • pkgs/p2p_core/src/error.rs
  • contrib/codeql/decl.ql
  • Cargo.toml
  • pkgs/types/marker/Cargo.toml
  • pkgs/dev/Cargo.toml
  • pkgs/p2p_core/src/primitives/command.rs
  • pkgs/types/marker/src/lib.rs
  • pkgs/primitives/src/payload/proupregtx.rs
  • pkgs/p2p_core/src/msg/gov.rs
  • pkgs/p2p_core/src/msg/mod.rs
  • pkgs/p2p_core/src/msg/version.rs
  • contrib/lint/lint_codeql.py
  • contrib/codeql/lib/filters.qll
  • pkgs/num/src/util.rs
  • pkgs/params/tests/genesis_valid.rs
  • pkgs/params/src/regtest.rs
  • pkgs/p2p_core/src/primitives/inventory.rs
  • pkgs/primitives/src/payload/assetlock.rs
  • pkgs/types/src/uint.rs
  • pkgs/p2p_core/src/msg/inv.rs
  • contrib/codeql/lib/imports.qll
  • pkgs/p2p_core/src/msg/ping.rs
  • pkgs/p2p_core/src/primitives/user_agent.rs
  • pkgs/p2p_core/src/primitives/short_id.rs
  • contrib/samples/solver/solver.rs
  • pkgs/primitives/src/payload/mnhftx.rs
  • pkgs/params/src/mainnet.rs
  • pkgs/types/src/hex.rs
  • contrib/codeql/attrib.ql
  • pkgs/primitives/src/payload/assetunlock.rs
  • contrib/codeql/lib/policy.qll
  • pkgs/primitives/src/types/addrv2.rs
  • pkgs/p2p_core/src/primitives/compressed_header.rs
  • pkgs/primitives/src/types/addrv1.rs
  • pkgs/primitives/src/payload/quorum.rs
  • pkgs/primitives/src/payload/proupservtx.rs
  • pkgs/params/src/test3.rs
  • pkgs/p2p_core/src/msg/compact_filters.rs
  • pkgs/primitives/src/payload/mod.rs
  • pkgs/p2p_core/src/msg/headers.rs
  • pkgs/p2p_core/src/msg/addr.rs
  • pkgs/p2p_core/src/msg/headers2.rs
  • pkgs/primitives/src/script.rs
  • pkgs/primitives/src/payload/proregtx.rs
  • pkgs/primitives/src/block.rs
  • pkgs/primitives/src/types/netaddr.rs
  • pkgs/primitives/src/codec.rs
  • pkgs/primitives/src/types/netinfo.rs
  • pkgs/primitives/src/support.rs
  • pkgs/primitives/src/payload/cbtx.rs
  • pkgs/primitives/src/gov.rs
  • pkgs/primitives/src/transaction.rs
  • pkgs/p2p_core/src/primitives/mn_list.rs
  • pkgs/dev/build.rs
  • pkgs/types/src/codec.rs

📝 Walkthrough

Walkthrough

Introduces dash-types-marker derive macros for TypeId and Unencodable, adds EncodeBuf, TypeId, Hashable, and hash_impl!, wires them through primitives and P2P types, refactors block merkle-root computation, and updates CodeQL, Semgrep, build, docs, and config support.

Changes

TypeId / Hashable / EncodeBuf codec system

Layer / File(s) Summary
dash-types-marker and core codec traits
Cargo.toml, pkgs/types/marker/Cargo.toml, pkgs/types/marker/src/lib.rs, pkgs/types/src/codec.rs, pkgs/types/src/entity.rs, pkgs/types/src/hex.rs, pkgs/types/src/lib.rs, pkgs/types/src/uint.rs, pkgs/types/Cargo.toml
Creates dash-types-marker as a proc-macro crate; TypeId derive computes XXH32 of the type name as const TYPE_ID: u32; Unencodable derive emits __CodecMarker/__UnencodableMarker impls. Adds EncodeBuf, ArrayBuf<N>, TypeId, Hashable, and feature-gated Codec to dash_types::codec. Updates all BaseCodec::encode signatures to &mut impl EncodeBuf. Re-exports TypeId/Unencodable from dash_types.
hash_impl! and primitive crate plumbing
pkgs/primitives/Cargo.toml, pkgs/primitives/src/codec.rs, pkgs/primitives/src/lib.rs
Adds hash_impl!, updates codec_base! to use EncodeBuf, makes codec_type! and codec_payload! compose hashing support, adds extern crate self as dash_primitives, removes the internal hash module and public double_sha256/tx_hash re-exports, and extends __private with bitcoin_hashes and dash_num.
Block hashing and merkle-root refactor
pkgs/primitives/src/block.rs, pkgs/params/src/mainnet.rs, pkgs/params/src/regtest.rs, pkgs/params/src/test3.rs, pkgs/params/tests/genesis_valid.rs, pkgs/params/Cargo.toml, contrib/samples/solver/solver.rs
Adds Hashable for BlockHeader (PoW hash via dash_pow::hash over 80-byte ArrayBuf). Introduces MerkleRoot. Adds Block::merkle() with mutation detection. Replaces all manual double_sha256 merkle-root derivations in genesis constructors and the solver sample with block.merkle() / coinbase.hash(). Updates params tests to assert both the stored and computed merkle roots.
Primitive type derives, hashes, and codec updates
pkgs/primitives/src/transaction.rs, pkgs/primitives/src/script.rs, pkgs/primitives/src/gov.rs, pkgs/primitives/src/support.rs, pkgs/primitives/src/payload/*, pkgs/primitives/src/types/*
Adds TypeId, Unencodable, EncodeBuf, and hash_impl! coverage across transaction, script, governance, support, payload, and network-address primitives; replaces GovObject and GovVote inherent hash methods with Hashable implementations returning Hash256; and rewrites DynBitset encoding.
p2p_core codec, type, and marker wiring
pkgs/p2p_core/src/lib.rs, pkgs/p2p_core/src/codec.rs, pkgs/p2p_core/src/error.rs, pkgs/p2p_core/src/msg/*, pkgs/p2p_core/src/primitives/*
Adds __private re-exports, switches macro paths to $crate::__private::, derives TypeId or Unencodable across P2P messages and primitives, adds hash_impl! to message and primitive types, adds cached prev_block_hash to CompressionState, and updates codec encoders to use EncodeBuf.
dash_num macro hygiene and lambda txid update
pkgs/num/src/hash.rs, pkgs/num/src/util.rs, pkgs/num/src/lib.rs, pkgs/num/src/compact.rs, pkgs/dev/src/lambda.rs
Updates dash_num hash and numeric macros to use private dash_types paths, switches generated encoders to EncodeBuf, adds TypeId derives to generated hash types, re-exports dash_types from dash_num::__private, moves impl_num!(CompactTarget, u32), and updates assert_txid to decode a Transaction and call .hash().
Build-time TypeId hash collision detection
pkgs/dev/Cargo.toml, pkgs/dev/build.rs
Adds a build script that scans workspace source directories for types deriving TypeId, correlates macro invocations with macro bodies containing TypeId, computes XXH32 hashes per type name, and panics on collisions. Adds proc-macro2, syn, and xxhash-rust as build-dependencies.
CodeQL and Semgrep policy updates
contrib/codeql/attrib.ql, contrib/codeql/decl.ql, contrib/codeql/lib/filters.qll, contrib/codeql/lib/imports.qll, contrib/codeql/lib/policy.qll, contrib/lint/lint_codeql.py, contrib/semgrep/workspace.yml
Adds hasTypeId predicate; refines codec-coverage enforcement to classify wire vs. non-wire types with distinct diagnostics; replaces isEvaluatedCrate with isEnforcedCrate/isUnencodableCrate; adds THashableImpl declaration slot; rewrites isNotEncodable via hasDerive; recognizes ArrayBuf as codec infrastructure; excludes build-script types from source filtering; allowlists dash_types_marker re-exports; expands lint-script keywords. Adds Semgrep rule enforcing $crate::__private:: in macros.
Docs, dependency graph, and config
README.md, docs/zen/index.md, unconv.toml
Updates pow → primitives dependency edge from test (dotted) to build (solid) in README and docs mermaid graphs. Adds perf to the commit type allowlist.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 58.73% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the core codec/type-safety additions, including Hashable, Codec validation, and TypeId support.
Description check ✅ Passed The description is related to the PR via its dependency note and checklist, and is not off-topic.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jun 28, 2026

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 12

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pkgs/p2p_core/src/primitives/compressed_header.rs (1)

138-153: 🚀 Performance & Scalability | 🟠 Major | ⚡ Quick win

prev_hash elision is still keyed off the wrong predecessor value.

Line 147 compares header.prev_hash with prev.prev_hash. For a normal contiguous chain those values almost never match, so FLAG_PREV_HASH stays set and headers2 keeps paying the full 32-byte prev-hash on nearly every header. The decode fallback mirrors the same assumption, so both sides should reconstruct against the previous header's block hash instead.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkgs/p2p_core/src/primitives/compressed_header.rs` around lines 138 - 153,
The prev-hash compression logic in `CompressedHeader::encode_header` is
comparing against the wrong field, so `FLAG_PREV_HASH` is rarely cleared on
normal chains. Update the `need_prev_hash` check to compare `header.prev_hash`
against the previous header’s block hash rather than `prev.prev_hash`, and make
the matching decode fallback in the compressed header path reconstruct using the
previous header’s block hash as well so both `encode_header` and the
corresponding decode logic use the same predecessor reference.
🧹 Nitpick comments (4)
pkgs/primitives/src/block.rs (1)

175-217: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a regression case for mutated = true.

The new CVE-2012-2459 path is only covered here through non-mutated corpus/genesis blocks, so the duplicate-sibling branch can regress silently. A small unit test that feeds duplicate leaf hashes into compute_merkle_root() (or a crafted block with repeated txids) would lock down the new contract.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkgs/primitives/src/block.rs` around lines 175 - 217, Add a regression test
for the CVE-2012-2459 mutated path in compute_merkle_root() and/or
Block::merkle(). Create a small unit test that uses duplicate sibling leaf
hashes so the duplicate-last-pair branch is exercised and assert that the
returned mutated flag is true; this will lock down the new contract and prevent
silent regressions. Use the existing compute_merkle_root helper and the
Block::merkle method as the entry points for the test.
pkgs/primitives/src/gov.rs (1)

372-390: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Please add a hash regression for GovVote.

GovVote::hash() now has custom legacy-compatible serialization, but the test module only round-trips vote wire/serde data. One fixed-vector assertion for the canonical vote hash would protect the padding/ordering contract you just introduced.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkgs/primitives/src/gov.rs` around lines 372 - 390, Add a regression test for
GovVote::hash to lock down the new legacy-compatible serialization contract. Use
the existing GovVote type in the gov.rs test module and add one fixed-vector
assertion that checks the exact canonical Hash256 output for a known vote
instance. This should verify the padding and field ordering in GovVote::hash,
not just wire/serde round-trips, so future changes to masternode_outpoint,
parent_hash, signal, outcome, or time encoding are caught.
pkgs/primitives/src/payload/proupregtx.rs (1)

21-21: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Avoid restating the type name in the rustdoc summary.

Line 21 repeats ProUpRegTx; make the summary describe the type instead.

Proposed wording
-/// ProUpRegTx -- update MN keys/payout (type 3).
+/// Updates masternode keys and payout details (type 3).

As per coding guidelines, rustdoc summaries should be written "without restating the signature".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkgs/primitives/src/payload/proupregtx.rs` at line 21, The rustdoc summary on
ProUpRegTx should describe the type without repeating its name or the signature.
Update the comment above the ProUpRegTx type in proupregtx.rs so it focuses on
what the type represents (an update to MN keys/payout) instead of restating
“ProUpRegTx”.

Source: Coding guidelines

pkgs/primitives/src/payload/prouprevtx.rs (1)

20-20: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Avoid restating the type name in the rustdoc summary.

Line 20 repeats ProUpRevTx; make the summary describe the type instead.

Proposed wording
-/// ProUpRevTx -- revoke a masternode (type 4).
+/// Revokes a masternode (type 4).

As per coding guidelines, rustdoc summaries should be written "without restating the signature".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkgs/primitives/src/payload/prouprevtx.rs` at line 20, The rustdoc summary on
ProUpRevTx restates the type name, so rewrite the doc comment to describe what
the type does without repeating the signature text. Update the summary attached
to the ProUpRevTx item to use a descriptive phrase about revoking a masternode,
keeping the wording concise and aligned with the rustdoc summary guidelines.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@contrib/codeql/lib/policy.qll`:
- Around line 212-218: Exclude the proc-macro marker crate from isEnforcedCrate
by tightening the path checks in policy.qll so the pkgs/types rule does not
match pkgs/types/marker/**. Update the isEnforcedCrate predicate to keep the
existing crate coverage for num, types, primitives, and p2p_core while
explicitly filtering out the marker crate, matching the Semgrep policy behavior.
- Around line 15-24: The hasDerive predicate is currently matching any attribute
text on the same lines, so unrelated attrs like doc or cfg can be mistaken for
derive. Update hasDerive in policy.qll to only accept derive-style attributes by
checking the attribute kind or meta directly, or by filtering to derive/cfg_attr
before scanning the source text. Keep the existing TypeItem/Attr logic, but make
sure isNotEncodable can only infer Unencodable from a real #[derive(...)]-style
attribute.

In `@contrib/semgrep/workspace.yml`:
- Around line 56-70: The Semgrep rule macro-no-bare-foreign-crate is too broadly
scoped and its crate-name regex is too restrictive. Update the rule in
workspace.yml so paths.include only targets macro-generated code instead of all
Rust files, and adjust the pattern-regex to allow digits in crate names (for
example, crate names like proc_macro2). Keep the existing exclusions and the
$crate::__private hygiene check intact while narrowing the scope and broadening
the crate-name match.

In `@pkgs/dev/build.rs`:
- Around line 64-71: Do not deduplicate type names before the collision check in
build.rs: ScanResult::names currently uses BTreeSet<String>, which hides
duplicate `Foo` spellings across crates/modules before the TypeId hash pass.
Change ScanResult and the related insertion sites in the scan logic to collect
names with push semantics, then detect repeated names during the hash/collision
pass and panic on duplicates, ideally including the source paths or other
provenance in the error message.

In `@pkgs/num/src/hash.rs`:
- Line 309: The generated EncodeBuf path in the macro still uses invocation-site
crate::, which breaks when the macro is exported or reused. Update the
encode-related path in the hash macro (the fn encode signature in the generated
impl) to use $crate::__private::dash_types::codec::EncodeBuf instead of crate::,
so it always resolves through dash_num regardless of expansion site.

In `@pkgs/p2p_core/src/error.rs`:
- Line 17: The public Rust enum in error.rs is missing the required Hash eager
derive. Update the derive list on the enum identified by Unencodable to include
Hash alongside Clone, Debug, PartialEq, and Eq, keeping the existing derives
intact and in the repository’s standard eager-derive order.

In `@pkgs/primitives/src/codec.rs`:
- Around line 45-46: The TypeId assertion in the macro helper is too long for
the Rust line-width limit; wrap the bound in the `_assert` function in
`codec.rs` so the `BaseCodec` and `TypeId` constraints fit within 120
characters. Keep the change localized to the `_assert`/`_check` helper and
preserve the existing type-check behavior while splitting the trait bounds
across multiple lines.
- Around line 35-40: The macro expansion for the `hash()` body in `codec.rs`
relies on the `sha256d::Hash::hash(...)` trait method, but it does not import
`bitcoin_hashes::Hash` itself. Update the macro-generated code in the
`BaseCodec`/`hash` expansion to bring `bitcoin_hashes::Hash as _` into scope so
the expansion is self-contained and does not depend on the caller’s imports.

In `@pkgs/primitives/src/support.rs`:
- Around line 214-229: The bit-masking logic in the serialization path is
applied to the wrong byte when the source is shorter than required; in the
`support.rs` code around the `take`/`last_byte` handling for `DynBitset`, ensure
the final encoded wire byte is masked instead of masking the last copied source
byte. Update the logic so padding behavior stays unchanged, but the partial-byte
mask is applied to the actual last output byte in the buffer when `self.num_bits
% 8 != 0`, preserving the intended serialized bytes and downstream hashes.

In `@pkgs/types/marker/Cargo.toml`:
- Around line 7-13: The new crate is missing the standard feature contract in
its Cargo.toml, so add a [features] table for the crate and follow the workspace
convention by defining default = [], std = [...], and full = ["std"]. Update the
package’s feature configuration in Cargo.toml so the crate opts into the shared
feature layout and exposes its dependencies through the std feature as expected.

In `@pkgs/types/marker/src/lib.rs`:
- Around line 25-45: The derive macros in marker use an absolute path to
::dash_types::codec::TypeId, so the pkgs/types crate must expose itself under
that name for the generated path to resolve. Add a self-alias in
pkgs/types/src/lib.rs with extern crate self as dash_types; near the crate-level
exports so the TypeId derive in pkgs/types/marker/src/lib.rs can reference the
local crate correctly. Keep the alias alongside the other public module setup
used by the dash_types crate root.

In `@pkgs/types/src/lib.rs`:
- Line 25: Do not re-export Unencodable from dash_types in the public lib.rs
yet; the derive macros still resolve against dash_primitives::__CodecMarker and
__UnencodableMarker, so exposing dash_types::Unencodable would break crates that
only depend on dash_types. Keep the marker available through dash_primitives for
now, or update the derive expansion to reference a path that dash_types
re-exports consistently, and verify the symbols involved in
pkgs/types/src/lib.rs and the related derive macro path.

---

Outside diff comments:
In `@pkgs/p2p_core/src/primitives/compressed_header.rs`:
- Around line 138-153: The prev-hash compression logic in
`CompressedHeader::encode_header` is comparing against the wrong field, so
`FLAG_PREV_HASH` is rarely cleared on normal chains. Update the `need_prev_hash`
check to compare `header.prev_hash` against the previous header’s block hash
rather than `prev.prev_hash`, and make the matching decode fallback in the
compressed header path reconstruct using the previous header’s block hash as
well so both `encode_header` and the corresponding decode logic use the same
predecessor reference.

---

Nitpick comments:
In `@pkgs/primitives/src/block.rs`:
- Around line 175-217: Add a regression test for the CVE-2012-2459 mutated path
in compute_merkle_root() and/or Block::merkle(). Create a small unit test that
uses duplicate sibling leaf hashes so the duplicate-last-pair branch is
exercised and assert that the returned mutated flag is true; this will lock down
the new contract and prevent silent regressions. Use the existing
compute_merkle_root helper and the Block::merkle method as the entry points for
the test.

In `@pkgs/primitives/src/gov.rs`:
- Around line 372-390: Add a regression test for GovVote::hash to lock down the
new legacy-compatible serialization contract. Use the existing GovVote type in
the gov.rs test module and add one fixed-vector assertion that checks the exact
canonical Hash256 output for a known vote instance. This should verify the
padding and field ordering in GovVote::hash, not just wire/serde round-trips, so
future changes to masternode_outpoint, parent_hash, signal, outcome, or time
encoding are caught.

In `@pkgs/primitives/src/payload/proupregtx.rs`:
- Line 21: The rustdoc summary on ProUpRegTx should describe the type without
repeating its name or the signature. Update the comment above the ProUpRegTx
type in proupregtx.rs so it focuses on what the type represents (an update to MN
keys/payout) instead of restating “ProUpRegTx”.

In `@pkgs/primitives/src/payload/prouprevtx.rs`:
- Line 20: The rustdoc summary on ProUpRevTx restates the type name, so rewrite
the doc comment to describe what the type does without repeating the signature
text. Update the summary attached to the ProUpRevTx item to use a descriptive
phrase about revoking a masternode, keeping the wording concise and aligned with
the rustdoc summary guidelines.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 3ed4ddbb-481c-4cf2-a937-4014aed178c8

📥 Commits

Reviewing files that changed from the base of the PR and between 577a749 and 73fea3b.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (76)
  • Cargo.toml
  • README.md
  • contrib/codeql/attrib.ql
  • contrib/codeql/decl.ql
  • contrib/codeql/lib/filters.qll
  • contrib/codeql/lib/imports.qll
  • contrib/codeql/lib/policy.qll
  • contrib/lint/lint_codeql.py
  • contrib/samples/solver/solver.rs
  • contrib/semgrep/workspace.yml
  • docs/zen/index.md
  • pkgs/dev/Cargo.toml
  • pkgs/dev/build.rs
  • pkgs/dev/src/lambda.rs
  • pkgs/num/src/compact.rs
  • pkgs/num/src/hash.rs
  • pkgs/num/src/lib.rs
  • pkgs/num/src/util.rs
  • pkgs/p2p_core/src/codec.rs
  • pkgs/p2p_core/src/error.rs
  • pkgs/p2p_core/src/lib.rs
  • pkgs/p2p_core/src/msg/addr.rs
  • pkgs/p2p_core/src/msg/compact_filters.rs
  • pkgs/p2p_core/src/msg/gov.rs
  • pkgs/p2p_core/src/msg/headers.rs
  • pkgs/p2p_core/src/msg/headers2.rs
  • pkgs/p2p_core/src/msg/inv.rs
  • pkgs/p2p_core/src/msg/mod.rs
  • pkgs/p2p_core/src/msg/ping.rs
  • pkgs/p2p_core/src/msg/version.rs
  • pkgs/p2p_core/src/primitives/command.rs
  • pkgs/p2p_core/src/primitives/compressed_header.rs
  • pkgs/p2p_core/src/primitives/inventory.rs
  • pkgs/p2p_core/src/primitives/magic.rs
  • pkgs/p2p_core/src/primitives/mn_list.rs
  • pkgs/p2p_core/src/primitives/protocol_version.rs
  • pkgs/p2p_core/src/primitives/service_flags.rs
  • pkgs/p2p_core/src/primitives/short_id.rs
  • pkgs/p2p_core/src/primitives/user_agent.rs
  • pkgs/params/Cargo.toml
  • pkgs/params/src/mainnet.rs
  • pkgs/params/src/regtest.rs
  • pkgs/params/src/test3.rs
  • pkgs/params/tests/genesis_valid.rs
  • pkgs/primitives/Cargo.toml
  • pkgs/primitives/src/block.rs
  • pkgs/primitives/src/codec.rs
  • pkgs/primitives/src/gov.rs
  • pkgs/primitives/src/hash.rs
  • pkgs/primitives/src/lib.rs
  • pkgs/primitives/src/payload/assetlock.rs
  • pkgs/primitives/src/payload/assetunlock.rs
  • pkgs/primitives/src/payload/cbtx.rs
  • pkgs/primitives/src/payload/mnhftx.rs
  • pkgs/primitives/src/payload/mod.rs
  • pkgs/primitives/src/payload/proregtx.rs
  • pkgs/primitives/src/payload/proupregtx.rs
  • pkgs/primitives/src/payload/prouprevtx.rs
  • pkgs/primitives/src/payload/proupservtx.rs
  • pkgs/primitives/src/payload/quorum.rs
  • pkgs/primitives/src/script.rs
  • pkgs/primitives/src/support.rs
  • pkgs/primitives/src/transaction.rs
  • pkgs/primitives/src/types/addrv1.rs
  • pkgs/primitives/src/types/addrv2.rs
  • pkgs/primitives/src/types/netaddr.rs
  • pkgs/primitives/src/types/netinfo.rs
  • pkgs/types/Cargo.toml
  • pkgs/types/marker/Cargo.toml
  • pkgs/types/marker/src/lib.rs
  • pkgs/types/src/codec.rs
  • pkgs/types/src/entity.rs
  • pkgs/types/src/hex.rs
  • pkgs/types/src/lib.rs
  • pkgs/types/src/uint.rs
  • unconv.toml
💤 Files with no reviewable changes (2)
  • pkgs/primitives/src/hash.rs
  • pkgs/params/Cargo.toml

Comment thread contrib/codeql/lib/policy.qll
Comment thread contrib/codeql/lib/policy.qll
Comment thread contrib/semgrep/workspace.yml
Comment thread pkgs/dev/build.rs
Comment thread pkgs/num/src/hash.rs
Comment thread pkgs/primitives/src/codec.rs
Comment thread pkgs/primitives/src/support.rs
Comment thread pkgs/types/marker/Cargo.toml
Comment thread pkgs/types/marker/src/lib.rs
Comment thread pkgs/types/src/lib.rs

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkgs/p2p_core/src/primitives/compressed_header.rs`:
- Around line 34-42: `CompressionState` currently lets `prev_header` and
`prev_block_hash` drift apart because both are public and serde-derived. Make
the cached hash internal to `CompressionState` or add atomic setter/init logic
in `CompressionState`/`compress`-related paths so `prev_block_hash` is always
derived from `prev_header` when absent. Update the decode/compression logic that
reads `prev_hash` and the decision branch in the compression path to fall back
to the header-derived hash instead of trusting stale state.

In `@pkgs/types/src/codec.rs`:
- Around line 446-453: Rename the hidden marker traits in codec.rs to satisfy
Rust trait naming conventions by changing __CodecMarker and __UnencodableMarker
to UpperCamelCase names like CodecMarker and UnencodableMarker. Update all
references in the derive macro implementation and the CodeQL policy so they use
the new trait names consistently. Also adjust any blanket impls, trait bounds,
or generated code paths that reference these markers to avoid broken
compile-time checks.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a1ce5931-7223-4e78-908b-305970de92a5

📥 Commits

Reviewing files that changed from the base of the PR and between 73fea3b and 99709ca.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (76)
  • Cargo.toml
  • README.md
  • contrib/codeql/attrib.ql
  • contrib/codeql/decl.ql
  • contrib/codeql/lib/filters.qll
  • contrib/codeql/lib/imports.qll
  • contrib/codeql/lib/policy.qll
  • contrib/lint/lint_codeql.py
  • contrib/samples/solver/solver.rs
  • contrib/semgrep/workspace.yml
  • docs/zen/index.md
  • pkgs/dev/Cargo.toml
  • pkgs/dev/build.rs
  • pkgs/dev/src/lambda.rs
  • pkgs/num/src/compact.rs
  • pkgs/num/src/hash.rs
  • pkgs/num/src/lib.rs
  • pkgs/num/src/util.rs
  • pkgs/p2p_core/src/codec.rs
  • pkgs/p2p_core/src/error.rs
  • pkgs/p2p_core/src/lib.rs
  • pkgs/p2p_core/src/msg/addr.rs
  • pkgs/p2p_core/src/msg/compact_filters.rs
  • pkgs/p2p_core/src/msg/gov.rs
  • pkgs/p2p_core/src/msg/headers.rs
  • pkgs/p2p_core/src/msg/headers2.rs
  • pkgs/p2p_core/src/msg/inv.rs
  • pkgs/p2p_core/src/msg/mod.rs
  • pkgs/p2p_core/src/msg/ping.rs
  • pkgs/p2p_core/src/msg/version.rs
  • pkgs/p2p_core/src/primitives/command.rs
  • pkgs/p2p_core/src/primitives/compressed_header.rs
  • pkgs/p2p_core/src/primitives/inventory.rs
  • pkgs/p2p_core/src/primitives/magic.rs
  • pkgs/p2p_core/src/primitives/mn_list.rs
  • pkgs/p2p_core/src/primitives/protocol_version.rs
  • pkgs/p2p_core/src/primitives/service_flags.rs
  • pkgs/p2p_core/src/primitives/short_id.rs
  • pkgs/p2p_core/src/primitives/user_agent.rs
  • pkgs/params/Cargo.toml
  • pkgs/params/src/mainnet.rs
  • pkgs/params/src/regtest.rs
  • pkgs/params/src/test3.rs
  • pkgs/params/tests/genesis_valid.rs
  • pkgs/primitives/Cargo.toml
  • pkgs/primitives/src/block.rs
  • pkgs/primitives/src/codec.rs
  • pkgs/primitives/src/gov.rs
  • pkgs/primitives/src/hash.rs
  • pkgs/primitives/src/lib.rs
  • pkgs/primitives/src/payload/assetlock.rs
  • pkgs/primitives/src/payload/assetunlock.rs
  • pkgs/primitives/src/payload/cbtx.rs
  • pkgs/primitives/src/payload/mnhftx.rs
  • pkgs/primitives/src/payload/mod.rs
  • pkgs/primitives/src/payload/proregtx.rs
  • pkgs/primitives/src/payload/proupregtx.rs
  • pkgs/primitives/src/payload/prouprevtx.rs
  • pkgs/primitives/src/payload/proupservtx.rs
  • pkgs/primitives/src/payload/quorum.rs
  • pkgs/primitives/src/script.rs
  • pkgs/primitives/src/support.rs
  • pkgs/primitives/src/transaction.rs
  • pkgs/primitives/src/types/addrv1.rs
  • pkgs/primitives/src/types/addrv2.rs
  • pkgs/primitives/src/types/netaddr.rs
  • pkgs/primitives/src/types/netinfo.rs
  • pkgs/types/Cargo.toml
  • pkgs/types/marker/Cargo.toml
  • pkgs/types/marker/src/lib.rs
  • pkgs/types/src/codec.rs
  • pkgs/types/src/entity.rs
  • pkgs/types/src/hex.rs
  • pkgs/types/src/lib.rs
  • pkgs/types/src/uint.rs
  • unconv.toml
💤 Files with no reviewable changes (2)
  • pkgs/params/Cargo.toml
  • pkgs/primitives/src/hash.rs
✅ Files skipped from review due to trivial changes (13)
  • unconv.toml
  • README.md
  • Cargo.toml
  • docs/zen/index.md
  • pkgs/primitives/src/payload/assetlock.rs
  • pkgs/num/src/lib.rs
  • pkgs/p2p_core/src/msg/gov.rs
  • pkgs/types/src/entity.rs
  • pkgs/types/marker/Cargo.toml
  • pkgs/types/Cargo.toml
  • pkgs/primitives/Cargo.toml
  • pkgs/num/src/compact.rs
  • pkgs/p2p_core/src/msg/version.rs
🚧 Files skipped from review as they are similar to previous changes (56)
  • pkgs/p2p_core/src/msg/ping.rs
  • pkgs/p2p_core/src/primitives/magic.rs
  • pkgs/p2p_core/src/codec.rs
  • pkgs/num/src/util.rs
  • contrib/lint/lint_codeql.py
  • pkgs/dev/Cargo.toml
  • contrib/codeql/decl.ql
  • pkgs/p2p_core/src/msg/inv.rs
  • pkgs/p2p_core/src/msg/mod.rs
  • pkgs/types/src/lib.rs
  • pkgs/p2p_core/src/primitives/short_id.rs
  • contrib/samples/solver/solver.rs
  • contrib/semgrep/workspace.yml
  • pkgs/p2p_core/src/lib.rs
  • pkgs/types/src/uint.rs
  • contrib/codeql/lib/filters.qll
  • pkgs/p2p_core/src/primitives/service_flags.rs
  • pkgs/p2p_core/src/error.rs
  • pkgs/p2p_core/src/primitives/inventory.rs
  • pkgs/dev/src/lambda.rs
  • pkgs/p2p_core/src/primitives/protocol_version.rs
  • pkgs/primitives/src/payload/assetunlock.rs
  • pkgs/types/src/hex.rs
  • pkgs/primitives/src/types/netaddr.rs
  • pkgs/p2p_core/src/primitives/command.rs
  • pkgs/types/marker/src/lib.rs
  • pkgs/primitives/src/payload/prouprevtx.rs
  • pkgs/primitives/src/payload/mnhftx.rs
  • pkgs/num/src/hash.rs
  • pkgs/primitives/src/payload/proupregtx.rs
  • contrib/codeql/attrib.ql
  • pkgs/p2p_core/src/primitives/user_agent.rs
  • pkgs/primitives/src/payload/proupservtx.rs
  • pkgs/params/tests/genesis_valid.rs
  • pkgs/params/src/test3.rs
  • pkgs/params/src/regtest.rs
  • contrib/codeql/lib/imports.qll
  • pkgs/params/src/mainnet.rs
  • pkgs/p2p_core/src/msg/headers2.rs
  • pkgs/p2p_core/src/msg/addr.rs
  • pkgs/primitives/src/types/addrv1.rs
  • contrib/codeql/lib/policy.qll
  • pkgs/p2p_core/src/primitives/mn_list.rs
  • pkgs/p2p_core/src/msg/headers.rs
  • pkgs/primitives/src/support.rs
  • pkgs/primitives/src/types/addrv2.rs
  • pkgs/primitives/src/transaction.rs
  • pkgs/p2p_core/src/msg/compact_filters.rs
  • pkgs/primitives/src/payload/cbtx.rs
  • pkgs/dev/build.rs
  • pkgs/primitives/src/payload/quorum.rs
  • pkgs/primitives/src/payload/proregtx.rs
  • pkgs/primitives/src/block.rs
  • pkgs/primitives/src/gov.rs
  • pkgs/primitives/src/payload/mod.rs
  • pkgs/primitives/src/types/netinfo.rs

Comment thread pkgs/p2p_core/src/primitives/compressed_header.rs Outdated
Comment thread pkgs/types/src/codec.rs
@kwvg

kwvg commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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.

1 participant