Skip to content

Commit

Permalink
chore: add test and benchmarks for poseidon2 (#5386)
Browse files Browse the repository at this point in the history
# Description

## Problem\*

Resolves <!-- Link to GitHub Issue -->

## Summary\*

This PR adds benchmarks for poseidon2

## Additional Context



## Documentation\*

Check one:
- [ ] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[For Experimental Features]** Documentation to be submitted in a
separate PR.

# PR Checklist\*

- [ ] I have tested the changes locally.
- [ ] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
  • Loading branch information
TomAFrench authored Jul 5, 2024
1 parent df73fe2 commit 44abe7f
Show file tree
Hide file tree
Showing 21 changed files with 380 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ function, there is only one hash and you can specify a message_size to hash only
Poseidon2::hash(input, 3);
```

The above example for Poseidon also includes Poseidon2.
example:

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

## mimc_bn254 and mimc

Expand Down
7 changes: 7 additions & 0 deletions test_programs/benchmarks/bench_poseidon2_hash/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "bench_poseidon2_hash"
version = "0.1.0"
type = "bin"
authors = [""]

[dependencies]
1 change: 1 addition & 0 deletions test_programs/benchmarks/bench_poseidon2_hash/Prover.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
input = [1,2]
5 changes: 5 additions & 0 deletions test_programs/benchmarks/bench_poseidon2_hash/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use std::hash::poseidon2;

fn main(input: [Field; 2]) -> pub Field {
poseidon2::Poseidon2::hash(input, input.len())
}
7 changes: 7 additions & 0 deletions test_programs/benchmarks/bench_poseidon2_hash_100/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "bench_poseidon2_hash_100"
version = "0.1.0"
type = "bin"
authors = [""]

[dependencies]
102 changes: 102 additions & 0 deletions test_programs/benchmarks/bench_poseidon2_hash_100/Prover.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
input = [
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
]
12 changes: 12 additions & 0 deletions test_programs/benchmarks/bench_poseidon2_hash_100/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use std::hash::poseidon2;

global SIZE = 100;

fn main(input: [[Field; 2]; SIZE]) -> pub [Field; SIZE] {
let mut results: [Field; SIZE] = [0; SIZE];
for i in 0..SIZE {
results[i] = poseidon2::Poseidon2::hash(input[i], 2);
}

results
}
7 changes: 7 additions & 0 deletions test_programs/benchmarks/bench_poseidon2_hash_30/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "bench_poseidon2_hash_30"
version = "0.1.0"
type = "bin"
authors = [""]

[dependencies]
32 changes: 32 additions & 0 deletions test_programs/benchmarks/bench_poseidon2_hash_30/Prover.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
input = [
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
]
12 changes: 12 additions & 0 deletions test_programs/benchmarks/bench_poseidon2_hash_30/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use std::hash::poseidon2;

global SIZE = 30;

fn main(input: [[Field; 2]; SIZE]) -> pub [Field; SIZE] {
let mut results: [Field; SIZE] = [0; SIZE];
for i in 0..SIZE {
results[i] = poseidon2::Poseidon2::hash(input[i], 2);
}

results
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "bench_poseidon_hash_100"
version = "0.1.0"
type = "bin"
authors = [""]

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
input = [
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use std::hash;

global SIZE = 100;

fn main(input: [[Field; 2]; SIZE]) -> pub [Field; SIZE] {
let mut results: [Field; SIZE] = [0; SIZE];
for i in 0..SIZE {
results[i] = hash::poseidon::bn254::hash_2(input[i]);
}

results
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "bench_poseidon_hash_30"
version = "0.1.0"
type = "bin"
authors = [""]

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
input = [
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use std::hash;

global SIZE = 30;

fn main(input: [[Field; 2]; SIZE]) -> pub [Field; SIZE] {
let mut results: [Field; SIZE] = [0; SIZE];
for i in 0..SIZE {
results[i] = hash::poseidon::bn254::hash_2(input[i]);
}

results
}
6 changes: 6 additions & 0 deletions test_programs/execution_success/poseidon2/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "poseidon2"
type = "bin"
authors = [""]

[dependencies]
5 changes: 5 additions & 0 deletions test_programs/execution_success/poseidon2/Prover.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
inputs = ["4218458030232820015255714794613421442512497197372123294583664908262453897094",
"4218458030232820015255714794613421442512497197372123294583664908262453897094",
"4218458030232820015255714794613421442512497197372123294583664908262453897094",
"4218458030232820015255714794613421442512497197372123294583664908262453897094"]
expected_hash = "0x2f43a0f83b51a6f5fc839dea0ecec74947637802a579fa9841930a25a0bcec11"
Loading

0 comments on commit 44abe7f

Please sign in to comment.