Skip to content
23 changes: 15 additions & 8 deletions contracts/governance/Governor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,7 @@ abstract contract Governor is Context, ERC165, EIP712, Nonces, IGovernor, IERC72
* governance protocol (since v4.6).
*/
modifier onlyGovernance() {
if (_executor() != _msgSender()) {
revert GovernorOnlyExecutor(_msgSender());
}
if (_executor() != address(this)) {
bytes32 msgDataHash = keccak256(_msgData());
// loop until popping the expected operation - throw if deque is empty (operation not authorized)
while (_governanceCall.popFront() != msgDataHash) {}
}
_checkGovernance();
_;
}

Expand Down Expand Up @@ -227,6 +220,20 @@ abstract contract Governor is Context, ERC165, EIP712, Nonces, IGovernor, IERC72
return _proposals[proposalId].proposer;
}

/**
* @dev Throws if the executor is not the owner.
*/
function _checkGovernance() internal virtual {
if (_executor() != _msgSender()) {
revert GovernorOnlyExecutor(_msgSender());
}
if (_executor() != address(this)) {
bytes32 msgDataHash = keccak256(_msgData());
// loop until popping the expected operation - throw if deque is empty (operation not authorized)
while (_governanceCall.popFront() != msgDataHash) {}
}
}

/**
* @dev Amount of votes already cast passes the threshold limit.
*/
Expand Down
9 changes: 8 additions & 1 deletion contracts/proxy/utils/Initializable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,17 @@ abstract contract Initializable {
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
_checkInitializing();
_;
}

/**
* @dev Throws if not Initializing.
*/
function _checkInitializing() internal view virtual {
if (!_initializing) {
revert NotInitializing();
}
_;
}

/**
Expand Down
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