Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: merkle damgard and poseidon2 #1407

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open

feat: merkle damgard and poseidon2 #1407

wants to merge 13 commits into from

Conversation

Tabaie
Copy link
Contributor

@Tabaie Tabaie commented Jan 31, 2025

Companion to Consensys/gnark-crypto#623
This PR introduces a generic Merkle Damgard construction and uses it to instantiate Poseidon2 as a full hash function.
(Parameters only for BLS12-377)

@Tabaie Tabaie requested review from gbotrel and removed request for gbotrel February 5, 2025 16:39
@Tabaie Tabaie marked this pull request as draft February 5, 2025 16:52
@Tabaie Tabaie marked this pull request as ready for review February 11, 2025 15:22
Copy link
Collaborator

@ivokub ivokub left a comment

Choose a reason for hiding this comment

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

I refactored a bit so that it would align with gnark-crypto (method names, documentation, referring to default parameters from gnark-crypto etc.).

Otherwise, looks good. I'm not so sure about the test utility for single function circuits.

if err != nil {
return nil, fmt.Errorf("could not create poseidon2 hasher: %w", err)
}
return hash.NewMerkleDamgardHasher(api, f, 0), nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is IV=0 temporary or it indeed doesn't have preimage?

}

// SingleFunction returns a test function that can run a simple circuit consisting of function f, and match its output with outs
func SingleFunction(curve ecc.ID, f func(frontend.API) []frontend.Variable, outs ...frontend.Variable) func(*testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it is a cool idea, but currently imo it is still not ready. I have several issues with the implementation currently:

  • you already have TODO that the registry is not thread safe. If adding a new feature then I would avoid adding implementation debt.
  • this utility function prevents self-documenting tests. I'm referring (myself and also if anyone asks in dicusssions or through communication) quite a lot to test circuits to see how to implement. But this abstraction makes the tests a bit more confusing as would have to refer to the snarkFunctionTestCircuit definition and the provided function.
  • it only uses IsSolved, but this tests only against test engine. It is good, but still not perfect and there have been cases where the actual solver/prover etc. differs from the test engine. And it also prevents running Solidity tests easily etc.

I would remove it and define the circuit directly in the std/hash/poseidon2/poseidon2_test.go file, it is only a few lines of code.

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