zero 2 лет назад
Родитель
Сommit
eb635dc3df

+ 3 - 6
bin/drk/src/money.rs

@@ -25,17 +25,14 @@ use rusqlite::types::Value;
 use darkfi::{tx::Transaction, zk::halo2::Field, Error, Result};
 use darkfi_money_contract::{
     client::{MoneyNote, OwnCoin},
-    model::{
-        Coin, MoneyTokenFreezeParamsV1, MoneyTokenMintParamsV1, MoneyTransferParamsV1,
-    },
+    model::{Coin, MoneyTokenFreezeParamsV1, MoneyTokenMintParamsV1, MoneyTransferParamsV1},
     MoneyFunction,
 };
 use darkfi_sdk::{
     bridgetree,
     crypto::{
-        poseidon_hash, Keypair, MerkleNode, MerkleTree, Nullifier, PublicKey, SecretKey, TokenId,
-        MONEY_CONTRACT_ID,
-        note::AeadEncryptedNote,
+        note::AeadEncryptedNote, poseidon_hash, Keypair, MerkleNode, MerkleTree, Nullifier,
+        PublicKey, SecretKey, TokenId, MONEY_CONTRACT_ID,
     },
     pasta::pallas,
 };

+ 18 - 11
bin/drk/src/token.rs

