miden_objects/transaction/
tx_witness.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use alloc::vec::Vec;

use vm_core::utils::{ByteReader, Deserializable, Serializable};
use vm_processor::DeserializationError;

use super::{AdviceInputs, TransactionArgs, TransactionInputs};
use crate::accounts::AccountCode;

// TRANSACTION WITNESS
// ================================================================================================

/// Transaction witness contains all the data required to execute and prove a Miden rollup
/// transaction.
///
/// The main purpose of the transaction witness is to enable stateless re-execution and proving
/// of transactions.
///
/// A transaction witness consists of:
/// - Transaction inputs which contain information about the initial state of the account, input
///   notes, block header etc.
/// - Optional transaction arguments which may contain a transaction script, note arguments, and any
///   additional advice data to initialize the advice provide with prior to transaction execution.
/// - Advice witness which contains all data requested by the VM from the advice provider while
///   executing the transaction program.
///
/// TODO: currently, the advice witness contains redundant and irrelevant data (e.g., tx inputs
/// and tx outputs; account codes and a subset of that data in advice inputs).
/// We should optimize it to contain only the minimum data required for executing/proving the
/// transaction.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct TransactionWitness {
    pub tx_inputs: TransactionInputs,
    pub tx_args: TransactionArgs,
    pub advice_witness: AdviceInputs,
    pub account_codes: Vec<AccountCode>,
}

// SERIALIZATION
// ================================================================================================

impl Serializable for TransactionWitness {
    fn write_into<W: miden_crypto::utils::ByteWriter>(&self, target: &mut W) {
        self.tx_inputs.write_into(target);
        self.tx_args.write_into(target);
        self.advice_witness.write_into(target);
        self.account_codes.write_into(target);
    }
}

impl Deserializable for TransactionWitness {
    fn read_from<R: ByteReader>(source: &mut R) -> Result<Self, DeserializationError> {
        let tx_inputs = TransactionInputs::read_from(source)?;
        let tx_args = TransactionArgs::read_from(source)?;
        let advice_witness = AdviceInputs::read_from(source)?;
        let account_codes = <Vec<AccountCode>>::read_from(source)?;
        Ok(Self {
            tx_inputs,
            tx_args,
            advice_witness,
            account_codes,
        })
    }
}