EIP-7778 - Block Gas Limit Accounting without Refunds

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

Abstract

This EIP modifies the block gas accounting mechanism to prevent the circumvention of block gas limits. It proposes that gas refunds, particularly those from SSTORE operations setting storage slots to zero, should not reduce the gas counted toward the block gas limit, while still being applied to transaction gas costs for users.

Motivation

Currently, gas refunds from operations like clearing storage slots (setting to zero) reduce both the transaction gas cost for users and the gas counted toward the block gas limit. This creates a discrepancy between the computational work performed and the gas accounted for in the block.

Example: Block 20878522 shows a net usage of 28.5 MGas, but contains 4.01 MGas of refunds, bringing the gross usage to 32.51 MGas—exceeding the block gas limit by 2.51 MGas.

This mechanism can be exploited to perform more operations in a block than the gas limit intends to allow, potentially leading to:

  1. Network instability due to oversized blocks
  2. Denial-of-service vectors
  3. Computational loads exceeding the intended block gas limit

Specification

Gas Accounting Changes

  1. User Gas Costs (Unchanged):
  2. Users continue to receive gas refunds for operations that qualify (e.g., setting storage to zero)
  3. The transaction gas cost remains: tx.gas_used = gas_used - gas_refund

  4. Block Gas Accounting (Modified):

  5. When calculating gas for block gas limit enforcement, refunds are not subtracted
  6. Block gas accounting becomes: block.gas_used += gas_used (without subtracting refunds)
  7. Storage discounts that reflect actual reduced computational work (e.g., warm storage access, reverting to original values) remain applied to block gas accounting

Block Gas Limit Enforcement

Rationale

Aligning Gas Limits with Computational Work

Preserving User Incentives

Backwards Compatibility

Test Cases

  1. SSTORE Operations:
  2. Setting storage to zero: User receives refund, but block gas accounting uses full cost
  3. Verify blocks containing many storage-clearing operations still adhere to gas limits

  4. Block Gas Limit Edge Cases:

  5. Construct blocks with varying amounts of refundable operations
  6. Ensure blocks cannot exceed gas limits through refund mechanisms

  7. Transaction Gas vs Block Gas:

  8. Verify that transaction costs for users remain unchanged
  9. Confirm block gas accounting properly excludes refunds

Security Considerations

Copyright

Copyright and related rights waived via CC0 1.0 Universal.