Feat/remove note libraries#2374
Merged
PhilippGackstatter merged 8 commits into0xMiden:nextfrom Feb 2, 2026
Merged
Conversation
Contributor
Author
bobbinth
reviewed
Jan 31, 2026
This change implements issue 0xMiden#2339 - converting note scripts from program format to library format with @note_script annotation support. Changes: - Add @note_script annotation to all standard note scripts (p2id, p2ide, swap, mint, burn) in asm/standards/notes/ - Add NoteScript::from_library constructor that finds the procedure with @note_script attribute (or falls back to 'main' procedure) and uses it as the entrypoint - Update build.rs to compile note scripts as libraries (.masl) instead of programs (.masb) using assemble_library_from_dir with unique namespace - Update well_known_note.rs to load NoteScript from Library - Remove wrapper script files (asm/note_scripts/*.masm) that are no longer needed - Add NoteError variants for missing/multiple @note_script procedures Note: The @note_script attribute propagation from MASM to Library is not yet fully supported in miden-assembly 0.20. The implementation falls back to finding a procedure named 'main' when the attribute is not found.
Address review feedback: instead of the temp directory workaround in build.rs, use simple wrapper files in note_scripts/ that re-export the main procedure from miden::standards::notes with pub use. Changes: - Add wrapper files (BURN.masm, P2ID.masm, P2IDE.masm, MINT.masm, SWAP.masm) with pub use re-exports - Simplify compile_note_scripts in build.rs to use assemble_library directly without temp directory hack - Remove unused ASM_STANDARDS_NOTES_DIR constant and AsmPath import
Changes based on PR review: - Replace hardcoded note script roots with procref in bridge_out.masm and agglayer_faucet.masm (BURN_NOTE_ROOT and P2ID_SCRIPT_ROOT) - Remove main procedure fallback in NoteScript::from_library, require @note_script attribute - Update note script wrappers to use @note_script attribute with exec instead of pub use re-exports (MASM doesn't support attributes on pub use) - Improve error handling in build.rs (replace expect with proper errors) - Use lowercase library paths (miden::standards::note_scripts::burn) - Update miden-* dependencies to v0.20.3 for attribute serialization fix
This removes the individual note script wrapper files (BURN, P2ID, P2IDE, MINT, SWAP) and their separate compilation, as suggested in PR 0xMiden#2340. Instead of compiling and loading each note script as a separate .masl file, the note scripts are now loaded directly from the main standards library using the new NoteScript::from_library_with_path method. Changes: - Add NoteScript::from_library_with_path method to extract a specific note script procedure from a library containing multiple note scripts - Remove asm/note_scripts/ wrapper files - Remove compile_note_scripts function from build.rs - Update note Rust files (burn.rs, p2id.rs, p2ide.rs, mint.rs, swap.rs) to use StandardsLib with procedure path lookup - Add NoteScriptProcedureNotFound and NoteScriptProcedureMissingAttribute error variants
f5f0a29 to
fe9e3fb
Compare
…ith_path Instead of copying the entire library's MastForest, create a minimal forest containing only a single ExternalNode referencing the procedure's digest. This significantly reduces memory usage as the actual procedure code will be resolved at runtime via MastForestStore.
fe9e3fb to
344fa6f
Compare
bobbinth
approved these changes
Jan 31, 2026
Contributor
bobbinth
left a comment
There was a problem hiding this comment.
Looks good! Thank you! I left a couple of small comments inline.
| /// Returns an error if: | ||
| /// - The library does not contain a procedure at the specified path. | ||
| /// - The procedure at the specified path does not have the `@note_script` attribute. | ||
| pub fn from_library_with_path(library: &Library, path: &Path) -> Result<Self, NoteError> { |
Contributor
There was a problem hiding this comment.
I would maybe name this more like from_library_reference() or something like that to indicate more clearly that the resulting note script would contain only the reference to the specified procedure.
Comment on lines
+118
to
+133
| let export = library | ||
| .exports() | ||
| .find(|e| e.path().as_ref() == path) | ||
| .ok_or_else(|| NoteError::NoteScriptProcedureNotFound(path.to_string().into()))?; | ||
|
|
||
| // Get the procedure export and verify it has the @note_script attribute | ||
| let proc_export = export | ||
| .as_procedure() | ||
| .ok_or_else(|| NoteError::NoteScriptProcedureNotFound(path.to_string().into()))?; | ||
|
|
||
| if !proc_export.attributes.has(NOTE_SCRIPT_ATTRIBUTE) { | ||
| return Err(NoteError::NoteScriptProcedureMissingAttribute(path.to_string().into())); | ||
| } | ||
|
|
||
| // Get the digest of the procedure from the library | ||
| let digest = library.mast_forest()[proc_export.node].digest(); |
Contributor
There was a problem hiding this comment.
Not for this PR: but it would be nice if we had something like Library:get_procedure_by_path(path) which returned ProcedureExport and ProcedureExport contained the digest of the procedure.
- Renamed NoteScript::from_library_with_path to from_library_reference to better indicate that the resulting note script contains only a reference to the procedure - Updated docstring for create_external_node_forest helper function - Updated all usages in miden-standards note modules
Contributor
Author
|
good 👍 |
PhilippGackstatter
approved these changes
Feb 2, 2026
Contributor
PhilippGackstatter
left a comment
There was a problem hiding this comment.
Looks good, much cleaner!
afa7789
pushed a commit
to afa7789/miden-base
that referenced
this pull request
Mar 9, 2026
* refactor: convert note scripts from program to library format This change implements issue 0xMiden#2339 - converting note scripts from program format to library format with @note_script annotation support. Changes: - Add @note_script annotation to all standard note scripts (p2id, p2ide, swap, mint, burn) in asm/standards/notes/ - Add NoteScript::from_library constructor that finds the procedure with @note_script attribute (or falls back to 'main' procedure) and uses it as the entrypoint - Update build.rs to compile note scripts as libraries (.masl) instead of programs (.masb) using assemble_library_from_dir with unique namespace - Update well_known_note.rs to load NoteScript from Library - Remove wrapper script files (asm/note_scripts/*.masm) that are no longer needed - Add NoteError variants for missing/multiple @note_script procedures Note: The @note_script attribute propagation from MASM to Library is not yet fully supported in miden-assembly 0.20. The implementation falls back to finding a procedure named 'main' when the attribute is not found. * refactor: use pub use re-exports in note script wrappers Address review feedback: instead of the temp directory workaround in build.rs, use simple wrapper files in note_scripts/ that re-export the main procedure from miden::standards::notes with pub use. Changes: - Add wrapper files (BURN.masm, P2ID.masm, P2IDE.masm, MINT.masm, SWAP.masm) with pub use re-exports - Simplify compile_note_scripts in build.rs to use assemble_library directly without temp directory hack - Remove unused ASM_STANDARDS_NOTES_DIR constant and AsmPath import * refactor: address review feedback for note script library conversion Changes based on PR review: - Replace hardcoded note script roots with procref in bridge_out.masm and agglayer_faucet.masm (BURN_NOTE_ROOT and P2ID_SCRIPT_ROOT) - Remove main procedure fallback in NoteScript::from_library, require @note_script attribute - Update note script wrappers to use @note_script attribute with exec instead of pub use re-exports (MASM doesn't support attributes on pub use) - Improve error handling in build.rs (replace expect with proper errors) - Use lowercase library paths (miden::standards::note_scripts::burn) - Update miden-* dependencies to v0.20.3 for attribute serialization fix * refactor: remove individual note script libraries This removes the individual note script wrapper files (BURN, P2ID, P2IDE, MINT, SWAP) and their separate compilation, as suggested in PR 0xMiden#2340. Instead of compiling and loading each note script as a separate .masl file, the note scripts are now loaded directly from the main standards library using the new NoteScript::from_library_with_path method. Changes: - Add NoteScript::from_library_with_path method to extract a specific note script procedure from a library containing multiple note scripts - Remove asm/note_scripts/ wrapper files - Remove compile_note_scripts function from build.rs - Update note Rust files (burn.rs, p2id.rs, p2ide.rs, mint.rs, swap.rs) to use StandardsLib with procedure path lookup - Add NoteScriptProcedureNotFound and NoteScriptProcedureMissingAttribute error variants * refactor: use minimal MastForest with external node in from_library_with_path Instead of copying the entire library's MastForest, create a minimal forest containing only a single ExternalNode referencing the procedure's digest. This significantly reduces memory usage as the actual procedure code will be resolved at runtime via MastForestStore. * refactor: rename from_library_with_path to from_library_reference - Renamed NoteScript::from_library_with_path to from_library_reference to better indicate that the resulting note script contains only a reference to the procedure - Updated docstring for create_external_node_forest helper function - Updated all usages in miden-standards note modules * fix: remove duplicate changelog entry --------- Co-authored-by: Philipp Gackstatter <PhilippGackstatter@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
As suggested by @bobbinth in #2340 (comment)
NoteScript::from_library_with_pathmethodRelated
Follow-up to #2340