Просмотр исходного кода

cleanup imports by flattening everything to submodules.

x 3 лет назад
Родитель
Сommit
9cd9c3113e

+ 5 - 0
src/consensus/mod.rs

@@ -22,6 +22,10 @@ pub use block::{Block, BlockInfo, BlockProposal, Header};
 
 
 /// Constants
 /// Constants
 pub mod constants;
 pub mod constants;
+pub use constants::{
+    TESTNET_BOOTSTRAP_TIMESTAMP, TESTNET_GENESIS_HASH_BYTES, TESTNET_GENESIS_TIMESTAMP,
+    TESTNET_INITIAL_DISTRIBUTION,
+};
 
 
 /// Consensus block leader information
 /// Consensus block leader information
 pub mod lead_info;
 pub mod lead_info;
@@ -47,6 +51,7 @@ pub use clock::{Clock, Ticks};
 
 
 /// Consensus participation coin functions and definitions
 /// Consensus participation coin functions and definitions
 pub mod leadcoin;
 pub mod leadcoin;
+pub use leadcoin::LeadCoin;
 
 
 /// Utility types
 /// Utility types
 pub mod types;
 pub mod types;

+ 3 - 8
src/contract/dao/src/dao_client/exec.rs

@@ -16,9 +16,8 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
  */
 
 
-use darkfi_sdk::{
-    crypto::{pedersen::pedersen_commitment_u64, poseidon_hash, SecretKey},
-    pasta::{arithmetic::CurveAffine, group::Curve, pallas},
+use darkfi_sdk::crypto::{
+    pallas, pasta_prelude::*, pedersen_commitment_u64, poseidon_hash, SecretKey,
 };
 };
 
 
 use halo2_proofs::circuit::Value;
 use halo2_proofs::circuit::Value;
@@ -26,11 +25,7 @@ use log::debug;
 use rand::rngs::OsRng;
 use rand::rngs::OsRng;
 
 
 use darkfi::{
 use darkfi::{
-    zk::{
-        proof::{Proof, ProvingKey},
-        vm::ZkCircuit,
-        vm_stack::Witness,
-    },
+    zk::{Proof, ProvingKey, Witness, ZkCircuit},
     zkas::ZkBinary,
     zkas::ZkBinary,
     Result,
     Result,
 };
 };

+ 2 - 6
src/contract/dao/src/dao_client/mint.rs

@@ -17,15 +17,11 @@
  */
  */
 
 
 use darkfi::{
 use darkfi::{
-    zk::{proof::ProvingKey, vm::ZkCircuit, vm_stack::Witness, Proof},
+    zk::{Proof, ProvingKey, Value, Witness, ZkCircuit},
     zkas::ZkBinary,
     zkas::ZkBinary,
     Result,
     Result,
 };
 };
-use darkfi_sdk::{
-    crypto::{poseidon_hash, PublicKey, TokenId},
-    pasta::pallas,
-};
-use halo2_proofs::circuit::Value;
+use darkfi_sdk::crypto::{pallas, poseidon_hash, PublicKey, TokenId};
 use log::debug;
 use log::debug;
 use rand::rngs::OsRng;
 use rand::rngs::OsRng;
 
 

+ 6 - 19
src/contract/dao/src/dao_client/propose.rs

@@ -16,28 +16,15 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
  */
 
 
-use darkfi_sdk::{
-    crypto::{
-        pedersen::pedersen_commitment_u64, poseidon_hash, MerkleNode, PublicKey, SecretKey, TokenId,
-    },
-    incrementalmerkletree,
-    incrementalmerkletree::Hashable,
-    pasta::{
-        arithmetic::CurveAffine,
-        group::{ff::Field, Curve},
-        pallas,
-    },
+use darkfi_sdk::crypto::{
+    merkle_prelude::*, pallas, pasta_prelude::*, pedersen::pedersen_commitment_u64, poseidon_hash,
+    MerkleNode, MerklePosition, PublicKey, SecretKey, TokenId,
 };
 };
 use darkfi_serial::{SerialDecodable, SerialEncodable};
 use darkfi_serial::{SerialDecodable, SerialEncodable};
-use halo2_proofs::circuit::Value;
 use rand::rngs::OsRng;
 use rand::rngs::OsRng;
 
 
 use darkfi::{
 use darkfi::{
-    zk::{
-        proof::{Proof, ProvingKey},
-        vm::ZkCircuit,
-        vm_stack::Witness,
-    },
+    zk::{Proof, ProvingKey, Value, Witness, ZkCircuit},
     zkas::ZkBinary,
     zkas::ZkBinary,
     Result,
     Result,
 };
 };
@@ -58,7 +45,7 @@ pub struct ProposalStakeInput {
     pub secret: SecretKey,
     pub secret: SecretKey,
     //pub note: money::transfer::wallet::Note,
     //pub note: money::transfer::wallet::Note,
     pub note: darkfi_money_contract::client::Note,
     pub note: darkfi_money_contract::client::Note,
-    pub leaf_position: incrementalmerkletree::Position,
+    pub leaf_position: MerklePosition,
     pub merkle_path: Vec<MerkleNode>,
     pub merkle_path: Vec<MerkleNode>,
     pub signature_secret: SecretKey,
     pub signature_secret: SecretKey,
 }
 }
@@ -76,7 +63,7 @@ pub struct ProposeCall {
     pub inputs: Vec<ProposalStakeInput>,
     pub inputs: Vec<ProposalStakeInput>,
     pub proposal: Proposal,
     pub proposal: Proposal,
     pub dao: Dao,
     pub dao: Dao,
-    pub dao_leaf_position: incrementalmerkletree::Position,
+    pub dao_leaf_position: MerklePosition,
     pub dao_merkle_path: Vec<MerkleNode>,
     pub dao_merkle_path: Vec<MerkleNode>,
     pub dao_merkle_root: MerkleNode,
     pub dao_merkle_root: MerkleNode,
 }
 }

