Skip to content

Commit

Permalink
fixed bug with crashing poseidon hashing
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry123 committed Mar 16, 2024
1 parent 5f30c85 commit 9c40c5f
Show file tree
Hide file tree
Showing 18 changed files with 57 additions and 1,355 deletions.
82 changes: 38 additions & 44 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ alloy-primitives = { version = "0.5.4", default-features = false, features = ["r
hashbrown = { version = "0.14.3" }
serde = { version = "1.0.193", default-features = false }
casey = "0.4.0"
halo2curves = { git = "https://github.com/fluentlabs-xyz/halo2curves", branch = "0.3.1-derive-serde" }
halo2curves = { git = "https://github.com/privacy-scaling-explorations/halo2curves", tag = "v0.6.1" }
paste = { version = "1.0", default-features = false }
alloy-rlp = { version = "0.3.4", default-features = false }
revm-interpreter = { git = "https://github.com/bluealloy/revm", tag = "v28", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions crates/poseidon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ keywords.workspace = true
categories.workspace = true

[dependencies]
poseidon = {git = "https://github.com/scroll-tech/poseidon", rev = "0b9965fbcd9e03559088b8f68489592286bc55e0"}
poseidon = { git = "https://github.com/privacy-scaling-explorations/poseidon", tag = "v2024_01_31" }
lazy_static = "1.4.0"
halo2curves = { workspace = true }
halo2curves = { git = "https://github.com/privacy-scaling-explorations/halo2curves", tag = "v0.6.1" }
bitvec = "1"

[dev-dependencies]
69 changes: 0 additions & 69 deletions crates/poseidon/src/hash.rs

This file was deleted.

17 changes: 8 additions & 9 deletions crates/poseidon/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
pub mod hash;
pub use hash::*;
mod primitives;
pub use primitives::*;
mod septidon;
use halo2curves::bn256::Fr;
pub use poseidon::Poseidon;
pub use septidon::*;

pub fn poseidon_hash(data: &[u8]) -> [u8; 32] {
let mut hasher = Poseidon::<Fr, 3, 2>::new(8, 56);
Expand All @@ -20,11 +14,17 @@ pub fn poseidon_hash(data: &[u8]) -> [u8; 32] {
h.to_bytes()
}

pub fn hash_with_domain(arr: &[Fr], domain: &Fr) -> Fr {
let mut hasher = Poseidon::<Fr, 3, 2>::new(8, 56);
hasher.update(arr);
hasher.squeeze()
}

#[cfg(test)]
mod poseidon_tests {
extern crate alloc;

use crate::{poseidon_hash, Hashable};
use crate::{hash_with_domain, poseidon_hash};
use halo2curves::{bn256::Fr, group::ff::PrimeField};

#[test]
Expand Down Expand Up @@ -70,8 +70,7 @@ mod poseidon_tests {
let fb = Fr::from_bytes(&b.try_into().unwrap()).unwrap();
let fdomain = Fr::from_bytes(&domain.try_into().unwrap()).unwrap();

let hasher = Fr::hasher();
let h2 = hasher.hash([fa, fb], fdomain);
let h2 = hash_with_domain(&[fa, fb], &fdomain);
let repr_h2 = h2.to_repr();

let expected_repr = [
Expand Down
Loading

0 comments on commit 9c40c5f

Please sign in to comment.