Repository navigation
Truncate hash gadget outputs with component_truncate - #306
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The focused substitution preserves documented semantics and is covered by the existing circuit-to-native equivalence test.
0 open findings
What changed in this PR
Replaces the hash gadget’s bitwise truncation with dusk-plonk’s lower-cost truncation component while preserving the low 250-bit output.
Changes:
- Use
component_truncate::<250>for truncated gadget outputs. - Document the gate-count optimization in the changelog.
| File | Description |
|---|---|
src/hash/gadget.rs |
Uses the dedicated truncation component. |
CHANGELOG.md |
Records the optimization and issue reference. |
🧠 Review effort: Balanced
Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.
moCello
left a comment
There was a problem hiding this comment.
APPROVE — The new truncation constrains the same low 250 bits that the native Hash::finalize_truncated mask keeps, and test_truncated_gadget compares the two inside a circuit.
30f9899 to
499be20
Compare
|
Force-pushed |
Resolves #304
Stacked on #305.
HashGadget::finalize_truncatedandHashGadget::digest_truncatednow truncate withcomponent_truncate::<250>instead ofappend_logic_xor::<125>(_, ZERO). The outputs stay the low 250 bits, and each truncated output takes 146 fewer gates:append_logic_xorcomponent_truncatedigest_truncated, 1 / 2 / 4 inputsMerkle4truncated digestPlain digests are unchanged (652 / 653 / 655 gates), and the pinned truncated count in
hash_gadget_constraint_countsmoves from 889 to 743.test_truncated_gadgetchecks inside a circuit that the gadget output equals the native truncation, and plonk's soundness suite coverscomponent_truncateat this width.