-
Notifications
You must be signed in to change notification settings - Fork 138
feat: Blake2s implementation #821
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
Open
thiagodeev
wants to merge
10
commits into
main
Choose a base branch
from
thiagodeev/feat/blake2s-hash
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
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
- Implemented Blake2s and Blake2sArray functions for hashing felt.Felt pointers.
…lake hash - Introduced CompiledClassHashV2 for using the Blake2s hash function to generate Compiled Clash Hashes - Make a compiledClassHash function that accepts a hash function as a parameter, and use it for the CompiledClassHash and CompiledClassHashV2 functions.
…aram - Adds a new hashFunc param to make the function work with any hash function specified. - Adjusted return values in hashCasmClassByteCode to return the computed hash instead of a function.
- Introduced the UseBlake2sHash option in TxnOptions to allow selection of the Blake2s hash function for compiled class hash calculation. - Updated BuildDeclareTxn to conditionally use Blake2s or the default hash function based on the new option. - Added unit tests to validate the behavior of BuildDeclareTxn with both hash options.
…hods - Added the shouldUseBlake2sHash function to determine if the Blake2s hash function should be used for compiled class hashes based on the Starknet version. - Updated BuildAndSendDeclareTxn and other transaction methods to utilize the new hash selection logic. - Introduced unit tests for BuildAndSendDeclareTxn to validate behavior with different Starknet versions and their corresponding compiled class hashes.
… selection - Updated TxnOptions to accept a new UseBlake2sHash field, allowing users to specify whether to use the Blake2s hash function for compiled class hash calculation. - Modified the logic to determine the hash function based on the provided options or default to fetching the Starknet version. - Enhanced unit tests to cover various scenarios for hash selection based on Starknet versions and TxnOptions.
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.
From Starknet v0.14.1 onward, the hash function to calculate the compiled class hash will be Blake2s instead of Poseidon.
This PR implements the Blake2s hash function in Starknet.go, and a feature to automatically decide whether to use it or not to calculate the compiled class hash.
Key changes:
UseBlake2sHashparam in theTxnOptionstruct to be used by theBuildAndSendDeclareTxnmethod. It's a pointer to a bool value, so it can be: true, false, or nil. True or false is to determine whether or not to use the blake hash, and if nil (the default value if not manually set by the user), Starknet.go will automatically fetch the current Starknet version and decide whether to use the Blake2s hash function.Blake2sandBlake2sArrayfunctions.getByteCodeSegmentHasher,hashCasmClassEntryPointByType(renamed tohashCasmEntryPoints), andhashCasmClassByteCodefunctions to accept a custom hash function as a parameter, making them able to be used with any provided hash function instead of using thePoseidonArrayfunction hardcoded inside them.CompiledClassHashfunction: it was converted to an internalcompiledClassHashfunction, accepting a custom hash function to be used. Now we have two functions to calculate the compiled class hash:CompiledClassHash, which calls thecompiledClassHashfunction with thePoseidonArrayhash functionCompiledClassHashV2, which calls thecompiledClassHashfunction with theBlake2shash functionUseBlake2sHashparam in theTxnOptionstruct to be used by theBuildDeclareTxnfunction.TODO: