Skip to content

Implement new hashing #7259

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

Merged
merged 20 commits into from
Jul 11, 2025
Merged

Implement new hashing #7259

merged 20 commits into from
Jul 11, 2025

Conversation

ironcev
Copy link
Member

@ironcev ironcev commented Jun 27, 2025

Description

This PR implements new hashing, as explained in the tracking issue #7256. New hashing is an opt-in experimental feature with the feature flag new_hashing.

The new hashing hashes lengths as prefix to the content hash for the following built-in and std types:

  • string slices (str)
  • arrays ([T; N])
  • std::vec::Vec<T>
  • std::bytes::Bytes

Additionally, the PR adds missing Hash implementations, "old", without lengths, and new for:

  • string arrays (str[N])
  • raw slices (raw_slice)

Some of the std types that use the above types internally for storing their content still hash only the content, without the length prefix of the container. The reason for this is that:

  1. the choice of the container is just an implementation detail, and
  2. the semantics of the type requires only the content (mostly of the fixed, type-specific length) to be hashed.

A typical example would be std::b512::B512 where, same to b256 we want to hash only the content.

Notice that this does not cause the security issue described in #7256.

Here is the complete list of those types:

  • std::crypto::secp256k1::Secp256k1
  • std::crypto::secp256r1::Secp256r1
  • std::crypto::message::Message
  • std::crypto::public_key::PublicKey
  • std::b512::B512

Some of the implementations differ based on the combination of const_generics and new_hashing features. Therefore, on CI, we have a step testing both experimental features together.

Additionally, the PR:

  • adds testing of const_generics experimental feature to CI.

Checklist

  • I have linked to any relevant issues.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation where relevant (API docs, the reference, and the Sway book).
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added (or requested a maintainer to add) the necessary Breaking* or New Feature labels where relevant.
  • I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • I have requested a review from the relevant team or maintainers.

@ironcev ironcev self-assigned this Jun 27, 2025
@ironcev ironcev added lib: std Standard library breaking May cause existing user code to break. Requires a minor or major release. labels Jun 27, 2025
@ironcev ironcev temporarily deployed to fuel-sway-bot June 27, 2025 14:28 — with GitHub Actions Inactive
@ironcev ironcev temporarily deployed to fuel-sway-bot June 27, 2025 16:57 — with GitHub Actions Inactive
@ironcev ironcev temporarily deployed to fuel-sway-bot June 28, 2025 14:08 — with GitHub Actions Inactive
@ironcev ironcev temporarily deployed to fuel-sway-bot June 28, 2025 14:18 — with GitHub Actions Inactive
@ironcev ironcev temporarily deployed to fuel-sway-bot June 28, 2025 14:26 — with GitHub Actions Inactive
@ironcev ironcev marked this pull request as ready for review June 28, 2025 14:51
@ironcev ironcev requested review from a team as code owners June 28, 2025 14:51
@ironcev ironcev enabled auto-merge (squash) June 28, 2025 14:51
@ironcev ironcev requested review from bitzoic and a team June 28, 2025 14:51
@ironcev ironcev temporarily deployed to fuel-sway-bot June 30, 2025 12:31 — with GitHub Actions Inactive
@ironcev ironcev temporarily deployed to fuel-sway-bot June 30, 2025 14:31 — with GitHub Actions Inactive
@ironcev ironcev temporarily deployed to fuel-sway-bot June 30, 2025 16:26 — with GitHub Actions Inactive
@ironcev ironcev temporarily deployed to fuel-sway-bot July 1, 2025 09:57 — with GitHub Actions Inactive
@ironcev ironcev temporarily deployed to fuel-sway-bot July 2, 2025 11:43 — with GitHub Actions Inactive
@ironcev ironcev temporarily deployed to fuel-sway-bot July 4, 2025 09:55 — with GitHub Actions Inactive
IGI-111
IGI-111 previously approved these changes Jul 4, 2025
@IGI-111 IGI-111 requested a review from a team July 4, 2025 14:59
@IGI-111 IGI-111 temporarily deployed to fuel-sway-bot July 7, 2025 10:35 — with GitHub Actions Inactive
@ironcev ironcev temporarily deployed to fuel-sway-bot July 9, 2025 06:45 — with GitHub Actions Inactive
@IGI-111 IGI-111 requested a review from a team July 10, 2025 15:53
Copy link
Contributor

@zees-dev zees-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice; LGTM 👍

@ironcev ironcev merged commit 8d4178f into master Jul 11, 2025
39 checks passed
@ironcev ironcev deleted the ironcev/new-hashing branch July 11, 2025 02:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking May cause existing user code to break. Requires a minor or major release. lib: std Standard library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants