Skip to content

Truncate hash gadget outputs with component_truncate - #306

Merged
HDauven merged 1 commit into
deps/plonk-0.24from
gadget/component-truncate
Oct 8, 2026
Merged

HDauven merged 1 commit into
deps/plonk-0.24from
gadget/component-truncate

Conversation

@HDauven

@HDauven HDauven commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

Resolves #304

Stacked on #305.

HashGadget::finalize_truncated and HashGadget::digest_truncated now truncate with component_truncate::<250> instead of append_logic_xor::<125>(_, ZERO). The outputs stay the low 250 bits, and each truncated output takes 146 fewer gates:

Gadget append_logic_xor component_truncate
digest_truncated, 1 / 2 / 4 inputs 886 / 887 / 889 740 / 741 / 743
Merkle4 truncated digest 889 743

Plain digests are unchanged (652 / 653 / 655 gates), and the pinned truncated count in hash_gadget_constraint_counts moves from 889 to 743. test_truncated_gadget checks inside a circuit that the gadget output equals the native truncation, and plonk's soundness suite covers component_truncate at this width.

@HDauven HDauven mentioned this pull request Oct 8, 2026
@HDauven
HDauven added this pull request to stack #308 October 8, 2026 11:47
@HDauven
HDauven requested review from Neotamandua, moCello and xevisalle and a balanced review from Copilot October 8, 2026 11:47

Copilot AI 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.

🟢 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 moCello left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@HDauven
HDauven force-pushed the gadget/component-truncate branch from 30f9899 to 499be20 Compare October 8, 2026 13:26
@HDauven

HDauven commented Oct 8, 2026

Copy link
Copy Markdown
Member Author

Force-pushed 499be20, rebased onto the updated #305: the pinned truncated count moves from 889 to 743.

@HDauven
HDauven merged commit 6b4681f into master Oct 8, 2026
8 checks passed
@HDauven
HDauven deleted the gadget/component-truncate branch October 8, 2026 13:29
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.

Truncate hash gadget outputs with component_truncate

3 participants