-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add EIP: GAS2ETH opcode #8980
Open
charles-cooper
wants to merge
21
commits into
ethereum:master
Choose a base branch
from
charles-cooper:gas_to_eth
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add EIP: GAS2ETH opcode #8980
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
8ae8e07
being drafting gas_to_eth eip
charles-cooper a399da1
add some motivation
charles-cooper 48e0bab
update pricing
charles-cooper 1f4755e
reduce pricing again to mimic sstore
charles-cooper 7169abe
📝 Amend `GAS2ETH` Proposal
pcaversaccio 9927a7b
Merge pull request #1 from pcaversaccio/amend-gas-to-eth
charles-cooper 9a78029
update / roll back some wording
charles-cooper 324ef9b
add author
charles-cooper 799361d
add EIP number
charles-cooper 3f5f76d
add discussions-to link
charles-cooper 527b729
remove backticks in title
charles-cooper 3a58567
move eip md to the numbered file
charles-cooper d431238
grammar touchups, rewording
charles-cooper 23f511e
fix lint
charles-cooper 6d84465
remove zero address case
charles-cooper 90cca4b
add TODO tags
charles-cooper 414910f
update outdated comment re. CALL2
charles-cooper fa500f6
Merge branch 'master' into gas_to_eth
charles-cooper abfa48c
update gas costs
charles-cooper fc4202f
Apply suggestions from code review
charles-cooper cd30b81
clarify gas price
charles-cooper File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
--- | ||
eip: 7791 | ||
title: GAS2ETH opcode | ||
description: Introduces a new opcode, `GAS2ETH`, to convert gas to ETH | ||
author: Charles Cooper (@charles-cooper), Pascal Caversaccio (@pcaversaccio) | ||
discussions-to: https://ethereum-magicians.org/t/eip-7791-gas2eth-opcode/21418 | ||
status: Draft | ||
type: Standards Track | ||
category: Core | ||
created: 2024-08-13 | ||
requires: 2929 | ||
--- | ||
|
||
## Abstract | ||
|
||
This EIP introduces a new `GAS2ETH` opcode that enables the direct conversion of gas into ether (ETH). | ||
|
||
## Motivation | ||
|
||
This EIP is based on the premise that smart contract authors, compiler teams and public goods projects in general should be compensated for their contributions. | ||
Moreover, their compensation should scale with the usage of their contracts. | ||
A widely used and popular contract offers significant value to its users through its functionality and to the network by driving demand for blockspace — Ethereum's _raison d'être_. | ||
This increased demand also benefits miners and validators, who are rewarded for executing these contracts. | ||
|
||
Monetizing smart contracts in a scalable manner remains challenging at the time of this writing. | ||
This difficulty is evident from existence of many different monetization strategies employed across various smart contracts — ranging from fee structures to the issuance of tokens with "tokenomics" of varying levels of complexity. | ||
Additionally, many public goods projects struggle to secure funding. | ||
|
||
Introducing the `GAS2ETH` opcode offers contract authors, as well as the tools they use, a new way to achieve their monetization objectives. | ||
By charging gas, they integrate with an established user experience that is both familiar and understood by users. | ||
The proposed instruction ensures that existing transaction creation and processing tools remain unchanged. | ||
Moreover, by charging gas, contract authors align economically with network activity; they benefit from higher compensation during periods of intense network usage and receive less when activity is low. | ||
This helps align the incentives of smart contract authors, validators, and the broader network. | ||
|
||
## Specification | ||
|
||
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119 and RFC 8174. | ||
|
||
A new opcode is introduced, `GAS2ETH` (`0xFC`), which: | ||
|
||
- Pops two values from the stack: `addr` then `gas_amount`. If there are fewer than two values on the stack, the calling context should fail with stack underflow. | ||
- Deducts `gas_amount` from the current calling context. | ||
- Computes `wei_val` by multiplying `gas_amount` by the current transaction context's `gas_price` ([EELS][gasprice]). | ||
- Endows the address `addr` with `wei_val` wei. | ||
- If the gas cost of this opcode + `gas_amount` is greater than the available gas in the current calling context, the calling context should fail with "out-of-gas" and any state changes reverted. | ||
- Pushes `wei_val` onto the stack. | ||
|
||
[gasprice]: https://github.com/ethereum/execution-specs/blob/98d6ddaaa709a2b7d0cd642f4cfcdadc8c0808e1/src/ethereum/cancun/vm/instructions/environment.py#L325 | ||
|
||
Note that the transfer of `wei_val` to the given account cannot fail. In particular, the destination account code (if any) is not executed, or, if the account does not exist, the balance is still added to the given address `addr`. | ||
|
||
### Gas cost | ||
|
||
The proposed cost of this opcode is identical to the recently proposed `PAY` opcode. | ||
|
||
#### Constants | ||
|
||
| Constant | Definition | | ||
| -------------------------- | ------------------------- | | ||
| `WARM_STORAGE_READ_COST` | [EIP-2929](./eip-2929.md) | | ||
| `COLD_ACCOUNT_ACCESS_COST` | [EIP-2929](./eip-2929.md) | | ||
| `GAS_NEW_ACCOUNT` | [EELS][gna] | | ||
| `GAS_CALL_VALUE` | [EELS][gcv] | | ||
|
||
[gna]: https://github.com/ethereum/execution-specs/blob/4d953035fb0cceda7cf21d71b2ab7a9a6f4632f0/src/ethereum/frontier/vm/gas.py#L52 | ||
[gcv]: https://github.com/ethereum/execution-specs/blob/4d953035fb0cceda7cf21d71b2ab7a9a6f4632f0/src/ethereum/frontier/vm/gas.py#L53 | ||
|
||
#### Gas calculation | ||
|
||
- Is `addr` in `accessed_addresses`? | ||
- If yes, `WARM_STORAGE_READ_COST`; | ||
- Otherwise, `COLD_ACCOUNT_ACCESS_COST`. | ||
- Does `addr` exist or is `val` zero? | ||
- If yes to either, zero; | ||
- Otherwise, `GAS_NEW_ACCOUNT`. | ||
- Is `val` zero? | ||
- If yes, zero; | ||
- Otherwise, `GAS_CALL_VALUE`. | ||
|
||
## Rationale | ||
|
||
- `GAS2ETH` vs. pro-rata: The pro-rata model incentivizes inflating contract gas usage to artificially increase fees. In contrast, this proposal allows contract authors to charge their desired amount directly, eliminating the need for unnecessary gas consumption. | ||
- Target address vs. simply increasing balance of the currently executing contract: Using a target address is more flexible, enabling contract authors to write more modular code and separate the concerns of fee collection from contract functionality. For instance, the contract may want to designate a specific recipient for fees without necessarily granting them direct withdrawal access. | ||
- Charging gas instead of ETH: Charging ETH directly complicates the user experience and prevents contract authors from participating in fluctuations in gas demand directly. | ||
- For the value of `gas_price`, use the same gas price as which is used to calculate the tx cost in ETH. This leads to the most consistent computation between `GAS2ETH` and the user's experience when creating a transaction. | ||
|
||
## Backwards Compatibility | ||
|
||
No backward compatibility issues found. | ||
|
||
## Test Cases | ||
|
||
<!-- TODO --> TBD | ||
Check warning on line 93 in EIPS/eip-7791.md
|
||
|
||
## Reference Implementation | ||
|
||
<!-- TODO --> TBD | ||
|
||
## Security Considerations | ||
|
||
Needs discussion. | ||
|
||
## Copyright | ||
|
||
Copyright and related rights waived via [CC0](../LICENSE.md). |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is extra gas cost in CALL if the call sends value and a new address is created in the trie. I think this should be added here as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that is included in the line explaining the account access costs -- https://github.com/ethereum/EIPs/pull/8980/files#diff-945c598617f3a1437a229375d8089476b61a7537d0891e4be08b6cc6e261dd15R53