Verified contractExactMIT
Executor
Address0x77a737f96f411eda4bb7c0b5e80c7771e380c7ee
- Balance
0 ETH
- Transactions
3
- Compiler
solc 0.8.34
- Same code
3 more contracts
Details
- Compiler
- solc 0.8.34+commit.80d5c536
- Language
- solidity
- Optimization
- No
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,372,568
- Creation transaction
- 0x804c91c4cf…37801020fa
contracts/executor.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/// @notice Sponsor-controlled EIP-7702 batch executor with an atomic coinbase tip.
/// @dev Delegating an EOA to this code trusts the sponsor with its assets until
/// delegation is changed/revoked. Deploy with the sponsor as owner.
contract Executor {
address payable public immutable owner;
address public immutable selfOwner;
// Only the deployed implementation uses storage; delegated EOAs do not.
bool private entered;
struct Call {
address target;
uint256 value;
bytes data;
// For standard ERC-20 transfer/approve: require exactly ABI bool true.
bool requireTrue;
}
error Unauthorized();
error InvalidContext();
error BlockOutOfRange(uint256 firstBlock, uint256 lastBlock, uint256 actual);
error InvalidDelegation(address account);
error EmptyBatch();
error IncorrectValue(uint256 expected, uint256 actual);
error CallFailed(uint256 index, address target, bytes reason);
error InvalidReturn(uint256 index, address target, bytes result);
error PaymentFailed(address recipient, uint256 amount);
error Reentrancy();
event Executed(address indexed account, uint256 indexed firstBlock, uint256 lastBlock, address coinbase, uint256 tip);
constructor(address payable sponsor) {
if (sponsor == address(0)) revert Unauthorized();
owner = sponsor;
selfOwner = address(this);
}
// Withdrawals may send ETH back to the delegated EOA, even with 2300 gas.
receive() external payable {}
/// @notice Called by the sponsor on the deployed implementation.
/// @dev msg.value must cover exactly call values plus the tip. The tip stays
/// here while calls run, so the delegated EOA cannot spend it early.
function execute(
address delegatedAccount,
Call[] calldata calls,
uint256 firstBlock,
uint256 lastBlock,
uint256 coinbaseTip
) external payable {
if (address(this) != selfOwner) revert InvalidContext();
if (msg.sender != owner) revert Unauthorized();
if (entered) revert Reentrancy();
entered = true;
_checkBlockRange(firstBlock, lastBlock);
if (calls.length == 0) revert EmptyBatch();
// EIP-7702 silently skips invalid/stale authorizations. Calling an
// undelegated EOA would otherwise succeed without executing any code.
if (delegatedAccount == selfOwner || delegatedAccount.codehash !=
keccak256(abi.encodePacked(hex"ef0100", selfOwner))) {
revert InvalidDelegation(delegatedAccount);
}
uint256 callValue;
for (uint256 i; i < calls.length; ++i) callValue += calls[i].value;
uint256 required = callValue + coinbaseTip;
if (msg.value != required) revert IncorrectValue(required, msg.value);
bytes4 result = Executor(payable(delegatedAccount)).executeCalls{value: callValue}(calls, firstBlock, lastBlock);
if (result != Executor.executeCalls.selector) revert InvalidDelegation(delegatedAccount);
// Any failure here or below reverts ALL nested calls and the tip.
if (coinbaseTip != 0) _pay(payable(block.coinbase), coinbaseTip);
uint256 remainder = address(this).balance;
if (remainder != 0) _pay(owner, remainder);
emit Executed(delegatedAccount, firstBlock, lastBlock, block.coinbase, coinbaseTip);
entered = false;
}
/// @notice Runs in the delegated EOA, called only by this implementation.
function executeCalls(Call[] calldata calls, uint256 firstBlock, uint256 lastBlock) external payable returns (bytes4) {
if (address(this) == selfOwner) revert InvalidContext();
if (msg.sender != selfOwner) revert Unauthorized();
_checkBlockRange(firstBlock, lastBlock);
if (calls.length == 0) revert EmptyBatch();
for (uint256 i; i < calls.length; ++i) {
Call calldata c = calls[i];
// A CALL to an address with no code is an EVM-successful no-op.
(bool success, bytes memory result) = c.target.call{value: c.value}(c.data);
if (!success) revert CallFailed(i, c.target, result);
if (c.requireTrue && (result.length != 32 || abi.decode(result, (uint256)) != 1)) {
revert InvalidReturn(i, c.target, result);
}
}
// Preserve the original behavior of returning the EOA's remaining ETH.
uint256 remainder = address(this).balance;
if (remainder != 0) _pay(owner, remainder);
return Executor.executeCalls.selector;
}
function _checkBlockRange(uint256 firstBlock, uint256 lastBlock) private view {
if (firstBlock > lastBlock || block.number < firstBlock || block.number > lastBlock) {
revert BlockOutOfRange(firstBlock, lastBlock, block.number);
}
}
function _pay(address payable recipient, uint256 amount) private {
(bool success,) = recipient.call{value: amount}("");
if (!success) revert PaymentFailed(recipient, amount);
}
}
Compiler settingsShow
{
"optimizer": {
"runs": 200,
"enabled": false
},
"remappings": []
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.