Replace error strings with custom errors (#4261)

This commit is contained in:
Francisco Giordano
2023-06-06 01:08:31 -03:00
parent 253bfa68c2
commit 99a4cfca17
133 changed files with 3157 additions and 1204 deletions

View File

@ -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));
}
_;
}