Skip to content

Conversation

@partylikeits1983
Copy link
Contributor

Asset Conversion Procedure Overview

This PR adds the functionality for converting between asset amounts with various decimals for Agglayer bridging operations.

Note:
Resolves: #2011

The convert_to_u256_scaled procedure converts Miden amounts to Agglayer compatible u256 format for bridging to agglayer chains.

@partylikeits1983 partylikeits1983 added the no changelog This PR does not require an entry in the `CHANGELOG.md` file label Dec 5, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements asset conversion functionality for Agglayer bridging operations, specifically adding a procedure to convert Miden asset amounts to U256 format with decimal scaling. The implementation includes a MASM procedure for computing scaled U256 values and Rust utilities for testing and integration.

Key changes:

  • Adds convert_to_u256_scaled MASM procedure to scale asset amounts by powers of 10 and convert to U256 format
  • Implements helper utilities for converting between Felt and U256 byte representations
  • Provides comprehensive test coverage with two test cases validating scaling operations

Reviewed changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
crates/miden-lib/asm/agglayer/account_components/asset_conversion.masm Core MASM implementation with pow10 helper and convert_to_u256_scaled procedure for asset scaling
crates/miden-lib/src/agglayer/mod.rs Module definition providing asset conversion library initialization and component creation
crates/miden-lib/src/agglayer/utils.rs Utility functions for converting between Felt values and U256 byte representations
crates/miden-testing/tests/agglayer/asset_conversion.rs Test suite validating asset conversion with ETH and large amount scenarios
crates/miden-testing/tests/agglayer/mod.rs Module declaration for agglayer tests
crates/miden-testing/tests/lib.rs Adds agglayer test module to test suite
crates/miden-lib/src/lib.rs Exposes agglayer module for testing/test features
crates/miden-lib/build.rs Extends build script to compile agglayer account components
crates/miden-testing/Cargo.toml Adds primitive-types dependency for U256 support in tests
Cargo.toml Adds primitive-types to workspace dependencies
Cargo.lock Locks new dependencies (primitive-types, byteorder, fixed-hash, hex, uint, static_assertions)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

partylikeits1983 and others added 7 commits December 5, 2025 14:24
…ion.masm

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ion.masm

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ion.masm

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@partylikeits1983 partylikeits1983 marked this pull request as ready for review December 5, 2025 17:50
@partylikeits1983 partylikeits1983 self-assigned this Dec 5, 2025
@partylikeits1983 partylikeits1983 changed the title feat: implement u256 agglayer asset scaling procedure feat: implement u256 agglayer asset scaling up procedure Dec 9, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 12 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@partylikeits1983
Copy link
Contributor Author

Renamed this PR to "feat: implement u256 agglayer asset scaling up procedure" since I think we should implement scaling down in a separate PR.

tokio = { default-features = false, features = ["sync"], version = "1" }
anyhow = { default-features = false, features = ["backtrace", "std"], version = "1.0" }
assert_matches = { default-features = false, version = "1.5" }
primitive-types = { default-features = false, version = "0.14" }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Importing U256 type.

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 left a few comments inline - the main one is about using u64 multiplication to make the procedure much more efficient.

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 left a few more comments inline.

@partylikeits1983
Copy link
Contributor Author

Changed felts_to_u256_bytes return type from Vec<u8> to [u8; 32] and updated it to accept little-endian input order. Updated asset_conversion.masm to output U256 results in little-endian format and fixed stack comments to properly document intermediate values. Updated corresponding tests to match the new little-endian behavior across both Rust and MASM.

I think this is ready to merge @bobbinth @mmagician

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.

All looks good! Thank you!

@bobbinth bobbinth merged commit cb885a8 into agglayer Dec 15, 2025
15 checks passed
@bobbinth bobbinth deleted the ajl-asset-conversion-agglayer branch December 15, 2025 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agglayer no changelog This PR does not require an entry in the `CHANGELOG.md` file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants