Skip to content

fix: MerkleDamgardHasher IV#701

Merged
ThomasPiellard merged 4 commits intomasterfrom
fix/merkledamgard-iv
Jun 24, 2025
Merged

fix: MerkleDamgardHasher IV#701
ThomasPiellard merged 4 commits intomasterfrom
fix/merkledamgard-iv

Conversation

@Tabaie
Copy link
Copy Markdown
Contributor

@Tabaie Tabaie commented Jun 24, 2025

Fixes an incorrect IV initialization that would make the hash fail after a Reset.

@Tabaie Tabaie requested a review from Copilot June 24, 2025 19:16
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a bug in the MerkleDamgardHasher where the IV was incorrectly re‐used on a reset, which could cause the hash to fail after a reset. The changes update the Reset method (using a safe clone of the IV), refactor state initialization via cloneLeftPadded, and add additional tests across multiple curve implementations to validate the fix.

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

File Description
internal/generator/crypto/hash/poseidon2/template/poseidon2.test.go.tmpl Added new tests and imports to validate the MerkleDamgardHasher functionality
hash/merkle-damgard.go Updated Reset and SetState to clone the IV and refactored padding logic via cloneLeftPadded
ecc/*/fr/poseidon2/poseidon2_test.go Added new tests (TestHashSmall and TestHashReset) across various ECC curves to verify correct hashing behavior
Comments suppressed due to low confidence (1)

hash/merkle-damgard.go:96

  • Consider adding unit tests to verify the error handling in cloneLeftPadded when the input buffer length exceeds the expected size.
	if len(b) > n {

@Tabaie Tabaie requested a review from ThomasPiellard June 24, 2025 19:23
@ThomasPiellard ThomasPiellard merged commit 2a5e15b into master Jun 24, 2025
6 checks passed
@ThomasPiellard ThomasPiellard deleted the fix/merkledamgard-iv branch June 24, 2025 20:07
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.

3 participants