Skip to content

feat: migrate miden-agglayer to VM 0.21 and crypto 0.22#2546

Merged
mmagician merged 33 commits intonextfrom
mmagician-claude/migrate-agglayer
Mar 11, 2026
Merged

feat: migrate miden-agglayer to VM 0.21 and crypto 0.22#2546
mmagician merged 33 commits intonextfrom
mmagician-claude/migrate-agglayer

Conversation

@mmagician
Copy link
Collaborator

@mmagician mmagician commented Mar 4, 2026

Summary

  • Re-enables the miden-agglayer crate in the workspace (was commented out during the VM 0.21 migration)
  • Applies all Rust API changes: FieldElement removal, as_int() -> as_canonical_u64(), serde trait path changes, Program import path, bytes_to_packed_u32_elements rename, AccountId constructor update
  • Migrates MASM from RPO256 to Poseidon2 hash function
  • Updates MASM for LE convention: u64::widening_mul, rewritten u128_sub_no_underflow, updated verify_u128_to_native_amount_conversion
  • Renames asset::mem_store/mem_load to asset::store/load
  • Fixes eth_address.masm build_felt u32split verification for LE output order
  • Fixes create_burn_note note_idx corruption (pre-existing bug: loc_loadw_be destroyed both copies from dup; now uses local variable)
  • Fixes Word element ordering for bridge admin, GER manager, faucet registry keys, and conversion metadata (LE convention)
  • Fixes canonical zeros generation and MMR frontier memory operations for LE convention
  • Re-enables and migrates all 39 agglayer integration tests in miden-testing

Test plan

  • cargo clippy -p miden-agglayer --all-features -- -D warnings passes
  • All 39 agglayer tests pass (cargo nextest run -p miden-testing -E 'test(agglayer)')
  • Full test suite passes: 697 tests, 0 failures (make test-dev)

🤖 Generated with Claude Code

Re-enable the miden-agglayer crate in the workspace and apply all
necessary API and convention changes from the VM 0.21 migration:

Rust changes:
- Remove FieldElement trait imports (removed from miden-core)
- Felt::as_int() -> Felt::as_canonical_u64()
- Program import moved to miden_core::program::Program
- bytes_to_packed_u32_felts -> bytes_to_packed_u32_elements (miden_core::utils)
- AccountId::try_from([Felt;2]) -> AccountId::try_from_elements(suffix, prefix)
- Serializable/Deserializable from miden_assembly::serde (was ::utils)

MASM changes:
- rpo256 -> poseidon2 (hash function migration)
- asset::mem_store/mem_load -> asset::store/load (procedure renames)
- u64::overflowing_mul -> u64::widening_mul
- u128_sub_no_underflow rewritten for LE convention (u64 procedures
  now use [lo, hi] input/output order)
- verify_u128_to_native_amount_conversion updated for LE result order

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mmagician mmagician marked this pull request as draft March 4, 2026 17:13
Re-enable agglayer tests in miden-testing and fix all compilation
and runtime errors from the VM 0.21 migration:

Test compilation fixes:
- FieldElement import removal, as_int -> as_canonical_u64
- AuthScheme::Falcon512Rpo -> Falcon512Poseidon2
- AdviceInputs path: miden_processor::advice::AdviceInputs
- FastProcessor::new_debug -> new().with_advice().with_debugging()
- StackInputs::new(vec![]) -> new(&[])
- bytes_to_packed_u32_felts -> bytes_to_packed_u32_elements
- AccountId::try_from -> try_from_elements

MASM runtime fixes:
- eth_address.masm: fix u32split LE output order in build_felt
  verification (movup.4 -> movup.3 for lo/hi comparison)
- bridge_out.masm: fix create_burn_note note_idx corruption -
  loc_loadw_be overwrites top 4 stack elements including both
  copies from dup; save note_idx to local instead (pre-existing
  bug that only manifested with multiple output notes)
- bridge_out.masm: fix num_leaves storage LE ordering - push
  new_leaf_count to stack top for Word[0] storage, use
  mem_storew_le instead of mem_storew_be for loading
- bridge_config.masm: update GER hash from Rpo256 to Poseidon2
- canonical_zeros: remove .rev() from build.rs generation, swap
  push order for LE memory layout
- Word element ordering fixes for bridge admin, GER manager,
  faucet registry keys, and conversion metadata

