feat(AggLayer claim e2e #3): GlobalIndex wrapper#2407
Merged
mmagician merged 3 commits intoagglayer-newfrom Feb 14, 2026
Merged
feat(AggLayer claim e2e #3): GlobalIndex wrapper#2407mmagician merged 3 commits intoagglayer-newfrom
GlobalIndex wrapper#2407mmagician merged 3 commits intoagglayer-newfrom
Conversation
049a4f6 to
e80e7ea
Compare
18439d5 to
be2e67a
Compare
19cb775 to
778b6e7
Compare
GlobalIndex wrapperGlobalIndex wrapper
mmagician
commented
Feb 8, 2026
partylikeits1983
approved these changes
Feb 13, 2026
Contributor
partylikeits1983
left a comment
There was a problem hiding this comment.
Looks great! Makes sense to store GlobalIndex in Rust as [u8; 32] and in the VM [u32; 8].
Comment on lines
+22
to
+36
| // ================================================================================================ | ||
| // GLOBAL INDEX | ||
| // ================================================================================================ | ||
|
|
||
| /// Represents an AggLayer global index as a 256-bit value (32 bytes). | ||
| /// | ||
| /// The global index is a uint256 that encodes (from MSB to LSB): | ||
| /// - Top 160 bits (limbs 0-4): must be zero | ||
| /// - 32 bits (limb 5): mainnet flag (value = 1 for mainnet, 0 for rollup) | ||
| /// - 32 bits (limb 6): rollup index (must be 0 for mainnet deposits) | ||
| /// - 32 bits (limb 7): leaf index (deposit index in the local exit tree) | ||
| /// | ||
| /// Bytes are stored in big-endian order, matching Solidity's uint256 representation. | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
| pub struct GlobalIndex([u8; 32]); |
Contributor
There was a problem hiding this comment.
I think I can follow this same type of layout for implementing theu256 type for the u256 to Felt scaling PR: #2331
b658ab6 to
ea8d6d7
Compare
12c5dda to
df775f2
Compare
bobbinth
reviewed
Feb 16, 2026
Comment on lines
+48
to
+59
| /// Creates a new [`GlobalIndex`] from a 32-byte array (big-endian). | ||
| pub fn new(bytes: [u8; 32]) -> Self { | ||
| Self(bytes) | ||
| } | ||
|
|
||
| /// Validates that this is a valid mainnet deposit global index. | ||
| /// | ||
| /// Checks that: | ||
| /// - The top 160 bits (limbs 0-4, bytes 0-19) are zero | ||
| /// - The mainnet flag (limb 5, bytes 20-23) is exactly 1 | ||
| /// - The rollup index (limb 6, bytes 24-27) is 0 | ||
| pub fn validate_mainnet(&self) -> Result<(), GlobalIndexError> { |
Contributor
There was a problem hiding this comment.
Would it make sense to change this into a constructor - e.g., something like:
pub fn new_mainnet(bytes: [u8; 32]) -> Result<Self, GlobalIndexError> {
...
}
bobbinth
reviewed
Feb 16, 2026
Comment on lines
+43
to
+46
| pub fn from_hex(hex_str: &str) -> Result<Self, HexParseError> { | ||
| let bytes: [u8; 32] = hex_to_bytes(hex_str)?; | ||
| Ok(Self(bytes)) | ||
| } |
Contributor
There was a problem hiding this comment.
Should we do more validation here? We could return GlobalIndexError and hex parsing could be one reason to return an error. Other reasons would be if the global index is malformed.
The general idea is to enforce that if we have GlobalIndex struct, we know the underlying index is correctly formed.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
[u32; 8]to[u8; 32]so that it's easier to construct from raw bytes coming in from Ethereum tx's,GlobalIndexstructmainnet_flag,leaf_indexeasier, we reverse to BE order before processingswap_u32_bytesto a sharedutillocation