Explorar el Código

Add "crypto" feature.

parazyd hace 4 años
padre
commit
fabafa3e5e

+ 1 - 1
src/crypto/address.rs

@@ -4,7 +4,7 @@ use sha2::Digest;
 
 use crate::{
     crypto::keypair::PublicKey,
-    serial::{Decodable, Encodable, ReadExt, WriteExt},
+    util::serial::{Decodable, Encodable, ReadExt, WriteExt},
     Error, Result,
 };
 

+ 1 - 1
src/crypto/coin.rs

@@ -3,7 +3,7 @@ use std::io;
 use pasta_curves::{arithmetic::FieldExt, pallas};
 
 use crate::{
-    serial::{Decodable, Encodable, ReadExt, WriteExt},
+    util::serial::{Decodable, Encodable, ReadExt, WriteExt},
     Result,
 };
 

+ 4 - 5
src/crypto/keypair.rs

@@ -9,9 +9,8 @@ use pasta_curves::{
 use rand::RngCore;
 
 use crate::{
-    crypto::{constants::OrchardFixedBases, util::mod_r_p},
-    serial::{Decodable, Encodable, ReadExt, WriteExt},
-    util::Address,
+    crypto::{address::Address, constants::OrchardFixedBases, util::mod_r_p},
+    util::serial::{Decodable, Encodable, ReadExt, WriteExt},
     Error, Result,
 };
 
@@ -193,9 +192,9 @@ impl Decodable for PublicKey {
 #[cfg(test)]
 mod tests {
     use super::*;
-    use crate::{
-        crypto::util::pedersen_commitment_scalar,
+    use crate::crypto::{
         serial::{deserialize, serialize},
+        util::pedersen_commitment_scalar,
     };
 
     #[test]

+ 2 - 2
src/crypto/merkle_node.rs

@@ -23,8 +23,8 @@ use crate::{
             L_ORCHARD_MERKLE, MERKLE_DEPTH_ORCHARD,
         },
     },
-    error::Result,
-    serial::{Decodable, Encodable},
+    util::serial::{Decodable, Encodable},
+    Result,
 };
 
 lazy_static! {

+ 2 - 2
src/crypto/mint_proof.rs

@@ -16,10 +16,10 @@ use crate::{
         coin::Coin,
         keypair::PublicKey,
         proof::{Proof, ProvingKey, VerifyingKey},
+        types::{DrkCoinBlind, DrkSerial, DrkTokenId, DrkValue, DrkValueBlind, DrkValueCommit},
         util::{mod_r_p, pedersen_commitment_scalar, pedersen_commitment_u64},
     },
-    serial::{Decodable, Encodable},
-    types::{DrkCoinBlind, DrkSerial, DrkTokenId, DrkValue, DrkValueBlind, DrkValueCommit},
+    util::serial::{Decodable, Encodable},
     zk::circuit::mint_contract::MintContract,
     Result,
 };

+ 4 - 3
src/crypto/mod.rs

@@ -1,3 +1,4 @@
+pub mod address;
 pub mod arith_chip;
 pub mod coin;
 pub mod constants;
@@ -13,9 +14,9 @@ pub mod spend_proof;
 pub mod types;
 pub mod util;
 
-pub(crate) use mint_proof::MintRevealedValues;
-pub(crate) use proof::Proof;
-pub(crate) use spend_proof::SpendRevealedValues;
+pub use mint_proof::MintRevealedValues;
+pub use proof::Proof;
+pub use spend_proof::SpendRevealedValues;
 
 use keypair::SecretKey;
 

+ 2 - 2
src/crypto/note.rs

@@ -7,9 +7,9 @@ use crate::{
     crypto::{
         diffie_hellman::{kdf_sapling, sapling_ka_agree},
         keypair::{PublicKey, SecretKey},
+        types::*,
     },
-    serial::{Decodable, Encodable, ReadExt, WriteExt},
-    types::*,
+    util::serial::{Decodable, Encodable, ReadExt, WriteExt},
     Error, Result,
 };
 

+ 1 - 1
src/crypto/nullifier.rs

@@ -8,7 +8,7 @@ use pasta_curves::{arithmetic::FieldExt, pallas};
 
 use crate::{
     crypto::keypair::SecretKey,
-    serial::{Decodable, Encodable, ReadExt, WriteExt},
+    util::serial::{Decodable, Encodable, ReadExt, WriteExt},
     Result,
 };
 

+ 2 - 2
src/crypto/proof.rs

@@ -10,8 +10,8 @@ use halo2::{
 use pasta_curves::vesta;
 
 use crate::{
-    serial::{encode_with_size, Decodable, Encodable, ReadExt, VarInt},
-    types::*,
+    crypto::types::*,
+    util::serial::{encode_with_size, Decodable, Encodable, ReadExt, VarInt},
     Result,
 };
 

+ 1 - 1
src/crypto/schnorr.rs

@@ -10,7 +10,7 @@ use crate::{
         keypair::{PublicKey, SecretKey},
         util::{hash_to_scalar, mod_r_p},
     },
-    serial::{Decodable, Encodable},
+    util::serial::{Decodable, Encodable},
     Result,
 };
 

+ 2 - 2
src/crypto/spend_proof.rs

@@ -21,9 +21,9 @@ use crate::{
     crypto::{
         keypair::{PublicKey, SecretKey},
         merkle_node::MerkleNode,
+        types::*,
     },
-    serial::{Decodable, Encodable},
-    types::*,
+    util::serial::{Decodable, Encodable},
     zk::circuit::spend_contract::SpendContract,
     Result,
 };

+ 1 - 1
src/crypto/util.rs

@@ -8,7 +8,7 @@ use pasta_curves::{
 use super::constants::fixed_bases::{
     VALUE_COMMITMENT_PERSONALIZATION, VALUE_COMMITMENT_R_BYTES, VALUE_COMMITMENT_V_BYTES,
 };
-use crate::types::*;
+use crate::crypto::types::*;
 
 pub fn hash_to_scalar(persona: &[u8], a: &[u8], b: &[u8]) -> pallas::Scalar {
     let mut hasher = Params::new().hash_length(64).personal(persona).to_state();

+ 28 - 22
src/error.rs

@@ -72,22 +72,25 @@ pub enum Error {
     // /// Contract
     // #[error("Bad variable ref type byte")]
     // BadVariableRefType,
-    // #[error("Bad operation type byte")]
-    // BadOperationType,
+    #[error("Bad operation type byte")]
+    BadOperationType,
     // #[error("Bad constraint type byte")]
     // BadConstraintType,
-    // #[error("Invalid param name")]
-    // InvalidParamName,
-    // #[error("Invalid param type")]
-    // InvalidParamType,
+    #[error("Invalid param name")]
+    InvalidParamName,
+    #[error("Invalid param type")]
+    InvalidParamType,
     // #[error("Missing params")]
     // MissingParams,
     // #[error("Contract is poorly defined")]
     // BadContract,
-    // #[error("PLONK error: `{0}`")]
-    // PlonkError(String),
-    // #[error("Unable to decrypt mint note")]
-    // NoteDecryptionFailed,
+    #[cfg(feature = "crypto")]
+    #[error("PLONK error: `{0}`")]
+    PlonkError(String),
+
+    #[cfg(feature = "crypto")]
+    #[error("Unable to decrypt mint note")]
+    NoteDecryptionFailed,
 
     // #[cfg(feature = "node")]
     // #[error(transparent)]
@@ -162,15 +165,17 @@ pub enum Error {
     // #[error(transparent)]
     // AsyncChannelReceiverError(#[from] async_channel::RecvError),
 
-    // /// Keypari & Address
     // #[error("Error converting Address to PublicKey")]
     // AddressToPublicKeyError,
-    // #[error("Error converting bytes to PublicKey")]
-    // PublicKeyFromBytes,
-    // #[error("Error converting bytes to SecretKey")]
-    // SecretKeyFromBytes,
-    // #[error("Invalid Address")]
-    // InvalidAddress,
+    #[cfg(feature = "crypto")]
+    #[error("Error converting bytes to PublicKey")]
+    PublicKeyFromBytes,
+    #[cfg(feature = "crypto")]
+    #[error("Error converting bytes to SecretKey")]
+    SecretKeyFromBytes,
+    #[cfg(feature = "crypto")]
+    #[error("Invalid Address")]
+    InvalidAddress,
 }
 
 // #[cfg(feature = "node")]
@@ -247,11 +252,12 @@ impl From<tungstenite::Error> for Error {
     }
 }
 
-// impl From<halo2::plonk::Error> for Error {
-// fn from(err: halo2::plonk::Error) -> Error {
-// Error::PlonkError(format!("{:?}", err))
-// }
-// }
+#[cfg(feature = "crypto")]
+impl From<halo2::plonk::Error> for Error {
+    fn from(err: halo2::plonk::Error) -> Error {
+        Error::PlonkError(format!("{:?}", err))
+    }
+}
 
 // impl From<Box<bincode::ErrorKind>> for Error {
 // fn from(err: Box<bincode::ErrorKind>) -> Error {

+ 1 - 1
src/zk/vm_serial.rs

@@ -4,7 +4,7 @@ use super::vm::{ZkBinary, ZkContract, ZkFunctionCall, ZkType};
 use crate::{
     error::{Error, Result},
     impl_vec,
-    serial::{Decodable, Encodable, ReadExt, VarInt},
+    util::serial::{Decodable, Encodable, ReadExt, VarInt},
 };
 
 impl_vec!((String, ZkType));