Sfoglia il codice sorgente

crypto/constants.rs: created commonly used MERKLE_DEPT constant

aggstam 4 anni fa
parent
commit
d5c96db14c

+ 1 - 1
bin/ircd/src/main.rs

@@ -75,7 +75,7 @@ impl Ircd {
             .spawn(async move {
                 while let Ok(msg) = p2p_receiver_cloned.recv().await {
                     for (addr, sender) in senders.lock().await.iter() {
-                        // TODO: this need stop signal instead 
+                        // TODO: this need stop signal instead
                         if let Err(e) = sender.send(msg.clone()).await {
                             error!("Can't send msg to the client {}: {}", addr, e);
                             // removing a client sender from the hashmap if any error occured

+ 1 - 3
example/lead.rs

@@ -10,7 +10,7 @@ use rand::{thread_rng, Rng};
 
 use darkfi::{
     crypto::{
-        constants::MERKLE_DEPTH_ORCHARD,
+        constants::{MERKLE_DEPTH_ORCHARD, MERKLE_DEPTH},
         leadcoin::LeadCoin,
         merkle_node::MerkleNode,
         util::{mod_r_p, pedersen_commitment_scalar},
@@ -18,8 +18,6 @@ use darkfi::{
     zk::circuit::lead_contract::LeadContract,
 };
 
-const MERKLE_DEPTH: u8 = MERKLE_DEPTH_ORCHARD as u8;
-
 fn create_coins_sks(len: usize) -> (Vec<MerkleNode>, Vec<[MerkleNode; MERKLE_DEPTH_ORCHARD]>) {
     /*
     at the onset of an epoch, the first slot's coin's secret key

+ 1 - 3
example/tx.rs

@@ -4,7 +4,7 @@ use rand::rngs::OsRng;
 
 use darkfi::{
     crypto::{
-        constants::MERKLE_DEPTH_ORCHARD,
+        constants::MERKLE_DEPTH,
         keypair::{Keypair, PublicKey, SecretKey},
         merkle_node::MerkleNode,
         note::{EncryptedNote, Note},
@@ -23,8 +23,6 @@ use darkfi::{
     Result,
 };
 
-const MERKLE_DEPTH: u8 = MERKLE_DEPTH_ORCHARD as u8;
-
 /// The state machine, held in memory.
 struct MemoryState {
     /// The entire Merkle tree state

+ 2 - 0
src/crypto/constants.rs

@@ -8,6 +8,8 @@ pub const DRK_SCHNORR_DOMAIN: &[u8] = b"DarkFi_Schnorr";
 
 pub const MERKLE_DEPTH_ORCHARD: usize = 32;
 
+pub const MERKLE_DEPTH: u8 = MERKLE_DEPTH_ORCHARD as u8;
+
 #[allow(dead_code)]
 /// $\ell^\mathsf{Orchard}_\mathsf{base}$
 pub(crate) const L_ORCHARD_BASE: usize = 255;

+ 1 - 3
src/node/client.rs

@@ -8,7 +8,7 @@ use crate::{
     crypto::{
         address::Address,
         coin::Coin,
-        constants::MERKLE_DEPTH_ORCHARD,
+        constants::MERKLE_DEPTH,
         keypair::{Keypair, PublicKey},
         merkle_node::MerkleNode,
         proof::ProvingKey,
@@ -29,8 +29,6 @@ use crate::{
     ClientFailed, ClientResult, Result,
 };
 
-const MERKLE_DEPTH: u8 = MERKLE_DEPTH_ORCHARD as u8;
-
 /// The Client structure, used for transaction operations.
 /// This includes, receiving, broadcasting, and building.
 pub struct Client {

+ 2 - 4
src/node/memorystate.rs

@@ -3,12 +3,10 @@ use log::debug;
 
 use super::state::{ProgramState, State, StateUpdate};
 use crate::crypto::{
-    constants::MERKLE_DEPTH_ORCHARD, keypair::PublicKey, merkle_node::MerkleNode,
-    nullifier::Nullifier, proof::VerifyingKey,
+    constants::MERKLE_DEPTH, keypair::PublicKey, merkle_node::MerkleNode, nullifier::Nullifier,
+    proof::VerifyingKey,
 };
 
-const MERKLE_DEPTH: u8 = MERKLE_DEPTH_ORCHARD as u8;
-
 /// In-memory state extension for state transition validations
 #[derive(Clone)]
 pub struct MemoryState {

+ 1 - 3
src/node/state.rs

@@ -7,7 +7,7 @@ use crate::{
     blockchain::{nfstore::NullifierStore, rootstore::RootStore},
     crypto::{
         coin::Coin,
-        constants::MERKLE_DEPTH_ORCHARD,
+        constants::MERKLE_DEPTH,
         keypair::{PublicKey, SecretKey},
         merkle_node::MerkleNode,
         note::{EncryptedNote, Note},
@@ -22,8 +22,6 @@ use crate::{
     Result, VerifyFailed, VerifyResult,
 };
 
-const MERKLE_DEPTH: u8 = MERKLE_DEPTH_ORCHARD as u8;
-
 /// Trait implementing the state functions used by the state transition.
 pub trait ProgramState {
     /// Check if the public key is coming from a trusted cashier

+ 1 - 3
src/wallet/walletdb.rs

@@ -14,7 +14,7 @@ use crate::{
     crypto::{
         address::Address,
         coin::Coin,
-        constants::MERKLE_DEPTH_ORCHARD,
+        constants::MERKLE_DEPTH,
         keypair::{Keypair, PublicKey, SecretKey},
         merkle_node::MerkleNode,
         note::Note,
@@ -32,8 +32,6 @@ use crate::{
     Result,
 };
 
-const MERKLE_DEPTH: u8 = MERKLE_DEPTH_ORCHARD as u8;
-
 pub type WalletPtr = Arc<WalletDb>;
 
 #[derive(Clone, Debug)]