Skip to content

Commit 5ad130f

Browse files
committed
chore: update usage of poseidon
1 parent 289f236 commit 5ad130f

File tree

32 files changed

+24
-272
lines changed

32 files changed

+24
-272
lines changed

docs/docs/noir/standard_library/containers/hashmap.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Example:
1616
```rust
1717
// Create a mapping from Fields to u32s with a maximum length of 12
1818
// using a poseidon2 hasher
19-
use std::hash::poseidon2::Poseidon2Hasher;
19+
use poseidon::poseidon2::Poseidon2Hasher;
2020
let mut map: HashMap<Field, u32, 12, BuildHasherDefault<Poseidon2Hasher>> = HashMap::default();
2121

2222
map.insert(1, 2);

docs/docs/noir/standard_library/cryptographic_primitives/hashes.mdx

-29
Original file line numberDiff line numberDiff line change
@@ -83,35 +83,6 @@ Given an initial `[u64; 25]` state, returns the state resulting from applying a
8383

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

86-
## poseidon
87-
88-
Given an array of Fields, returns a new Field with the Poseidon Hash. Mind that you need to specify
89-
how many inputs are there to your Poseidon function.
90-
91-
```rust
92-
// example for hash_1, hash_2 accepts an array of length 2, etc
93-
fn hash_1(input: [Field; 1]) -> Field
94-
```
95-
96-
example:
97-
98-
#include_code poseidon test_programs/execution_success/poseidon_bn254_hash/src/main.nr rust
99-
100-
## poseidon 2
101-
102-
Given an array of Fields, returns a new Field with the Poseidon2 Hash. Contrary to the Poseidon
103-
function, there is only one hash and you can specify a message_size to hash only the first
104-
`message_size` bytes of the input,
105-
106-
```rust
107-
// example for hashing the first three elements of the input
108-
Poseidon2::hash(input, 3);
109-
```
110-
111-
example:
112-
113-
#include_code poseidon2 test_programs/execution_success/poseidon2/src/main.nr rust
114-
11586
## hash_to_field
11687

11788
```rust

test_programs/benchmarks/bench_eddsa_poseidon/Nargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ authors = [""]
66

77
[dependencies]
88
ec = { tag = "v0.1.2", git = "https://github.com/noir-lang/ec" }
9+
poseidon = { tag = "v0.1.0", git = "https://github.com/noir-lang/poseidon" }

test_programs/benchmarks/bench_eddsa_poseidon/src/main.nr

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1+
use poseidon::poseidon::PoseidonHasher;
12
use std::default::Default;
23
use std::hash::Hasher;
3-
use std::hash::poseidon::PoseidonHasher;
44

55
use ec::consts::te::baby_jubjub;
66
use ec::tecurve::affine::Point as TEPoint;
77

