Proxy — Unstructured Storage

Eszymi
Coinmonks
Published in
2 min readOct 5, 2022

--

This pattern of storage is similar to the inherited storage pattern, but has one big difference. The Logic contract doesn’t have to know the Proxy’s storage layout.

How I wrote in my previous post, developers create a different type of storage to avoid Storage Collision. In the inherited storage pattern, all state variables were written in the firsts slots of storage. But this leads to a big risk, that this slot could be overwritten.

Therefor in unstructured storage pattern, all Proxy’s state variables like address of Logic contract has been written in the pseudorandom slot. The index of this slot is occur by something like that

bytes32 private constant implementationPosition = bytes32(uint256(
keccak256(‘eip1967.proxy.implementation’)) – 1 ));

The result depends on the input, ‘eip1967.proxy.implementation’ in our case, and it’s saving as a constant, so nothing will overwrite it, because the constant value is not store in the storage. The slots to write Proxy’s state variables are defined by EIP-1967.

The Solidity use storage with 2²⁵⁶ slots. So, the chance that our Logic overwrite this one slot is very, very small.

The rest of this pattern is the same as inherited storage. Therefor, the new Logic contract has to inherit all state variables from the old one.

Summary

Advantage

  • The risk of overwrite the Proxy’s state variable is minimal
  • It’s simply method

Disadvantage

  • New versions need to inherit storage that may contain many state variables that they don’t use. So with the time, this method could be expensive in implementation.
  • The all implementations of the Logic become tightly coupled to specific proxy contracts and cannot be used by other proxy contracts that declare different state variables.

I hope you find this post useful. If you have any idea, how could I make my posts better, let my know. I am always ready to learn. You can connect with me on LinkedIn and Telegram.

If you would like to talk with me about this or any other topic I wrote, feel free. I’m open to conversation.

Happy learning!

New to trading? Try crypto trading bots or copy trading

--

--