@@ -27,14 +27,19 @@ use darkfi::{
     Error, Result,
 };
 use darkfi_money_contract::{
-    client::{token_freeze_v1::TokenFreezeCallBuilder, token_mint_v1::TokenMintCallBuilder, auth_token_mint_v1::AuthTokenMintCallBuilder},
-    MoneyFunction, MONEY_CONTRACT_ZKAS_TOKEN_FRZ_NS_V1,
+    client::{
+        auth_token_mint_v1::AuthTokenMintCallBuilder, token_freeze_v1::TokenFreezeCallBuilder,
+        token_mint_v1::TokenMintCallBuilder,
+    },
+    model::{CoinAttributes, TokenAttributes},
+    MoneyFunction, MONEY_CONTRACT_ZKAS_AUTH_TOKEN_MINT_NS_V1, MONEY_CONTRACT_ZKAS_TOKEN_FRZ_NS_V1,
     MONEY_CONTRACT_ZKAS_TOKEN_MINT_NS_V1,
-    MONEY_CONTRACT_ZKAS_AUTH_TOKEN_MINT_NS_V1,
-    model::{CoinAttributes, TokenAttributes}
 };
 use darkfi_sdk::{
-    crypto::{contract_id::MONEY_CONTRACT_ID, Keypair, PublicKey, SecretKey, TokenId, FuncRef, pasta_prelude::*},
+    crypto::{
+        contract_id::MONEY_CONTRACT_ID, pasta_prelude::*, FuncRef, Keypair, PublicKey, SecretKey,
+        TokenId,
+    },
     dark_tree::DarkLeaf,
     pasta::pallas,
     tx::ContractCall,
@@ -151,8 +156,7 @@ impl Drk {
             };
 
             let mint_zkbin = ZkBinary::decode(&token_mint_zkbin.1)?;
-            let token_mint_circuit =
-                ZkCircuit::new(empty_witnesses(&mint_zkbin)?, &mint_zkbin);
+            let token_mint_circuit = ZkCircuit::new(empty_witnesses(&mint_zkbin)?, &mint_zkbin);
 
             eprintln!("Creating token mint circuit proving keys");
             let mint_pk = ProvingKey::build(mint_zkbin.k, &token_mint_circuit);
@@ -290,13 +294,16 @@ impl Drk {
         };
 
         let freeze_zkbin = ZkBinary::decode(&token_freeze_zkbin.1)?;
-        let token_freeze_circuit =
-            ZkCircuit::new(empty_witnesses(&freeze_zkbin)?, &freeze_zkbin);
+        let token_freeze_circuit = ZkCircuit::new(empty_witnesses(&freeze_zkbin)?, &freeze_zkbin);
 
         eprintln!("Creating token freeze circuit proving keys");
         let freeze_pk = ProvingKey::build(freeze_zkbin.k, &token_freeze_circuit);
-        let freeze_builder =
-            TokenFreezeCallBuilder { mint_keypair: mint_authority, token_attrs, freeze_zkbin, freeze_pk };
+        let freeze_builder = TokenFreezeCallBuilder {
+            mint_keypair: mint_authority,
+            token_attrs,
+            freeze_zkbin,
+            freeze_pk,
+        };
 
         eprintln!("Building transaction parameters");
         let debris = freeze_builder.build()?;

+ 46 - 13
src/contract/dao/tests/integration.rs

@@ -19,13 +19,16 @@
 use darkfi::Result;
 use darkfi_contract_test_harness::{init_logger, Holder, TestHarness};
 use darkfi_dao_contract::model::{Dao, DaoBlindAggregateVote};
-use darkfi_money_contract::model::CoinAttributes;
+use darkfi_money_contract::{
+    model::{CoinAttributes, TokenAttributes},
+    MoneyFunction,
+};
 use darkfi_sdk::{
     crypto::{
         pasta_prelude::*,
-        pedersen_commitment_u64,
+        pedersen_commitment_u64, poseidon_hash,
         util::{fp_mod_fv, fp_to_u64},
-        DAO_CONTRACT_ID, DARK_TOKEN_ID,
+        FuncRef, DAO_CONTRACT_ID, DARK_TOKEN_ID, MONEY_CONTRACT_ID,
     },
     pasta::pallas,
 };
@@ -55,7 +58,22 @@ fn integration_test() -> Result<()> {
         let mut th = TestHarness::new(&["money".to_string(), "dao".to_string()], false).await?;
 
         // We'll use the ALICE token as the DAO governance token
-        let gov_token_id = th.token_id(&Holder::Alice);
+        let wallet = th.holders.get(&Holder::Alice).unwrap();
+        let mint_authority = wallet.token_mint_authority;
+        let token_blind = wallet.token_blind;
+
+        let auth_func_id = FuncRef {
+            contract_id: *MONEY_CONTRACT_ID,
+            func_code: MoneyFunction::AuthTokenMintV1 as u8,
+        }
+        .to_func_id();
+        let token_attrs = TokenAttributes {
+            auth_parent: auth_func_id,
+            user_data: poseidon_hash([mint_authority.public.x(), mint_authority.public.y()]),
+            blind: token_blind,
+        };
+        let gov_token_id = token_attrs.to_token_id();
+
         const ALICE_GOV_SUPPLY: u64 = 100_000_000;
         const BOB_GOV_SUPPLY: u64 = 100_000_000;
         const CHARLIE_GOV_SUPPLY: u64 = 100_000_000;
@@ -124,7 +142,7 @@ fn integration_test() -> Result<()> {
         th.assert_trees(&HOLDERS);
 
         // Gather the DAO owncoin
-        th.gather_owncoin(&Holder::Dao, &airdrop_params.outputs[0], None)?;
+        th.gather_owncoin_from_output(&Holder::Dao, &airdrop_params.outputs[0], None)?;
 
         // ======================================
         // Mint the governance token to 3 holders
@@ -132,7 +150,7 @@ fn integration_test() -> Result<()> {
         info!("Stage 3. Minting governance token");
 
         info!("[Alice] Building governance token mint tx for Alice");
-        let (a_token_mint_tx, a_token_mint_params) =
+        let (a_token_mint_tx, a_token_mint_params, a_auth_token_mint_params) =
             th.token_mint(ALICE_GOV_SUPPLY, &Holder::Alice, &Holder::Alice, None, None)?;
 
         for holder in &HOLDERS {
@@ -149,10 +167,15 @@ fn integration_test() -> Result<()> {
         th.assert_trees(&HOLDERS);
 
         // Gather owncoin
-        th.gather_owncoin(&Holder::Alice, &a_token_mint_params.output, None)?;
+        th.gather_owncoin(
+            &Holder::Alice,
+            &a_token_mint_params.coin,
+            &a_auth_token_mint_params.enc_note,
+            None,
+        )?;
 
         info!("[Alice] Building governance token mint tx for Bob");
-        let (b_token_mint_tx, b_token_mint_params) =
+        let (b_token_mint_tx, b_token_mint_params, b_auth_token_mint_params) =
             th.token_mint(BOB_GOV_SUPPLY, &Holder::Alice, &Holder::Bob, None, None)?;
 
         for holder in &HOLDERS {
@@ -169,10 +192,15 @@ fn integration_test() -> Result<()> {
         th.assert_trees(&HOLDERS);
 
         // Gather owncoin
-        th.gather_owncoin(&Holder::Bob, &b_token_mint_params.output, None)?;
+        th.gather_owncoin(
+            &Holder::Bob,
+            &b_token_mint_params.coin,
+            &b_auth_token_mint_params.enc_note,
+            None,
+        )?;
 
         info!("[Alice] Building governance token mint tx for Charlie");
-        let (c_token_mint_tx, c_token_mint_params) =
+        let (c_token_mint_tx, c_token_mint_params, c_auth_token_mint_params) =
             th.token_mint(CHARLIE_GOV_SUPPLY, &Holder::Alice, &Holder::Charlie, None, None)?;
 
         for holder in &HOLDERS {
@@ -189,7 +217,12 @@ fn integration_test() -> Result<()> {
         th.assert_trees(&HOLDERS);
 
         // Gather owncoin
-        th.gather_owncoin(&Holder::Charlie, &c_token_mint_params.output, None)?;
+        th.gather_owncoin(
+            &Holder::Charlie,
+            &c_token_mint_params.coin,
+            &c_auth_token_mint_params.enc_note,
+            None,
+        )?;
 
         // ================
         // Dao::Propose
@@ -393,8 +426,8 @@ fn integration_test() -> Result<()> {
         th.assert_trees(&HOLDERS);
 
         // Gather the coins
-        th.gather_owncoin(&Holder::Rachel, &xfer_params.outputs[0], None)?;
-        th.gather_owncoin(&Holder::Dao, &xfer_params.outputs[1], None)?;
+        th.gather_owncoin_from_output(&Holder::Rachel, &xfer_params.outputs[0], None)?;
+        th.gather_owncoin_from_output(&Holder::Dao, &xfer_params.outputs[1], None)?;
 
         let rachel_wallet = th.holders.get(&Holder::Rachel).unwrap();
         assert!(rachel_wallet.unspent_money_coins[0].note.value == PROPOSAL_AMOUNT);

+ 1 - 0
src/contract/money/src/client/transfer_v1/builder.rs

@@ -86,6 +86,7 @@ impl TransferCallBuilder {
         let token_blind = pallas::Base::random(&mut OsRng);
         debug!("Building clear inputs");
         for input in self.clear_inputs {
+            signature_secrets.push(input.signature_secret);
             let signature_public = PublicKey::from_secret(input.signature_secret);
             let value_blind = pallas::Scalar::random(&mut OsRng);
 

+ 1 - 1
src/contract/test-harness/src/dao_exec.rs

@@ -217,7 +217,7 @@ impl TestHarness {
         };
         let auth_xfer_sigs = vec![];
         let xfer_sigs = tx.create_sigs(&mut OsRng, &xfer_secrets.signature_secrets)?;
-        let exec_sigs = tx.create_sigs(&mut OsRng, &[exec_signature_secret])?;
+        let exec_sigs = tx.create_sigs(&mut OsRng, &[])?;
         tx.signatures = vec![auth_xfer_sigs, xfer_sigs, exec_sigs];
         tx_action_benchmark.creation_times.push(timer.elapsed());