1 of 26

Namespace Storage

Hadrien Croubois (@Amxx) – Research Engineer @ OpenZeppelin

(for now and for a Verkle EVM)

2 of 26

The grammar of storage layouts

Given the linearized contract …

… take all the variables in order …

… and follow the grammar (with root 0)

3 of 26

Storage matters … when performing upgrades

Upgradeable smart contract needs to preserve a similar view of the storage layout across upgrades.

�A lot can potentially go wrong:

  • Inserting a variable that shift the layout
  • Resize a variable (sometimes it's ok, not always)
  • Reorder variables in a contract
  • Reorder inheritance

4 of 26

The gap approach

Used in @openzeppelin/contracts-upgradeable 3.x – 4.x

5 of 26

The namespace approach

Used in @openzeppelin/contracts-upgradeable 5.x

6 of 26

ERC-7201

7 of 26

ERC-7201: derivation of a new (safe) root

8 of 26

Going back to the grammar

What is not in the grammar for a root 0 ?

If n is small enough, and if keccak256 is a good hashing function, we just need to find a location that is not in Lroot, and use that as our new root.

9 of 26

ERC-7201 derivation explained

keccak256(keccak256(“openzeppelin.storage.Ownable”) - 1) & ~0xFF

“openzeppelin.storage.Ownable”

Seed

keccak256(...) - 1

Hash of the seed might collide if the seed matches a valid storage location is L0, so we subtract 1 to exit L0

keccak256(...)

Get a completely new space (so doing “+n”) don’t bring us back into L0

... & ~0xFF

Clean the last byte so our namespace starts at the beginning of a bucket

10 of 26

What is a bucket?

Should Solidity (& Vyper) change their grammar?

Maybe!

Stateless Ethereum: How Verkle Trees Make Ethereum Lean and Mean by Guillaume Ballet

https://www.youtube.com/watch?v=Q7rStTKwuYs

11 of 26

Thursday,

Nov 16, 2023

Istanbul, Türkiye

12 of 26

Welcome to the Solidity Summit template!

First of all, thank you so much for being a speaker & sharing your knowledge with the audience! 💙

Please help us make Solidity Summit 2023 a high-quality and enjoyable conference experience for all by…

  • Refraining from marketing-focused talks or pure product presentations
  • Keeping the content technical, informational and educational
  • Asking yourself: If you were in the audience, would you find your talk interesting, helpful, and relevant?

Looking forward to seeing your talk at the summit and don’t hesitate to reach out to us with any questions!

13 of 26

Of course you don’t have to use the template provided!

You can also use your own slide design by simply deleting all these slides and copy pasting in an existing presentation or creating your own from scratch!

14 of 26

There is a dark mode

…and a light mode

*(at the end of this presentation)

15 of 26

ADD YOUR TITLE HERE

SUBTITLE AND/OR SPEAKER INFO

16 of 26

This is a regular slide.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer eget volutpat eros, sit amet tristique enim. Aliquam nec odio eu ligula aliquam ultrices. Nulla fermentum dui nisl, ut tempus eros volutpat convallis.

  • Bullet lists
  • Content
  • More content

  1. Numbered lists
    1. Etc.
    2. Also
    3. Moreover,

17 of 26

This is a slide with two columns.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer eget volutpat eros, sit amet tristique enim. Aliquam nec odio eu ligula aliquam ultrices. Nulla fermentum dui nisl, ut tempus eros volutpat convallis.

  • Point 1
  • Point 2
  • Point 3

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer eget volutpat eros, sit amet tristique enim. Aliquam nec odio eu ligula aliquam ultrices. Nulla fermentum dui nisl, ut tempus eros volutpat convallis.

  • Point 1
  • Point 2
  • Point 3

18 of 26

This is a split slide.

Space for subtitles.

Add text or a visualization here.

19 of 26

You can also use title only slides and add content of your choice!

20 of 26

Thursday,

Nov 16, 2023

Istanbul, Türkiye

21 of 26

ADD YOUR TITLE HERE

SUBTITLE AND/OR SPEAKER INFO

22 of 26

This is a regular slide.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer eget volutpat eros, sit amet tristique enim. Aliquam nec odio eu ligula aliquam ultrices. Nulla fermentum dui nisl, ut tempus eros volutpat convallis.

  • Bullet lists
  • Content
  • More content

  1. Numbered lists
    1. Etc.
    2. Also
    3. Moreover,

23 of 26

This is a slide with two columns.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer eget volutpat eros, sit amet tristique enim. Aliquam nec odio eu ligula aliquam ultrices. Nulla fermentum dui nisl, ut tempus eros volutpat convallis.

  • Point 1
  • Point 2
  • Point 3

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer eget volutpat eros, sit amet tristique enim. Aliquam nec odio eu ligula aliquam ultrices. Nulla fermentum dui nisl, ut tempus eros volutpat convallis.

  • Point 1
  • Point 2
  • Point 3

24 of 26

This is a split slide.

Space for subtitles.

Add text or a visualization here.

25 of 26

You can also use title only slides and add content of your choice!

26 of 26

Thursday,

Nov 16, 2023

Istanbul, Türkiye