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 rollup
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, and any
17///   additional advice data to initialize the advice provide with prior to transaction execution.
18/// - Advice witness which contains all data requested by the VM from the advice provider while
19///   executing the transaction program.
20///
21/// TODO: currently, the advice witness contains redundant and irrelevant data (e.g., tx inputs
22/// and tx outputs; account codes and a subset of that data in advice inputs).
23/// We should optimize it to contain only the minimum data required for executing/proving the
24/// transaction.
25#[derive(Clone, Debug, PartialEq, Eq)]
26pub struct TransactionWitness {
27    pub tx_inputs: TransactionInputs,
28    pub tx_args: TransactionArgs,
29    pub advice_witness: AdviceInputs,
30}
31
32// SERIALIZATION
33// ================================================================================================
34
35impl Serializable for TransactionWitness {
36    fn write_into<W: miden_crypto::utils::ByteWriter>(&self, target: &mut W) {
37        self.tx_inputs.write_into(target);
38        self.tx_args.write_into(target);
39        self.advice_witness.write_into(target);
40    }
41}
42
43impl Deserializable for TransactionWitness {
44    fn read_from<R: ByteReader>(source: &mut R) -> Result<Self, DeserializationError> {
45        let tx_inputs = TransactionInputs::read_from(source)?;
46        let tx_args = TransactionArgs::read_from(source)?;
47        let advice_witness = AdviceInputs::read_from(source)?;
48        Ok(Self { tx_inputs, tx_args, advice_witness })
49    }
50}