Add MIP-8 page commit tests.#27
Conversation
| ) -> None: | ||
| """``storage_root_paged`` matches a keccak-MPT built by hand. | ||
|
|
||
| Cross-checks the trie-assembly layer for a single page (page 0): slot | ||
| grouping, the ``keccak256(page_index)`` trie key, and the | ||
| ``rlp.encode(commitment)`` leaf framing — independently of the BLAKE3 | ||
| internals of ``page_commit``. | ||
| """ | ||
| commitment = page_commit(_page(slot_values)) | ||
| key = keccak256(U256(0).to_be_bytes32()) | ||
| obj = {bytes_to_nibble_list(key): rlp.encode(commitment)} | ||
|
|
||
| root_node = encode_internal_node(patricialize(obj, Uint(0))) | ||
| encoded = rlp.encode(root_node) | ||
| expected = keccak256(encoded) if len(encoded) < 32 else Hash32(root_node) | ||
|
|
||
| assert storage_root_paged(_storage(slot_values)) == expected |
There was a problem hiding this comment.
if len(encoded) < 32 branch is dead for all parametrized cases
For a single-page leaf the MPT root_node encodes to a [hex-prefix-path, rlp(commitment)] structure where the path alone is 33 bytes (0x20 || 32-byte keccak key) and the value is 33 bytes. rlp.encode(root_node) is therefore always well above 32 bytes, so the keccak256(encoded) path on line 200 is never exercised by this test. The assertion on line 203 ends up testing only the else / Hash32(root_node) branch. This is consistent with what the production code does for these inputs, but if the threshold condition was accidentally inverted in either place the test would not catch it.
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/testing/src/execution_testing/forks/tests/test_paged_storage_trie.py
Line: 187-203
Comment:
**`if len(encoded) < 32` branch is dead for all parametrized cases**
For a single-page leaf the MPT `root_node` encodes to a `[hex-prefix-path, rlp(commitment)]` structure where the path alone is 33 bytes (`0x20` || 32-byte keccak key) and the value is 33 bytes. `rlp.encode(root_node)` is therefore always well above 32 bytes, so the `keccak256(encoded)` path on line 200 is never exercised by this test. The assertion on line 203 ends up testing only the `else` / `Hash32(root_node)` branch. This is consistent with what the production code does for these inputs, but if the threshold condition was accidentally inverted in either place the test would not catch it.
How can I resolve this? If you propose a fix, please make it concise.083df74 to
a7da928
Compare
pdobacz
left a comment
There was a problem hiding this comment.
LGTM, this is a great addition to the tests of the mEELS implementation of MIP-8, but note it is not a new spec test (the remaining 3 points from your list you've sent me seem to be new spec tests)
|
the CI failure, seems like it needs a formatter run: is my go-to line for this to check afterwards |
Co-Authored-By: Claude claude-fable-5
ba4e4f3 to
57dbd06
Compare
ENG-1132
🗒️ Description
🔗 Related Issues or PRs
N/A.
✅ Checklist
just statictype(scope):.mkdocs servelocally and verified the auto-generated docs for new tests in the Test Case Reference are correctly formatted.@ported_frommarker.Cute Animal Picture
Greptile Summary
This PR adds a new test file,
test_paged_storage_trie.py, that covers the MIP-8 page-based storage commitment primitivespage_commitandstorage_root_paged. The tests are split into two categories: self-referential known-answer vectors forpage_commit(with an appropriate disclaimer in the module docstring) and structural property tests.page_commitoutputs (single slot, pair, multi-level, full page, sparse even) to catch accidental ISMC regressions, with a clear warning that they must be cross-checked against the Monad reference client.Confidence Score: 5/5
This is a test-only addition with no changes to production code; safe to merge.
The PR adds only a new test file. No production logic is modified. The known-answer vectors carry a clear self-referential disclaimer, and all structural property tests are independently correct. The two pre-existing review thread concerns (the functionally duplicate empty-storage test and the dead < 32 branch in the manual reconstruction) are style/coverage issues already on the author's radar and do not introduce incorrect behaviour.
No files require special attention.
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[_storage helper\nslot→Bytes32 key mapping] --> B[storage_root_paged] C[_page helper\noffset→4096-byte page image] --> D[page_commit] subgraph "page_commit tests" D --> E[test_page_commit_known_vectors\n6 parametrized vectors] D --> F[test_page_commit_length_is_32] D --> G[test_page_commit_rejects_all_zero_page] D --> H[test_page_commit_deterministic] D --> I[test_page_commit_sensitive_to_value] D --> J[test_page_commit_sensitive_to_offset] end subgraph "storage_root_paged tests" B --> K[test_empty_storage_is_empty_trie_root] B --> L[test_storage_root_length_is_32] B --> M[test_storage_root_order_independent] B --> N[test_storage_root_distinguishes_pages] B --> O[test_storage_root_clears_to_empty_when_slots_omitted] D --> P[test_single_page_root_matches_manual_reconstruction\nmanual keccak-MPT cross-check] B --> P end%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%% flowchart TD A[_storage helper\nslot→Bytes32 key mapping] --> B[storage_root_paged] C[_page helper\noffset→4096-byte page image] --> D[page_commit] subgraph "page_commit tests" D --> E[test_page_commit_known_vectors\n6 parametrized vectors] D --> F[test_page_commit_length_is_32] D --> G[test_page_commit_rejects_all_zero_page] D --> H[test_page_commit_deterministic] D --> I[test_page_commit_sensitive_to_value] D --> J[test_page_commit_sensitive_to_offset] end subgraph "storage_root_paged tests" B --> K[test_empty_storage_is_empty_trie_root] B --> L[test_storage_root_length_is_32] B --> M[test_storage_root_order_independent] B --> N[test_storage_root_distinguishes_pages] B --> O[test_storage_root_clears_to_empty_when_slots_omitted] D --> P[test_single_page_root_matches_manual_reconstruction\nmanual keccak-MPT cross-check] B --> P endReviews (4): Last reviewed commit: "Fix lint in paged storage trie tests" | Re-trigger Greptile