Browse Source

Update imports for type migrations.

Luther Blissett 3 năm trước cách đây
mục cha
commit
62d1f06c1f
73 tập tin đã thay đổi với 245 bổ sung501 xóa
  1. 5 30
      Cargo.lock
  2. 5 15
      Cargo.toml
  3. 1 0
      Makefile
  4. 1 0
      bin/dao/daod/Cargo.toml
  5. 5 4
      bin/dao/daod/src/contract/dao/propose/validate.rs
  6. 5 5
      bin/dao/daod/src/contract/dao/propose/wallet.rs
  7. 4 5
      bin/dao/daod/src/contract/dao/state.rs
  8. 5 6
      bin/dao/daod/src/contract/dao/vote/validate.rs
  9. 5 6
      bin/dao/daod/src/contract/dao/vote/wallet.rs
  10. 1 3
      bin/dao/daod/src/contract/money/state.rs
  11. 3 4
      bin/dao/daod/src/contract/money/transfer/validate.rs
  12. 2 2
      bin/dao/daod/src/contract/money/transfer/wallet.rs
  13. 1 1
      bin/dao/daod/src/main.rs
  14. 1 0
      bin/darkfid/Cargo.toml
  15. 6 6
      bin/darkfid/src/rpc_blockchain.rs
  16. 1 0
      bin/darkotc/Cargo.toml
  17. 1 1
      bin/darkotc/src/rpc.rs
  18. 4 3
      example/dao/contract/dao_contract/propose/validate.rs
  19. 4 4
      example/dao/contract/dao_contract/propose/wallet.rs
  20. 3 4
      example/dao/contract/dao_contract/state.rs
  21. 3 4
      example/dao/contract/dao_contract/vote/validate.rs
  22. 3 4
      example/dao/contract/dao_contract/vote/wallet.rs
  23. 1 3
      example/dao/contract/money_contract/state.rs
  24. 2 3
      example/dao/contract/money_contract/transfer/validate.rs
  25. 1 1
      example/dao/contract/money_contract/transfer/wallet.rs
  26. 5 4
      example/dao/dao.rs
  27. 7 5
      example/dao/util.rs
  28. 5 8
      example/dchat/Cargo.toml
  29. 4 5
      example/dchat/src/main.rs
  30. 1 1
      example/dchat/src/protocol_dchat.rs
  31. 0 12
      example/derive_macro_example.rs
  32. 2 4
      example/tx.rs
  33. 2 1
      src/blockchain/nfstore.rs
  34. 2 1
      src/blockchain/rootstore.rs
  35. 3 7
      src/consensus/block.rs
  36. 2 6
      src/consensus/ouroboros/epoch.rs
  37. 11 18
      src/consensus/ouroboros/mod.rs
  38. 2 4
      src/consensus/ouroboros/state.rs
  39. 3 3
      src/consensus/ouroboros/utils.rs
  40. 5 3
      src/consensus/ouroboros/workspace.rs
  41. 2 3
      src/consensus/state.rs
  42. 3 4
      src/crypto/burn_proof.rs
  43. 2 1
      src/crypto/coin.rs
  44. 2 2
      src/crypto/diffie_hellman.rs
  45. 2 1
      src/crypto/keypair.rs
  46. 5 11
      src/crypto/leadcoin.rs
  47. 0 120
      src/crypto/merkle_node.rs
  48. 0 3
      src/crypto/mod.rs
  49. 1 1
      src/crypto/note.rs
  50. 0 29
      src/crypto/nullifier.rs
  51. 1 1
      src/crypto/proof.rs
  52. 1 1
      src/crypto/schnorr.rs
  53. 1 1
      src/crypto/token_id.rs
  54. 1 1
      src/crypto/token_list.rs
  55. 8 12
      src/crypto/util.rs
  56. 0 22
      src/error.rs
  57. 2 3
      src/node/client.rs
  58. 3 5
      src/node/memorystate.rs
  59. 2 4
      src/node/state.rs
  60. 2 4
      src/runtime/chain_state.rs
  61. 8 1
      src/sdk/src/crypto/merkle_node.rs
  62. 8 1
      src/sdk/src/crypto/nullifier.rs
  63. 2 2
      src/tx/builder.rs
  64. 1 1
      src/tx/mod.rs
  65. 9 12
      src/wallet/walletdb.rs
  66. 18 19
      src/zk/circuit/burn_contract.rs
  67. 2 2
      src/zk/circuit/lead_contract.rs
  68. 5 7
      src/zk/circuit/mint_contract.rs
  69. 5 4
      src/zk/gadget/native_range_check.rs
  70. 8 10
      src/zk/vm.rs
  71. 2 4
      src/zk/vm_stack.rs
  72. 6 7
      tests/burn_proof.rs
  73. 6 6
      tests/zkvm_opcodes.rs

+ 5 - 30
Cargo.lock

@@ -338,25 +338,6 @@ version = "0.13.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
 
-[[package]]
-name = "bincode"
-version = "2.0.0-rc.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7bb50c5a2ef4b9b1e7ae73e3a73b52ea24b20312d629f9c4df28260b7ad2c3c4"
-dependencies = [
- "bincode_derive",
- "serde",
-]
-
-[[package]]
-name = "bincode_derive"
-version = "2.0.0-rc.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0a45a23389446d2dd25dc8e73a7a3b3c43522b630cac068927f0649d43d719d2"
-dependencies = [
- "virtue",
-]
-
 [[package]]
 name = "bit-set"
 version = "0.5.3"
