EIP-8455: RESERVOIR Opcode

Discussion topic EIP-8455

Summary

EIP-8037 splits gas into execution gas and state gas, and lets state gas be paid from a reservoir that GAS does not report. EIP-8141 frame transactions have a similar per-frame state_gas_left. As a result, contracts can no longer see their full remaining budget, and measuring a sub-call with two gasleft() readings under-counts any state gas the reservoir paid for.

This EIP adds one opcode, RESERVOIR (0x4d), which pushes the state gas available to the current frame that GAS does not include:

  • for reservoir-model transactions (EIP-8037), the frame’s state_gas_reservoir
  • inside an EIP-8141 frame transaction, the frame’s state_gas_left

GAS and RESERVOIR together let a contract read its whole remaining budget and measure the full cost of a code region or call, state gas included.

Motivation

Protocols that meter sub-calls by subtracting two gasleft() readings, such as the ERC-4337 EntryPoint, under-count state gas whenever the reservoir pays for it. A call that creates one storage slot looks 97,920 gas cheaper when the reservoir funds the slot than when gas_left does. EIP-8037 points this out and asks such protocols to account for state gas explicitly, but no instruction currently exposes the value they need. RESERVOIR exposes it.

Design notes

  • Opcode 0x4d. It sits in the block/transaction environment range (0x40–0x4f) and is currently unassigned. There is no free byte next to GAS (0x5a).
  • GAS is not redefined. Making GAS return gas_left + reservoir would break its main use as the CALL gas argument, which is capped at 63/64 of gas_left. It would also change behavior for deployed contracts.
  • Separate instruction rather than a combined one. One opcode returning both pools was rejected to keep the interface aligned with GAS. A CALL variant taking a state-gas limit is a larger change that could later build on RESERVOIR.
  • EIP-7702. Authorization charges are applied before the first frame and are not refilled by a top-level revert, so delegated code cannot observe an inflated value.

Security considerations

  • RESERVOIR depends on the inclusion context the same way GAS does. ERC-7562 validation rules restrict GAS during ERC-4337 validation and should restrict RESERVOIR in the same way.
  • Contracts whose success depends on RESERVOIR can make the set of sufficient tx.gas values non-monotonic, as with GAS, which affects gas estimation.
  • State gas prices and the execution/state split may change in later forks, so contracts should measure consumption rather than hard-code expected amounts.

Reference implementation & tests

The assets include patches for go-ethereum and execution-specs, plus test fillers covering both the reservoir model and frame transactions.

Update Log

External Reviews

None as of 2026-10-28.

Outstanding Issues

None as of 2026-10-28.

Feedback is especially welcome on:

  • the choice of 0x4d versus other free bytes, given pending proposals for 0x4c, 0x4e and 0x4f
  • whether ERC-4337 / ERC-7562 maintainers agree on the validation-time restriction
  • whether returning the reservoir alone is enough, or a combined view would be useful too
2 Likes

Two notes from the 4337 side.

ERC-7562 doesn’t block GAS outright: OP-012 allows it when it’s immediately followed by a *CALL, since that’s its real use as a gas argument. RESERVOIR has no use like that, and its value starts as whatever the bundler put in tx.gas above the EIP-7825 cap, so the same UserOp can read different values in simulation and in the bundle. I’d list it in OP-011 next to SLOTNUM rather than mirror GAS. Today 0x4d is caught by OP-013 as an unassigned opcode, and it drops out of that rule the day it’s assigned.

On reservoir alone vs a combined view, worth saying in the spec that a measurement has to diff GAS + RESERVOIR as one sum. When a child call succeeds, the parent moves min(state_gas_reservoir, state_gas_from_gas_left) from the reservoir back into gas_left (the step 8037 has for refills that land in a different frame than their charge), so either value diffed alone can misreport the call’s cost, while the sum stays put.

1 Like

Thanks @Zealynx, both points are spot on. I’ve updated the draft and the EELS test suite.

On ERC-7562: agreed. GAS only gets a pass under OP-012 when feeding a *CALL, and RESERVOIR has no equivalent use. It’s also less bounded than GAS since the full reservoir is forwarded to every frame regardless of the validation gas limit, and its starting value just reflects whatever tx.gas the bundler set above the EIP-7825 cap (plus any ops that ran earlier in the bundle). I updated Security Considerations to place RESERVOIR under OP-011 next to SLOTNUM, with a note that this needs to land by activation since 0x4d drops out of OP-013 once assigned. Happy to open the ERC-7562 PR when this gets closer to being scheduled.

