主页EIPs
EIPsEIP-3978
EIP-3978

Gas refunds on reverts

Reprice reverted SSTORE/CREATE/SELFDESTRUCT/LOGX operations gas via gas refund mechanism
StagnantStandards Track: Core
创建时间: 2021-09-16
关联 EIP: EIP-2929
Anton Bukov (@k06a), Mikhail Melnik (@ZumZoom)
社区讨论原文链接编辑
1 分钟了解
欢迎补充好内容
去提交
相关视频
欢迎补充好内容
去提交
正文

Abstract

For reverted state modification operations, keep access cost, but refund modification cost.

Motivation

Reverting a transaction, or any of its sub-calls, drops any state modifications that happened inside. But now, users are being charged for the dropped modifications as if they persisted.

Since EIP-3298, the gas refund mechanism works for storage restores only inside the same transaction. But on revert, the gas refund is not increased; it is completely erased. It can even be cheaper to transfer tokens back at the end of a transaction instead of reverting, to keep the existing gas refund. This should be changed.

  • Reverted SSTORE deserves to be repriced to SLOAD gas (100 gas)
  • Reverted LOG0, LOG1, LOG2, LOG3 and LOG4 deserve to be repriced to 100 gas
  • Reverted CALL with value (positive_value_cost = 9,000 gas) deserves to be repriced to 100 gas
  • Reverted CALL with value and account creation (value_to_empty_account_cost = 25,000 gas) deserves to be repriced to 100 gas
  • Reverted CREATE and CREATE2 (32,000 gas) deserve to be repriced to 100 gas
  • Reverted SELFDESTRUCT (5,000 or 25,000 gas) deserves to be repriced to 100 gas

Moreover, it seems fair to charge CREATE and CREATE2 operations 32,000 fix price conditionally only if returned bytecode is not empty.

Specification

For each callframe, track revert_gas_refund, initially 0.

The set of operations that modify revert_gas_refund are:

  • SSTORE
  • LOG0, LOG1, LOG2, LOG3, LOG4
  • CALL
  • CREATE, CREATE2
  • SELFDESTRUCT

They increase revert_gas_refund as follows:

call.revert_gas_refund += operation.gas - WARM_STORAGE_READ_COST

And in case of revert let's use this value instead of just erasing gas_refund:

if (call.reverted) { // existing behavior tx.gas_refund -= call.gas_refund; // New behavior added to existing according to the EIP-3978 tx.gas_refund += call.revert_gas_refund; }

Rationale

Gas should reflect the cost of use. The revert cost reflects the cost of access during execution, but not the cost of modification.

Backwards Compatibility

No known backward incompatibilities.

Test Cases

TBD

Reference Implementation

TBD

Security Considerations

TBD

Copyright and related rights waived via CC0.

扩展阅读
欢迎补充好内容
去提交
相关项目
欢迎补充好内容
去提交

不想错过最新的 EIP 动态?

订阅 EIPs Fun 周刊以跟进相关更新,建⽴你与 EIP 之间的连接 ,更好地建设以太坊。

详情
支持以太坊贡献者,推动生态建设
资源
GitHub
支持社区