Skip to content

fix(assembly): validate procedure roots during library deserialization#2933

Open
giwaov wants to merge 1 commit into0xMiden:nextfrom
giwaov:fix/library-deser-validate-roots
Open

fix(assembly): validate procedure roots during library deserialization#2933
giwaov wants to merge 1 commit into0xMiden:nextfrom
giwaov:fix/library-deser-validate-roots

Conversation

@giwaov
Copy link
Copy Markdown
Contributor

@giwaov giwaov commented Mar 28, 2026

Description

This PR fixes an issue where \Library::read_from\ accepts procedure exports whose \MastNodeId\ is not a procedure root in the underlying MAST forest. This allows crafting a library with uncallable procedure exports, violating the invariant enforced by \Library::new().

This was identified as finding 19 in the audit report.

Changes

Fix

  • Added a validation loop to the \Deserializable\ implementation for \Library\ (in \crates/assembly-syntax/src/library/mod.rs) that checks each procedure export references a valid procedure root in the \MastForest, matching the existing check in \Library::new().

Test

  • Added \library_deserialization_rejects_non_root_export\ test that constructs a tampered serialized library with an export pointing to a non-root node and verifies deserialization rejects it with an appropriate error message.

Testing

  • \cargo test -p miden-assembly library_deserialization_rejects_non_root_export\ passes
  • \cargo test -p miden-assembly library_serialization\ still passes (no regression)
  • Both \miden-assembly\ and \miden-assembly-syntax\ crates compile cleanly

Closes #2831

@huitseeker
Copy link
Copy Markdown
Contributor

huitseeker commented Mar 30, 2026

@amathxbt Please cease spam comments.

@github-actions
Copy link
Copy Markdown

This PR contains unsigned commits. All commits must be cryptographically signed (GPG or SSH).

Unsigned commits:

  • 9ff84ee0 fix(assembly): validate procedure roots during library deserialization

For instructions on setting up commit signing and re-signing existing commits, see:
https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits

@giwaov giwaov force-pushed the fix/library-deser-validate-roots branch from 8754a14 to 619f63f Compare March 30, 2026 08:43
Library::read_from accepts procedure exports whose MastNodeId is not a
procedure root in the underlying MAST forest. This means a malicious
library can export uncallable procedures, violating the invariant
enforced by Library::new().

Add a validation loop to the Deserializable implementation for Library
that checks each procedure export has a corresponding procedure root in
the MastForest, matching the existing check in Library::new().

Add a regression test that constructs a tampered library with an export
pointing to a non-root node and verifies deserialization rejects it.

Closes 0xMiden#2831
@giwaov giwaov force-pushed the fix/library-deser-validate-roots branch from 619f63f to 8d82445 Compare March 30, 2026 09:50
Copy link
Copy Markdown
Contributor

@huitseeker huitseeker left a comment

Choose a reason for hiding this comment

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

🙏

@huitseeker huitseeker requested review from bitwalker and plafer March 31, 2026 11:27
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.

Library deserialization accepts uncallable procedure exports

2 participants