diff --git a/CHANGELOG.md b/CHANGELOG.md index 461301d3aa..5598ebc4e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,7 @@ - Added the canonical `ExpirationTransactionScript` to `miden-standards`, with a delta-independent script root that network accounts can allowlist ([#3051](https://github.com/0xMiden/protocol/pull/3051)). - [BREAKING] Migrated the `miden-standards` library to a `miden-project.toml` project ([#3107](https://github.com/0xMiden/protocol/pull/3107)). - [BREAKING] Migrated `miden-protocol` MASM assembly to a `miden-project.toml` project ([#3094](https://github.com/0xMiden/protocol/pull/3094)). +- Added `ExpirationTransactionScript` to standards package and assemble it at build-time ([#3111](https://github.com/0xMiden/protocol/pull/3111)). - [BREAKING] Replaced `AccountInterface::build_send_notes_script` with a standalone `SendNotesTransactionScript` built against `AccountCodeInterface` ([#3055](https://github.com/0xMiden/protocol/pull/3055)). - Added an `AccountCode::interface` helper that returns the public `AccountCodeInterface` ([#3080](https://github.com/0xMiden/protocol/pull/3080)). - [BREAKING] Tightened `AccountStorage::get_map_item` to take a `StorageMapKey` instead of a raw `Word` ([#3080](https://github.com/0xMiden/protocol/pull/3080)). diff --git a/crates/miden-standards/asm/standards/mod.masm b/crates/miden-standards/asm/standards/mod.masm index e2dd4d4791..a2704cfff3 100644 --- a/crates/miden-standards/asm/standards/mod.masm +++ b/crates/miden-standards/asm/standards/mod.masm @@ -7,4 +7,5 @@ pub mod metadata pub mod note pub mod note_tag pub mod notes +pub mod tx_scripts pub mod wallets diff --git a/crates/miden-standards/asm/standards/tx_scripts/expiration.masm b/crates/miden-standards/asm/standards/tx_scripts/expiration.masm new file mode 100644 index 0000000000..6b00e46dbd --- /dev/null +++ b/crates/miden-standards/asm/standards/tx_scripts/expiration.masm @@ -0,0 +1,16 @@ +use miden::protocol::tx + +#! Set the transaction's expiration delta. +#! +#! Inputs: [[delta, 0, 0, 0], pad(12)] +#! Outputs: [pad(16)] +#! +#! Panics if: +#! - delta is 0 or not a u32 in the range 1..=0xFFFF (ERR_TX_INVALID_EXPIRATION_DELTA). +#! +#! Invocation: call +@transaction_script +pub proc main + exec.tx::update_expiration_block_delta + # => [pad(16)] +end diff --git a/crates/miden-standards/asm/standards/tx_scripts/mod.masm b/crates/miden-standards/asm/standards/tx_scripts/mod.masm new file mode 100644 index 0000000000..c5f9194837 --- /dev/null +++ b/crates/miden-standards/asm/standards/tx_scripts/mod.masm @@ -0,0 +1 @@ +pub mod expiration diff --git a/crates/miden-standards/build.rs b/crates/miden-standards/build.rs index b6389fae7e..e99aa23efb 100644 --- a/crates/miden-standards/build.rs +++ b/crates/miden-standards/build.rs @@ -33,8 +33,8 @@ const STANDARDS_ERRORS_ARRAY_NAME: &str = "STANDARDS_ERRORS"; // ================================================================================================ /// Read and parse the contents from `./asm`. -/// - Compiles the contents of asm/standards directory into a package. Note scripts are included in -/// this library. +/// - Compiles the contents of asm/standards directory into a package. Note scripts and transaction +/// scripts are included in this library. /// - Compiles the contents of asm/components directory into individual packages. fn main() -> Result<()> { // re-build when the MASM code changes @@ -56,7 +56,8 @@ fn main() -> Result<()> { let source_manager: Arc = Arc::new(DefaultSourceManager::default()); let assembler = Assembler::new(source_manager.clone()).with_warnings_as_errors(true); - // compile standards library (includes note scripts) and seed it into the registry + // compile standards library (includes note scripts and transaction scripts) and seed it into + // the registry compile_standards_lib(&source_dir, &target_dir, assembler.clone(), &mut registry)?; // compile account components diff --git a/crates/miden-standards/src/tx_script/expiration_script.rs b/crates/miden-standards/src/tx_script/expiration_script.rs index 4eecbdbe20..8beca430ff 100644 --- a/crates/miden-standards/src/tx_script/expiration_script.rs +++ b/crates/miden-standards/src/tx_script/expiration_script.rs @@ -1,38 +1,27 @@ use core::num::NonZeroU16; +use miden_protocol::assembly::Path; use miden_protocol::transaction::{TransactionScript, TransactionScriptRoot}; use miden_protocol::utils::sync::LazyLock; use miden_protocol::{Felt, Word}; -use crate::code_builder::CodeBuilder; +use crate::StandardsLib; -// EXPIRATION TRANSACTION SCRIPT +// CONSTANTS // ================================================================================================ -/// Transaction script that sets the expiration delta. -const EXPIRATION_TX_SCRIPT_SOURCE: &str = "\ -use miden::protocol::tx +/// Path to the expiration transaction script procedure in the standards library, assembled from +/// `asm/standards/tx_scripts/expiration.masm`. +const EXPIRATION_TX_SCRIPT_PATH: &str = "::miden::standards::tx_scripts::expiration::main"; -#! Set the transaction's expiration delta. -#! -#! Inputs: [[delta, 0, 0, 0], pad(12)] -#! Outputs: [pad(16)] -#! -#! Panics if: -#! - delta is 0 or not a u32 in the range 1..=0xFFFF (ERR_TX_INVALID_EXPIRATION_DELTA). -#! -#! Invocation: call -@transaction_script -pub proc main - exec.tx::update_expiration_block_delta - # => [pad(16)] -end -"; +// EXPIRATION TRANSACTION SCRIPT +// ================================================================================================ static EXPIRATION_TX_SCRIPT: LazyLock = LazyLock::new(|| { - CodeBuilder::default() - .compile_tx_script(EXPIRATION_TX_SCRIPT_SOURCE) - .expect("canonical expiration tx script should compile") + let standards_lib = StandardsLib::default(); + let path = Path::new(EXPIRATION_TX_SCRIPT_PATH); + TransactionScript::from_library_reference(standards_lib.as_ref(), path) + .expect("standards library should contain the expiration tx script procedure") }); /// The canonical transaction script that sets the transaction's expiration delta to the value