Skip to content

Feat/remove note libraries#2374

Merged
PhilippGackstatter merged 8 commits into0xMiden:nextfrom
Farukest:feat/remove-note-libraries
Feb 2, 2026
Merged

Feat/remove note libraries#2374
PhilippGackstatter merged 8 commits into0xMiden:nextfrom
Farukest:feat/remove-note-libraries

Conversation

@Farukest
Copy link
Copy Markdown
Contributor

Summary

As suggested by @bobbinth in #2340 (comment)

  • Remove individual note script wrapper files and their compilation
  • Load note scripts directly from StandardsLib using procedure path lookup
  • Add NoteScript::from_library_with_path method

Related

Follow-up to #2340

@Farukest
Copy link
Copy Markdown
Contributor Author

@bobbinth I got that one too as you suggested on #2340 👍

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
@Farukest Farukest force-pushed the feat/remove-note-libraries branch 2 times, most recently from f5f0a29 to fe9e3fb Compare January 31, 2026 14:59
…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.
@Farukest Farukest force-pushed the feat/remove-note-libraries branch from fe9e3fb to 344fa6f Compare January 31, 2026 15:04
Copy link
Copy Markdown
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@Farukest
Copy link
Copy Markdown
Contributor Author

good 👍
I thought those too :)
and prepared already. need review @bobbinth

Copy link
Copy Markdown
Contributor

@PhilippGackstatter PhilippGackstatter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, much cleaner!

@PhilippGackstatter PhilippGackstatter merged commit 528a1e2 into 0xMiden:next Feb 2, 2026
15 checks passed
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants