// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)pragmasolidity ^0.8.20;/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/abstractcontractContext{
function_msgSender() internalviewvirtualreturns (address) {
returnmsg.sender;
}
function_msgData() internalviewvirtualreturns (bytescalldata) {
returnmsg.data;
}
function_contextSuffixLength() internalviewvirtualreturns (uint256) {
return0;
}
}
// SPDX-License-Identifier: AGPL-3.0-onlypragmasolidity =0.8.24;import {ISafe} from"./interfaces/external/ISafe.sol";
import {Enum} from"./interfaces/external/ISafe.sol";
import {RumpelGuard} from"./RumpelGuard.sol";
/// @notice Delegatecall script to initialize Safes.contractInitializationScript{
errorInitializationFailed();
eventInitialCall(address to, bytes data);
structInitCall {
address to;
bytes data;
}
/// @notice This function is called via delegatecall by newly created Safes.functioninitialize(address module, address guard, InitCall[] memory initCalls) external{
ISafe safe = ISafe(address(this));
safe.enableModule(module);
safe.setGuard(guard);
// Arbitrary initial calls.for (uint256 i =0; i < initCalls.length; i++) {
address to = initCalls[i].to;
bytesmemory data = initCalls[i].data;
// Check each tx with the guard.
RumpelGuard(guard).checkTransaction(
to, 0, data, Enum.Operation.Call, 0, 0, 0, address(0), payable(address(0)), bytes(""), address(0)
);
bool success;
assembly {
success :=call(sub(gas(), 500), to, 0, add(data, 0x20), mload(data), 0, 0)
}
if (!success) revert InitializationFailed();
emit InitialCall(to, data);
}
}
}
Contract Source Code
File 6 of 9: Ownable.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)pragmasolidity ^0.8.20;import {Context} from"../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/abstractcontractOwnableisContext{
addressprivate _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/errorOwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/errorOwnableInvalidOwner(address owner);
eventOwnershipTransferred(addressindexed previousOwner, addressindexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/constructor(address initialOwner) {
if (initialOwner ==address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/modifieronlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/functionowner() publicviewvirtualreturns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/function_checkOwner() internalviewvirtual{
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/functionrenounceOwnership() publicvirtualonlyOwner{
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/functiontransferOwnership(address newOwner) publicvirtualonlyOwner{
if (newOwner ==address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/function_transferOwnership(address newOwner) internalvirtual{
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
Contract Source Code
File 7 of 9: Pausable.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v5.0.0) (utils/Pausable.sol)pragmasolidity ^0.8.20;import {Context} from"../utils/Context.sol";
/**
* @dev Contract module which allows children to implement an emergency stop
* mechanism that can be triggered by an authorized account.
*
* This module is used through inheritance. It will make available the
* modifiers `whenNotPaused` and `whenPaused`, which can be applied to
* the functions of your contract. Note that they will not be pausable by
* simply including this module, only once the modifiers are put in place.
*/abstractcontractPausableisContext{
boolprivate _paused;
/**
* @dev Emitted when the pause is triggered by `account`.
*/eventPaused(address account);
/**
* @dev Emitted when the pause is lifted by `account`.
*/eventUnpaused(address account);
/**
* @dev The operation failed because the contract is paused.
*/errorEnforcedPause();
/**
* @dev The operation failed because the contract is not paused.
*/errorExpectedPause();
/**
* @dev Initializes the contract in unpaused state.
*/constructor() {
_paused =false;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*
* Requirements:
*
* - The contract must not be paused.
*/modifierwhenNotPaused() {
_requireNotPaused();
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/modifierwhenPaused() {
_requirePaused();
_;
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/functionpaused() publicviewvirtualreturns (bool) {
return _paused;
}
/**
* @dev Throws if the contract is paused.
*/function_requireNotPaused() internalviewvirtual{
if (paused()) {
revert EnforcedPause();
}
}
/**
* @dev Throws if the contract is not paused.
*/function_requirePaused() internalviewvirtual{
if (!paused()) {
revert ExpectedPause();
}
}
/**
* @dev Triggers stopped state.
*
* Requirements:
*
* - The contract must not be paused.
*/function_pause() internalvirtualwhenNotPaused{
_paused =true;
emit Paused(_msgSender());
}
/**
* @dev Returns to normal state.
*
* Requirements:
*
* - The contract must be paused.
*/function_unpause() internalvirtualwhenPaused{
_paused =false;
emit Unpaused(_msgSender());
}
}
Contract Source Code
File 8 of 9: RumpelGuard.sol
// SPDX-License-Identifier: AGPL-3.0-onlypragmasolidity =0.8.24;import {Ownable} from"@openzeppelin/contracts/access/Ownable.sol";
import {Enum} from"./interfaces/external/ISafe.sol";
import {IGuard} from"./interfaces/external/IGuard.sol";
/// @notice Rumpel Safe Guard with a blocklist for the Rumpel Wallet./// @dev Compatible with Safe v1.3.0-libs.0, the last Safe Ethereum mainnet release, so it can't use module execution hooks.contractRumpelGuardisOwnable, IGuard{
mapping(address=>mapping(bytes4=> AllowListState)) public allowedCalls; // target => functionSelector => allowListStateaddresspublicimmutable signMessageLib;
enumAllowListState {
OFF,
ON,
PERMANENTLY_ON
}
eventSetCallAllowed(addressindexed target, bytes4indexed functionSelector, AllowListState allowListState);
errorCallNotAllowed(address target, bytes4 functionSelector);
errorPermanentlyOn();
constructor(address _signMessageLib) Ownable(msg.sender) {
signMessageLib = _signMessageLib;
}
/// @notice Called by the Safe contract before a transaction is executed./// @dev Safe user execution hook that blocks all calls by default, including delegatecalls, unless explicitly added to the allowlist.functioncheckTransaction(address to,
uint256,
bytesmemory data,
Enum.Operation operation,
uint256,
uint256,
uint256,
address,
addresspayable,
bytesmemory,
address) externalview{
// Disallow calls with function selectors that will be padded with 0s.// Allow calls with data length 0 for ETH transfers.if (data.length>0&& data.length<4) {
revert CallNotAllowed(to, bytes4(data));
}
bytes4 functionSelector =bytes4(data);
// Only allow delegatecalls to the signMessageLib.if (operation == Enum.Operation.DelegateCall) {
if (to == signMessageLib) {
return;
} else {
revert CallNotAllowed(to, functionSelector);
}
}
bool toSafe =msg.sender== to;
if (toSafe) {
// If this transaction is to a Safe itself, to e.g. update config, we check the zero address for allowed calls.if (allowedCalls[address(0)][functionSelector] == AllowListState.OFF) {
revert CallNotAllowed(to, functionSelector);
}
} elseif (data.length==0) {
// If this transaction is a simple ETH transfer, we check the zero address with the zero function selector to see if it's allowed.if (allowedCalls[address(0)][bytes4(0)] == AllowListState.OFF) {
revert CallNotAllowed(address(0), bytes4(0));
}
} else {
// For all other calls, we check the allowedCalls mapping normally.if (allowedCalls[to][functionSelector] == AllowListState.OFF) {
revert CallNotAllowed(to, functionSelector);
}
}
}
/// @notice Called by the Safe contract after a transaction is executed./// @dev No-op.functioncheckAfterExecution(bytes32, bool) externalview{}
functionsupportsInterface(bytes4 interfaceId) publicviewreturns (bool) {
return interfaceId ==type(IGuard).interfaceId;
}
// Admin ----/// @notice Enable or disable Safes from calling a function./// @dev Scoped to <address>.<selector>, so all calls to added address <> selector pairs are allowed./// @dev Function arguments aren't checked, so any arguments are allowed for the enabled functions./// @dev Calls can be enabled, disabled, or permanently enabled, that last of which guarantees the call can't be rugged.functionsetCallAllowed(address target, bytes4 functionSelector, AllowListState allowListState)
externalonlyOwner{
if (allowedCalls[target][functionSelector] == AllowListState.PERMANENTLY_ON) {
revert PermanentlyOn();
}
allowedCalls[target][functionSelector] = allowListState;
emit SetCallAllowed(target, functionSelector, allowListState);
}
}
Contract Source Code
File 9 of 9: RumpelWalletFactory.sol
// SPDX-License-Identifier: AGPL-3.0-onlypragmasolidity =0.8.24;import {Ownable} from"@openzeppelin/contracts/access/Ownable.sol";
import {Pausable} from"@openzeppelin/contracts/utils/Pausable.sol";
import {ISafe} from"./interfaces/external/ISafe.sol";
import {ISafeProxyFactory} from"./interfaces/external/ISafeProxyFactory.sol";
import {InitializationScript} from"./InitializationScript.sol";
/// @notice Factory to create Rumpel Wallets; Safes with the Rumpel Guard and Rumpel Module added on.contractRumpelWalletFactoryisOwnable, Pausable{
mapping(address=>uint256) public saltNonce;
ISafeProxyFactory public proxyFactory;
addresspublic compatibilityFallback;
addresspublic safeSingleton;
addresspublic rumpelModule;
addresspublic rumpelGuard;
addresspublic initializationScript;
eventSafeCreated(addressindexed safe, address[] indexed owners, uint256 threshold);
eventParamChanged(bytes32 what, address data);
errorUnrecognizedParam(bytes32 what);
constructor(
ISafeProxyFactory _proxyFactory,
address _compatibilityFallback,
address _safeSingleton,
address _rumpelModule,
address _rumpelGuard,
address _initializationScript
) Ownable(msg.sender) {
proxyFactory = _proxyFactory;
compatibilityFallback = _compatibilityFallback;
safeSingleton = _safeSingleton;
rumpelModule = _rumpelModule;
rumpelGuard = _rumpelGuard;
initializationScript = _initializationScript;
}
/// @notice Create a Safe with the Rumpel Module and Rumpel Guard added.functioncreateWallet(address[] calldata owners,
uint256 threshold,
InitializationScript.InitCall[] calldata initCalls
) externalwhenNotPausedreturns (address) {
// Calculate a unique salt based on the sender's address and nonce.uint256 salt =uint256(keccak256(abi.encodePacked(msg.sender, saltNonce[msg.sender]++)));
address safe = proxyFactory.createProxyWithNonce(
safeSingleton,
abi.encodeWithSelector(
ISafe.setup.selector,
owners,
threshold,
initializationScript, // Contract with initialization logicabi.encodeWithSelector(InitializationScript.initialize.selector, rumpelModule, rumpelGuard, initCalls), // Add module and guard + initial calls
compatibilityFallback, // fallbackHandleraddress(0), // paymentToken0, // paymentaddress(0) // paymentReceiver
),
salt // For deterministic address generation
);
emit SafeCreated(safe, owners, threshold);
return safe;
}
functionprecomputeAddress(bytesmemory _initializer, address _sender, uint256 _saltNonce)
externalviewreturns (address)
{
bytes32 salt =keccak256(
abi.encodePacked(keccak256(_initializer), uint256(keccak256(abi.encodePacked(_sender, _saltNonce))))
);
bytesmemory deploymentData =abi.encodePacked(proxyFactory.proxyCreationCode(), uint256(uint160(safeSingleton)));
bytes32 deploymentHash =keccak256(abi.encodePacked(bytes1(0xff), address(proxyFactory), salt, keccak256(deploymentData)));
returnaddress(uint160(uint256(deploymentHash)));
}
// Admin ----/// @notice Set admin params, only callable by the owner./// @dev These changes will only apply to future Safes deployed with this factory.functionsetParam(bytes32 what, address data) externalonlyOwner{
if (what =="PROXY_FACTORY") proxyFactory = ISafeProxyFactory(data);
elseif (what =="SAFE_SINGLETON") safeSingleton = data;
elseif (what =="RUMPEL_MODULE") rumpelModule = data;
elseif (what =="RUMPEL_GUARD") rumpelGuard = data;
elseif (what =="INITIALIZATION_SCRIPT") initializationScript = data;
elseif (what =="COMPATIBILITY_FALLBACK") compatibilityFallback = data;
elserevert UnrecognizedParam(what);
emit ParamChanged(what, data);
}
functionpauseWalletCreation() externalonlyOwner{
_pause();
}
functionunpauseWalletCreation() externalonlyOwner{
_unpause();
}
}