Organize imports (#188)

* Organize imports

Use rustfmt to organize imports.  Resolve #162

* remove unused imports

* cargo fmt
This commit is contained in:
Eduard S. 2025-04-07 16:19:13 -07:00 committed by GitHub
parent 1214cdfa1b
commit 24ff82dd3d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
32 changed files with 329 additions and 276 deletions

View file

@ -2,24 +2,37 @@
//! `backend_plonky2` feature is enabled.
//! See src/middleware/basetypes.rs for more details.
use crate::middleware::serialization::{
deserialize_hash_tuple, deserialize_value_tuple, serialize_hash_tuple, serialize_value_tuple,
use std::{
cmp::{Ord, Ordering},
fmt,
};
use crate::middleware::{Params, ToFields};
use anyhow::{anyhow, Error, Result};
use hex::{FromHex, FromHexError};
use plonky2::field::goldilocks_field::GoldilocksField;
use plonky2::field::types::{Field, PrimeField64};
use plonky2::hash::poseidon::PoseidonHash;
use plonky2::plonk::config::Hasher;
use plonky2::plonk::config::PoseidonGoldilocksConfig;
use plonky2::plonk::proof::Proof as Plonky2Proof;
use plonky2::{
field::{
goldilocks_field::GoldilocksField,
types::{Field, PrimeField64},
},
hash::poseidon::PoseidonHash,
plonk::{
config::{Hasher, PoseidonGoldilocksConfig},
proof::Proof as Plonky2Proof,
},
};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::cmp::{Ord, Ordering};
use std::fmt;
use crate::backends::counter;
use crate::{
backends::counter,
middleware::{
serialization::{
deserialize_hash_tuple, deserialize_value_tuple, serialize_hash_tuple,
serialize_value_tuple,
},
Params, ToFields,
},
};
/// F is the native field we use everywhere. Currently it's Goldilocks from plonky2
pub type F = GoldilocksField;

View file

@ -1,23 +1,34 @@
//! Common functionality to build Pod circuits with plonky2
use crate::backends::plonky2::basetypes::D;
use crate::backends::plonky2::mock::mainpod::Statement;
use crate::backends::plonky2::mock::mainpod::{Operation, OperationArg};
use crate::backends::plonky2::primitives::merkletree::MerkleClaimAndProofTarget;
use crate::middleware::{
NativeOperation, NativePredicate, Params, Predicate, StatementArg, ToFields, Value,
EMPTY_VALUE, F, HASH_SIZE, OPERATION_ARG_F_LEN, OPERATION_AUX_F_LEN, STATEMENT_ARG_F_LEN,
VALUE_SIZE,
};
use anyhow::Result;
use plonky2::field::extension::Extendable;
use plonky2::field::types::{Field, PrimeField64};
use plonky2::hash::hash_types::{HashOutTarget, RichField, NUM_HASH_OUT_ELTS};
use plonky2::iop::target::{BoolTarget, Target};
use plonky2::iop::witness::{PartialWitness, WitnessWrite};
use plonky2::plonk::circuit_builder::CircuitBuilder;
use std::{array, iter};
use anyhow::Result;
use plonky2::{
field::{
extension::Extendable,
types::{Field, PrimeField64},
},
hash::hash_types::{HashOutTarget, RichField, NUM_HASH_OUT_ELTS},
iop::{
target::{BoolTarget, Target},
witness::{PartialWitness, WitnessWrite},
},
plonk::circuit_builder::CircuitBuilder,
};
use crate::{
backends::plonky2::{
basetypes::D,
mock::mainpod::{Operation, OperationArg, Statement},
primitives::merkletree::MerkleClaimAndProofTarget,
},
middleware::{
NativeOperation, NativePredicate, Params, Predicate, StatementArg, ToFields, Value,
EMPTY_VALUE, F, HASH_SIZE, OPERATION_ARG_F_LEN, OPERATION_AUX_F_LEN, STATEMENT_ARG_F_LEN,
VALUE_SIZE,
},
};
pub const CODE_SIZE: usize = HASH_SIZE + 2;
#[derive(Copy, Clone)]

View file

@ -1,4 +1,4 @@
use anyhow::{anyhow, Result};
use anyhow::Result;
use itertools::zip_eq;
use plonky2::{
hash::{hash_types::HashOutTarget, poseidon::PoseidonHash},
@ -6,28 +6,27 @@ use plonky2::{
plonk::circuit_builder::CircuitBuilder,
};
use crate::backends::plonky2::mock::mainpod;
use crate::backends::plonky2::signedpod::SignedPod;
use crate::backends::plonky2::{
basetypes::{Value, D, EMPTY_HASH, F, VALUE_SIZE},
mock::mainpod::MerkleClaimAndProof,
primitives::merkletree::{MerkleClaimAndProofTarget, MerkleProofGadget},
};
use crate::middleware::{
hash_str, AnchoredKey, NativeOperation, NativePredicate, Params, PodType, Statement,
StatementArg, ToFields, KEY_TYPE, SELF,
};
use crate::{
backends::plonky2::{
circuits::common::{CircuitBuilderPod, OperationTarget, StatementTarget, ValueTarget},
primitives::merkletree,
basetypes::{Value, D, EMPTY_HASH, F, VALUE_SIZE},
circuits::{
common::{
CircuitBuilderPod, Flattenable, MerkleClaimTarget, OperationTarget,
StatementTarget, ValueTarget,
},
signedpod::{SignedPodVerifyGadget, SignedPodVerifyTarget},
},
mock::{mainpod, mainpod::MerkleClaimAndProof},
primitives::{
merkletree,
merkletree::{MerkleClaimAndProofTarget, MerkleProofGadget},
},
signedpod::SignedPod,
},
middleware::{
hash_str, AnchoredKey, NativeOperation, NativePredicate, Params, PodType, Statement,
StatementArg, ToFields, KEY_TYPE, SELF,
},
middleware,
};
use super::{
common::{Flattenable, MerkleClaimTarget},
signedpod::{SignedPodVerifyGadget, SignedPodVerifyTarget},
};
//
@ -555,12 +554,16 @@ mod tests {
use plonky2::plonk::{circuit_builder::CircuitBuilder, circuit_data::CircuitConfig};
use super::*;
use crate::backends::plonky2::mock::mainpod;
use crate::backends::plonky2::{
basetypes::C,
mock::mainpod::{OperationArg, OperationAux},
use crate::{
backends::plonky2::{
basetypes::C,
mock::{
mainpod,
mainpod::{OperationArg, OperationAux},
},
},
middleware::{OperationType, PodId},
};
use crate::middleware::{OperationType, PodId};
fn operation_verify(
st: mainpod::Statement,

View file

@ -1,24 +1,29 @@
use std::iter;
use anyhow::Result;
use itertools::Itertools;
use plonky2::{
hash::hash_types::{HashOut, HashOutTarget},
iop::target::Target,
iop::witness::{PartialWitness, WitnessWrite},
iop::{
target::Target,
witness::{PartialWitness, WitnessWrite},
},
plonk::circuit_builder::CircuitBuilder,
};
use std::iter;
use crate::backends::plonky2::{
basetypes::{Value, D, EMPTY_VALUE, F},
circuits::common::{CircuitBuilderPod, StatementArgTarget, StatementTarget, ValueTarget},
primitives::{
merkletree::{MerkleProof, MerkleProofExistenceGadget, MerkleProofExistenceTarget},
signature::{PublicKey, SignatureVerifyGadget, SignatureVerifyTarget},
use crate::{
backends::plonky2::{
basetypes::{Value, D, EMPTY_VALUE, F},
circuits::common::{CircuitBuilderPod, StatementArgTarget, StatementTarget, ValueTarget},
primitives::{
merkletree::{MerkleProof, MerkleProofExistenceGadget, MerkleProofExistenceTarget},
signature::{PublicKey, SignatureVerifyGadget, SignatureVerifyTarget},
},
signedpod::SignedPod,
},
middleware::{
hash_str, NativePredicate, Params, PodType, Predicate, ToFields, KEY_SIGNER, KEY_TYPE, SELF,
},
signedpod::SignedPod,
};
use crate::middleware::{
hash_str, NativePredicate, Params, PodType, Predicate, ToFields, KEY_SIGNER, KEY_TYPE, SELF,
};
pub struct SignedPodVerifyGadget {
@ -188,16 +193,18 @@ pub mod tests {
use plonky2::plonk::{circuit_builder::CircuitBuilder, circuit_data::CircuitConfig};
use super::*;
use crate::backends::plonky2::{
basetypes::C,
primitives::signature::SecretKey,
signedpod::{SignedPod, Signer},
use crate::{
backends::plonky2::{
basetypes::C,
primitives::signature::SecretKey,
signedpod::{SignedPod, Signer},
},
middleware::F,
};
use crate::middleware::F;
#[test]
fn test_signed_pod_verify() -> Result<()> {
let mut params = Params {
let params = Params {
max_signed_pod_values: 6,
..Default::default()
};

View file

@ -1,29 +1,26 @@
use crate::backends::plonky2::basetypes::C;
use anyhow::{anyhow, Result};
use base64::prelude::*;
use itertools::Itertools;
use log::error;
use plonky2::hash::poseidon::PoseidonHash;
use plonky2::iop::witness::PartialWitness;
use plonky2::plonk::config::Hasher;
use plonky2::plonk::proof::ProofWithPublicInputs;
use plonky2::plonk::{circuit_builder::CircuitBuilder, circuit_data::CircuitConfig};
use serde::{Deserialize, Serialize};
use std::any::Any;
use std::fmt;
use crate::backends::plonky2::basetypes::{Hash, Value, D, EMPTY_HASH, EMPTY_VALUE, F, VALUE_SIZE};
use crate::backends::plonky2::circuits::mainpod::{MainPodVerifyCircuit, MainPodVerifyInput};
use crate::backends::plonky2::signedpod::SignedPod;
// TODO: Move the shared components between MockMainPod and MainPod to a common place.
use crate::backends::plonky2::mock::mainpod::{hash_statements, MockMainPod, Operation, Statement};
use crate::middleware::{
self, hash_str, AnchoredKey, MainPodInputs, NativeOperation, NativePredicate, NonePod,
OperationType, Params, Pod, PodId, PodProver, Predicate, StatementArg, ToFields, KEY_TYPE,
SELF,
use anyhow::{anyhow, Result};
use itertools::Itertools;
use plonky2::{
iop::witness::PartialWitness,
plonk::{
circuit_builder::CircuitBuilder, circuit_data::CircuitConfig, proof::ProofWithPublicInputs,
},
};
use super::mock::mainpod::MerkleClaimAndProof;
use crate::{
backends::plonky2::{
basetypes::{C, D, F},
circuits::mainpod::{MainPodVerifyCircuit, MainPodVerifyInput},
mock::mainpod::{hash_statements, MockMainPod, Statement},
signedpod::SignedPod,
},
middleware::{
self, AnchoredKey, MainPodInputs, Params, Pod, PodId, PodProver, StatementArg, SELF,
},
};
// TODO: Move the shared components between MockMainPod and MainPod to a common place.
pub struct Prover {}
@ -163,13 +160,15 @@ impl Pod for MainPod {
#[cfg(test)]
pub mod tests {
use super::*;
use crate::backends::plonky2::mock::mainpod::{MockProver, OperationAux};
use crate::backends::plonky2::primitives::signature::SecretKey;
use crate::backends::plonky2::signedpod::Signer;
use crate::examples::zu_kyc_sign_pod_builders;
use crate::frontend;
use crate::middleware;
use crate::op;
use crate::{
backends::plonky2::{
mock::mainpod::MockProver, primitives::signature::SecretKey, signedpod::Signer,
},
examples::zu_kyc_sign_pod_builders,
frontend, middleware,
middleware::Value,
op,
};
// TODO: Use the method from examples once everything works
pub fn zu_kyc_pod_builder(

View file

@ -1,12 +1,10 @@
use std::{any::Any, fmt};
use anyhow::{anyhow, Result};
use base64::prelude::*;
use itertools::Itertools;
use log::error;
use plonky2::hash::poseidon::PoseidonHash;
use plonky2::plonk::config::Hasher;
use plonky2::{hash::poseidon::PoseidonHash, plonk::config::Hasher};
use serde::{Deserialize, Serialize};
use std::any::Any;
use std::fmt;
use crate::{
backends::plonky2::primitives::merkletree,
@ -608,13 +606,14 @@ impl Pod for MockMainPod {
#[cfg(test)]
pub mod tests {
use super::*;
use crate::backends::plonky2::mock::signedpod::MockSigner;
use crate::examples::{
great_boy_pod_full_flow, tickets_pod_full_flow, zu_kyc_pod_builder,
zu_kyc_sign_pod_builders,
use crate::{
backends::plonky2::mock::signedpod::MockSigner,
examples::{
great_boy_pod_full_flow, tickets_pod_full_flow, zu_kyc_pod_builder,
zu_kyc_sign_pod_builders,
},
middleware,
};
use crate::middleware;
use crate::middleware::containers::Set;
#[test]
fn test_mock_main_zu_kyc() -> Result<()> {

View file

@ -1,12 +1,16 @@
use super::Statement;
use std::{fmt, iter};
use anyhow::{anyhow, Result};
use plonky2::field::types::Field;
use serde::{Deserialize, Serialize};
use crate::{
backends::plonky2::primitives::merkletree::{self, kv_hash},
backends::plonky2::{
mock::mainpod::Statement,
primitives::merkletree::{self},
},
middleware::{self, Hash, OperationType, Params, ToFields, Value, EMPTY_HASH, EMPTY_VALUE, F},
};
use anyhow::{anyhow, Result};
use plonky2::field::types::{Field, PrimeField64};
use serde::{Deserialize, Serialize};
use std::{fmt, iter};
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum OperationArg {

View file

@ -1,6 +1,7 @@
use std::fmt;
use anyhow::{anyhow, Result};
use serde::{Deserialize, Serialize};
use std::fmt;
use crate::middleware::{
self, AnchoredKey, NativePredicate, Params, Predicate, StatementArg, ToFields,

View file

@ -1,13 +1,15 @@
use std::{any::Any, collections::HashMap};
use anyhow::{anyhow, Result};
use itertools::Itertools;
use std::any::Any;
use std::collections::HashMap;
use crate::backends::plonky2::primitives::merkletree::MerkleTree;
use crate::constants::MAX_DEPTH;
use crate::middleware::{
containers::Dictionary, hash_str, AnchoredKey, Hash, Params, Pod, PodId, PodSigner, PodType,
Statement, Value, KEY_SIGNER, KEY_TYPE,
use crate::{
backends::plonky2::primitives::merkletree::MerkleTree,
constants::MAX_DEPTH,
middleware::{
containers::Dictionary, hash_str, AnchoredKey, Hash, Params, Pod, PodId, PodSigner,
PodType, Statement, Value, KEY_SIGNER, KEY_TYPE,
},
};
pub struct MockSigner {
@ -129,13 +131,16 @@ impl Pod for MockSignedPod {
#[cfg(test)]
pub mod tests {
use plonky2::field::types::Field;
use std::iter;
use plonky2::field::types::Field;
use super::*;
use crate::constants::MAX_DEPTH;
use crate::frontend;
use crate::middleware::{self, EMPTY_HASH, F};
use crate::{
constants::MAX_DEPTH,
frontend,
middleware::{self, EMPTY_HASH, F},
};
#[test]
fn test_mock_signed_0() -> Result<()> {

View file

@ -1,16 +1,16 @@
//! Module that implements the MerkleTree specified at
//! https://0xparc.github.io/pod2/merkletree.html .
use std::{collections::HashMap, fmt, iter::IntoIterator};
use anyhow::{anyhow, Result};
use plonky2::field::types::Field;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::fmt;
use std::iter::IntoIterator;
use crate::backends::counter;
use crate::backends::plonky2::basetypes::{hash_fields, Hash, Value, EMPTY_HASH, F};
pub use super::merkletree_circuit::*;
use crate::backends::{
counter,
plonky2::basetypes::{hash_fields, Hash, Value, EMPTY_HASH, F},
};
/// Implements the MerkleTree specified at
/// https://0xparc.github.io/pod2/merkletree.html
@ -582,9 +582,10 @@ impl<'a> Iterator for Iter<'a> {
#[cfg(test)]
pub mod tests {
use itertools::Itertools;
use std::cmp::Ordering;
use itertools::Itertools;
use super::*;
#[test]

View file

@ -8,6 +8,8 @@
//! If only proofs of existence are needed, use `MerkleProofExistenceCircuit`,
//! which requires less amount of constraints than `MerkleProofCircuit`.
//!
use std::iter;
use anyhow::Result;
use plonky2::{
field::types::Field,
@ -21,11 +23,12 @@ use plonky2::{
},
plonk::circuit_builder::CircuitBuilder,
};
use std::iter;
use crate::backends::plonky2::basetypes::{Hash, Value, D, EMPTY_HASH, EMPTY_VALUE, F, HASH_SIZE};
use crate::backends::plonky2::circuits::common::{CircuitBuilderPod, ValueTarget};
use crate::backends::plonky2::primitives::merkletree::MerkleProof;
use crate::backends::plonky2::{
basetypes::{Hash, Value, D, EMPTY_HASH, EMPTY_VALUE, F, HASH_SIZE},
circuits::common::{CircuitBuilderPod, ValueTarget},
primitives::merkletree::MerkleProof,
};
/// `MerkleProofGadget` allows to verify both proofs of existence and proofs
/// non-existence with the same circuit.
@ -396,13 +399,15 @@ fn kv_hash_target(
#[cfg(test)]
pub mod tests {
use plonky2::plonk::{circuit_builder::CircuitBuilder, circuit_data::CircuitConfig};
use std::collections::HashMap;
use plonky2::plonk::{circuit_builder::CircuitBuilder, circuit_data::CircuitConfig};
use super::*;
use crate::backends::plonky2::basetypes::hash_value;
use crate::backends::plonky2::basetypes::C;
use crate::backends::plonky2::primitives::merkletree::*;
use crate::backends::plonky2::{
basetypes::{hash_value, C},
primitives::merkletree::*,
};
#[test]
fn test_keypath() -> Result<()> {

View file

@ -20,9 +20,8 @@ use plonky2::{
},
};
use crate::backends::plonky2::basetypes::{Proof, Value, C, D, F, VALUE_SIZE};
pub use super::signature_circuit::*;
use crate::backends::plonky2::basetypes::{Proof, Value, C, D, F, VALUE_SIZE};
lazy_static! {
/// Signature prover parameters
@ -201,9 +200,8 @@ impl SignatureInternalCircuit {
#[cfg(test)]
pub mod tests {
use crate::backends::plonky2::basetypes::Hash;
use super::*;
use crate::backends::plonky2::basetypes::Hash;
#[test]
fn test_signature() -> Result<()> {

View file

@ -11,19 +11,24 @@ use plonky2::{
target::{BoolTarget, Target},
witness::{PartialWitness, WitnessWrite},
},
plonk::circuit_builder::CircuitBuilder,
plonk::circuit_data::{
CircuitConfig, CircuitData, ProverCircuitData, VerifierCircuitData, VerifierCircuitTarget,
plonk::{
circuit_builder::CircuitBuilder,
circuit_data::{
CircuitConfig, CircuitData, ProverCircuitData, VerifierCircuitData,
VerifierCircuitTarget,
},
config::Hasher,
proof::{ProofWithPublicInputs, ProofWithPublicInputsTarget},
},
plonk::config::Hasher,
plonk::proof::{ProofWithPublicInputs, ProofWithPublicInputsTarget},
};
use super::signature::{PublicKey, SecretKey, Signature, DUMMY_PUBLIC_INPUTS, DUMMY_SIGNATURE};
use crate::backends::plonky2::basetypes::{
Hash, Proof, Value, C, D, EMPTY_HASH, EMPTY_VALUE, F, VALUE_SIZE,
use crate::backends::plonky2::{
basetypes::{Hash, Proof, Value, C, D, EMPTY_HASH, EMPTY_VALUE, F, VALUE_SIZE},
circuits::common::{CircuitBuilderPod, ValueTarget},
primitives::signature::{
PublicKey, SecretKey, Signature, DUMMY_PUBLIC_INPUTS, DUMMY_SIGNATURE,
},
};
use crate::backends::plonky2::circuits::common::{CircuitBuilderPod, ValueTarget};
lazy_static! {
/// SignatureVerifyGadget VerifierCircuitData
@ -164,10 +169,8 @@ impl SignatureVerifyTarget {
#[cfg(test)]
pub mod tests {
use crate::backends::plonky2::basetypes::Hash;
use crate::backends::plonky2::primitives::signature::SecretKey;
use super::*;
use crate::backends::plonky2::{basetypes::Hash, primitives::signature::SecretKey};
#[test]
fn test_signature_gadget() -> Result<()> {

View file

@ -1,17 +1,20 @@
use std::{any::Any, collections::HashMap};
use anyhow::{anyhow, Result};
use itertools::Itertools;
use std::any::Any;
use std::collections::HashMap;
use super::primitives::merkletree::MerkleTree;
use crate::constants::MAX_DEPTH;
use crate::middleware::{
containers::Dictionary, hash_str, AnchoredKey, Hash, Params, Pod, PodId, PodSigner, PodType,
Statement, Value, KEY_SIGNER, KEY_TYPE,
use crate::{
backends::plonky2::primitives::{
merkletree::MerkleTree,
signature::{PublicKey, SecretKey, Signature},
},
constants::MAX_DEPTH,
middleware::{
containers::Dictionary, hash_str, AnchoredKey, Hash, Params, Pod, PodId, PodSigner,
PodType, Statement, Value, KEY_SIGNER, KEY_TYPE,
},
};
use super::primitives::signature::{PublicKey, SecretKey, Signature};
pub struct Signer(pub SecretKey);
impl PodSigner for Signer {
@ -111,13 +114,16 @@ impl Pod for SignedPod {
#[cfg(test)]
pub mod tests {
use plonky2::field::types::Field;
use std::iter;
use plonky2::field::types::Field;
use super::*;
use crate::constants::MAX_DEPTH;
use crate::frontend;
use crate::middleware::{self, EMPTY_HASH, F};
use crate::{
constants::MAX_DEPTH,
frontend,
middleware::{self, EMPTY_HASH, F},
};
#[test]
fn test_signed_0() -> Result<()> {