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

Refactor - move tree initializer to its own module. #740

Merged
merged 1 commit into from
Jun 5, 2024
Merged
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
408 changes: 20 additions & 388 deletions src/app.rs

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions src/contracts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
pub mod abi;
pub mod scanner;

use std::sync::Arc;

use anyhow::{anyhow, Context};
use ethers::providers::Middleware;
use ethers::types::{H256, U256};
Expand Down Expand Up @@ -470,6 +468,3 @@ impl IdentityManager {
self.deletion_prover_map.read().await.len() > 0
}
}

/// A type for an identity manager object that can be sent across threads.
pub type SharedIdentityManager = Arc<IdentityManager>;
1 change: 1 addition & 0 deletions src/identity/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod validator;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also moved other modules to agreed new structure (mod.rs inside directory).

32 changes: 32 additions & 0 deletions src/identity/validator.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use ruint::uint;
use semaphore::Field;

use crate::identity_tree::Hash;

// See <https://docs.rs/ark-bn254/latest/ark_bn254>
pub const MODULUS: Field =
uint!(21888242871839275222246405745257275088548364400416034343698204186575808495617_U256);

pub struct IdentityValidator {
snark_scalar_field: Hash,
}

// TODO Export the reduced-ness check that this is enabling from the
// `semaphore-rs` library when we bump the version.
impl IdentityValidator {
pub fn new() -> Self {
Self {
snark_scalar_field: Hash::from(MODULUS),
}
}

pub fn identity_is_reduced(&self, commitment: Hash) -> bool {
commitment.lt(&self.snark_scalar_field)
}
}

impl Default for IdentityValidator {
fn default() -> Self {
Self::new()
}
}
Loading
Loading