Skip to content

Commit

Permalink
chore!: remove deprecated hash functions from stdlib
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench committed Feb 20, 2025
1 parent c254c3c commit f9c2b30
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 1,205 deletions.
4 changes: 2 additions & 2 deletions docs/docs/noir/modules_packages_crates/dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ use lib_a;
You can also import only the specific parts of dependency that you want to use, like so:

```rust
use std::hash::sha256;
use std::hash::blake3;
use std::scalar_mul::fixed_base_embedded_curve;
```

Lastly, You can import multiple items in the same line by enclosing them in curly braces:

```rust
use std::hash::{keccak256, sha256};
use std::hash::{blake2s, blake3};
```

We don't have a way to consume libraries from inside a [workspace](./workspaces.md) as external dependencies right now.
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/noir/standard_library/black_box_fns.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Here is a list of the current black box functions:
- AND
- XOR
- RANGE
- [Keccak256](./cryptographic_primitives/hashes.mdx#keccak256)
- [Keccakf1600](./cryptographic_primitives/hashes.mdx#keccakf1600)
- [Recursive proof verification](./recursion.mdx)

Most black box functions are included as part of the Noir standard library, however `AND`, `XOR` and `RANGE` are used as part of the Noir language syntax. For instance, using the bitwise operator `&` will invoke the `AND` black box function.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,11 @@ example:

<BlackBoxInfo to="../black_box_fns"/>

## keccak256
## keccakf1600

Given an array of bytes (`u8`), returns the resulting keccak hash as an array of
32 bytes (`[u8; 32]`). Specify a message_size to hash only the first
`message_size` bytes of the input.
Given an initial `[u64; 25]` state, returns the state resulting from applying a keccakf1600 permutation (`[u64; 25]`).

#include_code keccak256 noir_stdlib/src/hash/mod.nr rust

example:

#include_code keccak256 test_programs/execution_success/keccak256/src/main.nr rust
#include_code keccakf1600 noir_stdlib/src/hash/mod.nr rust

<BlackBoxInfo to="../black_box_fns"/>

Expand Down
155 changes: 0 additions & 155 deletions noir_stdlib/src/hash/keccak.nr

This file was deleted.

22 changes: 11 additions & 11 deletions noir_stdlib/src/hash/mod.nr
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
pub mod poseidon;
pub mod poseidon2;
pub mod keccak;
pub mod sha256;
pub mod sha512;

use crate::default::Default;
use crate::embedded_curve_ops::{
Expand All @@ -11,8 +8,17 @@ use crate::embedded_curve_ops::{
use crate::meta::derive_via;
use crate::uint128::U128;

// Kept for backwards compatibility
pub use sha256::{digest, sha256, sha256_compression, sha256_var};
pub mod sha256 {
#[foreign(sha256_compression)]
pub fn sha256_compression(input: [u32; 16], state: [u32; 8]) -> [u32; 8] {}
}

pub mod keccak256 {
#[foreign(keccakf1600)]
// docs:start:keccakf1600
pub fn keccakf1600(input: [u64; 25]) -> [u64; 25] {}
// docs:end:keccakf1600
}

#[foreign(blake2s)]
// docs:start:blake2s
Expand Down Expand Up @@ -114,12 +120,6 @@ pub fn hash_to_field(inputs: [Field]) -> Field {
sum
}

// docs:start:keccak256
pub fn keccak256<let N: u32>(input: [u8; N], message_size: u32) -> [u8; 32]
// docs:end:keccak256
{
crate::hash::keccak::keccak256(input, message_size)
}

#[foreign(poseidon2_permutation)]
pub fn poseidon2_permutation<let N: u32>(_input: [Field; N], _state_length: u32) -> [Field; N] {}
Expand Down
Loading

0 comments on commit f9c2b30

Please sign in to comment.