Introduction
Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.
I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.
I also build and publish a variety of tools, libraries, and open-source projects.
This article covers ERC1967, which proposes a standard for upgrading contracts.
The explanation below translates, summarizes, and expands on the following proposal.
Contract upgrades are also covered in the following articles.
https://chaldene.net/upgradable-contracts
Understanding Smart Contract Upgrades
Overview
Delegate proxy contracts are widely used to upgrade smart contracts and reduce gas costs. These proxies use a special operation called delegatecall to invoke a logic contract, also known as an implementation contract or master copy. With delegatecall, a proxy retains its storage data and funds while delegating code execution to the logic contract.
See the following article for more about delegatecall.
https://chaldene.net/solidity-delegatecall
Proxy contract A proxy contract holds data and funds and can use delegatecall to invoke the contract that performs the actual processing (the logic contract).
Logic contract The logic contract, in contrast, performs the actual processing without holding the data or funds.
To avoid storage conflicts between the proxy and logic contract, the logic contract address is usually stored in a storage slot within the proxy contract.
The proxy stores information identifying which contract to invoke when making a delegatecall to the logic contract.
For example, OpenZeppelin contracts use a location such as 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc.
This is a special location that the compiler is guaranteed not to allocate.
This proposal introduces a new way to manage information about proxy contracts. Since proxies use logic contracts, knowing which logic contract a proxy uses is important. Without a common mechanism, however, it is difficult to immediately identify which logic contract is associated with a given proxy.
The proposed approach stores proxy-related information in specific storage slots. These are special locations that the compiler and similar tools do not allocate automatically. Block explorers and other clients can then retrieve proxy information easily and present it clearly to users. In other words, it becomes easier to identify which contract address the proxy calls.
The logic contract can also recognize that it is being used through a proxy and act accordingly. This allows the logic contract to work with the proxy to provide specific functionality or update code when required.
In short, the proposal makes delegate proxies easier to handle and provides a way to manage their associated information effectively. It clarifies the relationship between the proxy and the logic contract, making proxies easier to use and upgrade.
Motivation
Although proxies are widely used to support upgrades and reduce deployment gas costs, the lack of a common way to retrieve a logic contract address from a proxy has limited the availability of tools that use this information.
A block explorer is one example. Users typically want to interact with the logic contract behind a proxy rather than the proxy itself.
This is because the actual functionality is defined in the logic contract.
Without a common method for retrieving the logic contract address from the proxy, however, an explorer has difficulty displaying the correct ABI (Application Binary Interface) for the logic contract. Using the proposed standard slots enables tools such as block explorers to identify the logic contract used by a given proxy. This clarifies the relationship between the proxy and the logic contract behind it.
Specifically, the proxy stores the address of its logic contract at a designated location (the proposed standard slot). The explorer checks the proxy address and reads the address stored in that slot. This address identifies the logic contract used by the proxy.
See the following article for more about storage data and slots.
https://chaldene.net/solidity-private-data#st-toc-h-3

