mirror of
https://github.com/luxdao/zodiac.git
synced 2026-10-30 20:34:38 +00:00
60 lines
18 KiB
JSON
60 lines
18 KiB
JSON
{
|
|
"contractName": "ScopeGuard",
|
|
"sourceName": "contracts/ScopeGuard.sol",
|
|
"compilerVersion": "v0.8.6+commit.11564f7e",
|
|
"constructorArguments": "",
|
|
"input": {
|
|
"language": "Solidity",
|
|
"sources": {
|
|
"contracts/ScopeGuard.sol": {
|
|
"content": "// SPDX-License-Identifier: LGPL-3.0-only\npragma solidity ^0.8.6;\n\nimport \"@gnosis.pm/zodiac/contracts/guard/BaseGuard.sol\";\nimport \"@gnosis.pm/zodiac/contracts/factory/FactoryFriendly.sol\";\n\ncontract ScopeGuard is FactoryFriendly, BaseGuard {\n event SetTargetAllowed(address target, bool allowed);\n event SetTargetScoped(address target, bool scoped);\n event SetFallbackAllowedOnTarget(address target, bool allowed);\n event SetValueAllowedOnTarget(address target, bool allowed);\n event SetDelegateCallAllowedOnTarget(address target, bool allowed);\n event SetFunctionAllowedOnTarget(\n address target,\n bytes4 functionSig,\n bool allowed\n );\n event ScopeGuardSetup(address indexed initiator, address indexed owner);\n\n constructor(address _owner) {\n bytes memory initializeParams = abi.encode(_owner);\n setUp(initializeParams);\n }\n\n /// @dev Initialize function, will be triggered when a new proxy is deployed\n /// @param initializeParams Parameters of initialization encoded\n function setUp(bytes memory initializeParams) public override {\n __Ownable_init();\n address _owner = abi.decode(initializeParams, (address));\n\n transferOwnership(_owner);\n\n emit ScopeGuardSetup(msg.sender, _owner);\n }\n\n struct Target {\n bool allowed;\n bool scoped;\n bool delegateCallAllowed;\n bool fallbackAllowed;\n bool valueAllowed;\n mapping(bytes4 => bool) allowedFunctions;\n }\n\n mapping(address => Target) public allowedTargets;\n\n /// @dev Set whether or not calls can be made to an address.\n /// @notice Only callable by owner.\n /// @param target Address to be allowed/disallowed.\n /// @param allow Bool to allow (true) or disallow (false) calls to target.\n function setTargetAllowed(address target, bool allow) public onlyOwner {\n allowedTargets[target].allowed = allow;\n emit SetTargetAllowed(target, allowedTargets[target].allowed);\n }\n\n /// @dev Set whether or not delegate calls can be made to a target.\n /// @notice Only callable by owner.\n /// @param target Address to which delegate calls should be allowed/disallowed.\n /// @param allow Bool to allow (true) or disallow (false) delegate calls to target.\n function setDelegateCallAllowedOnTarget(address target, bool allow)\n public\n onlyOwner\n {\n allowedTargets[target].delegateCallAllowed = allow;\n emit SetDelegateCallAllowedOnTarget(\n target,\n allowedTargets[target].delegateCallAllowed\n );\n }\n\n /// @dev Sets whether or not calls to an address should be scoped to specific function signatures.\n /// @notice Only callable by owner.\n /// @param target Address to be scoped/unscoped.\n /// @param scoped Bool to scope (true) or unscope (false) function calls on target.\n function setScoped(address target, bool scoped) public onlyOwner {\n allowedTargets[target].scoped = scoped;\n emit SetTargetScoped(target, allowedTargets[target].scoped);\n }\n\n /// @dev Sets whether or not a target can be sent to (incluces fallback/receive functions).\n /// @notice Only callable by owner.\n /// @param target Address to be allow/disallow sends to.\n /// @param allow Bool to allow (true) or disallow (false) sends on target.\n function setFallbackAllowedOnTarget(address target, bool allow)\n public\n onlyOwner\n {\n allowedTargets[target].fallbackAllowed = allow;\n emit SetFallbackAllowedOnTarget(\n target,\n allowedTargets[target].fallbackAllowed\n );\n }\n\n /// @dev Sets whether or not a target can be sent to (incluces fallback/receive functions).\n /// @notice Only callable by owner.\n /// @param target Address to be allow/disallow sends to.\n /// @param allow Bool to allow (true) or disallow (false) sends on target.\n function setValueAllowedOnTarget(address target, bool allow)\n public\n onlyOwner\n {\n allowedTargets[target].valueAllowed = allow;\n emit SetValueAllowedOnTarget(\n target,\n allowedTargets[target].valueAllowed\n );\n }\n\n /// @dev Sets whether or not a specific function signature should be allowed on a scoped target.\n /// @notice Only callable by owner.\n /// @param target Scoped address on which a function signature should be allowed/disallowed.\n /// @param functionSig Function signature to be allowed/disallowed.\n /// @param allow Bool to allow (true) or disallow (false) calls a function signature on target.\n function setAllowedFunction(\n address target,\n bytes4 functionSig,\n bool allow\n ) public onlyOwner {\n allowedTargets[target].allowedFunctions[functionSig] = allow;\n emit SetFunctionAllowedOnTarget(\n target,\n functionSig,\n allowedTargets[target].allowedFunctions[functionSig]\n );\n }\n\n /// @dev Returns bool to indicate if an address is an allowed target.\n /// @param target Address to check.\n function isAllowedTarget(address target) public view returns (bool) {\n return (allowedTargets[target].allowed);\n }\n\n /// @dev Returns bool to indicate if an address is scoped.\n /// @param target Address to check.\n function isScoped(address target) public view returns (bool) {\n return (allowedTargets[target].scoped);\n }\n\n /// @dev Returns bool to indicate if fallback is allowed to a target.\n /// @param target Address to check.\n function isfallbackAllowed(address target) public view returns (bool) {\n return (allowedTargets[target].fallbackAllowed);\n }\n\n /// @dev Returns bool to indicate if ETH can be sent to a target.\n /// @param target Address to check.\n function isValueAllowed(address target) public view returns (bool) {\n return (allowedTargets[target].valueAllowed);\n }\n\n /// @dev Returns bool to indicate if a function signature is allowed for a target address.\n /// @param target Address to check.\n /// @param functionSig Signature to check.\n function isAllowedFunction(address target, bytes4 functionSig)\n public\n view\n returns (bool)\n {\n return (allowedTargets[target].allowedFunctions[functionSig]);\n }\n\n /// @dev Returns bool to indicate if delegate calls are allowed to a target address.\n /// @param target Address to check.\n function isAllowedToDelegateCall(address target)\n public\n view\n returns (bool)\n {\n return (allowedTargets[target].delegateCallAllowed);\n }\n\n // solhint-disallow-next-line payable-fallback\n fallback() external {\n // We don't revert on fallback to avoid issues in case of a Safe upgrade\n // E.g. The expected check method might change and then the Safe would be locked.\n }\n\n function checkTransaction(\n address to,\n uint256 value,\n bytes memory data,\n Enum.Operation operation,\n uint256,\n uint256,\n uint256,\n address,\n // solhint-disallow-next-line no-unused-vars\n address payable,\n bytes memory,\n address\n ) external view override {\n require(\n operation != Enum.Operation.DelegateCall ||\n allowedTargets[to].delegateCallAllowed,\n \"Delegate call not allowed to this address\"\n );\n require(allowedTargets[to].allowed, \"Target address is not allowed\");\n if (value > 0) {\n require(\n allowedTargets[to].valueAllowed,\n \"Cannot send ETH to this target\"\n );\n }\n if (data.length >= 4) {\n require(\n !allowedTargets[to].scoped ||\n allowedTargets[to].allowedFunctions[bytes4(data)],\n \"Target function is not allowed\"\n );\n } else {\n require(data.length == 0, \"Function signature too short\");\n require(\n !allowedTargets[to].scoped ||\n allowedTargets[to].fallbackAllowed,\n \"Fallback not allowed for this address\"\n );\n }\n }\n\n function checkAfterExecution(bytes32, bool) external view override {}\n}\n"
|
|
},
|
|
"@gnosis.pm/zodiac/contracts/guard/BaseGuard.sol": {
|
|
"content": "// SPDX-License-Identifier: LGPL-3.0-only\npragma solidity >=0.7.0 <0.9.0;\n\nimport \"@gnosis.pm/safe-contracts/contracts/common/Enum.sol\";\nimport \"@gnosis.pm/safe-contracts/contracts/interfaces/IERC165.sol\";\nimport \"../interfaces/IGuard.sol\";\n\nabstract contract BaseGuard is IERC165 {\n function supportsInterface(bytes4 interfaceId)\n external\n pure\n override\n returns (bool)\n {\n return\n interfaceId == type(IGuard).interfaceId || // 0xe6d7a83a\n interfaceId == type(IERC165).interfaceId; // 0x01ffc9a7\n }\n\n /// Module transactions only use the first four parameters: to, value, data, and operation.\n /// Module.sol hardcodes the remaining parameters as 0 since they are not used for module transactions.\n /// This interface is used to maintain compatibilty with Gnosis Safe transaction guards.\n function checkTransaction(\n address to,\n uint256 value,\n bytes memory data,\n Enum.Operation operation,\n uint256 safeTxGas,\n uint256 baseGas,\n uint256 gasPrice,\n address gasToken,\n address payable refundReceiver,\n bytes memory signatures,\n address msgSender\n ) external virtual;\n\n function checkAfterExecution(bytes32 txHash, bool success) external virtual;\n}\n"
|
|
},
|
|
"@gnosis.pm/zodiac/contracts/factory/FactoryFriendly.sol": {
|
|
"content": "// SPDX-License-Identifier: LGPL-3.0-only\n\n/// @title Zodiac FactoryFriendly - A contract that allows other contracts to be initializable and pass bytes as arguments to define contract state\npragma solidity >=0.7.0 <0.9.0;\n\nimport \"@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol\";\n\nabstract contract FactoryFriendly is OwnableUpgradeable {\n function setUp(bytes memory initializeParams) public virtual;\n}\n"
|
|
},
|
|
"@gnosis.pm/safe-contracts/contracts/common/Enum.sol": {
|
|
"content": "// SPDX-License-Identifier: LGPL-3.0-only\npragma solidity >=0.7.0 <0.9.0;\n\n/// @title Enum - Collection of enums\n/// @author Richard Meissner - <[email protected]>\ncontract Enum {\n enum Operation {Call, DelegateCall}\n}\n"
|
|
},
|
|
"@gnosis.pm/safe-contracts/contracts/interfaces/IERC165.sol": {
|
|
"content": "// SPDX-License-Identifier: LGPL-3.0-only\npragma solidity >=0.7.0 <0.9.0;\n\n/// @notice More details at https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/introspection/IERC165.sol\ninterface IERC165 {\n /**\n * @dev Returns true if this contract implements the interface defined by\n * `interfaceId`. See the corresponding\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\n * to learn more about how these ids are created.\n *\n * This function call must use less than 30 000 gas.\n */\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n"
|
|
},
|
|
"@gnosis.pm/zodiac/contracts/interfaces/IGuard.sol": {
|
|
"content": "// SPDX-License-Identifier: LGPL-3.0-only\npragma solidity >=0.7.0 <0.9.0;\n\nimport \"@gnosis.pm/safe-contracts/contracts/common/Enum.sol\";\n\ninterface IGuard {\n function checkTransaction(\n address to,\n uint256 value,\n bytes memory data,\n Enum.Operation operation,\n uint256 safeTxGas,\n uint256 baseGas,\n uint256 gasPrice,\n address gasToken,\n address payable refundReceiver,\n bytes memory signatures,\n address msgSender\n ) external;\n\n function checkAfterExecution(bytes32 txHash, bool success) external;\n}\n"
|
|
},
|
|
"@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\nimport \"../utils/ContextUpgradeable.sol\";\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {\n address private _owner;\n\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /**\n * @dev Initializes the contract setting the deployer as the initial owner.\n */\n function __Ownable_init() internal initializer {\n __Context_init_unchained();\n __Ownable_init_unchained();\n }\n\n function __Ownable_init_unchained() internal initializer {\n _setOwner(_msgSender());\n }\n\n /**\n * @dev Returns the address of the current owner.\n */\n function owner() public view virtual returns (address) {\n return _owner;\n }\n\n /**\n * @dev Throws if called by any account other than the owner.\n */\n modifier onlyOwner() {\n require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n _;\n }\n\n /**\n * @dev Leaves the contract without owner. It will not be possible to call\n * `onlyOwner` functions anymore. Can only be called by the current owner.\n *\n * NOTE: Renouncing ownership will leave the contract without an owner,\n * thereby removing any functionality that is only available to the owner.\n */\n function renounceOwnership() public virtual onlyOwner {\n _setOwner(address(0));\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Can only be called by the current owner.\n */\n function transferOwnership(address newOwner) public virtual onlyOwner {\n require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n _setOwner(newOwner);\n }\n\n function _setOwner(address newOwner) private {\n address oldOwner = _owner;\n _owner = newOwner;\n emit OwnershipTransferred(oldOwner, newOwner);\n }\n uint256[49] private __gap;\n}\n"
|
|
},
|
|
"@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract ContextUpgradeable is Initializable {\n function __Context_init() internal initializer {\n __Context_init_unchained();\n }\n\n function __Context_init_unchained() internal initializer {\n }\n function _msgSender() internal view virtual returns (address) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes calldata) {\n return msg.data;\n }\n uint256[50] private __gap;\n}\n"
|
|
},
|
|
"@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n */\nabstract contract Initializable {\n /**\n * @dev Indicates that the contract has been initialized.\n */\n bool private _initialized;\n\n /**\n * @dev Indicates that the contract is in the process of being initialized.\n */\n bool private _initializing;\n\n /**\n * @dev Modifier to protect an initializer function from being invoked twice.\n */\n modifier initializer() {\n require(_initializing || !_initialized, \"Initializable: contract is already initialized\");\n\n bool isTopLevelCall = !_initializing;\n if (isTopLevelCall) {\n _initializing = true;\n _initialized = true;\n }\n\n _;\n\n if (isTopLevelCall) {\n _initializing = false;\n }\n }\n}\n"
|
|
}
|
|
},
|
|
"settings": {
|
|
"optimizer": {
|
|
"enabled": false,
|
|
"runs": 200
|
|
},
|
|
"outputSelection": {
|
|
"*": {
|
|
"*": [
|
|
"evm.bytecode",
|
|
"evm.deployedBytecode",
|
|
"devdoc",
|
|
"userdoc",
|
|
"metadata",
|
|
"abi"
|
|
]
|
|
}
|
|
},
|
|
"metadata": {
|
|
"useLiteralContent": true
|
|
},
|
|
"libraries": {}
|
|
}
|
|
}
|
|
} |