Skip to content

Conversation

lima-limon-inc
Copy link
Contributor

@lima-limon-inc lima-limon-inc commented Sep 4, 2025

Note: This PR is still in WIP
While working on midenup's tutorial, I tried to create an Account with the miden-client's CLI from the generated .masp that the compiler produced.*

The problem I stumbled upon was that the client failed to deserialize the generated Package from the .masp, erroring out with: unsupported version. Got '[0.0.0]', but only '[1.0.0]' is supported.

If I'm not mistaken, this error originates from a mismatch between the client and the compiler VM's version. The compiler is using version 0.15 of the miden-mast-package crate (which is a crate present in the VM's repo), while the client is using version 0.17 the VM (indirectly via its usage of version 0.11 of the miden-objects crate). Particularly, the Package serialization format got a major version bump from version 0.15.0 to version 0.17.0

So, this PR updates the VM version used by the compiler.

* I added a small experimental-only patch to the miden-client in order to consume the Package.

PR status:

  • The compiler compiles correctly (some items are still left as todo!).
  • The cargo-miden extension compiles correctly
  • cargo miden build manages to compile a basic miden repository generated from cargo miden new without crashing
  • The tests are passing

Here's a list of changes that this PR introduces:

  • miden-core no longer has the diagnostics feature flag, it got removed.
  • miden-core no longer has debug_info, moved to miden-debug-types
  • LibraryPathComponent got moved from assembly to assembly-syntax
  • miden-lib got upgraded to version 0.11.0 since that's the version that uses miden-vm version 0.17.0
  • CompiledLibrary::from_dir got replaced with miden_assembly::Assembler::assemble_library_from_dir(path, ns)
  • miden_processor::Digest got replaced with miden_core::Word
  • Calls to Assembler::add_module were replaced with calls to Assembler::compile_and_link_moduels.
  • Library::exports now returns a LibraryExport rather than a QualifiedProcedureName
    • QualifiedProcedureName is a field inside LibraryExports
    • recover_wasm_cm_interfaces now returns BTreeMap<masm::QualifiedProcedureName, LibraryExport> instead of BTreeMap<masm::QualifiedProcedureName, MastNodeID>
  • PushWord now receives a WordValue instead of miden_core/crypto::Word.
    • Sidenote: These two are functionally equivalent, so maybe turning from one to the other could be added to miden-vm
  • MemAdviceProvider no longer exists, and got replaced with AdviceProvider
  • The Host trait got moved into BaseHost.
    • In host.rs, DebuggerHost implements both BaseHost and SyncHost. Some function implementations are still left as todo!()'s
    • Question: Should AsyncHost be implemented as well?
  • PackageExport now incluldes funciton signature (updated in assemble.rs).
  • SourceFile no longer has a path() method, now it's construted from like so: Path::new(source_file.uri()). Seen in breakpoint.rs. Question: Should uri.as_path() be used?
  • QUESTION: Should ResolvedLocation receive a LineNumber and ColumnNumber instead of two u32?
  • Update miden-objects to version 0.11.0
  • The VM's default MAX_CYCLES changed from u32::max to 536870912 (1 << 29 )
  • The code produced in the array.masm test changed with the following diff: (this also happened to multiple other tests)
    -     push.2552035692683956824
    -     push.5323511717551755022
    -     push.6168074652703322390 
    -     push.2298154438505521656 
    +     push.[2552035692683956824,5323511717551755022,6168074652703322390,2298154438505521656]
    
    • I updated the test's expected output to the new output. Question, are these two equivalent?
  • Assembler::add_library got renamed to Assembler::link_dynamic_library

Sidenote for reference: The diff before the Cargo.lock files were included was +249 −241.

@lima-limon-inc lima-limon-inc marked this pull request as draft September 4, 2025 14:35
@lima-limon-inc lima-limon-inc changed the title wip: upgrade miden VM to 0.17 #8 wip: upgrade miden VM to 0.17 Sep 9, 2025
Comment on lines -458 to +460
match self {
Self::Executable(ref prog) => {
if matches!(mode, OutputMode::Binary) {
log::warn!(
"unable to write 'masl' output type for miden_core::Program: skipping.."
);
}
prog.write_to(writer, mode, session)
}
Self::Library(ref lib) => lib.write_to(writer, mode, session),
}
let mut writer = ByteWriterAdapter(&mut writer);
self.write_into(&mut writer);
Ok(())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sidenote: This change is not realted to the VM update itself, the integration tests pass with the previous version as well.
However, shouldn't MastArtifact's serialization function be called, instead of calling the underlying variant's serialization function. There is a slight difference in serialization, mainly the presence of the initial MagicBytes when serialized via MastArtifact.

Here's MastArtifact's serialization when there's an underlying Library:
https://github.com/0xMiden/miden-vm/blob/da78ba2ab0db3e092d063e5526c0cd3ddee7163a/package/src/package/serialization.rs#L158-L161

And here's the Library's:
https://github.com/0xMiden/miden-vm/blob/da78ba2ab0db3e092d063e5526c0cd3ddee7163a/assembly-syntax/src/library/mod.rs#L409-L428

Comment on lines +317 to +319
// WARNING: These two are equivalent, shouldn't this be a no-op?
let word = rodata.digest.as_elements();
let word_value = [word[0], word[1], word[2], word[3]];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I'm not mistaken, WordValue and Word are two equivalent structs.
Here's WordValue's definition: link
And here's Word's: link, with WORD_SIZE_FELT being 4: link

Additionally, I believe before this PR (0xMiden/miden-vm@de03313), Word was used directly.

Comment on lines 450 to 452
// QUESTION/TODO(fabrio): Should this be A LineNumber and ColumnNumber respectively?
pub line: u32,
pub col: u32,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This commit 0xMiden/miden-vm@62275e9 in version 0.17.1 introduced the LineNumber and ColumnNumber structs.
Should these be used here as well?

Comment on lines -54 to -59
// Extract and load the advice map from the forest before putting it into the store.
let advice_map = forest.advice_map();
for (digest, values) in advice_map.iter() {
let key = digest.into();
self.adv_provider.insert_into_map(key, values.clone());
}
Copy link
Contributor Author

@lima-limon-inc lima-limon-inc Sep 12, 2025

Choose a reason for hiding this comment

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

…r::assemble_library_from_dir(path, ns)

Signed-off-by: Tomas Fabrizio Orsi <[email protected]>
Signed-off-by: Tomas Fabrizio Orsi <[email protected]>
Signed-off-by: Tomas Fabrizio Orsi <[email protected]>
Signed-off-by: Tomas Fabrizio Orsi <[email protected]>
Signed-off-by: Tomas Fabrizio Orsi <[email protected]>
Signed-off-by: Tomas Fabrizio Orsi <[email protected]>
Signed-off-by: Tomas Fabrizio Orsi <[email protected]>
Signed-off-by: Tomas Fabrizio Orsi <[email protected]>
Signed-off-by: Tomas Fabrizio Orsi <[email protected]>
Signed-off-by: Tomas Fabrizio Orsi <[email protected]>
Signed-off-by: Tomas Fabrizio Orsi <[email protected]>
Signed-off-by: Tomas Fabrizio Orsi <[email protected]>
Signed-off-by: Tomas Fabrizio Orsi <[email protected]>
… underlying Lib/Prog

Signed-off-by: Tomas Fabrizio Orsi <[email protected]>
Signed-off-by: Tomas Fabrizio Orsi <[email protected]>
Signed-off-by: Tomas Fabrizio Orsi <[email protected]>
Signed-off-by: Tomas Fabrizio Orsi <[email protected]>
@lima-limon-inc lima-limon-inc force-pushed the fabrizioorsi/update-vm-0.17 branch from dcdd3e2 to 0f4f4ed Compare September 12, 2025 20:31
@lima-limon-inc lima-limon-inc marked this pull request as ready for review September 12, 2025 21:05
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.

1 participant