Ver Fonte

fix various warnings and general cleanup

x há 3 anos atrás
pai
commit
155e7473a4

+ 0 - 5
src/blockchain/contractstore.rs

@@ -25,11 +25,6 @@ use crate::{Error, Result};
 const SLED_CONTRACTS_TREE: &[u8] = b"_contracts";
 const SLED_BINCODE_TREE: &[u8] = b"_wasm_bincode";
 
-// Logger targets
-const CS_TGT_INIT: &str = "blockchain::contractstatestore::init";
-const CS_TGT_LKUP: &str = "blockchain::contractstatestore::lookup";
-const CS_TGT_DROP: &str = "blockchain::contractstatestore::remove";
-
 /// The `WasmStore` is a `sled` tree that stores the wasm bincode for deployed
 /// contracts.
 #[derive(Clone)]

+ 2 - 2
src/contract/dao/src/dao_client/exec.rs

@@ -46,12 +46,12 @@ use darkfi::{
     Error, Result,
 };
 
-use super::propose::{DaoParams, Proposal};
+use super::{propose::Proposal, Dao};
 use crate::dao_model::DaoExecParams;
 
 pub struct Builder {
     pub proposal: Proposal,
-    pub dao: DaoParams,
+    pub dao: Dao,
     pub yes_votes_value: u64,
     pub all_votes_value: u64,
     pub yes_votes_blind: pallas::Scalar,

+ 11 - 0
src/contract/dao/src/dao_client/mint.rs

@@ -98,6 +98,17 @@ impl WalletCache {
     }
 }
 
+#[derive(Clone)]
+pub struct Dao {
+    pub proposer_limit: u64,
+    pub quorum: u64,
+    pub approval_ratio_quot: u64,
+    pub approval_ratio_base: u64,
+    pub gov_token_id: TokenId,
+    pub public_key: PublicKey,
+    pub bulla_blind: pallas::Base,
+}
+
 struct DaoMintRevealed {
     pub bulla: DaoBulla,
 }

+ 7 - 16
src/contract/dao/src/dao_client/propose.rs

@@ -50,23 +50,14 @@ use crate::{
     note,
 };
 
-#[derive(Clone)]
-pub struct DaoParams {
-    pub proposer_limit: u64,
-    pub quorum: u64,
-    pub approval_ratio_quot: u64,
-    pub approval_ratio_base: u64,
-    pub gov_token_id: TokenId,
-    pub public_key: PublicKey,
-    pub bulla_blind: pallas::Base,
-}
+use super::Dao;
 
 #[derive(SerialEncodable, SerialDecodable)]
 pub struct Note {
     pub proposal: Proposal,
 }
 