On diffing the sum vs. individual counters: good catch. The draft defined GAS + RESERVOIR as the frame’s remaining budget, but didn’t explicitly warn against diffing either reading on its own across a call. I added a paragraph under Relationship to GAS pointing to the EIP-8037 merge step (min(state_gas_reservoir, state_gas_from_gas_left)) as the reason. While I was in there, I also tightened Security Considerations: a drop in RESERVOIR across a call still shows it drew on the reservoir, without implying that an unchanged value means zero state gas was charged.

I also added your cross-frame refill scenario (first child creates a slot, second child clears it) to the spec and the EELS fillers:

  • With R = 500,000, the refill stays in RESERVOIR: the caller reads R again, and GAS only drops by the execution cost of the call.
  • With tx.gas <= TX_MAX_GAS_LIMIT, the clearing child sees RESERVOIR = 97,920, then the merge step shifts it back into gas_left, leaving the caller at RESERVOIR = 0 while its GAS rises.

In both runs GAS + RESERVOIR goes up across the call as expected (also sanity-checked the filler by disabling the merge step in EELS, which breaks the second case).

How should an ERC-4337 consumer handle a negative measured cost when GAS + RESERVOIR increases across a call?

Suppose one UserOperation creates a slot and a later operation clears it within the same bundle. A checked unsigned subtraction could revert. Clamping the result to zero would discard the excess credit.

Could you include a worked accounting example showing who receives that credit and how per-operation charges reconcile with the bundle’s actual cost? Measuring the net budget change seems useful but does not by itself define how to charge each operation.

1 Like

Good question. You’re right that measuring the budget delta doesn’t by itself define a charging rule—that policy belongs on the ERC-4337 side, though the numbers make the trade-offs clear.

Signed arithmetic. Consumers have to use signed arithmetic. This isn’t new with RESERVOIR: under EIP-8037, a plain gasleft() delta already goes negative whenever gas_left funded the slot, and EIP-8037 explicitly notes that this reverts under checked unsigned subtraction.

Worked example. Here is your exact scenario filled on EELS (Bogota + EIP-8037 + EIP-8455), where op 1 creates a shared slot and op 2 clears it (before - after):

Case ΔGAS ΔRESERVOIR m (sum)
op 1 (R = 500,000) 18,275 97,920 116,195
op 2 (R = 500,000) 3,375 −97,920 −94,545
op 1 (R = 0) 116,195 0 116,195
op 2 (R = 0) −94,545 0 −94,545

The per-op sums (m) are identical regardless of which pool funded the slot; only the internal split changes. Across both ops, Σm = 21,650. Compared against a no-op control bundle (Σm_control = 6,088 across the two calls, 69,628 total tx gas), this bundle uses 85,190 tx gas before traditional refunds—an increase of 15,562, which reconciles to the exact gas with Σm - Σm_control (21,650 - 6,088).

Who gets the credit. The 97,920 refill is never lost. Whether it lands in the reservoir or gas_left, it remains unused gas that the protocol returns to tx.origin (the bundler). The charging policy only decides how the bundler passes it on:

  • Signed charges (116,195 and −94,545): Total charges equal the ops’ net execution cost, and the credit goes to op 2 (funded out of op 1’s charge, which still pays for a slot that didn’t persist).

  • Clamped at zero, max(0, m) (116,195 and 0): op 2’s execution cost is covered by the refill, and the bundler keeps the remaining 94,545. This matches how the traditional refund counter is already handled today (e.g., the 10,000 STORAGE_WRITE refund at the end of this tx, which neither opcode sees).

Clamping is the conservative default since no op gets paid more than it spent, and crediting op 1 would require an end-of-bundle settlement pass since op 1 is already settled before op 2 runs. I’ve added a short paragraph to Measurement, not attribution covering this, while leaving the concrete charging policy to ERC-4337.

1 Like

What’s the plan for existing ERC-4337 deployments under 8037? Is the expectation that accounts and paymasters move to a new EntryPoint?

Deployed EntryPoints can’t start using a new opcode, and we can’t assume every account can change its trusted EntryPoint. How are those deployments supposed to keep working?

I understand this EIP is scoped to measurement. But saying the charging policy belongs to 4337 still leaves the compatibility question unanswered. Even for a new EntryPoint, the CALL gas argument doesn’t bound reservoir consumption, so preserving per-UserOp spending limits and prefund guarantees needs an actual integration.

Is there a concrete proposal covering that, including deployments that cannot migrate? I don’t think we can treat a new opcode and a future EntryPoint as a compatibility plan for existing accounts.

1 Like

Fair challenge. Let me separate what EIP-8037 already decides for deployed contracts from what a new EntryPoint needs to do, because the compatibility story for non-migrating accounts turns out not to depend on this opcode at all.

