Replace error strings with custom errors (#4261)
This commit is contained in:
@ -22,6 +22,11 @@ abstract contract UUPSUpgradeable is IERC1822Proxiable, ERC1967Upgrade {
|
||||
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment
|
||||
address private immutable __self = address(this);
|
||||
|
||||
/**
|
||||
* @dev The call is from an unauthorized context.
|
||||
*/
|
||||
error UUPSUnauthorizedCallContext(address context);
|
||||
|
||||
/**
|
||||
* @dev Check that the execution is being performed through a delegatecall call and that the execution context is
|
||||
* a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case
|
||||
@ -30,8 +35,15 @@ abstract contract UUPSUpgradeable is IERC1822Proxiable, ERC1967Upgrade {
|
||||
* fail.
|
||||
*/
|
||||
modifier onlyProxy() {
|
||||
require(address(this) != __self, "Function must be called through delegatecall");
|
||||
require(_getImplementation() == __self, "Function must be called through active proxy");
|
||||
if (address(this) == __self) {
|
||||
// Must be called through delegatecall
|
||||
revert UUPSUnauthorizedCallContext(address(this));
|
||||
}
|
||||
address implementation = _getImplementation();
|
||||
if (implementation != __self) {
|
||||
// Must be called through an active proxy
|
||||
revert UUPSUnauthorizedCallContext(implementation);
|
||||
}
|
||||
_;
|
||||
}
|
||||
|
||||
@ -40,7 +52,10 @@ abstract contract UUPSUpgradeable is IERC1822Proxiable, ERC1967Upgrade {
|
||||
* callable on the implementing contract but not through proxies.
|
||||
*/
|
||||
modifier notDelegated() {
|
||||
require(address(this) == __self, "UUPSUpgradeable: must not be called through delegatecall");
|
||||
if (address(this) != __self) {
|
||||
// Must not be called through delegatecall
|
||||
revert UUPSUnauthorizedCallContext(address(this));
|
||||
}
|
||||
_;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user