Organize imports (#188)
* Organize imports Use rustfmt to organize imports. Resolve #162 * remove unused imports * cargo fmt
This commit is contained in:
parent
1214cdfa1b
commit
24ff82dd3d
32 changed files with 329 additions and 276 deletions
3
rustfmt.toml
Normal file
3
rustfmt.toml
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
imports_granularity = "Crate"
|
||||||
|
reorder_imports = true # default
|
||||||
|
group_imports = "StdExternalCrate"
|
||||||
|
|
@ -9,9 +9,7 @@
|
||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
use std::cell::RefCell;
|
use std::{cell::RefCell, fmt, thread_local};
|
||||||
use std::fmt;
|
|
||||||
use std::thread_local;
|
|
||||||
|
|
||||||
thread_local! {
|
thread_local! {
|
||||||
static COUNTER: RefCell<Counter> = RefCell::new(Counter::new());
|
static COUNTER: RefCell<Counter> = RefCell::new(Counter::new());
|
||||||
|
|
|
||||||
|
|
@ -2,24 +2,37 @@
|
||||||
//! `backend_plonky2` feature is enabled.
|
//! `backend_plonky2` feature is enabled.
|
||||||
//! See src/middleware/basetypes.rs for more details.
|
//! See src/middleware/basetypes.rs for more details.
|
||||||
|
|
||||||
use crate::middleware::serialization::{
|
use std::{
|
||||||
deserialize_hash_tuple, deserialize_value_tuple, serialize_hash_tuple, serialize_value_tuple,
|
cmp::{Ord, Ordering},
|
||||||
|
fmt,
|
||||||
};
|
};
|
||||||
use crate::middleware::{Params, ToFields};
|
|
||||||
use anyhow::{anyhow, Error, Result};
|
use anyhow::{anyhow, Error, Result};
|
||||||
use hex::{FromHex, FromHexError};
|
use hex::{FromHex, FromHexError};
|
||||||
use plonky2::field::goldilocks_field::GoldilocksField;
|
use plonky2::{
|
||||||
use plonky2::field::types::{Field, PrimeField64};
|
field::{
|
||||||
use plonky2::hash::poseidon::PoseidonHash;
|
goldilocks_field::GoldilocksField,
|
||||||
use plonky2::plonk::config::Hasher;
|
types::{Field, PrimeField64},
|
||||||
use plonky2::plonk::config::PoseidonGoldilocksConfig;
|
},
|
||||||
use plonky2::plonk::proof::Proof as Plonky2Proof;
|
hash::poseidon::PoseidonHash,
|
||||||
|
plonk::{
|
||||||
|
config::{Hasher, PoseidonGoldilocksConfig},
|
||||||
|
proof::Proof as Plonky2Proof,
|
||||||
|
},
|
||||||
|
};
|
||||||
use schemars::JsonSchema;
|
use schemars::JsonSchema;
|
||||||
use serde::{Deserialize, Serialize};
|
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
|
/// F is the native field we use everywhere. Currently it's Goldilocks from plonky2
|
||||||
pub type F = GoldilocksField;
|
pub type F = GoldilocksField;
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,33 @@
|
||||||
//! Common functionality to build Pod circuits with plonky2
|
//! Common functionality to build Pod circuits with plonky2
|
||||||
|
|
||||||
use crate::backends::plonky2::basetypes::D;
|
use std::{array, iter};
|
||||||
use crate::backends::plonky2::mock::mainpod::Statement;
|
|
||||||
use crate::backends::plonky2::mock::mainpod::{Operation, OperationArg};
|
use anyhow::Result;
|
||||||
use crate::backends::plonky2::primitives::merkletree::MerkleClaimAndProofTarget;
|
use plonky2::{
|
||||||
use crate::middleware::{
|
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,
|
NativeOperation, NativePredicate, Params, Predicate, StatementArg, ToFields, Value,
|
||||||
EMPTY_VALUE, F, HASH_SIZE, OPERATION_ARG_F_LEN, OPERATION_AUX_F_LEN, STATEMENT_ARG_F_LEN,
|
EMPTY_VALUE, F, HASH_SIZE, OPERATION_ARG_F_LEN, OPERATION_AUX_F_LEN, STATEMENT_ARG_F_LEN,
|
||||||
VALUE_SIZE,
|
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};
|
|
||||||
|
|
||||||
pub const CODE_SIZE: usize = HASH_SIZE + 2;
|
pub const CODE_SIZE: usize = HASH_SIZE + 2;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::Result;
|
||||||
use itertools::zip_eq;
|
use itertools::zip_eq;
|
||||||
use plonky2::{
|
use plonky2::{
|
||||||
hash::{hash_types::HashOutTarget, poseidon::PoseidonHash},
|
hash::{hash_types::HashOutTarget, poseidon::PoseidonHash},
|
||||||
|
|
@ -6,28 +6,27 @@ use plonky2::{
|
||||||
plonk::circuit_builder::CircuitBuilder,
|
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::{
|
use crate::{
|
||||||
backends::plonky2::{
|
backends::plonky2::{
|
||||||
circuits::common::{CircuitBuilderPod, OperationTarget, StatementTarget, ValueTarget},
|
basetypes::{Value, D, EMPTY_HASH, F, VALUE_SIZE},
|
||||||
primitives::merkletree,
|
circuits::{
|
||||||
|
common::{
|
||||||
|
CircuitBuilderPod, Flattenable, MerkleClaimTarget, OperationTarget,
|
||||||
|
StatementTarget, ValueTarget,
|
||||||
},
|
},
|
||||||
middleware,
|
|
||||||
};
|
|
||||||
|
|
||||||
use super::{
|
|
||||||
common::{Flattenable, MerkleClaimTarget},
|
|
||||||
signedpod::{SignedPodVerifyGadget, SignedPodVerifyTarget},
|
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,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
@ -555,12 +554,16 @@ mod tests {
|
||||||
use plonky2::plonk::{circuit_builder::CircuitBuilder, circuit_data::CircuitConfig};
|
use plonky2::plonk::{circuit_builder::CircuitBuilder, circuit_data::CircuitConfig};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::backends::plonky2::mock::mainpod;
|
use crate::{
|
||||||
use crate::backends::plonky2::{
|
backends::plonky2::{
|
||||||
basetypes::C,
|
basetypes::C,
|
||||||
mock::mainpod::{OperationArg, OperationAux},
|
mock::{
|
||||||
|
mainpod,
|
||||||
|
mainpod::{OperationArg, OperationAux},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
middleware::{OperationType, PodId},
|
||||||
};
|
};
|
||||||
use crate::middleware::{OperationType, PodId};
|
|
||||||
|
|
||||||
fn operation_verify(
|
fn operation_verify(
|
||||||
st: mainpod::Statement,
|
st: mainpod::Statement,
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,18 @@
|
||||||
|
use std::iter;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use plonky2::{
|
use plonky2::{
|
||||||
hash::hash_types::{HashOut, HashOutTarget},
|
hash::hash_types::{HashOut, HashOutTarget},
|
||||||
iop::target::Target,
|
iop::{
|
||||||
iop::witness::{PartialWitness, WitnessWrite},
|
target::Target,
|
||||||
|
witness::{PartialWitness, WitnessWrite},
|
||||||
|
},
|
||||||
plonk::circuit_builder::CircuitBuilder,
|
plonk::circuit_builder::CircuitBuilder,
|
||||||
};
|
};
|
||||||
use std::iter;
|
|
||||||
|
|
||||||
use crate::backends::plonky2::{
|
use crate::{
|
||||||
|
backends::plonky2::{
|
||||||
basetypes::{Value, D, EMPTY_VALUE, F},
|
basetypes::{Value, D, EMPTY_VALUE, F},
|
||||||
circuits::common::{CircuitBuilderPod, StatementArgTarget, StatementTarget, ValueTarget},
|
circuits::common::{CircuitBuilderPod, StatementArgTarget, StatementTarget, ValueTarget},
|
||||||
primitives::{
|
primitives::{
|
||||||
|
|
@ -16,9 +20,10 @@ use crate::backends::plonky2::{
|
||||||
signature::{PublicKey, SignatureVerifyGadget, SignatureVerifyTarget},
|
signature::{PublicKey, SignatureVerifyGadget, SignatureVerifyTarget},
|
||||||
},
|
},
|
||||||
signedpod::SignedPod,
|
signedpod::SignedPod,
|
||||||
};
|
},
|
||||||
use crate::middleware::{
|
middleware::{
|
||||||
hash_str, NativePredicate, Params, PodType, Predicate, ToFields, KEY_SIGNER, KEY_TYPE, SELF,
|
hash_str, NativePredicate, Params, PodType, Predicate, ToFields, KEY_SIGNER, KEY_TYPE, SELF,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct SignedPodVerifyGadget {
|
pub struct SignedPodVerifyGadget {
|
||||||
|
|
@ -188,16 +193,18 @@ pub mod tests {
|
||||||
use plonky2::plonk::{circuit_builder::CircuitBuilder, circuit_data::CircuitConfig};
|
use plonky2::plonk::{circuit_builder::CircuitBuilder, circuit_data::CircuitConfig};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::backends::plonky2::{
|
use crate::{
|
||||||
|
backends::plonky2::{
|
||||||
basetypes::C,
|
basetypes::C,
|
||||||
primitives::signature::SecretKey,
|
primitives::signature::SecretKey,
|
||||||
signedpod::{SignedPod, Signer},
|
signedpod::{SignedPod, Signer},
|
||||||
|
},
|
||||||
|
middleware::F,
|
||||||
};
|
};
|
||||||
use crate::middleware::F;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_signed_pod_verify() -> Result<()> {
|
fn test_signed_pod_verify() -> Result<()> {
|
||||||
let mut params = Params {
|
let params = Params {
|
||||||
max_signed_pod_values: 6,
|
max_signed_pod_values: 6,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -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::any::Any;
|
||||||
use std::fmt;
|
|
||||||
|
|
||||||
use crate::backends::plonky2::basetypes::{Hash, Value, D, EMPTY_HASH, EMPTY_VALUE, F, VALUE_SIZE};
|
use anyhow::{anyhow, Result};
|
||||||
use crate::backends::plonky2::circuits::mainpod::{MainPodVerifyCircuit, MainPodVerifyInput};
|
use itertools::Itertools;
|
||||||
use crate::backends::plonky2::signedpod::SignedPod;
|
use plonky2::{
|
||||||
// TODO: Move the shared components between MockMainPod and MainPod to a common place.
|
iop::witness::PartialWitness,
|
||||||
use crate::backends::plonky2::mock::mainpod::{hash_statements, MockMainPod, Operation, Statement};
|
plonk::{
|
||||||
use crate::middleware::{
|
circuit_builder::CircuitBuilder, circuit_data::CircuitConfig, proof::ProofWithPublicInputs,
|
||||||
self, hash_str, AnchoredKey, MainPodInputs, NativeOperation, NativePredicate, NonePod,
|
},
|
||||||
OperationType, Params, Pod, PodId, PodProver, Predicate, StatementArg, ToFields, KEY_TYPE,
|
|
||||||
SELF,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
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 {}
|
pub struct Prover {}
|
||||||
|
|
||||||
|
|
@ -163,13 +160,15 @@ impl Pod for MainPod {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub mod tests {
|
pub mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::backends::plonky2::mock::mainpod::{MockProver, OperationAux};
|
use crate::{
|
||||||
use crate::backends::plonky2::primitives::signature::SecretKey;
|
backends::plonky2::{
|
||||||
use crate::backends::plonky2::signedpod::Signer;
|
mock::mainpod::MockProver, primitives::signature::SecretKey, signedpod::Signer,
|
||||||
use crate::examples::zu_kyc_sign_pod_builders;
|
},
|
||||||
use crate::frontend;
|
examples::zu_kyc_sign_pod_builders,
|
||||||
use crate::middleware;
|
frontend, middleware,
|
||||||
use crate::op;
|
middleware::Value,
|
||||||
|
op,
|
||||||
|
};
|
||||||
|
|
||||||
// TODO: Use the method from examples once everything works
|
// TODO: Use the method from examples once everything works
|
||||||
pub fn zu_kyc_pod_builder(
|
pub fn zu_kyc_pod_builder(
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,10 @@
|
||||||
|
use std::{any::Any, fmt};
|
||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use base64::prelude::*;
|
use base64::prelude::*;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use log::error;
|
use plonky2::{hash::poseidon::PoseidonHash, plonk::config::Hasher};
|
||||||
use plonky2::hash::poseidon::PoseidonHash;
|
|
||||||
use plonky2::plonk::config::Hasher;
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::any::Any;
|
|
||||||
use std::fmt;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
backends::plonky2::primitives::merkletree,
|
backends::plonky2::primitives::merkletree,
|
||||||
|
|
@ -608,13 +606,14 @@ impl Pod for MockMainPod {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub mod tests {
|
pub mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::backends::plonky2::mock::signedpod::MockSigner;
|
use crate::{
|
||||||
use crate::examples::{
|
backends::plonky2::mock::signedpod::MockSigner,
|
||||||
|
examples::{
|
||||||
great_boy_pod_full_flow, tickets_pod_full_flow, zu_kyc_pod_builder,
|
great_boy_pod_full_flow, tickets_pod_full_flow, zu_kyc_pod_builder,
|
||||||
zu_kyc_sign_pod_builders,
|
zu_kyc_sign_pod_builders,
|
||||||
|
},
|
||||||
|
middleware,
|
||||||
};
|
};
|
||||||
use crate::middleware;
|
|
||||||
use crate::middleware::containers::Set;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_mock_main_zu_kyc() -> Result<()> {
|
fn test_mock_main_zu_kyc() -> Result<()> {
|
||||||
|
|
|
||||||
|
|
@ -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::{
|
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},
|
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)]
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
pub enum OperationArg {
|
pub enum OperationArg {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
|
use std::fmt;
|
||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt;
|
|
||||||
|
|
||||||
use crate::middleware::{
|
use crate::middleware::{
|
||||||
self, AnchoredKey, NativePredicate, Params, Predicate, StatementArg, ToFields,
|
self, AnchoredKey, NativePredicate, Params, Predicate, StatementArg, ToFields,
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,15 @@
|
||||||
|
use std::{any::Any, collections::HashMap};
|
||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use std::any::Any;
|
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
use crate::backends::plonky2::primitives::merkletree::MerkleTree;
|
use crate::{
|
||||||
use crate::constants::MAX_DEPTH;
|
backends::plonky2::primitives::merkletree::MerkleTree,
|
||||||
use crate::middleware::{
|
constants::MAX_DEPTH,
|
||||||
containers::Dictionary, hash_str, AnchoredKey, Hash, Params, Pod, PodId, PodSigner, PodType,
|
middleware::{
|
||||||
Statement, Value, KEY_SIGNER, KEY_TYPE,
|
containers::Dictionary, hash_str, AnchoredKey, Hash, Params, Pod, PodId, PodSigner,
|
||||||
|
PodType, Statement, Value, KEY_SIGNER, KEY_TYPE,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct MockSigner {
|
pub struct MockSigner {
|
||||||
|
|
@ -129,13 +131,16 @@ impl Pod for MockSignedPod {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub mod tests {
|
pub mod tests {
|
||||||
use plonky2::field::types::Field;
|
|
||||||
use std::iter;
|
use std::iter;
|
||||||
|
|
||||||
|
use plonky2::field::types::Field;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::constants::MAX_DEPTH;
|
use crate::{
|
||||||
use crate::frontend;
|
constants::MAX_DEPTH,
|
||||||
use crate::middleware::{self, EMPTY_HASH, F};
|
frontend,
|
||||||
|
middleware::{self, EMPTY_HASH, F},
|
||||||
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_mock_signed_0() -> Result<()> {
|
fn test_mock_signed_0() -> Result<()> {
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,16 @@
|
||||||
//! Module that implements the MerkleTree specified at
|
//! Module that implements the MerkleTree specified at
|
||||||
//! https://0xparc.github.io/pod2/merkletree.html .
|
//! https://0xparc.github.io/pod2/merkletree.html .
|
||||||
|
use std::{collections::HashMap, fmt, iter::IntoIterator};
|
||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use plonky2::field::types::Field;
|
use plonky2::field::types::Field;
|
||||||
use serde::{Deserialize, Serialize};
|
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::*;
|
pub use super::merkletree_circuit::*;
|
||||||
|
use crate::backends::{
|
||||||
|
counter,
|
||||||
|
plonky2::basetypes::{hash_fields, Hash, Value, EMPTY_HASH, F},
|
||||||
|
};
|
||||||
|
|
||||||
/// Implements the MerkleTree specified at
|
/// Implements the MerkleTree specified at
|
||||||
/// https://0xparc.github.io/pod2/merkletree.html
|
/// https://0xparc.github.io/pod2/merkletree.html
|
||||||
|
|
@ -582,9 +582,10 @@ impl<'a> Iterator for Iter<'a> {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub mod tests {
|
pub mod tests {
|
||||||
use itertools::Itertools;
|
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
|
|
||||||
|
use itertools::Itertools;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@
|
||||||
//! If only proofs of existence are needed, use `MerkleProofExistenceCircuit`,
|
//! If only proofs of existence are needed, use `MerkleProofExistenceCircuit`,
|
||||||
//! which requires less amount of constraints than `MerkleProofCircuit`.
|
//! which requires less amount of constraints than `MerkleProofCircuit`.
|
||||||
//!
|
//!
|
||||||
|
use std::iter;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use plonky2::{
|
use plonky2::{
|
||||||
field::types::Field,
|
field::types::Field,
|
||||||
|
|
@ -21,11 +23,12 @@ use plonky2::{
|
||||||
},
|
},
|
||||||
plonk::circuit_builder::CircuitBuilder,
|
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::{
|
||||||
use crate::backends::plonky2::circuits::common::{CircuitBuilderPod, ValueTarget};
|
basetypes::{Hash, Value, D, EMPTY_HASH, EMPTY_VALUE, F, HASH_SIZE},
|
||||||
use crate::backends::plonky2::primitives::merkletree::MerkleProof;
|
circuits::common::{CircuitBuilderPod, ValueTarget},
|
||||||
|
primitives::merkletree::MerkleProof,
|
||||||
|
};
|
||||||
|
|
||||||
/// `MerkleProofGadget` allows to verify both proofs of existence and proofs
|
/// `MerkleProofGadget` allows to verify both proofs of existence and proofs
|
||||||
/// non-existence with the same circuit.
|
/// non-existence with the same circuit.
|
||||||
|
|
@ -396,13 +399,15 @@ fn kv_hash_target(
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub mod tests {
|
pub mod tests {
|
||||||
use plonky2::plonk::{circuit_builder::CircuitBuilder, circuit_data::CircuitConfig};
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use plonky2::plonk::{circuit_builder::CircuitBuilder, circuit_data::CircuitConfig};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::backends::plonky2::basetypes::hash_value;
|
use crate::backends::plonky2::{
|
||||||
use crate::backends::plonky2::basetypes::C;
|
basetypes::{hash_value, C},
|
||||||
use crate::backends::plonky2::primitives::merkletree::*;
|
primitives::merkletree::*,
|
||||||
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_keypath() -> Result<()> {
|
fn test_keypath() -> Result<()> {
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,8 @@ use plonky2::{
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::backends::plonky2::basetypes::{Proof, Value, C, D, F, VALUE_SIZE};
|
|
||||||
|
|
||||||
pub use super::signature_circuit::*;
|
pub use super::signature_circuit::*;
|
||||||
|
use crate::backends::plonky2::basetypes::{Proof, Value, C, D, F, VALUE_SIZE};
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
/// Signature prover parameters
|
/// Signature prover parameters
|
||||||
|
|
@ -201,9 +200,8 @@ impl SignatureInternalCircuit {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub mod tests {
|
pub mod tests {
|
||||||
use crate::backends::plonky2::basetypes::Hash;
|
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::backends::plonky2::basetypes::Hash;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_signature() -> Result<()> {
|
fn test_signature() -> Result<()> {
|
||||||
|
|
|
||||||
|
|
@ -11,19 +11,24 @@ use plonky2::{
|
||||||
target::{BoolTarget, Target},
|
target::{BoolTarget, Target},
|
||||||
witness::{PartialWitness, WitnessWrite},
|
witness::{PartialWitness, WitnessWrite},
|
||||||
},
|
},
|
||||||
plonk::circuit_builder::CircuitBuilder,
|
plonk::{
|
||||||
plonk::circuit_data::{
|
circuit_builder::CircuitBuilder,
|
||||||
CircuitConfig, CircuitData, ProverCircuitData, VerifierCircuitData, VerifierCircuitTarget,
|
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::{
|
||||||
use crate::backends::plonky2::basetypes::{
|
basetypes::{Hash, Proof, Value, C, D, EMPTY_HASH, EMPTY_VALUE, F, VALUE_SIZE},
|
||||||
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! {
|
lazy_static! {
|
||||||
/// SignatureVerifyGadget VerifierCircuitData
|
/// SignatureVerifyGadget VerifierCircuitData
|
||||||
|
|
@ -164,10 +169,8 @@ impl SignatureVerifyTarget {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub mod tests {
|
pub mod tests {
|
||||||
use crate::backends::plonky2::basetypes::Hash;
|
|
||||||
use crate::backends::plonky2::primitives::signature::SecretKey;
|
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::backends::plonky2::{basetypes::Hash, primitives::signature::SecretKey};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_signature_gadget() -> Result<()> {
|
fn test_signature_gadget() -> Result<()> {
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,20 @@
|
||||||
|
use std::{any::Any, collections::HashMap};
|
||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use std::any::Any;
|
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
use super::primitives::merkletree::MerkleTree;
|
use crate::{
|
||||||
use crate::constants::MAX_DEPTH;
|
backends::plonky2::primitives::{
|
||||||
use crate::middleware::{
|
merkletree::MerkleTree,
|
||||||
containers::Dictionary, hash_str, AnchoredKey, Hash, Params, Pod, PodId, PodSigner, PodType,
|
signature::{PublicKey, SecretKey, Signature},
|
||||||
Statement, Value, KEY_SIGNER, KEY_TYPE,
|
},
|
||||||
|
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);
|
pub struct Signer(pub SecretKey);
|
||||||
|
|
||||||
impl PodSigner for Signer {
|
impl PodSigner for Signer {
|
||||||
|
|
@ -111,13 +114,16 @@ impl Pod for SignedPod {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub mod tests {
|
pub mod tests {
|
||||||
use plonky2::field::types::Field;
|
|
||||||
use std::iter;
|
use std::iter;
|
||||||
|
|
||||||
|
use plonky2::field::types::Field;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::constants::MAX_DEPTH;
|
use crate::{
|
||||||
use crate::frontend;
|
constants::MAX_DEPTH,
|
||||||
use crate::middleware::{self, EMPTY_HASH, F};
|
frontend,
|
||||||
|
middleware::{self, EMPTY_HASH, F},
|
||||||
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_signed_0() -> Result<()> {
|
fn test_signed_0() -> Result<()> {
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,17 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
use NativePredicate as NP;
|
||||||
|
use StatementTmplBuilder as STB;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
frontend::{
|
frontend::{
|
||||||
literal, CustomPredicateBatch, CustomPredicateBatchBuilder, CustomPredicateRef,
|
literal, CustomPredicateBatch, CustomPredicateBatchBuilder, CustomPredicateRef,
|
||||||
NativePredicate, Predicate, StatementTmplBuilder, Value,
|
NativePredicate, Predicate, StatementTmplBuilder,
|
||||||
},
|
},
|
||||||
middleware::{self, Params, PodType, KEY_SIGNER, KEY_TYPE},
|
middleware::{self, Params, PodType, KEY_SIGNER, KEY_TYPE},
|
||||||
};
|
};
|
||||||
|
|
||||||
use NativePredicate as NP;
|
|
||||||
use StatementTmplBuilder as STB;
|
|
||||||
|
|
||||||
/// Instantiates an ETH friend batch
|
/// Instantiates an ETH friend batch
|
||||||
pub fn eth_friend_batch(params: &Params) -> Result<Arc<CustomPredicateBatch>> {
|
pub fn eth_friend_batch(params: &Params) -> Result<Arc<CustomPredicateBatch>> {
|
||||||
let mut builder = CustomPredicateBatchBuilder::new("eth_friend".into());
|
let mut builder = CustomPredicateBatchBuilder::new("eth_friend".into());
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,19 @@
|
||||||
pub mod custom;
|
pub mod custom;
|
||||||
|
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use custom::{eth_dos_batch, eth_friend_batch};
|
use custom::{eth_dos_batch, eth_friend_batch};
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
use crate::backends::plonky2::mock::signedpod::MockSigner;
|
use crate::{
|
||||||
use crate::frontend::CustomPredicateRef;
|
backends::plonky2::mock::signedpod::MockSigner,
|
||||||
use crate::frontend::{
|
frontend::{
|
||||||
containers::{Dictionary, Set},
|
containers::{Dictionary, Set},
|
||||||
MainPodBuilder, SignedPod, SignedPodBuilder, Statement, Value,
|
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
|
// ZuKYC
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,14 @@ use anyhow::Result;
|
||||||
use schemars::JsonSchema;
|
use schemars::JsonSchema;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use super::Value;
|
use crate::{
|
||||||
use crate::frontend::serialization::ordered_map;
|
frontend::{serialization::ordered_map, Value},
|
||||||
use crate::middleware::{
|
middleware::{
|
||||||
containers::{
|
containers::{
|
||||||
Array as MiddlewareArray, Dictionary as MiddlewareDictionary, Set as MiddlewareSet,
|
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)]
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, JsonSchema)]
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,15 @@
|
||||||
#![allow(unused)]
|
#![allow(unused)]
|
||||||
|
use std::{collections::HashMap, fmt, hash as h, iter, iter::zip, sync::Arc};
|
||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use schemars::JsonSchema;
|
use schemars::JsonSchema;
|
||||||
use serde::{Deserialize, Serialize};
|
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::{
|
||||||
use crate::util::hashmap_insert_no_dupe;
|
frontend::{AnchoredKey, NativePredicate, Origin, Statement, StatementArg, Value},
|
||||||
|
middleware::{self, hash_str, HashOrWildcard, Params, PodId, ToFields},
|
||||||
use super::{AnchoredKey, NativePredicate, Origin, Statement, StatementArg, Value};
|
util::hashmap_insert_no_dupe,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, h::Hash, Serialize, Deserialize, JsonSchema)]
|
#[derive(Clone, Debug, PartialEq, Eq, h::Hash, Serialize, Deserialize, JsonSchema)]
|
||||||
/// Argument to a statement template
|
/// Argument to a statement template
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,21 @@
|
||||||
//! The frontend includes the user-level abstractions and user-friendly types to define and work
|
//! The frontend includes the user-level abstractions and user-friendly types to define and work
|
||||||
//! with Pods.
|
//! with Pods.
|
||||||
|
|
||||||
use crate::frontend::serialization::*;
|
use std::{collections::HashMap, convert::From, fmt, hash as h, hash::Hasher};
|
||||||
use crate::middleware::{
|
|
||||||
self, hash_str, Hash, MainPodInputs, Params, PodId, PodProver, PodSigner, SELF,
|
|
||||||
};
|
|
||||||
use crate::middleware::{KEY_SIGNER, KEY_TYPE};
|
|
||||||
use anyhow::{anyhow, Error, Result};
|
use anyhow::{anyhow, Error, Result};
|
||||||
use containers::{Array, Dictionary, Set};
|
use containers::{Array, Dictionary, Set};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use schemars::JsonSchema;
|
use schemars::JsonSchema;
|
||||||
use serde::{Deserialize, Serialize};
|
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;
|
pub mod containers;
|
||||||
mod custom;
|
mod custom;
|
||||||
|
|
@ -24,8 +23,7 @@ mod operation;
|
||||||
mod predicate;
|
mod predicate;
|
||||||
mod serialization;
|
mod serialization;
|
||||||
mod statement;
|
mod statement;
|
||||||
pub use custom::*;
|
pub use custom::{CustomPredicateRef, Predicate, *};
|
||||||
pub use custom::{CustomPredicateRef, Predicate};
|
|
||||||
pub use operation::*;
|
pub use operation::*;
|
||||||
pub use predicate::*;
|
pub use predicate::*;
|
||||||
pub use statement::*;
|
pub use statement::*;
|
||||||
|
|
@ -1152,13 +1150,15 @@ pub mod build_utils {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub mod tests {
|
pub mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::backends::plonky2::basetypes;
|
use crate::{
|
||||||
use crate::backends::plonky2::mock::mainpod::MockProver;
|
backends::plonky2::{
|
||||||
use crate::backends::plonky2::mock::signedpod::MockSigner;
|
basetypes,
|
||||||
use crate::backends::plonky2::primitives::merkletree::MerkleTree;
|
mock::{mainpod::MockProver, signedpod::MockSigner},
|
||||||
use crate::examples::{
|
},
|
||||||
|
examples::{
|
||||||
eth_dos_pod_builder, eth_friend_signed_pod_builder, great_boy_pod_full_flow,
|
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,
|
tickets_pod_full_flow, zu_kyc_pod_builder, zu_kyc_sign_pod_builders,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// Check that frontend public statements agree with those
|
// Check that frontend public statements agree with those
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,10 @@ use std::fmt;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use super::{CustomPredicateRef, NativePredicate, Predicate, SignedPod, Statement, Value};
|
use crate::{
|
||||||
use crate::middleware::{self, OperationAux};
|
frontend::{CustomPredicateRef, NativePredicate, Predicate, SignedPod, Statement, Value},
|
||||||
|
middleware::{self, OperationAux},
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub enum OperationArg {
|
pub enum OperationArg {
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,6 @@
|
||||||
use anyhow::{anyhow, Result};
|
|
||||||
use schemars::JsonSchema;
|
use schemars::JsonSchema;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt;
|
|
||||||
|
|
||||||
use super::{AnchoredKey, SignedPod, Value};
|
|
||||||
use crate::middleware::{self, CustomPredicateRef};
|
use crate::middleware::{self, CustomPredicateRef};
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,11 @@ use std::collections::{BTreeMap, HashMap};
|
||||||
use schemars::{JsonSchema, Schema};
|
use schemars::{JsonSchema, Schema};
|
||||||
use serde::{Deserialize, Serialize, Serializer};
|
use serde::{Deserialize, Serialize, Serializer};
|
||||||
|
|
||||||
use crate::backends::plonky2::mock::mainpod::MockMainPod;
|
use crate::{
|
||||||
use crate::backends::plonky2::mock::signedpod::MockSignedPod;
|
backends::plonky2::mock::{mainpod::MockMainPod, signedpod::MockSignedPod},
|
||||||
use crate::frontend::containers::Dictionary;
|
frontend::{containers::Dictionary, MainPod, SignedPod, Statement, Value},
|
||||||
use crate::frontend::Statement;
|
middleware::PodId,
|
||||||
use crate::middleware::PodId;
|
};
|
||||||
|
|
||||||
use super::{MainPod, SignedPod, Value};
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, JsonSchema)]
|
#[derive(Serialize, Deserialize, JsonSchema)]
|
||||||
#[schemars(title = "SignedPod")]
|
#[schemars(title = "SignedPod")]
|
||||||
|
|
@ -156,6 +154,7 @@ mod tests {
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use schemars::generate::SchemaSettings;
|
use schemars::generate::SchemaSettings;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
backends::plonky2::mock::{mainpod::MockProver, signedpod::MockSigner},
|
backends::plonky2::mock::{mainpod::MockProver, signedpod::MockSigner},
|
||||||
examples::{zu_kyc_pod_builder, zu_kyc_sign_pod_builders},
|
examples::{zu_kyc_pod_builder, zu_kyc_sign_pod_builders},
|
||||||
|
|
@ -166,8 +165,6 @@ mod tests {
|
||||||
middleware::{self, Params},
|
middleware::{self, Params},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_value_serialization() {
|
fn test_value_serialization() {
|
||||||
// Pairs of values and their expected serialized representations
|
// Pairs of values and their expected serialized representations
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,13 @@
|
||||||
use super::{AnchoredKey, NativePredicate, SignedPod, Value};
|
use std::fmt;
|
||||||
use crate::frontend::Predicate;
|
|
||||||
use crate::middleware;
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use schemars::JsonSchema;
|
use schemars::JsonSchema;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt;
|
|
||||||
|
use crate::{
|
||||||
|
frontend::{AnchoredKey, NativePredicate, Predicate, SignedPod, Value},
|
||||||
|
middleware,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
|
||||||
pub enum StatementArg {
|
pub enum StatementArg {
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,15 @@
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
/// This file implements the types defined at
|
/// This file implements the types defined at
|
||||||
/// https://0xparc.github.io/pod2/values.html#dictionary-array-set .
|
/// https://0xparc.github.io/pod2/values.html#dictionary-array-set .
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
use crate::constants::MAX_DEPTH;
|
|
||||||
|
|
||||||
#[cfg(feature = "backend_plonky2")]
|
#[cfg(feature = "backend_plonky2")]
|
||||||
use crate::backends::plonky2::primitives::merkletree::{Iter as TreeIter, MerkleProof, MerkleTree};
|
use crate::backends::plonky2::primitives::merkletree::{Iter as TreeIter, MerkleProof, MerkleTree};
|
||||||
|
use crate::{
|
||||||
use super::basetypes::{hash_value, Hash, Value, EMPTY_VALUE};
|
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.
|
/// Dictionary: the user original keys and values are hashed to be used in the leaf.
|
||||||
/// leaf.key=hash(original_key)
|
/// leaf.key=hash(original_key)
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,18 @@
|
||||||
use std::collections::HashMap;
|
use std::{collections::HashMap, fmt, hash as h, iter, iter::zip, sync::Arc};
|
||||||
use std::sync::Arc;
|
|
||||||
use std::{fmt, hash as h, iter, iter::zip};
|
|
||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use plonky2::field::types::Field;
|
use plonky2::field::types::Field;
|
||||||
use schemars::JsonSchema;
|
use schemars::JsonSchema;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use super::{
|
use crate::{
|
||||||
|
backends::plonky2::basetypes::HASH_SIZE,
|
||||||
|
middleware::{
|
||||||
hash_fields, AnchoredKey, Hash, NativePredicate, Params, PodId, Statement, StatementArg,
|
hash_fields, AnchoredKey, Hash, NativePredicate, Params, PodId, Statement, StatementArg,
|
||||||
ToFields, Value, F,
|
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
|
// BEGIN Custom 1b
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,20 +7,16 @@ mod custom;
|
||||||
mod operation;
|
mod operation;
|
||||||
pub mod serialization;
|
pub mod serialization;
|
||||||
mod statement;
|
mod statement;
|
||||||
pub use basetypes::*;
|
use std::{any::Any, collections::HashMap, fmt};
|
||||||
pub use custom::*;
|
|
||||||
pub use operation::*;
|
|
||||||
use schemars::JsonSchema;
|
|
||||||
pub use statement::*;
|
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
pub use basetypes::*;
|
||||||
|
pub use custom::*;
|
||||||
use dyn_clone::DynClone;
|
use dyn_clone::DynClone;
|
||||||
|
pub use operation::*;
|
||||||
|
use schemars::JsonSchema;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::any::Any;
|
pub use statement::*;
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::fmt;
|
|
||||||
|
|
||||||
use crate::backends::plonky2::primitives::merkletree::MerkleProof;
|
|
||||||
|
|
||||||
pub const SELF: PodId = PodId(SELF_ID_HASH);
|
pub const SELF: PodId = PodId(SELF_ID_HASH);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,16 @@
|
||||||
|
use std::{fmt, iter};
|
||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use log::error;
|
use log::error;
|
||||||
use plonky2::field::types::Field;
|
use plonky2::field::types::Field;
|
||||||
use serde::{Deserialize, Serialize};
|
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::{
|
use crate::{
|
||||||
backends::plonky2::primitives::merkletree::{MerkleProof, MerkleTree},
|
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)]
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use plonky2::field::types::Field;
|
use plonky2::field::types::Field;
|
||||||
use serde::Deserialize;
|
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>(
|
fn serialize_field_tuple<S, const N: usize>(
|
||||||
value: &[F; N],
|
value: &[F; N],
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,14 @@
|
||||||
|
use std::{fmt, iter};
|
||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use plonky2::field::types::Field;
|
use plonky2::field::types::Field;
|
||||||
use schemars::JsonSchema;
|
use schemars::JsonSchema;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{fmt, iter};
|
|
||||||
use strum_macros::FromRepr;
|
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]
|
// hash(KEY_SIGNER) = [2145458785152392366, 15113074911296146791, 15323228995597834291, 11804480340100333725]
|
||||||
pub const KEY_SIGNER: &str = "_signer";
|
pub const KEY_SIGNER: &str = "_signer";
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
use std::collections::HashMap;
|
use std::{collections::HashMap, fmt::Debug, hash::Hash};
|
||||||
use std::fmt::Debug;
|
|
||||||
use std::hash::Hash;
|
|
||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue