Skip to content

[smr-moonshot#5339] Bound BlockMeta.blockPrologue's own gas and drop the block-metadata transaction's gas limit - #99

Merged
isaacdoidge merged 8 commits into
feature/revm-43-syncfrom
issue-5339
Dec 3, 2026
Merged

isaacdoidge merged 8 commits into
feature/revm-43-syncfrom
issue-5339

Conversation

@isaacdoidge

@isaacdoidge isaacdoidge commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

Implements the fork side of Entropy-Foundation/smr-moonshot#5339 on the revm 43 sync branch. Entropy-Foundation/smr-moonshot#5357 pins this branch and removes what read or recorded the carried limit; it is stacked on smr-moonshot#5341, which pins feature/revm-43-sync.

What

BlockMeta.blockPrologue() completes within the block-metadata transaction's gas limit for every registration BlockMeta accepts and whatever its targets do, and the BlockMetadata transaction no longer carries a gas limit.

Changes

BlockMeta.sol (changed in place; no UUPS upgrade, since BlockMeta runs only on Devnet, which is re-genesised)

  • blockPrologue() calls each entry in assembly with a zero-length output buffer, so no return data is copied. CallFailed logs at most the first MAX_LOGGED_RETURN_DATA = 128 bytes of the return data, built in memory past the free-memory pointer without advancing it, so every entry costs the same. The event signature is unchanged.
  • register and updateExecutionOrder require the sum of the entries' gas limits plus ENTRY_GAS_RESERVE (16,500) per entry plus PROLOGUE_GAS_RESERVE (12,000) to fit in BLOCK_METADATA_GAS_LIMIT × (63/64)², the square covering the proxy's DELEGATECALL and the CALL to each entry. BLOCK_METADATA_GAS_LIMIT = 2^24 is the gas limit the transaction executes with (DEFAULT_BLOCK_METADATA_GAS_LIMIT). One private helper, gasBudgetLeft, gives both those checks and the new view maxRegistrableGasLimit().
  • The configurable prologue cap is removed: the blockPrologueGasCap storage variable, setBlockPrologueGasCap, its event and error, and the cap argument of initialize (now initialize(address)). The owner that set it is the only party that registers entries, so it bounded nothing the owner did not already control.
  • blockPrologue, register, deregister, deregisterAt, updateExecutionOrder and _authorizeUpgrade are nonReentrant (OZ ReentrancyGuardTransient, no storage slot), so an entry cannot change the entry list or the implementation during the loop.
  • GovActions.s.sol InitializeCycleMonitoring checks against maxRegistrableGasLimit().

BlockMetadata transaction (crates/supra-extension/src/transactions/block_metadata.rs)

  • The gas_limit field and its builder setter are removed; Transaction::gas_limit returns DEFAULT_BLOCK_METADATA_GAS_LIMIT (2^24). The serialized forms change.
  • BLOCK_PROLOGUE_GAS_MEASURED_SPECS (PRAGUE, OSAKA) lists the specs the reserves were measured under. smr-moonshot checks that every spec it supports is on the list.

Measurement (crates/ee-tests/src/block_prologue_gas.rs)

  • Deploys BlockMeta from the genesis transactions and runs blockPrologue() as the node does (ExecutionMode::System, validate_caller then run_system_call), under each measured spec, with 1, 2, 64, 980 and 984 entries (984 is the most the budget admits). Every target is a cold EIP-7702-delegated account that consumes its whole gas limit and reverts with as much return data as the rest pays for.
  • Asserts the transaction succeeds, one CallFailed per entry carries the right 128-byte prefix, each entry receives exactly its gas limit, and the gas spent outside the entry calls is within the reserves.
  • Measured: 10,924 gas per entry; 7,866 outside the entries under the default Foundry profile, 7,761 under the production profile. Each reserve is the measured figure plus 50%, rounded up to a multiple of 500.

Genesis: block_prologue_gas_cap is removed from GenesisTransactionGeneratorConfig, and the genesis transaction calls initialize(owner).

Other: BlockMeta golden bytecode hash in generator.rs; Foundry tests for the budget boundaries, the per-entry reserve, the 128-byte prefix, reentrancy and maxRegistrableGasLimit against register (fuzzed); AUTOMATION_REGISTRY_GAS_GUIDE.md, README.md and comments.

Testing

  • cargo fmt --all --check, RUSTFLAGS=-Dwarnings cargo clippy --workspace --all-targets --all-features: clean.
  • cargo test --workspace: 678 passed, 11 ignored. cargo test --workspace --all-features: 691 passed, 12 ignored.
  • cargo test --release -p revm-ee-tests block_prologue_gas: 5 cases, each under PRAGUE and OSAKA, passed.
  • forge test: 696 passed. check_event_indexing.sh: pass. forge build --sizes: BlockMeta 5,866 bytes (default), 6,348 bytes (production).

🤖 Generated with Claude Code

isaacdoidge and others added 6 commits November 30, 2026 17:39
…logue gas cap at the block-metadata transaction's gas limit

blockPrologue calls each entry without copying its return data and logs at most
MAX_LOGGED_RETURN_DATA (128) bytes of it in CallFailed, from the same memory for every
entry, so that its own cost per entry does not depend on what a target returns.

register, updateExecutionOrder and setBlockPrologueGasCap require the entries' gas limits,
ENTRY_GAS_RESERVE (16,500) per entry and PROLOGUE_GAS_RESERVE (12,000) to fit in
63/64 * 63/64 of the cap: one 63/64 for the proxy's DELEGATECALL to the implementation and
one for the CALL to each entry. With that bound every entry's call receives its whole gas
limit and blockPrologue completes. maxRegistrableGasLimit() returns the largest gas limit a
new entry can have, and InitializeCycleMonitoring checks against it.

initialize and setBlockPrologueGasCap refuse a cap above MAX_BLOCK_PROLOGUE_GAS_CAP, 2^24,
the gas limit the node executes the block-metadata transaction with.

blockPrologue and the functions that change the entry list, the cap or the implementation
are nonReentrant (transient storage), so that none of them changes while the loop runs.

BlockMeta changes in place: it exists only on Devnet, which is re-genesised.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ETADATA_GAS_LIMIT

BlockMetadata no longer carries a gas limit: Transaction::gas_limit returns
DEFAULT_BLOCK_METADATA_GAS_LIMIT (2^24) for every block-metadata transaction, and the builder
has no gas_limit setter. BlockMeta keeps its cap at or below that limit and bounds its own
cost within the cap, so the limit changes no execution result.

The field's removal changes the transaction's serde forms and so its hash.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…k's revm and measure its gas

The ee-tests deploy BlockMeta from the genesis transactions and run blockPrologue as the node
runs the block-metadata transaction, in ExecutionMode::System through run_system_call, under
the Prague and Osaka gas schedules. With the entries' gas limits and reserves filling the
budget at MAX_BLOCK_PROLOGUE_GAS_CAP, for 1, 2, 64 and the most entries the cap admits, and
cold EIP-7702-delegated targets that spend their whole gas limit and revert with more return
data than CallFailed logs, they check that blockPrologue succeeds, that every entry receives
its whole gas limit, and that the gas spent outside the entries is within the reserves.

Measured: 10,924 gas per entry and 7,866 outside the entries, for both the default and the
production Foundry profile within 18 gas. ENTRY_GAS_RESERVE and PROLOGUE_GAS_RESERVE are
those figures plus 50%, rounded up to a multiple of 500.

AUTOMATION_REGISTRY_GAS_GUIDE.md describes the bound.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rom one helper

register, updateExecutionOrder, setBlockPrologueGasCap and maxRegistrableGasLimit all read
gasBudgetLeft, which returns whether the entries fit the cap's budget and the gas the budget
leaves after them. register accepts a gas limit up to what the helper leaves for one more
entry, the figure maxRegistrableGasLimit returns, so the two cannot disagree. A fuzz test
registers maxRegistrableGasLimit and one gas more at random caps beside a first entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…red under

BLOCK_PROLOGUE_GAS_MEASURED_SPECS (Prague and Osaka) names the EVM specs under which
ENTRY_GAS_RESERVE and PROLOGUE_GAS_RESERVE were measured. The ee-test runs blockPrologue under
every spec on it, so adding a spec to the list re-runs the measurement under it. smr-moonshot
checks its supported spec codes against the list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ransaction's gas limit and remove the configurable cap

BlockMeta no longer has a block prologue gas cap: the blockPrologueGasCap storage variable,
setBlockPrologueGasCap, the cap argument of initialize, InvalidGasCap and
BlockPrologueGasCapUpdated are removed. register and updateExecutionOrder budget against
BLOCK_METADATA_GAS_LIMIT (2^24), the gas limit the node executes the block-metadata transaction
with: the entries' gas limits, ENTRY_GAS_RESERVE per entry and PROLOGUE_GAS_RESERVE within
63/64 * 63/64 of it. The ee-test asserts that BLOCK_METADATA_GAS_LIMIT equals
DEFAULT_BLOCK_METADATA_GAS_LIMIT.

The genesis config loses block_prologue_gas_cap with its validation and tests, and the genesis
transaction initializes BlockMeta with its owner only. BlockMeta changes in place: it exists
only on Devnet, which is re-genesised.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… and upgraded implementations

The bound holds while the node's gas limit for the block-metadata transaction is at
least BlockMeta.BLOCK_METADATA_GAS_LIMIT, and for an implementation whose blockPrologue
the reserves were measured against. Document the order of a change to the limit and the
measurement an upgraded implementation needs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
GovActions.t.sol keeps #100's digest tests and this branch's
test_acceptsTheLargestLimitBlockMetaAccepts, which replaced
test_acceptsALimitEqualToTheCallableShare.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@isaacdoidge
isaacdoidge added this pull request to stack #103 December 3, 2026 10:00
@isaacdoidge
isaacdoidge merged commit 482bdc0 into feature/revm-43-sync Dec 3, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant