Verified contractExactGPL-2.0-or-later
OperatorRegistryModule
Address0x3be6c2ffbef229d457629b5a5262770c357899fa
- Balance
0 ETH
- Transactions
4
- Compiler
solc 0.8.20
- Same code
Only this contract
Details
- Compiler
- solc 0.8.20+commit.a1b79de6
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- shanghai
- License
- GPL-2.0-or-later
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,493,947
- Creation transaction
- 0xa1948f4b92…94fbfb7701
2 files
- src/OperatorRegistryModule.solmain2.31 KB
- src/safe/ISafeModuleExecutor.sol324 B
src/OperatorRegistryModule.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.8.20;
import {ISafeModuleExecutor} from "./safe/ISafeModuleExecutor.sol";
/// @notice Lets registered operators make zero-value calls from one Safe to explicitly permitted functions.
/// @dev The Safe must enable this contract as a module. Permissions match an operator, target and selector only.
contract OperatorRegistryModule {
address public immutable safe;
mapping(bytes32 => bool) private _permissions;
error InvalidSafe();
error InvalidPermission();
error OnlySafe();
error Unauthorized();
error InvalidCalldata();
error ExecutionFailed();
event PermissionUpdated(address indexed operator, address indexed target, bytes4 indexed selector, bool allowed);
modifier onlySafe() {
if (msg.sender != safe) revert OnlySafe();
_;
}
constructor(address safe_) {
if (safe_.code.length == 0) revert InvalidSafe();
safe = safe_;
}
function setPermission(address operator, address target, bytes4 selector, bool allowed) external onlySafe {
if (operator == address(0) || target == address(0) || target == safe || target == address(this)) {
revert InvalidPermission();
}
if (allowed && target.code.length == 0) revert InvalidPermission();
_permissions[permissionKey(operator, target, selector)] = allowed;
emit PermissionUpdated(operator, target, selector, allowed);
}
function isAuthorized(address operator, address target, bytes4 selector) external view returns (bool) {
return _permissions[permissionKey(operator, target, selector)];
}
function permissionKey(address operator, address target, bytes4 selector) public pure returns (bytes32) {
return keccak256(abi.encodePacked(operator, target, selector));
}
function execute(address target, bytes calldata data) external {
if (data.length < 4) revert InvalidCalldata();
bytes4 selector = bytes4(data[:4]);
if (!_permissions[permissionKey(msg.sender, target, selector)]) revert Unauthorized();
bool success =
ISafeModuleExecutor(safe).execTransactionFromModule(target, 0, data, ISafeModuleExecutor.Operation.Call);
if (!success) revert ExecutionFailed();
}
}
src/safe/ISafeModuleExecutor.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.8.20;
interface ISafeModuleExecutor {
enum Operation {
Call,
DelegateCall
}
function execTransactionFromModule(address to, uint256 value, bytes calldata data, Operation operation)
external
returns (bool success);
}
Compiler settingsShow
{
"viaIR": false,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "shanghai",
"remappings": [
"lib/openzeppelin-contracts/:forge-std/=lib/openzeppelin-contracts/lib/forge-std/src/",
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"forge-std/=lib/forge-std/src/",
"halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.