+ 5 - 40
src/contract/dao/src/dao_client/vote.rs

@@ -16,30 +16,16 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
  */
 
 
-use darkfi_sdk::{
-    crypto::{
-        keypair::Keypair, pedersen::pedersen_commitment_u64, poseidon_hash, MerkleNode, Nullifier,
-        PublicKey, SecretKey,
-    },
-    incrementalmerkletree,
-    incrementalmerkletree::Hashable,
-    pasta::{
-        arithmetic::CurveAffine,
-        group::{ff::Field, Curve},
-        pallas,
-    },
+use darkfi_sdk::crypto::{
+    merkle_prelude::*, pallas, pasta_prelude::*, pedersen_commitment_u64, poseidon_hash, Keypair,
+    MerkleNode, MerklePosition, Nullifier, PublicKey, SecretKey,
 };
 };
 use darkfi_serial::{SerialDecodable, SerialEncodable};
 use darkfi_serial::{SerialDecodable, SerialEncodable};
-use halo2_proofs::circuit::Value;
 use log::debug;
 use log::debug;
 use rand::rngs::OsRng;
 use rand::rngs::OsRng;
 
 
 use darkfi::{
 use darkfi::{
-    zk::{
-        proof::{Proof, ProvingKey},
-        vm::ZkCircuit,
-        vm_stack::Witness,
-    },
+    zk::{Proof, ProvingKey, Value, Witness, ZkCircuit},
     zkas::ZkBinary,
     zkas::ZkBinary,
     Result,
     Result,
 };
 };
@@ -67,7 +53,7 @@ pub struct BuilderInput {
     pub secret: SecretKey,
     pub secret: SecretKey,
     //pub note: money::transfer::wallet::Note,
     //pub note: money::transfer::wallet::Note,
     pub note: darkfi_money_contract::client::Note,
     pub note: darkfi_money_contract::client::Note,
-    pub leaf_position: incrementalmerkletree::Position,
+    pub leaf_position: MerklePosition,
     pub merkle_path: Vec<MerkleNode>,
     pub merkle_path: Vec<MerkleNode>,
     pub signature_secret: SecretKey,
     pub signature_secret: SecretKey,
 }
 }
