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