Repository navigation
feat(satin): consensus limits as protocol params, mega-evme on both engines, byte-price grid - #399
Conversation
require_params, and so validate_schedule, now runs the params type's own validate() on the value a scheduled fork carries and reports ScheduleError::InvalidParams, so a node whose schedule type attaches its parameters without MegaHardforkConfig::with_params still refuses a bad value at load. with_params_unchecked, under test-utils, attaches a value no chain may carry for tests.
A schedule entry held one params value per fork, so attaching a second params type to a fork silently replaced the first. The entry now keeps one value per type, and fork_params_any looks a value up by fork and TypeId, so a fork can require several params types as validate_schedule already allows.
ProtocolLimits holds the limits every node of a chain must share: the per-transaction runtime limits and the block's execution-gas, state-gas, data-size and KV budgets. It is a Satin HardforkParams type, serde-ready for a chain configuration, whose validate() refuses a zero limit, a transaction data-size limit below a body and an unlimited detention cap. Its default is today's values. validate_schedule requires it, MegaHardforks::protocol_limits resolves it at a timestamp, and the unknown-chain fallback carries the default. Block execution does not read it yet.
…ck context MegaBlockExecutor now reads the ProtocolLimits of the fork active at the block's timestamp: it installs their per-transaction limits on the EVM at construction and again before every transaction, and holds the block to their four budgets. BlockLimits in the block context is the builder's policy only: the transaction gas, encoded-size and data-availability limits, and caps that can lower a block budget but never raise it (BlockLimits::within); its default restricts nothing. A block whose schedule carries no limits is refused before it starts (MissingProtocolLimits). The limiter is no longer a public field. Block tests run on a test chain whose limits are the unlimited set, attached through the test-only unchecked route, so each test runs under the limits it ran under before; a test that holds a block to a limit attaches its own.
…s not A block on a chain whose ProtocolLimits are not the defaults, attached through the checked route, stops a transaction at the chain's data-size limit and refuses one once it reached the chain's KV budget. A builder that packs under its own policy (a DA cap, a declared-gas cap, a block data-size cap below the chain's) and validators that re-execute its block under no policy or another one compute the same receipts, counters and state; the same block under different chain limits does not.
… parameters The spec page no longer says a node supplies the limits with each block: the per-transaction limits, the detention caps and the four block limits are protocol values the chain configuration carries as Satin's parameters, a configuration without them or with a value no chain can run on does not load, and a builder's transaction gas, encoded-size and data-availability limits are building policy a validator does not apply. AGENTS.md and the crate README describe ProtocolLimits, the building policy and the test-only route.
… covers The builder and validator test gave its candidates 200,000 gas, which a measurement build's higher byte prices exhaust, so the first write ran out of gas instead of being kept. Every transaction of the module now declares 2,000,000, and the builder's declared-gas cap is that figure.
mega-evme rejoins the workspace. A command runs on the engine its spec names: Satin on the in-tree sources, ported to the Satin engine; a spec from Equivalence to Rex6 on the released mega-evme and mega-evm 1.7.1, linked under aliases, with the user's arguments handed over unchanged. Rex7 is refused. Satin output adds a `satin` object with the gas by ledger and keeps every legacy field. The legacy line is pinned to the 1.7.1 lockfile's versions, and the release build selects the tool by manifest path.
…hain `replay --block N[..M]` runs each block on the engine its spec names and compares every receipt and the receipts root with the chain's; --verify turns a difference into exit code 2. One driver loads the block, its receipts and the state its parent left from a block cache or over RPC, and hands the engine plain data: the legacy executor reaches the 1.7.1 line only through its re-exports, the Satin one runs the counterfactual. Reads the recorded pre-state lacks fall back to the parent block over RPC and are folded into the cache.
The single-transaction replay forks state lazily over RPC; the block replay runs on the recorded pre-state. A mock RPC answering only from a recorded block serves the first, and on both engines four transactions must agree with the block replay's rows: gas, status, logs, cumulative gas, and on Satin the ledgers.
… engine tests/satin-differences.md is rendered from what the two engines produce on the same inputs and compared with the checked-in file: every run and tx fixture on both engines, and the three recorded mainnet blocks, per block and per call target. UPDATE_EVME_DIFFERENCES=1 rewrites it.
The docs, the crate README, the help text and the agent files describe how a spec picks the engine, the additive `satin` output, replay's engine auto-detection (an unknown chain now runs Satin, where 1.7.1 ran Rex7), --dump-fixture being legacy-only, and replay --block with its cache, records and exit codes. The build command selects the tool by manifest path.
A cache a legacy replay wrote lacks the EIP-7997 factory Satin's pre-block changes read, so the Satin examples pass --rpc, and say that later runs can drop it.
….7.1 did A `?` inside each dispatch arm returned before the report, so an error fell through to main and printed its Debug form twice. Satin commands now print the message once to stderr and exit 1. A legacy command's error is printed as the 1.7.1 binary printed it: Debug to stdout, then `Error:` with the Debug form to stderr, exit 1.
A transaction's gas limit covers its body's history, the state it adds and the records it keeps at the prices in effect, and a call that forwards all but a 64th of its gas keeps 64 times the history of the records it pays for. A case whose scenario is state gas to cross a limit with is skipped where a state byte costs nothing.
LimitCheck loses its Exempt variant: no outcome ever carried it, and it made within_limit and exceeded_limit both false for one value. The layer keeps the exemption as its own sticky flag, and an exempt transaction's verdict is WithinLimit whatever it crosses.
…pth guard The guard answered CALL and STATICCALL only; every other start past the limit reached the count and then revm's CallTooDeep, and a creation's count had to be taken back for the nonce revm never bumped. The guard now gives revm's own answer for every scheme and for a creation before anything counts the start, so the creator's nonce snapshot, creation_did_not_bump_nonce, undo_frame_start and drop_caller_record go. No transaction reaches the limit.
Gas limits cover what a scenario adds at the prices in effect, a call or creation that forwards all but a 64th keeps 64 times the history of the records it pays for, and a bill is the larger of the charge and the EIP-7623 floor where a cheap history byte lets the floor bind. A test whose scenario is state or history gas to cross, scale or give back returns early where that byte costs nothing, and says so once on stderr.
…g the engine reads
🧬 Mutation testing — ✅ PASSNothing to test: the mutant list under the run's filters was empty. |
Codecov Report✅ All modified and coverable lines are covered by tests. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Merging this PR will degrade performance by 0.76%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ❌ | oracle_reads/satin |
177.7 µs | 206.1 µs | -13.75% |
| ❌ | oracle_reads/op_revm |
154.6 µs | 170.5 µs | -9.34% |
| ❌ | steady_pre_block |
78.5 µs | 83 µs | -5.44% |
| ⚡ | storage_reads/op_revm |
170.4 µs | 153.2 µs | +11.21% |
| ⚡ | storage_reads/satin |
182.8 µs | 165.5 µs | +10.43% |
| ⚡ | value_calls/satin |
511.2 µs | 485.9 µs | +5.2% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing cz/feat/satin-w6 (4912ae7) with cz/feat/satin-w5 (9f7e5a2)
Footnotes
-
388 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
🧬 Mutation testing — ✅ PASSDiff mutation score: 100.0% (133/133 viable mutants killed)
No new test gaps introduced by this change. 🎉 |
…tests and four engine fixes (#400) Co-authored-by: mega-putin <mega-putin[bot]@users.noreply.github.com>
Summary
Satin's limits that change a result become protocol values carried by the Satin fork's parameters,
mega-evmeruns on both engines, and the test suite holds at other byte prices under a CI job of its own. Stacked on #390 (cz/feat/satin-w5).ProtocolLimits, Satin's hardfork params, read from the chain's schedule at the block's timestamp; the block context keeps only a builder's packing policy (BlockLimits), which can tighten a block budget and never loosen one. Moving the limits changes no execution result at today's default values.MegaEvmFactoryresolves the chain's limits, so an EVM a node builds outside block execution (an RPC call, a simulation) runs under the limits block execution holds its block to.mega-evmeis ported to Satin and rejoins the workspace:Satinruns on the in-tree engine,EquivalencethroughRex6on the released 1.7.1 CLI it links, and whole blocks replay on either engine and are compared with the chain's receipts; the 200 recorded mainnet blocks 26,400,000–26,400,199 replay on the legacy leg with every receipt and receipts root matching the chain.--separator, the legacy leg's precompile and encoding backends are pinned (c-kzgback to the 2.1.7 the release shipped), a run under--override.limitssays so in its output, a pending transaction's engine is decided at the block the replay runs it in, and seven tests whose "cannot pay" premise held only while a byte was dear derive it from the prices in effect.The consensus limits as
ProtocolLimitsProtocolLimits::tx_runtime_limitsProtocolLimits, with a builder cap inBlockLimitsheld below it byBlockLimits::withinBlockLimitsProtocolLimitsis serde-ready (camelCase, every field required, unknown fields refused).validate()refuses a zero limit (the value a configuration format that defaults a missing number to zero hands over; the type's own serde refuses a missing field), a transaction data-size limit belowTX_BODY_SIZE(310), and a detention cap at or aboveMAX_TX_COMPUTE_GAS(199,987,900: the execution cap less EIP-2780's base cost and the warm access a frame that runs code pays at least), which no transaction's compute reaches, so no chain can turn detention off.ProtocolLimits::DEFAULTis today's values, provisional with the constants: 13,107,200 bytes per transaction and per block, both detention caps at 20,000,000, every other limit unlimited.validate_schedulerequires the params for Satin and runs theirvalidate()(require_params,ScheduleError::InvalidParams), so a node whose own schedule type attaches params withoutwith_paramsstill refuses a bad value at load.SequencerRegistryConfig; it now keeps one value per type, andMegaHardforks::fork_params_anytakes(fork, TypeId).MegaHardforks::protocol_limits(timestamp)resolves the limits of the fork active at a timestamp; the engine's schedule for a chain it does not know carriesDEFAULT.MegaBlockExecutorinstalls the chain's per-transaction limits at construction and again before every transaction, holds the block to the chain's budgets lowered to the builder's caps, and refuses a block whose schedule carries no limits at its timestamp (MissingProtocolLimits) or limitsvalidate()refuses (InvalidProtocolLimits), both internal errors, at every entry point: the pre-block changes, a transaction's execution and the end of the block.ProtocolLimitsin its Satin chain configuration, answered per type by itsfork_params_any; aBlockLimitsonly on the builder path (a validator leaves the default, which restricts nothing); and its schedule to the EVM factory (below). Builder-side settings that raised a block budget above the protocol's no longer do; a test chain changes its schedule's params instead, andProtocolLimits::loosest()is the loosest set a chain may carry (every limit unlimited, the detention caps atMAX_TX_COMPUTE_GAS - 1), result-identical to no limits for every transaction but one marked before execution (a sender or recipient that is the block beneficiary, an authority that is, or a recipient delegating to it) that spends the most compute any can.The factory resolves the limits
MegaEvmFactory::with_schedule(schedule): every EVM it creates runs under the limits the schedule carries at the block's timestamp, the traced path included; where the schedule carries none there, or limitsvalidate()refuses, it installsDEFAULT's, since an EVM cannot refuse to be built while block execution refuses such a block.Arcis handed over as a clone of theArc:MegaHardforksholds for anArcor aBoxof a schedule, now stated and tested.MegaEvmFactory::new()anddefault()installProtocolLimits::DEFAULT's per-transaction limits rather than a bare context's: an RPC EVM that never touched limits gains the 13,107,200-byte data-size limit.MegaEvmFactory::with_tx_runtime_limitsis the explicit opt-out, for tests and for a caller that wants exactly the limits it names. AMegaContextbuilt by hand still gets its limits from its caller: the execution-spec gate's equivalence mode installsno_limits()on a context it builds by hand and never goes through the factory.mega-evmeon both enginesSatinruns on the in-tree sources;EquivalencethroughRex6run on the releasedmega-evmeandmega-evm1.7.1, linked asmega-evme-legacy/mega-evm-legacy(featurelegacy, on by default). A legacy command's arguments are handed to the 1.7.1 CLI as they are, but for--spec Rex6added, before any--, to arunortxthat left--specout (1.7.1's own default isRex7, which is refused: it never activated and Satin supersedes it). A legacy command's output and errors are 1.7.1's.replaypicks the engine from the chain's activation table at the timestamp of the block it runs the transaction in (its own, or the latest for a pending one); mainnet and testnet schedule no Satin yet, so their blocks replay on the legacy engine, and--override.spec Satinis the counterfactual. An unknown chain runs Satin, where 1.7.1 ran itsRex7fallback. Without--override.spec, a transaction replay reads the chain id (oneeth_chainId) to pick the engine, and, on a chain whose table schedules Satin, the transaction's block as well (the latest block for a pending transaction).satinobject is added: the gas by ledger, the data size and write records kept, the limit that stopped the transaction, and, under--override.limits, the limits the run was held to.replay --block N[..M] [--block-cache DIR] [--rpc URL] [--verify] [--json]runs each block on its engine after its pre-block changes and compares every receipt (status, gas used, cumulative gas used, every log) and the receipts root with the chain's;--verifyexits 2 on a difference. It does not compare the state a block leaves with the header's state root, so a difference that leaves every receipt as it was (a storage write with no log) would pass; the docs say so.ProtocolLimits::DEFAULT. A chain whose schedule runs Satin without its params is refused: the tool does not guess a chain's limits.--override.limits <JSON|FILE>onrun,txandreplay: a JSON object in the chain-configuration shape, merged over the run's limits and held to what a chain configuration is (unknown fields, zeros, a data-size limit below 310 and a cap that never binds are refused); refused on a legacy command before it reaches the 1.7.1 parser. The run's output carries the merged limits insatin.limits_override, a block replay on the block's record and aslimits overriddenon its line.replay --blockfetches, for a block its cache lacks, the block, its receipts, aprestateTracertrace and the parent block's state for reads the trace does not cover: an endpoint with thedebugnamespace and historical state at the parent block. A Satin run of a block cached by a legacy run needs--rpconce, for the EIP-7997 factory Satin's pre-block changes read and no legacy spec does. A transaction replay forks state at the parent block over RPC, as 1.7.1 did.tests/legacy_line.rspins the released engine, CLI and their revm/op-revm/alloy line at the 1.7.1 lockfile's versions, and now the backends it shares with the engine that decide what it executes: the precompiles' (secp256k1,k256,sha2,ripemd,aurora-engine-modexp, arkworks for BN254,blst,c-kzg,p256), hashing and word arithmetic (alloy-primitives,ruint,sha3), and the encodings.c-kzghad drifted to 2.1.8 and is back at the 2.1.7 the release shipped (its 2.1.8 only wraps the sameblstcalls in helpers; the point evaluation's arithmetic is the same).alloy-rlp,alloy-trieand thealloy-sol-typesfamily, which the engine's alloy 2 line holds above the release's versions, are pinned where they are. Transport and JSON crates float, as do derive crates outside the pinnedalloy-rlpandalloy-sol-typesfamilies.cargo … -p mega-evmenow names two packages; the tool is selected by--manifest-path bin/mega-evme/Cargo.toml(the release workflow, README and docs do). The legacy leg adds 153 packages to the tool's dependency graph (cargo tree --manifest-path bin/mega-evme/Cargo.toml -e normal --prefix none --locked | sort -u | wc -l: 590 with the default features, 437 with--no-default-features; 42 of them are crate names the Satin-only graph lacks, and the lockfile grows from 518 to 654 entries), and its release binary is 21.5 MB (21,463,488 bytes) at this head; a Satin-only build (--no-default-features) leaves out the legacy leg's revm 27, 1.7.1 CLI and alloy 1 RPC stack.--dump-fixtureis legacy-only (no Satin-priced state-test runner exists); the Satin leg's forked state reads an all-zero RPC account as absent, and prints an error once to stderr where 1.7.1 printed itsDebugform twice (the legacy leg keeps 1.7.1's behaviour).bin/mega-evme/tests/satin-differences.mdis rendered from both engines on the same inputs (everyrun/txfixture, three recorded blocks) and compared with the checked-in file.The byte-price grid, and no parked tests
scripts/price_grid.shbuilds the suite once withsatin-price-overrideand runs it per point withMEGA_SATIN_CPSB/MEGA_SATIN_CPHB;.github/workflows/price-grid.ymlruns five points on a pull request (0/0, 1/1, 312.5/20, 5000/300, 10000/1000) and the whole grid nightly: CPSB {0, 1, 312.5, 700, 1530, 2000, 5000, 10000} by CPHB {0, 1, 20, 50, 88, 100, 200, 300, 1000}, and 0.001 on both. Ascheduletrigger runs on the repository's default branch only, so the nightly grid stays inert whilesatinis not it; the job is meant to inform the review and should stay off the required checks, asREVIEW.mdstates.test_utils::note_price_guard), so a point at which tests returned early is told from one at which they ran.crates/mega-evm/tests/_pending/holds only its README, which records where every kept row went.The refactors, and the one fix's result changes
LimitChecklosesExempt, which no outcome ever carried and which madewithin_limitandexceeded_limitboth false for one value; the layer keeps the exemption as a sticky flag, and an exempt transaction's verdict isWithinLimit. No outcome changes.CallTooDeep, every scheme and a creation, before anything counts the start; the code that took a counted creation back for the nonce revm never bumps is gone. No transaction reaches the limit.limit/state_gas.rsand its alignment assertion are gone. No outcome changes.useda state-growth stop reports is the state gas held where the limit was crossed: a deposit whose created caller alone crosses reports that account (183,600 at the spec's prices), where it reported the whole state gas charged before the first frame (367,200 with a new recipient).usedis onMegaTransactionOutcome::limit_exceededand the tool's report only; the revert data carries(kind, limit), so no receipt or state moves. Documented onLimitCheck::ExceedsLimit::usedand pinned.Breaking changes
MegaHardforks::fork_params_any(fork, TypeId): answered per params type; a schedule keeps one value per type of a fork.ProtocolLimits(new): required byvalidate_schedulefor Satin;require_paramsruns the params'validate()(ScheduleError::InvalidParams);ProtocolLimits::DEFAULT,ProtocolLimits::loosest(),MegaHardforks::protocol_limits(timestamp),constants::MAX_TX_COMPUTE_GAS.BlockLimitsis building policy only: it losestx_runtime_limits,with_production_data_limitsandto_evm_tx_runtime_limits, its default restricts nothing, andwithinholds its caps below the protocol's.MegaBlockExecutor:limiteris no longer a public field (limiter()reads it); new internal errorsMegaBlockExecutionError::MissingProtocolLimitsandInvalidProtocolLimits; a block is refused under a schedule without valid limits.MegaEvmFactory::new()/default()installProtocolLimits::DEFAULT's per-transaction limits;with_scheduleandwith_tx_runtime_limitschoose otherwise.LimitCheck::Exemptis removed.MegaHardforkConfig::with_params_uncheckedexists only undercfg(test)ortest-utils.test_utils::note_price_guardandPRICE_GUARD_LOG_ENV_VARare new test utilities.mega-evmelibrary's types change (the tool's command line is additive):SatinReport(new;Clone, withlimits_override),ExecutedBlockcarries the limits a block ran under, and the block replay, engine and schedule modules are new.Cargo.lock: the tool's legacy line added, every package at the 1.7.1 lockfile's version but thealloy-rlp,alloy-trieandalloy-sol-typesfamilies, which the engine's alloy 2 line holds above it, andc-kzgmoves from 2.1.8 to 2.1.7 for the engine too.Open items
MAX_TX_COMPUTE_GASis exact only while the fork charges a first frame as it does (EIP-2780's base cost, a delegate's warm access); a fork change moves it loudly, through the test that readsGASat the first instruction of the frame that holds the most.validate()accepts a transaction data-size limit from 310 bytes and that deposit keeps about 486–526, so a chain configured in between would stop its own L1-attributes deposit every block. The floor or the exemption is a decision of its own.SequencerRegistryConfigandProtocolLimits), which the table's ownvalidate_scheduletests will demand the day a timestamp is set.--override.limitsis held to what a chain may carry, so a tool counterfactual with detention off is not expressible;loosest()is the closest.alloy-rlp(0.3.12 → 0.3.16),alloy-trie(0.9.0 → 0.9.5) andalloy-sol-types(1.4.1 → 1.6.0) run on the legacy leg at the engine's versions, which the engine's alloy 2 line requires; they are pinned there, and the 200/200 runs on them.mega-t8nis not ported; it should follow the same rule, with its legacy leg a verbatim copy of 1.7.1's compiled against the aliased crates (it was never published).RewritingInspectorstays a validation error.Changed by the stacked follow-up
The next pull request in the stack changes the following, so these statements describe this head only.
--genesis <FILE>onrunandtx: a command that leaves--specout runsSatinunder the file's chain, and a legacy spec under--genesisis refused.replayunder--genesis: the file'ssatinTimedecides the engine, and a block before it is refused.--genesisis the way to supply a chain's Satin params, read by the shared parserSatinChainConfig::from_genesis_config, so a Satin block of a known chain is no longer refused for want of them once a file carries them.satinTxDataSizeLimit,satinBlockEnvAccessComputeGasLimit, and the rest besidesatinTimeand the registry seeds) is parsed by the engine; the camelCase object stays the shape of--override.limits.--rpcfor those slots as well as for the EIP-7997 factory.LimitStop::from_resultanddecode_mega_limit_exceededread a stop's(kind, limit)off a result's revert data;usedis unchanged.legacy_line.rs's doc names the locked alloy line as 2.1, not 2.4.Test plan
Run at the head of this branch on macOS (aarch64).
cargo fmt --all --check,cargo clippy --workspace --lib --examples --tests --benches --all-features --locked,cargo sort --check …, the riscv no-std check,cargo metadata --locked, Prettier ondocs/**/*.mdand*.md,git diff --check: all clean.cargo tree -i revm(the engine's graph, the default member): one revm, the fork (v40.0.3-mega.4); the workspace also locks revm 27.1.0, reached only bymega-evme's legacy leg.cargo check --workspace --all-targets --lockedon each commit of the review fixes: no warning.cargo test --workspace --locked: 1,550 passed, 0 failed, 3 ignored in debug (mega-evmlib 351, block 128, satin 578, system 321;mega-evme127 + 2 ignored live-RPC tests;mega-state-test35; system contracts 6;state-test4); 1,535 in release (the gap is the debug-assertion tests).--full: every point passes 1,380 tests with 0 failed; guarded 0 at the spec's prices (1530/88), 85 or 86 at every other priced point, 168 where a state byte is free. The five pull-request points pass likewise. Sweeps between the grid's points during the fixes (62 points from CPSB 1–7,500 by CPHB 0–700): all pass; two points past the grid (15000/1500, 20000/2000) fail 34 and 58 tests, outside the range the suite is held to.c-kzg2.1.7).mega-evme replay --block 26400000..26400199 --block-cache <recording> --verify, offline:200 block(s) replayed: 200 match the chain, 0 differ, 0 failed, exit 0; the recording unchanged.c-kzg: the legacy line resolves ["2.1.8"], the 1.7.1 release shipped 2.1.7); the--separator test fails on the previous hand-off (unexpected argument '--spec' found, exit 2); the 1/1 grid point fails the seven old premises.scripts/mutation_test.sh diff, sharded: 121 mutants, 88 caught, 33 unviable, 0 missed, 0 timed out; every shard's gate passes; no suppression added.