Skip to content
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

chore!: remove deprecated hash functions from stdlib #7477

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
@@ -1,32 +1,19 @@
---
title: Hash methods
description:
Learn about the cryptographic primitives ready to use for any Noir project, including sha256,
blake2s and pedersen
Learn about the cryptographic primitives ready to use for any Noir project
keywords:
[cryptographic primitives, Noir project, sha256, blake2s, pedersen, hash]
sidebar_position: 0
---

import BlackBoxInfo from '@site/src/components/Notes/_blackbox';

## sha256
## sha256 compression

Given an array of bytes, returns the resulting sha256 hash.
Specify a message_size to hash only the first `message_size` bytes of the input.

#include_code sha256 noir_stdlib/src/hash/sha256.nr rust

example:
#include_code sha256_var test_programs/execution_success/sha256/src/main.nr rust

```rust
fn main() {
let x = [163, 117, 178, 149]; // some random bytes
let hash = std::sha256::sha256_var(x, 4);
}
```
Performs a sha256 compression on an input and initial state, returning the resulting state.

#include_code sha256_compression noir_stdlib/src/hash/sha256.nr rust

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

Expand Down Expand Up @@ -88,17 +75,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.

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

example:
Given an initial `[u64; 25]` state, returns the state resulting from applying a keccakf1600 permutation (`[u64; 25]`).

#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.

28 changes: 16 additions & 12 deletions noir_stdlib/src/hash/mod.nr
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
pub mod poseidon;
pub mod poseidon2;
pub mod keccak;
pub mod sha256;
pub mod sha512;

use crate::default::Default;
use crate::embedded_curve_ops::{
EmbeddedCurvePoint, EmbeddedCurveScalar, multi_scalar_mul, multi_scalar_mul_array_return,
};
use crate::meta::derive_via;

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

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

pub mod keccak256 {
#[deprecated("This function has been moved to std::hash::keccakf1600")]
pub fn keccakf1600(input: [u64; 25]) -> [u64; 25] {
super::keccakf1600(input)
}
}

#[foreign(blake2s)]
// docs:start:blake2s
Expand Down Expand Up @@ -113,13 +124,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
Loading