Test expectation fixes:
- Rpo256 -> Poseidon2 for GER hash computation
- Removed word reversal in root/proof reading (LE convention)
- Fixed expected storage value ordering
- mem_storew_be -> mem_storew_le in test MASM code

All 39 agglayer tests pass.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mmagician mmagician added the no changelog This PR does not require an entry in the `CHANGELOG.md` file label Mar 4, 2026
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
# Arrange args for u64::overflowing_sub as:
# [y1, y0, x1, x0]
# Low 64 bits: (x0,x1) - (y0,y1)
# Arrange args for u64::overflowing_sub (LE convention) as:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

did overflowing_sub change its expected inputs?
clarify, and as before, if docs are wrong, update the docs in the relevant repo

- Extract `create_id_key(id: AccountId) -> Word` helper and reuse for
  bridge_admin, ger_manager, bridge_account_id, and faucet_registry_key
- Replace `felts_to_bytes` with re-export of `packed_u32_elements_to_bytes`
  from miden-core (identical implementation)
- Remove stale comment in config_note.rs
- Use `Felt::ONE` instead of `Felt::new(1)` in config_bridge test
- Add TODO comments referencing issue #2548 for getter helpers
- Simplify note_idx handling: use `padw` before `loc_loadw_le` instead of
  saving to a local variable; revert @Locals(15) to @Locals(14)
- Switch `loc_storew_be`/`loc_loadw_be` to `_le` variants in create_burn_note
- Add stack state comments before third overflowing_sub in u128_sub_no_underflow

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mmagician mmagician force-pushed the mmagician-claude/migrate-agglayer branch from 87cc819 to b1a0b6f Compare March 5, 2026 15:35
@mmagician mmagician marked this pull request as ready for review March 5, 2026 15:40
Copy link
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.

Review in progress, left some questions.

claude and others added 2 commits March 6, 2026 11:32
Add convention to masm_doc_comment_fmt.md:
- `value` = single felt
- `value(N)` = N felts (non-word)
- `VALUE` = word (4 felts, no (4) suffix needed)

Apply throughout agglayer MASM: drop redundant (4) from ASSET_KEY,
ASSET_VALUE, SERIAL_NUM, SCRIPT_ROOT, RECIPIENT, NOTE_ATTACHMENT,
PROC_MAST_ROOT, OLD_VALUE, VALUE, U256_LO, U256_HI.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
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.

Left a few comments regarding the big-endian -> little-endian migration.

@mmagician mmagician added the pr-from-maintainers PRs that come from internal contributors or integration partners. They should be given priority label Mar 9, 2026
@mmagician mmagician force-pushed the mmagician-claude/migrate-agglayer branch from 4339785 to 05ae95c Compare March 9, 2026 12:21
mmagician and others added 5 commits March 9, 2026 12:59
Change GER_KNOWN_FLAG and IS_FAUCET_REGISTERED_FLAG to be stored at
word[0] instead of word[3]. Under LE, `push.0.0.0.FLAG` puts FLAG at
stack top = word[0], matching the documented layout [1, 0, 0, 0].

Previously `push.FLAG.0.0.0` placed FLAG at stack bottom = word[3],
resulting in Word([0, 0, 0, 1]) which contradicted the docs.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
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 to me!

There is one TODO(bele) that would be good to do in this PR in scripts/check-features.sh.

Copy link
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 focused mostly on non-test code and left just one comment inline (and also pushed a couple of small commits).

Once @PhilippGackstatter's comments are addressed, this should be good to merge.

mmagician and others added 5 commits March 11, 2026 09:04
Now that miden-agglayer has been migrated, add it back to the
check-features.sh loop.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
All other bridge/faucet MASM procedures use [suffix, prefix] (suffix on
top) for account IDs on the stack. Align to_account_id with this
convention by adding a swap at the end, and update all callers:
- faucet/mod.masm: update get_destination_account_id_data, claim, and
  build_p2id_output_note to handle the new stack order
- solidity_miden_address_conversion test: swap stack index expectations

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mmagician mmagician enabled auto-merge (squash) March 11, 2026 10:19
@mmagician mmagician disabled auto-merge March 11, 2026 10:20
@mmagician mmagician merged commit 69f0c9e into next Mar 11, 2026
17 checks passed
@mmagician mmagician deleted the mmagician-claude/migrate-agglayer branch March 11, 2026 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no changelog This PR does not require an entry in the `CHANGELOG.md` file pr-from-maintainers PRs that come from internal contributors or integration partners. They should be given priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants