Skip to content

Commit c3aec1c

Browse files
committed
move upgradeToAndCallUUPS to UUPSUpgradeable
1 parent ff85c7b commit c3aec1c

File tree

3 files changed

+24
-38
lines changed

3 files changed

+24
-38
lines changed

contracts/proxy/ERC1967/ERC1967Utils.sol

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ pragma solidity ^0.8.20;
55

66
import "../beacon/IBeacon.sol";
77
import "../../interfaces/IERC1967.sol";
8-
import "../../interfaces/draft-IERC1822.sol";
98
import "../../utils/Address.sol";
109
import "../../utils/StorageSlot.sol";
1110

@@ -59,11 +58,6 @@ library ERC1967Utils {
5958
*/
6059
error ERC1967InvalidBeacon(address beacon);
6160

62-
/**
63-
* @dev The storage `slot` is unsupported as a UUID.
64-
*/
65-
error ERC1967UnsupportedProxiableUUID(bytes32 slot);
66-
6761
/**
6862
* @dev Returns the current implementation address.
6963
*/
@@ -103,30 +97,6 @@ library ERC1967Utils {
10397
}
10498
}
10599

106-
/**
107-
* @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call.
108-
*
109-
* Emits an {IERC1967-Upgraded} event.
110-
*/
111-
function upgradeToAndCallUUPS(address newImplementation, bytes memory data, bool forceCall) internal {
112-
// Upgrades from old implementations will perform a rollback test. This test requires the new
113-
// implementation to upgrade back to the old, non-ERC1822 compliant, implementation. Removing
114-
// this special case will break upgrade paths from old UUPS implementation to new ones.
115-
if (StorageSlot.getBooleanSlot(_ROLLBACK_SLOT).value) {
116-
_setImplementation(newImplementation);
117-
} else {
118-
try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) {
119-
if (slot != IMPLEMENTATION_SLOT) {
120-
revert ERC1967UnsupportedProxiableUUID(slot);
121-
}
122-
} catch {
123-
// The implementation is not UUPS
124-
revert ERC1967InvalidImplementation(newImplementation);
125-
}
126-
upgradeToAndCall(newImplementation, data, forceCall);
127-
}
128-
}
129-
130100
/**
131101
* @dev Storage slot with the admin of the contract.
132102
* This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is

contracts/proxy/utils/UUPSUpgradeable.sol

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ abstract contract UUPSUpgradeable is IERC1822Proxiable {
2727
*/
2828
error UUPSUnauthorizedCallContext();
2929

30+
/**
31+
* @dev The storage `slot` is unsupported as a UUID.
32+
*/
33+
error UUPSUnsupportedProxiableUUID(bytes32 slot);
34+
3035
/**
3136
* @dev Check that the execution is being performed through a delegatecall call and that the execution context is
3237
* a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case
@@ -81,7 +86,7 @@ abstract contract UUPSUpgradeable is IERC1822Proxiable {
8186
*/
8287
function upgradeTo(address newImplementation) public virtual onlyProxy {
8388
_authorizeUpgrade(newImplementation);
84-
ERC1967Utils.upgradeToAndCallUUPS(newImplementation, new bytes(0), false);
89+
_upgradeToAndCallUUPS(newImplementation, new bytes(0), false);
8590
}
8691

8792
/**
@@ -96,7 +101,7 @@ abstract contract UUPSUpgradeable is IERC1822Proxiable {
96101
*/
97102
function upgradeToAndCall(address newImplementation, bytes memory data) public payable virtual onlyProxy {
98103
_authorizeUpgrade(newImplementation);
99-
ERC1967Utils.upgradeToAndCallUUPS(newImplementation, data, true);
104+
_upgradeToAndCallUUPS(newImplementation, data, true);
100105
}
101106

102107
/**
@@ -110,4 +115,21 @@ abstract contract UUPSUpgradeable is IERC1822Proxiable {
110115
* ```
111116
*/
112117
function _authorizeUpgrade(address newImplementation) internal virtual;
118+
119+
/**
120+
* @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call.
121+
*
122+
* Emits an {IERC1967-Upgraded} event.
123+
*/
124+
function _upgradeToAndCallUUPS(address newImplementation, bytes memory data, bool forceCall) private {
125+
try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) {
126+
if (slot != ERC1967Utils.IMPLEMENTATION_SLOT) {
127+
revert UUPSUnsupportedProxiableUUID(slot);
128+
}
129+
} catch {
130+
// The implementation is not UUPS
131+
revert ERC1967Utils.ERC1967InvalidImplementation(newImplementation);
132+
}
133+
ERC1967Utils.upgradeToAndCall(newImplementation, data, forceCall);
134+
}
113135
}

test/proxy/utils/UUPSUpgradeable.test.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,6 @@ contract('UUPSUpgradeable', function () {
7171
);
7272

7373
const receipt = await legacyInstance.upgradeTo(this.implInitial.address);
74-
75-
const UpgradedEvents = receipt.logs.filter(
76-
({ address, event }) => address === legacyInstance.address && event === 'Upgraded',
77-
);
78-
expect(UpgradedEvents.length).to.be.equal(1);
79-
8074
expectEvent(receipt, 'Upgraded', { implementation: this.implInitial.address });
8175

8276
const implementationSlot = await getSlot(legacyInstance, ImplementationSlot);

0 commit comments

Comments
 (0)