소스 검색

Remove old obsolete tx module and replace with tx2.

parazyd 3 년 전
부모
커밋
4886b0ec0b
13개의 변경된 파일52개의 추가작업 그리고 602개의 파일을 삭제
  1. 7 0
      Cargo.lock
  2. 1 1
      bin/darkfid/src/internal.rs
  3. 1 1
      bin/darkfid/src/rpc_tx.rs
  4. 1 1
      src/blockchain/txstore.rs
  5. 1 1
      src/consensus/block.rs
  6. 1 1
      src/consensus/proto/protocol_tx.rs
  7. 1 1
      src/consensus/state.rs
  8. 1 1
      src/lib.rs
  9. 0 218
      src/tx/builder.rs
  10. 0 30
      src/tx/contract.rs
  11. 38 225
      src/tx/mod.rs
  12. 0 45
      src/tx/partial.rs
  13. 0 77
      src/tx2/mod.rs

+ 7 - 0
Cargo.lock

@@ -1338,9 +1338,14 @@ dependencies = [
 name = "darkfi-money-contract"
 version = "0.3.0"
 dependencies = [
+ "chacha20poly1305",
+ "darkfi",
  "darkfi-sdk",
  "darkfi-serial",
  "getrandom 0.2.8",
+ "halo2_proofs",
+ "log",
+ "rand",
 ]
 
 [[package]]
@@ -1941,6 +1946,7 @@ dependencies = [
  "easy-parallel",
  "hex",
  "lazy-init",
+ "libsqlite3-sys",
  "log",
  "rand",
  "serde",
@@ -1948,6 +1954,7 @@ dependencies = [
  "simplelog",
  "sled",
  "smol",
+ "sqlx",
  "structopt",
  "structopt-toml",
  "url",

+ 1 - 1
bin/darkfid/src/internal.rs

@@ -16,7 +16,7 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-use darkfi::{tx2::Transaction, Result};
+use darkfi::{tx::Transaction, Result};
 
 use super::Darkfid;
 

+ 1 - 1
bin/darkfid/src/rpc_tx.rs

@@ -25,7 +25,7 @@ use serde_json::{json, Value};
 
 use darkfi::{
     rpc::jsonrpc::{ErrorCode::InvalidParams, JsonError, JsonResponse, JsonResult},
-    tx2::Transaction,
+    tx::Transaction,
 };
 
 use super::Darkfid;

+ 1 - 1
src/blockchain/txstore.rs

@@ -18,7 +18,7 @@
 
 use darkfi_serial::{deserialize, serialize};
 
-use crate::{tx2::Transaction, Error, Result};
+use crate::{tx::Transaction, Error, Result};
 
 const SLED_TX_TREE: &[u8] = b"_transactions";
 

+ 1 - 1
src/consensus/block.rs

@@ -28,7 +28,7 @@ use super::{
     constants::{BLOCK_MAGIC_BYTES, BLOCK_VERSION},
     Metadata,
 };
-use crate::{net, tx2::Transaction, util::time::Timestamp};
+use crate::{net, tx::Transaction, util::time::Timestamp};
 
 /// This struct represents a tuple of the form (version, previous, epoch, slot, timestamp, merkle_root).
 #[derive(Debug, Clone, PartialEq, Eq, SerialEncodable, SerialDecodable)]

+ 1 - 1
src/consensus/proto/protocol_tx.rs

@@ -29,7 +29,7 @@ use crate::{
         ChannelPtr, MessageSubscription, P2pPtr, ProtocolBase, ProtocolBasePtr,
         ProtocolJobsManager, ProtocolJobsManagerPtr,
     },
-    tx2::Transaction,
+    tx::Transaction,
     Result,
 };
 

+ 1 - 1
src/consensus/state.rs

@@ -50,7 +50,7 @@ use crate::{
     crypto::proof::{ProvingKey, VerifyingKey},
     net,
     runtime::vm_runtime::Runtime,
-    tx2::Transaction,
+    tx::Transaction,
     util::time::Timestamp,
     wallet::WalletPtr,
     zk::circuit::LeadContract,

+ 1 - 1
src/lib.rs

@@ -49,7 +49,7 @@ pub mod rpc;
 pub mod system;
 
 #[cfg(feature = "tx")]
-pub mod tx2;
+pub mod tx;
 
 #[cfg(feature = "util")]
 pub mod util;

+ 0 - 218
src/tx/builder.rs

@@ -1,218 +0,0 @@
-/* This file is part of DarkFi (https://dark.fi)
- *
- * Copyright (C) 2020-2022 Dyne.org foundation
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <https://www.gnu.org/licenses/>.
- */
-
-use darkfi_sdk::crypto::{schnorr::SchnorrSecret, MerkleNode, PublicKey, SecretKey, TokenId};
-use darkfi_serial::serialize;
-use pasta_curves::group::ff::Field;
-use rand::rngs::OsRng;
-
-use super::{
-    partial::{PartialTransaction, PartialTransactionClearInput, PartialTransactionInput},
-    Transaction, TransactionClearInput, TransactionInput, TransactionOutput,
-};
-use crate::{
-    crypto::{
-        burn_proof::create_burn_proof,
-        mint_proof::create_mint_proof,
-        note::Note,
-        proof::ProvingKey,
-        types::{
-            DrkCoinBlind, DrkSerial, DrkSpendHook, DrkUserData, DrkUserDataBlind, DrkValueBlind,
-        },
-    },
-    Result,
-};
-
-pub struct TransactionBuilder {
-    pub clear_inputs: Vec<TransactionBuilderClearInputInfo>,
-    pub inputs: Vec<TransactionBuilderInputInfo>,
-    pub outputs: Vec<TransactionBuilderOutputInfo>,
-}
-
-pub struct TransactionBuilderClearInputInfo {
-    pub value: u64,
-    pub token_id: TokenId,
-    pub signature_secret: SecretKey,
-}
-
-pub struct TransactionBuilderInputInfo {
-    pub leaf_position: incrementalmerkletree::Position,
-    pub merkle_path: Vec<MerkleNode>,
-    pub secret: SecretKey,
-    pub note: Note,
-}
-
-pub struct TransactionBuilderOutputInfo {
-    pub value: u64,
-    pub token_id: TokenId,
-    pub public: PublicKey,
-}
-
-impl TransactionBuilder {
-    fn compute_remainder_blind(
-        clear_inputs: &[PartialTransactionClearInput],
-        input_blinds: &[DrkValueBlind],
-        output_blinds: &[DrkValueBlind],
-    ) -> DrkValueBlind {
-        let mut total = DrkValueBlind::zero();
-
-        for input in clear_inputs {
-            total += input.value_blind;
-        }
-
-        for input_blind in input_blinds {
-            total += input_blind;
-        }
-
-        for output_blind in output_blinds {
-            total -= output_blind;
-        }
-
-        total
-    }
-
-    pub fn build(self, mint_pk: &ProvingKey, burn_pk: &ProvingKey) -> Result<Transaction> {
-        assert!(self.clear_inputs.len() + self.inputs.len() > 0);
-
-        let mut clear_inputs = vec![];
-        let token_blind = DrkValueBlind::random(&mut OsRng);
-        for input in &self.clear_inputs {
-            let signature_public = PublicKey::from_secret(input.signature_secret);
-            let value_blind = DrkValueBlind::random(&mut OsRng);
-
-            let clear_input = PartialTransactionClearInput {
-                value: input.value,
-                token_id: input.token_id,
-                value_blind,
-                token_blind,
-                signature_public,
-            };
-            clear_inputs.push(clear_input);
-        }
-
-        let mut inputs = vec![];
-        let mut input_blinds = vec![];
-        let mut signature_secrets = vec![];
-        for input in self.inputs {
-            let value_blind = DrkValueBlind::random(&mut OsRng);
-            input_blinds.push(value_blind);
-
-            let signature_secret = SecretKey::random(&mut OsRng);
-
-            // Disable composability for this old obselete API
-            let spend_hook = DrkSpendHook::from(0);
-            let user_data = DrkUserData::from(0);
-            let user_data_blind = DrkUserDataBlind::random(&mut OsRng);
-
-            let (proof, revealed) = create_burn_proof(
-                burn_pk,
-                input.note.value,
-                input.note.token_id,
-                value_blind,
-                token_blind,
-                input.note.serial,
-                spend_hook,
-                user_data,
-                user_data_blind,
-                input.note.coin_blind,
-                input.secret,
-                input.leaf_position,
-                input.merkle_path,
-                signature_secret,
-            )?;
-
-            // First we make the tx then sign after
-            signature_secrets.push(signature_secret);
-
-            let input = PartialTransactionInput { burn_proof: proof, revealed };
-            inputs.push(input);
-        }
-
-        let mut outputs = vec![];
-        let mut output_blinds = vec![];
-        // This value_blind calc assumes there will always be at least a single output
-        assert!(!self.outputs.is_empty());
-
-        for (i, output) in self.outputs.iter().enumerate() {
-            let value_blind = if i == self.outputs.len() - 1 {
-                Self::compute_remainder_blind(&clear_inputs, &input_blinds, &output_blinds)
-            } else {
-                DrkValueBlind::random(&mut OsRng)
-            };
-            output_blinds.push(value_blind);
-
-            let serial = DrkSerial::random(&mut OsRng);
-            let coin_blind = DrkCoinBlind::random(&mut OsRng);
-
-            // Disable composability for this old obselete API
-            let spend_hook = DrkSpendHook::from(0);
-            let user_data = DrkUserData::from(0);
-
-            let (mint_proof, revealed) = create_mint_proof(
-                mint_pk,
-                output.value,
-                output.token_id,
-                value_blind,
-                token_blind,
-                serial,
-                spend_hook,
-                user_data,
-                coin_blind,
-                output.public,
-            )?;
-
-            // Encrypted note
-            let note = Note {
-                serial,
-                value: output.value,
-                token_id: output.token_id,
-                coin_blind,
-                value_blind,
-                token_blind,
-                memo: vec![],
-            };
-
-            let encrypted_note = note.encrypt(&output.public)?;
-
-            let output = TransactionOutput { mint_proof, revealed, enc_note: encrypted_note };
-            outputs.push(output);
-        }
-
-        let partial_tx = PartialTransaction { clear_inputs, inputs, outputs };
-        let unsigned_tx_data = serialize(&partial_tx);
-
-        let mut clear_inputs = vec![];
-        for (input, info) in partial_tx.clear_inputs.into_iter().zip(self.clear_inputs) {
-            let secret = info.signature_secret;
-            let signature = secret.sign(&mut OsRng, &unsigned_tx_data);
-            let input = TransactionClearInput::from_partial(input, signature);
-            clear_inputs.push(input);
-        }
-
-        let mut inputs = vec![];
-        for (input, signature_secret) in
-            partial_tx.inputs.into_iter().zip(signature_secrets.into_iter())
-        {
-            let signature = signature_secret.sign(&mut OsRng, &unsigned_tx_data);
-            let input = TransactionInput::from_partial(input, signature);
-            inputs.push(input);
-        }
-
-        Ok(Transaction { clear_inputs, inputs, outputs: partial_tx.outputs })
-    }
-}

+ 0 - 30
src/tx/contract.rs

@@ -1,30 +0,0 @@
-/* This file is part of DarkFi (https://dark.fi)
- *
- * Copyright (C) 2020-2022 Dyne.org foundation
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <https://www.gnu.org/licenses/>.
- */
-
-pub struct ContractDeploy {
-    /// Public address of the contract, derived from the deploy key.
-    pub address: pallas::Base,
-    /// Public key of the contract, derived from the deploy key.
-    /// Used for signatures and authorizations, as well as deriving the
-    /// contract's address.
-    pub public: PublicKey,
-    /// Compiled smart contract wasm binary to be executed in the wasm vm runtime.
-    pub wasm_binary: Vec<u8>,
-    /// Compiled zkas circuits used by the smart contract provers and verifiers.
-    pub circuits: Vec<Vec<u8>>, // XXX: TODO: FIXME: The namespace of the zkas circuit should be in the bin
-}

+ 38 - 225
src/tx/mod.rs

@@ -16,249 +16,62 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-use std::io;
-
-use darkfi_sdk::crypto::{
-    pedersen::{pedersen_commitment_base, pedersen_commitment_u64},
-    schnorr,
-    schnorr::SchnorrPublic,
-    PublicKey, TokenId,
-};
-use darkfi_serial::{Encodable, SerialDecodable, SerialEncodable, VarInt};
-use log::error;
-use pasta_curves::group::Group;
-
-use crate::{
+use darkfi_sdk::{
     crypto::{
-        burn_proof::verify_burn_proof,
-        mint_proof::verify_mint_proof,
-        note::EncryptedNote,
-        proof::VerifyingKey,
-        types::{DrkValueBlind, DrkValueCommit},
-        BurnRevealedValues, MintRevealedValues, Proof,
+        schnorr::{SchnorrPublic, Signature},
+        PublicKey,
     },
-    Result, VerifyFailed, VerifyResult,
+    pasta::pallas,
+    tx::ContractCall,
 };
+use darkfi_serial::{Encodable, SerialDecodable, SerialEncodable};
+use log::{debug, error};
 
-pub mod builder;
-pub mod partial;
+use crate::{crypto::Proof, Error, Result};
 
-/// A DarkFi transaction
-#[derive(Debug, Clone, PartialEq, Eq, SerialEncodable, SerialDecodable)]
+/// A Transaction contains an arbitrary number of `ContractCall` objects,
+/// along with corresponding ZK proofs and Schnorr signatures.
+#[derive(Debug, Clone, Eq, PartialEq, SerialEncodable, SerialDecodable)]
 pub struct Transaction {
-    /// Clear inputs
-    pub clear_inputs: Vec<TransactionClearInput>,
-    /// Anonymous inputs
-    pub inputs: Vec<TransactionInput>,
-    /// Anonymous outputs
-    pub outputs: Vec<TransactionOutput>,
-}
-
-/// A transaction's clear input
-#[derive(Debug, Clone, PartialEq, Eq, SerialEncodable, SerialDecodable)]
-pub struct TransactionClearInput {
-    /// Input's value (amount)
-    pub value: u64,
-    /// Input's token ID
-    pub token_id: TokenId,
-    /// Blinding factor for `value`
-    pub value_blind: DrkValueBlind,
-    /// Blinding factor for `token_id`
-    pub token_blind: DrkValueBlind,
-    /// Public key for the signature
-    pub signature_public: PublicKey,
-    /// Transaction signature
-    pub signature: schnorr::Signature,
-}
-
-/// A transaction's anonymous input
-#[derive(Debug, Clone, PartialEq, Eq, SerialEncodable, SerialDecodable)]
-pub struct TransactionInput {
-    /// Zero-knowledge proof for the input
-    pub burn_proof: Proof,
-    /// Public inputs for the zero-knowledge proof
-    pub revealed: BurnRevealedValues,
-    /// Input's signature
-    pub signature: schnorr::Signature,
-}
-
-/// A transaction's anonymous output
-#[derive(Debug, Clone, PartialEq, Eq, SerialEncodable, SerialDecodable)]
-pub struct TransactionOutput {
-    /// Zero-knowledge proof for the output
-    pub mint_proof: Proof,
-    /// Public inputs for the zero-knowledge proof
-    pub revealed: MintRevealedValues,
-    /// The encrypted note
-    pub enc_note: EncryptedNote,
+    /// Calls executed in this transaction
+    pub calls: Vec<ContractCall>,
+    /// Attached ZK proofs
+    pub proofs: Vec<Vec<Proof>>,
+    /// Attached Schnorr signatures
+    pub signatures: Vec<Vec<Signature>>,
 }
 
 impl Transaction {
-    /// Verify the transaction
-    pub fn verify(&self, mint_vk: &VerifyingKey, burn_vk: &VerifyingKey) -> VerifyResult<()> {
-        // Transaction 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");
-            return Err(VerifyFailed::LackingInputs)
-        }
-        if self.outputs.is_empty() {
-            error!("tx::verify(): Missing outputs");
-            return Err(VerifyFailed::LackingOutputs)
-        }
-
-        // Accumulator for the value commitments
-        let mut valcom_total = DrkValueCommit::identity();
+    /// Verify ZK proofs for the entire transaction.
+    pub fn verify_zkps(&self, zkp_table: Vec<Vec<(String, Vec<pallas::Base>)>>) -> Result<()> {
+        Ok(())
+    }
 
-        // Add values from the clear inputs
-        for input in &self.clear_inputs {
-            valcom_total += pedersen_commitment_u64(input.value, input.value_blind);
-        }
+    /// Verify Schnorr signatures for the entire transaction.
+    pub fn verify_sigs(&self, pub_table: Vec<Vec<PublicKey>>) -> Result<()> {
+        let tx_data = self.encode_without_sigs()?;
+        let data_hash = blake3::hash(&tx_data);
 
-        // Add values from the inputs
-        for (i, input) in self.inputs.iter().enumerate() {
-            match verify_burn_proof(burn_vk, &input.burn_proof, &input.revealed) {
-                Ok(()) => valcom_total += &input.revealed.value_commit,
-                Err(e) => {
-                    error!("tx::verify(): Failed to verify burn proof {}: {}", i, e);
-                    return Err(VerifyFailed::BurnProof(i))
-                }
-            }
-        }
+        assert!(pub_table.len() == self.signatures.len());
 
-        // Subtract values from the outputs
-        for (i, output) in self.outputs.iter().enumerate() {
-            match verify_mint_proof(mint_vk, &output.mint_proof, &output.revealed) {
-                Ok(()) => valcom_total -= &output.revealed.value_commit,
-                Err(e) => {
-                    error!("tx::verify(): Failed to verify mint proof {}: {}", i, e);
-                    return Err(VerifyFailed::MintProof(i))
+        for (i, (sigs, pubkeys)) in self.signatures.iter().zip(pub_table.iter()).enumerate() {
+            for (pubkey, signature) in pubkeys.iter().zip(sigs) {
+                if !pubkey.verify(&data_hash.as_bytes()[..], &signature) {
+                    error!("tx::verify_sigs[{}] failed to verify", i);
+                    return Err(Error::InvalidSignature)
                 }
             }
-        }
-
-        // If the accumulator is not back in its initial state,
-        // there's a value mismatch.
-        if valcom_total != DrkValueCommit::identity() {
-            error!("tx::verify(): Missing funds");
-            return Err(VerifyFailed::MissingFunds)
-        }
-
-        // Verify that the token commitments match
-        if !self.verify_token_commitments() {
-            error!("tx::verify(): Token ID mismatch");
-            return Err(VerifyFailed::TokenMismatch)
-        }
-
-        // Verify the available signatures
-        let mut unsigned_tx_data = vec![];
-        self.encode_without_signature(&mut unsigned_tx_data)?;
-
-        for (i, input) in self.clear_inputs.iter().enumerate() {
-            let public = &input.signature_public;
-            if !public.verify(&unsigned_tx_data[..], &input.signature) {
-                error!("tx::verify(): Failed to verify Clear Input signature {}", i);
-                return Err(VerifyFailed::ClearInputSignature(i))
-            }
-        }
-
-        for (i, input) in self.inputs.iter().enumerate() {
-            let public = &input.revealed.signature_public;
-            if !public.verify(&unsigned_tx_data[..], &input.signature) {
-                error!("tx::verify(): Failed to verify Input signature {}", i);
-                return Err(VerifyFailed::InputSignature(i))
-            }
+            debug!("tx::verify_sigs[{}] passed", i);
         }
 
         Ok(())
     }
 
-    pub fn encode_without_signature<S: io::Write>(&self, mut s: S) -> Result<usize> {
-        let mut len = 0;
-        len += self.clear_inputs.encode_without_signature(&mut s)?;
-        len += self.inputs.encode_without_signature(&mut s)?;
-        len += self.outputs.encode(s)?;
-        Ok(len)
-    }
-
-    fn verify_token_commitments(&self) -> bool {
-        assert_ne!(self.outputs.len(), 0);
-        let token_commit_value = self.outputs[0].revealed.token_commit;
-
-        let mut failed =
-            self.inputs.iter().any(|input| input.revealed.token_commit != token_commit_value);
-
-        failed = failed ||
-            self.outputs.iter().any(|output| output.revealed.token_commit != token_commit_value);
-
-        failed = failed ||
-            self.clear_inputs.iter().any(|input| {
-                pedersen_commitment_base(input.token_id.inner(), input.token_blind) !=
-                    token_commit_value
-            });
-        !failed
-    }
-}
-
-impl TransactionClearInput {
-    fn from_partial(
-        partial: partial::PartialTransactionClearInput,
-        signature: schnorr::Signature,
-    ) -> Self {
-        Self {
-            value: partial.value,
-            token_id: partial.token_id,
-            value_blind: partial.value_blind,
-            token_blind: partial.token_blind,
-            signature_public: partial.signature_public,
-            signature,
-        }
-    }
-
-    fn encode_without_signature<S: io::Write>(&self, mut s: S) -> Result<usize> {
-        let mut len = 0;
-        len += self.value.encode(&mut s)?;
-        len += self.token_id.encode(&mut s)?;
-        len += self.value_blind.encode(&mut s)?;
-        len += self.token_blind.encode(&mut s)?;
-        len += self.signature_public.encode(s)?;
-        Ok(len)
-    }
-}
-
-impl TransactionInput {
-    pub fn from_partial(
-        partial: partial::PartialTransactionInput,
-        signature: schnorr::Signature,
-    ) -> Self {
-        Self { burn_proof: partial.burn_proof, revealed: partial.revealed, signature }
+    /// Encode the object into a byte vector for signing
+    pub fn encode_without_sigs(&self) -> Result<Vec<u8>> {
+        let mut buf = vec![];
+        self.calls.encode(&mut buf)?;
+        self.proofs.encode(&mut buf)?;
+        Ok(buf)
     }
-
-    fn encode_without_signature<S: io::Write>(&self, mut s: S) -> Result<usize> {
-        let mut len = 0;
-        len += self.burn_proof.encode(&mut s)?;
-        len += self.revealed.encode(&mut s)?;
-        Ok(len)
-    }
-}
-
-trait EncodableWithoutSignature {
-    fn encode_without_signature<S: io::Write>(&self, s: S) -> Result<usize>;
-}
-
-macro_rules! impl_vec_without_signature {
-    ($type: ty) => {
-        impl EncodableWithoutSignature for Vec<$type> {
-            #[inline]
-            fn encode_without_signature<S: io::Write>(&self, mut s: S) -> Result<usize> {
-                let mut len = 0;
-                len += VarInt(self.len() as u64).encode(&mut s)?;
-                for c in self.iter() {
-                    len += c.encode_without_signature(&mut s)?;
-                }
-                Ok(len)
-            }
-        }
-    };
 }
-impl_vec_without_signature!(TransactionClearInput);
-impl_vec_without_signature!(TransactionInput);

+ 0 - 45
src/tx/partial.rs

@@ -1,45 +0,0 @@
-/* This file is part of DarkFi (https://dark.fi)
- *
- * Copyright (C) 2020-2022 Dyne.org foundation
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <https://www.gnu.org/licenses/>.
- */
-
-use darkfi_sdk::crypto::{PublicKey, TokenId};
-use darkfi_serial::{SerialDecodable, SerialEncodable};
-
-use super::TransactionOutput;
-use crate::crypto::{types::DrkValueBlind, BurnRevealedValues, Proof};
-
-#[derive(Clone, SerialEncodable, SerialDecodable)]
-pub struct PartialTransaction {
-    pub clear_inputs: Vec<PartialTransactionClearInput>,
-    pub inputs: Vec<PartialTransactionInput>,
-    pub outputs: Vec<TransactionOutput>,
-}
-
-#[derive(Clone, SerialEncodable, SerialDecodable)]
-pub struct PartialTransactionClearInput {
-    pub value: u64,
-    pub token_id: TokenId,
-    pub value_blind: DrkValueBlind,
-    pub token_blind: DrkValueBlind,
-    pub signature_public: PublicKey,
-}
-
-#[derive(Clone, SerialEncodable, SerialDecodable)]
-pub struct PartialTransactionInput {
-    pub burn_proof: Proof,
-    pub revealed: BurnRevealedValues,
-}

+ 0 - 77
src/tx2/mod.rs

@@ -1,77 +0,0 @@
-/* This file is part of DarkFi (https://dark.fi)
- *
- * Copyright (C) 2020-2022 Dyne.org foundation
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <https://www.gnu.org/licenses/>.
- */
-
-use darkfi_sdk::{
-    crypto::{
-        schnorr::{SchnorrPublic, Signature},
-        PublicKey,
-    },
-    pasta::pallas,
-    tx::ContractCall,
-};
-use darkfi_serial::{Encodable, SerialDecodable, SerialEncodable};
-use log::{debug, error};
-
-use crate::{crypto::Proof, Error, Result};
-
-/// A Transaction contains an arbitrary number of `ContractCall` objects,
-/// along with corresponding ZK proofs and Schnorr signatures.
-#[derive(Debug, Clone, Eq, PartialEq, SerialEncodable, SerialDecodable)]
-pub struct Transaction {
-    /// Calls executed in this transaction
-    pub calls: Vec<ContractCall>,
-    /// Attached ZK proofs
-    pub proofs: Vec<Vec<Proof>>,
-    /// Attached Schnorr signatures
-    pub signatures: Vec<Vec<Signature>>,
-}
-
-impl Transaction {
-    /// Verify ZK proofs for the entire transaction.
-    pub fn verify_zkps(&self, zkp_table: Vec<Vec<(String, Vec<pallas::Base>)>>) -> Result<()> {
-        Ok(())
-    }
-
-    /// Verify Schnorr signatures for the entire transaction.
-    pub fn verify_sigs(&self, pub_table: Vec<Vec<PublicKey>>) -> Result<()> {
-        let tx_data = self.encode_without_sigs()?;
-        let data_hash = blake3::hash(&tx_data);
-
-        assert!(pub_table.len() == self.signatures.len());
-
-        for (i, (sigs, pubkeys)) in self.signatures.iter().zip(pub_table.iter()).enumerate() {
-            for (pubkey, signature) in pubkeys.iter().zip(sigs) {
-                if !pubkey.verify(&data_hash.as_bytes()[..], &signature) {
-                    error!("tx::verify_sigs[{}] failed to verify", i);
-                    return Err(Error::InvalidSignature)
-                }
-            }
-            debug!("tx::verify_sigs[{}] passed", i);
-        }
-
-        Ok(())
-    }
-
-    /// Encode the object into a byte vector for signing
-    pub fn encode_without_sigs(&self) -> Result<Vec<u8>> {
-        let mut buf = vec![];
-        self.calls.encode(&mut buf)?;
-        self.proofs.encode(&mut buf)?;
-        Ok(buf)
-    }
-}