-
Notifications
You must be signed in to change notification settings - Fork 122
Compute claimed global index chain hash #2516
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
Open
Fumuran
wants to merge
13
commits into
ajl-reorient-claim-note-flow
Choose a base branch
from
andrew-compute-cgi-chain-hash
base: ajl-reorient-claim-note-flow
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a0d43bf
feat: add CGI chain hash computation
Fumuran 1e5f5aa
test: [WiP-1] first iteration, not building
Fumuran 8c3dcdf
test: [WiP-2] building state
Fumuran 5f707de
test: updated script, failing
Fumuran 558257d
test: update script (passing)
Fumuran ef477d5
refactor: create ctorage slots for CGI chain hash, use actiual proced…
Fumuran 2d5149b
Merge branch 'ajl-reorient-claim-note-flow' into andrew-compute-cgi-c…
Fumuran 3ec49db
Merge branch 'ajl-reorient-claim-note-flow' into andrew-compute-cgi-c…
Fumuran 38e6ea1
refactor: incapsulate CGI hash computation
Fumuran 9892099
test: update solidity contracts to generate CGI chain hash. Test is f…
Fumuran 9e015fe
Merge branch 'ajl-reorient-claim-note-flow' into andrew-compute-cgi-c…
Fumuran 877b06a
test: fix bug, test is passing
Fumuran a40feb9
chore: fix doc format
Fumuran 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
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 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -14,6 +14,8 @@ use miden::protocol::output_note::ATTACHMENT_KIND_NONE | |||||||||
| use miden::protocol::tx | ||||||||||
| use miden::standards::note_tag | ||||||||||
| use miden::standards::attachments::network_account_target | ||||||||||
| use miden::protocol::native_account | ||||||||||
| use miden::protocol::active_account | ||||||||||
| use miden::standards::note::execution_hint::ALWAYS | ||||||||||
|
|
||||||||||
| # TYPE ALIASES | ||||||||||
|
|
@@ -35,6 +37,14 @@ const ERR_INVALID_CLAIM_PROOF = "invalid claim proof" | |||||||||
| # CONSTANTS | ||||||||||
| # ================================================================================================= | ||||||||||
|
|
||||||||||
| # Storage slots | ||||||||||
| # ------------------------------------------------------------------------------------------------- | ||||||||||
|
|
||||||||||
| # Storage slot constants for the CGI (claimed global index) chain hash. | ||||||||||
| # It is stored in two separate value slots. | ||||||||||
| const CGI_CHAIN_HASH_LO_SLOT_NAME = word("miden::agglayer::bridge::cgi_chain_hash_lo") | ||||||||||
| const CGI_CHAIN_HASH_HI_SLOT_NAME = word("miden::agglayer::bridge::cgi_chain_hash_hi") | ||||||||||
|
|
||||||||||
| # Data sizes | ||||||||||
| # ------------------------------------------------------------------------------------------------- | ||||||||||
|
|
||||||||||
|
|
@@ -167,6 +177,7 @@ const CREATE_MINT_FAUCET_SUFFIX_LOC = 1 | |||||||||
| #! - the Merkle proof for the provided leaf-index tuple against the computed GER is invalid. | ||||||||||
| #! | ||||||||||
| #! Invocation: call | ||||||||||
| @locals(8) # leaf value | ||||||||||
| pub proc verify_leaf_bridge | ||||||||||
| # get the leaf value. We have all the necessary leaf data in the advice map | ||||||||||
| exec.get_leaf_value | ||||||||||
|
|
@@ -175,9 +186,23 @@ pub proc verify_leaf_bridge | |||||||||
| movupw.3 dropw | ||||||||||
| # => [LEAF_VALUE[8], PROOF_DATA_KEY, pad(4)] | ||||||||||
|
|
||||||||||
| # save the leaf value to the local memory to reuse it during the computation of the CGI chain | ||||||||||
| # hash | ||||||||||
|
Comment on lines
+189
to
+190
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit:
Suggested change
|
||||||||||
| loc_storew_le.0 swapw | ||||||||||
| loc_storew_le.4 swapw | ||||||||||
| # => [LEAF_VALUE[8], PROOF_DATA_KEY, pad(4)] | ||||||||||
|
|
||||||||||
| # delegate proof verification | ||||||||||
| exec.verify_leaf | ||||||||||
| # => [pad(16)] | ||||||||||
|
|
||||||||||
| # load the pointer to the leaf value back to the stack | ||||||||||
| locaddr.0 | ||||||||||
| # => [leaf_value_ptr, pad(16)] | ||||||||||
|
|
||||||||||
| # update the CGI chain hash | ||||||||||
| exec.update_cgi_chain_hash | ||||||||||
| # => [pad(16)] | ||||||||||
| end | ||||||||||
|
|
||||||||||
| #! Assert the global index is valid for a mainnet deposit. | ||||||||||
|
|
@@ -468,8 +493,7 @@ proc verify_leaf | |||||||||
| # => [LEAF_VALUE[8]] | ||||||||||
|
|
||||||||||
| # 3. load global index from memory | ||||||||||
| padw mem_loadw_le.GLOBAL_INDEX_PTR | ||||||||||
| padw push.GLOBAL_INDEX_PTR add.4 mem_loadw_le swapw | ||||||||||
| push.GLOBAL_INDEX_PTR exec.utils::mem_load_double_word | ||||||||||
mmagician marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
| # => [GLOBAL_INDEX[8], LEAF_VALUE[8]] | ||||||||||
|
|
||||||||||
| # to see if we're dealing with a deposit from mainnet or from a rollup, process the global index | ||||||||||
|
|
@@ -830,3 +854,73 @@ proc calculate_root( | |||||||||
| padw loc_loadw_le.CUR_HASH_HI_LOCAL padw loc_loadw_le.CUR_HASH_LO_LOCAL | ||||||||||
| # => [ROOT_LO, ROOT_HI] | ||||||||||
| end | ||||||||||
|
|
||||||||||
| #! Updates the claimed global index (CGI) chain hash by recomputing it and storing into the | ||||||||||
| #! corresponding storage slot. | ||||||||||
| #! | ||||||||||
| #! The resulting hash is computed as a sequential hash of leaf value, global index, and previous | ||||||||||
| #! value of the CGI chain hash: | ||||||||||
| #! NEW_CGI_CHAIN_HASH[8] = Keccak256(OLD_CGI_CHAIN_HASH[8], Keccak256(GLOBAL_INDEX[8], LEAF_VALUE[8])) | ||||||||||
| #! | ||||||||||
| #! Inputs: [leaf_value_ptr] | ||||||||||
| #! Outputs: [] | ||||||||||
| #! | ||||||||||
| #! Invocation: exec | ||||||||||
| proc update_cgi_chain_hash | ||||||||||
| # load the required CGI chain data values onto the stack | ||||||||||
| exec.load_cgi_chain_hash_data | ||||||||||
| # => [GLOBAL_INDEX[8], LEAF_VALUE[8], OLD_CGI_CHAIN_HASH[8]] | ||||||||||
|
|
||||||||||
| # compute the new CGI chain hash | ||||||||||
| exec.keccak256::merge swapdw | ||||||||||
| # => [OLD_CGI_CHAIN_HASH[8], Keccak256(GLOBAL_INDEX, LEAF_VALUE)] | ||||||||||
|
|
||||||||||
| exec.keccak256::merge | ||||||||||
| # => [NEW_CGI_CHAIN_HASH[8]] | ||||||||||
|
|
||||||||||
| # store the new CGI chain hash | ||||||||||
| exec.store_cgi_chain_hash | ||||||||||
| # => [] | ||||||||||
| end | ||||||||||
|
|
||||||||||
| #! Loads the old CGI chain hash, the leaf value, and the global index onto the stack as a | ||||||||||
| #! preparation for the new CGI chain hash computation. | ||||||||||
| #! | ||||||||||
| #! Inputs: [leaf_value_ptr] | ||||||||||
| #! Outputs: [GLOBAL_INDEX[8], LEAF_VALUE[8], OLD_CGI_CHAIN_HASH[8]] | ||||||||||
| #! | ||||||||||
| #! Invocation: exec | ||||||||||
| proc load_cgi_chain_hash_data | ||||||||||
| # load the old CGI chain hash onto the stack | ||||||||||
| push.CGI_CHAIN_HASH_HI_SLOT_NAME[0..2] | ||||||||||
| exec.active_account::get_item | ||||||||||
| # => [OLD_CGI_CHAIN_HASH_HI, leaf_value_ptr] | ||||||||||
|
|
||||||||||
| push.CGI_CHAIN_HASH_LO_SLOT_NAME[0..2] | ||||||||||
| exec.active_account::get_item | ||||||||||
| # => [OLD_CGI_CHAIN_HASH[8], leaf_value_ptr] | ||||||||||
|
|
||||||||||
| # load the leaf value onto the stack | ||||||||||
| movup.8 exec.utils::mem_load_double_word | ||||||||||
| # => [LEAF_VALUE[8], OLD_CGI_CHAIN_HASH[8]] | ||||||||||
|
|
||||||||||
| # load the global index onto the stack | ||||||||||
| push.GLOBAL_INDEX_PTR exec.utils::mem_load_double_word | ||||||||||
| # => [GLOBAL_INDEX[8], LEAF_VALUE[8], OLD_CGI_CHAIN_HASH[8]] | ||||||||||
| end | ||||||||||
|
|
||||||||||
| #! Stores the computed global index (CGI) chain hash into the corresponding storage slots. | ||||||||||
| #! | ||||||||||
| #! Inputs: [NEW_CGI_CHAIN_HASH_LO, NEW_CGI_CHAIN_HASH_HI] | ||||||||||
| #! Outputs: [] | ||||||||||
| #! | ||||||||||
| #! Invocation: exec | ||||||||||
| proc store_cgi_chain_hash | ||||||||||
| push.CGI_CHAIN_HASH_LO_SLOT_NAME[0..2] | ||||||||||
| exec.native_account::set_item dropw | ||||||||||
| # => [NEW_CGI_CHAIN_HASH_HI] | ||||||||||
|
|
||||||||||
| push.CGI_CHAIN_HASH_HI_SLOT_NAME[0..2] | ||||||||||
| exec.native_account::set_item dropw | ||||||||||
| # => [] | ||||||||||
| 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
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
1 change: 1 addition & 0 deletions
1
crates/miden-agglayer/solidity-compat/lib/openzeppelin-contracts
Submodule openzeppelin-contracts
added at
dbb610
1 change: 1 addition & 0 deletions
1
crates/miden-agglayer/solidity-compat/lib/openzeppelin-contracts-upgradeable5
Submodule openzeppelin-contracts-upgradeable5
added at
723f8c
3 changes: 2 additions & 1 deletion
3
crates/miden-agglayer/solidity-compat/test-vectors/claim_asset_vectors_local_tx.json
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
1 change: 1 addition & 0 deletions
1
crates/miden-agglayer/solidity-compat/test-vectors/claim_asset_vectors_real_tx.json
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: it seems we have a v4 and v5 of the same submodule, is it possible to just have the latest version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like some of the contracts which we use have both v5 and v4 dependencies. I struggled a few hours to make it work, and AFAIU, it is the only configuration which makes it possible. Removing any of them results in a compilation error.