Blockchain / Global / Address

Contract

0x3d4BA2E0884aa488718476ca2FB8Efc291A46199

Balance
0 SOMI
Transactions sent
1
Type
Contract · 850 bytes of code

SimulateTxAccessor Verified

Compiler
solc 0.7.6+commit.7338295f
Language
Solidity
Optimization
No
EVM version
—
License
—
Verified
2026-10-12

contracts/accessors/SimulateTxAccessor.sol

and 2 more files

Solidity
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;

import "../base/Executor.sol";

/**
 * @title Simulate Transaction Accessor.
 * @notice Can be used with StorageAccessible to simulate Safe transactions.
 * @author Richard Meissner - @rmeissner
 */
contract SimulateTxAccessor is Executor {
    address private immutable accessorSingleton;

    constructor() {
        accessorSingleton = address(this);
    }

    /**
     * @notice Modifier to make a function callable via delegatecall only.
     * If the function is called via a regular call, it will revert.
     */
    modifier onlyDelegateCall() {
        require(address(this) != accessorSingleton, "SimulateTxAccessor should only be called via delegatecall");
        _;
    }

    /**
     * @notice Simulates a Safe transaction and returns the used gas, success boolean and the return data.
     * @dev Executes the specified operation {Call, DelegateCall} and returns operation-specific data.
     *      Has to be called via delegatecall.
     *      This returns the data equal to `abi.encode(uint256(etimate), bool(success), bytes(returnData))`.
     *      Specifically, the returndata will be:
     *      `estimate:uint256 || success:bool || returnData.length:uint256 || returnData:bytes`.
     * @param to Destination address .
     * @param value Native token value.
     * @param data Data payload.
     * @param operation Operation type {Call, DelegateCall}.
     * @return estimate Gas used.
     * @return success Success boolean value.
     * @return returnData Return data.
     */
    function simulate(
        address to,
        uint256 value,
        bytes calldata data,
        Enum.Operation operation
    ) external onlyDelegateCall returns (uint256 estimate, bool success, bytes memory returnData) {
        uint256 startGas = gasleft();
        success = execute(to, value, data, operation, gasleft());
        estimate = startGas - gasleft();
        // solhint-disable-next-line no-inline-assembly
        assembly {
            // Load free memory location
            let ptr := mload(0x40)
            // We allocate memory for the return data by setting the free memory location to
            // current free memory location + data size + 32 bytes for data size value
            mstore(0x40, add(ptr, add(returndatasize(), 0x20)))
            // Store the size
            mstore(ptr, returndatasize())
            // Store the data
            returndatacopy(add(ptr, 0x20), 0, returndatasize())
            // Point the return data to the correct memory location
            returnData := ptr
        }
    }
}

Other files

  • contracts/base/Executor.sol
    // SPDX-License-Identifier: LGPL-3.0-only
    pragma solidity >=0.7.0 <0.9.0;
    import "../common/Enum.sol";
    
    /**
     * @title Executor - A contract that can execute transactions
     * @author Richard Meissner - @rmeissner
     */
    abstract contract Executor {
        /**
         * @notice Executes either a delegatecall or a call with provided parameters.
         * @dev This method doesn't perform any sanity check of the transaction, such as:
         *      - if the contract at `to` address has code or not
         *      It is the responsibility of the caller to perform such checks.
         * @param to Destination address.
         * @param value Ether value.
         * @param data Data payload.
         * @param operation Operation type.
         * @return success boolean flag indicating if the call succeeded.
         */
        function execute(
            address to,
            uint256 value,
            bytes memory data,
            Enum.Operation operation,
            uint256 txGas
        ) internal returns (bool success) {
            if (operation == Enum.Operation.DelegateCall) {
                // solhint-disable-next-line no-inline-assembly
                assembly {
                    success := delegatecall(txGas, to, add(data, 0x20), mload(data), 0, 0)
                }
            } else {
                // solhint-disable-next-line no-inline-assembly
                assembly {
                    success := call(txGas, to, value, add(data, 0x20), mload(data), 0, 0)
                }
            }
        }
    }
    
  • contracts/common/Enum.sol
    // SPDX-License-Identifier: LGPL-3.0-only
    pragma solidity >=0.7.0 <0.9.0;
    
    /**
     * @title Enum - Collection of enums used in Safe contracts.
     * @author Richard Meissner - @rmeissner
     */
    abstract contract Enum {
        enum Operation {
            Call,
            DelegateCall
        }
    }
    
ABI · 2 entries
json
[
  {
    "type": "constructor",
    "inputs": [],
    "stateMutability": "nonpayable"
  },
  {
    "name": "simulate",
    "type": "function",
    "inputs": [
      {
        "name": "to",
        "type": "address",
        "internalType": "address"
      },
      {
        "name": "value",
        "type": "uint256",
        "internalType": "uint256"
      },
      {
        "name": "data",
        "type": "bytes",
        "internalType": "bytes"
      },
      {
        "name": "operation",
        "type": "uint8",
        "internalType": "enum Enum.Operation"
      }
    ],
    "outputs": [
      {
        "name": "estimate",
        "type": "uint256",
        "internalType": "uint256"
      },
      {
        "name": "success",
        "type": "bool",
        "internalType": "bool"
      },
      {
        "name": "returnData",
        "type": "bytes",
        "internalType": "bytes"
      }
    ],
    "stateMutability": "nonpayable"
  }
]