-
Notifications
You must be signed in to change notification settings - Fork 106
feat: add getLeafValue procedure
#2262
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
Merged
Merged
Changes from 17 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
46143c8
feat: add Solidity<>Miden address type conversion functions
partylikeits1983 3c84da6
fix: formatting
partylikeits1983 c71d9df
refactor: rm unnecessary indirection
partylikeits1983 779ab24
refactor: use crypto util functions
partylikeits1983 a8238b6
refactor: implement suggestions & refactor
partylikeits1983 5dd9c85
refactor: update logic & comments to little endian
partylikeits1983 99bcee7
Update crates/miden-agglayer/src/utils.rs
partylikeits1983 2d0a89a
refactor: improve EthAddress representation clarity and MASM alignment
partylikeits1983 3d45e7f
refactor: simplify ethereum_address_to_account_id proc
partylikeits1983 43cbcf3
fix: clippy
partylikeits1983 049e8be
fix: lint doc check
partylikeits1983 99161e3
refactor: use u32assert2
partylikeits1983 3dc29f6
refactor: simplify from_account_id() & u32 check
partylikeits1983 4c6289d
revert: undo drop addr4 in ethereum_address_to_account_id
partylikeits1983 a5f3309
Merge branch 'ajl-solidity-type-conversions' into ajl-agglayer-get-le…
partylikeits1983 576f907
feat: init getLeafValue() test
partylikeits1983 a8e35d3
feat: implement AdviceMap key based getLeafValue procedure
partylikeits1983 a1a1c3d
Update crates/miden-agglayer/src/eth_address.rs
partylikeits1983 359b3ef
refactor: update test name
partylikeits1983 1264d24
refactor: rename to EthAddressFormat
partylikeits1983 2288c0d
refactor: rearrange EthAddressFormat
partylikeits1983 d9c309a
refactor: rename file to eth_address_format
partylikeits1983 393ee03
Merge branch 'agglayer' into ajl-solidity-type-conversions
partylikeits1983 3c3c29e
fix: update script roots
partylikeits1983 a926316
Merge branch 'ajl-solidity-type-conversions' into ajl-agglayer-get-le…
mmagician af29827
chore: pipe words to memory
mmagician d6b9954
refactor: add stack comments
partylikeits1983 f9f2d57
chore: pipe words to memory instead of manual `adv_loadw`
partylikeits1983 d61f836
refactor: deduplicate execute_program_with_default_host
partylikeits1983 d51bed1
feat: add hardcoded expected hash to test
partylikeits1983 1388770
fix: verify hash matches commitment
mmagician f200752
fix: put data under correct key in advice map
mmagician 8ebdc7b
chore: merge agglayer
partylikeits1983 1567d89
fix: rm redundant file
partylikeits1983 c1aec4d
Merge branch 'agglayer' into ajl-agglayer-get-leaf-value
partylikeits1983 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| use miden::core::crypto::hashes::keccak256 | ||
| use miden::core::word | ||
|
|
||
| # CONSTANTS | ||
| # ================================================================================================= | ||
|
|
||
| const U32_MAX=4294967295 | ||
| const TWO_POW_32=4294967296 | ||
|
|
||
| const ERR_NOT_U32="address limb is not u32" | ||
| const ERR_ADDR4_NONZERO="most-significant 4 bytes (addr4) must be zero" | ||
| const ERR_FELT_OUT_OF_FIELD="combined u64 doesn't fit in field" | ||
|
|
||
|
|
||
| # ETHEREUM ADDRESS PROCEDURES | ||
| # ================================================================================================= | ||
|
|
||
| #! Builds a single felt from two u32 limbs (little-endian limb order). | ||
| #! Conceptually, this is packing a 64-bit word (lo + (hi << 32)) into a field element. | ||
| #! This proc additionally verifies that the packed value did *not* reduce mod p by round-tripping | ||
| #! through u32split and comparing the limbs. | ||
| #! | ||
| #! Inputs: [lo, hi] | ||
| #! Outputs: [felt] | ||
| proc build_felt | ||
| # --- validate u32 limbs --- | ||
| u32assert2.err=ERR_NOT_U32 | ||
| # => [lo, hi] | ||
|
|
||
| # keep copies for the overflow check | ||
| dup.1 dup.1 | ||
| # => [lo, hi, lo, hi] | ||
|
|
||
| # felt = (hi * 2^32) + lo | ||
| swap | ||
| push.TWO_POW_32 mul | ||
| add | ||
| # => [felt, lo, hi] | ||
|
|
||
| # ensure no reduction mod p happened: | ||
| # split felt back into (hi, lo) and compare to inputs | ||
| dup u32split | ||
| # => [hi2, lo2, felt, lo, hi] | ||
|
|
||
| movup.4 assert_eq.err=ERR_FELT_OUT_OF_FIELD | ||
| # => [lo2, felt, lo] | ||
|
|
||
| movup.2 assert_eq.err=ERR_FELT_OUT_OF_FIELD | ||
| # => [felt] | ||
| end | ||
|
|
||
| #! Converts an Ethereum address (address[5] type) back into an AccountId [prefix, suffix] type. | ||
| #! | ||
| #! The Ethereum address is represented as 5 u32 limbs (20 bytes total) in *little-endian limb order*: | ||
| #! addr0 = bytes[16..19] (least-significant 4 bytes) | ||
| #! addr1 = bytes[12..15] | ||
| #! addr2 = bytes[ 8..11] | ||
| #! addr3 = bytes[ 4.. 7] | ||
| #! addr4 = bytes[ 0.. 3] (most-significant 4 bytes) | ||
| #! | ||
| #! The most-significant 4 bytes must be zero for a valid AccountId conversion (addr4 == 0). | ||
| #! The remaining 16 bytes are treated as two 8-byte words (conceptual u64 values): | ||
| #! prefix = (addr3 << 32) | addr2 # bytes[4..11] | ||
| #! suffix = (addr1 << 32) | addr0 # bytes[12..19] | ||
| #! | ||
| #! These 8-byte words are represented as field elements by packing two u32 limbs into a felt. | ||
| #! The packing is done via build_felt, which validates limbs are u32 and checks the packed value | ||
| #! did not reduce mod p (i.e. the word fits in the field). | ||
| #! | ||
| #! Inputs: [addr0, addr1, addr2, addr3, addr4] | ||
| #! Outputs: [prefix, suffix] | ||
| #! | ||
| #! Invocation: exec | ||
| pub proc ethereum_address_to_account_id | ||
| # addr4 must be 0 (most-significant limb) | ||
| movup.4 | ||
| eq.0 assert.err=ERR_ADDR4_NONZERO | ||
| # => [addr0, addr1, addr2, addr3] | ||
|
|
||
| exec.build_felt | ||
| # => [suffix, addr2, addr3] | ||
|
|
||
| movdn.2 | ||
| # => [addr2, addr3, suffix] | ||
|
|
||
| exec.build_felt | ||
| # => [prefix, suffix] | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.