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

feat: add poseidon-halo2 crate #633

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ members = [
"crates/components/block-cipher",
"crates/components/hmac-sha256",
"crates/components/hmac-sha256-circuits",
"crates/components/poseidon-halo2",
"crates/components/key-exchange",
"crates/components/stream-cipher",
"crates/components/universal-hash",
Expand Down Expand Up @@ -43,6 +44,7 @@ opt-level = 1
[workspace.dependencies]
notary-client = { path = "crates/notary/client" }
notary-server = { path = "crates/notary/server" }
poseidon-halo2 = { path = "crates/components/poseidon-halo2" }
tls-server-fixture = { path = "crates/tls/server-fixture" }
tlsn-aead = { path = "crates/components/aead" }
tlsn-benches-browser-core = { path = "crates/benches/browser/core" }
Expand Down
17 changes: 17 additions & 0 deletions crates/components/poseidon-halo2/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "poseidon-halo2"
authors = ["TLSNotary Team"]
description = "An experimental implementation of Poseidon based on PSE's poseidon-gadget"
categories = ["cryptography"]
license = "MIT OR Apache-2.0"
version = "0.1.0"
edition = "2021"

[lib]
name = "poseidon_halo2"

[dependencies]
ff = "0.13"
group = "0.13"
themighty1 marked this conversation as resolved.
Show resolved Hide resolved
halo2_poseidon = { git = "https://github.com/privacy-scaling-explorations/poseidon-gadget", rev="764a682"}
themighty1 marked this conversation as resolved.
Show resolved Hide resolved
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2", tag = "v0.3.0", default-features = false}
themighty1 marked this conversation as resolved.
Show resolved Hide resolved
32 changes: 32 additions & 0 deletions crates/components/poseidon-halo2/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//! An experimental Poseidon hash implementation over the BN256 curve with custom parameters.
//!
//! This crate is only meant to be used for experimental purposes. The parameters were not checked
//! to be secure.

mod rate15_params;
mod rate1_params;
mod rate2_params;
mod spec;

use halo2_poseidon::poseidon::primitives::{ConstantLength, Hash};
use halo2_proofs::halo2curves::bn256;

pub use halo2_proofs::halo2curves::bn256::Fr as F;
pub use spec::{Spec1, Spec15, Spec2};

/// Hashes the provided input field elements and returns the digest.
///
/// # Panics
///
/// Panics if the provided input's length is not 15, 2, or 1 field elements.
pub fn hash(input: &[bn256::Fr]) -> bn256::Fr {
match input.len() {
15 => Hash::<bn256::Fr, spec::Spec15, ConstantLength<15>, 16, 15>::init()
themighty1 marked this conversation as resolved.
Show resolved Hide resolved
.hash(input.try_into().unwrap()),
2 => Hash::<bn256::Fr, spec::Spec2, ConstantLength<2>, 3, 2>::init()
.hash(input.try_into().unwrap()),
1 => Hash::<bn256::Fr, spec::Spec1, ConstantLength<1>, 2, 1>::init()
.hash(input.try_into().unwrap()),
_ => unimplemented!(),

Check warning on line 30 in crates/components/poseidon-halo2/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/components/poseidon-halo2/src/lib.rs#L22-L30

Added lines #L22 - L30 were not covered by tests
}
}

Check warning on line 32 in crates/components/poseidon-halo2/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/components/poseidon-halo2/src/lib.rs#L32

Added line #L32 was not covered by tests
Loading
Loading