Skip to content

refactor: use the lean-imt crate #8

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

Merged
merged 4 commits into from
May 1, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/target
/zkey
.DS_Store
3 changes: 2 additions & 1 deletion Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ark-ed-on-bn254 = { version = "=0.5.0", default-features = false }
ark-ff = { version = "=0.5.0", default-features = false }

# zk-kit
zk-kit-lean-imt = { git = "https://github.com/brech1/zk-kit.rust", package = "zk-kit-lean-imt", branch = "feat/generic-tree" }
zk-kit-lean-imt = "0.1.0"

# serde
serde = { version = "1", features = ["derive"], optional = true }
Expand All @@ -35,7 +35,7 @@ circom-prover = "=0.1.1"
default = ["serde"]
serde = [
"dep:serde",
"serde_json",
"serde_json",
"zk-kit-lean-imt/serde"
]

Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Error Module

use lean_imt::lean_imt::LeanIMTError;
use thiserror::Error;
use zk_kit_lean_imt::lean_imt::LeanIMTError;

#[derive(Error, Debug, PartialEq, Eq)]
pub enum SemaphoreError {
Expand Down
14 changes: 4 additions & 10 deletions src/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
use crate::error::SemaphoreError;
use ark_ed_on_bn254::Fq;
use ark_ff::{BigInteger, PrimeField};
use lean_imt::hashed_tree::{HashedLeanIMT, LeanIMTHasher};
use light_poseidon::{Poseidon, PoseidonHasher};
use zk_kit_lean_imt::{
hashed_tree::{HashedLeanIMT, LeanIMTHasher},
lean_imt,
};

/// Size of nodes and leaves in bytes
pub const ELEMENT_SIZE: usize = 32;
Expand All @@ -22,7 +19,7 @@ pub const EMPTY_ELEMENT: Element = [0u8; ELEMENT_SIZE];
pub type Element = [u8; ELEMENT_SIZE];

/// Merkle proof alias
pub type MerkleProof = lean_imt::MerkleProof<ELEMENT_SIZE>;
pub type MerkleProof = lean_imt::lean_imt::MerkleProof<ELEMENT_SIZE>;

/// Poseidon LeanIMT hasher
#[derive(Debug, Default, Clone, PartialEq, Eq)]
Expand Down Expand Up @@ -165,15 +162,12 @@ impl Group {

/// Imports a Group from a JSON string representing a LeanIMT tree.
pub fn import(json: &str) -> Result<Self, SemaphoreError> {
let lean_imt_tree: zk_kit_lean_imt::lean_imt::LeanIMT<ELEMENT_SIZE> =
let lean_imt_tree: lean_imt::lean_imt::LeanIMT<ELEMENT_SIZE> =
serde_json::from_str(json)
.map_err(|e| SemaphoreError::SerializationError(e.to_string()))?;

Ok(Group {
tree: zk_kit_lean_imt::hashed_tree::HashedLeanIMT::new_from_tree(
lean_imt_tree,
PoseidonHash,
),
tree: HashedLeanIMT::new_from_tree(lean_imt_tree, PoseidonHash),
})
}
}
Expand Down
Loading