Skip to content

feat(ux): storage namespacing pragma#4810

Draft
fubuloubu wants to merge 6 commits intovyperlang:masterfrom
fubuloubu:claude/implement-vip-4647-3xHob
Draft

feat(ux): storage namespacing pragma#4810
fubuloubu wants to merge 6 commits intovyperlang:masterfrom
fubuloubu:claude/implement-vip-4647-3xHob

Conversation

@fubuloubu
Copy link
Member

What I did

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.

fixes: #4647

How I did it

100% Claude Code

How to verify it

  • Verify storage slot output using namespaces
  • Verify no conflicts when used with Purse

Commit message

feat: add storage-namespace pragma directive

Allows 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-namespace pragma directive

Cute Animal Picture

clod

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
@fubuloubu fubuloubu changed the title feat: storage namespacing pragma feat(ux): storage namespacing pragma Jan 14, 2026
@codecov
Copy link

codecov bot commented Jan 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.30%. Comparing base (9964d42) to head (0523d56).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- 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
Copy link
Member Author

@fubuloubu fubuloubu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simpler

Comment on lines +108 to +110
if pragma.startswith("storage-namespace") and (
pragma == "storage-namespace" or pragma.startswith("storage-namespace ")
):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if pragma.startswith("storage-namespace") and (
pragma == "storage-namespace" or pragma.startswith("storage-namespace ")
):
if pragma.startswith("storage-namespace"):

self.storage_allocator = SimpleAllocator(
max_slot=2**256, starting_slot=storage_starting_slot
)
self.transient_storage_allocator = SimpleAllocator(max_slot=2**256)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: do we want this pragma to impact transient storage as well? Or require a separate pragma?


def __init__(self):
self.storage_allocator = SimpleAllocator(max_slot=2**256)
def __init__(self, storage_starting_slot: int = 0):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was thinking to rename this to:

Suggested change
def __init__(self, storage_starting_slot: int = 0):
def __init__(self, starting_slot: int = 0):

Copy link
Member Author

@fubuloubu fubuloubu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Streamline this test

@fubuloubu fubuloubu force-pushed the claude/implement-vip-4647-3xHob branch from 1e0ee7e to dace638 Compare January 14, 2026 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VIP: Global Storage Namespace

2 participants