This repository has been archived by the owner on Jan 24, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename: zos-lib contracts and zos command (#1074)
* Update contract names and references in code * Fix comment reference * Export admin & implementation slots references * Reference deprecated and now slot reference for both admin and implementation slots * Change bin name from zos to oz, and add aliases * Change admin and implementation keccak256 values * Fix leaked log in Bytecode.ts * Change some oz bin reference names * Uncomment tests * Remove commented code in contracts * Add check new proxy slots labels in tests * Add deprecated warning when calling `zos` bin * Change comment syntax * Use eip1967 for admin and implementation slots * Add legacy contracts as mocks for tests * Set eip1967 storage slots labels in Constants * Update packages/cli/src/bin/oz-cli.ts Co-Authored-By: Santiago Palladino <santiago@openzeppelin.com> * Enhance tests * Rollback changes in < 2.x deprecated contract
- Loading branch information
1 parent
7273429
commit 71c9ad7
Showing
38 changed files
with
524 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
packages/lib/contracts/mocks/zos/ZosAdminUpgradeabilityProxy.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
pragma solidity ^0.5.0; | ||
|
||
import './ZosBaseAdminUpgradeabilityProxy.sol'; | ||
|
||
/** | ||
* @title AdminUpgradeabilityProxy | ||
* @dev Extends from BaseAdminUpgradeabilityProxy with a constructor for | ||
* initializing the implementation, admin, and init data. | ||
*/ | ||
contract ZosAdminUpgradeabilityProxy is ZosBaseAdminUpgradeabilityProxy, ZosUpgradeabilityProxy { | ||
/** | ||
* Contract constructor. | ||
* @param _logic address of the initial implementation. | ||
* @param _admin Address of the proxy administrator. | ||
* @param _data Data to send as msg.data to the implementation to initialize the proxied contract. | ||
* It should include the signature and the parameters of the function to be called, as described in | ||
* https://solidity.readthedocs.io/en/v0.4.24/abi-spec.html#function-selector-and-argument-encoding. | ||
* This parameter is optional, if no data is given the initialization call to proxied contract will be skipped. | ||
*/ | ||
constructor(address _logic, address _admin, bytes memory _data) ZosUpgradeabilityProxy(_logic, _data) public payable { | ||
assert(ADMIN_SLOT == keccak256("org.zeppelinos.proxy.admin")); | ||
_setAdmin(_admin); | ||
} | ||
} |
120 changes: 120 additions & 0 deletions
120
packages/lib/contracts/mocks/zos/ZosBaseAdminUpgradeabilityProxy.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
pragma solidity ^0.5.0; | ||
|
||
import './ZosUpgradeabilityProxy.sol'; | ||
|
||
/** | ||
* @title BaseAdminUpgradeabilityProxy | ||
* @dev This contract combines an upgradeability proxy with an authorization | ||
* mechanism for administrative tasks. | ||
* All external functions in this contract must be guarded by the | ||
* `ifAdmin` modifier. See ethereum/solidity#3864 for a Solidity | ||
* feature proposal that would enable this to be done automatically. | ||
*/ | ||
contract ZosBaseAdminUpgradeabilityProxy is ZosBaseUpgradeabilityProxy { | ||
/** | ||
* @dev Emitted when the administration has been transferred. | ||
* @param previousAdmin Address of the previous admin. | ||
* @param newAdmin Address of the new admin. | ||
*/ | ||
event AdminChanged(address previousAdmin, address newAdmin); | ||
|
||
/** | ||
* @dev Storage slot with the admin of the contract. | ||
* This is the keccak-256 hash of "org.zeppelinos.proxy.admin", and is | ||
* validated in the constructor. | ||
*/ | ||
|
||
bytes32 internal constant ADMIN_SLOT = 0x10d6a54a4754c8869d6886b5f5d7fbfa5b4522237ea5c60d11bc4e7a1ff9390b; | ||
|
||
/** | ||
* @dev Modifier to check whether the `msg.sender` is the admin. | ||
* If it is, it will run the function. Otherwise, it will delegate the call | ||
* to the implementation. | ||
*/ | ||
modifier ifAdmin() { | ||
if (msg.sender == _admin()) { | ||
_; | ||
} else { | ||
_fallback(); | ||
} | ||
} | ||
|
||
/** | ||
* @return The address of the proxy admin. | ||
*/ | ||
function admin() external ifAdmin returns (address) { | ||
return _admin(); | ||
} | ||
|
||
/** | ||
* @return The address of the implementation. | ||
*/ | ||
function implementation() external ifAdmin returns (address) { | ||
return _implementation(); | ||
} | ||
|
||
/** | ||
* @dev Changes the admin of the proxy. | ||
* Only the current admin can call this function. | ||
* @param newAdmin Address to transfer proxy administration to. | ||
*/ | ||
function changeAdmin(address newAdmin) external ifAdmin { | ||
require(newAdmin != address(0), "Cannot change the admin of a proxy to the zero address"); | ||
emit AdminChanged(_admin(), newAdmin); | ||
_setAdmin(newAdmin); | ||
} | ||
|
||
/** | ||
* @dev Upgrade the backing implementation of the proxy. | ||
* Only the admin can call this function. | ||
* @param newImplementation Address of the new implementation. | ||
*/ | ||
function upgradeTo(address newImplementation) external ifAdmin { | ||
_upgradeTo(newImplementation); | ||
} | ||
|
||
/** | ||
* @dev Upgrade the backing implementation of the proxy and call a function | ||
* on the new implementation. | ||
* This is useful to initialize the proxied contract. | ||
* @param newImplementation Address of the new implementation. | ||
* @param data Data to send as msg.data in the low level call. | ||
* It should include the signature and the parameters of the function to be called, as described in | ||
* https://solidity.readthedocs.io/en/v0.4.24/abi-spec.html#function-selector-and-argument-encoding. | ||
*/ | ||
function upgradeToAndCall(address newImplementation, bytes calldata data) payable external ifAdmin { | ||
_upgradeTo(newImplementation); | ||
(bool success,) = newImplementation.delegatecall(data); | ||
require(success); | ||
} | ||
|
||
/** | ||
* @return The admin slot. | ||
*/ | ||
function _admin() internal view returns (address adm) { | ||
bytes32 slot = ADMIN_SLOT; | ||
assembly { | ||
adm := sload(slot) | ||
} | ||
} | ||
|
||
/** | ||
* @dev Sets the address of the proxy admin. | ||
* @param newAdmin Address of the new proxy admin. | ||
*/ | ||
function _setAdmin(address newAdmin) internal { | ||
bytes32 slot = ADMIN_SLOT; | ||
|
||
assembly { | ||
sstore(slot, newAdmin) | ||
} | ||
} | ||
|
||
/** | ||
* @dev Only fall back when the sender is not the admin. | ||
*/ | ||
function _willFallback() internal { | ||
require(msg.sender != _admin(), "Cannot call fallback function from the proxy admin"); | ||
super._willFallback(); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
packages/lib/contracts/mocks/zos/ZosBaseUpgradeabilityProxy.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
pragma solidity ^0.5.0; | ||
|
||
import '../../upgradeability/Proxy.sol'; | ||
import '../../utils/Address.sol'; | ||
|
||
/** | ||
* @title BaseUpgradeabilityProxy | ||
* @dev This contract implements a proxy that allows to change the | ||
* implementation address to which it will delegate. | ||
* Such a change is called an implementation upgrade. | ||
*/ | ||
contract ZosBaseUpgradeabilityProxy is Proxy { | ||
/** | ||
* @dev Emitted when the implementation is upgraded. | ||
* @param implementation Address of the new implementation. | ||
*/ | ||
event Upgraded(address indexed implementation); | ||
|
||
/** | ||
* @dev Storage slot with the address of the current implementation. | ||
* This is the keccak-256 hash of "org.zeppelinos.proxy.implementation", and is | ||
* validated in the constructor. | ||
*/ | ||
bytes32 internal constant IMPLEMENTATION_SLOT = 0x7050c9e0f4ca769c69bd3a8ef740bc37934f8e2c036e5a723fd8ee048ed3f8c3; | ||
|
||
/** | ||
* @dev Returns the current implementation. | ||
* @return Address of the current implementation | ||
*/ | ||
function _implementation() internal view returns (address impl) { | ||
bytes32 slot = IMPLEMENTATION_SLOT; | ||
assembly { | ||
impl := sload(slot) | ||
} | ||
} | ||
|
||
/** | ||
* @dev Upgrades the proxy to a new implementation. | ||
* @param newImplementation Address of the new implementation. | ||
*/ | ||
function _upgradeTo(address newImplementation) internal { | ||
_setImplementation(newImplementation); | ||
emit Upgraded(newImplementation); | ||
} | ||
|
||
/** | ||
* @dev Sets the implementation address of the proxy. | ||
* @param newImplementation Address of the new implementation. | ||
*/ | ||
function _setImplementation(address newImplementation) internal { | ||
require(OpenZeppelinUpgradesAddress.isContract(newImplementation), "Cannot set a proxy implementation to a non-contract address"); | ||
|
||
bytes32 slot = IMPLEMENTATION_SLOT; | ||
|
||
assembly { | ||
sstore(slot, newImplementation) | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
packages/lib/contracts/mocks/zos/ZosInitializableAdminUpgradeabilityProxy.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
pragma solidity ^0.5.0; | ||
|
||
import './ZosBaseAdminUpgradeabilityProxy.sol'; | ||
import './ZosInitializableUpgradeabilityProxy.sol'; | ||
|
||
/** | ||
* @title InitializableAdminUpgradeabilityProxy | ||
* @dev Extends from BaseAdminUpgradeabilityProxy with an initializer for | ||
* initializing the implementation, admin, and init data. | ||
*/ | ||
contract ZosInitializableAdminUpgradeabilityProxy is ZosBaseAdminUpgradeabilityProxy, ZosInitializableUpgradeabilityProxy { | ||
/** | ||
* Contract initializer. | ||
* @param _logic address of the initial implementation. | ||
* @param _admin Address of the proxy administrator. | ||
* @param _data Data to send as msg.data to the implementation to initialize the proxied contract. | ||
* It should include the signature and the parameters of the function to be called, as described in | ||
* https://solidity.readthedocs.io/en/v0.4.24/abi-spec.html#function-selector-and-argument-encoding. | ||
* This parameter is optional, if no data is given the initialization call to proxied contract will be skipped. | ||
*/ | ||
function initialize(address _logic, address _admin, bytes memory _data) public payable { | ||
require(_implementation() == address(0)); | ||
ZosInitializableUpgradeabilityProxy.initialize(_logic, _data); | ||
assert(ADMIN_SLOT == keccak256("org.zeppelinos.proxy.admin")); | ||
_setAdmin(_admin); | ||
} | ||
} |
Oops, something went wrong.