Deployed EntryPoints under EIP-8037 (R = 0). Whether a bundle has a reservoir is entirely the bundler’s choice: R = max(0, tx.gas - TX_MAX_GAS_LIMIT), so R = 0 whenever tx.gas stays at or below the 16,777,216 cap. With R = 0, every state charge is paid from gas_left. The callGasLimit passed to CALL then bounds the entire cost of the op, gasleft() deltas include state gas, and verification-gas checks keep working. Per-UserOp limits and prefund guarantees hold just as they do today, with two trade-offs: bundles are capped at 16.77M gas, and state-heavy ops cost more due to EIP-8037’s repricing. That is the compatibility plan for accounts that cannot migrate—it’s a bundler configuration (simply keeping tx.gas at or below the cap), not a contract upgrade.

What if op 2 clears a slot that op 1 created earlier in the same R = 0 bundle? In my previous reply, I assumed this would drive preGas - gasleft() negative inside deployed EntryPoints and revert under checked arithmetic—but it actually doesn’t, thanks to EntryPoint’s frame hierarchy. When op 1’s innerHandleOp returns, its state charge is merged up into the outer handleOps frame. Consequently, the innerHandleOp frame that meters op 2 has zero state_gas_from_gas_left of its own: op 2’s refill stays in the reservoir throughout innerHandleOp and only merges back into gas_left when innerHandleOp returns to handleOps.

I verified this on EELS with an EntryPoint-shaped test (test_refill_two_levels): across op 2, the inner frame sees GAS drop by 478 and RESERVOIR rise by 97,920 under both R = 500,000 and R = 0; only the outer handleOps frame (when R = 0) sees GAS jump by 97,216 after the inner call returns. Since v0.6 and v0.7 both compute actualGas inside innerHandleOp, op 2 is simply charged its 478 execution gas while the 97,920 refill ends up as unused transaction gas refunded to the bundler. Nothing wraps and nothing reverts—deployed EntryPoints naturally get the clamped policy out of the box.

A new EntryPoint with R > 0. Agreed that CALL’s gas argument doesn’t cap reservoir usage since EIP-8037 forwards the full reservoir to child frames. However, a new EntryPoint can enforce a hard per-op state-gas bound using the innerHandleOp self-call frame it already has:

  1. Read RESERVOIR before and after the user call inside innerHandleOp.

  2. If the reservoir decrease exceeds the UserOp’s state-gas allowance, revert innerHandleOp with a dedicated revert code.

  3. EIP-8037’s rollback restores the reservoir to its pre-innerHandleOp baseline, leaving subsequent ops in the bundle untouched while charging the offending UserOp via the existing postOpReverted flow.

The allowance can be a new UserOp parameter (or carved out of callGasLimit), covered by the prefund, with actualGas (and the unused-gas penalty) measured via the combined GAS + RESERVOIR delta. I added test_bounded_child to the EELS patch to demonstrate this: a wrapper frame enforcing a 1-slot (97,920) allowance lets op A (1 slot) succeed while reverting op B (2 slots), restoring the caller’s RESERVOIR to R - 97,920 and rolling back op B’s state.

As for bundler risk: the bundler chooses R and can size it to the sum of allowances in the bundle (any shortfall simply spills into gas_left, where callGasLimit bounds it as today). Better yet, an EntryPoint written against GAS + RESERVOIR works unchanged in EIP-8141 frame transactions, where per-frame state budgets are protocol-enforced and read by RESERVOIR.

In summary:

  1. Non-migrating deployments run with R = 0 (bundler keeps tx.gas <= 16.77M), requiring zero contract changes and safely surviving cross-op storage clears.

  2. Future EntryPoints (R > 0) enforce per-op state allowances by checking RESERVOIR deltas inside innerHandleOp and reverting on excess, while metering via GAS + RESERVOIR so refill credits can go to the UserOp.

Point (1) belongs in EIP-8037’s backwards-compatibility notes, and (2) in a future ERC-4337 revision. I’ve added a note on the bound-by-revert pattern to Security Considerations in EIP-8455, and I’d be glad to help draft the ERC-4337 integration spec if the maintainers find it useful.

1 Like

Could you add a regression test using an actual deployed EntryPoint implementation for the two-operation example? The frame placement turned out to change the conclusion about unsigned subtraction. Testing the real accounting path would make the compatibility claim stronger than an EntryPoint-shaped wrapper alone.

Makes sense. I’ll put together an EELS regression test running the two-op bundle through the actual unmodified EntryPoint v0.7 runtime bytecode and follow up here with the fixtures and numbers.

