-
Notifications
You must be signed in to change notification settings - Fork 414
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
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)