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

@ -9,9 +9,7 @@
//! }
//! ```
//!
use std::cell::RefCell;
use std::fmt;
use std::thread_local;
use std::{cell::RefCell, fmt, thread_local};
thread_local! {
static COUNTER: RefCell<Counter> = RefCell::new(Counter::new());

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<()> {

View file

@ -1,18 +1,17 @@
use std::sync::Arc;
use anyhow::Result;
use NativePredicate as NP;
use StatementTmplBuilder as STB;
use crate::{
frontend::{
literal, CustomPredicateBatch, CustomPredicateBatchBuilder, CustomPredicateRef,
NativePredicate, Predicate, StatementTmplBuilder, Value,
NativePredicate, Predicate, StatementTmplBuilder,
},
middleware::{self, Params, PodType, KEY_SIGNER, KEY_TYPE},
};
use NativePredicate as NP;
use StatementTmplBuilder as STB;
/// Instantiates an ETH friend batch
pub fn eth_friend_batch(params: &Params) -> Result<Arc<CustomPredicateBatch>> {
let mut builder = CustomPredicateBatchBuilder::new("eth_friend".into());

View file

@ -1,17 +1,19 @@
pub mod custom;
use std::collections::HashMap;
use anyhow::{anyhow, Result};
use custom::{eth_dos_batch, eth_friend_batch};
use std::collections::HashMap;
use crate::backends::plonky2::mock::signedpod::MockSigner;
use crate::frontend::CustomPredicateRef;
use crate::frontend::{
containers::{Dictionary, Set},
MainPodBuilder, SignedPod, SignedPodBuilder, Statement, Value,
use crate::{
backends::plonky2::mock::signedpod::MockSigner,
frontend::{
containers::{Dictionary, Set},
CustomPredicateRef, MainPodBuilder, SignedPod, SignedPodBuilder, Statement, Value,
},
middleware::{Params, PodType, KEY_SIGNER, KEY_TYPE},
op,
};
use crate::middleware::{Params, PodType, KEY_SIGNER, KEY_TYPE};
use crate::op;
// ZuKYC

View file

@ -4,13 +4,14 @@ use anyhow::Result;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use super::Value;
use crate::frontend::serialization::ordered_map;
use crate::middleware::{
containers::{
Array as MiddlewareArray, Dictionary as MiddlewareDictionary, Set as MiddlewareSet,
use crate::{
frontend::{serialization::ordered_map, Value},
middleware::{
containers::{
Array as MiddlewareArray, Dictionary as MiddlewareDictionary, Set as MiddlewareSet,
},
hash_str, Value as MiddlewareValue,
},
hash_str, Value as MiddlewareValue,
};
#[derive(Clone, Debug, PartialEq, Eq, Serialize, JsonSchema)]

View file

@ -1,16 +1,15 @@
#![allow(unused)]
use std::{collections::HashMap, fmt, hash as h, iter, iter::zip, sync::Arc};
use anyhow::{anyhow, Result};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::iter::zip;
use std::sync::Arc;
use std::{fmt, hash as h, iter};
use crate::middleware::{self, hash_str, HashOrWildcard, Params, PodId, ToFields};
use crate::util::hashmap_insert_no_dupe;
use super::{AnchoredKey, NativePredicate, Origin, Statement, StatementArg, Value};
use crate::{
frontend::{AnchoredKey, NativePredicate, Origin, Statement, StatementArg, Value},
middleware::{self, hash_str, HashOrWildcard, Params, PodId, ToFields},
util::hashmap_insert_no_dupe,
};
#[derive(Clone, Debug, PartialEq, Eq, h::Hash, Serialize, Deserialize, JsonSchema)]
/// Argument to a statement template

View file

@ -1,22 +1,21 @@
//! The frontend includes the user-level abstractions and user-friendly types to define and work
//! with Pods.
use crate::frontend::serialization::*;
use crate::middleware::{
self, hash_str, Hash, MainPodInputs, Params, PodId, PodProver, PodSigner, SELF,
};
use crate::middleware::{KEY_SIGNER, KEY_TYPE};
use std::{collections::HashMap, convert::From, fmt, hash as h, hash::Hasher};
use anyhow::{anyhow, Error, Result};
use containers::{Array, Dictionary, Set};
use itertools::Itertools;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::convert::From;
use std::hash::Hasher;
use std::{fmt, hash as h};
use crate::middleware::{hash_value, OperationAux, EMPTY_VALUE};
use crate::{
frontend::serialization::*,
middleware::{
self, hash_str, hash_value, Hash, MainPodInputs, OperationAux, Params, PodId, PodProver,
PodSigner, EMPTY_VALUE, KEY_SIGNER, KEY_TYPE, SELF,
},
};
pub mod containers;
mod custom;
@ -24,8 +23,7 @@ mod operation;
mod predicate;
mod serialization;
mod statement;
pub use custom::*;
pub use custom::{CustomPredicateRef, Predicate};
pub use custom::{CustomPredicateRef, Predicate, *};
pub use operation::*;
pub use predicate::*;
pub use statement::*;
@ -1152,13 +1150,15 @@ pub mod build_utils {
#[cfg(test)]
pub mod tests {
use super::*;
use crate::backends::plonky2::basetypes;
use crate::backends::plonky2::mock::mainpod::MockProver;
use crate::backends::plonky2::mock::signedpod::MockSigner;
use crate::backends::plonky2::primitives::merkletree::MerkleTree;
use crate::examples::{
eth_dos_pod_builder, eth_friend_signed_pod_builder, great_boy_pod_full_flow,
tickets_pod_full_flow, zu_kyc_pod_builder, zu_kyc_sign_pod_builders,
use crate::{
backends::plonky2::{
basetypes,
mock::{mainpod::MockProver, signedpod::MockSigner},
},
examples::{
eth_dos_pod_builder, eth_friend_signed_pod_builder, great_boy_pod_full_flow,
tickets_pod_full_flow, zu_kyc_pod_builder, zu_kyc_sign_pod_builders,
},
};
// Check that frontend public statements agree with those

View file

@ -2,8 +2,10 @@ use std::fmt;
use serde::{Deserialize, Serialize};
use super::{CustomPredicateRef, NativePredicate, Predicate, SignedPod, Statement, Value};
use crate::middleware::{self, OperationAux};
use crate::{
frontend::{CustomPredicateRef, NativePredicate, Predicate, SignedPod, Statement, Value},
middleware::{self, OperationAux},
};
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum OperationArg {

View file

@ -1,9 +1,6 @@
use anyhow::{anyhow, Result};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::fmt;
use super::{AnchoredKey, SignedPod, Value};
use crate::middleware::{self, CustomPredicateRef};
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]

View file

@ -3,13 +3,11 @@ use std::collections::{BTreeMap, HashMap};
use schemars::{JsonSchema, Schema};
use serde::{Deserialize, Serialize, Serializer};
use crate::backends::plonky2::mock::mainpod::MockMainPod;
use crate::backends::plonky2::mock::signedpod::MockSignedPod;
use crate::frontend::containers::Dictionary;
use crate::frontend::Statement;
use crate::middleware::PodId;
use super::{MainPod, SignedPod, Value};
use crate::{
backends::plonky2::mock::{mainpod::MockMainPod, signedpod::MockSignedPod},
frontend::{containers::Dictionary, MainPod, SignedPod, Statement, Value},
middleware::PodId,
};
#[derive(Serialize, Deserialize, JsonSchema)]
#[schemars(title = "SignedPod")]
@ -156,6 +154,7 @@ mod tests {
use anyhow::Result;
use schemars::generate::SchemaSettings;
use super::*;
use crate::{
backends::plonky2::mock::{mainpod::MockProver, signedpod::MockSigner},
examples::{zu_kyc_pod_builder, zu_kyc_sign_pod_builders},
@ -166,8 +165,6 @@ mod tests {
middleware::{self, Params},
};
use super::*;
#[test]
fn test_value_serialization() {
// Pairs of values and their expected serialized representations

View file

@ -1,10 +1,13 @@
use super::{AnchoredKey, NativePredicate, SignedPod, Value};
use crate::frontend::Predicate;
use crate::middleware;
use std::fmt;
use anyhow::{anyhow, Result};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::fmt;
use crate::{
frontend::{AnchoredKey, NativePredicate, Predicate, SignedPod, Value},
middleware,
};
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub enum StatementArg {

View file

@ -1,14 +1,15 @@
use std::collections::HashMap;
/// This file implements the types defined at
/// https://0xparc.github.io/pod2/values.html#dictionary-array-set .
use anyhow::Result;
use std::collections::HashMap;
use crate::constants::MAX_DEPTH;
#[cfg(feature = "backend_plonky2")]
use crate::backends::plonky2::primitives::merkletree::{Iter as TreeIter, MerkleProof, MerkleTree};
use super::basetypes::{hash_value, Hash, Value, EMPTY_VALUE};
use crate::{
constants::MAX_DEPTH,
middleware::basetypes::{hash_value, Hash, Value, EMPTY_VALUE},
};
/// Dictionary: the user original keys and values are hashed to be used in the leaf.
/// leaf.key=hash(original_key)

View file

@ -1,18 +1,18 @@
use std::collections::HashMap;
use std::sync::Arc;
use std::{fmt, hash as h, iter, iter::zip};
use std::{collections::HashMap, fmt, hash as h, iter, iter::zip, sync::Arc};
use anyhow::{anyhow, Result};
use plonky2::field::types::Field;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use super::{
hash_fields, AnchoredKey, Hash, NativePredicate, Params, PodId, Statement, StatementArg,
ToFields, Value, F,
use crate::{
backends::plonky2::basetypes::HASH_SIZE,
middleware::{
hash_fields, AnchoredKey, Hash, NativePredicate, Params, PodId, Statement, StatementArg,
ToFields, Value, F,
},
util::hashmap_insert_no_dupe,
};
use crate::backends::plonky2::basetypes::HASH_SIZE;
use crate::util::hashmap_insert_no_dupe;
// BEGIN Custom 1b

View file

@ -7,20 +7,16 @@ mod custom;
mod operation;
pub mod serialization;
mod statement;
pub use basetypes::*;
pub use custom::*;
pub use operation::*;
use schemars::JsonSchema;
pub use statement::*;
use std::{any::Any, collections::HashMap, fmt};
use anyhow::Result;
pub use basetypes::*;
pub use custom::*;
use dyn_clone::DynClone;
pub use operation::*;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::any::Any;
use std::collections::HashMap;
use std::fmt;
use crate::backends::plonky2::primitives::merkletree::MerkleProof;
pub use statement::*;
pub const SELF: PodId = PodId(SELF_ID_HASH);

View file

@ -1,17 +1,16 @@
use std::{fmt, iter};
use anyhow::{anyhow, Result};
use log::error;
use plonky2::field::types::Field;
use serde::{Deserialize, Serialize};
use std::fmt;
use std::iter;
use super::Hash;
use super::{CustomPredicateRef, NativePredicate, Statement, StatementArg, ToFields, F};
use crate::middleware::EMPTY_HASH;
use crate::middleware::EMPTY_VALUE;
use crate::{
backends::plonky2::primitives::merkletree::{MerkleProof, MerkleTree},
middleware::{AnchoredKey, Params, Predicate, Value, SELF},
middleware::{
AnchoredKey, CustomPredicateRef, NativePredicate, Params, Predicate, Statement,
StatementArg, ToFields, Value, F, SELF,
},
};
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]

View file

@ -1,7 +1,7 @@
use plonky2::field::types::Field;
use serde::Deserialize;
use super::{F, HASH_SIZE, VALUE_SIZE};
use crate::middleware::{F, HASH_SIZE, VALUE_SIZE};
fn serialize_field_tuple<S, const N: usize>(
value: &[F; N],

View file

@ -1,11 +1,14 @@
use std::{fmt, iter};
use anyhow::{anyhow, Result};
use plonky2::field::types::Field;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::{fmt, iter};
use strum_macros::FromRepr;
use super::{AnchoredKey, CustomPredicateRef, Params, Predicate, ToFields, Value, F, VALUE_SIZE};
use crate::middleware::{
AnchoredKey, CustomPredicateRef, Params, Predicate, ToFields, Value, F, VALUE_SIZE,
};
// hash(KEY_SIGNER) = [2145458785152392366, 15113074911296146791, 15323228995597834291, 11804480340100333725]
pub const KEY_SIGNER: &str = "_signer";

View file

@ -1,6 +1,4 @@
use std::collections::HashMap;
use std::fmt::Debug;
use std::hash::Hash;
use std::{collections::HashMap, fmt::Debug, hash::Hash};
use anyhow::{anyhow, Result};