parazyd 3 лет назад
Родитель
Сommit
d4cfefe132
4 измененных файлов с 0 добавлено и 660 удалено
  1. 0 259
      src/node/client.rs
  2. 0 89
      src/node/memorystate.rs
  3. 0 26
      src/node/mod.rs
  4. 0 286
      src/node/state.rs

+ 0 - 259
src/node/client.rs

@@ -1,259 +0,0 @@
-/* This file is part of DarkFi (https://dark.fi)
- *
- * Copyright (C) 2020-2022 Dyne.org foundation
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <https://www.gnu.org/licenses/>.
- */
-
-use async_std::sync::{Arc, Mutex};
-use darkfi_sdk::crypto::{
-    constants::MERKLE_DEPTH, Address, Keypair, MerkleNode, PublicKey, TokenId,
-};
-use incrementalmerkletree::{bridgetree::BridgeTree, Tree};
-use lazy_init::Lazy;
-use log::{debug, error, info};
-
-use super::state::{state_transition, State};
-use crate::{
-    crypto::{
-        coin::{Coin, OwnCoin},
-        proof::ProvingKey,
-    },
-    tx::{
-        builder::{
-            TransactionBuilder, TransactionBuilderClearInputInfo, TransactionBuilderInputInfo,
-            TransactionBuilderOutputInfo,
-        },
-        Transaction,
-    },
-    wallet::walletdb::{Balance, Balances, WalletPtr},
-    zk::circuit::{BurnContract, MintContract},
-    ClientFailed, ClientResult, Result,
-};
-
-/// The Client structure, used for transaction operations.
-/// This includes, receiving, broadcasting, and building.
-pub struct Client {
-    pub main_keypair: Mutex<Keypair>,
-    pub wallet: WalletPtr,
-    mint_pk: Lazy<ProvingKey>,
-    burn_pk: Lazy<ProvingKey>,
-}
-
-impl Client {
-    pub async fn new(wallet: WalletPtr) -> Result<Self> {
-        // Initialize or load the wallet
-        wallet.init_db().await?;
-
-        // Get default keypair or create one
-        let main_keypair = wallet.get_default_keypair_or_create_one().await?;
-        info!(target: "client", "Main keypair: {}", Address::from(main_keypair.public));
-
-        // Generate merkle tree if we don't have one.
-        // TODO: See what to do about this
-        if wallet.get_tree().await.is_err() {
-            wallet.tree_gen().await?;
-        }
-
-        Ok(Self {
-            main_keypair: Mutex::new(main_keypair),
-            wallet,
-            mint_pk: Lazy::new(),
-            burn_pk: Lazy::new(),
-        })
-    }
-
-    // TODO: Better function name
-    async fn build_slab_from_tx(
-        &self,
-        pubkey: PublicKey,
-        value: u64,
-        token_id: TokenId,
-        clear_input: bool,
-        state: Arc<Mutex<State>>,
-    ) -> ClientResult<(Transaction, Vec<Coin>)> {
-        debug!("build_slab_from_tx(): Begin building slab from tx");
-        let mut clear_inputs = vec![];
-        let mut inputs = vec![];
-        let mut outputs = vec![];
-        let mut coins = vec![];
-
-        if clear_input {
-            debug!("build_slab_from_tx(): Building clear input");
-            let signature_secret = self.main_keypair.lock().await.secret;
-            let input = TransactionBuilderClearInputInfo { value, token_id, signature_secret };
-            clear_inputs.push(input);
-        } else {
-            debug!("build_slab_from_tx(): Building tx inputs");
-            let mut inputs_value = 0;
-            let state_m = state.lock().await;
-            let own_coins = self.wallet.get_own_coins().await?;
-
-            for own_coin in own_coins.iter() {
-                if inputs_value >= value {
-                    debug!("build_slab_from_tx(): inputs_value >= value");
-                    break
-                }
-
-                let leaf_position = own_coin.leaf_position;
-                let root = state_m.tree.root(0).unwrap();
-                let merkle_path = state_m.tree.authentication_path(leaf_position, &root).unwrap();
-                inputs_value += own_coin.note.value;
-
-                let input = TransactionBuilderInputInfo {
-                    leaf_position,
-                    merkle_path,
-                    secret: own_coin.secret,
-                    note: own_coin.note.clone(),
-                };
-
-                inputs.push(input);
-                coins.push(own_coin.coin);
-            }
-            // Release state lock
-            drop(state_m);
-
-            if inputs_value < value {
-                error!("build_slab_from_tx(): Not enough value to build tx inputs");
-                return Err(ClientFailed::NotEnoughValue(inputs_value))
-            }
-
-            if inputs_value > value {
-                let return_value = inputs_value - value;
-                outputs.push(TransactionBuilderOutputInfo {
-                    value: return_value,
-                    token_id,
-                    public: self.main_keypair.lock().await.public,
-                });
-            }
-
-            debug!("build_slab_from_tx(): Finished building inputs");
-        }
-
-        outputs.push(TransactionBuilderOutputInfo { value, token_id, public: pubkey });
-        let builder = TransactionBuilder { clear_inputs, inputs, outputs };
-
-        let mint_pk = self.mint_pk.get_or_create(Client::build_mint_pk);
-        let burn_pk = self.burn_pk.get_or_create(Client::build_burn_pk);
-        let tx = builder.build(mint_pk, burn_pk)?;
-
-        // Check if state transition is valid before broadcasting
-        debug!("build_slab_from_tx(): Checking if state transition is valid");
-        let state = &*state.lock().await;
-        debug!("build_slab_from_tx(): Got state lock");
-        state_transition(state, tx.clone())?;
-        debug!("build_slab_from_tx(): Successful state transition");
-
-        Ok((tx, coins))
-    }
-
-    /// Build a transaction given the required parameters and state machine.
-    pub async fn build_transaction(
-        &self,
-        pubkey: PublicKey,
-        amount: u64,
-        token_id: TokenId,
-        clear_input: bool,
-        state: Arc<Mutex<State>>,
-    ) -> ClientResult<Transaction> {
-        debug!("send(): Sending {} {} tokens", amount, token_id);
-
-        if amount == 0 {
-            return Err(ClientFailed::InvalidAmount(0))
-        }
-
-        if !self.wallet.token_id_exists(token_id).await? && !clear_input {
-            return Err(ClientFailed::NotEnoughValue(amount))
-        }
-
-        let (tx, coins) =
-            self.build_slab_from_tx(pubkey, amount, token_id, clear_input, state).await?;
-        for coin in coins.iter() {
-            // TODO: This should be more robust. In case our transaction is denied,
-            // we want to revert to be able to send again.
-            self.wallet.confirm_spend_coin(coin).await?;
-        }
-
-        debug!("send(): Sent {}", amount);
-        Ok(tx)
-    }
-
-    pub async fn init_db(&self) -> Result<()> {
-        self.wallet.init_db().await
-    }
-
-    pub async fn get_own_coins(&self) -> Result<Vec<OwnCoin>> {
-        self.wallet.get_own_coins().await
-    }
-
-    pub async fn confirm_spend_coin(&self, coin: &Coin) -> Result<()> {
-        self.wallet.confirm_spend_coin(coin).await
-    }
-
-    pub async fn revert_spend_coin(&self, coin: &Coin) -> Result<()> {
-        self.wallet.revert_spend_coin(coin).await
-    }
-
-    pub async fn get_keypairs(&self) -> Result<Vec<Keypair>> {
-        self.wallet.get_keypairs().await
-    }
-
-    pub async fn put_keypair(&self, keypair: &Keypair) -> Result<()> {
-        self.wallet.put_keypair(keypair).await
-    }
-
-    pub async fn set_default_keypair(&self, public: &PublicKey) -> Result<()> {
-        let kp = self.wallet.set_default_keypair(public).await?;
-        let mut mk = self.main_keypair.lock().await;
-        *mk = kp;
-        drop(mk);
-        Ok(())
-    }
-
-    pub async fn keygen(&self) -> Result<Address> {
-        let kp = self.wallet.keygen().await?;
-        Ok(Address::from(kp.public))
-    }
-
-    pub async fn get_balance(&self, token_id: TokenId) -> Result<Option<Balance>> {
-        self.wallet.get_balance(token_id).await
-    }
-
-    pub async fn get_balances(&self) -> Result<Balances> {
-        self.wallet.get_balances().await
-    }
-
-    pub async fn get_coins_valtok(
-        &self,
-        value: u64,
-        token_id: TokenId,
-        unspent: bool,
-    ) -> Result<Vec<OwnCoin>> {
-        self.wallet.get_coins_valtok(value, token_id, unspent).await
-    }
-
-    pub async fn get_tree(&self) -> Result<BridgeTree<MerkleNode, MERKLE_DEPTH>> {
-        self.wallet.get_tree().await
-    }
-
-    fn build_mint_pk() -> ProvingKey {
-        debug!("Building proving key for MintContract");
-        ProvingKey::build(11, &MintContract::default())
-    }
-
-    fn build_burn_pk() -> ProvingKey {
-        debug!("Building proving key for BurnContract");
-        ProvingKey::build(11, &BurnContract::default())
-    }
-}

