Skip to content
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 @@ -49,6 +49,7 @@

### Changes

- [BREAKING] Renamed `AccountComponent::get_procedures()` to `procedures()`, returning `impl Iterator<Item = (AccountProcedureRoot, bool)>` ([#2597](https://github.com/0xMiden/protocol/pull/2597)).
- [BREAKING] Removed `NoteAssets::add_asset`; `OutputNoteBuilder` now accumulates assets in a `Vec` and computes the commitment only when `build()` is called, avoiding rehashing on every asset addition. ([#2577](https://github.com/0xMiden/protocol/pull/2577))
- [BREAKING] Made `supported_types` a required parameter of `AccountComponentMetadata::new()`; removed `with_supported_type`, `with_supported_types`, `with_supports_all_types`, and `with_supports_regular_types` builder methods; added `AccountType::all()` and `AccountType::regular()` helpers ([#2554](https://github.com/0xMiden/protocol/pull/2554)).
- [BREAKING] Migrated to miden-vm 0.21 and miden-crypto 0.22 ([#2508](https://github.com/0xMiden/miden-base/pull/2508)).
Expand Down
9 changes: 4 additions & 5 deletions crates/miden-protocol/src/account/code/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ impl AccountProcedureBuilder {
fn add_auth_component(&mut self, component: &AccountComponent) -> Result<(), AccountError> {
let mut auth_proc_count = 0;

for (proc_root, is_auth) in component.get_procedures() {
for (proc_root, is_auth) in component.procedures() {
self.add_procedure(proc_root);

if is_auth {
Expand All @@ -358,20 +358,19 @@ impl AccountProcedureBuilder {
}

fn add_component(&mut self, component: &AccountComponent) -> Result<(), AccountError> {
for (proc_mast_root, is_auth) in component.get_procedures() {
for (proc_root, is_auth) in component.procedures() {
if is_auth {
return Err(AccountError::AccountCodeMultipleAuthComponents);
}
self.add_procedure(proc_mast_root);
self.add_procedure(proc_root);
}

Ok(())
}

fn add_procedure(&mut self, proc_mast_root: Word) {
fn add_procedure(&mut self, proc_root: AccountProcedureRoot) {
// Allow procedures with the same MAST root from different components, but only add them
// once.
let proc_root = AccountProcedureRoot::from_raw(proc_mast_root);
if !self.procedures.contains(&proc_root) {
self.procedures.push(proc_root);
}
Expand Down
20 changes: 19 additions & 1 deletion crates/miden-protocol/src/account/component/code.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use miden_assembly::Library;
use miden_processor::mast::MastForest;
use miden_assembly::library::ProcedureExport;
use miden_processor::mast::{MastForest, MastNodeExt};

use crate::account::AccountProcedureRoot;
use crate::vm::AdviceMap;

// ACCOUNT COMPONENT CODE
Expand All @@ -26,6 +28,22 @@ impl AccountComponentCode {
self.0
}

/// Returns an iterator over the [`AccountProcedureRoot`]s of this component's exported
/// procedures.
pub fn procedure_roots(&self) -> impl Iterator<Item = AccountProcedureRoot> + '_ {
self.0.exports().filter_map(|export| {
export.as_procedure().map(|proc_export| {
let digest = self.0.mast_forest()[proc_export.node].digest();
AccountProcedureRoot::from_raw(digest)
})
})
}

/// Returns the procedure exports of this component.
pub fn exports(&self) -> impl Iterator<Item = &ProcedureExport> + '_ {
self.0.exports().filter_map(|export| export.as_procedure())
}

/// Returns a new [AccountComponentCode] with the provided advice map entries merged into the
/// underlying [Library]'s [MastForest].
///
Expand Down
19 changes: 9 additions & 10 deletions crates/miden-protocol/src/account/component/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub use storage::*;
mod code;
pub use code::AccountComponentCode;

use crate::account::{AccountType, StorageSlot};
use crate::account::{AccountProcedureRoot, AccountType, StorageSlot};
use crate::assembly::Path;
use crate::errors::AccountError;
use crate::{MastForest, Word};
Expand Down Expand Up @@ -196,25 +196,24 @@ impl AccountComponent {
self.metadata.supported_types().contains(&account_type)
}

/// Returns a vector of tuples (digest, is_auth) for all procedures in this component.
/// Returns an iterator over ([`AccountProcedureRoot`], is_auth) for all procedures in this
/// component.
///
/// A procedure is considered an authentication procedure if it has the `@auth_script`
/// attribute.
pub fn get_procedures(&self) -> Vec<(Word, bool)> {
pub fn procedures(&self) -> impl Iterator<Item = (AccountProcedureRoot, bool)> + '_ {
let library = self.code.as_library();
let mut procedures = Vec::new();
for export in library.exports() {
if let Some(proc_export) = export.as_procedure() {
library.exports().filter_map(|export| {
export.as_procedure().map(|proc_export| {
let digest = library
.mast_forest()
.get_node_by_id(proc_export.node)
.expect("export node not in the forest")
.digest();
let is_auth = proc_export.attributes.has(AUTH_SCRIPT_ATTRIBUTE);
procedures.push((digest, is_auth));
}
}
procedures
(AccountProcedureRoot::from_raw(digest), is_auth)
})
})
}

/// Returns the digest of the procedure with the specified path, or `None` if it was not found
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ static INCR_NONCE_AUTH_LIBRARY: LazyLock<Library> = LazyLock::new(|| {
CodeBuilder::default()
.compile_component_code("incr_nonce", INCR_NONCE_AUTH_CODE)
.expect("incr nonce code should be valid")
.into_library()
.into()
});

/// Creates a mock authentication [`AccountComponent`] for testing purposes under the "incr_nonce"
Expand Down
4 changes: 2 additions & 2 deletions crates/miden-standards/src/testing/mock_account_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,14 @@ static MOCK_FAUCET_LIBRARY: LazyLock<Library> = LazyLock::new(|| {
CodeBuilder::default()
.compile_component_code("mock::faucet", MOCK_FAUCET_CODE)
.expect("mock faucet code should be valid")
.into_library()
.into()
});

static MOCK_ACCOUNT_LIBRARY: LazyLock<Library> = LazyLock::new(|| {
CodeBuilder::default()
.compile_component_code("mock::account", MOCK_ACCOUNT_CODE)
.expect("mock account code should be valid")
.into_library()
.into()
});

// MOCK ACCOUNT CODE EXT
Expand Down
Loading