Skip to content

Commit

Permalink
try replicating changes from first two commits from #529
Browse files Browse the repository at this point in the history
  • Loading branch information
mFragaBA committed Apr 9, 2024
1 parent 89952a1 commit 1056c38
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 30 deletions.
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions miden-lib/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ impl TransactionKernel {
/// tuples for the notes consumed by the transaction.
pub fn build_input_stack(
acct_id: AccountId,
init_acct_hash: Digest,
init_acct_hash: Option<Digest>,
input_notes_hash: Digest,
block_hash: Digest,
) -> StackInputs {
let mut inputs: Vec<Felt> = Vec::with_capacity(13);
inputs.extend(input_notes_hash);
inputs.extend_from_slice(init_acct_hash.as_elements());
inputs.extend_from_slice(init_acct_hash.unwrap_or_default().as_elements());
inputs.push(acct_id.into());
inputs.extend_from_slice(block_hash.as_elements());
StackInputs::new(inputs)
Expand Down
10 changes: 3 additions & 7 deletions miden-tx/src/prover/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use core::ops::Not;

use miden_lib::transaction::{ToTransactionKernelInputs, TransactionKernel};
use miden_objects::{
notes::Nullifier,
Expand Down Expand Up @@ -48,7 +50,7 @@ impl TransactionProver {
let input_notes: InputNotes<Nullifier> = (tx_witness.tx_inputs().input_notes()).into();

let account_id = tx_witness.account().id();
let initial_account_hash = tx_witness.account().hash();
let initial_hash = tx_witness.account().is_new().not().then(|| tx_witness.account().hash());
let block_hash = tx_witness.block_header().hash();
let tx_script_root = tx_witness.tx_args().tx_script().map(|script| *script.hash());

Expand All @@ -65,12 +67,6 @@ impl TransactionProver {
TransactionKernel::from_transaction_parts(&stack_outputs, &map.into(), output_notes)
.map_err(TransactionProverError::InvalidTransactionOutput)?;

let initial_hash = if tx_witness.account().is_new() {
Digest::default()
} else {
initial_account_hash
};

let builder = ProvenTransactionBuilder::new(
account_id,
initial_hash,
Expand Down
10 changes: 4 additions & 6 deletions objects/src/accounts/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use core::ops::Not;

use crate::{
assembly::{Assembler, AssemblyContext, ModuleAst},
assets::AssetVault,
Expand Down Expand Up @@ -96,12 +98,8 @@ impl Account {
/// against a new account, public input for the initial account state is set to [ZERO; 4] to
/// distinguish new accounts from existing accounts. The actual hash of the initial account
/// state (and the initial state itself), are provided to the VM via the advice provider.
pub fn proof_init_hash(&self) -> Digest {
if self.is_new() {
Digest::default()
} else {
self.hash()
}
pub fn proof_init_hash(&self) -> Option<Digest> {
self.is_new().not().then(|| self.hash())
}

/// Returns unique identifier of this account.
Expand Down
13 changes: 7 additions & 6 deletions objects/src/transaction/proven_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub struct ProvenTransaction {
/// The hash of the account before the transaction was executed.
///
/// Set to `Digest::default()` for new accounts.
initial_account_hash: Digest,
initial_account_hash: Option<Digest>,

/// The hash of the account after the transaction was executed.
final_account_hash: Digest,
Expand Down Expand Up @@ -74,7 +74,7 @@ impl ProvenTransaction {
}

/// Returns the initial account state hash.
pub fn initial_account_hash(&self) -> Digest {
pub fn initial_account_hash(&self) -> Option<Digest> {
self.initial_account_hash
}

Expand Down Expand Up @@ -129,7 +129,7 @@ impl ProvenTransaction {
))
},
Some(ref details) => {
let is_new_account = self.initial_account_hash == Digest::default();
let is_new_account = self.initial_account_hash.is_none();

match (is_new_account, details) {
(true, AccountDetails::Delta(_)) => {
Expand Down Expand Up @@ -180,7 +180,7 @@ pub struct ProvenTransactionBuilder {
account_id: AccountId,

/// The hash of the account before the transaction was executed.
initial_account_hash: Digest,
initial_account_hash: Option<Digest>,

/// The hash of the account after the transaction was executed.
final_account_hash: Digest,
Expand Down Expand Up @@ -211,11 +211,12 @@ impl ProvenTransactionBuilder {
/// Returns a [ProvenTransactionBuilder] used to build a [ProvenTransaction].
pub fn new(
account_id: AccountId,
initial_account_hash: Digest,
initial_account_hash: Option<Digest>,
final_account_hash: Digest,
block_ref: Digest,
proof: ExecutionProof,
) -> Self {
debug_assert_ne!(initial_account_hash, Some(Digest::default()));
Self {
account_id,
initial_account_hash,
Expand Down Expand Up @@ -346,7 +347,7 @@ impl Serializable for ProvenTransaction {
impl Deserializable for ProvenTransaction {
fn read_from<R: ByteReader>(source: &mut R) -> Result<Self, DeserializationError> {
let account_id = AccountId::read_from(source)?;
let initial_account_hash = Digest::read_from(source)?;
let initial_account_hash = <Option<Digest>>::read_from(source)?;
let final_account_hash = Digest::read_from(source)?;
let account_details = <Option<AccountDetails>>::read_from(source)?;

Expand Down
7 changes: 4 additions & 3 deletions objects/src/transaction/transaction_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ pub struct TransactionId(Digest);
impl TransactionId {
/// Returns a new [TransactionId] instantiated from the provided transaction components.
pub fn new(
init_account_hash: Digest,
init_account_hash: Option<Digest>,
final_account_hash: Digest,
input_notes_hash: Digest,
output_notes_hash: Digest,
) -> Self {
debug_assert_ne!(init_account_hash, Some(Digest::default()));
let mut elements = [ZERO; 4 * WORD_SIZE];
elements[..4].copy_from_slice(init_account_hash.as_elements());
elements[..4].copy_from_slice(init_account_hash.unwrap_or_default().as_elements());
elements[4..8].copy_from_slice(final_account_hash.as_elements());
elements[8..12].copy_from_slice(input_notes_hash.as_elements());
elements[12..].copy_from_slice(output_notes_hash.as_elements());
Expand Down Expand Up @@ -89,7 +90,7 @@ impl From<&ExecutedTransaction> for TransactionId {
let input_notes_hash = tx.input_notes().commitment();
let output_notes_hash = tx.output_notes().commitment();
Self::new(
tx.initial_account().hash(),
tx.initial_account().proof_init_hash(),
tx.final_account().hash(),
input_notes_hash,
output_notes_hash,
Expand Down

0 comments on commit 1056c38

Please sign in to comment.