Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
- Contract name:
- RouterCaller
- Optimization enabled
- false
- Compiler version
- v0.8.28+commit.7893614a
- EVM Version
- Verified at
- 2026-11-21T15:18:30.392229Z
Constructor Arguments
src/hardened/mediator/RouterCaller.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
import {ExactGasCall} from "./ExactGasCall.sol";
/// @title RouterCaller
/// @notice The account that makes the follow-up call of a `DeliveryRouter` delivery. The router creates it in its
/// constructor, and only that router may use it. It makes one call to a target with exactly the gas that the sender
/// stated, the given data and no native value, and answers whether the call succeeded. The target sees this contract
/// as `msg.sender`, not the router.
/// @dev Why it exists. The sender of a delivery names the target and the call data, so the call can do anything that
/// its caller may do. When the router made the call itself, a call `token.transfer(attacker, balance)` took what the
/// router held at that moment: tokens of a plain relay to the router, of a failed callback, or of a refused hand-off,
/// which `sweep` sends to `failedDeliveryAddress` (code review, 2026-11-18, third round). This contract holds nothing,
/// gives no approval and has no owner, so the call can reach nothing that belongs to anyone. Anything sent to it (a
/// token transfer, coin from a self-destruct) is not protected: any follow-up call can move it. It is not where funds
/// go, and nothing in the bridge pays it.
///
/// The data from the router is packed, with no selector: the gas of the call (one word), the 20 byte target, then the
/// call data, which fills the rest. These are the last word of the router's `FeeDirector` (its `callGas`, at most
/// `DeliveryRouter.MAX_CALL_GAS`) and the bytes that follow it, so the router passes them in place with no copy. The
/// router always sends at least the 52 bytes of the gas word and the target.
///
/// The gas rule is the one of `ExactGasCall`, written out in assembly so that the code stays small: the router creates
/// this contract in its constructor, and the creation of the router must stay under the gas cap of one transaction
/// (`CreationGasCap.t.sol`). (a) Before the call it requires `gas + gas / 63 + ExactGasCall.CALL_OVERHEAD +
/// RETURN_RESERVE`, else it reverts with `ExactGasCall.InsufficientGas(available, required)`. (b) After a failed call
/// that leaves less than `gas / 63`, the target received less than its gas: it reverts with
/// `ExactGasCall.CallOutOfGas(gas)`. The router passes either revert up, so the delivery can run again with more gas.
/// Otherwise it answers one word: 1 when the target succeeded, 0 when it failed with its whole gas. It copies no
/// return data of the target. `RouterCaller.t.sol` checks the rule at the boundary.
contract RouterCaller {
/// @notice The gas that this contract keeps after the call to the target, to return its answer. A target that
/// burns its whole gas leaves at least this much, so its failure is always answered.
uint256 internal constant RETURN_RESERVE = 1_000;
/// @notice The router that created this contract, the only account that may use it.
address public immutable router;
/// @notice The caller is not the router.
error NotRouter(address caller);
constructor() {
router = msg.sender;
}
/// @notice Calls the target with exactly the gas of the first word, no native value and the data after the target.
/// Only the router may call it, and it takes no coin. It answers one word: 1 when the target succeeded, else 0.
fallback() external {
address only = router;
uint256 overhead = ExactGasCall.CALL_OVERHEAD + RETURN_RESERVE;
bytes4 notRouter = NotRouter.selector;
bytes4 insufficientGas = ExactGasCall.InsufficientGas.selector;
bytes4 callOutOfGas = ExactGasCall.CallOutOfGas.selector;
assembly {
// The memory of this frame holds only the call data or an error; the frame ends in this block.
if iszero(eq(caller(), only)) {
mstore(0, notRouter)
mstore(4, caller())
revert(0, 36)
}
let gasAmount := calldataload(0)
let length := sub(calldatasize(), 52)
calldatacopy(0, 52, length)
let required := add(add(gasAmount, div(gasAmount, 63)), overhead)
let available := gas()
if lt(available, required) {
mstore(0, insufficientGas)
mstore(4, available)
mstore(36, required)
revert(0, 68)
}
let success := call(gasAmount, shr(96, calldataload(32)), 0, 0, length, 0, 0)
if and(iszero(success), lt(gas(), div(gasAmount, 63))) {
mstore(0, callOutOfGas)
mstore(4, gasAmount)
revert(0, 36)
}
mstore(0, success)
return(0, 32)
}
}
}
src/hardened/mediator/ExactGasCall.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/// @title ExactGasCall
/// @notice A call that gets exactly the gas that a sender stated, or none at all. The rule is the same wherever a
/// sender states a gas number for a call (the callback of the mediator, the follow-up call of a router, which
/// `RouterCaller` makes with this rule written out in assembly): not enough gas
/// reverts the whole delivery, so it can run again with more gas; a callee that fails with the gas it was promised is
/// a recorded failure, and the delivery completes.
/// @dev Two checks, one on each side of the call.
/// (a) Before the call. The EVM forwards at most 63/64 of the gas left, so the call can receive `gasAmount` only when
/// `gasleft() >= gasAmount + gasAmount / 63` at the moment it forwards. Between this check and that moment the call
/// spends some gas of its own: the address access (2,600 cold), a second access of 2,600 when the target is an account
/// that delegates its code (EIP-7702), and the opcodes that prepare the call; after the call, check (b) spends a few
/// more before it reads the gas left. `CALL_OVERHEAD` (6,000) covers all of it. Measured (`ExactGasCall.t.sol`):
/// 2,845 gas with a cold target, 5,445 with a cold target that delegates to a cold account. The caller adds `reserve`,
/// the gas that it needs after the call. So the check requires `gasAmount + gasAmount / 63 + CALL_OVERHEAD + reserve`;
/// less gas reverts with `InsufficientGas`.
/// (b) After a failed call. Let `L` be the gas left at the moment the call forwards. Check (a) gives
/// `L >= gasAmount + gasAmount / 63 + reserve + t`, where `t` is the gas that check (b) spends before it reads the gas
/// left. Then `L - L / 64 >= gasAmount`, so the callee received all of `gasAmount`, and a callee that used all of it
/// leaves at least `L - gasAmount - t >= gasAmount / 63 + reserve` when check (b) reads the gas left. So a failed call
/// that leaves less than `gasAmount / 63` received less than its gas: it reverts with `CallOutOfGas`. On the EVM of
/// today check (a) makes that impossible; check (b) keeps the rule if a call ever spends more than `CALL_OVERHEAD`
/// before it forwards. A failed call that leaves more ran with the gas that it was promised. The sum holds for any
/// `reserve`, zero included: without `CALL_OVERHEAD`, a caller with a reserve smaller than the call's own gas could
/// see a callee that received all of its gas and failed reported as `CallOutOfGas`.
/// The call copies no return data, so a callee cannot spend the gas of the caller with a large answer or a large
/// error.
library ExactGasCall {
/// @notice The gas that the call spends of its own between check (a) and the moment it forwards, and that check (b)
/// spends before it reads the gas left. Check (a) requires it on top of the gas of the call and its 63/64 share.
uint256 internal constant CALL_OVERHEAD = 6_000;
/// @notice The gas left cannot give the call its gas under the 63/64 rule, plus `CALL_OVERHEAD` and the reserve of
/// the caller.
error InsufficientGas(uint256 available, uint256 required);
/// @notice The call failed after it received less than its gas. The delivery can run again with more gas.
error CallOutOfGas(uint256 gasAmount);
/// @notice Calls `target` with exactly `gasAmount`, no native value, and the bytes of `data` from `start` on.
/// @param target The callee.
/// @param gasAmount The gas that the callee gets.
/// @param reserve The gas that the caller needs after the call. Check (a) adds it. Any value is sound, even zero.
/// @param data The memory that holds the call data.
/// @param start The offset of the call data in `data`. The call data runs to the end of `data`.
/// @return success Whether the call succeeded.
function callWithExactGas(address target, uint256 gasAmount, uint256 reserve, bytes memory data, uint256 start)
internal
returns (bool success)
{
uint256 required = gasAmount + gasAmount / 63 + CALL_OVERHEAD + reserve;
uint256 available = gasleft();
if (available < required) revert InsufficientGas(available, required);
uint256 length = data.length - start;
assembly ("memory-safe") {
success := call(gasAmount, target, 0, add(add(data, 32), start), length, 0, 0)
}
if (!success && gasleft() < gasAmount / 63) revert CallOutOfGas(gasAmount);
}
}
Compiler Settings
{"viaIR":false,"remappings":["@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/","forge-std/=lib/forge-std/src/","erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/","halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/","openzeppelin-contracts/=lib/openzeppelin-contracts/"],"outputSelection":{"*":{"*":["abi","evm.bytecode","evm.deployedBytecode"]}},"optimizer":{"runs":200,"enabled":true},"metadata":{"useLiteralContent":false,"bytecodeHash":"none","appendCBOR":false},"libraries":{},"evmVersion":"shanghai"}
Contract ABI
[{"type":"constructor","stateMutability":"nonpayable","inputs":[]},{"type":"error","name":"NotRouter","inputs":[{"type":"address","name":"caller","internalType":"address"}]},{"type":"fallback","stateMutability":"nonpayable"},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"router","inputs":[]}]
Contract Creation Code
0x60a0604052348015600e575f5ffd5b503360805260805161014d6100305f395f8181602b015260ea015261014d5ff3fe608060405234801561000f575f5ffd5b5060043610610029575f3560e01c8063f887ea40146100e5575b7f00000000000000000000000000000000000000000000000000000000000000005f6100596103e8611770610128565b9050632462ed0960e01b6323e228cb60e01b634de8e2d960e01b33851461008657825f523360045260245ffd5b5f35603436038060345f3785603f83048301015a818110156100b257855f52806004528160245260445ffd5b50505f5f825f5f60203560601c87f19050603f82045a10811516156100dd57825f528160045260245ffd5b805f5260205ff35b61010c7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b03909116815260200160405180910390f35b8082018082111561014757634e487b7160e01b5f52601160045260245ffd5b9291505056
Deployed ByteCode
0x608060405234801561000f575f5ffd5b5060043610610029575f3560e01c8063f887ea40146100e5575b7f000000000000000000000000dd78014c06b49d3056ffd5f15b41f8bad8bf047c5f6100596103e8611770610128565b9050632462ed0960e01b6323e228cb60e01b634de8e2d960e01b33851461008657825f523360045260245ffd5b5f35603436038060345f3785603f83048301015a818110156100b257855f52806004528160245260445ffd5b50505f5f825f5f60203560601c87f19050603f82045a10811516156100dd57825f528160045260245ffd5b805f5260205ff35b61010c7f000000000000000000000000dd78014c06b49d3056ffd5f15b41f8bad8bf047c81565b6040516001600160a01b03909116815260200160405180910390f35b8082018082111561014757634e487b7160e01b5f52601160045260245ffd5b9291505056