Commit 8986f165 authored by smartcontracts's avatar smartcontracts Committed by GitHub

fix(ctb): solc warnings in ProxyAdmin.sol (#2952)

Addresses solc warnings in ProxyAdmin.sol. Also changes the input type
from Proxy to address payable because it is *not* guaranteed that the
input will actually be of Proxy type.
parent 42a4cc30
---
'@eth-optimism/contracts-bedrock': patch
---
Fix solc warnings in ProxyAdmin
...@@ -103,18 +103,18 @@ contract ProxyAdmin_Test is Test { ...@@ -103,18 +103,18 @@ contract ProxyAdmin_Test is Test {
} }
function test_erc1967GetProxyImplementation() external { function test_erc1967GetProxyImplementation() external {
getProxyImplementation(proxy); getProxyImplementation(payable(proxy));
} }
function test_chugsplashGetProxyImplementation() external { function test_chugsplashGetProxyImplementation() external {
getProxyImplementation(Proxy(payable(chugsplash))); getProxyImplementation(payable(chugsplash));
} }
function test_delegateResolvedGetProxyImplementation() external { function test_delegateResolvedGetProxyImplementation() external {
getProxyImplementation(Proxy(payable(resolved))); getProxyImplementation(payable(resolved));
} }
function getProxyImplementation(Proxy _proxy) internal { function getProxyImplementation(address payable _proxy) internal {
{ {
address impl = admin.getProxyImplementation(_proxy); address impl = admin.getProxyImplementation(_proxy);
assertEq(impl, address(0)); assertEq(impl, address(0));
...@@ -130,35 +130,35 @@ contract ProxyAdmin_Test is Test { ...@@ -130,35 +130,35 @@ contract ProxyAdmin_Test is Test {
} }
function test_erc1967GetProxyAdmin() external { function test_erc1967GetProxyAdmin() external {
getProxyAdmin(proxy); getProxyAdmin(payable(proxy));
} }
function test_chugsplashGetProxyAdmin() external { function test_chugsplashGetProxyAdmin() external {
getProxyAdmin(Proxy(payable(chugsplash))); getProxyAdmin(payable(chugsplash));
} }
function test_delegateResolvedGetProxyAdmin() external { function test_delegateResolvedGetProxyAdmin() external {
getProxyAdmin(Proxy(payable(resolved))); getProxyAdmin(payable(resolved));
} }
function getProxyAdmin(Proxy _proxy) internal { function getProxyAdmin(address payable _proxy) internal {
address owner = admin.getProxyAdmin(_proxy); address owner = admin.getProxyAdmin(_proxy);
assertEq(owner, address(admin)); assertEq(owner, address(admin));
} }
function test_erc1967ChangeProxyAdmin() external { function test_erc1967ChangeProxyAdmin() external {
changeProxyAdmin(proxy); changeProxyAdmin(payable(proxy));
} }
function test_chugsplashChangeProxyAdmin() external { function test_chugsplashChangeProxyAdmin() external {
changeProxyAdmin(Proxy(payable(chugsplash))); changeProxyAdmin(payable(chugsplash));
} }
function test_delegateResolvedChangeProxyAdmin() external { function test_delegateResolvedChangeProxyAdmin() external {
changeProxyAdmin(Proxy(payable(resolved))); changeProxyAdmin(payable(resolved));
} }
function changeProxyAdmin(Proxy _proxy) internal { function changeProxyAdmin(address payable _proxy) internal {
ProxyAdmin.ProxyType proxyType = admin.proxyType(address(_proxy)); ProxyAdmin.ProxyType proxyType = admin.proxyType(address(_proxy));
vm.prank(alice); vm.prank(alice);
...@@ -184,7 +184,7 @@ contract ProxyAdmin_Test is Test { ...@@ -184,7 +184,7 @@ contract ProxyAdmin_Test is Test {
// Different proxy types have different interfaces. // Different proxy types have different interfaces.
vm.prank(address(128)); vm.prank(address(128));
if (proxyType == ProxyAdmin.ProxyType.ERC1967) { if (proxyType == ProxyAdmin.ProxyType.ERC1967) {
assertEq(_proxy.admin(), address(128)); assertEq(Proxy(payable(_proxy)).admin(), address(128));
} else if (proxyType == ProxyAdmin.ProxyType.Chugsplash) { } else if (proxyType == ProxyAdmin.ProxyType.Chugsplash) {
assertEq( assertEq(
L1ChugSplashProxy(payable(_proxy)).getOwner(), L1ChugSplashProxy(payable(_proxy)).getOwner(),
...@@ -201,18 +201,18 @@ contract ProxyAdmin_Test is Test { ...@@ -201,18 +201,18 @@ contract ProxyAdmin_Test is Test {
} }
function test_erc1967Upgrade() external { function test_erc1967Upgrade() external {
upgrade(proxy); upgrade(payable(proxy));
} }
function test_chugsplashUpgrade() external { function test_chugsplashUpgrade() external {
upgrade(Proxy(payable(chugsplash))); upgrade(payable(chugsplash));
} }
function test_delegateResolvedUpgrade() external { function test_delegateResolvedUpgrade() external {
upgrade(Proxy(payable(resolved))); upgrade(payable(resolved));
} }
function upgrade(Proxy _proxy) internal { function upgrade(address payable _proxy) internal {
vm.prank(alice); vm.prank(alice);
admin.upgrade(_proxy, address(implementation)); admin.upgrade(_proxy, address(implementation));
...@@ -221,18 +221,18 @@ contract ProxyAdmin_Test is Test { ...@@ -221,18 +221,18 @@ contract ProxyAdmin_Test is Test {
} }
function test_erc1967UpgradeAndCall() external { function test_erc1967UpgradeAndCall() external {
upgradeAndCall(proxy); upgradeAndCall(payable(proxy));
} }
function test_chugsplashUpgradeAndCall() external { function test_chugsplashUpgradeAndCall() external {
upgradeAndCall(Proxy(payable(chugsplash))); upgradeAndCall(payable(chugsplash));
} }
function test_delegateResolvedUpgradeAndCall() external { function test_delegateResolvedUpgradeAndCall() external {
upgradeAndCall(Proxy(payable(resolved))); upgradeAndCall(payable(resolved));
} }
function upgradeAndCall(Proxy _proxy) internal { function upgradeAndCall(address payable _proxy) internal {
vm.prank(alice); vm.prank(alice);
admin.upgradeAndCall( admin.upgradeAndCall(
_proxy, _proxy,
...@@ -249,13 +249,13 @@ contract ProxyAdmin_Test is Test { ...@@ -249,13 +249,13 @@ contract ProxyAdmin_Test is Test {
function test_onlyOwner() external { function test_onlyOwner() external {
vm.expectRevert("UNAUTHORIZED"); vm.expectRevert("UNAUTHORIZED");
admin.changeProxyAdmin(proxy, address(0)); admin.changeProxyAdmin(payable(proxy), address(0));
vm.expectRevert("UNAUTHORIZED"); vm.expectRevert("UNAUTHORIZED");
admin.upgrade(proxy, address(implementation)); admin.upgrade(payable(proxy), address(implementation));
vm.expectRevert("UNAUTHORIZED"); vm.expectRevert("UNAUTHORIZED");
admin.upgradeAndCall(proxy, address(implementation), hex""); admin.upgradeAndCall(payable(proxy), address(implementation), hex"");
} }
function test_isUpgrading() external { function test_isUpgrading() external {
......
...@@ -152,15 +152,14 @@ contract ProxyAdmin is Owned { ...@@ -152,15 +152,14 @@ contract ProxyAdmin is Owned {
* *
* @return Address of the implementation of the proxy. * @return Address of the implementation of the proxy.
*/ */
function getProxyImplementation(Proxy _proxy) external view returns (address) { function getProxyImplementation(address _proxy) external view returns (address) {
ProxyType proxyType = proxyType[address(_proxy)]; ProxyType ptype = proxyType[_proxy];
if (ptype == ProxyType.ERC1967) {
if (proxyType == ProxyType.ERC1967) { return IStaticERC1967Proxy(_proxy).implementation();
return IStaticERC1967Proxy(address(_proxy)).implementation(); } else if (ptype == ProxyType.Chugsplash) {
} else if (proxyType == ProxyType.Chugsplash) { return IStaticL1ChugSplashProxy(_proxy).getImplementation();
return IStaticL1ChugSplashProxy(address(_proxy)).getImplementation(); } else if (ptype == ProxyType.ResolvedDelegate) {
} else if (proxyType == ProxyType.ResolvedDelegate) { return addressManager.getAddress(implementationName[_proxy]);
return addressManager.getAddress(implementationName[address(_proxy)]);
} else { } else {
revert("ProxyAdmin: unknown proxy type"); revert("ProxyAdmin: unknown proxy type");
} }
...@@ -173,14 +172,13 @@ contract ProxyAdmin is Owned { ...@@ -173,14 +172,13 @@ contract ProxyAdmin is Owned {
* *
* @return Address of the admin of the proxy. * @return Address of the admin of the proxy.
*/ */
function getProxyAdmin(Proxy _proxy) external view returns (address) { function getProxyAdmin(address payable _proxy) external view returns (address) {
ProxyType proxyType = proxyType[address(_proxy)]; ProxyType ptype = proxyType[_proxy];
if (ptype == ProxyType.ERC1967) {
if (proxyType == ProxyType.ERC1967) { return IStaticERC1967Proxy(_proxy).admin();
return IStaticERC1967Proxy(address(_proxy)).admin(); } else if (ptype == ProxyType.Chugsplash) {
} else if (proxyType == ProxyType.Chugsplash) { return IStaticL1ChugSplashProxy(_proxy).getOwner();
return IStaticL1ChugSplashProxy(address(_proxy)).getOwner(); } else if (ptype == ProxyType.ResolvedDelegate) {
} else if (proxyType == ProxyType.ResolvedDelegate) {
return addressManager.owner(); return addressManager.owner();
} else { } else {
revert("ProxyAdmin: unknown proxy type"); revert("ProxyAdmin: unknown proxy type");
...@@ -193,14 +191,13 @@ contract ProxyAdmin is Owned { ...@@ -193,14 +191,13 @@ contract ProxyAdmin is Owned {
* @param _proxy Address of the proxy to update. * @param _proxy Address of the proxy to update.
* @param _newAdmin Address of the new proxy admin. * @param _newAdmin Address of the new proxy admin.
*/ */
function changeProxyAdmin(Proxy _proxy, address _newAdmin) external onlyOwner { function changeProxyAdmin(address payable _proxy, address _newAdmin) external onlyOwner {
ProxyType proxyType = proxyType[address(_proxy)]; ProxyType ptype = proxyType[_proxy];
if (ptype == ProxyType.ERC1967) {
if (proxyType == ProxyType.ERC1967) { Proxy(_proxy).changeAdmin(_newAdmin);
_proxy.changeAdmin(_newAdmin); } else if (ptype == ProxyType.Chugsplash) {
} else if (proxyType == ProxyType.Chugsplash) { L1ChugSplashProxy(_proxy).setOwner(_newAdmin);
L1ChugSplashProxy(payable(_proxy)).setOwner(_newAdmin); } else if (ptype == ProxyType.ResolvedDelegate) {
} else if (proxyType == ProxyType.ResolvedDelegate) {
addressManager.transferOwnership(_newAdmin); addressManager.transferOwnership(_newAdmin);
} else { } else {
revert("ProxyAdmin: unknown proxy type"); revert("ProxyAdmin: unknown proxy type");
...@@ -213,18 +210,17 @@ contract ProxyAdmin is Owned { ...@@ -213,18 +210,17 @@ contract ProxyAdmin is Owned {
* @param _proxy Address of the proxy to upgrade. * @param _proxy Address of the proxy to upgrade.
* @param _implementation Address of the new implementation address. * @param _implementation Address of the new implementation address.
*/ */
function upgrade(Proxy _proxy, address _implementation) public onlyOwner { function upgrade(address payable _proxy, address _implementation) public onlyOwner {
ProxyType proxyType = proxyType[address(_proxy)]; ProxyType ptype = proxyType[_proxy];
if (ptype == ProxyType.ERC1967) {
if (proxyType == ProxyType.ERC1967) { Proxy(_proxy).upgradeTo(_implementation);
_proxy.upgradeTo(_implementation); } else if (ptype == ProxyType.Chugsplash) {
} else if (proxyType == ProxyType.Chugsplash) { L1ChugSplashProxy(_proxy).setStorage(
L1ChugSplashProxy(payable(_proxy)).setStorage(
0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc, 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc,
bytes32(uint256(uint160(_implementation))) bytes32(uint256(uint160(_implementation)))
); );
} else if (proxyType == ProxyType.ResolvedDelegate) { } else if (ptype == ProxyType.ResolvedDelegate) {
string memory name = implementationName[address(_proxy)]; string memory name = implementationName[_proxy];
addressManager.setAddress(name, _implementation); addressManager.setAddress(name, _implementation);
} else { } else {
revert("ProxyAdmin: unknown proxy type"); revert("ProxyAdmin: unknown proxy type");
...@@ -240,19 +236,18 @@ contract ProxyAdmin is Owned { ...@@ -240,19 +236,18 @@ contract ProxyAdmin is Owned {
* @param _data Data to trigger the new implementation with. * @param _data Data to trigger the new implementation with.
*/ */
function upgradeAndCall( function upgradeAndCall(
Proxy _proxy, address payable _proxy,
address _implementation, address _implementation,
bytes memory _data bytes memory _data
) external payable onlyOwner { ) external payable onlyOwner {
ProxyType proxyType = proxyType[address(_proxy)]; ProxyType ptype = proxyType[_proxy];
if (ptype == ProxyType.ERC1967) {
if (proxyType == ProxyType.ERC1967) { Proxy(_proxy).upgradeToAndCall{ value: msg.value }(_implementation, _data);
_proxy.upgradeToAndCall{ value: msg.value }(_implementation, _data);
} else { } else {
// reverts if proxy type is unknown // reverts if proxy type is unknown
upgrade(_proxy, _implementation); upgrade(_proxy, _implementation);
(bool success, ) = address(_proxy).call{ value: msg.value }(_data); (bool success, ) = _proxy.call{ value: msg.value }(_data);
require(success); require(success, "ProxyAdmin: call to proxy after upgrade failed");
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment