Skip to content
Verified contractPartialMIT

Executor

Address0x6a23e889cf36486bfb7dcfef1deb9ae68a284f03
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.8.25

 

Same code

28 more contracts

 

Details

Compiler
solc 0.8.25+commit.b61c2a91
Language
solidity
Optimization
Yes, 200 runs
EVM version
cancun
Via IR
yes
License
MIT
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
25,903,478
Creation transaction
0x63c3b46a20…e71e0e8a1d
Main copy (most transactions)
0x01ccf2b2…2f8a5a79

contracts/Executor.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

import {IExecutor, Placeholder} from "./interfaces/IExecutor.sol";

uint256 constant FALLBACK_CONTEXT_TLOC = 0;

contract Executor is IExecutor {
    address internal immutable OWNER;

    constructor(address _owner) {
        OWNER = _owner;
    }

    /* EXTERNAL */

    /// @notice Executes a batch of calls.
    function exec_606BaXt(bytes[] memory data) external payable {
        require(msg.sender == OWNER);

        _multicall(data);
    }

    /// @notice Executes a normal call, requiring its success.
    /// @param target The target address to call.
    /// @param value The value of the call.
    /// @param context The 32-bytes concatenation of:
    /// - the address expected to call back. Set to address(0) to prevent any callback.
    /// - the expected callback data index.
    /// @param callData the calldata of the call.
    function call_g0oyU7o(address target, uint256 value, bytes32 context, bytes memory callData) public payable {
        require(msg.sender == address(this));

        bytes32 prevContext = _tload(FALLBACK_CONTEXT_TLOC);

        _tstore(FALLBACK_CONTEXT_TLOC, context);

        (bool success, bytes memory returnData) = target.call{value: value}(callData);
        if (!success) _revert(returnData);

        _tstore(FALLBACK_CONTEXT_TLOC, prevContext);
    }

    /// @notice Executes a normal call, requiring its success.
    /// @param target The target address to call.
    /// @param value The value of the call.
    /// @param context The 32-bytes concatenation of:
    /// - the address expected to call back. Set to address(0) to prevent any callback.
    /// - the expected callback data index.
    /// @param callData the calldata of the call.
    function callWithPlaceholders4845164670(
        address target,
        uint256 value,
        bytes32 context,
        bytes memory callData,
        Placeholder[] calldata placeholders
    ) external payable {
        for (uint256 i; i < placeholders.length; ++i) {
            Placeholder calldata placeholder = placeholders[i];

            (bool success, bytes memory resData) = placeholder.to.staticcall(placeholder.data);
            if (!success) _revert(resData);

            uint64 offset = placeholder.offset;
            uint64 length = placeholder.length;
            uint64 resOffset = placeholder.resOffset;

            assembly ("memory-safe") {
                mcopy(add(callData, add(32, offset)), add(resData, add(32, resOffset)), length)
            }
        }

        call_g0oyU7o(target, value, context, callData);
    }

    /// @notice Transfers ETH to the recipient.
    /// @param recipient The recipient of the transfer. Set to address(0) to transfer to the coinbase.
    /// @param amount The amount to transfer. Automatically minimumed to the current ETH balance.
    function transfer(address recipient, uint256 amount) external payable {
        require(msg.sender == address(this));

        if (recipient == address(0)) recipient = block.coinbase;

        amount = _min(amount, address(this).balance);

        (bool success, bytes memory returnData) = recipient.call{value: amount}("");
        if (!success) _revert(returnData);
    }

    receive() external payable {}

    fallback(bytes calldata) external payable returns (bytes memory returnData) {
        bytes32 context = _tload(FALLBACK_CONTEXT_TLOC);
        require(msg.sender == address(uint160(uint256(context))));

        uint256 dataIndex = uint256(context >> 160);

        bytes memory fallbackData;
        assembly ("memory-safe") {
            let offset := add(4, calldataload(add(4, mul(32, dataIndex))))
            let length := calldataload(offset)

            fallbackData := mload(0x40)

            calldatacopy(fallbackData, offset, add(32, length))

            mstore(0x40, add(fallbackData, add(32, length)))
        }

        bytes[] memory multicallData;
        (multicallData, returnData) = abi.decode(fallbackData, (bytes[], bytes));

        _multicall(multicallData);
    }

    /* INTERNAL */

    /// @notice Executes a series of calls.
    function _multicall(bytes[] memory data) internal {
        for (uint256 i; i < data.length; ++i) {
            (bool success, bytes memory returnData) = address(this).call(data[i]);
            if (!success) _revert(returnData);
        }
    }

    /// @dev Bubbles up the revert reason / custom error encoded in `returnData`.
    /// @dev Assumes `returnData` is the return data of any kind of failing CALL to a contract.
    function _revert(bytes memory returnData) internal pure {
        uint256 length = returnData.length;
        require(length > 0);

        assembly ("memory-safe") {
            revert(add(32, returnData), length)
        }
    }

    function _tload(uint256 tloc) internal view returns (bytes32 value) {
        assembly ("memory-safe") {
            value := tload(tloc)
        }
    }

    function _tstore(uint256 tloc, bytes32 value) internal {
        assembly ("memory-safe") {
            tstore(tloc, value)
        }
    }

    function _min(uint256 x, uint256 y) internal pure returns (uint256 z) {
        assembly {
            z := xor(x, mul(xor(x, y), lt(y, x)))
        }
    }
}

contracts/interfaces/IExecutor.sol

// SPDX-License-Identifier: MIT
pragma solidity >=0.5.0;

struct Placeholder {
    address to;
    bytes data;
    uint64 offset;
    uint64 length;
    uint64 resOffset;
}

interface IExecutor {
    function exec_606BaXt(bytes[] memory data) external payable;

    function call_g0oyU7o(address target, uint256 value, bytes32 context, bytes memory callData) external payable;

    function callWithPlaceholders4845164670(
        address target,
        uint256 value,
        bytes32 context,
        bytes memory callData,
        Placeholder[] calldata placeholders
    ) external payable;

    function transfer(address recipient, uint256 amount) external payable;
}
Compiler settingsShow
{
  "viaIR": true,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "cancun",
  "remappings": [
    "forge-std/=lib/forge-std/src/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.