diff --git a/bin/daod/src/dao_contract/mint/validate.rs b/bin/daod/src/dao_contract/mint/validate.rs index a8afba837..c39a81267 100644 --- a/bin/daod/src/dao_contract/mint/validate.rs +++ b/bin/daod/src/dao_contract/mint/validate.rs @@ -1,4 +1,3 @@ -use pasta_curves::pallas; use std::any::{Any, TypeId}; use darkfi::crypto::types::DrkCircuitField; @@ -9,7 +8,7 @@ use crate::{ }; pub fn state_transition( - states: &StateRegistry, + _states: &StateRegistry, func_call_index: usize, parent_tx: &Transaction, ) -> Result { @@ -22,8 +21,6 @@ pub fn state_transition( // This will be inside wasm so unwrap is fine. let call_data = call_data.unwrap(); - // Code goes here - Ok(Update { dao_bulla: call_data.dao_bulla.clone() }) } @@ -39,10 +36,8 @@ pub fn apply(states: &mut StateRegistry, update: Update) { } #[derive(Debug, Clone, thiserror::Error)] -pub enum Error { - #[error("Malformed packet")] - MalformedPacket, -} +pub enum Error {} + type Result = std::result::Result; pub struct CallData { diff --git a/bin/daod/src/dao_contract/mint/wallet.rs b/bin/daod/src/dao_contract/mint/wallet.rs index bc6902fb8..43d1c73ac 100644 --- a/bin/daod/src/dao_contract/mint/wallet.rs +++ b/bin/daod/src/dao_contract/mint/wallet.rs @@ -1,19 +1,16 @@ -use std::any::Any; - use crate::dao_contract::state::DaoBulla; use darkfi::{ - crypto::{keypair::PublicKey, types::DrkCircuitField, Proof}, + crypto::{keypair::PublicKey, Proof}, zk::vm::{Witness, ZkCircuit}, }; -use halo2_gadgets::poseidon::primitives as poseidon; use halo2_proofs::circuit::Value; use pasta_curves::{arithmetic::CurveAffine, group::Curve, pallas}; use rand::rngs::OsRng; use crate::{ dao_contract::mint::validate::CallData, - demo::{CallDataBase, FuncCall, ZkContractInfo, ZkContractTable}, + demo::{FuncCall, ZkContractInfo, ZkContractTable}, util::poseidon_hash, }; diff --git a/bin/daod/src/dao_contract/mod.rs b/bin/daod/src/dao_contract/mod.rs index 7395f875a..d40b130a2 100644 --- a/bin/daod/src/dao_contract/mod.rs +++ b/bin/daod/src/dao_contract/mod.rs @@ -1,5 +1,3 @@ -#![allow(unused)] - // mint() pub mod mint; // propose() diff --git a/bin/daod/src/dao_contract/propose/validate.rs b/bin/daod/src/dao_contract/propose/validate.rs index 6b17a1d4f..b59547e25 100644 --- a/bin/daod/src/dao_contract/propose/validate.rs +++ b/bin/daod/src/dao_contract/propose/validate.rs @@ -1,27 +1,28 @@ use darkfi::{ crypto::{ keypair::PublicKey, merkle_node::MerkleNode, schnorr, schnorr::SchnorrPublic, - types::DrkCircuitField, Proof, + types::DrkCircuitField, }, - util::serial::{Encodable, SerialDecodable, SerialEncodable, VarInt}, + util::serial::{Encodable, SerialDecodable, SerialEncodable}, Error as DarkFiError, }; -use log::{debug, error}; +use log::error; use pasta_curves::{ arithmetic::CurveAffine, - group::{ff::Field, Curve, Group}, + group::{Curve, Group}, pallas, }; use std::any::{Any, TypeId}; use crate::{ - dao_contract::{DaoBulla, State as DaoState}, + dao_contract::State as DaoState, demo::{CallDataBase, StateRegistry, Transaction}, money_contract::state::State as MoneyState, note::EncryptedNote2, }; -const TARGET: &str = "dao_contract::propose::validate::state_transition()"; +// used for debugging +// const TARGET: &str = "dao_contract::propose::validate::state_transition()"; #[derive(Debug, Clone, thiserror::Error)] pub enum Error { @@ -152,7 +153,7 @@ pub fn state_transition( call_data.inputs.encode(&mut unsigned_tx_data).expect("failed to encode inputs"); func_call.proofs.encode(&mut unsigned_tx_data).expect("failed to encode proofs"); - for (i, (input, signature)) in + for (_i, (input, signature)) in call_data.inputs.iter().zip(call_data.signatures.iter()).enumerate() { let public = &input.signature_public; diff --git a/bin/daod/src/dao_contract/propose/wallet.rs b/bin/daod/src/dao_contract/propose/wallet.rs index 4bad06e2f..b5d77459f 100644 --- a/bin/daod/src/dao_contract/propose/wallet.rs +++ b/bin/daod/src/dao_contract/propose/wallet.rs @@ -2,24 +2,17 @@ use halo2_proofs::circuit::Value; use incrementalmerkletree::Hashable; use pasta_curves::{ arithmetic::CurveAffine, - group::{ff::Field, Curve, Group}, + group::{ff::Field, Curve}, pallas, }; use rand::rngs::OsRng; use darkfi::{ crypto::{ - burn_proof::create_burn_proof, keypair::{PublicKey, SecretKey}, merkle_node::MerkleNode, - mint_proof::create_mint_proof, - proof::ProvingKey, schnorr::SchnorrSecret, - types::{ - DrkCircuitField, DrkCoinBlind, DrkSerial, DrkSpendHook, DrkTokenId, DrkUserData, - DrkUserDataBlind, DrkValueBlind, - }, - util::{pedersen_commitment_base, pedersen_commitment_u64}, + util::pedersen_commitment_u64, Proof, }, util::serial::{Encodable, SerialDecodable, SerialEncodable}, @@ -28,7 +21,7 @@ use darkfi::{ use crate::{ dao_contract::propose::validate::{CallData, Header, Input}, - demo::{CallDataBase, FuncCall, StateRegistry, ZkContractInfo, ZkContractTable}, + demo::{FuncCall, ZkContractInfo, ZkContractTable}, money_contract, note, util::poseidon_hash, }; diff --git a/bin/daod/src/dao_contract/state.rs b/bin/daod/src/dao_contract/state.rs index 0d435e1bc..0f1045c4a 100644 --- a/bin/daod/src/dao_contract/state.rs +++ b/bin/daod/src/dao_contract/state.rs @@ -1,34 +1,11 @@ use incrementalmerkletree::{bridgetree::BridgeTree, Tree}; use pasta_curves::{ - arithmetic::CurveAffine, - group::{ - ff::{Field, PrimeField}, - Curve, Group, GroupEncoding, - }, + group::{ff::PrimeField, Group}, pallas, }; -use std::{ - any::{Any, TypeId}, - collections::HashMap, - hash::{Hash, Hasher}, -}; +use std::{any::Any, collections::HashMap, hash::Hasher}; -use darkfi::{ - crypto::{ - constants::MERKLE_DEPTH, - keypair::{Keypair, PublicKey, SecretKey}, - merkle_node::MerkleNode, - nullifier::Nullifier, - proof::VerifyingKey, - }, - node::state::{ProgramState, StateUpdate}, -}; - -use crate::{ - dao_contract::mint::validate::CallData, - demo::{StateRegistry, Transaction}, - Result, -}; +use darkfi::crypto::{constants::MERKLE_DEPTH, merkle_node::MerkleNode, nullifier::Nullifier}; #[derive(Clone)] pub struct DaoBulla(pub pallas::Base); @@ -122,7 +99,8 @@ impl State { self.dao_roots.iter().any(|m| m == root) } - pub fn is_valid_proposal_merkle(&self, root: &MerkleNode) -> bool { + // TODO: This never gets called. + pub fn _is_valid_proposal_merkle(&self, root: &MerkleNode) -> bool { self.proposal_roots.iter().any(|m| m == root) } } diff --git a/bin/daod/src/dao_contract/vote/validate.rs b/bin/daod/src/dao_contract/vote/validate.rs index c2201cfd6..5265946b2 100644 --- a/bin/daod/src/dao_contract/vote/validate.rs +++ b/bin/daod/src/dao_contract/vote/validate.rs @@ -1,21 +1,21 @@ use darkfi::{ crypto::{ keypair::PublicKey, merkle_node::MerkleNode, nullifier::Nullifier, schnorr, - schnorr::SchnorrPublic, types::DrkCircuitField, Proof, + schnorr::SchnorrPublic, types::DrkCircuitField, }, - util::serial::{Encodable, SerialDecodable, SerialEncodable, VarInt}, + util::serial::{Encodable, SerialDecodable, SerialEncodable}, Error as DarkFiError, }; -use log::{debug, error}; +use log::error; use pasta_curves::{ arithmetic::CurveAffine, - group::{ff::Field, Curve, Group}, + group::{Curve, Group}, pallas, }; use std::any::{Any, TypeId}; use crate::{ - dao_contract::{DaoBulla, State as DaoState}, + dao_contract::State as DaoState, demo::{CallDataBase, StateRegistry, Transaction}, money_contract::state::State as MoneyState, note::EncryptedNote2, @@ -35,9 +35,6 @@ pub enum Error { #[error("Invalid input merkle root")] InvalidInputMerkleRoot, - #[error("Invalid DAO merkle root")] - InvalidDaoMerkleRoot, - #[error("Signature verification failed")] SignatureVerifyFailed, @@ -185,7 +182,7 @@ pub fn state_transition( //debug!("unsigned_tx_data: {:?}", unsigned_tx_data); - for (i, (input, signature)) in + for (_i, (input, signature)) in call_data.inputs.iter().zip(call_data.signatures.iter()).enumerate() { let public = &input.signature_public; diff --git a/bin/daod/src/dao_contract/vote/wallet.rs b/bin/daod/src/dao_contract/vote/wallet.rs index 111c32569..eec5d9645 100644 --- a/bin/daod/src/dao_contract/vote/wallet.rs +++ b/bin/daod/src/dao_contract/vote/wallet.rs @@ -1,39 +1,30 @@ -use halo2_proofs::circuit::Value; -use incrementalmerkletree::Hashable; -use pasta_curves::{ - arithmetic::CurveAffine, - group::{ff::Field, Curve, Group}, - pallas, -}; -use rand::rngs::OsRng; -use std::any::{Any, TypeId}; - use darkfi::{ crypto::{ - burn_proof::create_burn_proof, keypair::{Keypair, PublicKey, SecretKey}, merkle_node::MerkleNode, - mint_proof::create_mint_proof, nullifier::Nullifier, - proof::ProvingKey, schnorr::SchnorrSecret, - types::{ - DrkCircuitField, DrkCoinBlind, DrkSerial, DrkSpendHook, DrkTokenId, DrkUserData, - DrkUserDataBlind, DrkValueBlind, - }, - util::{pedersen_commitment_base, pedersen_commitment_u64}, + util::pedersen_commitment_u64, Proof, }, util::serial::{Encodable, SerialDecodable, SerialEncodable}, zk::vm::{Witness, ZkCircuit}, }; +use halo2_proofs::circuit::Value; +use incrementalmerkletree::Hashable; +use pasta_curves::{ + arithmetic::CurveAffine, + group::{ff::Field, Curve}, + pallas, +}; +use rand::rngs::OsRng; use crate::{ dao_contract::{ propose::wallet::{DaoParams, Proposal}, vote::validate::{CallData, Header, Input}, }, - demo::{CallDataBase, FuncCall, StateRegistry, ZkContractInfo, ZkContractTable}, + demo::{FuncCall, ZkContractInfo, ZkContractTable}, money_contract, note, util::poseidon_hash, }; diff --git a/bin/daod/src/demo.rs b/bin/daod/src/demo.rs index fa45e149b..1d62020c6 100644 --- a/bin/daod/src/demo.rs +++ b/bin/daod/src/demo.rs @@ -1,8 +1,4 @@ -#![allow(unused)] - -use halo2_gadgets::poseidon::primitives as poseidon; -use halo2_proofs::circuit::Value; -use incrementalmerkletree::{bridgetree::BridgeTree, Tree}; +use incrementalmerkletree::Tree; use log::debug; use pasta_curves::{ arithmetic::CurveAffine, @@ -18,26 +14,15 @@ use std::{ use darkfi::{ crypto::{ - constants::MERKLE_DEPTH, keypair::{Keypair, PublicKey, SecretKey}, - merkle_node::MerkleNode, - note::{EncryptedNote, Note}, - nullifier::Nullifier, proof::{ProvingKey, VerifyingKey}, - token_id::generate_id, types::{DrkCircuitField, DrkSpendHook, DrkUserData, DrkValue}, util::pedersen_commitment_u64, - OwnCoin, OwnCoins, Proof, + Proof, }, - node::state::{ProgramState, StateUpdate}, - tx::builder::{ - TransactionBuilder, TransactionBuilderClearInputInfo, TransactionBuilderInputInfo, - TransactionBuilderOutputInfo, - }, - util::NetworkName, zk::{ circuit::{BurnContract, MintContract}, - vm::{Witness, ZkCircuit}, + vm::ZkCircuit, vm_stack::empty_witnesses, }, zkas::decoder::ZkBinary, @@ -50,7 +35,6 @@ use crate::{dao_contract, example_contract, money_contract, util::poseidon_hash} // * Vote updates are linked to the proposal_bulla // * Nullifier of vote will link vote with the coin when it's spent -// TODO: reenable unused vars warning and fix it // TODO: strategize and cleanup Result/Error usage // TODO: fix up code doc @@ -313,11 +297,6 @@ pub async fn demo() -> Result<()> { let dao_state = dao_contract::State::new(); states.register("DAO".to_string(), dao_state); - // For this demo lets create 10 random preexisting DAO bullas - for _ in 0..10 { - let bulla = pallas::Base::random(&mut OsRng); - } - ///////////////////////////////////////////////////// ////// Create the DAO bulla ///////////////////////////////////////////////////// @@ -447,35 +426,31 @@ pub async fn demo() -> Result<()> { //// Wallet // DAO reads the money received from the encrypted note - let dao_recv = { - let state = states.lookup_mut::(&"Money".to_string()).unwrap(); - let mut recv_coins = state.wallet_cache.get_received(&dao_keypair.secret); - assert_eq!(recv_coins.len(), 1); - let recv_coin = recv_coins.pop().unwrap(); - let note = &recv_coin.note; + let state = states.lookup_mut::(&"Money".to_string()).unwrap(); + let mut recv_coins = state.wallet_cache.get_received(&dao_keypair.secret); + assert_eq!(recv_coins.len(), 1); + let recv_coin = recv_coins.pop().unwrap(); + let note = &recv_coin.note; - // Check the actual coin received is valid before accepting it + // Check the actual coin received is valid before accepting it - let coords = dao_keypair.public.0.to_affine().coordinates().unwrap(); - let coin = poseidon_hash::<8>([ - *coords.x(), - *coords.y(), - DrkValue::from(note.value), - note.token_id, - note.serial, - note.spend_hook, - note.user_data, - note.coin_blind, - ]); - assert_eq!(coin, recv_coin.coin.0); + let coords = dao_keypair.public.0.to_affine().coordinates().unwrap(); + let coin = poseidon_hash::<8>([ + *coords.x(), + *coords.y(), + DrkValue::from(note.value), + note.token_id, + note.serial, + note.spend_hook, + note.user_data, + note.coin_blind, + ]); + assert_eq!(coin, recv_coin.coin.0); - assert_eq!(note.spend_hook, hook_dao_exec); - assert_eq!(note.user_data, dao_bulla.0); + assert_eq!(note.spend_hook, hook_dao_exec); + assert_eq!(note.user_data, dao_bulla.0); - debug!("DAO received a coin worth {} xDRK", note.value); - - recv_coin - }; + debug!("DAO received a coin worth {} xDRK", note.value); /////////////////////////////////////////////////// //// Mint the governance token diff --git a/bin/daod/src/money_contract/mod.rs b/bin/daod/src/money_contract/mod.rs index 0ce65a9f8..b0ade295b 100644 --- a/bin/daod/src/money_contract/mod.rs +++ b/bin/daod/src/money_contract/mod.rs @@ -1,5 +1,3 @@ -#![allow(unused)] - pub mod state; pub mod transfer; diff --git a/bin/daod/src/money_contract/state.rs b/bin/daod/src/money_contract/state.rs index b80716cea..198c3a3d0 100644 --- a/bin/daod/src/money_contract/state.rs +++ b/bin/daod/src/money_contract/state.rs @@ -1,15 +1,11 @@ use incrementalmerkletree::{bridgetree::BridgeTree, Tree}; -use darkfi::{ - crypto::{ - coin::Coin, - constants::MERKLE_DEPTH, - keypair::{Keypair, PublicKey, SecretKey}, - merkle_node::MerkleNode, - nullifier::Nullifier, - proof::VerifyingKey, - }, - node::state::{ProgramState, StateUpdate}, +use darkfi::crypto::{ + coin::Coin, + constants::MERKLE_DEPTH, + keypair::{PublicKey, SecretKey}, + merkle_node::MerkleNode, + nullifier::Nullifier, }; use super::transfer; diff --git a/bin/daod/src/money_contract/transfer/validate.rs b/bin/daod/src/money_contract/transfer/validate.rs index aeb57d504..d8a11eb79 100644 --- a/bin/daod/src/money_contract/transfer/validate.rs +++ b/bin/daod/src/money_contract/transfer/validate.rs @@ -1,30 +1,23 @@ -use std::{ - any::{Any, TypeId}, - io, -}; +use std::any::{Any, TypeId}; -use incrementalmerkletree::{bridgetree::BridgeTree, Tree}; +use incrementalmerkletree::Tree; use log::{debug, error}; use pasta_curves::group::Group; use darkfi::{ crypto::{ - burn_proof::verify_burn_proof, coin::Coin, keypair::PublicKey, merkle_node::MerkleNode, - mint_proof::verify_mint_proof, nullifier::Nullifier, - proof::VerifyingKey, schnorr, schnorr::SchnorrPublic, types::{DrkCircuitField, DrkTokenId, DrkValueBlind, DrkValueCommit}, util::{pedersen_commitment_base, pedersen_commitment_u64}, - BurnRevealedValues, MintRevealedValues, Proof, + BurnRevealedValues, MintRevealedValues, }, - node::state::ProgramState, - util::serial::{Encodable, SerialDecodable, SerialEncodable, VarInt}, + util::serial::{Encodable, SerialDecodable, SerialEncodable}, Error as DarkFiError, }; @@ -127,7 +120,7 @@ pub fn state_transition( } debug!(target: TARGET, "Verifying call data"); - match call_data.verify(&func_call.proofs) { + match call_data.verify() { Ok(()) => { debug!(target: TARGET, "Verified successfully") } @@ -183,7 +176,7 @@ impl CallDataBase for CallData { } impl CallData { /// Verify the transaction - pub fn verify(&self, proofs: &Vec) -> VerifyResult<()> { + pub fn verify(&self) -> VerifyResult<()> { // must have minimum 1 clear or anon input, and 1 output if self.clear_inputs.len() + self.inputs.len() == 0 { error!("tx::verify(): Missing inputs"); @@ -338,12 +331,6 @@ pub enum VerifyFailed { #[error("Money in does not match money out (value commitments)")] MissingFunds, - #[error("Mint proof verification failure for input {0}")] - MintProof(usize), - - #[error("Burn proof verification failure for input {0}")] - BurnProof(usize), - #[error("Failed verifying zk proofs: {0}")] ProofVerifyFailed(String), diff --git a/bin/daod/src/money_contract/transfer/wallet/builder.rs b/bin/daod/src/money_contract/transfer/wallet/builder.rs index dc279a695..288127533 100644 --- a/bin/daod/src/money_contract/transfer/wallet/builder.rs +++ b/bin/daod/src/money_contract/transfer/wallet/builder.rs @@ -7,7 +7,6 @@ use darkfi::{ keypair::{PublicKey, SecretKey}, merkle_node::MerkleNode, mint_proof::create_mint_proof, - proof::ProvingKey, schnorr::SchnorrSecret, types::{ DrkCoinBlind, DrkSerial, DrkSpendHook, DrkTokenId, DrkUserData, DrkUserDataBlind,