@@ -107,17 +93,6 @@ impl Builder {
 
 
             let signature_public = PublicKey::from_secret(input.signature_secret);
             let signature_public = PublicKey::from_secret(input.signature_secret);
 
 
-            /*
-            let zk_info = zk_bins.lookup(&"dao-vote-burn".to_string()).unwrap();
-
-            let zk_info = if let ZkContractInfo::Binary(info) = zk_info {
-                info
-            } else {
-                panic!("Not binary info")
-            };
-            let zk_bin = zk_info.bincode.clone();
-            */
-
             // Note from the previous output
             // Note from the previous output
             let note = input.note;
             let note = input.note;
             let leaf_pos: u64 = input.leaf_position.into();
             let leaf_pos: u64 = input.leaf_position.into();
@@ -246,16 +221,6 @@ impl Builder {
         let all_vote_commit = pedersen_commitment_u64(vote_value, vote_value_blind);
         let all_vote_commit = pedersen_commitment_u64(vote_value, vote_value_blind);
         let all_vote_commit_coords = all_vote_commit.to_affine().coordinates().unwrap();
         let all_vote_commit_coords = all_vote_commit.to_affine().coordinates().unwrap();
 
 
-        /*
-        let zk_info = zk_bins.lookup(&"dao-vote-main".to_string()).unwrap();
-        let zk_info = if let ZkContractInfo::Binary(info) = zk_info {
-            info
-        } else {
-            panic!("Not binary info")
-        };
-        let zk_bin = zk_info.bincode.clone();
-        */
-
         let prover_witnesses = vec![
         let prover_witnesses = vec![
             // proposal params
             // proposal params
             Witness::Base(Value::known(proposal_dest_x)),
             Witness::Base(Value::known(proposal_dest_x)),

+ 1 - 4
src/contract/dao/src/dao_model.rs

@@ -16,10 +16,7 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
  */
 
 
-use darkfi_sdk::{
-    crypto::{MerkleNode, Nullifier, PublicKey},
-    pasta::{group::Group, pallas},
-};
+use darkfi_sdk::crypto::{pallas, pasta_prelude::*, MerkleNode, Nullifier, PublicKey};
 use darkfi_serial::{SerialDecodable, SerialEncodable};
 use darkfi_serial::{SerialDecodable, SerialEncodable};
 
 
 #[derive(SerialEncodable, SerialDecodable)]
 #[derive(SerialEncodable, SerialDecodable)]

+ 3 - 12
src/contract/dao/src/entrypoint.rs

@@ -20,22 +20,14 @@ use std::io::Cursor;
 
 
 use darkfi_sdk::{
 use darkfi_sdk::{
     crypto::{
     crypto::{
-        contract_id::{DAO_CONTRACT_ID, MONEY_CONTRACT_ID},
-        ContractId, MerkleNode, MerkleTree, PublicKey,
+        pallas, pasta_prelude::*, ContractId, MerkleNode, MerkleTree, PublicKey, DAO_CONTRACT_ID,
+        MONEY_CONTRACT_ID,
     },
     },
     db::{
     db::{
         db_contains_key, db_del, db_get, db_init, db_lookup, db_set, SMART_CONTRACT_ZKAS_DB_NAME,
         db_contains_key, db_del, db_get, db_init, db_lookup, db_set, SMART_CONTRACT_ZKAS_DB_NAME,
     },
     },
     error::{ContractError, ContractResult},
     error::{ContractError, ContractResult},
-    merkle::merkle_add,
-    msg,
-    pasta::{
-        arithmetic::CurveAffine,
-        group::{Curve, Group},
-        pallas,
-    },
-    tx::ContractCall,
-    util::set_return_data,
+    merkle_add, msg, set_return_data, ContractCall,
 };
 };
 use darkfi_serial::{deserialize, serialize, Decodable, Encodable, WriteExt};
 use darkfi_serial::{deserialize, serialize, Decodable, Encodable, WriteExt};
 
 
@@ -242,7 +234,6 @@ fn process_instruction(cid: ContractId, ix: &[u8]) -> ContractResult {
             let mut proposal_votes: ProposalVotes = deserialize(&proposal_votes)?;
             let mut proposal_votes: ProposalVotes = deserialize(&proposal_votes)?;
 
 
             // Check the Merkle roots and nullifiers for the input coins are valid
             // Check the Merkle roots and nullifiers for the input coins are valid
-            // TODO: vote_nullifiers is useless
             let money_roots_db = db_lookup(money_cid, MONEY_CONTRACT_COIN_ROOTS_TREE)?;
             let money_roots_db = db_lookup(money_cid, MONEY_CONTRACT_COIN_ROOTS_TREE)?;
             let money_nullifier_db = db_lookup(money_cid, MONEY_CONTRACT_NULLIFIERS_TREE)?;
             let money_nullifier_db = db_lookup(money_cid, MONEY_CONTRACT_NULLIFIERS_TREE)?;
             let dao_vote_nulls_db = db_lookup(cid, DAO_VOTE_NULLS)?;
             let dao_vote_nulls_db = db_lookup(cid, DAO_VOTE_NULLS)?;

+ 4 - 42
src/contract/dao/src/money_client.rs

@@ -17,14 +17,12 @@
  */
  */
 
 
 use darkfi::{
 use darkfi::{
-    zk::proof::{Proof, ProvingKey},
+    zk::{Proof, ProvingKey},
     zkas::ZkBinary,
     zkas::ZkBinary,
     Result,
     Result,
 };
 };
-use darkfi_sdk::{
-    crypto::{pedersen::ValueBlind, MerkleNode, PublicKey, SecretKey, TokenId},
-    incrementalmerkletree,
-    pasta::{group::ff::Field, pallas},
+use darkfi_sdk::crypto::{
+    pallas, pasta_prelude::*, MerkleNode, MerklePosition, PublicKey, SecretKey, TokenId, ValueBlind,
 };
 };
 
 
 use rand::rngs::OsRng;
 use rand::rngs::OsRng;
@@ -34,42 +32,6 @@ use darkfi_money_contract::{
     state::{ClearInput, Input, MoneyTransferParams, Output},
     state::{ClearInput, Input, MoneyTransferParams, Output},
 };
 };
 
 
-/*
-use darkfi::{
-    crypto::{
-        burn_proof::create_burn_proof,
-        mint_proof::create_mint_proof,
-        types::{
-            DrkCoinBlind, DrkSerial, DrkSpendHook, DrkUserData, DrkUserDataBlind, DrkValueBlind,
-        },
-    },
-    Result,
-};
-
-use crate::{
-    contract::money::{
-        transfer::validate::{CallData, ClearInput, Input, Output},
-        CONTRACT_ID,
-    },
-    note,
-    util::{FuncCall, ZkContractInfo, ZkContractTable},
-};
-*/
-
-/*
-#[derive(Clone, SerialEncodable, SerialDecodable)]
-pub struct Note {
-    pub serial: DrkSerial,
-    pub value: u64,
-    pub token_id: TokenId,
-    pub spend_hook: DrkSpendHook,
-    pub user_data: DrkUserData,
-    pub coin_blind: DrkCoinBlind,
-    pub value_blind: DrkValueBlind,
-    pub token_blind: DrkValueBlind,
-}
-*/
-
 pub struct Builder {
 pub struct Builder {
     pub clear_inputs: Vec<BuilderClearInputInfo>,
     pub clear_inputs: Vec<BuilderClearInputInfo>,
     pub inputs: Vec<BuilderInputInfo>,
     pub inputs: Vec<BuilderInputInfo>,
@@ -83,7 +45,7 @@ pub struct BuilderClearInputInfo {
 }
 }
 
 
 pub struct BuilderInputInfo {
 pub struct BuilderInputInfo {
-    pub leaf_position: incrementalmerkletree::Position,
+    pub leaf_position: MerklePosition,
     pub merkle_path: Vec<MerkleNode>,
     pub merkle_path: Vec<MerkleNode>,
     pub secret: SecretKey,
     pub secret: SecretKey,
     pub note: Note,
     pub note: Note,

+ 5 - 8
src/contract/dao/src/note.rs

@@ -17,10 +17,7 @@
  */
  */
 
 
 use chacha20poly1305::{AeadInPlace, ChaCha20Poly1305, KeyInit};
 use chacha20poly1305::{AeadInPlace, ChaCha20Poly1305, KeyInit};
-use darkfi_sdk::crypto::{
-    diffie_hellman::{kdf_sapling, sapling_ka_agree},
-    PublicKey, SecretKey,
-};
+use darkfi_sdk::crypto::{diffie_hellman, PublicKey, SecretKey};
 use darkfi_serial::{Decodable, Encodable, SerialDecodable, SerialEncodable};
 use darkfi_serial::{Decodable, Encodable, SerialDecodable, SerialEncodable};
 use rand::rngs::OsRng;
 use rand::rngs::OsRng;
 
 
@@ -31,8 +28,8 @@ pub const AEAD_TAG_SIZE: usize = 16;
 pub fn encrypt<T: Encodable>(note: &T, public: &PublicKey) -> Result<EncryptedNote2> {
 pub fn encrypt<T: Encodable>(note: &T, public: &PublicKey) -> Result<EncryptedNote2> {
     let ephem_secret = SecretKey::random(&mut OsRng);
     let ephem_secret = SecretKey::random(&mut OsRng);
     let ephem_public = PublicKey::from_secret(ephem_secret);
     let ephem_public = PublicKey::from_secret(ephem_secret);
-    let shared_secret = sapling_ka_agree(&ephem_secret, public);
-    let key = kdf_sapling(&shared_secret, &ephem_public);
+    let shared_secret = diffie_hellman::sapling_ka_agree(&ephem_secret, public);
+    let key = diffie_hellman::kdf_sapling(&shared_secret, &ephem_public);
 
 
     let mut input = Vec::new();
     let mut input = Vec::new();
     note.encode(&mut input)?;
     note.encode(&mut input)?;
@@ -56,8 +53,8 @@ pub struct EncryptedNote2 {
 
 
 impl EncryptedNote2 {
 impl EncryptedNote2 {
     pub fn decrypt<T: Decodable>(&self, secret: &SecretKey) -> Result<T> {
     pub fn decrypt<T: Decodable>(&self, secret: &SecretKey) -> Result<T> {
-        let shared_secret = sapling_ka_agree(secret, &self.ephem_public);
-        let key = kdf_sapling(&shared_secret, &self.ephem_public);
+        let shared_secret = diffie_hellman::sapling_ka_agree(secret, &self.ephem_public);
+        let key = diffie_hellman::kdf_sapling(&shared_secret, &self.ephem_public);
 
 
         let ciphertext_len = self.ciphertext.len();
         let ciphertext_len = self.ciphertext.len();
         let mut plaintext = vec![0_u8; ciphertext_len];
         let mut plaintext = vec![0_u8; ciphertext_len];

+ 3 - 7
src/contract/dao/src/wallet_cache.rs

@@ -16,20 +16,16 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
  */
 
 
-use darkfi_sdk::{
-    crypto::{coin::Coin, constants::MERKLE_DEPTH, MerkleNode, SecretKey},
-    incrementalmerkletree,
-    incrementalmerkletree::{bridgetree::BridgeTree, Tree},
+use darkfi_sdk::crypto::{
+    merkle_prelude::*, Coin, MerkleNode, MerklePosition, MerkleTree, SecretKey,
 };
 };
 
 
 use darkfi_money_contract::client::{EncryptedNote, Note};
 use darkfi_money_contract::client::{EncryptedNote, Note};
 
 
-pub type MerkleTree = BridgeTree<MerkleNode, { MERKLE_DEPTH }>;
-
 pub struct OwnCoin {
 pub struct OwnCoin {
     pub coin: Coin,
     pub coin: Coin,
     pub note: Note,
     pub note: Note,
-    pub leaf_position: incrementalmerkletree::Position,
+    pub leaf_position: MerklePosition,
 }
 }
 
 
 pub struct WalletCache {
 pub struct WalletCache {

+ 4 - 11
src/contract/dao/tests/harness.rs

@@ -19,24 +19,17 @@ use std::collections::HashMap;
 
 
 use darkfi::{
 use darkfi::{
     consensus::{
     consensus::{
-        constants::{
-            TESTNET_BOOTSTRAP_TIMESTAMP, TESTNET_GENESIS_HASH_BYTES, TESTNET_GENESIS_TIMESTAMP,
-            TESTNET_INITIAL_DISTRIBUTION,
-        },
-        ValidatorState, ValidatorStatePtr,
+        ValidatorState, ValidatorStatePtr, TESTNET_BOOTSTRAP_TIMESTAMP, TESTNET_GENESIS_HASH_BYTES,
+        TESTNET_GENESIS_TIMESTAMP, TESTNET_INITIAL_DISTRIBUTION,
     },
     },
     wallet::WalletDb,
     wallet::WalletDb,
-    zk::{proof::ProvingKey, vm::ZkCircuit, vm_stack::empty_witnesses},
+    zk::{empty_witnesses, ProvingKey, ZkCircuit},
     zkas::ZkBinary,
     zkas::ZkBinary,
     Result,
     Result,
 };
 };
 use darkfi_sdk::{
 use darkfi_sdk::{
-    crypto::{
-        contract_id::{DAO_CONTRACT_ID, MONEY_CONTRACT_ID},
-        ContractId, Keypair,
-    },
+    crypto::{pasta_prelude::*, ContractId, Keypair, DAO_CONTRACT_ID, MONEY_CONTRACT_ID},
     db::SMART_CONTRACT_ZKAS_DB_NAME,
     db::SMART_CONTRACT_ZKAS_DB_NAME,
-    pasta::group::ff::PrimeField,
 };
 };
 use darkfi_serial::serialize;
 use darkfi_serial::serialize;
 use log::{info, warn};
 use log::{info, warn};

+ 4 - 13
src/contract/dao/tests/integration.rs

@@ -19,19 +19,10 @@
 use darkfi::{tx::Transaction, Result};
 use darkfi::{tx::Transaction, Result};
 use darkfi_sdk::{
 use darkfi_sdk::{
     crypto::{
     crypto::{
-        coin::Coin,
-        contract_id::{DAO_CONTRACT_ID, MONEY_CONTRACT_ID},
-        keypair::Keypair,
-        pedersen::pedersen_commitment_u64,
-        poseidon_hash, MerkleNode, SecretKey, TokenId,
+        merkle_prelude::*, pallas, pasta_prelude::*, pedersen_commitment_u64, poseidon_hash, Coin,
+        Keypair, MerkleNode, MerkleTree, SecretKey, TokenId, DAO_CONTRACT_ID, MONEY_CONTRACT_ID,
     },
     },
-    incrementalmerkletree::Tree,
-    pasta::{
-        arithmetic::CurveAffine,
-        group::{ff::Field, Curve, Group},
-        pallas,
-    },
-    tx::ContractCall,
+    ContractCall,
 };
 };
 use darkfi_serial::{Decodable, Encodable};
 use darkfi_serial::{Decodable, Encodable};
 use log::debug;
 use log::debug;
@@ -41,7 +32,7 @@ use darkfi_dao_contract::{
     dao_client,
     dao_client,
     dao_client::{exec as dao_exec_client, propose as dao_propose_client, vote as dao_vote_client},
     dao_client::{exec as dao_exec_client, propose as dao_propose_client, vote as dao_vote_client},
     money_client, note,
     money_client, note,
-    wallet_cache::{MerkleTree, WalletCache},
+    wallet_cache::WalletCache,
     DaoFunction,
     DaoFunction,
 };
 };
 
 

+ 22 - 36
src/contract/money/src/client.rs

@@ -27,32 +27,18 @@
 
 
 use chacha20poly1305::{AeadInPlace, ChaCha20Poly1305, KeyInit};
 use chacha20poly1305::{AeadInPlace, ChaCha20Poly1305, KeyInit};
 use darkfi::{
 use darkfi::{
-    consensus::leadcoin::LeadCoin,
-    zk::{
-        proof::{Proof, ProvingKey},
-        vm::ZkCircuit,
-        vm_stack::Witness,
-    },
+    consensus::LeadCoin,
+    zk::{Proof, ProvingKey, Witness, ZkCircuit},
     zkas::ZkBinary,
     zkas::ZkBinary,
     ClientFailed, Error, Result,
     ClientFailed, Error, Result,
 };
 };
-use darkfi_sdk::{
-    crypto::{
-        constants::MERKLE_DEPTH,
-        diffie_hellman::{kdf_sapling, sapling_ka_agree},
-        pedersen::{pedersen_commitment_base, pedersen_commitment_u64, ValueBlind, ValueCommit},
-        poseidon_hash, Keypair, MerkleNode, Nullifier, PublicKey, SecretKey, TokenId,
-    },
-    incrementalmerkletree,
-    incrementalmerkletree::{bridgetree::BridgeTree, Hashable, Tree},
-    pasta::{
-        arithmetic::CurveAffine,
-        group::{
-            ff::{Field, PrimeField},
-            Curve,
-        },
-        pallas,
-    },
+use darkfi_sdk::crypto::{
+    diffie_hellman::{kdf_sapling, sapling_ka_agree},
+    merkle_prelude::*,
+    pallas,
+    pasta_prelude::*,
+    pedersen_commitment_base, pedersen_commitment_u64, poseidon_hash, Keypair, MerkleNode,
+    MerklePosition, MerkleTree, Nullifier, PublicKey, SecretKey, TokenId, ValueBlind, ValueCommit,
 };
 };
 use darkfi_serial::{serialize, Decodable, Encodable, SerialDecodable, SerialEncodable};
 use darkfi_serial::{serialize, Decodable, Encodable, SerialDecodable, SerialEncodable};
 use halo2_proofs::circuit::Value;
 use halo2_proofs::circuit::Value;
@@ -136,7 +122,7 @@ pub struct OwnCoin {
     /// Coin's nullifier,
     /// Coin's nullifier,
     pub nullifier: Nullifier,
     pub nullifier: Nullifier,
     /// Coin's leaf position in the Merkle tree of coins
     /// Coin's leaf position in the Merkle tree of coins
-    pub leaf_position: incrementalmerkletree::Position,
+    pub leaf_position: MerklePosition,
 }
 }
 
 
 /// The `Note` holds the inner attributes of a `Coin`
 /// The `Note` holds the inner attributes of a `Coin`
@@ -227,7 +213,7 @@ struct TransactionBuilderClearInputInfo {
 }
 }
 
 
 struct TransactionBuilderInputInfo {
 struct TransactionBuilderInputInfo {
-    pub leaf_position: incrementalmerkletree::Position,
+    pub leaf_position: MerklePosition,
     pub merkle_path: Vec<MerkleNode>,
     pub merkle_path: Vec<MerkleNode>,
     pub secret: SecretKey,
     pub secret: SecretKey,
     pub note: Note,
     pub note: Note,
@@ -262,7 +248,7 @@ impl TransferBurnRevealed {
         user_data_blind: pallas::Base,
         user_data_blind: pallas::Base,
         coin_blind: pallas::Base,
         coin_blind: pallas::Base,
         secret_key: SecretKey,
         secret_key: SecretKey,
-        leaf_position: incrementalmerkletree::Position,
+        leaf_position: MerklePosition,
         merkle_path: Vec<MerkleNode>,
         merkle_path: Vec<MerkleNode>,
         signature_secret: SecretKey,
         signature_secret: SecretKey,
     ) -> Self {
     ) -> Self {
@@ -450,7 +436,7 @@ pub fn create_transfer_burn_proof(
     user_data_blind: pallas::Base,
     user_data_blind: pallas::Base,
     coin_blind: pallas::Base,
     coin_blind: pallas::Base,
     secret_key: SecretKey,
     secret_key: SecretKey,
-    leaf_position: incrementalmerkletree::Position,
+    leaf_position: MerklePosition,
     merkle_path: Vec<MerkleNode>,
     merkle_path: Vec<MerkleNode>,
     signature_secret: SecretKey,
     signature_secret: SecretKey,
 ) -> Result<(Proof, TransferBurnRevealed)> {
 ) -> Result<(Proof, TransferBurnRevealed)> {
@@ -602,12 +588,12 @@ fn create_unstake_burn_proof(
     public_key: pallas::Base,
     public_key: pallas::Base,
     sk: pallas::Base,
     sk: pallas::Base,
     sk_root: pallas::Base,
     sk_root: pallas::Base,
-    sk_pos: incrementalmerkletree::Position,
+    sk_pos: MerklePosition,
     sk_path: Vec<MerkleNode>,
     sk_path: Vec<MerkleNode>,
     commitment_merkle_path: Vec<MerkleNode>,
     commitment_merkle_path: Vec<MerkleNode>,
     commitment: pallas::Point,
     commitment: pallas::Point,
     commitment_root: pallas::Base,
     commitment_root: pallas::Base,
-    commitment_pos: incrementalmerkletree::Position,
+    commitment_pos: MerklePosition,
     slot: u64,
     slot: u64,
     nonce: pallas::Base,
     nonce: pallas::Base,
     nullifier: pallas::Base,
     nullifier: pallas::Base,
@@ -665,7 +651,7 @@ pub fn build_half_swap_tx(
     value_blinds: &[ValueBlind],
     value_blinds: &[ValueBlind],
     token_blinds: &[ValueBlind],
     token_blinds: &[ValueBlind],
     coins: &[OwnCoin],
     coins: &[OwnCoin],
-    tree: &BridgeTree<MerkleNode, MERKLE_DEPTH>,
+    tree: &MerkleTree,
     mint_zkbin: &ZkBinary,
     mint_zkbin: &ZkBinary,
     mint_pk: &ProvingKey,
     mint_pk: &ProvingKey,
     burn_zkbin: &ZkBinary,
     burn_zkbin: &ZkBinary,
@@ -856,7 +842,7 @@ pub fn build_transfer_tx(
     value: u64,
     value: u64,
     token_id: TokenId,
     token_id: TokenId,
     coins: &[OwnCoin],
     coins: &[OwnCoin],
-    tree: &BridgeTree<MerkleNode, MERKLE_DEPTH>,
+    tree: &MerkleTree,
     mint_zkbin: &ZkBinary,
     mint_zkbin: &ZkBinary,
     mint_pk: &ProvingKey,
     mint_pk: &ProvingKey,
     burn_zkbin: &ZkBinary,
     burn_zkbin: &ZkBinary,
@@ -1070,9 +1056,9 @@ pub fn build_transfer_tx(
 pub fn build_stake_tx(
 pub fn build_stake_tx(
     //pubkey: &PublicKey,
     //pubkey: &PublicKey,
     coins: &[OwnCoin],
     coins: &[OwnCoin],
-    tx_tree: &mut BridgeTree<MerkleNode, MERKLE_DEPTH>,
-    cm_tree: &mut BridgeTree<MerkleNode, MERKLE_DEPTH>,
-    sk_tree: &mut BridgeTree<MerkleNode, MERKLE_DEPTH>,
+    tx_tree: &mut MerkleTree,
+    cm_tree: &mut MerkleTree,
+    sk_tree: &mut MerkleTree,
     mint_zkbin: &ZkBinary,
     mint_zkbin: &ZkBinary,
     mint_pk: &ProvingKey,
     mint_pk: &ProvingKey,
     burn_zkbin: &ZkBinary,
     burn_zkbin: &ZkBinary,
@@ -1204,12 +1190,12 @@ pub fn build_unstake_tx(
             pk,
             pk,
             coin.coin1_sk,
             coin.coin1_sk,
             coin.coin1_sk_root.inner(),
             coin.coin1_sk_root.inner(),
-            incrementalmerkletree::Position::from(coin.coin1_sk_pos as usize),
+            MerklePosition::from(coin.coin1_sk_pos as usize),
             coin.coin1_sk_merkle_path.to_vec(),
             coin.coin1_sk_merkle_path.to_vec(),
             coin.coin1_commitment_merkle_path.to_vec(),
             coin.coin1_commitment_merkle_path.to_vec(),
             coin.coin1_commitment,
             coin.coin1_commitment,
             coin.coin1_commitment_root.inner(),
             coin.coin1_commitment_root.inner(),
-            incrementalmerkletree::Position::from(coin.coin1_commitment_pos as usize),
+            MerklePosition::from(coin.coin1_commitment_pos as usize),
             coin.slot,
             coin.slot,
             coin.nonce,
             coin.nonce,
             nullifier,
             nullifier,

+ 3 - 11
src/contract/money/src/lib.rs

@@ -19,21 +19,13 @@
 #[cfg(not(feature = "no-entrypoint"))]
 #[cfg(not(feature = "no-entrypoint"))]
 use darkfi_sdk::{
 use darkfi_sdk::{
     crypto::{
     crypto::{
-        pedersen::{pedersen_commitment_base, pedersen_commitment_u64},
-        token_id::DARK_TOKEN_ID,
-        Coin, ContractId, MerkleNode, MerkleTree, PublicKey,
+        pallas, pasta_prelude::*, pedersen_commitment_base, pedersen_commitment_u64, Coin,
+        ContractId, MerkleNode, MerkleTree, PublicKey, DARK_TOKEN_ID,
     },
     },
     db::{db_contains_key, db_get, db_init, db_lookup, db_set, SMART_CONTRACT_ZKAS_DB_NAME},
     db::{db_contains_key, db_get, db_init, db_lookup, db_set, SMART_CONTRACT_ZKAS_DB_NAME},
     error::ContractResult,
     error::ContractResult,
     merkle::merkle_add,
     merkle::merkle_add,
-    msg,
-    pasta::{
-        arithmetic::CurveAffine,
-        group::{Curve, Group},
-        pallas,
-    },
-    tx::ContractCall,
-    util::set_return_data,
+    msg, set_return_data, ContractCall,
 };
 };
 
 
 use darkfi_sdk::error::ContractError;
 use darkfi_sdk::error::ContractError;

+ 2 - 6
src/contract/money/src/state.rs

@@ -16,12 +16,8 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
  */
 
 
-use darkfi_sdk::{
-    crypto::{
-        pedersen::{ValueBlind, ValueCommit},
-        Coin, MerkleNode, Nullifier, PublicKey, TokenId,
-    },
-    pasta::pallas,
+use darkfi_sdk::crypto::{
+    pallas, Coin, MerkleNode, Nullifier, PublicKey, TokenId, ValueBlind, ValueCommit,
 };
 };
 use darkfi_serial::{SerialDecodable, SerialEncodable};
 use darkfi_serial::{SerialDecodable, SerialEncodable};
 
 

+ 4 - 4
src/contract/money/tests/drop_pay_swap.rs

@@ -29,10 +29,10 @@
 
 
 use darkfi::{tx::Transaction, Result};
 use darkfi::{tx::Transaction, Result};
 use darkfi_sdk::{
 use darkfi_sdk::{
-    crypto::{poseidon_hash, MerkleNode, Nullifier, TokenId},
-    incrementalmerkletree::Tree,
-    pasta::{group::ff::Field, pallas},
-    tx::ContractCall,
+    crypto::{
+        merkle_prelude::*, pallas, pasta_prelude::*, poseidon_hash, MerkleNode, Nullifier, TokenId,
+    },
+    ContractCall,
 };
 };
 use darkfi_serial::Encodable;
 use darkfi_serial::Encodable;
 use log::info;
 use log::info;

+ 13 - 19
src/contract/money/tests/harness.rs

@@ -19,27 +19,21 @@ use std::collections::HashMap;
 
 
 use darkfi::{
 use darkfi::{
     consensus::{
     consensus::{
-        constants::{
-            TESTNET_BOOTSTRAP_TIMESTAMP, TESTNET_GENESIS_HASH_BYTES, TESTNET_GENESIS_TIMESTAMP,
-            TESTNET_INITIAL_DISTRIBUTION,
-        },
-        ValidatorState, ValidatorStatePtr,
+        ValidatorState, ValidatorStatePtr, TESTNET_BOOTSTRAP_TIMESTAMP, TESTNET_GENESIS_HASH_BYTES,
+        TESTNET_GENESIS_TIMESTAMP, TESTNET_INITIAL_DISTRIBUTION,
     },
     },
     tx::Transaction,
     tx::Transaction,
     wallet::WalletDb,
     wallet::WalletDb,
-    zk::{proof::ProvingKey, vm::ZkCircuit, vm_stack::empty_witnesses},
+    zk::{empty_witnesses, ProvingKey, ZkCircuit},
     zkas::ZkBinary,
     zkas::ZkBinary,
     Result,
     Result,
 };
 };
 use darkfi_sdk::{
 use darkfi_sdk::{
     crypto::{
     crypto::{
-        constants::MERKLE_DEPTH, contract_id::MONEY_CONTRACT_ID, ContractId, Keypair, MerkleNode,
-        PublicKey, TokenId,
+        pasta_prelude::*, ContractId, Keypair, MerkleTree, PublicKey, TokenId, MONEY_CONTRACT_ID,
     },
     },
     db::SMART_CONTRACT_ZKAS_DB_NAME,
     db::SMART_CONTRACT_ZKAS_DB_NAME,
-    incrementalmerkletree::bridgetree::BridgeTree,
-    pasta::group::ff::PrimeField,
-    tx::ContractCall,
+    ContractCall,
 };
 };
 use darkfi_serial::{serialize, Encodable};
 use darkfi_serial::{serialize, Encodable};
 use log::{info, warn};
 use log::{info, warn};
@@ -83,10 +77,10 @@ pub struct MoneyTestHarness {
     pub burn_zkbin: ZkBinary,
     pub burn_zkbin: ZkBinary,
     pub mint_pk: ProvingKey,
     pub mint_pk: ProvingKey,
     pub burn_pk: ProvingKey,
     pub burn_pk: ProvingKey,
-    pub faucet_merkle_tree: BridgeTree<MerkleNode, MERKLE_DEPTH>,
-    pub alice_merkle_tree: BridgeTree<MerkleNode, MERKLE_DEPTH>,
-    pub bob_merkle_tree: BridgeTree<MerkleNode, MERKLE_DEPTH>,
-    pub charlie_merkle_tree: BridgeTree<MerkleNode, MERKLE_DEPTH>,
+    pub faucet_merkle_tree: MerkleTree,
+    pub alice_merkle_tree: MerkleTree,
+    pub bob_merkle_tree: MerkleTree,
+    pub charlie_merkle_tree: MerkleTree,
 }
 }
 
 
 impl MoneyTestHarness {
 impl MoneyTestHarness {
@@ -185,10 +179,10 @@ impl MoneyTestHarness {
         ];
         ];
         proving_keys.insert(money_contract_id.inner().to_repr(), pks);
         proving_keys.insert(money_contract_id.inner().to_repr(), pks);
 
 
-        let faucet_merkle_tree = BridgeTree::<MerkleNode, MERKLE_DEPTH>::new(100);
-        let alice_merkle_tree = BridgeTree::<MerkleNode, MERKLE_DEPTH>::new(100);
-        let bob_merkle_tree = BridgeTree::<MerkleNode, MERKLE_DEPTH>::new(100);
-        let charlie_merkle_tree = BridgeTree::<MerkleNode, MERKLE_DEPTH>::new(100);
+        let faucet_merkle_tree = MerkleTree::new(100);
+        let alice_merkle_tree = MerkleTree::new(100);
+        let bob_merkle_tree = MerkleTree::new(100);
+        let charlie_merkle_tree = MerkleTree::new(100);
 
 
         Ok(Self {
         Ok(Self {
             faucet_kp,
             faucet_kp,

+ 5 - 4
src/contract/money/tests/verification_bench.rs

@@ -20,10 +20,11 @@ use std::{env, str::FromStr};
 
 
 use darkfi::{tx::Transaction, Result};
 use darkfi::{tx::Transaction, Result};
 use darkfi_sdk::{
 use darkfi_sdk::{
-    crypto::{contract_id::MONEY_CONTRACT_ID, poseidon_hash, MerkleNode, Nullifier, TokenId},
-    incrementalmerkletree::Tree,
-    pasta::{group::ff::Field, pallas},
-    tx::ContractCall,
+    crypto::{
+        merkle_prelude::*, pallas, pasta_prelude::*, poseidon_hash, MerkleNode, Nullifier, TokenId,
+        MONEY_CONTRACT_ID,
+    },
+    ContractCall,
 };
 };
 use darkfi_serial::Encodable;
 use darkfi_serial::Encodable;
 use log::info;
 use log::info;

+ 22 - 2
src/sdk/src/crypto/mod.rs

@@ -47,25 +47,45 @@ pub use coin::Coin;
 
 
 /// Contract ID definitions and methods
 /// Contract ID definitions and methods
 pub mod contract_id;
 pub mod contract_id;
-pub use contract_id::ContractId;
+pub use contract_id::{ContractId, DAO_CONTRACT_ID, MONEY_CONTRACT_ID};
 
 
 /// Token ID definitions and methods
 /// Token ID definitions and methods
 pub mod token_id;
 pub mod token_id;
-pub use token_id::TokenId;
+pub use token_id::{TokenId, DARK_TOKEN_ID};
 
 
 /// Merkle node definitions
 /// Merkle node definitions
 pub mod merkle_node;
 pub mod merkle_node;
 pub use merkle_node::{MerkleNode, MerkleTree};
 pub use merkle_node::{MerkleNode, MerkleTree};
 
 
+pub mod merkle_prelude {
+    pub use incrementalmerkletree::{Hashable, Tree};
+}
+pub use incrementalmerkletree::Position as MerklePosition;
+
 /// Nullifier definitions
 /// Nullifier definitions
 pub mod nullifier;
 pub mod nullifier;
 pub use nullifier::Nullifier;
 pub use nullifier::Nullifier;
 
 
 /// Pedersen commitment utilities
 /// Pedersen commitment utilities
 pub mod pedersen;
 pub mod pedersen;
+pub use pedersen::{pedersen_commitment_base, pedersen_commitment_u64, ValueBlind, ValueCommit};
 
 
 /// Schnorr signature traits
 /// Schnorr signature traits
 pub mod schnorr;
 pub mod schnorr;
 
 
 /// MiMC VDF
 /// MiMC VDF
 pub mod mimc_vdf;
 pub mod mimc_vdf;
+
+pub use incrementalmerkletree;
+pub use pasta_curves::{pallas, vesta};
+/// Convenience module to import all the pasta traits.
+/// You still have to import the curves.
+pub mod pasta_prelude {
+    pub use pasta_curves::{
+        arithmetic::CurveAffine,
+        group::{
+            ff::{Field, PrimeField},
+            Curve, Group,
+        },
+    };
+}

+ 3 - 0
src/sdk/src/lib.rs

@@ -36,9 +36,12 @@ pub mod crypto;
 
 
 /// Merkle
 /// Merkle
 pub mod merkle;
 pub mod merkle;
+pub use merkle::merkle_add;
 
 
 /// Transaction structure
 /// Transaction structure
 pub mod tx;
 pub mod tx;
+pub use tx::ContractCall;
 
 
 /// Utilities
 /// Utilities
 pub mod util;
 pub mod util;
+pub use util::set_return_data;

+ 6 - 2
src/zk/mod.rs

@@ -18,16 +18,20 @@
 
 
 /// Halo2 zkas virtual machine
 /// Halo2 zkas virtual machine
 pub mod vm;
 pub mod vm;
+pub use vm::ZkCircuit;
+
 pub mod vm_stack;
 pub mod vm_stack;
+pub use vm_stack::{empty_witnesses, Witness};
 
 
 /// ZK gadget implementations
 /// ZK gadget implementations
 pub mod gadget;
 pub mod gadget;
 
 
 /// Proof creation API
 /// Proof creation API
 pub mod proof;
 pub mod proof;
-pub use proof::Proof;
+pub use proof::{Proof, ProvingKey};
 
 
-use halo2_proofs::{
+// I thought about putting this in a sub-module called halo2
+pub use halo2_proofs::{
     arithmetic::Field,
     arithmetic::Field,
     circuit::{AssignedCell, Layouter, Value},
     circuit::{AssignedCell, Layouter, Value},
     plonk,
     plonk,