Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'master' into lib-805-transparent-proxy-immutable-admin
  • Loading branch information
ernestognw committed Jun 15, 2023
commit 5ad12bff3ce10afb7109ed68f34aaa40634a261d
8 changes: 2 additions & 6 deletions contracts/mocks/DummyImplementation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

pragma solidity ^0.8.19;

import "../interfaces/IERC1967.sol";
import "../utils/StorageSlot.sol";
import "../proxy/ERC1967/ERC1967Utils.sol";

abstract contract Impl {
function version() public pure virtual returns (string memory);
Expand All @@ -14,9 +13,6 @@ contract DummyImplementation {
string public text;
uint256[] public values;

// bytes32(uint256(keccak256('eip1967.proxy.admin')) - 1)
bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;

function initializeNonPayable() public {
value = 10;
}
Expand Down Expand Up @@ -54,7 +50,7 @@ contract DummyImplementation {
// Use for forcing an unsafe TransparentUpgradeableProxy admin override
// solhint-disable-next-line private-vars-leading-underscore
function _unsafeOverrideAdmin(address newAdmin) public {
StorageSlot.getAddressSlot(_ADMIN_SLOT).value = newAdmin;
StorageSlot.getAddressSlot(ERC1967Utils.ADMIN_SLOT).value = newAdmin;
}
}

Expand Down
4 changes: 2 additions & 2 deletions contracts/proxy/ERC1967/ERC1967Utils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ library ERC1967Utils {
* https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.
* `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103`
*/
function _getAdmin() internal view virtual returns (address) {
return StorageSlot.getAddressSlot(_ADMIN_SLOT).value;
function getAdmin() internal view returns (address) {
return StorageSlot.getAddressSlot(ADMIN_SLOT).value;
}

/**
Expand Down
13 changes: 2 additions & 11 deletions contracts/proxy/transparent/TransparentUpgradeableProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ contract TransparentUpgradeableProxy is ERC1967Proxy {
*/
constructor(address _logic, address admin_, bytes memory _data) payable ERC1967Proxy(_logic, _data) {
_admin = admin_;
_changeAdmin(admin_);
ERC1967Utils.changeAdmin(admin_);
}

/**
* @dev If caller is the admin process the call internally, otherwise transparently fallback to the proxy behavior
*/
function _fallback() internal virtual override {
if (msg.sender == ERC1967Utils.getAdmin()) {
if (msg.sender == _admin) {
bytes memory ret;
bytes4 selector = msg.sig;
if (selector == ITransparentUpgradeableProxy.upgradeTo.selector) {
Expand All @@ -100,15 +100,6 @@ contract TransparentUpgradeableProxy is ERC1967Proxy {
}
}

/**
* @dev Returns the current immutable admin.
*
* Overrides ERC1967's admin in favor of an immutable value to avoid unnecessary SLOADs on each proxy call.
*/
function _getAdmin() internal view virtual override returns (address) {
return _admin;
}

/**
* @dev Upgrade the implementation of the proxy.
*/
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.