Skip to content
This repository has been archived by the owner on Nov 5, 2023. It is now read-only.

fix: Gas accounting for reverting deposits post-regolith #92

Merged
merged 1 commit into from
Aug 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions crates/payload/basic/src/optimism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,19 +204,16 @@ where
commit_state_changes(&mut db, &mut post_state, block_number, state, true);

if chain_spec.optimism {
// If either Regolith is active or the transaction is not a deposit, we report the
// actual gas used in execution to the cumulative gas.
//
// Otherwise, if we are pre-Regolith and the transaction is a non-system-tx deposit,
// we report the gas limit of the transaction to the cumulative gas. Pre-Regolith,
// system transactions are not included in the cumulative gas and their execution
// gas is ignored. Post regolith, system transactions are deprecated and no longer
// exist.
if sequencer_tx.is_deposit() && !result.is_success() {
cumulative_gas_used += sequencer_tx.gas_limit();
} else if is_regolith || !sequencer_tx.is_deposit() {
cumulative_gas_used += result.gas_used()
} else if sequencer_tx.is_deposit() && !sequencer_tx.is_system_transaction() {
// Before Regolith, system transactions were a special type of deposit transaction
// that contributed no gas usage to the block. Regular deposits reported their gas
// usage as the gas limit of their transaction. After Regolith, system transactions
// are deprecated and all deposit transactions report the gas used during execution
// regardless of whether or not the transaction reverts.
if is_regolith || !sequencer_tx.is_deposit() {
cumulative_gas_used += result.gas_used();
} else if sequencer_tx.is_deposit() &&
(!result.is_success() || !sequencer_tx.is_system_transaction())
{
cumulative_gas_used += sequencer_tx.gas_limit();
}

Expand Down
13 changes: 7 additions & 6 deletions crates/revm/src/optimism/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,13 @@ where
// Before Regolith, system transactions were a special type of deposit transaction
// that contributed no gas usage to the block. Regular deposits reported their gas
// usage as the gas limit of their transaction. After Regolith, system transactions
// are deprecated and all deposit transactions report the gas used during execution.
if transaction.is_deposit() && !result.is_success() {
cumulative_gas_used += transaction.gas_limit();
} else if is_regolith || !transaction.is_deposit() {
cumulative_gas_used += result.gas_used()
} else if transaction.is_deposit() && !transaction.is_system_transaction() {
// are deprecated and all deposit transactions report the gas used during execution
// regardless of whether or not the transaction reverts.
if is_regolith || !transaction.is_deposit() {
cumulative_gas_used += result.gas_used();
} else if transaction.is_deposit() &&
(!result.is_success() || !transaction.is_system_transaction())
{
cumulative_gas_used += transaction.gas_limit();
}

Expand Down