Skip to content

Conversation

@thiagodeev
Copy link
Collaborator

@thiagodeev thiagodeev commented Nov 7, 2025

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:

  • account pkg:
    • new UseBlake2sHash param in the TxnOption struct to be used by the BuildAndSendDeclareTxn method. 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.
  • curve pkg:
    • new Blake2s and Blake2sArray functions.
  • hash pkg:
    • a refactor in the internal getByteCodeSegmentHasher, hashCasmClassEntryPointByType (renamed to hashCasmEntryPoints), and hashCasmClassByteCode functions to accept a custom hash function as a parameter, making them able to be used with any provided hash function instead of using the PoseidonArray function hardcoded inside them.
    • a refactor in the CompiledClassHash function: it was converted to an internal compiledClassHash function, accepting a custom hash function to be used. Now we have two functions to calculate the compiled class hash:
      • CompiledClassHash, which calls the compiledClassHash function with the PoseidonArray hash function
      • CompiledClassHashV2, which calls the compiledClassHash function with the Blake2s hash function
  • utils pkg:
    • new UseBlake2sHash param in the TxnOption struct to be used by the BuildDeclareTxn function.

TODO:

  • change the Juno imported version once we have the next release
  • update changelog

…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.
@thiagodeev thiagodeev marked this pull request as ready for review November 14, 2025 13:46
@thiagodeev thiagodeev changed the title Thiagodeev/feat/blake2s-hash feat: Blake2s implementation Nov 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants