Skip to content

Commit 202d92d

Browse files
Himessafa7789
authored andcommitted
feat: prefix account components with miden::standards namespace (#2400)
1 parent c113da6 commit 202d92d

14 files changed

Lines changed: 58 additions & 32 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Enable `CodeBuilder` to add advice map entries to compiled scripts ([#2275](http
4444
- [BREAKING] The native hash function changed from RPO256 to Poseidon2 - see PR description ([#2508](https://github.com/0xMiden/miden-base/pull/2508)).
4545
- Introduced `StorageMapKey` and `StorageMapKeyHash` Word wrappers for type-safe storage map key handling ([#2431](https://github.com/0xMiden/miden-base/pull/2431)).
4646
- Restructured `miden-agglayer/asm` directory to separate bridge and faucet into per-component libraries, preventing cross-component procedure exposure ([#2294](https://github.com/0xMiden/miden-base/issues/2294)).
47+
- Prefixed standard account component names with `miden::standards::components` ([#2400](https://github.com/0xMiden/miden-base/pull/2400)).
4748
- Made kernel procedure offset constants public and replaced accessor procedures with direct constant usage ([#2375](https://github.com/0xMiden/miden-base/pull/2375)).
4849
- [BREAKING] Made `AccountComponentMetadata` a required parameter of `AccountComponent::new()`; removed `with_supported_type`, `with_supports_all_types`, and `with_metadata` methods from `AccountComponent`; simplified `AccountComponentMetadata::new()` to take just `name`; renamed `AccountComponentTemplateError` to `ComponentMetadataError` ([#2373](https://github.com/0xMiden/miden-base/pull/2373), [#2395](https://github.com/0xMiden/miden-base/pull/2395)).
4950
- Fixed MASM inline comment casing to adhere to commenting conventions ([#2398](https://github.com/0xMiden/miden-base/pull/2398)).

crates/miden-standards/build.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const ASM_STANDARDS_DIR: &str = "standards";
1515
const ASM_ACCOUNT_COMPONENTS_DIR: &str = "account_components";
1616

1717
const STANDARDS_LIB_NAMESPACE: &str = "miden::standards";
18+
const ACCOUNT_COMPONENTS_LIB_NAMESPACE: &str = "miden::standards::components";
1819

1920
const STANDARDS_ERRORS_RS_FILE: &str = "standards_errors.rs";
2021
const STANDARDS_ERRORS_ARRAY_NAME: &str = "STANDARDS_ERRORS";
@@ -107,7 +108,19 @@ fn compile_account_components(
107108
let component_source_code = fs::read_to_string(&masm_file_path)
108109
.expect("reading the component's MASM source code should succeed");
109110

110-
let named_source = NamedSource::new(component_name.clone(), component_source_code);
111+
// Build full library path from directory structure:
112+
// e.g. faucets/basic_fungible_faucet.masm ->
113+
// miden::standards::components::faucets::basic_fungible_faucet
114+
let relative_path = masm_file_path
115+
.strip_prefix(source_dir)
116+
.expect("masm file should be inside source dir");
117+
let mut library_path = ACCOUNT_COMPONENTS_LIB_NAMESPACE.to_owned();
118+
for component in relative_path.with_extension("").components() {
119+
let part = component.as_os_str().to_str().expect("valid UTF-8");
120+
library_path.push_str("::");
121+
library_path.push_str(part);
122+
}
123+
let named_source = NamedSource::new(library_path, component_source_code);
111124

112125
let component_library = assembler
113126
.clone()

crates/miden-standards/src/account/auth/multisig.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ pub struct AuthMultisig {
142142

143143
impl AuthMultisig {
144144
/// The name of the component.
145-
pub const NAME: &'static str = "miden::auth::multisig";
145+
pub const NAME: &'static str = "miden::standards::components::auth::multisig";
146146

147147
/// Creates a new [`AuthMultisig`] component from the provided configuration.
148148
pub fn new(config: AuthMultisigConfig) -> Result<Self, AccountError> {

crates/miden-standards/src/account/auth/multisig_psm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ pub struct AuthMultisigPsm {
194194

195195
impl AuthMultisigPsm {
196196
/// The name of the component.
197-
pub const NAME: &'static str = "miden::auth::multisig_psm";
197+
pub const NAME: &'static str = "miden::standards::components::auth::multisig_psm";
198198

199199
/// Creates a new [`AuthMultisigPsm`] component from the provided configuration.
200200
pub fn new(config: AuthMultisigPsmConfig) -> Result<Self, AccountError> {

crates/miden-standards/src/account/auth/no_auth.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub struct NoAuth;
2121

2222
impl NoAuth {
2323
/// The name of the component.
24-
pub const NAME: &'static str = "miden::auth::no_auth";
24+
pub const NAME: &'static str = "miden::standards::components::auth::no_auth";
2525

2626
/// Creates a new [`NoAuth`] component.
2727
pub fn new() -> Self {

crates/miden-standards/src/account/auth/singlesig.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub struct AuthSingleSig {
4545

4646
impl AuthSingleSig {
4747
/// The name of the component.
48-
pub const NAME: &'static str = "miden::auth::singlesig";
48+
pub const NAME: &'static str = "miden::standards::components::auth::singlesig";
4949

5050
/// Creates a new [`AuthSingleSig`] component with the given `public_key`.
5151
pub fn new(pub_key: PublicKeyCommitment, auth_scheme: AuthScheme) -> Self {

crates/miden-standards/src/account/auth/singlesig_acl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ pub struct AuthSingleSigAcl {
157157

158158
impl AuthSingleSigAcl {
159159
/// The name of the component.
160-
pub const NAME: &'static str = "miden::auth::singlesig_acl";
160+
pub const NAME: &'static str = "miden::standards::components::auth::singlesig_acl";
161161
/// Creates a new [`AuthSingleSigAcl`] component with the given `public_key` and
162162
/// configuration.
163163
///

crates/miden-standards/src/account/faucets/basic_fungible.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ use crate::procedure_digest;
3333
// Initialize the digest of the `distribute` procedure of the Basic Fungible Faucet only once.
3434
procedure_digest!(
3535
BASIC_FUNGIBLE_FAUCET_DISTRIBUTE,
36+
BasicFungibleFaucet::NAME,
3637
BasicFungibleFaucet::DISTRIBUTE_PROC_NAME,
3738
basic_fungible_faucet_library
3839
);
3940

4041
// Initialize the digest of the `burn` procedure of the Basic Fungible Faucet only once.
4142
procedure_digest!(
4243
BASIC_FUNGIBLE_FAUCET_BURN,
44+
BasicFungibleFaucet::NAME,
4345
BasicFungibleFaucet::BURN_PROC_NAME,
4446
basic_fungible_faucet_library
4547
);
@@ -74,13 +76,13 @@ impl BasicFungibleFaucet {
7476
// --------------------------------------------------------------------------------------------
7577

7678
/// The name of the component.
77-
pub const NAME: &'static str = "miden::basic_fungible_faucet";
79+
pub const NAME: &'static str = "miden::standards::components::faucets::basic_fungible_faucet";
7880

7981
/// The maximum number of decimals supported by the component.
8082
pub const MAX_DECIMALS: u8 = TokenMetadata::MAX_DECIMALS;
8183

82-
const DISTRIBUTE_PROC_NAME: &str = "basic_fungible_faucet::distribute";
83-
const BURN_PROC_NAME: &str = "basic_fungible_faucet::burn";
84+
const DISTRIBUTE_PROC_NAME: &str = "distribute";
85+
const BURN_PROC_NAME: &str = "burn";
8486

8587
// CONSTRUCTORS
8688
// --------------------------------------------------------------------------------------------

crates/miden-standards/src/account/faucets/network_fungible.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@ const TOKEN_SYMBOL_TYPE: &str = "miden::standards::fungible_faucets::metadata::t
3434
// Initialize the digest of the `distribute` procedure of the Network Fungible Faucet only once.
3535
procedure_digest!(
3636
NETWORK_FUNGIBLE_FAUCET_DISTRIBUTE,
37+
NetworkFungibleFaucet::NAME,
3738
NetworkFungibleFaucet::DISTRIBUTE_PROC_NAME,
3839
network_fungible_faucet_library
3940
);
4041

4142
// Initialize the digest of the `burn` procedure of the Network Fungible Faucet only once.
4243
procedure_digest!(
4344
NETWORK_FUNGIBLE_FAUCET_BURN,
45+
NetworkFungibleFaucet::NAME,
4446
NetworkFungibleFaucet::BURN_PROC_NAME,
4547
network_fungible_faucet_library
4648
);
@@ -77,13 +79,13 @@ impl NetworkFungibleFaucet {
7779
// --------------------------------------------------------------------------------------------
7880

7981
/// The name of the component.
80-
pub const NAME: &'static str = "miden::network_fungible_faucet";
82+
pub const NAME: &'static str = "miden::standards::components::faucets::network_fungible_faucet";
8183

8284
/// The maximum number of decimals supported by the component.
8385
pub const MAX_DECIMALS: u8 = TokenMetadata::MAX_DECIMALS;
8486

85-
const DISTRIBUTE_PROC_NAME: &str = "network_fungible_faucet::distribute";
86-
const BURN_PROC_NAME: &str = "network_fungible_faucet::burn";
87+
const DISTRIBUTE_PROC_NAME: &str = "distribute";
88+
const BURN_PROC_NAME: &str = "burn";
8789

8890
// CONSTRUCTORS
8991
// --------------------------------------------------------------------------------------------

crates/miden-standards/src/account/mod.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,35 @@ pub use metadata::AccountBuilderSchemaCommitmentExt;
1515
/// This macro generates a `LazyLock<Word>` static variable that lazily initializes
1616
/// the digest of a procedure from a library.
1717
///
18+
/// The full procedure path is constructed by concatenating `$component_name` and `$proc_name`
19+
/// with `::` as separator (i.e. `"{component_name}::{proc_name}"`).
20+
///
1821
/// Note: This macro references exported types from `miden_protocol`, so your crate must
1922
/// include `miden_protocol` as a dependency.
2023
///
2124
/// # Arguments
2225
/// * `$name` - The name of the static variable to create
23-
/// * `$proc_name` - The string name of the procedure
26+
/// * `$component_name` - The name of the component (e.g. `BasicWallet::NAME`)
27+
/// * `$proc_name` - The short name of the procedure (e.g. `"receive_asset"`)
2428
/// * `$library_fn` - The function that returns the library containing the procedure
2529
///
2630
/// # Example
2731
/// ```ignore
2832
/// procedure_digest!(
2933
/// BASIC_WALLET_RECEIVE_ASSET,
34+
/// BasicWallet::NAME,
3035
/// BasicWallet::RECEIVE_ASSET_PROC_NAME,
3136
/// basic_wallet_library
3237
/// );
3338
/// ```
3439
#[macro_export]
3540
macro_rules! procedure_digest {
36-
($name:ident, $proc_name:expr, $library_fn:expr) => {
41+
($name:ident, $component_name:expr, $proc_name:expr, $library_fn:expr) => {
3742
static $name: miden_protocol::utils::sync::LazyLock<miden_protocol::Word> =
3843
miden_protocol::utils::sync::LazyLock::new(|| {
39-
$library_fn().get_procedure_root_by_path($proc_name).unwrap_or_else(|| {
40-
panic!("{} should contain '{}' procedure", stringify!($library_fn), $proc_name)
44+
let full_path = alloc::format!("{}::{}", $component_name, $proc_name);
45+
$library_fn().get_procedure_root_by_path(full_path.as_str()).unwrap_or_else(|| {
46+
panic!("{} should contain '{}' procedure", stringify!($library_fn), full_path)
4147
})
4248
});
4349
};

0 commit comments

Comments
 (0)