FEATURE: Allow custom hash functions to Internal library of LazyIMT #58
Open
jimjimvalkema wants to merge 9 commits intozk-kit:mainfrom
Open
FEATURE: Allow custom hash functions to Internal library of LazyIMT #58jimjimvalkema wants to merge 9 commits intozk-kit:mainfrom
jimjimvalkema wants to merge 9 commits intozk-kit:mainfrom
Conversation
initial gas test
internalLazyImt can use different hash functions by passing in a hash function as a parameter to every function that uses the hash function. LazyIMT does this for poseidonT3. BREAKING CHANGE: InternalLazyIMT requires additional inputs. Errors mention hasherLimit instead of SNARK_SCALAR_FIELD
…interfaces folder
7 tasks
…ddress switched to passing hasher as an function instead of an address. This allows for easier and more gas efficient intergration of other hash functions that do not have the same interface as poseidon. Like zemse poseidon2Huff or sha256 and keccak.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
I changed the InternalLazyIMT library so the user can provide their own hash function as an function parameter. And also their own default zeros.
I have setup the
LazyIMT.sollibrary so it uses the poseidon hash function so everything behaves as usual.changes made
InternalLazyIMT.IHasher(hasher).hash([left,right])(this also saves gas)._hasher, _defaultZero, SNARK_SCALER_LIMTas added arguments to functions that need them.HASHER_ADDRESSaddress as a constant, _defaultZero and _hasher function, and set the hasherLimit to the snark field limithere is a snipet:
in
InternalLazyIMTThen this is used as follows in
LazyIMTtest changes
I changed the deploy-imt-test task to deploy poseidon with the deterministic proxy so it always deploys to the same address. See in the poseidon-solidity readme
Breaking changes
I changed error that mention
SNARK_SCALAR_LIMITto instead sayhasherLimit, since the hash function is now generic. This might break error handling for users that expect the old error.LazyIMT now uses the create2 address of poseidonT3 directly, so users using a chain where it isn't deployed yet (or hardhat tests), will need to deploy it them selfs now.
If an user used the Internal version of the libraries for some reason. Then they do have now pass these new parameters like
_hasher,_defaultZerosandhasherLimit.Related Issue(s)
Closes #56
Other information
Calling poseidon with a interface saves from 10k - 100k gas for most functions. But making the libraries generic does add 0~100 gas on average.

In total expect a gas saving of 10k gas on average!
Checklist
yarn stylewithout getting any errorsImportant
We do not accept pull requests for minor grammatical fixes (e.g., correcting typos, rewording sentences) or for fixing broken links, unless they significantly improve clarity or functionality. These contributions, while appreciated, are not a priority for merging. If you notice any of these issues, please create a GitHub Issue to report them so they can be properly tracked and addressed.