-pub struct BuilderInput {
+pub struct ProposalStakeInput {
     pub secret: SecretKey,
     //pub note: money::transfer::wallet::Note,
     pub note: darkfi_money_contract::client::Note,
@@ -84,18 +75,18 @@ pub struct Proposal {
     pub blind: pallas::Base,
 }
 
-pub struct Builder {
-    pub inputs: Vec<BuilderInput>,
+pub struct ProposeCall {
+    pub inputs: Vec<ProposalStakeInput>,
     pub proposal: Proposal,
-    pub dao: DaoParams,
+    pub dao: Dao,
     pub dao_leaf_position: incrementalmerkletree::Position,
     pub dao_merkle_path: Vec<MerkleNode>,
     pub dao_merkle_root: MerkleNode,
 }
 
-impl Builder {
+impl ProposeCall {
     //pub fn build(self /*, zk_bins: &ZkContractTable */) -> Result<(DaoProposeParams, Vec<Proof>)> {
-    pub fn build(
+    pub fn make(
         self,
         burn_zkbin: &ZkBinary,
         burn_pk: &ProvingKey,

+ 2 - 2
src/contract/dao/src/dao_client/vote.rs

@@ -47,7 +47,7 @@ use darkfi::{
     Error, Result,
 };
 
-use super::propose::{DaoParams, Proposal};
+use super::{propose::Proposal, Dao};
 use crate::{
     dao_model::{DaoVoteParams, VoteInput},
     note,
@@ -82,7 +82,7 @@ pub struct Builder {
     pub vote: Vote,
     pub vote_keypair: Keypair,
     pub proposal: Proposal,
-    pub dao: DaoParams,
+    pub dao: Dao,
 }
 
 impl Builder {

+ 18 - 6
src/contract/dao/src/entrypoint.rs

@@ -67,6 +67,7 @@ pub const DAO_ROOTS_TREE: &str = "dao_roots";
 //pub const DAO_PROPOSAL_TREE: &str = "dao_proposals";
 //pub const DAO_PROPOSAL_ROOTS_TREE: &str = "dao_proposal_roots";
 pub const DAO_PROPOSAL_VOTES_TREE: &str = "dao_proposal_votes";
+pub const DAO_VOTE_NULLS: &str = "dao_vote_nulls";
 
 // These are keys inside the some db trees
 pub const DAO_MERKLE_TREE: &str = "dao_merkle_tree";
@@ -164,6 +165,11 @@ fn init_contract(cid: ContractId, _ix: &[u8]) -> ContractResult {
         Err(_) => db_init(cid, DAO_PROPOSAL_VOTES_TREE)?,
     };
 
+    let _ = match db_lookup(cid, DAO_VOTE_NULLS) {
+        Ok(v) => v,
+        Err(_) => db_init(cid, DAO_VOTE_NULLS)?,
+    };
+
     Ok(())
 }
 
@@ -236,10 +242,10 @@ fn process_instruction(cid: ContractId, ix: &[u8]) -> ContractResult {
             let mut proposal_votes: ProposalVotes = deserialize(&proposal_votes)?;
 
             // Check the Merkle roots and nullifiers for the input coins are valid
-            let mut vote_nullifiers = vec![];
-            let mut all_vote_commit = pallas::Point::identity();
+            // TODO: vote_nullifiers is useless
             let money_roots_db = db_lookup(money_cid, MONEY_CONTRACT_COIN_ROOTS_TREE)?;
             let money_nullifier_db = db_lookup(money_cid, MONEY_CONTRACT_NULLIFIERS_TREE)?;
+            let dao_vote_nulls_db = db_lookup(cid, DAO_VOTE_NULLS)?;
 
             for input in &params.inputs {
                 if !db_contains_key(money_roots_db, &serialize(&input.merkle_root))? {
@@ -252,8 +258,8 @@ fn process_instruction(cid: ContractId, ix: &[u8]) -> ContractResult {
                     return Err(ContractError::Custom(6))
                 }
 
-                if vote_nullifiers.contains(&input.nullifier) ||
-                    proposal_votes.vote_nullifiers.contains(&input.nullifier)
+                if proposal_votes.vote_nullifiers.contains(&input.nullifier) ||
+                    db_contains_key(dao_vote_nulls_db, &serialize(&input.nullifier))?
                 {
                     msg!("Attempted double vote");
                     return Err(ContractError::Custom(7))
@@ -376,7 +382,7 @@ fn process_update(cid: ContractId, ix: &[u8]) -> ContractResult {
         }
 
         DaoFunction::Vote => {
-            let mut update: DaoVoteUpdate = deserialize(&ix[1..])?;
+            let update: DaoVoteUpdate = deserialize(&ix[1..])?;
 
             // Perform this code:
             //votes_info.yes_votes_commit += self.yes_vote_commit;
@@ -390,6 +396,12 @@ fn process_update(cid: ContractId, ix: &[u8]) -> ContractResult {
                 &serialize(&update.proposal_votes),
             )?;
 
+            let dao_vote_nulls_db = db_lookup(cid, DAO_VOTE_NULLS)?;
+
+            for nullifier in update.proposal_votes.vote_nullifiers {
+                db_set(dao_vote_nulls_db, &serialize(&nullifier), &[])?;
+            }
+
             Ok(())
         }
 
@@ -405,7 +417,7 @@ fn process_update(cid: ContractId, ix: &[u8]) -> ContractResult {
     }
 }
 
-fn get_metadata(cid: ContractId, ix: &[u8]) -> ContractResult {
+fn get_metadata(_: ContractId, ix: &[u8]) -> ContractResult {
     let (call_idx, call): (u32, Vec<ContractCall>) = deserialize(ix)?;
     assert!(call_idx < call.len() as u32);
 

+ 8 - 8
src/contract/dao/tests/integration.rs

@@ -39,6 +39,7 @@ use log::{debug, info};
 use rand::rngs::OsRng;
 
 use darkfi_dao_contract::{
+    dao_client,
     dao_client::{
         exec as dao_exec_client,
         mint::{build_dao_mint_tx, MerkleTree, WalletCache},
@@ -68,7 +69,7 @@ use harness::{init_logger, DaoTestHarness};
 async fn integration_test() -> Result<()> {
     init_logger()?;
 
-    let mut dao_th = DaoTestHarness::new().await?;
+    let dao_th = DaoTestHarness::new().await?;
 
     // Money parameters
     let xdrk_supply = 1_000_000;
@@ -406,7 +407,7 @@ async fn integration_test() -> Result<()> {
     // TODO: is it possible for an invalid transfer() to be constructed on exec()?
     //       need to look into this
     let signature_secret = SecretKey::random(&mut OsRng);
-    let input = dao_propose_client::BuilderInput {
+    let input = dao_client::ProposalStakeInput {
         secret: dao_th.alice_kp.secret,
         note: gov_recv[0].note.clone(),
         leaf_position: money_leaf_position,
@@ -421,7 +422,7 @@ async fn integration_test() -> Result<()> {
         (merkle_path, root)
     };
 
-    let dao_params = dao_propose_client::DaoParams {
+    let dao_params = dao_client::Dao {
         proposer_limit: dao_proposer_limit,
         quorum: dao_quorum,
         approval_ratio_base: dao_approval_ratio_base,
@@ -431,7 +432,7 @@ async fn integration_test() -> Result<()> {
         bulla_blind: dao_bulla_blind,
     };
 
-    let proposal = dao_propose_client::Proposal {
+    let proposal = dao_client::Proposal {
         dest: receiver_keypair.public,
         amount: 1000,
         serial: pallas::Base::random(&mut OsRng),
@@ -439,7 +440,7 @@ async fn integration_test() -> Result<()> {
         blind: pallas::Base::random(&mut OsRng),
     };
 
-    let builder = dao_propose_client::Builder {
+    let call = dao_client::ProposeCall {
         inputs: vec![input],
         proposal,
         dao: dao_params.clone(),
@@ -447,7 +448,7 @@ async fn integration_test() -> Result<()> {
         dao_merkle_path,
         dao_merkle_root,
     };
-    let (params, proofs) = builder.build(
+    let (params, proofs) = call.make(
         &dao_th.dao_propose_burn_zkbin,
         &dao_th.dao_propose_burn_pk,
         &dao_th.dao_propose_main_zkbin,
@@ -882,8 +883,7 @@ async fn integration_test() -> Result<()> {
         hook_dao_exec: spend_hook,
         signature_secret: exec_signature_secret,
     };
-    let (exec_params, mut exec_proofs) =
-        builder.build(&dao_th.dao_exec_zkbin, &dao_th.dao_exec_pk)?;
+    let (exec_params, exec_proofs) = builder.build(&dao_th.dao_exec_zkbin, &dao_th.dao_exec_pk)?;
 
     let mut data = vec![DaoFunction::Exec as u8];
     exec_params.encode(&mut data)?;

+ 0 - 2
src/zk/vm.rs

@@ -63,8 +63,6 @@ use crate::zkas::{
     Opcode, ZkBinary,
 };
 
-const L_TGT: &str = "zkvm";
-
 #[derive(Clone)]
 pub struct VmConfig {
     primary: Column<InstanceColumn>,