From 36013bf4bad9a73643c4e7140fda2fed51f8fc8b Mon Sep 17 00:00:00 2001 From: Sydhds Date: Thu, 5 Jun 2025 10:32:43 +0200 Subject: [PATCH] Remove not explicit use statement (#317) --- rln/Cargo.toml | 2 +- rln/src/pm_tree_adapter.rs | 2 +- rln/src/poseidon_tree.rs | 25 ++++++++++++++++--------- rln/src/protocol.rs | 7 +++++-- rln/src/public.rs | 31 +++++++++++++++++++++---------- rln/src/public_api_tests.rs | 7 +++++-- rln/tests/ffi.rs | 2 +- rln/tests/poseidon_tree.rs | 5 ++++- rln/tests/protocol.rs | 7 ++++++- rln/tests/public.rs | 5 ++++- utils/src/merkle_tree/mod.rs | 8 +++++--- utils/src/poseidon/mod.rs | 3 +-- 12 files changed, 70 insertions(+), 34 deletions(-) diff --git a/rln/Cargo.toml b/rln/Cargo.toml index 247d124..7880931 100644 --- a/rln/Cargo.toml +++ b/rln/Cargo.toml @@ -67,7 +67,7 @@ criterion = { version = "0.6.0", features = ["html_reports"] } [features] default = ["pmtree-ft"] -fullmerkletree = ["default"] +fullmerkletree = [] stateless = [] arkzkey = [] diff --git a/rln/src/pm_tree_adapter.rs b/rln/src/pm_tree_adapter.rs index b7aa4f5..2b8fc28 100644 --- a/rln/src/pm_tree_adapter.rs +++ b/rln/src/pm_tree_adapter.rs @@ -9,7 +9,7 @@ use crate::utils::{bytes_le_to_fr, fr_to_bytes_le}; use utils::error::{FromConfigError, ZerokitMerkleTreeError}; use utils::pmtree::tree::Key; use utils::pmtree::{Database, Hasher, PmtreeErrorKind}; -use utils::*; +use utils::{pmtree, Config, Mode, SledDB, ZerokitMerkleProof, ZerokitMerkleTree}; const METADATA_KEY: [u8; 8] = *b"metadata"; diff --git a/rln/src/poseidon_tree.rs b/rln/src/poseidon_tree.rs index e86e4a5..4b9a652 100644 --- a/rln/src/poseidon_tree.rs +++ b/rln/src/poseidon_tree.rs @@ -4,26 +4,33 @@ use cfg_if::cfg_if; -cfg_if! { - if #[cfg(feature = "pmtree-ft")] { - use crate::pm_tree_adapter::*; - } else { - use crate::hashers::{PoseidonHash}; - use utils::merkle_tree::*; - } -} - // The zerokit RLN default Merkle tree implementation is the OptimalMerkleTree. // To switch to FullMerkleTree implementation, it is enough to enable the fullmerkletree feature cfg_if! { if #[cfg(feature = "fullmerkletree")] { + + use utils::{ + FullMerkleTree, + FullMerkleProof, + }; + use crate::hashers::PoseidonHash; + pub type PoseidonTree = FullMerkleTree; pub type MerkleProof = FullMerkleProof; } else if #[cfg(feature = "pmtree-ft")] { + use crate::pm_tree_adapter::{PmTree, PmTreeProof}; + pub type PoseidonTree = PmTree; pub type MerkleProof = PmTreeProof; } else { + + use crate::hashers::{PoseidonHash}; + use utils::{ + OptimalMerkleTree, + OptimalMerkleProof, + }; + pub type PoseidonTree = OptimalMerkleTree; pub type MerkleProof = OptimalMerkleProof; } diff --git a/rln/src/protocol.rs b/rln/src/protocol.rs index 2beaf13..98e594b 100644 --- a/rln/src/protocol.rs +++ b/rln/src/protocol.rs @@ -17,9 +17,12 @@ use tiny_keccak::{Hasher as _, Keccak}; use crate::circuit::{calculate_rln_witness, qap::CircomReduction, Curve}; use crate::error::{ComputeIdSecretError, ConversionError, ProofError, ProtocolError}; use crate::hashers::{hash_to_field, poseidon_hash}; -use crate::poseidon_tree::*; +use crate::poseidon_tree::{MerkleProof, PoseidonTree}; use crate::public::RLN_IDENTIFIER; -use crate::utils::*; +use crate::utils::{ + bytes_le_to_fr, bytes_le_to_vec_fr, bytes_le_to_vec_u8, fr_byte_size, fr_to_bytes_le, + normalize_usize, to_bigint, vec_fr_to_bytes_le, vec_u8_to_bytes_le, +}; use utils::{ZerokitMerkleProof, ZerokitMerkleTree}; /////////////////////////////////////////////////////// // RLN Witness data structure and utility functions diff --git a/rln/src/public.rs b/rln/src/public.rs index 0b82545..fcaaf6f 100644 --- a/rln/src/public.rs +++ b/rln/src/public.rs @@ -1,3 +1,24 @@ +use crate::circuit::{zkey_from_raw, Curve, Fr}; +use crate::hashers::{hash_to_field, poseidon_hash as utils_poseidon_hash}; +use crate::protocol::{ + compute_id_secret, deserialize_proof_values, deserialize_witness, extended_keygen, + extended_seeded_keygen, generate_proof, keygen, proof_inputs_to_rln_witness, + proof_values_from_witness, rln_witness_to_bigint_json, rln_witness_to_json, seeded_keygen, + serialize_proof_values, serialize_witness, verify_proof, +}; +use crate::utils::{ + bytes_le_to_fr, bytes_le_to_vec_fr, bytes_le_to_vec_u8, fr_byte_size, fr_to_bytes_le, + vec_fr_to_bytes_le, vec_u8_to_bytes_le, +}; +#[cfg(not(target_arch = "wasm32"))] +use { + crate::circuit::{graph_from_folder, zkey_from_folder}, + std::default::Default, +}; + +#[cfg(target_arch = "wasm32")] +use crate::protocol::generate_proof_with_witness; + /// This is the main public API for RLN module. It is used by the FFI, and should be /// used by tests etc. as well #[cfg(not(feature = "stateless"))] @@ -8,16 +29,6 @@ use { utils::{Hasher, ZerokitMerkleProof, ZerokitMerkleTree}, }; -use crate::circuit::{zkey_from_raw, Curve, Fr}; -use crate::hashers::{hash_to_field, poseidon_hash as utils_poseidon_hash}; -use crate::protocol::*; -use crate::utils::*; -#[cfg(not(target_arch = "wasm32"))] -use { - crate::circuit::{graph_from_folder, zkey_from_folder}, - std::default::Default, -}; - use crate::error::{ConversionError, ProtocolError, RLNError}; use ark_groth16::{Proof as ArkProof, ProvingKey, VerifyingKey}; use ark_relations::r1cs::ConstraintMatrices; diff --git a/rln/src/public_api_tests.rs b/rln/src/public_api_tests.rs index 44d7bf1..f19e794 100644 --- a/rln/src/public_api_tests.rs +++ b/rln/src/public_api_tests.rs @@ -1,7 +1,10 @@ use crate::circuit::TEST_TREE_HEIGHT; -use crate::protocol::*; +use crate::protocol::{ + proof_values_from_witness, random_rln_witness, serialize_proof_values, serialize_witness, + verify_proof, RLNProofValues, +}; use crate::public::RLN; -use crate::utils::*; +use crate::utils::{generate_input_buffer, str_to_fr}; use ark_groth16::Proof as ArkProof; use ark_serialize::CanonicalDeserialize; use std::io::Cursor; diff --git a/rln/tests/ffi.rs b/rln/tests/ffi.rs index aff4fed..e697ab4 100644 --- a/rln/tests/ffi.rs +++ b/rln/tests/ffi.rs @@ -3,7 +3,7 @@ mod test { use ark_std::{rand::thread_rng, UniformRand}; use rand::Rng; - use rln::circuit::*; + use rln::circuit::{Fr, TEST_TREE_HEIGHT}; use rln::ffi::{hash as ffi_hash, poseidon_hash as ffi_poseidon_hash, *}; use rln::hashers::{hash_to_field, poseidon_hash as utils_poseidon_hash, ROUND_PARAMS}; use rln::protocol::*; diff --git a/rln/tests/poseidon_tree.rs b/rln/tests/poseidon_tree.rs index 08bf612..7bd7203 100644 --- a/rln/tests/poseidon_tree.rs +++ b/rln/tests/poseidon_tree.rs @@ -5,7 +5,10 @@ #[cfg(test)] mod test { use rln::hashers::{poseidon_hash, PoseidonHash}; - use rln::{circuit::*, poseidon_tree::PoseidonTree}; + use rln::{ + circuit::{Fr, TEST_TREE_HEIGHT}, + poseidon_tree::PoseidonTree, + }; use utils::{FullMerkleTree, OptimalMerkleTree, ZerokitMerkleProof, ZerokitMerkleTree}; #[test] diff --git a/rln/tests/protocol.rs b/rln/tests/protocol.rs index 3e58b78..96001cb 100644 --- a/rln/tests/protocol.rs +++ b/rln/tests/protocol.rs @@ -5,7 +5,12 @@ mod test { use rln::circuit::{Fr, TEST_TREE_HEIGHT}; use rln::hashers::{hash_to_field, poseidon_hash}; use rln::poseidon_tree::PoseidonTree; - use rln::protocol::*; + use rln::protocol::{ + deserialize_proof_values, deserialize_witness, generate_proof, keygen, + proof_values_from_witness, rln_witness_from_json, rln_witness_from_values, + rln_witness_to_json, seeded_keygen, serialize_proof_values, serialize_witness, + verify_proof, RLNWitnessInput, + }; use rln::utils::str_to_fr; use utils::{ZerokitMerkleProof, ZerokitMerkleTree}; diff --git a/rln/tests/public.rs b/rln/tests/public.rs index d6acd64..ae52d21 100644 --- a/rln/tests/public.rs +++ b/rln/tests/public.rs @@ -12,7 +12,10 @@ mod test { use rln::hashers::{hash_to_field, poseidon_hash as utils_poseidon_hash, ROUND_PARAMS}; use rln::protocol::deserialize_identity_tuple; use rln::public::{hash as public_hash, poseidon_hash as public_poseidon_hash, RLN}; - use rln::utils::*; + use rln::utils::{ + bytes_le_to_fr, bytes_le_to_vec_fr, bytes_le_to_vec_u8, bytes_le_to_vec_usize, + fr_to_bytes_le, generate_input_buffer, str_to_fr, vec_fr_to_bytes_le, + }; use std::io::Cursor; #[test] diff --git a/utils/src/merkle_tree/mod.rs b/utils/src/merkle_tree/mod.rs index 60d40f3..776e64c 100644 --- a/utils/src/merkle_tree/mod.rs +++ b/utils/src/merkle_tree/mod.rs @@ -4,6 +4,8 @@ pub mod full_merkle_tree; pub mod merkle_tree; pub mod optimal_merkle_tree; -pub use self::full_merkle_tree::*; -pub use self::merkle_tree::*; -pub use self::optimal_merkle_tree::*; +pub use self::full_merkle_tree::{FullMerkleConfig, FullMerkleProof, FullMerkleTree}; +pub use self::merkle_tree::{ + FrOf, Hasher, ZerokitMerkleProof, ZerokitMerkleTree, MIN_PARALLEL_NODES, +}; +pub use self::optimal_merkle_tree::{OptimalMerkleConfig, OptimalMerkleProof, OptimalMerkleTree}; diff --git a/utils/src/poseidon/mod.rs b/utils/src/poseidon/mod.rs index d37721b..7fe211d 100644 --- a/utils/src/poseidon/mod.rs +++ b/utils/src/poseidon/mod.rs @@ -1,5 +1,4 @@ pub mod poseidon_hash; -pub use self::poseidon_hash::*; +pub use poseidon_hash::Poseidon; pub mod poseidon_constants; -pub use self::poseidon_constants::*;