-
Notifications
You must be signed in to change notification settings - Fork 187
Use namespaced storage for variables when upgradeable #704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ericglau
merged 25 commits into
OpenZeppelin:master
from
typicalHuman:erc721-uups-namespaced-integration
Oct 29, 2025
Merged
Changes from 3 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
9842397
Support for ERC721 with Mintable → Auto Increment IDs and Upgradeabil…
typicalHuman 478eb87
Formatting fixes
typicalHuman 7069b48
Use ethereum-cryptography, refactor
ericglau 5ed815d
Suggested fixes
typicalHuman a282e2c
Refactor, cleanup
ericglau 9e1c586
lint
ericglau f8086dc
Add namespace prefix option, refactor
ericglau 8addbc7
Add namespace prefix to UI
ericglau 1d4fc33
Fix lint
ericglau d353f08
Use namespace for token bridge
ericglau c809aa4
Use spaces between vars that have comments
ericglau 2e1258b
Update snapshots
ericglau bfeef29
Update snapshots
ericglau db46fd1
Update snapshots
ericglau 18b671d
Fix deno check
ericglau c56c34c
Added test for ERC721 with namespacePrefix
typicalHuman 17ca029
Updated namespacePrefix description
typicalHuman ddf8d21
Removed "ethereum-cryptography" dependency & changed "computeNamespac…
typicalHuman a14b9cc
Update packages/core/solidity/package.json
typicalHuman 417c581
Revert "Update packages/core/solidity/package.json"
ericglau 2695618
Revert "Removed "ethereum-cryptography" dependency & changed "compute…
ericglau be72639
Merge branch 'master' into erc721-uups-namespaced-integration
typicalHuman 7621522
Update prefix tooltip and prompt
ericglau 77eb539
Check for whitespace
ericglau 9dd2f37
Add unit tests
ericglau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@openzeppelin/wizard': minor | ||
| --- | ||
|
|
||
| Support for ERC721 with Mintable → Auto Increment IDs and Upgradeability, using \_nextTokenId in namespaced storage for safe upgradeable minting. | ||
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
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
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
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
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
Binary file not shown.
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
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
23 changes: 23 additions & 0 deletions
23
packages/core/solidity/src/utils/namespaced-storage-generator.test.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import test from 'ava'; | ||
| import { computeNamespacedStorageSlot } from './namespaced-storage-generator'; | ||
|
|
||
| test('namespaced storage slot generation', t => { | ||
| const cases = [ | ||
| { | ||
| input: 'myProject.MyToken', | ||
| expected: '0xfbb7c9e4123fcf4b1aad53c70358f7b1c1d7cf28092f5178b53e55db565e9200', | ||
| }, | ||
| { | ||
| input: 'myProject.token', | ||
| expected: '0x86796099e489af07082cc4e6965fe431aadf035a7b4d4b46f81d8dfb81822d00', | ||
| }, | ||
| { | ||
| input: 'myProject.token123456', | ||
| expected: '0x824a9aeab482b3e91ee3e454c74509cca55ad57e0185a36d070359384be52800', | ||
| }, | ||
| ]; | ||
|
|
||
| for (const { input, expected } of cases) { | ||
| t.is(computeNamespacedStorageSlot(input), expected); | ||
| } | ||
| }); |
23 changes: 23 additions & 0 deletions
23
packages/core/solidity/src/utils/namespaced-storage-generator.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
|
|
||
| import { keccak256 } from 'ethereum-cryptography/keccak'; | ||
| import { hexToBytes, toHex, utf8ToBytes } from 'ethereum-cryptography/utils'; | ||
|
|
||
| export function getNamespaceId(name: string, namespace: string = 'myProject') { | ||
| return `${namespace}.${name}`; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the ERC-7201 storage location for a given namespace id | ||
| */ | ||
| export function computeNamespacedStorageSlot(id: string): string { | ||
| const innerHash = keccak256(utf8ToBytes(id)); | ||
| const minusOne = BigInt('0x' + toHex(innerHash)) - 1n; | ||
| const minusOneBytes = hexToBytes(minusOne.toString(16).padStart(64, '0')); | ||
|
|
||
| const outerHash = keccak256(minusOneBytes); | ||
|
|
||
| const mask = BigInt('0xff'); | ||
| const masked = BigInt('0x' + toHex(outerHash)) & ~mask; | ||
|
|
||
| return '0x' + masked.toString(16).padStart(64, '0'); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.