Summary: The code of an upgradeable contract can change, but old data remains in its original storage locations. ERC-7201 organizes storage using namespaces, giving modules separate regions and making layouts easier for tools to inspect; it does not make every upgrade automatically safe.
1. Why can upgrades affect old data?
You can think of contract storage as a row of numbered drawers. After a proxy contract is upgraded, the new logic code still needs to read the existing drawers. If the new version changes the order or types of variables, causing the same locations to be interpreted differently, existing balance or permission data may be misread, potentially putting assets at risk.
Complex projects may also consist of multiple modules. Different modules executed through delegatecall use the caller's storage space, so they must coordinate storage locations to avoid overwriting one another. The more complex the project code, the easier it is to overlook details if relying on memory alone.
II. What does ERC-7201 do?
Created in 2023, this standard proposes a convention for annotating storage namespace locations. Developers can group related variables in a struct, identify the group with a unique namespace ID, and then derive the starting storage location for that group of data using the standard's formula. This allows different modules to organize their data independently, rather than all starting from the default storage tree location.
The standard also defines the NatSpec annotation @custom:storage-location, enabling analysis tools to identify namespaces and the method used to calculate their locations. The annotation describes the layout; it does not automatically move data or perform security checks on the developer's behalf. The implementation must still calculate locations correctly and use the appropriate storage pointers.
III. What should you still watch out for during upgrades?
A namespace ID should be unique within the contract and its inheritance hierarchy. Layout rules still apply within each namespace, so existing members cannot be arbitrarily reordered or have their types changed. Changing a namespace ID may also cause new code to read from a different location, so it should not be treated as a risk-free rename. For existing deployments, carefully analyze the old layout before migrating; do not assume that adding an annotation will automatically migrate existing data.
OpenZeppelin's upgrade tools support checks of namespace layouts, and the documentation requires Solidity 0.8.20 or later to provide the necessary compiler information. Real-world projects should also preserve build information from previous versions, compare the old implementation's layout before upgrading, and test permissions, initialization, and business processes. Passing these checks only reduces risk; it does not replace a full audit.
After learning about on-chain contracts, if you need to use Binance services, first review the official rules and the conditions that apply in your region. Binance referral code: WIN1000. Using a referral code may earn the referrer a commission; the specific benefits are subject to Binance's pages and rules.
This article was prepared with AI assistance and is based on publicly available standards. No code was run or contracts tested.
Sources verified:
https://eips.ethereum.org/EIPS/eip-7201
https://docs.openzeppelin.com/upgrades-plugins/writing-upgradeable