Add page aware implementation of an array.#7
Open
mijovic wants to merge 1 commit intocategory-labs:mainfrom
Open
Add page aware implementation of an array.#7mijovic wants to merge 1 commit intocategory-labs:mainfrom
mijovic wants to merge 1 commit intocategory-labs:mainfrom
Conversation
141acae to
f8956b9
Compare
mijovic
commented
Apr 1, 2026
Comment on lines
+9
to
+27
| /// belongs to a page via: | ||
| /// | ||
| /// page_index(slot) = slot >> 7 | ||
| /// offset(slot) = slot & 0x7F | ||
| /// | ||
| /// Once any slot on a page is accessed, all subsequent SLOAD/SSTORE on | ||
| /// that page are charged at warm cost. This library exploits that property | ||
| /// by aligning the array base to a 128-slot page boundary: | ||
| /// | ||
| /// base = and(keccak256(arr.slot), not(0x7f)) — clears low 7 bits | ||
| /// | ||
| /// base + 0 → length | ||
| /// base + 1 → arr[0] | ||
| /// base + 2 → arr[1] | ||
| /// ... | ||
| /// base + N → arr[N-1] | ||
| /// | ||
| /// Crucially, the length is stored at `base + 0` — on the same page as | ||
| /// the data — rather than at `arr.slot` (as a native Solidity array would). |
Member
There was a problem hiding this comment.
Ideally we leverage mip-8 for arrays that use second page too, giving that this optimize only when manipulating first 127 items, then it behave with cold cost on second page(as mentioned in Slack)
31072b5 to
211634e
Compare
211634e to
8200243
Compare
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.
No description provided.