Просмотр исходного кода

simplify note and make it generic

narodnik 4 лет назад
Родитель
Сommit
1ff5211566

+ 2 - 0
Cargo.lock

@@ -1167,9 +1167,11 @@ dependencies = [
  "async-executor",
  "async-std",
  "async-trait",
+ "crypto_api_chachapoly",
  "darkfi",
  "easy-parallel",
  "futures",
+ "group",
  "halo2_gadgets",
  "halo2_proofs",
  "incrementalmerkletree",

+ 2 - 0
bin/daod/Cargo.toml

@@ -30,6 +30,8 @@ pasta_curves = "0.4.0"
 halo2_gadgets = "0.2.0"
 halo2_proofs = "0.2.0"
 rand = "0.8.5"
+crypto_api_chachapoly = "0.5.0"
+group = "0.12.0"
 
 # Encoding and parsing
 serde_json = "1.0.83"

+ 2 - 2
bin/daod/src/dao_contract/mint/builder.rs

@@ -12,8 +12,8 @@ use pasta_curves::{arithmetic::CurveAffine, group::Curve, pallas};
 use rand::rngs::OsRng;
 
 use crate::{
-    dao_contract::mint::validate::CallData, demo::FuncCall, CallDataBase, ZkContractInfo,
-    ZkContractTable,
+    dao_contract::mint::validate::CallData,
+    demo::{CallDataBase, FuncCall, ZkContractInfo, ZkContractTable},
 };
 
 pub struct Builder {

+ 1 - 2
bin/daod/src/main.rs

@@ -17,8 +17,7 @@ use darkfi::{
 mod dao_contract;
 mod demo;
 mod money_contract;
-pub use demo::{CallDataBase, StateRegistry, Transaction, ZkContractInfo, ZkContractTable};
-
+mod note;
 use crate::demo::demo;
 
 async fn _start() -> Result<()> {

+ 21 - 10
bin/daod/src/money_contract/transfer/builder.rs

@@ -7,7 +7,6 @@ use darkfi::{
         keypair::{PublicKey, SecretKey},
         merkle_node::MerkleNode,
         mint_proof::create_mint_proof,
-        note::Note,
         proof::ProvingKey,
         schnorr::SchnorrSecret,
         types::{
@@ -15,17 +14,27 @@ use darkfi::{
             DrkValueBlind,
         },
     },
-    util::serial::Encodable,
+    util::serial::{Encodable, SerialDecodable, SerialEncodable},
     Result,
 };
 
 use super::partial::{Partial, PartialClearInput, PartialInput};
 use crate::{
-    demo::FuncCall,
+    demo::{FuncCall, ZkContractInfo, ZkContractTable},
     money_contract::transfer::validate::{CallData, ClearInput, Input, Output},
-    ZkContractInfo, ZkContractTable,
+    note,
 };
 
+#[derive(SerialEncodable, SerialDecodable)]
+pub struct Note {
+    pub serial: DrkSerial,
+    pub value: u64,
+    pub token_id: DrkTokenId,
+    pub coin_blind: DrkCoinBlind,
+    pub value_blind: DrkValueBlind,
+    pub token_blind: DrkValueBlind,
+}
+
 pub struct Builder {
     pub clear_inputs: Vec<BuilderClearInputInfo>,
     pub inputs: Vec<BuilderInputInfo>,
@@ -117,17 +126,20 @@ impl Builder {
             let user_data = DrkUserData::from(0);
             let user_data_blind = DrkUserDataBlind::random(&mut OsRng);
 
+            // Note from the previous output
+            let note = input.note;
+
             let (burn_proof, revealed) = create_burn_proof(
                 burn_pk,
-                input.note.value,
-                input.note.token_id,
+                note.value,
+                note.token_id,
                 value_blind,
                 token_blind,
-                input.note.serial,
+                note.serial,
                 spend_hook,
                 user_data,
                 user_data_blind,
-                input.note.coin_blind,
+                note.coin_blind,
                 input.secret,
                 input.leaf_position,
                 input.merkle_path,
@@ -192,10 +204,9 @@ impl Builder {
                 coin_blind,
                 value_blind,
                 token_blind,
-                memo: vec![],
             };
 
-            let encrypted_note = note.encrypt(&output.public)?;
+            let encrypted_note = note::encrypt(&note, &output.public)?;
 
             let output = Output { revealed, enc_note: encrypted_note };
             outputs.push(output);

+ 3 - 3
bin/daod/src/money_contract/transfer/validate.rs

@@ -15,7 +15,6 @@ use darkfi::{
         keypair::PublicKey,
         merkle_node::MerkleNode,
         mint_proof::verify_mint_proof,
-        note::EncryptedNote,
         nullifier::Nullifier,
         proof::VerifyingKey,
         schnorr,
@@ -35,6 +34,7 @@ use crate::{
         state::State,
         transfer::partial::{PartialClearInput, PartialInput},
     },
+    note::EncryptedNote2,
 };
 
 const TARGET: &str = "money_contract::transfer::validate::state_transition()";
@@ -48,7 +48,7 @@ pub struct Update {
     /// All coins in a transaction
     pub coins: Vec<Coin>,
     /// All encrypted notes in a transaction
-    pub enc_notes: Vec<EncryptedNote>,
+    pub enc_notes: Vec<EncryptedNote2>,
 }
 
 pub fn apply(states: &mut StateRegistry, mut update: Update) {
@@ -318,7 +318,7 @@ pub struct Output {
     /// Public inputs for the zero-knowledge proof
     pub revealed: MintRevealedValues,
     /// The encrypted note
-    pub enc_note: EncryptedNote,
+    pub enc_note: EncryptedNote2,
 }
 
 impl ClearInput {