Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement account code loading into transaction executor #936

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 7 additions & 1 deletion miden-tx/src/executor/mast_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use core::cell::RefCell;

use miden_lib::{transaction::TransactionKernel, MidenLib, StdLibrary};
use miden_objects::{
accounts::AccountCode,
assembly::mast::MastForest,
transaction::{TransactionArgs, TransactionInputs},
Digest,
Expand Down Expand Up @@ -50,6 +51,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.
///
Expand All @@ -59,7 +65,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() {
Expand Down
13 changes: 12 additions & 1 deletion miden-tx/src/executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
// --------------------------------------------------------------------------------------------

Expand Down
Loading