+ 0 - 89
src/node/memorystate.rs

@@ -1,89 +0,0 @@
-/* This file is part of DarkFi (https://dark.fi)
- *
- * Copyright (C) 2020-2022 Dyne.org foundation
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <https://www.gnu.org/licenses/>.
- */
-
-use darkfi_sdk::crypto::{constants::MERKLE_DEPTH, MerkleNode, Nullifier, PublicKey};
-use incrementalmerkletree::{bridgetree::BridgeTree, Tree};
-use log::debug;
-
-use super::state::{ProgramState, State, StateUpdate};
-use crate::crypto::proof::VerifyingKey;
-
-/// In-memory state extension for state transition validations
-#[derive(Clone)]
-pub struct MemoryState {
-    /// Canonical state
-    pub canon: State,
-    /// The entire Merkle tree state (copied from `canon`)
-    pub tree: BridgeTree<MerkleNode, MERKLE_DEPTH>,
-    /// List of all previous and the current merkle roots.
-    pub merkle_roots: Vec<MerkleNode>,
-    /// Nullifiers prevent double-spending
-    pub nullifiers: Vec<Nullifier>,
-}
-
-impl ProgramState for MemoryState {
-    fn is_valid_cashier_public_key(&self, public: &PublicKey) -> bool {
-        self.canon.is_valid_cashier_public_key(public)
-    }
-
-    fn is_valid_faucet_public_key(&self, public: &PublicKey) -> bool {
-        self.canon.is_valid_faucet_public_key(public)
-    }
-
-    fn is_valid_merkle(&self, merkle_root: &MerkleNode) -> bool {
-        self.merkle_roots.contains(merkle_root) || self.canon.is_valid_merkle(merkle_root)
-    }
-
-    fn nullifier_exists(&self, nullifier: &Nullifier) -> bool {
-        self.nullifiers.contains(nullifier) || self.canon.nullifier_exists(nullifier)
-    }
-
-    fn mint_vk(&self) -> &VerifyingKey {
-        self.canon.mint_vk()
-    }
-
-    fn burn_vk(&self) -> &VerifyingKey {
-        self.canon.burn_vk()
-    }
-}
-
-impl MemoryState {
-    pub fn new(canon_state: State) -> Self {
-        Self {
-            canon: canon_state.clone(),
-            tree: canon_state.tree,
-            merkle_roots: vec![],
-            nullifiers: vec![],
-        }
-    }
-
-    pub fn apply(&mut self, update: StateUpdate) {
-        debug!(target: "state_apply", "(in-memory) Extend nullifier set");
-        let mut nfs = update.nullifiers.clone();
-        self.nullifiers.append(&mut nfs);
-
-        debug!(target: "state_apply", "(in-memory) Update Merkle tree and witnesses");
-        for coin in update.coins {
-            let node = MerkleNode::from(coin.0);
-            self.tree.append(&node);
-            self.merkle_roots.push(self.tree.root(0).unwrap());
-        }
-
-        debug!(target: "state_apply", "(in-memory) Finished apply() successfully.");
-    }
-}

