fix(pipe): close gravity-audit#621 + #712 (gas_limit hardcode + budget)#358
Open
nekomoto911 wants to merge 1 commit into
Open
fix(pipe): close gravity-audit#621 + #712 (gas_limit hardcode + budget)#358nekomoto911 wants to merge 1 commit into
nekomoto911 wants to merge 1 commit into
Conversation
Two consensus-critical fixes to the pipe execution layer's block gas_limit plumbing: #712 (HIGH, consensus divergence): block gas_limit was sourced from per-node `--gravity.pipe-block-gas-limit` CLI flag, so validators with mismatched values produced different block hashes from the same OrderedBlock. Hardcoded to a single workspace const `PIPE_BLOCK_GAS_LIMIT = 1_000_000_000`; CLI flag, config field, and all init shims removed (mainnet pre-launch, no compat needed). #621 (HIGH, gas_used > gas_limit): system txns (metadata + DKG/JWK) run *before* user-tx filtering, then their gas is appended to the result via `SystemTxnResult::insert_to_executed_ordered_block_result`. The user-tx filter received the full `block.gas_limit` as budget, so a saturating user block plus system overhead could push `header.gas_used > header.gas_limit` in release builds (`validate_execution_output` is debug-only). Fix A from the issue thread: pass `sum_system_gas` into `create_block_for_executor` (computed from already-executed system results, so it's exact, not an upper bound) and apply `block.gas_limit.saturating_sub(sum_system_gas)` to the filter budget. `saturating_sub` covers the byzantine path where `sum_system_gas ≥ block.gas_limit` (all user txs dropped, system-only block is the safe fallback). `block.header.gas_limit` itself is unchanged so RPC / indexer / protocol-layer semantics stay stable.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two consensus-critical fixes to the pipe execution layer's block
gas_limitplumbing. Both audit issues land on the same code path (create_block_for_executor/execute_ordered_blockincrates/pipe-exec-layer-ext-v2/execute/src/lib.rs); fixing them in one PR avoids touch-the-same-line conflicts.gravity-audit#712(HIGH — consensus divergence / halt)Galxe/gravity-audit#712 — block
gas_limitwas sourced from per-node--gravity.pipe-block-gas-limitCLI flag (get_gravity_config().pipe_block_gas_limitinlib.rs:657/1023andmetadata_txn.rs:91). Validators with mismatched values produced different block hashes from the sameOrderedBlock, and the verification path's.unwrap()would panic-halt on mismatch.Fix: hardcode to a single workspace const
gravity_primitives::PIPE_BLOCK_GAS_LIMIT = 1_000_000_000. The CLI flag,Config.pipe_block_gas_limitfield, default initializers, and all read-sites are removed. Mainnet is pre-launch so no compat/migration shims.gravity-audit#621(HIGH —gas_used > gas_limit)Galxe/gravity-audit#621 — system txns (metadata
onBlockStart+ each DKG/JWK validator txn) execute before user-tx filtering, then their gas is appended to the block result viaSystemTxnResult::insert_to_executed_ordered_block_result:A user block sized to fit exactly under
block.gas_limitplus any system overhead pushedheader.gas_used > header.gas_limitin release builds. The existingvalidate_execution_outputguard (lib.rs:324) is#[cfg(debug_assertions)]-only so release had no enforcement.Fix A (per the issue thread): plumb
sum_system_gasintocreate_block_for_executor(computed from already-executed system results, so it's the exact gas, not thetx.gas_limit()upper bound), then applyblock.gas_limit.saturating_sub(sum_system_gas)to the budget passed tofilter_invalid_txs. The user-tx filter still usestx.gas_limit()for accumulation — that's a conservative upper bound, so the shrunk budget can over-truncate by at most one tx, never under-truncate.block.header.gas_limititself is unchanged so RPC / indexer / protocol-layer semantics are preserved.saturating_subhandles the byzantine path (sum_system_gas ≥ block.gas_limit): budget collapses to 0, every user tx is dropped, the block runs system-only — the safe fallback. New unit testtest_filter_invalid_txs_zero_budget_drops_allpins this contract.Fix B from the issue thread (release-mode
gas_used ≤ gas_limitassertion) is intentionally not included here; it's defense-in-depth, and once Fix A is in place the failure mode is provably impossible. Can be done as a follow-up if the team wants the belt-and-suspenders guarantee.Test plan
cargo nextest run -p reth-pipe-exec-layer-ext-v2 --lib— 45/45 pass, including newtest_filter_invalid_txs_zero_budget_drops_allcargo nextest run -p reth-engine-tree --lib recovery::— 6/6 pass (test init shim updated for the removedpipe_block_gas_limitfield)cargo +nightly fmt --all --checkpipe-exec-layer-ext-v2andpipe-exec-layer-relayeris not introduced by this PR)cargo check -p reth-node-core -p gravity-primitives -p reth-pipe-exec-layer-ext-v2 -p reth-engine-treegas_limitwould diverge; with the flag removed, divergence path is structurally gone (no per-node knob remains)Files
gravity-primitives(new const, drop field) ·node/core/args/gravity(drop CLI flag) ·engine/tree/recovery(test shim) ·pipe-exec-layer-ext-v2/execute/{lib,onchain_config/metadata_txn,tx_filter}