Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to miden-vm v0.10 #826

Merged
merged 6 commits into from
Aug 23, 2024
Merged

Migrate to miden-vm v0.10 #826

merged 6 commits into from
Aug 23, 2024

Conversation

bobbinth
Copy link
Contributor

@bobbinth bobbinth commented Aug 11, 2024

This PR migrates miden-base crates to miden-vm v0.10.

Here is a high-level summary of changes:

miden-objects:

  • AccountCode, NoteScript, and TransactionScript are now backed by MastForest (i.e., compiled MASM code) and so, no longer need an assembler to be instantiated. I did add compile() constructors to these so that they can be instantiated from source code as well.
  • ExecutedTransaction and TransactionWitness no longer need to have the Program field. This is because the program executed is the same for all transactions (it is the main procedure of the transaction kernel).
  • Removed PreparedTransaction as it is no longer needed.

miden-lib

  • All source MASM code is now compiled into MAST at build time. So, once we build the kernel, the library, and the note scripts, there is no need to use assembler for them again.
  • MASM modules under asm/miden/kernels/tx have been moved to asm/kernels/transaction/lib to indicate that these modules are relevant to the transaction kernel and not miden-lib itself. There were a couple of procedures that I had to duplicate because of this move. We'll figure out how to avoid this duplication in a future PR.
  • I inserted dummy instructions push.<random value> drop next to some advice injectors to make MAST nodes hash to unique values. This is a temporary workaround to avoid collisions of MAST nodes which differ only in their use of decorators. I'll create an issue in miden-vm for how this should be resolved properly.

miden-tx

  • TransactionCompiler has been replaced with TransactionMastStore. I haven't deleted yet the TransactionCompiler file because some logic still needs to be transferred to the TransactionMastStore. And generally, I need to document TransactionMastStore and maybe refactor it a bit.
  • TransactionExecutor now loads note/tx script into the MAST store before executing a transaction. The MAST store is then passed to the TransactionHost which serves requests from the VM for programs matching a given MAST root. TransactionProver works in a similar way.
  • I removed DataStore::get_account_code() method as we get all relevant info from DataStore::get_transaction_inputs() now.

bench-tx

  • I disabled this crate for now as it relies on the removed PreparedTransaction struct. This will need to be refactored in a subsequent PR.

@bobbinth bobbinth linked an issue Aug 11, 2024 that may be closed by this pull request
@bobbinth
Copy link
Contributor Author

This is not yet fully finished, but I'm opening it up for review because I got the p2id_script_multiple_assets test to pass and so things are mostly working though I do need to clean things up quite a bit and also refactor a few things in miden-tx. See PR description for the current state of things.

@bobbinth
Copy link
Contributor Author

I'm marking this as "ready for review" as I think most of the migration is complete. A few notes:

  1. All integration tests are currently passing locally - but I've disabled all "kernel tests" because the structure there needs to be updated. It is possible that once we enable kernel tests, we'll discover some additional bugs, but given that all integration tests are passing, I think the bugs should be fairly small. It may make sense to rebase #807 from this PR, get the kernel tests passing, and only after that merge this PR. @igamigo - could you take a look at this?
  2. Some of the integration tests are timing out in the CI because execution/proving times have roughly doubled. This is because we've disabled inlining in current assembler. I'm hoping that this is going to be partially fixed by 0xPolygonMiden/miden-vm#1454, but I think this degradation won't go away until we bring back full procedure inlining.
  3. Would be great to confirm the above by running transaction benchmarks. But I've disabled bench-tx crate for now. @Fumuran - could you open a PR based on this one to re-enable it? Once this is done, we can see how cycle counts have changed as compared to what we had before.

A few other things:

  • With the removal of TransactionCompiler, we've lost one nice feature: performing "soft checks" on whether a given note/tx script can be executed against an account. I'll create an issue describing how to bring this functionality back.
  • I still need to document TransactionMastStore - but this should be pretty straight-forward. One idea I tried to implement is trying to combine TransactionMastStore and DataStore into a single interface - but this turned out to be a much bigger change, and I decided to leave it for future PRs.
  • I still need to create an issue in the miden-vm repo about how to properly handle collision between MAST nodes which differ only in their use of decorators.

@bobbinth bobbinth marked this pull request as ready for review August 16, 2024 10:16
Copy link
Contributor

@plafer plafer left a comment

Choose a reason for hiding this comment

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

LGTM - at least the parts that touch the changes to the VM

@bobbinth
Copy link
Contributor Author

LGTM - at least the parts that touch the changes to the VM

btw, I ended up wrapping all MastForests in Arc (e.g., here). I think we can do something similar for Library and Program structs in miden-vm (could be just a small PR before we do some deeper refactorings).

Copy link
Contributor

@phklive phklive left a comment

Choose a reason for hiding this comment

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

LGTM, focused mainly on the MASM changes considering that @plafer focused on the VM side.

All tests passed locally, tests in CI are failing because of timeout ( should be fixed by updating the nextest timeout rules):
SCR-20240819-nliu
SCR-20240819-nlgw

Increase of 121.39% in testing time with the new assembler or we could say a decrease of 54.84% in performance.

We should run make lint to make sure we pass the fmt ci checks.

Left a few simple questions.

@@ -232,3 +232,58 @@ export.get_vault_commitment
syscall.get_account_vault_commitment
# => [COM]
end

# PROCEDURES COPIED FROM KERNEL (TODO: get rid of this duplication)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did we need to copy paste some code from the Kernel?

@phklive
Copy link
Contributor

phklive commented Aug 19, 2024

@bobbinth I have tried reading about it throughout the repo (issues, pr's, discussions) could you clarify what is a "decorator" in the context of MASM and why we need them?

@bobbinth
Copy link
Contributor Author

@bobbinth I have tried reading about it throughout the repo (issues, pr's, discussions) could you clarify what is a "decorator" in the context of MASM and why we need them?

As discussed offline, decorators are special instructions which do not affect the internal VM state (i.e., memory or stack). They are used primarily for two purposes:

  1. Update the state of the advice provider (i.e., advice injectors).
  2. Annotate VM operations, mostly for debugging purposes (e.g., the debug decorator).

bobbinth and others added 3 commits August 22, 2024 19:47
refactor: implement compilation of miden-lib MASM files

chore: fix miden-lib compilation

chore: make miden-tx crate compile

feat: add conversion for `NoteExecutionHint` (#827)

* feat: Add conversion for NoteExecutionHint

* Conversion and changelog

* Conversion

* Add test

* Rectify comment

chore: update miden-vm dependencies to crates.io versions

chore: refactor execute_transaction()

chore: remove unused TransactionCompiler
* refactor: use maps in storage and vault deltas

* docs: update CHANGELOG.md

* refactor: address review comments

* tests: fix compilation errors

* refactor: address review comments

* refactor: address review comments
* feat: High level mockchain methods; re-enable and fix kernel tests
@bobbinth bobbinth force-pushed the bobbin-miden-vm-migration branch from e78efd1 to 9631e8a Compare August 23, 2024 02:49
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.

Migrate to the MAST structure and forget MASM
5 participants