Skip to content

Commit

Permalink
Merge branch 'main' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbinth authored Jan 28, 2025
2 parents 9930c36 + 1eccdab commit fdfbd3c
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
- [BREAKING] Incremented minimum supported Rust version to 1.84.
- [BREAKING] Moved `generated` module from `miden-proving-service-client` crate to `tx_prover::generated` hierarchy (#1102).

## 0.7.2 (2025-01-28) - `miden-objects` crate only

### Changes

- Added serialization for `ExecutedTransaction` (#1113).

## 0.7.1 (2025-01-24) - `miden-objects` crate only

### Fixes
Expand Down
69 changes: 67 additions & 2 deletions crates/miden-objects/src/transaction/executed_tx.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use alloc::vec::Vec;
use core::cell::OnceCell;

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

use super::{
Account, AccountDelta, AccountHeader, AccountId, AdviceInputs, BlockHeader, InputNote,
InputNotes, NoteId, OutputNotes, TransactionArgs, TransactionId, TransactionInputs,
Expand All @@ -21,7 +24,7 @@ use crate::account::AccountCode;
/// stateless manner. This includes all public transaction inputs, but also all nondeterministic
/// inputs that the host provided to Miden VM while executing the transaction (i.e., advice
/// witness).
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct ExecutedTransaction {
id: OnceCell<TransactionId>,
tx_inputs: TransactionInputs,
Expand Down Expand Up @@ -161,12 +164,46 @@ impl From<ExecutedTransaction> for TransactionMeasurements {
}
}

impl Serializable for ExecutedTransaction {
fn write_into<W: ByteWriter>(&self, target: &mut W) {
self.tx_inputs.write_into(target);
self.tx_outputs.write_into(target);
self.account_codes.write_into(target);
self.account_delta.write_into(target);
self.tx_args.write_into(target);
self.advice_witness.write_into(target);
self.tx_measurements.write_into(target);
}
}

impl Deserializable for ExecutedTransaction {
fn read_from<R: ByteReader>(source: &mut R) -> Result<Self, DeserializationError> {
let tx_inputs = TransactionInputs::read_from(source)?;
let tx_outputs = TransactionOutputs::read_from(source)?;
let account_codes = Vec::<AccountCode>::read_from(source)?;
let account_delta = AccountDelta::read_from(source)?;
let tx_args = TransactionArgs::read_from(source)?;
let advice_witness = AdviceInputs::read_from(source)?;
let tx_measurements = TransactionMeasurements::read_from(source)?;

Ok(Self::new(
tx_inputs,
tx_outputs,
account_codes,
account_delta,
tx_args,
advice_witness,
tx_measurements,
))
}
}

// TRANSACTION MEASUREMENTS
// ================================================================================================

/// Stores the resulting number of cycles for each transaction execution stage obtained from the
/// `TransactionProgress` struct.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct TransactionMeasurements {
pub prologue: usize,
pub notes_processing: usize,
Expand All @@ -188,3 +225,31 @@ impl TransactionMeasurements {
total_cycles.next_power_of_two()
}
}

impl Serializable for TransactionMeasurements {
fn write_into<W: ByteWriter>(&self, target: &mut W) {
self.prologue.write_into(target);
self.notes_processing.write_into(target);
self.note_execution.write_into(target);
self.tx_script_processing.write_into(target);
self.epilogue.write_into(target);
}
}

impl Deserializable for TransactionMeasurements {
fn read_from<R: ByteReader>(source: &mut R) -> Result<Self, DeserializationError> {
let prologue = usize::read_from(source)?;
let notes_processing = usize::read_from(source)?;
let note_execution = Vec::<(NoteId, usize)>::read_from(source)?;
let tx_script_processing = usize::read_from(source)?;
let epilogue = usize::read_from(source)?;

Ok(Self {
prologue,
notes_processing,
note_execution,
tx_script_processing,
epilogue,
})
}
}
22 changes: 22 additions & 0 deletions crates/miden-objects/src/transaction/outputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,28 @@ pub struct TransactionOutputs {
pub expiration_block_num: BlockNumber,
}

impl Serializable for TransactionOutputs {
fn write_into<W: ByteWriter>(&self, target: &mut W) {
self.account.write_into(target);
self.output_notes.write_into(target);
self.expiration_block_num.write_into(target);
}
}

impl Deserializable for TransactionOutputs {
fn read_from<R: ByteReader>(source: &mut R) -> Result<Self, DeserializationError> {
let account = AccountHeader::read_from(source)?;
let output_notes = OutputNotes::read_from(source)?;
let expiration_block_num = BlockNumber::read_from(source)?;

Ok(Self {
account,
output_notes,
expiration_block_num,
})
}
}

// OUTPUT NOTES
// ================================================================================================

Expand Down

0 comments on commit fdfbd3c

Please sign in to comment.