The logic contract can also recognize the proxy contract and take specific actions. The common storage slots provide a foundation for such use cases independently of the proxy implementation.
Specification
Monitoring proxies is important for the security of many applications. It is therefore important to be able to track changes to the implementation and admin slots. Unfortunately, tracking changes to storage slots is not straightforward. Any function that changes one of these slots should therefore emit the corresponding event.
Events are logs.
This includes initialization and changes from 0x0 to the first nonzero value.
The proposed storage slots for proxy-specific information are listed below. Subsequent ERCs can introduce additional slots if more information is needed.
Logic contract address
The storage slot 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc (derived from the keccak256 hash of eip1967.proxy.implementation) holds the address of the logic contract to which the proxy delegates.
This slot should be empty if a beacon is used instead.
Changes to this slot are reported through the following event.
event Upgraded(address indexed implementation);This event is emitted when the logic contract address changes, allowing the change to be tracked. When the proxy upgrades to a new logic contract, other contracts and external tools can be notified of the change to the proxy's state.
Beacon contract address
The storage slot 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50 (derived from the keccak256 hash of eip1967.proxy.beacon) holds the address of the beacon contract on which the proxy depends, as a fallback.
This slot should be empty if the logic address is used directly.
The beacon contract slot is considered only when the logic contract slot is empty.
event BeaconUpgraded(address indexed beacon);This event is emitted when the beacon contract address changes, allowing the change to be tracked. A beacon stores the logic address for multiple proxies in one place, making it possible to upgrade multiple proxies by changing a single storage slot. The beacon contract must implement the following function.
function implementation() returns (address)A beacon-based proxy does not use the logic contract slot. Instead, it uses the beacon contract slot to store the address of the associated beacon. To identify the logic contract used by a beacon proxy, clients perform the following steps.
- Read the beacon address from the beacon storage slot.
- Call
implementation()on the beacon contract.
The result of the beacon contract's implementation() function should also be independent of the caller (msg.sender).
Admin address
The optional storage slot 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103 (derived from the keccak256 hash of eip1967.proxy.admin) holds the address authorized to upgrade the proxy's logic contract address.
This is the address authorized to upgrade the logic contract.
Changes to this slot are reported through the following event.
event AdminChanged(address previousAdmin, address newAdmin);This event is emitted when the address authorized to upgrade the proxy changes, allowing the change to be tracked. It records a history of changes to upgrade authority.
When upgrading the logic contract address, the authorized address (the admin address) is designated.
This allows only the specified admin address to upgrade the logic contract.
When the admin address changes, the AdminChanged event is emitted, recording the previous and new admin addresses.
This mechanism strengthens proxy and logic contract security and ensures upgrades are carried out by an authorized party.
Additional considerations
This EIP proposes standardizing the storage slot for the logic contract address instead of using a public method on the proxy contract. The reasoning is that proxies should not expose functions to end users that could collide with functions in the logic contract.
Because an ABI function selector uses only 4 bytes, collisions can occur even between functions with different names. Such collisions can cause unexpected errors, malicious behavior, or attacks. For example, a proxy contract may intercept a function call and return its own value rather than the intended result.
See the following article for more about function selector collisions.
Understanding Smart Contract Upgrades
According to Nomic Labs' "Malicious backdoors in Ethereum proxies", when a selector in the proxy contract matches one in the implementation contract, the corresponding proxy function is called directly, bypassing the implementation code entirely. The implementation of the logic contract is therefore ignored, potentially causing unexpected behavior.
In other words, the user intends to execute a function in the logic contract but instead executes the proxy contract's function with the same selector.
To avoid this problem, the standard stores the logic contract address in a storage slot rather than exposing a public proxy function that could collide with a logic contract function. This reduces the likelihood of unintended behavior for end users and the risk of unexpected interactions between proxy and logic contracts.
Any function in the Proxy contract whose selector matches with one in the implementation contract will be called directly, completely skipping the implementation code. Because the function selectors use a fixed amount of bytes, there will always be the possibility of a clash. This isn’t an issue for day to day development, given that the Solidity compiler will detect a selector clash within a contract, but this becomes exploitable when selectors are used for cross-contract interaction. Clashes can be abused to create a seemingly well-behaved contract that’s actually concealing a backdoor.
The potential for abuse of public proxy functions created a need to standardize another way of obtaining the logic contract address.
The primary requirement for the selected storage slots is that the compiler must not use them to store contract state variables. Otherwise, when the logic contract writes to its own variables, it may accidentally overwrite information stored by the proxy. The proxy could consequently lose critical information.
Solidity maps variables to storage based on their declaration order after linearizing the contract inheritance hierarchy. The first declared variable is assigned to the first slot, the second to the second slot, and so on. Dynamic arrays and mappings, however, use hashed storage locations based on the concatenation of keys and storage slots. This layout determines which slot each variable occupies.
See the following article for more about storage data and slots.
https://chaldene.net/solidity-private-data#st-toc-h-3
The Solidity development team has confirmed its policy of preserving storage layout across new versions. Accordingly, the storage slots chosen for proxy information are intended to remain stable despite future Solidity updates.
This approach protects against collisions and abuse involving public proxy functions and helps ensure data integrity and security between the proxy and logic contract.
The layout of state variables in storage is considered to be part of the external interface of Solidity due to the fact that storage pointers can be passed to libraries. This means that any change to the rules outlined in this section is considered a breaking change of the language and due to its critical nature should be considered very carefully before being executed. In the event of such a breaking change, we would want to release a compatibility mode in which the compiler would generate bytecode supporting the old layout.
Vyper follows the same policy as Solidity, and proxy storage slots are carefully chosen to avoid collisions with slots the compiler uses to store contract state variables. This approach is important for improving contract security.
These storage slots are carefully selected to avoid collisions with state variables allocated by the compiler. The selection relies on a hash function to transform a string into a hash that serves as a storage index. This hashing approach assigns unique slots using specific patterns or strings.
In addition, the -1 offset applied to the hash makes it difficult to infer a preimage for the resulting value.
This reduces the risk of an attacker reverse-engineering the storage slot selection method to attempt an attack.
The selection of storage slots that avoid compiler allocation in languages such as Vyper and Solidity protects contract behavior against unexpected problems and attacks. Contracts written in other languages or assembly may not follow the same rules, however, so a risk of collision can remain.
See the following article for more about storage collisions.
Understanding Smart Contract Upgrades
Reference implementation
contract ERC1967Proxy is Proxy, ERC1967Upgrade {
constructor(address _logic, bytes memory _data) payable {
assert(_IMPLEMENTATION_SLOT == bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1));
_upgradeToAndCall(_logic, _data, false);
}
function _implementation() internal view virtual override returns (address impl) {
return ERC1967Upgrade._getImplementation();
}
}
abstract contract ERC1967Upgrade {
// This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1
bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143;
bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
event Upgraded(address indexed implementation);
function _getImplementation() internal view returns (address) {
return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
}
function _setImplementation(address newImplementation) private {
require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
}
function _upgradeTo(address newImplementation) internal {
_setImplementation(newImplementation);
emit Upgraded(newImplementation);
}
function _upgradeToAndCall(
address newImplementation,
bytes memory data,
bool forceCall
) internal {
_upgradeTo(newImplementation);
if (data.length > 0 || forceCall) {
Address.functionDelegateCall(newImplementation, data);
}
}
function _upgradeToAndCallSecure(
address newImplementation,
bytes memory data,
bool forceCall
) internal {
address oldImplementation = _getImplementation();
// Initial upgrade and setup call
_setImplementation(newImplementation);
if (data.length > 0 || forceCall) {
Address.functionDelegateCall(newImplementation, data);
}
// Perform rollback test if not already in progress
StorageSlot.BooleanSlot storage rollbackTesting = StorageSlot.getBooleanSlot(_ROLLBACK_SLOT);
if (!rollbackTesting.value) {
// Trigger rollback using upgradeTo from the new implementation
rollbackTesting.value = true;
Address.functionDelegateCall(
newImplementation,
abi.encodeWithSignature("upgradeTo(address)", oldImplementation)
);
rollbackTesting.value = false;
// Check rollback was effective
require(oldImplementation == _getImplementation(), "ERC1967Upgrade: upgrade breaks further upgrades");
// Finally reset to the new implementation and log the upgrade
_upgradeTo(newImplementation);
}
}
bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
event AdminChanged(address previousAdmin, address newAdmin);
function _getAdmin() internal view returns (address) {
return StorageSlot.getAddressSlot(_ADMIN_SLOT).value;
}
function _setAdmin(address newAdmin) private {
require(newAdmin != address(0), "ERC1967: new admin is the zero address");
StorageSlot.getAddressSlot(_ADMIN_SLOT).value = newAdmin;
}
function _changeAdmin(address newAdmin) internal {
emit AdminChanged(_getAdmin(), newAdmin);
_setAdmin(newAdmin);
}
bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;
event BeaconUpgraded(address indexed beacon);
function _getBeacon() internal view returns (address) {
return StorageSlot.getAddressSlot(_BEACON_SLOT).value;
}
function _setBeacon(address newBeacon) private {
require(Address.isContract(newBeacon), "ERC1967: new beacon is not a contract");
require(
Address.isContract(IBeacon(newBeacon).implementation()),
"ERC1967: beacon implementation is not a contract"
);
StorageSlot.getAddressSlot(_BEACON_SLOT).value = newBeacon;
}
function _upgradeBeaconToAndCall(
address newBeacon,
bytes memory data,
bool forceCall
) internal {
_setBeacon(newBeacon);
emit BeaconUpgraded(newBeacon);
if (data.length > 0 || forceCall) {
Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data);
}
}
}
abstract contract Proxy {
function _delegate(address implementation) internal virtual {
assembly {
// Copy msg.data. We take full control of memory in this inline assembly
// block because it will not return to Solidity code. We overwrite the
// Solidity scratch pad at memory position 0.
calldatacopy(0, 0, calldatasize())
// Call the implementation.
// out and outsize are 0 because we don't know the size yet.
let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)
// Copy the returned data.
returndatacopy(0, 0, returndatasize())
switch result
// delegatecall returns 0 on error.
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
function _implementation() internal view virtual returns (address);
function _fallback() internal virtual {
_beforeFallback();
_delegate(_implementation());
}
fallback() external payable virtual {
_fallback();
}
receive() external payable virtual {
_fallback();
}
function _beforeFallback() internal virtual {}
}
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
assembly {
r.slot := slot
}
}
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
assembly {
r.slot := slot
}
}
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
assembly {
r.slot := slot
}
}
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
assembly {
r.slot := slot
}
}
}The implementation is long, so the following sections examine it in parts.
ERC1967Proxy
contract ERC1967Proxy is Proxy, ERC1967Upgrade {
constructor(address _logic, bytes memory _data) payable {
assert(_IMPLEMENTATION_SLOT == bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1));
_upgradeToAndCall(_logic, _data, false);
}
function _implementation() internal view virtual override returns (address impl) {
return ERC1967Upgrade._getImplementation();
}
}This is an implementation of an upgradeable proxy contract based on EIP1967. The proxy delegates calls to a specific implementation address and provides a mechanism for changing that address. Proxy contracts are designed to make it easier to change smart contract behavior through upgrades.
constructor
Receives the initial implementation address (_logic) and initial data (_data), and initializes the proxy.
If _data is not empty, it is executed against _logic through a delegatecall.
_implementation
Overrides a function inherited from the ERC1967Upgrade contract.
Returns the current implementation address, which the proxy uses as the target of delegatecall to invoke functionality in the logic contract.
ERC1967Upgrade
abstract contract ERC1967Upgrade {
// This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1
bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143;
bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
event Upgraded(address indexed implementation);
function _getImplementation() internal view returns (address) {
return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
}
function _setImplementation(address newImplementation) private {
require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
}
function _upgradeTo(address newImplementation) internal {
_setImplementation(newImplementation);
emit Upgraded(newImplementation);
}
function _upgradeToAndCall(
address newImplementation,
bytes memory data,
bool forceCall
) internal {
_upgradeTo(newImplementation);
if (data.length > 0 || forceCall) {
Address.functionDelegateCall(newImplementation, data);
}
}
function _upgradeToAndCallSecure(
address newImplementation,
bytes memory data,
bool forceCall
) internal {
address oldImplementation = _getImplementation();
// Initial upgrade and setup call
_setImplementation(newImplementation);
if (data.length > 0 || forceCall) {
Address.functionDelegateCall(newImplementation, data);
}
// Perform rollback test if not already in progress
StorageSlot.BooleanSlot storage rollbackTesting = StorageSlot.getBooleanSlot(_ROLLBACK_SLOT);
if (!rollbackTesting.value) {
// Trigger rollback using upgradeTo from the new implementation
rollbackTesting.value = true;
Address.functionDelegateCall(
newImplementation,
abi.encodeWithSignature("upgradeTo(address)", oldImplementation)
);
rollbackTesting.value = false;
// Check rollback was effective
require(oldImplementation == _getImplementation(), "ERC1967Upgrade: upgrade breaks further upgrades");
// Finally reset to the new implementation and log the upgrade
_upgradeTo(newImplementation);
}
}
bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
event AdminChanged(address previousAdmin, address newAdmin);
function _getAdmin() internal view returns (address) {
return StorageSlot.getAddressSlot(_ADMIN_SLOT).value;
}
function _setAdmin(address newAdmin) private {
require(newAdmin != address(0), "ERC1967: new admin is the zero address");
StorageSlot.getAddressSlot(_ADMIN_SLOT).value = newAdmin;
}
function _changeAdmin(address newAdmin) internal {
emit AdminChanged(_getAdmin(), newAdmin);
_setAdmin(newAdmin);
}
bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;
event BeaconUpgraded(address indexed beacon);
function _getBeacon() internal view returns (address) {
return StorageSlot.getAddressSlot(_BEACON_SLOT).value;
}
function _setBeacon(address newBeacon) private {
require(Address.isContract(newBeacon), "ERC1967: new beacon is not a contract");
require(
Address.isContract(IBeacon(newBeacon).implementation()),
"ERC1967: beacon implementation is not a contract"
);
StorageSlot.getAddressSlot(_BEACON_SLOT).value = newBeacon;
}
function _upgradeBeaconToAndCall(
address newBeacon,
bytes memory data,
bool forceCall
) internal {
_setBeacon(newBeacon);
emit BeaconUpgraded(newBeacon);
if (data.length > 0 || forceCall) {
Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data);
}
}
}An abstract contract for implementing upgradeable smart contracts based on EIP1967. It provides functions for retrieving information from EIP1967 slots and emitting events.
_ROLLBACK_SLOT
A variable that stores the progress of the rollback test during an upgrade. The rollback test is intended to allow a return to the previous implementation if an upgrade to a new implementation fails.
_IMPLEMENTATION_SLOT
A variable that stores the current implementation address. The proxy works by delegating calls to the implementation address stored in this slot.
_ADMIN_SLOT
A variable that stores the address of the proxy contract's admin account. The admin of an upgradeable contract has authority to perform important operations such as upgrading the contract.
_BEACON_SLOT
A variable that stores the current beacon address when an upgradeable contract uses the beacon pattern. The beacon pattern is a way for a proxy to point to an upgradeable contract.
_getImplementation
Retrieves the current implementation address.
_setImplementation
Updates the proxy's implementation address to the specified new address.
_upgradeTo
Upgrades to a new implementation address.
Emits the Upgraded event when the upgrade takes place.
_upgradeToAndCall
Upgrades to a new implementation address and performs an additional setup call using the supplied data.
A delegatecall is also performed as needed, including when forceCall is true.
_upgradeToAndCallSecure
Upgrades to a new implementation address and performs an additional setup call that includes security checks. It also performs a rollback test to verify that the upgrade works correctly.
_getAdmin
Retrieves the current admin account address.
_setAdmin
Updates the admin account to the specified new address.
_changeAdmin
Changes the proxy contract's admin.
Emits the AdminChanged event when the change takes place.
_upgradeBeaconToAndCall
Performs a beacon upgrade and makes a setup call to the new beacon address.
Proxy
abstract contract Proxy {
function _delegate(address implementation) internal virtual {
assembly {
// Copy msg.data. We take full control of memory in this inline assembly
// block because it will not return to Solidity code. We overwrite the
// Solidity scratch pad at memory position 0.
calldatacopy(0, 0, calldatasize())
// Call the implementation.
// out and outsize are 0 because we don't know the size yet.
let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)
// Copy the returned data.
returndatacopy(0, 0, returndatasize())
switch result
// delegatecall returns 0 on error.
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
function _implementation() internal view virtual returns (address);
function _fallback() internal virtual {
_beforeFallback();
_delegate(_implementation());
}
fallback() external payable virtual {
_fallback();
}
receive() external payable virtual {
_fallback();
}
function _beforeFallback() internal virtual {}
}An abstract contract that provides a fallback function and delegates calls to another contract using the EVM delegatecall instruction.
It allows another implementation contract to be called through a proxy.
_delegate
Delegates the current call to the specified implementation address using the delegatecall instruction.
Handles return data according to whether delegatecall succeeds or fails.
_implementation
Returns the implementation address to which the fallback and delegation functions delegate calls. This function must be overridden to specify the implementation address.
_fallback
Acts as the fallback handler and delegates calls to the designated implementation address.
The _beforeFallback function is called.
fallback
Provides the same functionality as the fallback handler but serves as an entry point for external calls.
This function is called when the contract does not contain the function being invoked.
It invokes delegatecall.
receive
Like the fallback function, it provides fallback functionality, but is used when calldata is empty.
_beforeFallback
A hook called before fallback. Override it to perform specific actions.
StorageSlot
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
assembly {
r.slot := slot
}
}
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
assembly {
r.slot := slot
}
}
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
assembly {
r.slot := slot
}
}
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
assembly {
r.slot := slot
}
}
}A library for reading and writing primitive data types at specific storage slots. It may be used to avoid storage conflicts in upgradeable contracts. This library helps read and write these slots without using inline assembly directly.
AddressSlot
An address-typed storage slot with a value member.
BooleanSlot
A bool-typed storage slot with a value member.
Bytes32Slot
A bytes32-typed storage slot with a value member.
Uint256Slot
A uint256-typed storage slot with a value member.
getAddressSlot
Returns the AddressSlot at a specified slot.
getBooleanSlot
Returns the BooleanSlot at a specified slot.
getBytes32Slot
Returns the Bytes32Slot at a specified slot.
getUint256Slot
Returns the Uint256Slot at a specified slot.
Security
This ERC provides an implementation of upgradeable proxies. The proxy provides upgradeable functionality by delegating external calls to another implementation address. The proxy stores the implementation address to be upgraded at a location specified by the Ethereum improvement proposal ERC1967. This avoids conflicts with the storage layout of the implementation behind the proxy.
From a security perspective, the implementation uses storage slots that the Solidity compiler does not allocate. This avoids the risk of accidentally overwriting information required for normal proxy operation. High slot numbers are chosen to minimize conflicts with slots allocated by the compiler. Selecting slots with no known preimage also prevents writes to mappings using malicious keys from overwriting proxy information.
To change proxy-related information, the implementation contract must deliberately write to a specific storage slot. This is a common approach to supporting upgradeable proxies, including the upgrade mechanism known as UUPS (Universal Upgradeable Proxy Standard). It helps ensure safe proxy operation and prevent unintended upgrades or overwrites.
References
Santiago Palladino (@spalladino), Francisco Giordano (@frangio), Hadrien Croubois (@Amxx), "ERC-1967: Proxy Storage Slots," Ethereum Improvement Proposals, no. 1967, April 2019. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-1967.
Conclusion
This article covered ERC1967, which proposes a standard for upgrading contracts.