@@ -1130,6 +1111,7 @@ dependencies = [
  "bs58",
  "crypto_api_chachapoly",
  "darkfi",
+ "darkfi-sdk",
  "darkfi-serial",
  "easy-parallel",
  "futures",
@@ -1157,7 +1139,6 @@ dependencies = [
  "async-std",
  "async-trait",
  "async-tungstenite",
- "bincode",
  "blake2b_simd",
  "blake3",
  "bs58",
@@ -1169,14 +1150,12 @@ dependencies = [
  "darkfi-sdk",
  "darkfi-serial",
  "dashu",
- "dirs",
  "ed25519-compact",
  "env_logger",
  "fast-socks5",
  "futures",
  "futures-rustls",
  "fxhash",
- "group",
  "halo2_gadgets",
  "halo2_proofs",
  "hex",
@@ -1247,8 +1226,10 @@ dependencies = [
  "halo2_gadgets",
  "halo2_proofs",
  "incrementalmerkletree",
+ "lazy_static",
  "pasta_curves",
  "rand",
+ "subtle",
  "thiserror",
 ]
 
@@ -1276,6 +1257,7 @@ dependencies = [
  "chrono",
  "ctrlc",
  "darkfi",
+ "darkfi-sdk",
  "darkfi-serial",
  "easy-parallel",
  "fxhash",
@@ -1302,6 +1284,7 @@ dependencies = [
  "bs58",
  "clap 3.2.22",
  "darkfi",
+ "darkfi-sdk",
  "darkfi-serial",
  "halo2_gadgets",
  "halo2_proofs",
@@ -1482,8 +1465,6 @@ dependencies = [
 name = "dchat"
 version = "0.1.0"
 dependencies = [
- "async-channel",
- "async-executor",
  "async-std",
  "async-trait",
  "darkfi",
@@ -4638,12 +4619,6 @@ version = "0.9.4"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
 
-[[package]]
-name = "virtue"
-version = "0.0.8"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7b60dcd6a64dd45abf9bd426970c9843726da7fc08f44cd6fcebf68c21220a63"
-
 [[package]]
 name = "wait-timeout"
 version = "0.2.0"

+ 5 - 15
Cargo.toml

@@ -70,7 +70,6 @@ rcgen = {version = "0.10.0", features = ["pem"], optional = true}
 rustls-pemfile = {version = "1.0.1", optional = true}
 
 # Encoding
-bincode = {version = "2.0.0-rc.2", features = ["serde"], optional = true}
 bs58 = {version = "0.4.0", optional = true}
 hex = {version = "0.4.3", optional = true}
 serde_json = {version = "1.0.85", optional = true}
@@ -80,20 +79,22 @@ structopt-toml = {version= "0.5.1", optional = true}
 toml = {version = "0.5.9", optional = true}
 
 # Utilities
+# TODO: check chrono usage and impl our own
 chrono = {version = "0.4.22", optional = true}
 darkfi-serial = {path = "src/serial", optional = true}
 darkfi-derive = {path = "src/serial/derive", optional = true}
 darkfi-derive-internal = {path = "src/serial/derive-internal", optional = true}
-dirs = {version = "4.0.0", optional = true}
 fxhash = {version = "0.2.1", optional = true}
 indexmap = {version = "1.9.1", optional = true}
 itertools = {version = "0.10.5", optional = true}
 lazy-init = {version = "0.5.1", optional = true}
 lazy_static = {version = "1.4.0", optional = true}
 subtle = {version = "2.4.1", optional = true}
+# TODO: Test without serde
 url = {version = "2.3.1", features = ["serde"], optional = true}
 
 # Misc
+# TODO: Implement something simple and kill these deps
 indicatif = {version = "0.17.1", optional = true}
 simplelog = {version = "0.12.0", optional = true}
 termion = {version = "1.5.6", optional = true}
@@ -110,7 +111,6 @@ rand = {version = "0.8.5", optional = true}
 blake2b_simd = {version = "1.0.0", optional = true}
 blake3 = {version = "1.3.1", optional = true}
 crypto_api_chachapoly = {version = "0.5.0", optional = true}
-group = {version = "0.12.0", optional = true}
 halo2_proofs = {version = "0.2.0", optional = true}
 halo2_gadgets = {version = "0.2.0", optional = true}
 incrementalmerkletree = {version = "0.3.0", optional = true}
@@ -156,7 +156,6 @@ async-runtime = [
 blockchain = [
     "blake3",
     "chrono",
-    "group",
     "halo2_gadgets",
     "halo2_proofs",
     "incrementalmerkletree",
@@ -169,6 +168,7 @@ blockchain = [
 
     "async-runtime",
     "crypto",
+    "darkfi-sdk",
     "darkfi-serial",
     "net",
     "tx",
@@ -182,7 +182,6 @@ crypto = [
     "bs58",
     "crypto_api_chachapoly",
     "fxhash",
-    "group",
     "halo2_gadgets",
     "halo2_proofs",
     "hex",
@@ -197,6 +196,7 @@ crypto = [
     "sha2",
     "subtle",
 
+    "darkfi-sdk",
     "darkfi-serial",
     "darkfi-serial/crypto",
     "util",
@@ -243,7 +243,6 @@ net = [
 
 node = [
     "bs58",
-    "group",
     "incrementalmerkletree",
     "lazy-init",
 
@@ -287,7 +286,6 @@ system = [
 ]
 
 tx = [
-    "group",
     "incrementalmerkletree",
     "rand",
 
@@ -297,7 +295,6 @@ tx = [
 
 util = [
     "chrono",
-    "dirs",
     "indicatif",
     "rand",
     "simplelog",
@@ -312,9 +309,7 @@ util = [
 
 wallet = [
     "async-std",
-    "bincode",
     "bs58",
-    "group",
     "rand",
     "sqlx",
     "incrementalmerkletree",
@@ -368,11 +363,6 @@ name = "dao"
 path = "example/dao/dao.rs"
 required-features = ["crypto"]
 
-[[example]]
-name = "test"
-path = "example/derive_macro_example.rs"
-required-features = ["serial"]
-
 [[example]]
 name = "lead"
 path = "example/lead.rs"

+ 1 - 0
Makefile

@@ -24,6 +24,7 @@ BINDEPS = \
 # ZK proofs to compile with zkas
 PROOFS = \
 	$(shell find bin/dao/daod/proof -type f -name '*.zk') \
+	$(shell find example/dao/proof -type f -name '*.zk') \
 	$(shell find proof -type f -name '*.zk') \
 	example/simple.zk
 

+ 1 - 0
bin/dao/daod/Cargo.toml

@@ -5,6 +5,7 @@ edition = "2021"
 
 [dependencies]
 darkfi = {path = "../../../", features = ["rpc", "crypto", "tx", "node"]}
+darkfi-sdk = {path = "../../../src/sdk"}
 darkfi-serial = {path = "../../../src/serial"}
 
 # Async

+ 5 - 4
bin/dao/daod/src/contract/dao/propose/validate.rs

@@ -1,5 +1,7 @@
 use std::any::{Any, TypeId};
 
+use darkfi_sdk::crypto::MerkleNode;
+use darkfi_serial::{Encodable, SerialDecodable, SerialEncodable};
 use log::error;
 use pasta_curves::{
     arithmetic::CurveAffine,
@@ -8,10 +10,9 @@ use pasta_curves::{
 };
 
 use darkfi::{
-    crypto::{keypair::PublicKey, merkle_node::MerkleNode, types::DrkCircuitField},
+    crypto::{keypair::PublicKey, types::DrkCircuitField},
     Error as DarkFiError,
 };
-use darkfi_serial::{Encodable, SerialDecodable, SerialEncodable};
 
 use crate::{
     contract::{dao, dao::State as DaoState, money, money::state::State as MoneyState},
@@ -65,7 +66,7 @@ impl CallDataBase for CallData {
                     *value_coords.x(),
                     *value_coords.y(),
                     self.header.token_commit,
-                    input.merkle_root.0,
+                    input.merkle_root.inner(),
                     *sigpub_coords.x(),
                     *sigpub_coords.y(),
                 ],
@@ -77,7 +78,7 @@ impl CallDataBase for CallData {
             "dao-propose-main".to_string(),
             vec![
                 self.header.token_commit,
-                self.header.dao_merkle_root.0,
+                self.header.dao_merkle_root.inner(),
                 self.header.proposal_bulla,
                 *total_funds_coords.x(),
                 *total_funds_coords.y(),

+ 5 - 5
bin/dao/daod/src/contract/dao/propose/wallet.rs

@@ -1,3 +1,5 @@
+use darkfi_sdk::crypto::MerkleNode;
+use darkfi_serial::{SerialDecodable, SerialEncodable};
 use halo2_proofs::circuit::Value;
 use incrementalmerkletree::Hashable;
 use pasta_curves::{
@@ -10,13 +12,11 @@ use rand::rngs::OsRng;
 use darkfi::{
     crypto::{
         keypair::{PublicKey, SecretKey},
-        merkle_node::MerkleNode,
         util::{pedersen_commitment_u64, poseidon_hash},
         Proof,
     },
     zk::vm::{Witness, ZkCircuit},
 };
-use darkfi_serial::{SerialDecodable, SerialEncodable};
 
 use crate::{
     contract::{
@@ -122,7 +122,7 @@ impl Builder {
 
             let merkle_root = {
                 let position: u64 = input.leaf_position.into();
-                let mut current = MerkleNode(coin);
+                let mut current = MerkleNode::from(coin);
                 for (level, sibling) in input.merkle_path.iter().enumerate() {
                     let level = level as u8;
                     current = if position & (1 << level) == 0 {
@@ -146,7 +146,7 @@ impl Builder {
                 *value_coords.x(),
                 *value_coords.y(),
                 token_commit,
-                merkle_root.0,
+                merkle_root.inner(),
                 *sigpub_coords.x(),
                 *sigpub_coords.y(),
             ];
@@ -239,7 +239,7 @@ impl Builder {
         ];
         let public_inputs = vec![
             token_commit,
-            self.dao_merkle_root.0,
+            self.dao_merkle_root.inner(),
             proposal_bulla,
             *total_funds_coords.x(),
             *total_funds_coords.y(),

+ 4 - 5
bin/dao/daod/src/contract/dao/state.rs

@@ -1,11 +1,10 @@
 use std::{any::Any, collections::HashMap};
 
+use darkfi_sdk::crypto::{constants::MERKLE_DEPTH, MerkleNode, Nullifier};
+use darkfi_serial::{SerialDecodable, SerialEncodable};
 use incrementalmerkletree::{bridgetree::BridgeTree, Tree};
 use pasta_curves::{group::Group, pallas};
 
-use darkfi::crypto::{constants::MERKLE_DEPTH, merkle_node::MerkleNode, nullifier::Nullifier};
-use darkfi_serial::{SerialDecodable, SerialEncodable};
-
 use crate::util::HashableBase;
 
 #[derive(Clone, SerialEncodable, SerialDecodable)]
@@ -55,14 +54,14 @@ impl State {
     }
 
     pub fn add_dao_bulla(&mut self, bulla: DaoBulla) {
-        let node = MerkleNode(bulla.0);
+        let node = MerkleNode::from(bulla.0);
         self.dao_bullas.push(bulla);
         self.dao_tree.append(&node);
         self.dao_roots.push(self.dao_tree.root(0).unwrap());
     }
 
     pub fn add_proposal_bulla(&mut self, bulla: pallas::Base) {
-        let node = MerkleNode(bulla);
+        let node = MerkleNode::from(bulla);
         //self.proposal_bullas.push(bulla);
         self.proposal_tree.append(&node);
         self.proposal_roots.push(self.proposal_tree.root(0).unwrap());

+ 5 - 6
bin/dao/daod/src/contract/dao/vote/validate.rs

@@ -1,5 +1,7 @@
 use std::any::{Any, TypeId};
 
+use darkfi_sdk::crypto::{MerkleNode, Nullifier};
+use darkfi_serial::{Encodable, SerialDecodable, SerialEncodable};
 use log::error;
 use pasta_curves::{
     arithmetic::CurveAffine,
@@ -8,12 +10,9 @@ use pasta_curves::{
 };
 
 use darkfi::{
-    crypto::{
-        keypair::PublicKey, merkle_node::MerkleNode, nullifier::Nullifier, types::DrkCircuitField,
-    },
+    crypto::{keypair::PublicKey, types::DrkCircuitField},
     Error as DarkFiError,
 };
-use darkfi_serial::{Encodable, SerialDecodable, SerialEncodable};
 
 use crate::{
     contract::{dao, dao::State as DaoState, money, money::state::State as MoneyState},
@@ -67,11 +66,11 @@ impl CallDataBase for CallData {
             zk_publics.push((
                 "dao-vote-burn".to_string(),
                 vec![
-                    input.nullifier.0,
+                    input.nullifier.inner(),
                     *value_coords.x(),
                     *value_coords.y(),
                     self.header.token_commit,
-                    input.merkle_root.0,
+                    input.merkle_root.inner(),
                     *sigpub_coords.x(),
                     *sigpub_coords.y(),
                 ],

+ 5 - 6
bin/dao/daod/src/contract/dao/vote/wallet.rs

@@ -1,3 +1,5 @@
+use darkfi_sdk::crypto::{MerkleNode, Nullifier};
+use darkfi_serial::{SerialDecodable, SerialEncodable};
 use halo2_proofs::circuit::Value;
 use incrementalmerkletree::Hashable;
 use log::debug;
@@ -11,14 +13,11 @@ use rand::rngs::OsRng;
 use darkfi::{
     crypto::{
         keypair::{Keypair, PublicKey, SecretKey},
-        merkle_node::MerkleNode,
-        nullifier::Nullifier,
         util::{pedersen_commitment_u64, poseidon_hash},
         Proof,
     },
     zk::vm::{Witness, ZkCircuit},
 };
-use darkfi_serial::{SerialDecodable, SerialEncodable};
 
 use crate::{
     contract::{
@@ -128,7 +127,7 @@ impl Builder {
 
             let merkle_root = {
                 let position: u64 = input.leaf_position.into();
-                let mut current = MerkleNode(coin);
+                let mut current = MerkleNode::from(coin);
                 for (level, sibling) in input.merkle_path.iter().enumerate() {
                     let level = level as u8;
                     current = if position & (1 << level) == 0 {
@@ -155,7 +154,7 @@ impl Builder {
                 *vote_commit_coords.x(),
                 *vote_commit_coords.y(),
                 token_commit,
-                merkle_root.0,
+                merkle_root.inner(),
                 *sigpub_coords.x(),
                 *sigpub_coords.y(),
             ];
@@ -168,7 +167,7 @@ impl Builder {
             proofs.push(input_proof);
 
             let input = Input {
-                nullifier: Nullifier(nullifier),
+                nullifier: Nullifier::from(nullifier),
                 vote_commit,
                 merkle_root,
                 signature_public,

+ 1 - 3
bin/dao/daod/src/contract/money/state.rs

@@ -1,11 +1,9 @@
+use darkfi_sdk::crypto::{constants::MERKLE_DEPTH, MerkleNode, Nullifier};
 use incrementalmerkletree::{bridgetree::BridgeTree, Tree};
 
 use darkfi::crypto::{
     coin::Coin,
-    constants::MERKLE_DEPTH,
     keypair::{PublicKey, SecretKey},
-    merkle_node::MerkleNode,
-    nullifier::Nullifier,
 };
 
 use super::transfer;

+ 3 - 4
bin/dao/daod/src/contract/money/transfer/validate.rs

@@ -1,5 +1,7 @@
 use std::any::{Any, TypeId};
 
+use darkfi_sdk::crypto::{MerkleNode, Nullifier};
+use darkfi_serial::{Encodable, SerialDecodable, SerialEncodable};
 use incrementalmerkletree::Tree;
 use log::{debug, error};
 use pasta_curves::{group::Group, pallas};
@@ -8,15 +10,12 @@ use darkfi::{
     crypto::{
         coin::Coin,
         keypair::PublicKey,
-        merkle_node::MerkleNode,
-        nullifier::Nullifier,
         types::{DrkCircuitField, DrkTokenId, DrkValueBlind, DrkValueCommit},
         util::{pedersen_commitment_base, pedersen_commitment_u64},
         BurnRevealedValues, MintRevealedValues,
     },
     Error as DarkFiError,
 };
-use darkfi_serial::{Encodable, SerialDecodable, SerialEncodable};
 
 use crate::{
     contract::{
@@ -51,7 +50,7 @@ impl UpdateBase for Update {
         //// Update merkle tree and witnesses
         for (coin, enc_note) in self.coins.into_iter().zip(self.enc_notes.into_iter()) {
             // Add the new coins to the Merkle tree
-            let node = MerkleNode(coin.0);
+            let node = MerkleNode::from(coin.0);
             state.tree.append(&node);
 
             // Keep track of all Merkle roots that have existed

+ 2 - 2
bin/dao/daod/src/contract/money/transfer/wallet.rs

@@ -1,3 +1,5 @@
+use darkfi_sdk::crypto::MerkleNode;
+use darkfi_serial::{SerialDecodable, SerialEncodable};
 use pasta_curves::group::ff::Field;
 use rand::rngs::OsRng;
 
@@ -5,7 +7,6 @@ use darkfi::{
     crypto::{
         burn_proof::create_burn_proof,
         keypair::{PublicKey, SecretKey},
-        merkle_node::MerkleNode,
         mint_proof::create_mint_proof,
         types::{
             DrkCoinBlind, DrkSerial, DrkSpendHook, DrkTokenId, DrkUserData, DrkUserDataBlind,
@@ -14,7 +15,6 @@ use darkfi::{
     },
     Result,
 };
-use darkfi_serial::{SerialDecodable, SerialEncodable};
 
 use crate::{
     contract::money::{

+ 1 - 1
bin/dao/daod/src/main.rs

@@ -1,5 +1,6 @@
 use std::{sync::Arc, time::Instant};
 
+use darkfi_sdk::crypto::MerkleNode;
 use fxhash::FxHashMap;
 use incrementalmerkletree::{Position, Tree};
 use log::debug;
@@ -15,7 +16,6 @@ use url::Url;
 use darkfi::{
     crypto::{
         keypair::{Keypair, PublicKey, SecretKey},
-        merkle_node::MerkleNode,
         proof::{ProvingKey, VerifyingKey},
         types::{DrkSpendHook, DrkUserData, DrkValue},
         util::{pedersen_commitment_u64, poseidon_hash},

+ 1 - 0
bin/darkfid/Cargo.toml

@@ -16,6 +16,7 @@ bs58 = "0.4.0"
 chrono = "0.4.22"
 ctrlc = { version = "3.2.3", features = ["termination"] }
 darkfi = {path = "../../", features = ["blockchain", "wallet", "rpc", "net", "node"]}
+darkfi-sdk = {path = "../../src/sdk"}
 darkfi-serial = {path = "../../src/serial"}
 easy-parallel = "3.2.0"
 fxhash = "0.2.1"

+ 6 - 6
bin/darkfid/src/rpc_blockchain.rs

@@ -1,12 +1,10 @@
+use darkfi_sdk::crypto::MerkleNode;
 use log::{debug, error};
 use serde_json::{json, Value};
 
-use darkfi::{
-    crypto::merkle_node::MerkleNode,
-    rpc::jsonrpc::{
-        ErrorCode::{InternalError, InvalidParams},
-        JsonError, JsonResponse, JsonResult,
-    },
+use darkfi::rpc::jsonrpc::{
+    ErrorCode::{InternalError, InvalidParams},
+    JsonError, JsonResponse, JsonResult,
 };
 
 use super::Darkfid;
@@ -70,6 +68,8 @@ impl Darkfid {
             }
         };
 
+        let roots: Vec<String> = roots.iter().map(|x| x.to_string()).collect();
+
         JsonResponse::new(json!(roots), id).into()
     }
 }

+ 1 - 0
bin/darkotc/Cargo.toml

@@ -13,6 +13,7 @@ async-std = {version = "1.12.0", features = ["attributes"]}
 bs58 = "0.4.0"
 clap = {version = "3.2.20", features = ["derive"]}
 darkfi = {path = "../../", features = ["crypto", "rpc", "util", "tx"]}
+darkfi-sdk = {path = "../../src/sdk"}
 darkfi-serial = {path = "../../src/serial"}
 halo2_proofs = "0.2.0"
 halo2_gadgets = "0.2.0"

+ 1 - 1
bin/darkotc/src/rpc.rs

@@ -1,5 +1,6 @@
 use std::{process::exit, str::FromStr};
 
+use darkfi_sdk::crypto::MerkleNode;
 use darkfi_serial::{deserialize, serialize};
 use serde_json::json;
 
@@ -7,7 +8,6 @@ use darkfi::{
     crypto::{
         address::Address,
         coin::OwnCoin,
-        merkle_node::MerkleNode,
         note::{EncryptedNote, Note},
     },
     rpc::{client::RpcClient, jsonrpc::JsonRequest},

+ 4 - 3
example/dao/contract/dao_contract/propose/validate.rs

@@ -1,5 +1,6 @@
 use std::any::{Any, TypeId};
 
+use darkfi_sdk::crypto::MerkleNode;
 use darkfi_serial::{Encodable, SerialDecodable, SerialEncodable};
 use log::error;
 use pasta_curves::{
@@ -9,7 +10,7 @@ use pasta_curves::{
 };
 
 use darkfi::{
-    crypto::{keypair::PublicKey, merkle_node::MerkleNode, types::DrkCircuitField},
+    crypto::{keypair::PublicKey, types::DrkCircuitField},
     Error as DarkFiError,
 };
 
@@ -68,7 +69,7 @@ impl CallDataBase for CallData {
                     *value_coords.x(),
                     *value_coords.y(),
                     self.header.token_commit,
-                    input.merkle_root.0,
+                    input.merkle_root.inner(),
                     *sigpub_coords.x(),
                     *sigpub_coords.y(),
                 ],
@@ -80,7 +81,7 @@ impl CallDataBase for CallData {
             "dao-propose-main".to_string(),
             vec![
                 self.header.token_commit,
-                self.header.dao_merkle_root.0,
+                self.header.dao_merkle_root.inner(),
                 self.header.proposal_bulla,
                 *total_funds_coords.x(),
                 *total_funds_coords.y(),

+ 4 - 4
example/dao/contract/dao_contract/propose/wallet.rs

@@ -1,3 +1,4 @@
+use darkfi_sdk::crypto::MerkleNode;
 use darkfi_serial::{SerialDecodable, SerialEncodable};
 use halo2_proofs::circuit::Value;
 use incrementalmerkletree::Hashable;
@@ -11,7 +12,6 @@ use rand::rngs::OsRng;
 use darkfi::{
     crypto::{
         keypair::{PublicKey, SecretKey},
-        merkle_node::MerkleNode,
         util::{pedersen_commitment_u64, poseidon_hash},
         Proof,
     },
@@ -122,7 +122,7 @@ impl Builder {
 
             let merkle_root = {
                 let position: u64 = input.leaf_position.into();
-                let mut current = MerkleNode(coin);
+                let mut current = MerkleNode::from(coin);
                 for (level, sibling) in input.merkle_path.iter().enumerate() {
                     let level = level as u8;
                     current = if position & (1 << level) == 0 {
@@ -146,7 +146,7 @@ impl Builder {
                 *value_coords.x(),
                 *value_coords.y(),
                 token_commit,
-                merkle_root.0,
+                merkle_root.inner(),
                 *sigpub_coords.x(),
                 *sigpub_coords.y(),
             ];
@@ -239,7 +239,7 @@ impl Builder {
         ];
         let public_inputs = vec![
             token_commit,
-            self.dao_merkle_root.0,
+            self.dao_merkle_root.inner(),
             proposal_bulla,
             *total_funds_coords.x(),
             *total_funds_coords.y(),

+ 3 - 4
example/dao/contract/dao_contract/state.rs

@@ -1,11 +1,10 @@
 use std::{any::Any, collections::HashMap};
 
+use darkfi_sdk::crypto::{constants::MERKLE_DEPTH, MerkleNode, Nullifier};
 use darkfi_serial::{SerialDecodable, SerialEncodable};
 use incrementalmerkletree::{bridgetree::BridgeTree, Tree};
 use pasta_curves::{group::Group, pallas};
 
-use darkfi::crypto::{constants::MERKLE_DEPTH, merkle_node::MerkleNode, nullifier::Nullifier};
-
 use crate::util::HashableBase;
 
 #[derive(Clone, SerialEncodable, SerialDecodable)]
@@ -55,14 +54,14 @@ impl State {
     }
 
     pub fn add_dao_bulla(&mut self, bulla: DaoBulla) {
-        let node = MerkleNode(bulla.0);
+        let node = MerkleNode::from(bulla.0);
         self.dao_bullas.push(bulla);
         self.dao_tree.append(&node);
         self.dao_roots.push(self.dao_tree.root(0).unwrap());
     }
 
     pub fn add_proposal_bulla(&mut self, bulla: pallas::Base) {
-        let node = MerkleNode(bulla);
+        let node = MerkleNode::from(bulla);
         //self.proposal_bullas.push(bulla);
         self.proposal_tree.append(&node);
         self.proposal_roots.push(self.proposal_tree.root(0).unwrap());

+ 3 - 4
example/dao/contract/dao_contract/vote/validate.rs

@@ -1,5 +1,6 @@
 use std::any::{Any, TypeId};
 
+use darkfi_sdk::crypto::{MerkleNode, Nullifier};
 use darkfi_serial::{Encodable, SerialDecodable, SerialEncodable};
 use log::error;
 use pasta_curves::{
@@ -9,9 +10,7 @@ use pasta_curves::{
 };
 
 use darkfi::{
-    crypto::{
-        keypair::PublicKey, merkle_node::MerkleNode, nullifier::Nullifier, types::DrkCircuitField,
-    },
+    crypto::{keypair::PublicKey, types::DrkCircuitField},
     Error as DarkFiError,
 };
 
@@ -74,7 +73,7 @@ impl CallDataBase for CallData {
                     *value_coords.x(),
                     *value_coords.y(),
                     self.header.token_commit,
-                    input.merkle_root.0,
+                    input.merkle_root.inner(),
                     *sigpub_coords.x(),
                     *sigpub_coords.y(),
                 ],

+ 3 - 4
example/dao/contract/dao_contract/vote/wallet.rs

@@ -1,3 +1,4 @@
+use darkfi_sdk::crypto::{MerkleNode, Nullifier};
 use darkfi_serial::{SerialDecodable, SerialEncodable};
 use halo2_proofs::circuit::Value;
 use incrementalmerkletree::Hashable;
@@ -12,8 +13,6 @@ use rand::rngs::OsRng;
 use darkfi::{
     crypto::{
         keypair::{Keypair, PublicKey, SecretKey},
-        merkle_node::MerkleNode,
-        nullifier::Nullifier,
         util::{pedersen_commitment_u64, poseidon_hash},
         Proof,
     },
@@ -128,7 +127,7 @@ impl Builder {
 
             let merkle_root = {
                 let position: u64 = input.leaf_position.into();
-                let mut current = MerkleNode(coin);
+                let mut current = MerkleNode::from(coin);
                 for (level, sibling) in input.merkle_path.iter().enumerate() {
                     let level = level as u8;
                     current = if position & (1 << level) == 0 {
@@ -156,7 +155,7 @@ impl Builder {
                 *vote_commit_coords.x(),
                 *vote_commit_coords.y(),
                 token_commit,
-                merkle_root.0,
+                merkle_root.inner(),
                 *sigpub_coords.x(),
                 *sigpub_coords.y(),
             ];

+ 1 - 3
example/dao/contract/money_contract/state.rs

@@ -1,11 +1,9 @@
+use darkfi_sdk::crypto::{constants::MERKLE_DEPTH, MerkleNode, Nullifier};
 use incrementalmerkletree::{bridgetree::BridgeTree, Tree};
 
 use darkfi::crypto::{
     coin::Coin,
-    constants::MERKLE_DEPTH,
     keypair::{PublicKey, SecretKey},
-    merkle_node::MerkleNode,
-    nullifier::Nullifier,
 };
 
 use super::transfer;

+ 2 - 3
example/dao/contract/money_contract/transfer/validate.rs

@@ -1,5 +1,6 @@
 use std::any::{Any, TypeId};
 
+use darkfi_sdk::crypto::{MerkleNode, Nullifier};
 use darkfi_serial::{Encodable, SerialDecodable, SerialEncodable};
 use incrementalmerkletree::Tree;
 use log::{debug, error};
@@ -9,8 +10,6 @@ use darkfi::{
     crypto::{
         coin::Coin,
         keypair::PublicKey,
-        merkle_node::MerkleNode,
-        nullifier::Nullifier,
         types::{DrkCircuitField, DrkTokenId, DrkValueBlind, DrkValueCommit},
         util::{pedersen_commitment_base, pedersen_commitment_u64},
         BurnRevealedValues, MintRevealedValues,
@@ -51,7 +50,7 @@ impl UpdateBase for Update {
         //// Update merkle tree and witnesses
         for (coin, enc_note) in self.coins.into_iter().zip(self.enc_notes.into_iter()) {
             // Add the new coins to the Merkle tree
-            let node = MerkleNode(coin.0);
+            let node = MerkleNode::from(coin.0);
             state.tree.append(&node);
 
             // Keep track of all Merkle roots that have existed

+ 1 - 1
example/dao/contract/money_contract/transfer/wallet.rs

@@ -1,3 +1,4 @@
+use darkfi_sdk::crypto::MerkleNode;
 use darkfi_serial::{SerialDecodable, SerialEncodable};
 use pasta_curves::group::ff::Field;
 use rand::rngs::OsRng;
@@ -6,7 +7,6 @@ use darkfi::{
     crypto::{
         burn_proof::create_burn_proof,
         keypair::{PublicKey, SecretKey},
-        merkle_node::MerkleNode,
         mint_proof::create_mint_proof,
         types::{
             DrkCoinBlind, DrkSerial, DrkSpendHook, DrkTokenId, DrkUserData, DrkUserDataBlind,

+ 5 - 4
example/dao/dao.rs

@@ -1,3 +1,8 @@
+use std::{
+    any::{Any, TypeId},
+    time::Instant,
+};
+
 use incrementalmerkletree::Tree;
 use log::debug;
 use pasta_curves::{
@@ -6,10 +11,6 @@ use pasta_curves::{
     pallas,
 };
 use rand::rngs::OsRng;
-use std::{
-    any::{Any, TypeId},
-    time::Instant,
-};
 
 use darkfi::{
     crypto::{

+ 7 - 5
example/dao/util.rs

@@ -1,3 +1,6 @@
+use std::{any::Any, collections::HashMap, hash::Hasher};
+
+use darkfi_serial::Encodable;
 use lazy_static::lazy_static;
 use log::debug;
 use pasta_curves::{
@@ -5,7 +8,6 @@ use pasta_curves::{
     pallas,
 };
 use rand::rngs::OsRng;
-use std::{any::Any, collections::HashMap, hash::Hasher};
 
 use darkfi::{
     crypto::{
@@ -15,7 +17,6 @@ use darkfi::{
         types::DrkCircuitField,
         Proof,
     },
-    util::serial::Encodable,
     zk::{vm::ZkCircuit, vm_stack::empty_witnesses},
     zkas::decoder::ZkBinary,
 };
@@ -177,7 +178,7 @@ pub struct FuncCall {
 }
 
 impl Encodable for FuncCall {
-    fn encode<W: std::io::Write>(&self, mut w: W) -> std::result::Result<usize, darkfi::Error> {
+    fn encode<W: std::io::Write>(&self, mut w: W) -> std::result::Result<usize, std::io::Error> {
         let mut len = 0;
         len += self.contract_id.encode(&mut w)?;
         len += self.func_id.encode(&mut w)?;
@@ -201,10 +202,11 @@ pub trait CallDataBase {
     fn encode_bytes(
         &self,
         writer: &mut dyn std::io::Write,
-    ) -> std::result::Result<usize, darkfi::Error>;
+    ) -> std::result::Result<usize, std::io::Error>;
 }
 
-type GenericContractState = Box<dyn Any + Send>;
+//type GenericContractState = Box<dyn Any + Send>;
+type GenericContractState = Box<dyn Any>;
 
 pub struct StateRegistry {
     pub states: HashMap<HashableBase, GenericContractState>,

+ 5 - 8
example/dchat/Cargo.toml

@@ -1,30 +1,27 @@
 [package]
 name = "dchat"
 version = "0.1.0"
+homepage = "https://dark.fi"
+description = "Demo chat app used to document DarkFi networking code"
+authors = ["darkfi <dev@dark.fi>"]
+repository = "https://github.com/darkrenaissance/darkfi"
+license = "AGPL-3.0-only"
 edition = "2021"
-description = "Demo chat to document darkfi net code"
 
 [dependencies]
 darkfi = {path = "../../", features = ["net", "rpc"]}
 darkfi-serial = {path = "../../src/serial"}
 
-# Async
 async-std = "1.12.0"
 async-trait = "0.1.57"
-async-executor = "1.4.1"
-async-channel = "1.7.1"
 easy-parallel = "3.2.0"
 smol = "1.2.5"
 num_cpus = "1.13.1"
 
-# Misc
 log = "0.4.17"
 simplelog = "0.12.0"
 url = "2.3.1"
 
-# Encoding and parsing
 serde_json = "1.0.85"
 serde = {version = "1.0.145", features = ["derive"]}
 toml = "0.5.9"
-
-

+ 4 - 5
example/dchat/src/main.rs

@@ -1,11 +1,10 @@
-use async_executor::Executor;
-use async_std::sync::{Arc, Mutex};
-use easy_parallel::Parallel;
-
 use std::{error, fs::File, io::stdin};
 
+use async_std::sync::{Arc, Mutex};
+use easy_parallel::Parallel;
 use log::debug;
 use simplelog::WriteLogger;
+use smol::Executor;
 use url::Url;
 
 use darkfi::{net, net::Settings, rpc::server::listen_and_serve};
@@ -196,7 +195,7 @@ async fn main() -> Result<()> {
     let p2p = net::P2p::new(settings.net).await;
 
     let nthreads = num_cpus::get();
-    let (signal, shutdown) = async_channel::unbounded::<()>();
+    let (signal, shutdown) = smol::channel::unbounded::<()>();
 
     let ex = Arc::new(Executor::new());
     let ex2 = ex.clone();

+ 1 - 1
example/dchat/src/protocol_dchat.rs

@@ -1,8 +1,8 @@
-use async_executor::Executor;
 use async_std::sync::Arc;
 use async_trait::async_trait;
 use darkfi::{net, Result};
 use log::debug;
+use smol::Executor;
 
 use crate::dchatmsg::{DchatMsg, DchatMsgsBuffer};
 

+ 0 - 12
example/derive_macro_example.rs

@@ -1,12 +0,0 @@
-use darkfi::serial::SerialEncodable;
-
-#[derive(Debug, SerialEncodable)]
-struct Test {
-    one: u64,
-    two: u64,
-}
-
-fn main() {
-    let test = Test { one: 1, two: 2 };
-    println!("Test: {:?}", test);
-}

+ 2 - 4
example/tx.rs

@@ -1,4 +1,5 @@
 // Example transaction flow
+use darkfi_sdk::crypto::{constants::MERKLE_DEPTH, MerkleNode, Nullifier};
 use incrementalmerkletree::{bridgetree::BridgeTree, Tree};
 use pasta_curves::{group::ff::Field, pallas};
 use rand::rngs::OsRng;
@@ -6,11 +7,8 @@ use rand::rngs::OsRng;
 use darkfi::{
     crypto::{
         coin::OwnCoin,
-        constants::MERKLE_DEPTH,
         keypair::{Keypair, PublicKey, SecretKey},
-        merkle_node::MerkleNode,
         note::{EncryptedNote, Note},
-        nullifier::Nullifier,
         proof::{ProvingKey, VerifyingKey},
         util::poseidon_hash,
     },
@@ -87,7 +85,7 @@ impl MemoryState {
         // Update merkle tree and witnesses
         for (coin, enc_note) in update.coins.into_iter().zip(update.enc_notes.into_iter()) {
             // Add the new coins to the Merkle tree
-            let node = MerkleNode(coin.0);
+            let node = MerkleNode::from(coin.0);
             self.tree.append(&node);
 
             // Keep track of all Merkle roots that have existed

+ 2 - 1
src/blockchain/nfstore.rs

@@ -1,6 +1,7 @@
+use darkfi_sdk::crypto::Nullifier;
 use darkfi_serial::{deserialize, serialize};
 
-use crate::{crypto::nullifier::Nullifier, Result};
+use crate::Result;
 
 const SLED_NULLIFIER_TREE: &[u8] = b"_nullifiers";
 

+ 2 - 1
src/blockchain/rootstore.rs

@@ -1,6 +1,7 @@
+use darkfi_sdk::crypto::MerkleNode;
 use darkfi_serial::{deserialize, serialize};
 
-use crate::{crypto::merkle_node::MerkleNode, Result};
+use crate::Result;
 
 const SLED_ROOTS_TREE: &[u8] = b"_merkleroots";
 

+ 3 - 7
src/consensus/block.rs

@@ -1,17 +1,13 @@
 use std::fmt;
 
+use darkfi_sdk::crypto::{constants::MERKLE_DEPTH, MerkleNode};
 use darkfi_serial::{serialize, SerialDecodable, SerialEncodable};
 use incrementalmerkletree::{bridgetree::BridgeTree, Tree};
 use log::debug;
 use pasta_curves::pallas;
 
 use super::{Metadata, BLOCK_MAGIC_BYTES, BLOCK_VERSION};
-use crate::{
-    crypto::{constants::MERKLE_DEPTH, merkle_node::MerkleNode},
-    net,
-    tx::Transaction,
-    util::time::Timestamp,
-};
+use crate::{net, tx::Transaction, util::time::Timestamp};
 
 /// This struct represents a tuple of the form (version, previous, epoch, slot, timestamp, merkle_root).
 #[derive(Debug, Clone, PartialEq, Eq, SerialEncodable, SerialDecodable)]
@@ -63,7 +59,7 @@ impl Default for Header {
             0,
             0,
             Timestamp::current_time(),
-            MerkleNode(pallas::Base::zero()),
+            MerkleNode::from(pallas::Base::zero()),
         )
     }
 }

+ 2 - 6
src/consensus/ouroboros/epoch.rs

@@ -1,15 +1,13 @@
+use darkfi_sdk::crypto::{constants::MERKLE_DEPTH_ORCHARD, MerkleNode};
 use halo2_gadgets::poseidon::primitives as poseidon;
 use halo2_proofs::arithmetic::Field;
 use incrementalmerkletree::{bridgetree::BridgeTree, Tree};
-
 use log::debug;
-
 use pasta_curves::{
     arithmetic::CurveAffine,
     group::{ff::PrimeField, Curve},
     pallas,
 };
-
 use rand::{thread_rng, Rng};
 
 use crate::{
@@ -20,11 +18,9 @@ use crate::{
     },
     crypto::{
         coin::OwnCoin,
-        constants::MERKLE_DEPTH_ORCHARD,
         keypair::{Keypair, SecretKey},
         lead_proof,
         leadcoin::LeadCoin,
-        merkle_node::MerkleNode,
         proof::{Proof, ProvingKey},
         types::DrkValueBlind,
         util::{mod_r_p, pedersen_commitment_base, pedersen_commitment_u64},
@@ -235,7 +231,7 @@ impl Epoch {
         let c_cm: pallas::Point = pedersen_commitment_base(coin_commit_msg, c_cm1_blind);
         let c_cm_coordinates = c_cm.to_affine().coordinates().unwrap();
         let c_cm_base: pallas::Base = c_cm_coordinates.x() * c_cm_coordinates.y();
-        let c_cm_node = MerkleNode(c_cm_base);
+        let c_cm_node = MerkleNode::from(c_cm_base);
         tree_cm.append(&c_cm_node.clone());
         let leaf_position = tree_cm.witness();
         let c_root_cm = tree_cm.root(0).unwrap();

+ 11 - 18
src/consensus/ouroboros/mod.rs

@@ -1,18 +1,14 @@
+use std::{fmt, thread, time::Duration};
+
 use async_std::sync::Arc;
+use darkfi_sdk::crypto::{constants::MERKLE_DEPTH, MerkleNode};
 use halo2_proofs::arithmetic::Field;
+use incrementalmerkletree::bridgetree::BridgeTree;
 use log::{debug, error, info};
-use smol::Executor;
-use std::fmt;
-
+use pasta_curves::{group::ff::PrimeField, pallas};
 use rand::rngs::OsRng;
-use std::{thread, time::Duration};
-
-use crate::zk::circuit::{BurnContract, LeadContract, MintContract};
-use incrementalmerkletree::bridgetree::BridgeTree;
-
-pub mod consts;
-pub mod types;
-pub mod utils;
+use smol::Executor;
+use url::Url;
 
 use crate::{
     blockchain::Blockchain,
@@ -28,10 +24,8 @@ use crate::{
     crypto::{
         address::Address,
         coin::OwnCoin,
-        constants::MERKLE_DEPTH,
         keypair::{PublicKey, SecretKey},
         leadcoin::LeadCoin,
-        merkle_node::MerkleNode,
         proof::{Proof, ProvingKey, VerifyingKey},
         schnorr::SchnorrSecret,
     },
@@ -44,14 +38,13 @@ use crate::{
         Transaction,
     },
     util::{path::expand_path, time::Timestamp},
+    zk::circuit::{BurnContract, LeadContract, MintContract},
     Result,
 };
 
-use url::Url;
-
-use pasta_curves::pallas;
-
-use group::ff::PrimeField;
+pub mod consts;
+pub mod types;
+pub mod utils;
 
 pub mod epochconsensus;
 pub use epochconsensus::EpochConsensus;

+ 2 - 4
src/consensus/ouroboros/state.rs

@@ -1,13 +1,11 @@
+use darkfi_sdk::crypto::{constants::MERKLE_DEPTH, MerkleNode, Nullifier};
 use incrementalmerkletree::{bridgetree::BridgeTree, Tree};
 
 use crate::{
     crypto::{
         coin::OwnCoin,
-        constants::MERKLE_DEPTH,
         keypair::{PublicKey, SecretKey},
-        merkle_node::MerkleNode,
         note::{EncryptedNote, Note},
-        nullifier::Nullifier,
         proof::VerifyingKey,
         util::poseidon_hash,
     },
@@ -77,7 +75,7 @@ impl StakeholderState {
         // Update merkle tree and witnesses
         for (coin, enc_note) in update.coins.into_iter().zip(update.enc_notes.into_iter()) {
             // Add the new coins to the Merkle tree
-            let node = MerkleNode(coin.0);
+            let node = MerkleNode::from(coin.0);
             self.tree.append(&node);
 
             // Keep track of all Merkle roots that have existed

+ 3 - 3
src/consensus/ouroboros/utils.rs

@@ -1,8 +1,8 @@
-use crate::consensus::ouroboros::types::Float10;
 use dashu::integer::{IBig, Sign, UBig};
-use group::ff::PrimeField;
 use log::info;
-use pasta_curves::pallas;
+use pasta_curves::{group::ff::PrimeField, pallas};
+
+use crate::consensus::ouroboros::types::Float10;
 
 pub(crate) fn fbig2ibig(f: Float10) -> IBig {
     info!("fbig -> ibig (f): {}", f);

+ 5 - 3
src/consensus/ouroboros/workspace.rs

@@ -1,10 +1,12 @@
+use darkfi_sdk::crypto::MerkleNode;
+use pasta_curves::pallas;
+
 use crate::{
     consensus::{BlockInfo, Header, Metadata},
-    crypto::{merkle_node::MerkleNode, proof::Proof},
+    crypto::proof::Proof,
     tx::Transaction,
     util::time::Timestamp,
 };
-use pasta_curves::pallas;
 
 #[derive(Debug)]
 pub struct SlotWorkspace {
@@ -27,7 +29,7 @@ impl Default for SlotWorkspace {
             e: 0,
             sl: 0,
             txs: vec![],
-            root: MerkleNode(pallas::Base::zero()),
+            root: MerkleNode::from(pallas::Base::zero()),
             is_leader: false,
             m: Metadata::default(),
             proof: Proof::default(),

+ 2 - 3
src/consensus/state.rs

@@ -7,6 +7,7 @@ use std::{
 
 use async_std::sync::{Arc, Mutex, RwLock};
 use chrono::{NaiveDateTime, Utc};
+use darkfi_sdk::crypto::{constants::MERKLE_DEPTH, MerkleNode};
 use darkfi_serial::{serialize, SerialDecodable, SerialEncodable};
 use incrementalmerkletree::{bridgetree::BridgeTree, Tree};
 use lazy_init::Lazy;
@@ -22,9 +23,7 @@ use crate::{
     blockchain::Blockchain,
     crypto::{
         address::Address,
-        constants::MERKLE_DEPTH,
         keypair::{PublicKey, SecretKey},
-        merkle_node::MerkleNode,
         schnorr::{SchnorrPublic, SchnorrSecret},
     },
     net,
@@ -292,7 +291,7 @@ impl ValidatorState {
         let mut tree = BridgeTree::<MerkleNode, MERKLE_DEPTH>::new(100);
         for tx in &unproposed_txs {
             for output in &tx.outputs {
-                tree.append(&MerkleNode::from_coin(&output.revealed.coin));
+                tree.append(&MerkleNode::from(output.revealed.coin.0));
                 tree.witness();
             }
         }

+ 3 - 4
src/crypto/burn_proof.rs

@@ -1,5 +1,6 @@
 use std::time::Instant;
 
+use darkfi_sdk::crypto::{MerkleNode, Nullifier};
 use darkfi_serial::{SerialDecodable, SerialEncodable};
 use halo2_proofs::circuit::Value;
 use incrementalmerkletree::Hashable;
@@ -8,14 +9,12 @@ use pasta_curves::{arithmetic::CurveAffine, group::Curve};
 use rand::rngs::OsRng;
 
 use super::{
-    nullifier::Nullifier,
     proof::{Proof, ProvingKey, VerifyingKey},
     util::{pedersen_commitment_base, pedersen_commitment_u64},
 };
 use crate::{
     crypto::{
         keypair::{PublicKey, SecretKey},
-        merkle_node::MerkleNode,
         types::{
             DrkCircuitField, DrkCoinBlind, DrkSerial, DrkSpendHook, DrkTokenId, DrkUserData,
             DrkUserDataBlind, DrkUserDataEnc, DrkValue, DrkValueBlind, DrkValueCommit,
@@ -72,7 +71,7 @@ impl BurnRevealedValues {
 
         let merkle_root = {
             let position: u64 = leaf_position.into();
-            let mut current = MerkleNode(coin);
+            let mut current = MerkleNode::from(coin);
             for (level, sibling) in merkle_path.iter().enumerate() {
                 let level = level as u8;
                 current = if position & (1 << level) == 0 {
@@ -103,7 +102,7 @@ impl BurnRevealedValues {
     pub fn make_outputs(&self) -> Vec<DrkCircuitField> {
         let value_coords = self.value_commit.to_affine().coordinates().unwrap();
         let token_coords = self.token_commit.to_affine().coordinates().unwrap();
-        let merkle_root = self.merkle_root.0;
+        let merkle_root = self.merkle_root.inner();
         let user_data_enc = self.user_data_enc;
         let sig_coords = self.signature_public.0.to_affine().coordinates().unwrap();
 

+ 2 - 1
src/crypto/coin.rs

@@ -1,7 +1,8 @@
+use darkfi_sdk::crypto::Nullifier;
 use darkfi_serial::{SerialDecodable, SerialEncodable};
 use pasta_curves::{group::ff::PrimeField, pallas};
 
-use super::{keypair::SecretKey, note::Note, nullifier::Nullifier};
+use super::{keypair::SecretKey, note::Note};
 
 #[derive(Clone, Copy, PartialEq, Eq, Debug, SerialEncodable, SerialDecodable)]
 pub struct Coin(pub pallas::Base);

+ 2 - 2
src/crypto/diffie_hellman.rs

@@ -1,5 +1,5 @@
 use blake2b_simd::{Hash as Blake2bHash, Params as Blake2bParams};
-use pasta_curves::group::{cofactor::CofactorGroup, GroupEncoding};
+use pasta_curves::group::{cofactor::CofactorGroup, GroupEncoding, Wnaf};
 
 use crate::crypto::{
     keypair::{PublicKey, SecretKey},
@@ -24,7 +24,7 @@ pub fn sapling_ka_agree(esk: &SecretKey, pk_d: &PublicKey) -> PublicKey {
     // We want that to be fast because it's in the hot path for trial decryption of
     // notes on chain.
     let esk_s = mod_r_p(esk.inner());
-    let mut wnaf = group::Wnaf::new();
+    let mut wnaf = Wnaf::new();
     PublicKey(wnaf.scalar(&esk_s).base(pk_d.0).clear_cofactor())
 }
 

+ 2 - 1
src/crypto/keypair.rs

@@ -4,6 +4,7 @@ use std::{
     str::FromStr,
 };
 
+use darkfi_sdk::crypto::constants::NullifierK;
 use darkfi_serial::{Decodable, Encodable, SerialDecodable, SerialEncodable};
 use halo2_gadgets::ecc::chip::FixedPoint;
 use pasta_curves::{
@@ -17,7 +18,7 @@ use pasta_curves::{
 use rand::RngCore;
 
 use crate::{
-    crypto::{address::Address, constants::NullifierK, util::mod_r_p},
+    crypto::{address::Address, util::mod_r_p},
     Error, Result,
 };
 

+ 5 - 11
src/crypto/leadcoin.rs

@@ -1,23 +1,17 @@
+use darkfi_sdk::crypto::{constants::MERKLE_DEPTH_ORCHARD, MerkleNode};
 use halo2_gadgets::poseidon::primitives as poseidon;
 use halo2_proofs::circuit::Value;
-use pasta_curves::pallas;
+use incrementalmerkletree::Hashable;
+use pasta_curves::{arithmetic::CurveAffine, group::Curve, pallas};
 
 use crate::{
     crypto::{
-        constants::MERKLE_DEPTH_ORCHARD,
         keypair::Keypair,
-        merkle_node::MerkleNode,
         util::{mod_r_p, pedersen_commitment_base},
     },
     zk::circuit::lead_contract::LeadContract,
 };
 
-use incrementalmerkletree::Hashable;
-
-use pasta_curves::{arithmetic::CurveAffine, group::Curve};
-
-//use halo2_proofs::arithmetic::CurveAffine;
-
 pub const LEAD_PUBLIC_INPUT_LEN: usize = 11;
 
 #[derive(Debug, Default, Clone, Copy)]
@@ -78,7 +72,7 @@ impl LeadCoin {
             let pos: u32 = cm_pos;
             let c_cm_coordinates = self.cm.unwrap().to_affine().coordinates().unwrap();
             let c_cm_base: pallas::Base = c_cm_coordinates.x() * c_cm_coordinates.y();
-            let mut current = MerkleNode(c_cm_base);
+            let mut current = MerkleNode::from(c_cm_base);
             for (level, sibling) in self.path.unwrap().iter().enumerate() {
                 let level = level as u8;
                 current = if pos & (1 << level) == 0 {
@@ -95,7 +89,7 @@ impl LeadCoin {
             *po_cm2.x(),
             *po_cm2.y(),
             po_nonce,
-            cm_root.0,
+            cm_root.inner(),
             *po_pk.x(),
             *po_pk.y(),
             po_sn,

+ 0 - 120
src/crypto/merkle_node.rs

@@ -1,120 +0,0 @@
-use std::iter;
-
-use darkfi_serial::{SerialDecodable, SerialEncodable};
-use halo2_gadgets::sinsemilla::primitives::HashDomain;
-use incrementalmerkletree::{Altitude, Hashable};
-use lazy_static::lazy_static;
-use pasta_curves::{
-    group::ff::{PrimeField, PrimeFieldBits},
-    pallas,
-};
-use serde::{
-    de::{Deserializer, Error},
-    ser::Serializer,
-    Deserialize, Serialize,
-};
-use subtle::{Choice, ConditionallySelectable};
-
-use crate::crypto::{
-    coin::Coin,
-    constants::{
-        sinsemilla::{i2lebsp_k, L_ORCHARD_MERKLE, MERKLE_CRH_PERSONALIZATION},
-        MERKLE_DEPTH_ORCHARD,
-    },
-};
-
-lazy_static! {
-    static ref UNCOMMITTED_ORCHARD: pallas::Base = pallas::Base::from(2);
-    static ref EMPTY_ROOTS: Vec<MerkleNode> = {
-        iter::empty()
-            .chain(Some(MerkleNode::empty_leaf()))
-            .chain((0..MERKLE_DEPTH_ORCHARD).scan(MerkleNode::empty_leaf(), |state, l| {
-                let l = l as u8;
-                *state = MerkleNode::combine(l.into(), state, state);
-                Some(*state)
-            }))
-            .collect()
-    };
-}
-
-#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, SerialEncodable, SerialDecodable)]
-pub struct MerkleNode(pub pallas::Base);
-
-impl MerkleNode {
-    pub fn to_bytes(&self) -> [u8; 32] {
-        self.0.to_repr()
-    }
-
-    pub fn from_bytes(bytes: [u8; 32]) -> Option<Self> {
-        let n = pallas::Base::from_repr(bytes);
-        match bool::from(n.is_some()) {
-            true => Some(Self(n.unwrap())),
-            false => None,
-        }
-    }
-
-    pub fn from_coin(coin: &Coin) -> Self {
-        MerkleNode(coin.0)
-    }
-
-    pub fn inner(&self) -> pallas::Base {
-        self.0
-    }
-}
-
-impl Serialize for MerkleNode {
-    fn serialize<S: Serializer>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error> {
-        self.to_bytes().serialize(serializer)
-    }
-}
-
-impl<'de> Deserialize<'de> for MerkleNode {
-    fn deserialize<D: Deserializer<'de>>(deserializer: D) -> std::result::Result<Self, D::Error> {
-        let parsed = <[u8; 32]>::deserialize(deserializer)?;
-        Self::from_bytes(parsed).ok_or_else(|| {
-            Error::custom("Attempted to deserialize a non-canonical representation of a Pallas base field element")
-        })
-    }
-}
-
-impl ConditionallySelectable for MerkleNode {
-    fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self {
-        MerkleNode(pallas::Base::conditional_select(&a.0, &b.0, choice))
-    }
-}
-
-impl Hashable for MerkleNode {
-    fn empty_leaf() -> Self {
-        MerkleNode(*UNCOMMITTED_ORCHARD)
-    }
-
-    /// Implements `MerkleCRH^Orchard` as defined in
-    /// <https://zips.z.cash/protocol/protocol.pdf#orchardmerklecrh>
-    ///
-    /// The layer with 2^n nodes is called "layer n":
-    ///      - leaves are at layer MERKLE_DEPTH_ORCHARD = 32;
-    ///      - the root is at layer 0.
-    /// `l` is MERKLE_DEPTH_ORCHARD - layer - 1.
-    ///      - when hashing two leaves, we produce a node on the layer above the leaves, i.e. layer
-    ///        = 31, l = 0
-    ///      - when hashing to the final root, we produce the anchor with layer = 0, l = 31.
-    fn combine(altitude: Altitude, left: &Self, right: &Self) -> Self {
-        // MerkleCRH Sinsemilla hash domain.
-        let domain = HashDomain::new(MERKLE_CRH_PERSONALIZATION);
-
-        MerkleNode(
-            domain
-                .hash(
-                    iter::empty()
-                        .chain(i2lebsp_k(altitude.into()).iter().copied())
-                        .chain(left.0.to_le_bits().iter().by_vals().take(L_ORCHARD_MERKLE))
-                        .chain(right.0.to_le_bits().iter().by_vals().take(L_ORCHARD_MERKLE)),
-                )
-                .unwrap_or(pallas::Base::zero()),
-        )
-    }
-
-    fn empty_root(altitude: Altitude) -> Self {
-        EMPTY_ROOTS[<usize>::from(altitude)]
-    }
-}

+ 0 - 3
src/crypto/mod.rs

@@ -1,13 +1,10 @@
 pub mod address;
 pub mod burn_proof;
 pub mod coin;
-pub mod constants;
 pub mod diffie_hellman;
 pub mod keypair;
-pub mod merkle_node;
 pub mod mint_proof;
 pub mod note;
-pub mod nullifier;
 pub mod proof;
 pub mod schnorr;
 pub mod token_id;

+ 1 - 1
src/crypto/note.rs

@@ -75,7 +75,7 @@ impl EncryptedNote {
 mod tests {
     use super::*;
     use crate::crypto::keypair::Keypair;
-    use group::ff::Field;
+    use pasta_curves::group::ff::Field;
 
     #[test]
     fn test_note_encdec() {

+ 0 - 29
src/crypto/nullifier.rs

@@ -1,29 +0,0 @@
-use darkfi_serial::{SerialDecodable, SerialEncodable};
-use pasta_curves::{group::ff::PrimeField, pallas};
-
-#[derive(Clone, Copy, Debug, PartialEq, Eq, SerialEncodable, SerialDecodable)]
-pub struct Nullifier(pub pallas::Base);
-
-impl Nullifier {
-    pub fn from_bytes(bytes: [u8; 32]) -> Option<Self> {
-        let n = pallas::Base::from_repr(bytes);
-        match bool::from(n.is_some()) {
-            true => Some(Self(n.unwrap())),
-            false => None,
-        }
-    }
-
-    pub fn to_bytes(self) -> [u8; 32] {
-        self.0.to_repr()
-    }
-
-    pub fn inner(&self) -> pallas::Base {
-        self.0
-    }
-}
-
-impl From<pallas::Base> for Nullifier {
-    fn from(x: pallas::Base) -> Self {
-        Self(x)
-    }
-}

+ 1 - 1
src/crypto/proof.rs

@@ -105,7 +105,7 @@ mod tests {
         Result,
     };
     use darkfi_serial::{Decodable, Encodable};
-    use group::ff::Field;
+    use pasta_curves::group::ff::Field;
     use rand::rngs::OsRng;
 
     #[test]

+ 1 - 1
src/crypto/schnorr.rs

@@ -1,3 +1,4 @@
+use darkfi_sdk::crypto::constants::{NullifierK, DRK_SCHNORR_DOMAIN};
 use darkfi_serial::{SerialDecodable, SerialEncodable};
 use halo2_gadgets::ecc::chip::FixedPoint;
 use pasta_curves::{
@@ -7,7 +8,6 @@ use pasta_curves::{
 use rand::rngs::OsRng;
 
 use crate::crypto::{
-    constants::{NullifierK, DRK_SCHNORR_DOMAIN},
     keypair::{PublicKey, SecretKey},
     util::{hash_to_scalar, mod_r_p},
 };

+ 1 - 1
src/crypto/token_id.rs

@@ -1,4 +1,4 @@
-use group::ff::PrimeField;
+use pasta_curves::group::ff::PrimeField;
 
 use super::types::DrkTokenId;
 use crate::{util::net_name::NetworkName, Error, Result};

+ 1 - 1
src/crypto/token_list.rs

@@ -1,7 +1,7 @@
 use std::str::FromStr;
 
 use fxhash::FxHashMap;
-use group::ff::PrimeField;
+use pasta_curves::group::ff::PrimeField;
 use serde_json::Value;
 
 use super::{token_id::generate_id, types::DrkTokenId};

+ 8 - 12
src/crypto/util.rs

@@ -1,23 +1,19 @@
 use blake2b_simd::Params;
-
+use darkfi_sdk::crypto::constants::{
+    fixed_bases::{
+        VALUE_COMMITMENT_PERSONALIZATION, VALUE_COMMITMENT_R_BYTES, VALUE_COMMITMENT_V_BYTES,
+    },
+    util::gen_const_array,
+    NullifierK,
+};
 use halo2_gadgets::{ecc::chip::FixedPoint, poseidon::primitives as poseidon};
-
 use pasta_curves::{
     arithmetic::{CurveExt, FieldExt},
     group::ff::PrimeField,
     pallas,
 };
 
-use super::{
-    constants::{
-        fixed_bases::{
-            VALUE_COMMITMENT_PERSONALIZATION, VALUE_COMMITMENT_R_BYTES, VALUE_COMMITMENT_V_BYTES,
-        },
-        util::gen_const_array,
-        NullifierK,
-    },
-    types::*,
-};
+use super::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();

+ 0 - 22
src/error.rs

@@ -67,14 +67,6 @@ pub enum Error {
     #[error(transparent)]
     TomlDeserializeError(#[from] toml::de::Error),
 
-    #[cfg(feature = "bincode")]
-    #[error("bincode decode error: {0}")]
-    BincodeDecodeError(String),
-
-    #[cfg(feature = "bincode")]
-    #[error("bincode encode error: {0}")]
-    BincodeEncodeError(String),
-
     #[cfg(feature = "bs58")]
     #[error(transparent)]
     Bs58DecodeError(#[from] bs58::decode::Error),
@@ -499,20 +491,6 @@ impl From<futures_rustls::rustls::client::InvalidDnsNameError> for Error {
     }
 }
 
-#[cfg(feature = "bincode")]
-impl From<bincode::error::DecodeError> for Error {
-    fn from(err: bincode::error::DecodeError) -> Self {
-        Self::BincodeDecodeError(err.to_string())
-    }
-}
-
-#[cfg(feature = "bincode")]
-impl From<bincode::error::EncodeError> for Error {
-    fn from(err: bincode::error::EncodeError) -> Self {
-        Self::BincodeEncodeError(err.to_string())
-    }
-}
-
 #[cfg(feature = "serde_json")]
 impl From<serde_json::Error> for Error {
     fn from(err: serde_json::Error) -> Self {

+ 2 - 3
src/node/client.rs

@@ -1,17 +1,16 @@
 use async_std::sync::{Arc, Mutex};
-use group::ff::PrimeField;
+use darkfi_sdk::crypto::{constants::MERKLE_DEPTH, MerkleNode};
 use incrementalmerkletree::{bridgetree::BridgeTree, Tree};
 use lazy_init::Lazy;
 use log::{debug, error, info};
+use pasta_curves::group::ff::PrimeField;
 
 use super::state::{state_transition, State};
 use crate::{
     crypto::{
         address::Address,
         coin::{Coin, OwnCoin},
-        constants::MERKLE_DEPTH,
         keypair::{Keypair, PublicKey},
-        merkle_node::MerkleNode,
         proof::ProvingKey,
         types::DrkTokenId,
     },

+ 3 - 5
src/node/memorystate.rs

@@ -1,11 +1,9 @@
+use darkfi_sdk::crypto::{constants::MERKLE_DEPTH, MerkleNode, Nullifier};
 use incrementalmerkletree::{bridgetree::BridgeTree, Tree};
 use log::debug;
 
 use super::state::{ProgramState, State, StateUpdate};
-use crate::crypto::{
-    constants::MERKLE_DEPTH, keypair::PublicKey, merkle_node::MerkleNode, nullifier::Nullifier,
-    proof::VerifyingKey,
-};
+use crate::crypto::{keypair::PublicKey, proof::VerifyingKey};
 
 /// In-memory state extension for state transition validations
 #[derive(Clone)]
@@ -63,7 +61,7 @@ impl MemoryState {
 
         debug!(target: "state_apply", "(in-memory) Update Merkle tree and witnesses");
         for coin in update.coins {
-            let node = MerkleNode(coin.0);
+            let node = MerkleNode::from(coin.0);
             self.tree.append(&node);
             self.merkle_roots.push(self.tree.root(0).unwrap());
         }

+ 2 - 4
src/node/state.rs

@@ -1,3 +1,4 @@
+use darkfi_sdk::crypto::{constants::MERKLE_DEPTH, MerkleNode, Nullifier};
 use incrementalmerkletree::{bridgetree::BridgeTree, Tree};
 use lazy_init::Lazy;
 use log::{debug, error};
@@ -7,11 +8,8 @@ use crate::{
     consensus::{TESTNET_GENESIS_HASH_BYTES, TESTNET_GENESIS_TIMESTAMP},
     crypto::{
         coin::{Coin, OwnCoin},
-        constants::MERKLE_DEPTH,
         keypair::{PublicKey, SecretKey},
-        merkle_node::MerkleNode,
         note::{EncryptedNote, Note},
-        nullifier::Nullifier,
         proof::VerifyingKey,
         util::poseidon_hash,
     },
@@ -166,7 +164,7 @@ impl State {
         debug!(target: "state_apply", "Update Merkle tree and witnesses");
         for (coin, enc_note) in update.coins.into_iter().zip(update.enc_notes.iter()) {
             // Add the new coins to the Merkle tree
-            let node = MerkleNode(coin.0);
+            let node = MerkleNode::from(coin.0);
             debug!("Current merkle tree: {:#?}", self.tree);
             self.tree.append(&node);
             debug!("Merkle tree after append: {:#?}", self.tree);

+ 2 - 4
src/runtime/chain_state.rs

@@ -1,10 +1,8 @@
+use darkfi_sdk::crypto::{MerkleNode, Nullifier};
 use log::{debug, error};
 
 use super::{memory::MemoryManipulation, vm_runtime::Env};
-use crate::{
-    crypto::{merkle_node::MerkleNode, nullifier::Nullifier},
-    node::state::ProgramState,
-};
+use crate::node::state::ProgramState;
 
 /// Try to read a `Nullifier` from the given pointer and check if it's
 /// an existing nullifier in the blockchain state machine.

+ 8 - 1
src/sdk/src/crypto/merkle_node.rs

@@ -1,4 +1,4 @@
-use core::str::FromStr;
+use core::{fmt, str::FromStr};
 use std::{io, iter};
 
 use darkfi_serial::{SerialDecodable, SerialEncodable};
@@ -63,10 +63,17 @@ impl From<pallas::Base> for MerkleNode {
     }
 }
 
+impl fmt::Display for MerkleNode {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        write!(f, "{}", bs58::encode(self.to_bytes()).into_string())
+    }
+}
+
 impl FromStr for MerkleNode {
     type Err = io::Error;
 
     /// Tries to decode a base58 string into a `MerkleNode` type.
+    /// This string is the same string received by calling `MerkleNode::to_string()`.
     fn from_str(s: &str) -> Result<Self, Self::Err> {
         let bytes = match bs58::decode(s).into_vec() {
             Ok(v) => v,

+ 8 - 1
src/sdk/src/crypto/nullifier.rs

@@ -1,4 +1,4 @@
-use core::str::FromStr;
+use core::{fmt, str::FromStr};
 use std::io;
 
 use darkfi_serial::{SerialDecodable, SerialEncodable};
@@ -37,10 +37,17 @@ impl From<pallas::Base> for Nullifier {
     }
 }
 
+impl fmt::Display for Nullifier {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        write!(f, "{}", bs58::encode(self.to_bytes()).into_string())
+    }
+}
+
 impl FromStr for Nullifier {
     type Err = io::Error;
 
     /// Tries to decode a base58 string into a `Nullifier` type.
+    /// This string is the same string received by calling `Nullifier::to_string()`.
     fn from_str(s: &str) -> Result<Self, Self::Err> {
         let bytes = match bs58::decode(s).into_vec() {
             Ok(v) => v,

+ 2 - 2
src/tx/builder.rs

@@ -1,5 +1,6 @@
+use darkfi_sdk::crypto::MerkleNode;
 use darkfi_serial::serialize;
-use group::ff::Field;
+use pasta_curves::group::ff::Field;
 use rand::rngs::OsRng;
 
 use super::{
@@ -10,7 +11,6 @@ use crate::{
     crypto::{
         burn_proof::create_burn_proof,
         keypair::{PublicKey, SecretKey},
-        merkle_node::MerkleNode,
         mint_proof::create_mint_proof,
         note::Note,
         proof::ProvingKey,

+ 1 - 1
src/tx/mod.rs

@@ -1,8 +1,8 @@
 use std::io;
 
 use darkfi_serial::{Encodable, SerialDecodable, SerialEncodable, VarInt};
-use group::Group;
 use log::error;
+use pasta_curves::group::Group;
 
 use crate::{
     crypto::{

+ 9 - 12
src/wallet/walletdb.rs

@@ -1,10 +1,11 @@
 use std::{fs::create_dir_all, path::Path, str::FromStr, time::Duration};
 
 use async_std::sync::Arc;
+use darkfi_sdk::crypto::{constants::MERKLE_DEPTH, MerkleNode, Nullifier};
 use darkfi_serial::{deserialize, serialize};
-use group::ff::PrimeField;
 use incrementalmerkletree::bridgetree::BridgeTree;
 use log::{debug, error, info, LevelFilter};
+use pasta_curves::group::ff::PrimeField;
 use rand::rngs::OsRng;
 use sqlx::{
     sqlite::{SqliteConnectOptions, SqliteJournalMode},
@@ -15,11 +16,8 @@ use crate::{
     crypto::{
         address::Address,
         coin::{Coin, OwnCoin},
-        constants::MERKLE_DEPTH,
         keypair::{Keypair, PublicKey, SecretKey},
-        merkle_node::MerkleNode,
         note::Note,
-        nullifier::Nullifier,
         types::DrkTokenId,
     },
     util::path::expand_path,
@@ -223,8 +221,7 @@ impl WalletDb {
         let mut conn = self.conn.acquire().await?;
 
         let row = sqlx::query("SELECT * FROM tree").fetch_one(&mut conn).await?;
-        let (tree, _read): (BridgeTree<MerkleNode, MERKLE_DEPTH>, usize) =
-            bincode::serde::decode_from_slice(row.get("tree"), bincode::config::legacy())?;
+        let tree = deserialize(row.get("tree"))?;
         Ok(tree)
     }
 
@@ -232,7 +229,7 @@ impl WalletDb {
         debug!("put_tree(): Attempting to write merkle tree");
         let mut conn = self.conn.acquire().await?;
 
-        let tree_bytes = bincode::serde::encode_to_vec(tree, bincode::config::legacy())?;
+        let tree_bytes = serialize(tree);
 
         debug!("put_tree(): Deleting old row");
         sqlx::query("DELETE FROM tree;").execute(&mut conn).await?;
@@ -520,10 +517,10 @@ impl WalletDb {
 mod tests {
     use super::*;
     use crate::crypto::{
-        merkle_node::MerkleNode,
         types::{DrkCoinBlind, DrkSerial, DrkValueBlind},
         util::poseidon_hash,
     };
+    use darkfi_sdk::crypto::MerkleNode;
     use incrementalmerkletree::Tree;
     use pasta_curves::{group::ff::Field, pallas};
     use rand::rngs::OsRng;
@@ -572,19 +569,19 @@ mod tests {
 
         // put_own_coin()
         wallet.put_own_coin(c0.clone()).await?;
-        tree1.append(&MerkleNode::from_coin(&c0.coin));
+        tree1.append(&MerkleNode::from(c0.coin.0));
         tree1.witness();
 
         wallet.put_own_coin(c1.clone()).await?;
-        tree1.append(&MerkleNode::from_coin(&c1.coin));
+        tree1.append(&MerkleNode::from(c1.coin.0));
         tree1.witness();
 
         wallet.put_own_coin(c2.clone()).await?;
-        tree1.append(&MerkleNode::from_coin(&c2.coin));
+        tree1.append(&MerkleNode::from(c2.coin.0));
         tree1.witness();
 
         wallet.put_own_coin(c3.clone()).await?;
-        tree1.append(&MerkleNode::from_coin(&c3.coin));
+        tree1.append(&MerkleNode::from(c3.coin.0));
         tree1.witness();
 
         // We'll check this merkle root corresponds to the one we'll retrieve.

+ 18 - 19
src/zk/circuit/burn_contract.rs

@@ -1,3 +1,11 @@
+use darkfi_sdk::crypto::{
+    constants::{
+        sinsemilla::{OrchardCommitDomains, OrchardHashDomains},
+        util::gen_const_array,
+        NullifierK, OrchardFixedBases, OrchardFixedBasesFull, ValueCommitV, MERKLE_DEPTH_ORCHARD,
+    },
+    MerkleNode,
+};
 use halo2_gadgets::{
     ecc::{
         chip::{EccChip, EccConfig},
@@ -22,18 +30,7 @@ use halo2_proofs::{
 };
 use pasta_curves::{pallas, Fp};
 
-use crate::{
-    crypto::{
-        constants::{
-            sinsemilla::{OrchardCommitDomains, OrchardHashDomains},
-            util::gen_const_array,
-            NullifierK, OrchardFixedBases, OrchardFixedBasesFull, ValueCommitV,
-            MERKLE_DEPTH_ORCHARD,
-        },
-        merkle_node::MerkleNode,
-    },
-    zk::assign_free_advice,
-};
+use crate::zk::assign_free_advice;
 
 #[allow(dead_code)]
 #[derive(Clone, Debug)]
@@ -539,14 +536,16 @@ mod tests {
         },
         Result,
     };
-    use group::{ff::Field, Curve};
     use halo2_gadgets::poseidon::{
         primitives as poseidon,
         primitives::{ConstantLength, P128Pow5T3},
     };
     use halo2_proofs::dev::{CircuitLayout, MockProver};
     use incrementalmerkletree::{bridgetree::BridgeTree, Tree};
-    use pasta_curves::arithmetic::CurveAffine;
+    use pasta_curves::{
+        arithmetic::CurveAffine,
+        group::{ff::Field, Curve},
+    };
     use rand::rngs::OsRng;
     use std::time::Instant;
 
@@ -585,12 +584,12 @@ mod tests {
         let coin1 = pallas::Base::random(&mut OsRng);
         let coin3 = pallas::Base::random(&mut OsRng);
 
-        tree.append(&MerkleNode(coin0));
+        tree.append(&MerkleNode::from(coin0));
         tree.witness();
-        tree.append(&MerkleNode(coin1));
-        tree.append(&MerkleNode(coin2));
+        tree.append(&MerkleNode::from(coin1));
+        tree.append(&MerkleNode::from(coin2));
         let leaf_pos = tree.witness().unwrap();
-        tree.append(&MerkleNode(coin3));
+        tree.append(&MerkleNode::from(coin3));
         tree.witness();
 
         let merkle_root = tree.root(0).unwrap();
@@ -620,7 +619,7 @@ mod tests {
             *value_coords.y(),
             *token_coords.x(),
             *token_coords.y(),
-            merkle_root.0,
+            merkle_root.inner(),
             user_data_enc,
             *sig_coords.x(),
             *sig_coords.y(),

+ 2 - 2
src/zk/circuit/lead_contract.rs

@@ -1,10 +1,10 @@
-use crate::crypto::{
+use darkfi_sdk::crypto::{
     constants::{
         sinsemilla::{OrchardCommitDomains, OrchardHashDomains},
         util::gen_const_array,
         NullifierK, OrchardFixedBases, OrchardFixedBasesFull, MERKLE_DEPTH_ORCHARD,
     },
-    merkle_node::MerkleNode,
+    MerkleNode,
 };
 use halo2_gadgets::{
     ecc::{

+ 5 - 7
src/zk/circuit/mint_contract.rs

@@ -1,3 +1,7 @@
+use darkfi_sdk::crypto::constants::{
+    sinsemilla::{OrchardCommitDomains, OrchardHashDomains},
+    NullifierK, OrchardFixedBases, OrchardFixedBasesFull, ValueCommitV,
+};
 use halo2_gadgets::{
     ecc::{
         chip::{EccChip, EccConfig},
@@ -17,13 +21,7 @@ use halo2_proofs::{
     plonk::{Advice, Circuit, Column, ConstraintSystem, Instance as InstanceColumn},
 };
 
-use crate::{
-    crypto::constants::{
-        sinsemilla::{OrchardCommitDomains, OrchardHashDomains},
-        NullifierK, OrchardFixedBases, OrchardFixedBasesFull, ValueCommitV,
-    },
-    zk::assign_free_advice,
-};
+use crate::zk::assign_free_advice;
 
 #[derive(Clone, Debug)]
 pub struct MintConfig {

+ 5 - 4
src/zk/gadget/native_range_check.rs

@@ -1,7 +1,9 @@
-use group::ff::{Field, PrimeFieldBits};
 use halo2_proofs::{
     circuit::{AssignedCell, Chip, Layouter, Region, Value},
-    pasta::pallas,
+    pasta::{
+        group::ff::{Field, PrimeFieldBits},
+        pallas,
+    },
     plonk,
     plonk::{Advice, Column, ConstraintSystem, Selector, TableColumn},
     poly::Rotation,
@@ -201,13 +203,12 @@ impl<const WINDOW_SIZE: usize, const NUM_BITS: usize, const NUM_WINDOWS: usize>
 mod tests {
     use super::*;
     use crate::zk::assign_free_advice;
-    use group::ff::PrimeField;
     use halo2_proofs::{
         circuit::floor_planner,
         dev::{CircuitLayout, MockProver},
         plonk::Circuit,
     };
-    use pasta_curves::arithmetic::FieldExt;
+    use pasta_curves::{arithmetic::FieldExt, group::ff::PrimeField};
 
     macro_rules! test_circuit {
         ($window_size:expr, $num_bits:expr, $num_windows:expr) => {

+ 8 - 10
src/zk/vm.rs

@@ -1,3 +1,8 @@
+use darkfi_sdk::crypto::constants::{
+    sinsemilla::{OrchardCommitDomains, OrchardHashDomains},
+    util::gen_const_array,
+    NullifierK, OrchardFixedBases, OrchardFixedBasesFull, ValueCommitV, MERKLE_DEPTH_ORCHARD,
+};
 use halo2_gadgets::{
     ecc::{
         chip::{EccChip, EccConfig},
@@ -34,16 +39,9 @@ use super::{
         small_range_check::{SmallRangeCheckChip, SmallRangeCheckConfig},
     },
 };
-use crate::{
-    crypto::constants::{
-        sinsemilla::{OrchardCommitDomains, OrchardHashDomains},
-        util::gen_const_array,
-        NullifierK, OrchardFixedBases, OrchardFixedBasesFull, ValueCommitV, MERKLE_DEPTH_ORCHARD,
-    },
-    zkas::{
-        types::{LitType, StackType},
-        Opcode, ZkBinary,
-    },
+use crate::zkas::{
+    types::{LitType, StackType},
+    Opcode, ZkBinary,
 };
 
 #[derive(Clone)]

+ 2 - 4
src/zk/vm_stack.rs

@@ -1,12 +1,10 @@
 //! VM stack type abstractions
+use darkfi_sdk::crypto::{constants::OrchardFixedBases, MerkleNode};
 use halo2_gadgets::ecc::{chip::EccChip, FixedPoint, FixedPointBaseField, FixedPointShort, Point};
 use halo2_proofs::circuit::{AssignedCell, Value};
 use pasta_curves::{pallas, EpAffine};
 
-use crate::{
-    crypto::{constants::OrchardFixedBases, merkle_node::MerkleNode},
-    zkas::{decoder::ZkBinary, types::VarType},
-};
+use crate::zkas::{decoder::ZkBinary, types::VarType};
 
 /// These represent the witness types outside of the circuit
 #[allow(clippy::large_enum_variant)]

+ 6 - 7
tests/burn_proof.rs

@@ -1,8 +1,6 @@
 use darkfi::{
     crypto::{
         keypair::{PublicKey, SecretKey},
-        merkle_node::MerkleNode,
-        nullifier::Nullifier,
         proof::{ProvingKey, VerifyingKey},
         util::{pedersen_commitment_base, pedersen_commitment_u64, poseidon_hash},
         Proof,
@@ -14,6 +12,7 @@ use darkfi::{
     zkas::decoder::ZkBinary,
     Result,
 };
+use darkfi_sdk::crypto::{MerkleNode, Nullifier};
 use halo2_gadgets::poseidon::primitives as poseidon;
 use halo2_proofs::circuit::Value;
 use incrementalmerkletree::{bridgetree::BridgeTree, Tree};
@@ -61,12 +60,12 @@ fn burn_proof() -> Result<()> {
     let coin1 = pallas::Base::random(&mut OsRng);
     let coin3 = pallas::Base::random(&mut OsRng);
 
-    tree.append(&MerkleNode(coin0));
+    tree.append(&MerkleNode::from(coin0));
     tree.witness();
-    tree.append(&MerkleNode(coin1));
-    tree.append(&MerkleNode(coin2));
+    tree.append(&MerkleNode::from(coin1));
+    tree.append(&MerkleNode::from(coin2));
     let leaf_pos = tree.witness().unwrap();
-    tree.append(&MerkleNode(coin3));
+    tree.append(&MerkleNode::from(coin3));
     tree.witness();
 
     let root = tree.root(0).unwrap();
@@ -106,7 +105,7 @@ fn burn_proof() -> Result<()> {
         *value_coords.y(),
         *token_coords.x(),
         *token_coords.y(),
-        merkle_root.0,
+        merkle_root.inner(),
         *sig_coords.x(),
         *sig_coords.y(),
     ];

+ 6 - 6
tests/zkvm_opcodes.rs

@@ -1,3 +1,4 @@
+use darkfi_sdk::crypto::MerkleNode;
 use halo2_gadgets::poseidon::{
     primitives as poseidon,
     primitives::{ConstantLength, P128Pow5T3},
@@ -14,7 +15,6 @@ use simplelog::{ColorChoice, Config, LevelFilter, TermLogger, TerminalMode};
 use darkfi::{
     crypto::{
         keypair::{PublicKey, SecretKey},
-        merkle_node::MerkleNode,
         proof::{ProvingKey, VerifyingKey},
         util::pedersen_commitment_u64,
         Proof,
@@ -52,12 +52,12 @@ fn zkvm_opcodes() -> Result<()> {
         poseidon::Hash::<_, P128Pow5T3, ConstantLength<2>, 3, 2>::init().hash(messages)
     };
 
-    tree.append(&MerkleNode(c0));
+    tree.append(&MerkleNode::from(c0));
     tree.witness();
-    tree.append(&MerkleNode(c1));
-    tree.append(&MerkleNode(c2));
+    tree.append(&MerkleNode::from(c1));
+    tree.append(&MerkleNode::from(c2));
     let leaf_pos = tree.witness().unwrap();
-    tree.append(&MerkleNode(c3));
+    tree.append(&MerkleNode::from(c3));
     tree.witness();
 
     let root = tree.root(0).unwrap();
@@ -89,7 +89,7 @@ fn zkvm_opcodes() -> Result<()> {
         *value_coords.y(),
         c2,
         d,
-        root.0,
+        root.inner(),
         *public_coords.x(),
         *public_coords.y(),
     ];