8-
98
fn main(
109
msg: pub Field,
1110
pub_key_x: Field,

test_programs/benchmarks/bench_poseidon2_hash/Nargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ type = "bin"
55
authors = [""]
66

77
[dependencies]
8+
poseidon = { tag = "v0.1.0", git = "https://github.com/noir-lang/poseidon" }
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::hash::poseidon2;
2-
31
fn main(input: [Field; 2]) -> pub Field {
4-
poseidon2::Poseidon2::hash(input, input.len())
2+
poseidon::poseidon2::Poseidon2::hash(input, input.len())
53
}

test_programs/benchmarks/bench_poseidon2_hash_100/Nargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ type = "bin"
55
authors = [""]
66

77
[dependencies]
8+
poseidon = { tag = "v0.1.0", git = "https://github.com/noir-lang/poseidon" }

test_programs/benchmarks/bench_poseidon2_hash_100/src/main.nr

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
use std::hash::poseidon2;
2-
31
global SIZE: u32 = 100;
42

53
fn main(input: [[Field; 2]; SIZE]) -> pub [Field; SIZE] {
64
let mut results: [Field; SIZE] = [0; SIZE];
75
for i in 0..SIZE {
8-
results[i] = poseidon2::Poseidon2::hash(input[i], 2);
6+
results[i] = poseidon::poseidon2::Poseidon2::hash(input[i], 2);
97
}
108

119
results

test_programs/benchmarks/bench_poseidon2_hash_30/Nargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ type = "bin"
55
authors = [""]
66

77
[dependencies]
8+
poseidon = { tag = "v0.1.0", git = "https://github.com/noir-lang/poseidon" }

test_programs/benchmarks/bench_poseidon2_hash_30/src/main.nr

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
use std::hash::poseidon2;
2-
31
global SIZE: u32 = 30;
42

53
fn main(input: [[Field; 2]; SIZE]) -> pub [Field; SIZE] {
64
let mut results: [Field; SIZE] = [0; SIZE];
75
for i in 0..SIZE {
8-
results[i] = poseidon2::Poseidon2::hash(input[i], 2);
6+
results[i] = poseidon::poseidon2::Poseidon2::hash(input[i], 2);
97
}
108

119
results

test_programs/benchmarks/bench_poseidon_hash/Nargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ type = "bin"
55
authors = [""]
66

77
[dependencies]
8+
poseidon = { tag = "v0.1.0", git = "https://github.com/noir-lang/poseidon" }

test_programs/benchmarks/bench_poseidon_hash/bench_poseidon_hash_100/Nargo.toml

-7
This file was deleted.

test_programs/benchmarks/bench_poseidon_hash/bench_poseidon_hash_100/Prover.toml

-102
This file was deleted.

test_programs/benchmarks/bench_poseidon_hash/bench_poseidon_hash_100/src/main.nr

-12
This file was deleted.

test_programs/benchmarks/bench_poseidon_hash/bench_poseidon_hash_30/Nargo.toml

-7
This file was deleted.

test_programs/benchmarks/bench_poseidon_hash/bench_poseidon_hash_30/Prover.toml

-32
This file was deleted.

test_programs/benchmarks/bench_poseidon_hash/bench_poseidon_hash_30/src/main.nr

-12
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::hash::poseidon;
2-
31
fn main(input: [Field; 2]) -> pub Field {
4-
poseidon::bn254::hash_2(input)
2+
poseidon::poseidon::bn254::hash_2(input)
53
}

test_programs/benchmarks/bench_poseidon_hash_100/Nargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ type = "bin"
55
authors = [""]
66

77
[dependencies]
8+
poseidon = { tag = "v0.1.0", git = "https://github.com/noir-lang/poseidon" }

test_programs/benchmarks/bench_poseidon_hash_100/src/main.nr

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
use std::hash;
2-
31
global SIZE: u32 = 100;
42

53
fn main(input: [[Field; 2]; SIZE]) -> pub [Field; SIZE] {
64
let mut results: [Field; SIZE] = [0; SIZE];
75
for i in 0..SIZE {
8-
results[i] = hash::poseidon::bn254::hash_2(input[i]);
6+
results[i] = poseidon::poseidon::bn254::hash_2(input[i]);
97
}
108

119
results

test_programs/benchmarks/bench_poseidon_hash_30/Nargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ type = "bin"
55
authors = [""]
66

77
[dependencies]
8+
poseidon = { tag = "v0.1.0", git = "https://github.com/noir-lang/poseidon" }

test_programs/benchmarks/bench_poseidon_hash_30/src/main.nr

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
use std::hash;
2-
31
global SIZE: u32 = 30;
42

53
fn main(input: [[Field; 2]; SIZE]) -> pub [Field; SIZE] {
64
let mut results: [Field; SIZE] = [0; SIZE];
75
for i in 0..SIZE {
8-
results[i] = hash::poseidon::bn254::hash_2(input[i]);
6+
results[i] = poseidon::poseidon::bn254::hash_2(input[i]);
97
}
108

119
results

test_programs/execution_failure/hashmap_load_factor/Nargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ name = "hashmap_load_factor"
33
type = "bin"
44
authors = [""]
55

6-
[dependencies]
6+
[dependencies]
7+
poseidon = { tag = "v0.1.0", git = "https://github.com/noir-lang/poseidon" }

test_programs/execution_failure/hashmap_load_factor/src/main.nr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
use std::collections::map::HashMap;
22
use std::hash::BuildHasherDefault;
3-
use std::hash::poseidon2::Poseidon2Hasher;
3+
use poseidon::poseidon2::Poseidon2Hasher;
44

55
struct Entry{
66
key: Field,
77
value: Field
88
}
99

10-
global HASHMAP_CAP = 8;
11-
global HASHMAP_LEN = 6;
10+
global HASHMAP_CAP: u32 = 8;
11+
global HASHMAP_LEN: u32 = 6;
1212

1313
fn allocate_hashmap() -> HashMap<Field, Field, HASHMAP_CAP, BuildHasherDefault<Poseidon2Hasher>> {
1414
HashMap::default()

test_programs/execution_success/fold_2_to_17/Nargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ type = "bin"
44
authors = [""]
55
compiler_version = ">=0.25.0"
66

7-
[dependencies]
7+
[dependencies]
8+
poseidon = { tag = "v0.1.0", git = "https://github.com/noir-lang/poseidon" }
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
use std::hash::poseidon2;
2-
31
global len: u32 = 2450 * 2 - 240; // for just under 2^17 gates
42
fn main(x: Field) {
53
let ped_input = [x; len];
6-
let mut val = poseidon2::Poseidon2::hash(ped_input, len);
4+
let mut val = poseidon::poseidon2::Poseidon2::hash(ped_input, len);
75
let z = foo(x);
86
assert(val == z);
97
}
108

119
#[fold]
1210
fn foo(x: Field) -> Field {
1311
let ped_input = [x; len];
14-
let mut val = poseidon2::Poseidon2::hash(ped_input, len);
12+
let mut val = poseidon::poseidon2::Poseidon2::hash(ped_input, len);
1513
val
1614
}

test_programs/execution_success/poseidon2/Nargo.toml

-6
This file was deleted.

0 commit comments

Comments
 (0)