EIP-7778 - Prevent Block Gas Smuggling

Created 2024-10-01
Status Draft
Category Core
Type Standards Track
Authors

Prevent the circumvention of the block gas limit by excluding certain gas discounts and refunds from block gas accounting, except for those reflecting actual reductions in computational work.

This proposal aims to align the block gas usage with the Ethereum Virtual Machine's (EVM) real workload, preventing "block gas smuggling." It complements EIP-7623 by further reducing the maximum block size and its variance, enhancing network stability and efficiency.

Example block 20878522 "uses" 28.5 MGas, but also in that net figure is 4.01 MGas of refunds for a total of 32.51 MGas gross; which is 2.51MGas above the current mainnet block gaslimit.

Abstract

This EIP modifies the gas accounting mechanism to prevent block gas smuggling — situations where transactions include more gas-consuming operations than the block gas limit intends due to gas discounts and refunds.

By excluding these discounts and refunds from block gas limit calculations, except for those corresponding to actual workload reductions (e.g., warm storage accesses, SSTORE reverting to original values), the proposal ensures that the block gas limit accurately reflects the EVM's computational and storage workload.

It complements EIP-7623, which increases calldata costs for data availability (DA) transactions, by further reducing maximum block sizes and over-the-wire data.

Motivation

Preventing Block Gas Smuggling

Complementing EIP-7623

Specification

Gas Cost Adjustments

  1. User Gas Costs:

  2. SSTORE Operations:

    • Users receive gas refunds when resetting storage to zero or reverting to original values.
  3. Warm vs. Cold Storage Access Costs:

    • Users benefit from lower gas costs for warm storage accesses.
  4. Block Gas Accounting:

  5. SSTORE Operations:

    • Setting Storage to Zero:
    • Charged at full cost in block gas accounting without subtracting refunds.
    • Reverting Storage to Original Value:
    • Receive discounts in block gas accounting, reflecting reduced workload (no actual write to storage).
  6. Warm vs. Cold Storage Access:
    • Discounts for warm storage accesses are preserved in block gas accounting, as they correspond to reduced computational effort.
  7. Other Discounts and Refunds:
    • Exclude any discounts and refunds not associated with actual reductions in computational workload from block gas accounting.

Transaction Gas Calculation (Adjusted)

With EIP-7623 for transactions, the gas used (tx.gasUsed) is calculated as:

tx.gasUsed = {
    21000 \ 
    + 
    max (
        STANDARD_TOKEN_COST * tokens_in_calldata \
           + evm_gas_used \
           + isContractCreation * (32000 + InitCodeWordGas * words(calldata)),
        TOTAL_COST_FLOOR_PER_TOKEN * tokens_in_calldata
    )

With this eip for evm_gas_used the user tx price the gas used remains the same:

tx.evm_gas_used = evm_gas_used - evm_gas_refund

However when calculating the block gas used, the refund is not considered

block.evm_gas_used += evm_gas_used

Block Gas Limit Enforcement

Implementation

Rationale

Preventing Block Gas Smuggling

Complementing EIP-7623

Backwards Compatibility

Test Cases

  1. DA-Heavy Transactions:

  2. Transactions with large calldata used for DA are charged higher costs.

  3. Verify that such transactions cannot cause the block gas usage to exceed limits.

  4. Regular Transactions:

  5. Transactions with typical calldata and EVM usage are processed as usual.

  6. Ensure that user costs and block gas accounting reflect minimal changes.

  7. SSTORE Operations:

  8. Reset to Zero:

    • User receives refunds, but block gas accounting charges full cost.
    • Verify that inclusion adheres to block gas limit.
  9. Revert to Original Value:

    • Discounts apply in both user costs and block gas accounting.
    • Ensure block gas usage reflects reduced workload.
  10. Warm vs. Cold Storage Accesses:

  11. Discounts for warm accesses are preserved in both user costs and block gas accounting.

  12. Verify accurate representation of computational effort.

  13. Blocks Near Gas Limit:

  14. Construct blocks to test the new gas limit enforcement.

  15. Ensure correct processing without exceeding limits.

Security Considerations

Copyright

Copyright and related rights waived via CC0 1.0 Universal.