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

Commit

Permalink
Merge pull request #92 from anton-rs/fix/reverted-deposit-regolith-gas
Browse files Browse the repository at this point in the history
fix: Gas accounting for reverting deposits post-regolith
  • Loading branch information
refcell authored Aug 27, 2023
2 parents eb21cb0 + e256007 commit 3855777
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
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

0 comments on commit 3855777

Please sign in to comment.