Skip to content
Verified contractPartialMIT

ZodiacOnlyGuard

Address0xa8ec098c284e2eb954fe9de31887e73efede3948
Balance

0 ETH

 

Transactions

0

 

Compiler

solc 0.8.33

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.33+commit.64118f21
Language
solidity
Optimization
Yes, 200 runs
EVM version
prague
License
MIT
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
24,263,559
Creation transaction
0x8d9c0b4325…23e6c88820

contracts/guards/ZodiacOnlyGuard.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

/**
 * @title ZodiacOnlyGuard
 * @author TimelockSuite
 * @notice Forces ALL Safe transactions to go through Zodiac Delay Module
 * @dev ~50 lines of custom code - all delay logic is in audited Zodiac Delay
 *
 * Architecture:
 *   EOAs → Zodiac Delay Module → Safe (with ZodiacOnlyGuard) → Assets
 *              48h+ cooldown         allows module txs only
 *
 * Security Properties:
 * - Blocks ALL direct transactions (must use Zodiac Delay)
 * - EXCEPTION: Guardian can call setTxNonce() on Zodiac to cancel instantly
 * - Blocks delegatecalls (can bypass guard by modifying storage)
 * - Only allows module calls from the configured Zodiac Delay
 *
 * Flow:
 * 1. User queues tx via Zodiac Delay: delay.execTransactionFromModule(...)
 * 2. Wait for 48h+ cooldown
 * 3. Anyone executes via Zodiac Delay
 * 4. Zodiac calls Safe.execTransactionFromModule()
 * 5. Guard.checkModuleTransaction() → allows (from Zodiac only)
 * 6. Transaction executes
 *
 * Guardian can cancel by calling Safe to execute setTxNonce() on Zodiac Delay.
 * This is the ONLY direct Safe tx allowed (Guardian → Safe → Zodiac.setTxNonce).
 */
contract ZodiacOnlyGuard {
    // ============ Immutables ============

    /// @notice The Zodiac Delay Modifier address (audited)
    address public immutable zodiacDelay;

    /// @notice Guardian (cold wallet) that can cancel via setTxNonce
    address public immutable guardian;

    // ============ Constants ============

    /// @notice setTxNonce(uint256) selector - guardian can call this to cancel
    bytes4 private constant SET_TX_NONCE = 0x8f9eafba;

    // ============ Errors ============

    /// @notice All transactions must go through Zodiac Delay
    error MustUseZodiacDelay();

    /// @notice DelegateCall operations are blocked (can bypass guard)
    error DelegateCallBlocked();

    /// @notice Invalid configuration
    error InvalidZodiacAddress();
    error InvalidGuardianAddress();

    // ============ Constructor ============

    /**
     * @notice Initialize the ZodiacOnlyGuard
     * @param _zodiacDelay Address of the Zodiac Delay Modifier
     * @param _guardian Guardian address (cold wallet) that can cancel operations
     */
    constructor(address _zodiacDelay, address _guardian) {
        if (_zodiacDelay == address(0)) revert InvalidZodiacAddress();
        if (_guardian == address(0)) revert InvalidGuardianAddress();

        zodiacDelay = _zodiacDelay;
        guardian = _guardian;
    }

    // ============ Guard Interface ============

    /**
     * @notice Called by Safe before executing a DIRECT transaction
     * @dev Blocks ALL direct transactions EXCEPT guardian calling setTxNonce on Zodiac
     */
    function checkTransaction(
        address to,
        uint256,
        bytes memory data,
        uint8,
        uint256,
        uint256,
        uint256,
        address,
        address payable,
        bytes memory,
        address msgSender
    ) external view {
        // Allow guardian to call setTxNonce() on Zodiac Delay (instant cancel)
        if (
            msgSender == guardian &&
            to == zodiacDelay &&
            data.length >= 4 &&
            bytes4(data) == SET_TX_NONCE
        ) {
            return; // Allow this specific call
        }

        // Block all other direct transactions
        revert MustUseZodiacDelay();
    }

    /**
     * @notice Called by Safe after executing a direct transaction
     * @dev No-op for this guard
     */
    function checkAfterExecution(bytes32, bool) external pure {}

    /**
     * @notice Called by Safe before executing a MODULE transaction (Safe v1.5+)
     * @dev Only allows transactions from the Zodiac Delay module, blocks delegatecalls
     */
    function checkModuleTransaction(
        address,
        uint256,
        bytes memory,
        uint8 operation,
        address module
    ) external view returns (bytes32) {
        // Block delegatecalls - they execute in Safe's context and can modify storage
        // operation: 0 = Call, 1 = DelegateCall
        if (operation == 1) revert DelegateCallBlocked();

        // Only allow transactions from Zodiac Delay module
        if (module != zodiacDelay) revert MustUseZodiacDelay();

        return bytes32(0);
    }

    /**
     * @notice Called by Safe after executing a module transaction
     * @dev No-op for this guard
     */
    function checkAfterModuleExecution(bytes32, bool) external pure {}

    /**
     * @notice ERC165 interface support
     */
    function supportsInterface(bytes4 interfaceId) external pure returns (bool) {
        return
            interfaceId == 0x945b8148 || // Guard interface
            interfaceId == 0x01ffc9a7;   // ERC165
    }
}
Compiler settingsShow
{
  "viaIR": false,
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "prague"
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.