Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
openzeppelin-contracts-upgradeable
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
俞永鹏
openzeppelin-contracts-upgradeable
Commits
6552adaf
Commit
6552adaf
authored
Apr 26, 2021
by
Hadrien Croubois
Committed by
Francisco Giordano
Apr 26, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge ERC1967Storage into ERC1967Upgrade (#2644)
(cherry picked from commit
5756e319
)
parent
a664fb1e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
82 additions
and
97 deletions
+82
-97
ERC1967Proxy.sol
contracts/proxy/ERC1967/ERC1967Proxy.sol
+1
-1
ERC1967Storage.sol
contracts/proxy/ERC1967/ERC1967Storage.sol
+0
-87
ERC1967Upgrade.sol
contracts/proxy/ERC1967/ERC1967Upgrade.sol
+81
-7
README.adoc
contracts/proxy/README.adoc
+0
-2
No files found.
contracts/proxy/ERC1967/ERC1967Proxy.sol
View file @
6552adaf
...
@@ -27,6 +27,6 @@ contract ERC1967Proxy is Proxy, ERC1967Upgrade {
...
@@ -27,6 +27,6 @@ contract ERC1967Proxy is Proxy, ERC1967Upgrade {
* @dev Returns the current implementation address.
* @dev Returns the current implementation address.
*/
*/
function _implementation() internal view virtual override returns (address impl) {
function _implementation() internal view virtual override returns (address impl) {
return ERC1967
Storag
e._getImplementation();
return ERC1967
Upgrad
e._getImplementation();
}
}
}
}
contracts/proxy/ERC1967/ERC1967Storage.sol
deleted
100644 → 0
View file @
a664fb1e
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../beacon/IBeacon.sol";
import "../../utils/Address.sol";
import "../../utils/StorageSlot.sol";
/**
* @dev This abstract contract provides setters and getters for the different
* https://eips.ethereum.org/EIPS/eip-1967[EIP1967] storage slots.
*
* _Available since v4.1._
*/
abstract contract ERC1967Storage {
/**
* @dev Storage slot with the address of the current implementation.
* This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is
* validated in the constructor.
*/
bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
/**
* @dev Returns the current implementation address.
*/
function _getImplementation() internal view returns (address) {
return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
}
/**
* @dev Stores a new address in the EIP1967 implementation slot.
*/
function _setImplementation(address newImplementation) internal {
require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
}
/**
* @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
* This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor.
*/
bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;
/**
* @dev Returns the current beacon.
*/
function _getBeacon() internal view returns (address) {
return StorageSlot.getAddressSlot(_BEACON_SLOT).value;
}
/**
* @dev Stores a new beacon in the EIP1967 beacon slot.
*/
function _setBeacon(address newBeacon) internal {
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;
}
/**
* @dev Storage slot with the admin of the contract.
* This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is
* validated in the constructor.
*/
bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
/**
* @dev Returns the current admin.
*/
function _getAdmin() internal view returns (address) {
return StorageSlot.getAddressSlot(_ADMIN_SLOT).value;
}
/**
* @dev Stores a new address in the EIP1967 admin slot.
*/
function _setAdmin(address newAdmin) internal {
require(newAdmin != address(0), "ERC1967: new admin is the zero address");
StorageSlot.getAddressSlot(_ADMIN_SLOT).value = newAdmin;
}
}
contracts/proxy/ERC1967/ERC1967Upgrade.sol
View file @
6552adaf
...
@@ -2,34 +2,48 @@
...
@@ -2,34 +2,48 @@
pragma solidity ^0.8.2;
pragma solidity ^0.8.2;
import "./ERC1967Storage.sol";
import "../beacon/IBeacon.sol";
import "../../utils/Address.sol";
import "../../utils/StorageSlot.sol";
/**
/**
* @dev This abstract contract provides event emitting update functions for
* @dev This abstract contract provides
getters and
event emitting update functions for
* https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.
* https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.
*
*
* _Available since v4.1._
* _Available since v4.1._
*
*
* @custom:oz-upgrades-unsafe-allow delegatecall
* @custom:oz-upgrades-unsafe-allow delegatecall
*/
*/
abstract contract ERC1967Upgrade
is ERC1967Storage
{
abstract contract ERC1967Upgrade {
// This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1
// This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1
bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143;
bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143;
/**
/**
* @dev Storage slot with the address of the current implementation.
* This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is
* validated in the constructor.
*/
bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
/**
* @dev Emitted when the implementation is upgraded.
* @dev Emitted when the implementation is upgraded.
*/
*/
event Upgraded(address indexed implementation);
event Upgraded(address indexed implementation);
/**
/**
* @dev
Emitted when the beacon is upgraded
.
* @dev
Returns the current implementation address
.
*/
*/
event BeaconUpgraded(address indexed beacon);
function _getImplementation() internal view returns (address) {
return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
}
/**
/**
* @dev
Emitted when the admin account has changed
.
* @dev
Stores a new address in the EIP1967 implementation slot
.
*/
*/
event AdminChanged(address previousAdmin, address newAdmin);
function _setImplementation(address newImplementation) private {
require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
}
/**
/**
* @dev Perform implementation upgrade
* @dev Perform implementation upgrade
...
@@ -104,6 +118,33 @@ abstract contract ERC1967Upgrade is ERC1967Storage {
...
@@ -104,6 +118,33 @@ abstract contract ERC1967Upgrade is ERC1967Storage {
}
}
/**
/**
* @dev Storage slot with the admin of the contract.
* This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is
* validated in the constructor.
*/
bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
/**
* @dev Emitted when the admin account has changed.
*/
event AdminChanged(address previousAdmin, address newAdmin);
/**
* @dev Returns the current admin.
*/
function _getAdmin() internal view returns (address) {
return StorageSlot.getAddressSlot(_ADMIN_SLOT).value;
}
/**
* @dev Stores a new address in the EIP1967 admin slot.
*/
function _setAdmin(address newAdmin) private {
require(newAdmin != address(0), "ERC1967: new admin is the zero address");
StorageSlot.getAddressSlot(_ADMIN_SLOT).value = newAdmin;
}
/**
* @dev Changes the admin of the proxy.
* @dev Changes the admin of the proxy.
*
*
* Emits an {AdminChanged} event.
* Emits an {AdminChanged} event.
...
@@ -112,4 +153,37 @@ abstract contract ERC1967Upgrade is ERC1967Storage {
...
@@ -112,4 +153,37 @@ abstract contract ERC1967Upgrade is ERC1967Storage {
emit AdminChanged(_getAdmin(), newAdmin);
emit AdminChanged(_getAdmin(), newAdmin);
_setAdmin(newAdmin);
_setAdmin(newAdmin);
}
}
/**
* @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
* This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor.
*/
bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;
/**
* @dev Emitted when the beacon is upgraded.
*/
event BeaconUpgraded(address indexed beacon);
/**
* @dev Returns the current beacon.
*/
function _getBeacon() internal view returns (address) {
return StorageSlot.getAddressSlot(_BEACON_SLOT).value;
}
/**
* @dev Stores a new beacon in the EIP1967 beacon slot.
*/
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;
}
}
}
contracts/proxy/README.adoc
View file @
6552adaf
...
@@ -40,8 +40,6 @@ When doing an upgrade, the second parameter of the {upgradeToAndCall} function a
...
@@ -40,8 +40,6 @@ When doing an upgrade, the second parameter of the {upgradeToAndCall} function a
{{ERC1967Proxy}}
{{ERC1967Proxy}}
{{ERC1967Storage}}
{{ERC1967Upgrade}}
{{ERC1967Upgrade}}
== UUPS
== UUPS
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment