// SPDX-License-Identifier: LGPL-3.0-only pragma solidity >=0.7.0 <0.9.0; import {Enum} from "../../libraries/Enum.sol"; import {BaseGuard} from "./BaseGuard.sol"; /** * @title DelegateCallTransactionGuard - Limits delegate calls to a specific target. * @author Richard Meissner - @rmeissner */ contract DelegateCallTransactionGuard is BaseGuard { address public immutable ALLOWED_TARGET; constructor(address target) { ALLOWED_TARGET = target; } // solhint-disable-next-line payable-fallback fallback() external { // We don't revert on fallback to avoid issues in case of a Safe upgrade // E.g. The expected check method might change and then the Safe would be locked. } /** * @notice Called by the Safe contract before a transaction is executed. * @dev Reverts if the transaction is a delegate call to a contract other than the allowed one. * @param to Destination address of Safe transaction. * @param operation Operation type of Safe transaction. */ function checkTransaction( address to, uint256, bytes memory, Enum.Operation operation, uint256, uint256, uint256, address, // solhint-disable-next-line no-unused-vars address payable, bytes memory, address ) external view override { require(operation != Enum.Operation.DelegateCall || to == ALLOWED_TARGET, "This call is restricted"); } /** * @notice Called by the Safe contract after a transaction is executed. * @dev No-op. */ function checkAfterExecution(bytes32, bool) external view override {} /** * @notice Called by the Safe contract before a transaction is executed via a module. * @param to Destination address of Safe transaction. * @param value Ether value of Safe transaction. * @param data Data payload of Safe transaction. * @param operation Operation type of Safe transaction. * @param module Module executing the transaction. */ function checkModuleTransaction( address to, uint256 value, bytes memory data, Enum.Operation operation, address module ) external view override returns (bytes32 moduleTxHash) { require(operation != Enum.Operation.DelegateCall || to == ALLOWED_TARGET, "This call is restricted"); moduleTxHash = keccak256(abi.encodePacked(to, value, data, operation, module)); } /** * @notice Called by the Safe contract after a module transaction is executed. * @dev No-op. */ function checkAfterModuleExecution(bytes32, bool) external view override {} }