daod: delete #allow_unused and clean up warnings

This commit is contained in:
ihateface
2022-08-24 16:28:23 +02:00
parent e396bd2701
commit 0cc717de93
13 changed files with 73 additions and 168 deletions

View File

@@ -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<Update> {
@@ -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<T> = std::result::Result<T, Error>;
pub struct CallData {

View File

@@ -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,
};

View File

@@ -1,5 +1,3 @@
#![allow(unused)]
// mint()
pub mod mint;
// propose()

View File

@@ -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;

View File

@@ -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,
};

View File

@@ -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)
}
}

View File

@@ -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;

View File

@@ -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,
};

View File

@@ -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_contract::State>(&"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_contract::State>(&"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

View File

@@ -1,5 +1,3 @@
#![allow(unused)]
pub mod state;
pub mod transfer;

View File

@@ -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;

View File

@@ -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<Proof>) -> 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),

View File

@@ -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,