Skip to main content

miden_standards/account/
upgrade.rs

1use miden_protocol::account::component::{AccountComponentCode, AccountComponentMetadata};
2use miden_protocol::account::{AccountComponent, AccountComponentName, AccountProcedureRoot};
3
4use crate::account::account_component_code;
5use crate::procedure_root;
6
7// UPGRADE MANAGER COMPONENT
8// ================================================================================================
9
10account_component_code!(UPGRADE_MANAGER_CODE, "miden-standards-upgrade-manager.masp");
11
12// PROCEDURE ROOTS
13// ================================================================================================
14
15/// MASL library namespace used for procedure-root lookups. Distinct from [`UpgradeManager::NAME`],
16/// which mirrors the standards-side MASM module path.
17const UPGRADE_MANAGER_LIBRARY_PATH: &str = "miden::standards::components::upgrade::manager";
18
19procedure_root!(
20    UPGRADE_MANAGER_UPGRADE,
21    UPGRADE_MANAGER_LIBRARY_PATH,
22    UpgradeManager::UPGRADE_PROC_NAME,
23    UpgradeManager::code()
24);
25
26/// Account component exposing an `upgrade` admin procedure, gated by the account-wide
27/// [`crate::account::access::Authority`] component via `exec.authority::assert_authorized`.
28///
29/// The procedure wraps the protocol `native_account::upgrade` kernel procedure, letting an account
30/// record the commitments describing an upgrade of its own code and storage. It is currently a
31/// no-op beyond storing the two commitments in kernel memory; the actual upgrade application is not
32/// yet implemented and the commitment formats are not yet defined. `assert_authorized` is the hook
33/// where any stronger authorization gate would live once upgrades are enabled.
34///
35/// `UpgradeManager` works with every standard access scheme that installs an [`Authority`]
36/// component.
37///
38/// Companion component required:
39/// - [`Authority`].
40///
41/// [`Authority`]: crate::account::access::Authority
42#[derive(Debug, Clone, Copy, Default)]
43pub struct UpgradeManager;
44
45impl UpgradeManager {
46    /// The name of the component.
47    const NAME: &'static str = "miden::standards::upgrade::manager";
48
49    const UPGRADE_PROC_NAME: &'static str = "upgrade";
50
51    /// Returns the canonical [`AccountComponentName`] of this component.
52    pub const fn name() -> AccountComponentName {
53        AccountComponentName::from_static_str(Self::NAME)
54    }
55
56    /// Returns the [`AccountComponentCode`] of this component.
57    pub fn code() -> &'static AccountComponentCode {
58        &UPGRADE_MANAGER_CODE
59    }
60
61    /// Returns the procedure root of the `upgrade` procedure exposed by this component.
62    pub fn upgrade_root() -> AccountProcedureRoot {
63        *UPGRADE_MANAGER_UPGRADE
64    }
65}
66
67impl From<UpgradeManager> for AccountComponent {
68    fn from(_: UpgradeManager) -> Self {
69        let metadata = AccountComponentMetadata::new(UpgradeManager::NAME)
70            .with_description("Code and storage upgrades for accounts.");
71
72        AccountComponent::new(UpgradeManager::code().clone(), vec![], metadata).expect(
73            "upgrade manager component should satisfy the requirements of a valid account component",
74        )
75    }
76}