Tracked functions
What trackState guarantees, storage layout rules, and what keeps a function extractable.
A tracked function is one whose execution an operator may reproduce off-chain. Marking it does two things: it declares intent, and it advances the transition counter that binds a signed payload to one specific state.
function recompute(uint32 rounds) external trackState {
// ...
}What trackState actually does
trackState increments a counter at a fixed slot before the function body
runs. verifyAndUpdate carries the same modifier, and enforces:
require(transitionIndex + 1 == stateTransitionCount(), InvalidTransitionIndex());So a payload is signed against a specific counter value and applies only while the contract still sits at that value. Anything that advances the counter (a settlement, or a direct call to another tracked function) invalidates every outstanding payload.
Mark every mutating path, not just the expensive one. verifyAndUpdate
bumps the counter itself, so a contract with no trackState anywhere still
settles and still looks correct. What breaks is replay protection: a direct call
to an unmarked function changes state without advancing the counter, so a
payload computed against the old state stays applicable and overwrites the
newer values when submitted.
The counter lives at keccak256("gasKiller.stateTracker") - 1, outside any
Solidity-allocated slot, so it never collides with your variables.
Storage layout matters
A settlement is a list of raw STORE operations at specific slot numbers,
computed off-chain from a simulation of your function. It writes slots, not
variables. Two consequences:
- The layout is part of your interface with a signed payload. Reordering state variables changes which slot holds what. Any payload assembled before the change writes the old positions.
- The layout must be predictable. Declare tracked state first and check it:
forge inspect src/Counter.sol:Counter storage-layoutSDK state is unaffected either way, since the configuration namespace is ERC-7201 and the transition counter is at a hashed slot, so neither consumes slots your variables could occupy.
What keeps a function extractable
Operators derive the diff by simulating your call and reading which slots changed. That works cleanly when the tracked function:
- Succeeds. A reverting call has no diff to sign; analysis fails rather than producing an empty payload.
- Writes only its own contract's storage. Storage changes in other accounts cannot be represented as a plain slot diff and need a full call replay, which is dramatically more expensive to extract and may not complete at all for a heavy function.
- Makes no state-changing external calls. Read-only calls (
STATICCALL, soview/pureon another contract) are fine and are ignored by the analysis.
Emitting logs is fully supported: they are reproduced as LOG0–LOG4
operations, including indexed topics.
The sweet spot is heavy compute, small diff: the cost of settling depends on how many slots changed, not on how much work produced them. A function that loops a million times and writes two slots settles for the same cost as one that loops twice.
If your design needs a state-changing external call, it is supported, but the call is replayed by running it, which is the expensive path, and it brings the reentrancy considerations below into play. When the callee is itself a Gas Killer contract, nested settlement avoids that cost.
Reading state during a transition
A settlement that makes an external call runs that code partway through
applying its changes, when your contract's state is neither the old one nor the
new one. Re-entering verifyAndUpdate reverts with ReentrantTransition, and
inTransition() reports the window. If other protocols read your contract and
your settlements make external calls, have those readers fail closed:
if (IGasKillerConsumer(target).inTransition()) revert MidTransition();Value-bearing transitions
Tracked functions can be payable. Submit the task with the ETH the call sends
as value, and the payload comes back carrying that same value. The
signature covers it, so the settlement only succeeds when sent with exactly
that amount. That is what makes crediting msg.value safe: nobody can settle
a deposit without sending the ETH.
ETH your function sends out (a transfer, or a payable call or deployment) is paid from the contract's balance at settlement. If the balance is short, the whole settlement reverts.
The settler can't add ETH. A settlement sent with more than the task's
value fails. If your function pays out of the contract's own balance, fund
it separately: GasKillerSDK has no receive(), so add one or a payable
funding function.
The router rejects a task with nonzero value (400 INVALID_REQUEST) unless
the target binds msg.value, which every contract on the current SDK does.
Check yours:
cast call "$TARGET" "supportsInterface(bytes4)(bool)" 0x0fd29ece --rpc-url "$RPC_URL"Checklist
- Every state-mutating function carries
trackState. - Tracked state is declared first, and the layout is pinned by a test.
- The tracked function succeeds, touches only its own storage, and makes no state-changing external calls.
- If other protocols read you and you make mid-transition calls, they check
inTransition(). - If the contract takes ETH, it reports
0x0fd29ece. - If it pays ETH out of its own balance, it has a way to be funded.