+ 0 - 26
src/node/mod.rs

@@ -1,26 +0,0 @@
-/* This file is part of DarkFi (https://dark.fi)
- *
- * Copyright (C) 2020-2022 Dyne.org foundation
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <https://www.gnu.org/licenses/>.
- */
-
-pub mod client;
-pub use client::Client;
-
-pub mod state;
-pub use state::State;
-
-pub mod memorystate;
-pub use memorystate::MemoryState;

+ 0 - 286
src/node/state.rs

@@ -1,286 +0,0 @@
-/* This file is part of DarkFi (https://dark.fi)
- *
- * Copyright (C) 2020-2022 Dyne.org foundation
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <https://www.gnu.org/licenses/>.
- */
-
-use darkfi_sdk::crypto::{
-    constants::MERKLE_DEPTH, poseidon_hash, MerkleNode, Nullifier, PublicKey, SecretKey,
-};
-use incrementalmerkletree::{bridgetree::BridgeTree, Tree};
-use lazy_init::Lazy;
-use log::{debug, error};
-
-use crate::{
-    blockchain::{nfstore::NullifierStore, rootstore::RootStore, Blockchain},
-    consensus::{TESTNET_GENESIS_HASH_BYTES, TESTNET_GENESIS_TIMESTAMP},
-    crypto::{
-        coin::{Coin, OwnCoin},
-        note::{EncryptedNote, Note},
-        proof::VerifyingKey,
-    },
-    tx::Transaction,
-    wallet::walletdb::WalletPtr,
-    zk::circuit::{BurnContract, MintContract},
-    Result, VerifyFailed, VerifyResult,
-};
-
-/// Trait implementing the state functions used by the state transition.
-pub trait ProgramState {
-    /// Check if the public key is coming from a trusted cashier
-    fn is_valid_cashier_public_key(&self, public: &PublicKey) -> bool;
-    /// Check if the public key is coming from a trusted faucet
-    fn is_valid_faucet_public_key(&self, public: &PublicKey) -> bool;
-    /// Check if a merkle root is valid in this context
-    fn is_valid_merkle(&self, merkle: &MerkleNode) -> bool;
-    /// Check if the nullifier has been seen already
-    fn nullifier_exists(&self, nullifier: &Nullifier) -> bool;
-    /// Mint proof verification key
-    fn mint_vk(&self) -> &VerifyingKey;
-    /// Burn proof verification key
-    fn burn_vk(&self) -> &VerifyingKey;
-}
-
-/// A struct representing a state update.
-/// This gets applied on top of an existing state.
-#[derive(Clone)]
-pub struct StateUpdate {
-    /// All nullifiers in a transaction
-    pub nullifiers: Vec<Nullifier>,
-    /// All coins in a transaction
-    pub coins: Vec<Coin>,
-    /// All encrypted notes in a transaction
-    pub enc_notes: Vec<EncryptedNote>,
-}
-
-/// State transition function
-pub fn state_transition<S: ProgramState>(state: &S, tx: Transaction) -> VerifyResult<StateUpdate> {
-    // Check the public keys in the clear inputs to see if they're coming
-    // from a valid cashier or faucet.
-    debug!(target: "state_transition", "Iterate clear_inputs");
-    for (i, input) in tx.clear_inputs.iter().enumerate() {
-        let pk = &input.signature_public;
-        // TODO: this depends on the token ID
-        if !state.is_valid_cashier_public_key(pk) && !state.is_valid_faucet_public_key(pk) {
-            error!(target: "state_transition", "Invalid pubkey for clear input: {:?}", pk);
-            return Err(VerifyFailed::InvalidCashierOrFaucetKey(i))
-        }
-    }
-
-    // Nullifiers in the transaction
-    let mut nullifiers = Vec::with_capacity(tx.inputs.len());
-
-    debug!(target: "state_transition", "Iterate inputs");
-    for (i, input) in tx.inputs.iter().enumerate() {
-        let merkle = &input.revealed.merkle_root;
-
-        // The Merkle root is used to know whether this is a coin that
-        // existed in a previous state.
-        if !state.is_valid_merkle(merkle) {
-            error!(target: "state_transition", "Invalid Merkle root (input {})", i);
-            debug!(target: "state_transition", "root: {:?}", merkle);
-            return Err(VerifyFailed::InvalidMerkle(i))
-        }
-
-        // The nullifiers should not already exist.
-        // It is the double-spend protection.
-        let nullifier = &input.revealed.nullifier;
-        if state.nullifier_exists(nullifier) ||
-            (1..nullifiers.len()).any(|i| nullifiers[i..].contains(&nullifiers[i - 1]))
-        {
-            error!(target: "state_transition", "Duplicate nullifier found (input {})", i);
-            debug!(target: "state_transition", "nullifier: {:?}", nullifier);
-            return Err(VerifyFailed::NullifierExists(i))
-        }
-
-        nullifiers.push(input.revealed.nullifier);
-    }
-
-    debug!(target: "state_transition", "Verifying zk proofs");
-    match tx.verify(state.mint_vk(), state.burn_vk()) {
-        Ok(()) => debug!(target: "state_transition", "Verified successfully"),
-        Err(e) => {
-            error!(target: "state_transition", "Failed verifying zk proofs: {}", e);
-            return Err(VerifyFailed::ProofVerifyFailed(e.to_string()))
-        }
-    }
-
-    // Newly created coins for this transaction
-    let mut coins = Vec::with_capacity(tx.outputs.len());
-    let mut enc_notes = Vec::with_capacity(tx.outputs.len());
-    for output in tx.outputs {
-        // Gather all the coins
-        coins.push(output.revealed.coin);
-        enc_notes.push(output.enc_note);
-    }
-
-    Ok(StateUpdate { nullifiers, coins, enc_notes })
-}
-
-/// Struct holding the state which we can apply a [`StateUpdate`] onto.
-#[derive(Clone)]
-pub struct State {
-    /// The entire Merkle tree state
-    pub tree: BridgeTree<MerkleNode, MERKLE_DEPTH>,
-    /// List of all previous and the current merkle roots.
-    /// This is the hashed value of all the children.
-    pub merkle_roots: RootStore,
-    /// Nullifiers prevent double-spending
-    pub nullifiers: NullifierStore,
-    /// List of Cashier public keys
-    pub cashier_pubkeys: Vec<PublicKey>,
-    /// List of Faucet public keys
-    pub faucet_pubkeys: Vec<PublicKey>,
-    /// Verifying key for the Mint ZK proof
-    pub mint_vk: Lazy<VerifyingKey>,
-    /// Verifying key for the Burn ZK proof
-    pub burn_vk: Lazy<VerifyingKey>,
-}
-
-impl State {
-    /// Create a dummy state
-    pub fn dummy() -> Result<Self> {
-        let db = sled::Config::new().temporary(true).open()?;
-        let bc = Blockchain::new(&db, *TESTNET_GENESIS_TIMESTAMP, *TESTNET_GENESIS_HASH_BYTES)?;
-        let mt = BridgeTree::<MerkleNode, 32>::new(100);
-        Ok(State {
-            tree: mt,
-            merkle_roots: bc.merkle_roots,
-            nullifiers: bc.nullifiers,
-            cashier_pubkeys: vec![],
-            faucet_pubkeys: vec![],
-            mint_vk: Lazy::new(),
-            burn_vk: Lazy::new(),
-        })
-    }
-
-    /// Apply a [`StateUpdate`] to some state.
-    pub async fn apply(
-        &mut self,
-        update: StateUpdate,
-        secret_keys: Vec<SecretKey>,
-        notify: Option<smol::channel::Sender<(PublicKey, u64)>>,
-        wallet: WalletPtr,
-    ) -> Result<()> {
-        debug!(target: "state_apply", "Extend nullifier set");
-        debug!("Existing nullifiers: {:#?}", self.nullifiers.get_all()?);
-        debug!("Update's nullifiers: {:#?}", update.nullifiers);
-        self.nullifiers.insert(&update.nullifiers)?;
-
-        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::from(coin.0);
-            debug!("Current merkle tree: {:#?}", self.tree);
-            self.tree.append(&node);
-            debug!("Merkle tree after append: {:#?}", self.tree);
-
-            // Keep track of all Merkle roots that have existed
-            debug!("Existing merkle roots: {:#?}", self.merkle_roots.get_all()?);
-            debug!("New merkle root: {:#?}", self.tree.root(0).unwrap());
-            self.merkle_roots.insert(&[self.tree.root(0).unwrap()])?;
-
-            for secret in secret_keys.iter() {
-                if let Some(note) = State::try_decrypt_note(enc_note, *secret) {
-                    debug!(target: "state_apply", "Received a coin: amount {}", note.value);
-                    let leaf_position = self.tree.witness().unwrap();
-                    let nullifier =
-                        Nullifier::from(poseidon_hash::<2>([secret.inner(), note.serial]));
-                    let own_coin = OwnCoin {
-                        coin,
-                        note: note.clone(),
-                        secret: *secret,
-                        nullifier,
-                        leaf_position,
-                    };
-
-                    // TODO: FIXME: BUG check values inside the note are correct
-                    // We need to hash them all and check them against the coin
-                    // for them to be accepted.
-                    // Don't trust - verify.
-
-                    wallet.put_own_coin(own_coin).await?;
-
-                    if let Some(ch) = notify.clone() {
-                        debug!(target: "state_apply", "Send a notification");
-                        let pubkey = PublicKey::from_secret(*secret);
-                        ch.send((pubkey, note.value)).await?;
-                    }
-                }
-            }
-
-            // Save updated merkle tree into the wallet.
-            wallet.put_tree(&self.tree).await?;
-        }
-
-        debug!(target: "state_apply", "Finished apply() successfully.");
-        Ok(())
-    }
-
-    pub fn try_decrypt_note(ciphertext: &EncryptedNote, secret: SecretKey) -> Option<Note> {
-        match ciphertext.decrypt(&secret) {
-            Ok(note) => Some(note),
-            Err(_) => None,
-        }
-    }
-}
-
-impl ProgramState for State {
-    fn is_valid_cashier_public_key(&self, public: &PublicKey) -> bool {
-        debug!(target: "state_transition", "Checking if pubkey is a valid cashier");
-        self.cashier_pubkeys.contains(public)
-    }
-
-    fn is_valid_faucet_public_key(&self, public: &PublicKey) -> bool {
-        debug!(target: "state_transition", "Checking if pubkey is a valid faucet");
-        self.faucet_pubkeys.contains(public)
-    }
-
-    fn is_valid_merkle(&self, merkle_root: &MerkleNode) -> bool {
-        debug!(target: "state_transition", "Checking if Merkle root is valid");
-        if let Ok(mr) = self.merkle_roots.contains(merkle_root) {
-            return mr
-        }
-
-        panic!("RootStore db corruption, could not check merkle_roots.contains()");
-    }
-
-    fn nullifier_exists(&self, nullifier: &Nullifier) -> bool {
-        debug!(target: "state_transition", "Checking if Nullifier exists");
-        if let Ok(nf) = self.nullifiers.contains(nullifier) {
-            return nf
-        }
-
-        panic!("NullifierStore db corruption, could not check nullifiers.contains()");
-    }
-
-    fn mint_vk(&self) -> &VerifyingKey {
-        self.mint_vk.get_or_create(build_mint_vk)
-    }
-
-    fn burn_vk(&self) -> &VerifyingKey {
-        self.burn_vk.get_or_create(build_burn_vk)
-    }
-}
-
-fn build_mint_vk() -> VerifyingKey {
-    debug!("Building verifying key for MintContract");
-    VerifyingKey::build(11, &MintContract::default())
-}
-
-fn build_burn_vk() -> VerifyingKey {
-    debug!("Building verifying key for BurnContract");
-    VerifyingKey::build(11, &BurnContract::default())
-}