Skip to content
Prev Previous commit
Next Next commit
Replace the onlyProxy code with an internal function called _checkPro…
…xy and the notDelegated code with a _checkNotDelegated internal function
  • Loading branch information
allwin199 committed Jul 21, 2023
commit 8de0e9f321b577223f9a5530d2448dd6d05d8574
35 changes: 25 additions & 10 deletions contracts/proxy/utils/UUPSUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,7 @@ abstract contract UUPSUpgradeable is IERC1822Proxiable {
* fail.
*/
modifier onlyProxy() {
if (
address(this) == __self || // Must be called through delegatecall
ERC1967Utils.getImplementation() != __self // Must be called through an active proxy
) {
revert UUPSUnauthorizedCallContext();
}
_checkProxy();
_;
}

Expand All @@ -62,10 +57,7 @@ abstract contract UUPSUpgradeable is IERC1822Proxiable {
* callable on the implementing contract but not through proxies.
*/
modifier notDelegated() {
if (address(this) != __self) {
// Must not be called through delegatecall
revert UUPSUnauthorizedCallContext();
}
_checkNotDelegated();
_;
}

Expand Down Expand Up @@ -96,6 +88,29 @@ abstract contract UUPSUpgradeable is IERC1822Proxiable {
_upgradeToAndCallUUPS(newImplementation, data);
}

/**
* @dev Throws if the execution is not being performed through a delegatecall call
* Throws if not called through an active proxy
*/
function _checkProxy() internal view virtual {
if (
address(this) == __self || // Must be called through delegatecall
ERC1967Utils.getImplementation() != __self // Must be called through an active proxy
) {
revert UUPSUnauthorizedCallContext();
}
}

/**
* @dev Throws if called through a delegate call
*/
function _checkNotDelegated() internal view virtual {
if (address(this) != __self) {
// Must not be called through delegatecall
revert UUPSUnauthorizedCallContext();
}
}

/**
* @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by
* {upgradeToAndCall}.
Expand Down