feat(ux): storage namespacing pragma#4810
Draft
fubuloubu wants to merge 6 commits intovyperlang:masterfrom
Draft
feat(ux): storage namespacing pragma#4810fubuloubu wants to merge 6 commits intovyperlang:masterfrom
fubuloubu wants to merge 6 commits intovyperlang:masterfrom
Conversation
Implement the `#pragma storage-namespace` directive that allows contracts to declare a global storage namespace, shifting the base storage slot from 0 to a calculated offset based on ERC-7201. Key changes: - Add `storage_namespace` field to Settings dataclass - Parse `storage-namespace` pragma in pre_parser.py - Implement `erc7201_storage_slot()` function in utils.py that calculates the namespace slot using the ERC-7201 formula: `keccak256(keccak256(id) - 1) & ~0xff` - Modify Allocators to accept a starting slot for storage allocation - Update storage layout export to include namespace information - Add comprehensive tests for the new functionality The pragma accepts either: - A namespace string (e.g., `#pragma storage-namespace myapp.storage.v1`) which is hashed using ERC-7201 - A hex value (e.g., `#pragma storage-namespace 0x1000`) which is used as a raw slot value This feature enables modular contract architectures like Diamond Standard and supports ERC-7201 namespaced storage patterns. Closes vyperlang#4647
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4810 +/- ##
==========================================
+ Coverage 93.29% 93.30% +0.01%
==========================================
Files 148 148
Lines 20592 20628 +36
Branches 3577 3585 +8
==========================================
+ Hits 19211 19247 +36
Misses 924 924
Partials 457 457 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
fubuloubu
commented
Jan 14, 2026
- Remove unused pytest import from test_erc7201.py - Fix pragma parsing to properly handle empty namespace case (now raises specific error instead of falling through to unknown pragma) - Apply black formatting to data_positions.py
fubuloubu
commented
Jan 14, 2026
Comment on lines
+108
to
+110
| if pragma.startswith("storage-namespace") and ( | ||
| pragma == "storage-namespace" or pragma.startswith("storage-namespace ") | ||
| ): |
Member
Author
There was a problem hiding this comment.
Suggested change
| if pragma.startswith("storage-namespace") and ( | |
| pragma == "storage-namespace" or pragma.startswith("storage-namespace ") | |
| ): | |
| if pragma.startswith("storage-namespace"): |
fubuloubu
commented
Jan 14, 2026
| self.storage_allocator = SimpleAllocator( | ||
| max_slot=2**256, starting_slot=storage_starting_slot | ||
| ) | ||
| self.transient_storage_allocator = SimpleAllocator(max_slot=2**256) |
Member
Author
There was a problem hiding this comment.
Question: do we want this pragma to impact transient storage as well? Or require a separate pragma?
fubuloubu
commented
Jan 14, 2026
|
|
||
| def __init__(self): | ||
| self.storage_allocator = SimpleAllocator(max_slot=2**256) | ||
| def __init__(self, storage_starting_slot: int = 0): |
Member
Author
There was a problem hiding this comment.
Was thinking to rename this to:
Suggested change
| def __init__(self, storage_starting_slot: int = 0): | |
| def __init__(self, starting_slot: int = 0): |
fubuloubu
commented
Jan 14, 2026
Member
Author
fubuloubu
left a comment
There was a problem hiding this comment.
Streamline this test
fubuloubu
commented
Jan 14, 2026
fubuloubu
commented
Jan 14, 2026
1e0ee7e to
dace638
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.
What I did
Implement the
#pragma storage-namespacedirective that allows contracts to declare a global storage namespace, shifting the base storage slot from 0 to a calculated offset based on ERC-7201.Key changes:
storage_namespacefield to Settings dataclassstorage-namespacepragma in pre_parser.pyerc7201_storage_slot()function in utils.py that calculates the namespace slot using the ERC-7201 formula:keccak256(keccak256(id) - 1) & ~0xffThe pragma accepts either:
#pragma storage-namespace myapp.storage.v1) which is hashed using ERC-7201#pragma storage-namespace 0x1000) which is used as a raw slot valueThis feature enables modular contract architectures like Diamond Standard and supports ERC-7201 namespaced storage patterns.
fixes: #4647
How I did it
100% Claude Code
How to verify it
Commit message
feat: add
storage-namespacepragma directiveAllows contracts to declare a global storage namespace, shifting the base storage slot from 0 to a calculated offset based on ERC-7201
Description for the changelog
add
storage-namespacepragma directiveCute Animal Picture