diff --git a/Cargo.lock b/Cargo.lock index 04bf7ecba..ff0ad58a6 100644 --- a/Cargo.lock +++ b/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", diff --git a/bin/daod/Cargo.toml b/bin/daod/Cargo.toml index b87d59208..b689e312e 100644 --- a/bin/daod/Cargo.toml +++ b/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" diff --git a/bin/daod/src/dao_contract/mint/builder.rs b/bin/daod/src/dao_contract/mint/builder.rs index 2ad7e2212..894f2b866 100644 --- a/bin/daod/src/dao_contract/mint/builder.rs +++ b/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 { diff --git a/bin/daod/src/main.rs b/bin/daod/src/main.rs index 02cd698db..2249b83d2 100644 --- a/bin/daod/src/main.rs +++ b/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<()> { diff --git a/bin/daod/src/money_contract/transfer/builder.rs b/bin/daod/src/money_contract/transfer/builder.rs index 9aa979206..25bb2eced 100644 --- a/bin/daod/src/money_contract/transfer/builder.rs +++ b/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, pub inputs: Vec, @@ -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(¬e, &output.public)?; let output = Output { revealed, enc_note: encrypted_note }; outputs.push(output); diff --git a/bin/daod/src/money_contract/transfer/validate.rs b/bin/daod/src/money_contract/transfer/validate.rs index 99e5c5f7f..2c98832fb 100644 --- a/bin/daod/src/money_contract/transfer/validate.rs +++ b/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, /// All encrypted notes in a transaction - pub enc_notes: Vec, + pub enc_notes: Vec, } 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 {