@SergeevDmitry Done. test_entrypoint_v07_two_ops (in the assets, tests/bogota/eip_reservoir/test_entrypoint.py) runs the two-operation bundle through the EntryPoint v0.7.0 runtime bytecode on EELS Bogota with EIP-8037 active. The bytecode is compiled from the tag with the repository’s own settings (solc 0.8.23, optimizer at 1,000,000 runs, viaIR); the compile script is in the assets. To be precise about what is and is not exercised: the runtime is installed in the fixture pre-state, with the SenderCreator immutable resolved to the fixture’s deployed address and the constructor-initialized storage (ReentrancyGuard._status) supplied explicitly, so the constructor is not run as a deployment transaction. Nothing in the accounting or control flow is replaced by a wrapper: the tested handleOps → innerHandleOp → _postExecution path is the production implementation. The accounts are minimal IAccount stubs that accept every operation and pay their prefund, so no signatures are involved. Per-op actualGas is inferred from the EntryPoint’s own deposits mapping as (prefund − finalDeposit) / GAS_PRICE with GAS_PRICE = 10; each account starts with no deposit and pays exactly its prefund in validation, so this is the gas _postExecution charged, penalty included. Following the suggestion, the test now also pins the two UserOperationEvent logs: success = true for both, the userOpHash recomputed as getUserOpHash does, the sender, and actualGasUsed equal to the deposit-inferred value (a mutant expecting success = false fails on the log data).

Operation 1 creates a slot in a shared contract, operation 2 clears it, both in one handleOps call:

Variant op 1 actualGas op 2 actualGas
create, clear; R = 500,000 138,225 124,740
create, clear; tx.gas ≤ TX_MAX_GAS_LIMIT 324,273 222,660
create only; R = 500,000 138,225 124,740
control, no slot created; R = 500,000 138,225 124,740

Three things the real accounting path shows:

  1. No revert, no wrap. handleOps succeeds in all four variants, both operations report success = true, and op 2 is charged a positive amount in both gas configurations, including when it clears op 1’s slot. The two configurations handle the refill differently and neither lets it reach op 2’s actualGas: below the cap it reaches gas_left in the outer handleOps frame only after innerHandleOp has computed actualGas; with sufficient reservoir capacity it returns to the reservoir and stays invisible to gasleft(). In both cases the credit ends up as the bundler’s unused gas.

  2. With enough reservoir capacity, the EntryPoint’s gasleft() accounting does not observe reservoir-funded state gas. In this bundle R = 500,000 covers every state charge, and the create, create-and-clear and control variants produce identical per-operation charges. This is conditional on capacity: once the reservoir is exhausted, further charges draw on gas_left and become visible. In the create-and-clear variant the measured windows incur 293,760 in gross state-gas charges, 195,840 for op 1 (its nonce slot and the shared slot) and 97,920 for op 2 (its nonce slot). Clearing the shared slot returns 97,920 to the reservoir, so the net consumption from those charges is 195,840. The refill improves the outer transaction’s accounting but does not change the actualGas already computed for op 2. None of this is attributed to either account; the bundler pays it. That is the under-counting the EIP’s motivation describes, measured on the production runtime rather than on a wrapper.

  3. Without a reservoir, the charges decompose exactly. Op 1: 138,225 + 2 × 97,920 − 9,792 = 324,273, the two slots less the 10% unused-gas penalty on the execution-phase slot. Op 2: 124,740 + 97,920 = 222,660, its nonce slot only; the cleared-slot refill is not credited. The deposit write after the measurement is paid by the bundler in every variant, as it is today.

What this establishes, and no more: on the genuine v0.7 accounting path, for this two-operation bundle with stub accounts and these two gas configurations, clearing the slot the previous operation created causes neither a wrap nor a revert, the below-cap configuration executes with its existing bounds and accounting intact, and with sufficient reservoir capacity the state gas falls outside per-operation accounting and onto the bundler. It is concrete evidence for the production v0.7 runtime rather than an EntryPoint-shaped wrapper; it is not a guarantee across EntryPoint versions, account implementations, operation sequences or gas configurations. The fixtures (state and blockchain formats) are in the assets alongside the others.

1 Like

cc @yoav @dror @forshtat — since we’ve been discussing how ERC-4337 handles EIP-8037’s state-gas reservoir (and testing against the unmodified EntryPoint v0.7 bytecode above), I’d love to get your thoughts on this. Specifically:

  1. Using RESERVOIR (0x4d) alongside GAS (GAS + RESERVOIR) in future EntryPoint versions to meter reservoir-funded state gas and enforce per-UserOp state allowances (via reverting innerHandleOp on excess).

  2. Adding RESERVOIR (0x4d) to the banned opcodes in ERC-7562 (OP-011, alongside SLOTNUM) upon activation.

This addresses the specific test gap I raised. The distinction between avoiding a revert and correctly attributing state-gas costs is now much clearer. Thanks for testing the production accounting path and stating the limits of the result.

1 Like