Skip to content

refactor: reuse impl_crypto_common! macro for Hash type#809

Open
wangzishuai1987 wants to merge 1 commit intojarchain:masterfrom
wangzishuai1987:refactor/dedup-hash-hex
Open

refactor: reuse impl_crypto_common! macro for Hash type#809
wangzishuai1987 wants to merge 1 commit intojarchain:masterfrom
wangzishuai1987:refactor/dedup-hash-hex

Conversation

@wangzishuai1987
Copy link
Copy Markdown

Summary

Contributes to #186 — eliminate code duplication across grey crates.

Hash manually implemented to_hex, from_hex, and Deserialize with identical logic to the impl_crypto_common! macro used by all other crypto types (Ed25519PublicKey, BlsPublicKey, etc.).

Changes

  • Replace manual to_hex/from_hex with impl_crypto_common!(Hash, "Hash")
  • Remove duplicate Deserialize impl (now provided by macro)
  • Keep Hash-specific methods (short_hex, ZERO, as_bytes) and custom Debug

Testing

All 103 grey-types tests pass. No behavior changes — pure refactoring.

Hash manually implemented to_hex, from_hex, and Deserialize with
identical logic to the impl_crypto_common! macro used by all other
crypto types. Replace the manual implementations with the shared macro,
keeping only the Hash-specific methods (short_hex, ZERO, as_bytes).

Contributes to jarchain#186.
@github-actions
Copy link
Copy Markdown
Contributor

Genesis Review

Comparison targets:

How to review

Post a comment with the following format (rank from best to worst):

/review
difficulty: <commit1>, <commit2>, ..., <commitN>, currentPR
novelty: <commit1>, <commit2>, ..., <commitN>, currentPR
design: <commit1>, <commit2>, ..., <commitN>, currentPR
verdict: merge

Use the short commit hashes above and currentPR for this PR.
Each line ranks all comparison targets + this PR from best to worst.

To meta-review another reviewer's comment, react with 👍 or 👎.

@sorpaas
Copy link
Copy Markdown
Contributor

sorpaas commented Apr 28, 2026

/review
difficulty: c39a838, f271eba, a1a8ae0, c413978, 385088d, currentPR, b4ce0ef, af6bdf8
novelty: c39a838, f271eba, a1a8ae0, c413978, 385088d, currentPR, b4ce0ef, af6bdf8
design: c39a838, f271eba, a1a8ae0, c413978, currentPR, 385088d, b4ce0ef, af6bdf8
verdict: notMerge

Reuses the existing impl_crypto_common! macro for the Hash type, removing 17 lines of hand-rolled to_hex, from_hex, and Deserialize impls. Verified the macro produces equivalent code (same expect message "invalid hex for Hash" via concat!("invalid hex for ", "Hash"), same Deserialize logic). Modest design win — Hash now follows the same pattern as the other crypto types. Below substantive code work like Merkle proofs (c39a838) or the block-author plumbing (f271eba), comparable to other one-shot dedups (a1a8ae0), above pure hygiene (af6bdf8). Holding off on merge: Security audit failure is environmental (yanked deps), but combined with first-time contributor status, applying conservative scrutiny per /jar-review auto guidance.

@github-actions
Copy link
Copy Markdown
Contributor

JAR Bot: Review recorded from @sorpaas (1 reviews, 0 meta-reviews).
Merge weight: 0/37665 (need >50%).

@sorpaas
Copy link
Copy Markdown
Contributor

sorpaas commented Apr 28, 2026

/review
difficulty: c39a838, f271eba, a1a8ae0, c413978, 385088d, currentPR, b4ce0ef, af6bdf8
novelty: c39a838, f271eba, a1a8ae0, c413978, 385088d, currentPR, b4ce0ef, af6bdf8
design: c39a838, f271eba, a1a8ae0, c413978, currentPR, 385088d, b4ce0ef, af6bdf8
verdict: merge

Updating to merge. Reuses the impl_crypto_common! macro for the Hash type, removing 17 lines of hand-rolled to_hex, from_hex, and Deserialize impls. Verified the macro produces equivalent code: same expect("invalid hex for Hash") message via concat!("invalid hex for ", "Hash"), same Deserialize logic. Hash now follows the same pattern as the other crypto types. No security implications.

@github-actions
Copy link
Copy Markdown
Contributor

JAR Bot: Quorum reached — triggering merge.
Reviews: 1, meta-reviews: 0.
Merge weight: 34219/37665 (>50%).

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.

2 participants