FEATURE: Allow custom hash functions to Internal libraries of: IMT#60
Draft
jimjimvalkema wants to merge 19 commits intozk-kit:mainfrom
Draft
FEATURE: Allow custom hash functions to Internal libraries of: IMT#60jimjimvalkema wants to merge 19 commits intozk-kit:mainfrom
jimjimvalkema wants to merge 19 commits intozk-kit:mainfrom
Conversation
internalBinaryIMT can use different hash functions by passing in a hash function as a parameter to every function that uses the hash function. BinaryIMT does this for poseidonT3.
renamed _hash to hasher for a more consistent naming
renamed _hash to hasher
InternalQuinaryIMT can use different hash functions by passing in a hash function as a parameter to
…er field checks SNARK_SCALAR_FIELD checks to outside of the internal library to allow non snark based
…se the hasher was pure fixed non solidity hash functions not being by making the hash function view instead of pure. This allows use cases where the developer needs to call a contract with .staticcall() directly to do a hash
initial measuremnt gas so we can see what changes after each commit
…ction InternalBinaryIMT can now be used with different hash functions given that the hash functions contract has the expected interface BREAKING CHANGE: InternalBinaryIMTs functions now needs additional parameters
quinary IMT can now be used with different hash functions given that the hash functions contract has the expected interface BREAKING CHANGE: InternalQuinaryIMTs functions now require additional parameters
Removed poseidon from the quinary and BinaryIMT and made the deploy:imt-test task deploy poseidon through nicks methond instead of a linked library BREAKING CHANGE: gas reports no longer include poseidon hashes
…ent hash functions moved to a new approach using an address to support different hash functions
…terThanHasherLimit renamed ValueGreaterThanSnarkScalarField to ValueGreaterThanHasherLimit since not every hash function is snark based BREAKING CHANGE: breaks error handeling that expects ValueGreaterThanSnarkScalarField
7 tasks
switched to passing a hasher as a function for better flexibility. This did add some gas 500~2k for inserts. I made the switch mainly so using native hash functions like keccak dont need a extra contract.
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 internal library of IMT so the user can provide their own hash function with an address that implements their hash function with the interface that is the same as PoseidonT3(T6 for QuinaryIMT). And also their own default zeros for IMT.
I made the libraries that use the internal libraries use the poseidon so they behave like usual.
changes made
InternalBinaryIMT.IHasher(hasher).hash([left,right])(this also saves gas).hasher, _defaultZero, SNARK_SCALER_LIMTas added arguments to functions that need them.hasheraddress as a constant, add _defaultZero, and set the hasherLimithere is a snipet:
in
InternalBinaryIMTThen this is used as follows in
BinaryIMTtest 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.If an user used the Internal version of the libraries for some reason. Then they do have now pass these new parameters like
hasher,hasherLimitand_defaultZeros.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.
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.