From 8c5ebfc182b6527ebdb3759be1e7018bf6646279 Mon Sep 17 00:00:00 2001 From: Bobbin Threadbare Date: Fri, 25 Oct 2024 10:16:27 -0700 Subject: [PATCH 1/2] feat: add ability to load account code directly into transaction executor --- miden-tx/src/executor/mast_store.rs | 11 +++++++---- miden-tx/src/executor/mod.rs | 13 ++++++++++++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/miden-tx/src/executor/mast_store.rs b/miden-tx/src/executor/mast_store.rs index be39e4f92..ea9aad5ac 100644 --- a/miden-tx/src/executor/mast_store.rs +++ b/miden-tx/src/executor/mast_store.rs @@ -3,9 +3,7 @@ use core::cell::RefCell; use miden_lib::{transaction::TransactionKernel, MidenLib, StdLibrary}; use miden_objects::{ - assembly::mast::MastForest, - transaction::{TransactionArgs, TransactionInputs}, - Digest, + accounts::AccountCode, assembly::mast::MastForest, transaction::{TransactionArgs, TransactionInputs}, Digest }; use vm_processor::MastForestStore; @@ -50,6 +48,11 @@ impl TransactionMastStore { store } + /// Loads the provided account code into this store. + pub fn load_account_code(&self, code: &AccountCode) { + self.insert(code.mast().clone()); + } + /// Loads code required for executing a transaction with the specified inputs and args into /// this store. /// @@ -59,7 +62,7 @@ impl TransactionMastStore { /// - Transaction script (if any) from the specified [TransactionArgs]. pub fn load_transaction_code(&self, tx_inputs: &TransactionInputs, tx_args: &TransactionArgs) { // load account code - self.insert(tx_inputs.account().code().mast().clone()); + self.load_account_code(tx_inputs.account().code()); // load note script MAST into the MAST store for note in tx_inputs.input_notes() { diff --git a/miden-tx/src/executor/mod.rs b/miden-tx/src/executor/mod.rs index 9341606c3..e7a21e0a6 100644 --- a/miden-tx/src/executor/mod.rs +++ b/miden-tx/src/executor/mod.rs @@ -2,7 +2,7 @@ use alloc::sync::Arc; use miden_lib::transaction::TransactionKernel; use miden_objects::{ - accounts::AccountId, + accounts::{AccountCode, AccountId}, notes::NoteId, transaction::{ExecutedTransaction, TransactionArgs, TransactionInputs}, vm::StackOutputs, @@ -97,6 +97,17 @@ impl TransactionExecutor { self } + // STATE MUTATORS + // -------------------------------------------------------------------------------------------- + + /// Loads the provided code into the internal MAST store and associates the procedures of the + /// account code with the specified account ID. + pub fn load_account_code(&mut self, _account_id: AccountId, code: &AccountCode) { + // TODO: account_id is not used yet, but it could be used to build a procedure map for the + // loaded accounts + self.mast_store.load_account_code(code); + } + // TRANSACTION EXECUTION // -------------------------------------------------------------------------------------------- From 19fb8f0534b6290534aec0af91f195d4b9732600 Mon Sep 17 00:00:00 2001 From: Bobbin Threadbare Date: Fri, 25 Oct 2024 10:26:27 -0700 Subject: [PATCH 2/2] chore: add changelog, fix lints --- CHANGELOG.md | 1 + miden-tx/src/executor/mast_store.rs | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 593e4992a..a5e961bc5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ - [BREAKING] Auto-generate `KERNEL_ERRORS` list from the transaction kernel's MASM files and rework error constant names (#906). - Implement `Serializable` for `FungibleAsset` (#907). - [BREAKING] Changed type of `EMPTY_STORAGE_MAP_ROOT` constant to `RpoDigst`, which references constant from `miden-crypto` (#916). +- Added `TransactionExecutor::load_account_code()` method to support foreign procedure invocation (#936). ## 0.5.1 (2024-08-28) - `miden-objects` crate only diff --git a/miden-tx/src/executor/mast_store.rs b/miden-tx/src/executor/mast_store.rs index ea9aad5ac..8f8865904 100644 --- a/miden-tx/src/executor/mast_store.rs +++ b/miden-tx/src/executor/mast_store.rs @@ -3,7 +3,10 @@ use core::cell::RefCell; use miden_lib::{transaction::TransactionKernel, MidenLib, StdLibrary}; use miden_objects::{ - accounts::AccountCode, assembly::mast::MastForest, transaction::{TransactionArgs, TransactionInputs}, Digest + accounts::AccountCode, + assembly::mast::MastForest, + transaction::{TransactionArgs, TransactionInputs}, + Digest, }; use vm_processor::MastForestStore;