Skip to content

Commit

Permalink
feat!: remove mimc from stdlib (#6402)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench authored Oct 31, 2024
1 parent 94a37bb commit ec03e77
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 206 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
title: Hash methods
description:
Learn about the cryptographic primitives ready to use for any Noir project, including sha256,
blake2s, pedersen, mimc_bn254 and mimc
blake2s and pedersen
keywords:
[cryptographic primitives, Noir project, sha256, blake2s, pedersen, mimc_bn254, mimc, hash]
[cryptographic primitives, Noir project, sha256, blake2s, pedersen, hash]
sidebar_position: 0
---

Expand Down Expand Up @@ -131,32 +131,6 @@ example:

#include_code poseidon2 test_programs/execution_success/poseidon2/src/main.nr rust

## mimc_bn254 and mimc

`mimc_bn254` is `mimc`, but with hardcoded parameters for the BN254 curve. You can use it by
providing an array of Fields, and it returns a Field with the hash. You can use the `mimc` method if
you're willing to input your own constants:

```rust
fn mimc<N>(x: Field, k: Field, constants: [Field; N], exp : Field) -> Field
```

otherwise, use the `mimc_bn254` method:

```rust
fn mimc_bn254<let N: u32>(array: [Field; N]) -> Field
```

example:

```rust

fn main() {
let x = [163, 117, 178, 149]; // some random bytes
let hash = std::hash::mimc::mimc_bn254(x);
}
```

## hash_to_field

```rust
Expand Down
158 changes: 0 additions & 158 deletions noir_stdlib/src/hash/mimc.nr

This file was deleted.

1 change: 0 additions & 1 deletion noir_stdlib/src/hash/mod.nr
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pub mod poseidon;
pub mod mimc;
pub mod poseidon2;
pub mod keccak;
pub mod sha256;
Expand Down
6 changes: 0 additions & 6 deletions test_programs/execution_success/6/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,9 @@
// bytes.
//
// If you do not cast, it will take all the bytes from the field element!
// Mimc input is an array of field elements
// The function is called mimc_bn254 to emphasize its parameters are chosen for bn254 curve, it should be used only with a proving system using the same curve (e.g Plonk from Aztec)
fn main(x: [u8; 5], result: pub [u8; 32]) {
let mut digest = std::hash::sha256(x);
digest[0] = 5 as u8;
digest = std::hash::sha256(x);
assert(digest == result);

let y = [12, 45, 78, 41];
let h = std::hash::mimc::mimc_bn254(y);
assert(h == 18226366069841799622585958305961373004333097209608110160936134895615261821931);
}
1 change: 0 additions & 1 deletion test_programs/execution_success/merkle_insert/Prover.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ old_hash_path = [
new_root = "0x25e2a8ee5b85e5b546ae27832b9b53f5fae5b371e3e7f8cddda839f41669fc68"
leaf = "0x23fe6c8f2426b793f0f156f57efbecbea52e951af761634a85e80cc1a9fb5003"
index = "0"
mimc_input = [12, 45, 78, 41]
8 changes: 0 additions & 8 deletions test_programs/execution_success/merkle_insert/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
use std::hash::mimc;

fn main(
old_root: Field,
old_leaf: Field,
old_hash_path: [Field; 3],
new_root: pub Field,
leaf: Field,
index: Field,
mimc_input: [Field; 4],
) {
assert(old_root == std::merkle::compute_merkle_root(old_leaf, index, old_hash_path));

let calculated_root = std::merkle::compute_merkle_root(leaf, index, old_hash_path);
assert(new_root == calculated_root);

let h = mimc::mimc_bn254(mimc_input);
// Regression test for PR #891
std::println(h);
assert(h == 18226366069841799622585958305961373004333097209608110160936134895615261821931);
}
6 changes: 2 additions & 4 deletions test_programs/execution_success/regression_5252/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::hash::{mimc, poseidon, poseidon2::Poseidon2};
use std::hash::{poseidon, poseidon2::Poseidon2};

global NUM_HASHES = 3;
global HASH_LENGTH = 20;
Expand All @@ -16,9 +16,7 @@ fn main(
let enable = enable[i];
let to_hash = to_hash[i];
if enable {
result[i] = poseidon_hash(to_hash)
+ poseidon::bn254::sponge(to_hash)
+ mimc::mimc_bn254(to_hash);
result[i] = poseidon_hash(to_hash) + poseidon::bn254::sponge(to_hash);
}
}
result
Expand Down

0 comments on commit ec03e77

Please sign in to comment.