miden_objects/transaction/tx_witness.rs
1use super::{AdviceInputs, TransactionArgs, TransactionInputs};
2use crate::utils::serde::{ByteReader, Deserializable, DeserializationError, Serializable};
3
4// TRANSACTION WITNESS
5// ================================================================================================
6
7/// Transaction witness contains all the data required to execute and prove a Miden blockchain
8/// transaction.
9///
10/// The main purpose of the transaction witness is to enable stateless re-execution and proving
11/// of transactions.
12///
13/// A transaction witness consists of:
14/// - Transaction inputs which contain information about the initial state of the account, input
15/// notes, block header etc.
16/// - Optional transaction arguments which may contain a transaction script, note arguments,
17/// transaction script arguments and any additional advice data to initialize the advice provider
18/// with prior to transaction execution.
19/// - Advice witness which contains all data requested by the VM from the advice provider while
20/// executing the transaction program.
21///
22/// TODO: currently, the advice witness contains redundant and irrelevant data (e.g., tx inputs
23/// and tx outputs; account codes and a subset of that data in advice inputs).
24/// We should optimize it to contain only the minimum data required for executing/proving the
25/// transaction.
26#[derive(Clone, Debug, PartialEq, Eq)]
27pub struct TransactionWitness {
28 pub tx_inputs: TransactionInputs,
29 pub tx_args: TransactionArgs,
30 pub advice_witness: AdviceInputs,
31}
32
33// SERIALIZATION
34// ================================================================================================
35
36impl Serializable for TransactionWitness {
37 fn write_into<W: miden_crypto::utils::ByteWriter>(&self, target: &mut W) {
38 self.tx_inputs.write_into(target);
39 self.tx_args.write_into(target);
40 self.advice_witness.write_into(target);
41 }
42}
43
44impl Deserializable for TransactionWitness {
45 fn read_from<R: ByteReader>(source: &mut R) -> Result<Self, DeserializationError> {
46 let tx_inputs = TransactionInputs::read_from(source)?;
47 let tx_args = TransactionArgs::read_from(source)?;
48 let advice_witness = AdviceInputs::read_from(source)?;
49 Ok(Self { tx_inputs, tx_args, advice_witness })
50 }
51}