2 keys and 21 EIPs for Ethereum Gas fee

avatar
白计划
4 years ago
This article is approximately 2807 words,and reading the entire article takes about 4 minutes
Ethereum has formulated more than 20 EIP proposals regarding Gas fees.

Written by: Li

Written by: Li

The gas fee problem is one of the most serious problems facing the Ethereum 1.0 chain at present. Although the Ethereum has a lot of computing power, the task capacity is due to the structural problems of the blockchain (every full node calculates the same data, so the tasks are rushing) The computing resources of a single node), Ethereum will be congested when processing a large number of tasks, and the Gas fee will be high after the congestion.

The explosive growth of DeFi applications has intensified this phenomenon. What I want to mention here is that in addition to packaging blockchain transactions, Ethereum also publishes smart contracts on the chain, so smart contracts consume resources when executed on the chain, so almost every step that users do in DeFi , all need to pay Gas fees, which is also a problem with the Gas model.

Recently, the discussion on EIP-1559 in the Ethereum community has also become more intense, because many mining pools do not agree to deploy this proposal. This proposal adjusts the composition of Gas fees. Although it cannot solve the problem of high Gas fees, it can increase the cost of Gas fees. Expected, perfect experience.

There is also a recent related news. On March 16, Philippe Castonguay, a developer of Ethereum, proposed another proposal EIP-3382, proposing to fix the block Gas limit at 12,500,000 Gas per block. And update the block verification rules, if the gas limit is not equal to 12,500,000, the block is invalid. This is to achieve a consensus on the block gas limit, and it is not restricted by miners.

In the original rules, the block gas limit is the only data part in Ethereum that is not determined by the consensus of nodes, and is a parameter chosen by miners. He sees this as a key parameter that requires node consensus to avoid any sudden harmful changes imposed by a small number of participants on the rest of the network.

There are many proposals to adjust the gas fee like EIP1559 and EIP-3382, because the gas fee occupies an important position in the operation of Ethereum, so there are many historical stories about the gas fee. If you browse all the news about the gas fee , it can be found that it is not easy to solve the gas fee.

If you want to understand the gas fee, you can understand it vividly from the dynamic image of TXStreet.

2 keys and 21 EIPs for Ethereum Gas fee

image description

TXStreet visualizes the Ethereum block packaging process as transportation

The road on which the car travels is the basic resource, and the toll needs to be paid to cover, while the gas fee required for packaging is the gas fee. So the Gas fee (Gas fee) is the final payment for the resource usage of Ethereum.

secondary title

The first key about Gas in the early days

The concept of Gas comes from the computer field. It can be seen in Ethereum. It first came from the Ethereum Yellow Paper. The author of the Yellow Paper is Gavin, the founder of Polkadot. is an arbitrary value, since there are theoretically more transactions to cover, up to 2^256 (which can cover nearly as many transactions as there are atoms in the known universe).

Before this version is confirmed, there is another interesting detail. In the Ethereum Gas model designed by Vitalik, the gas fee payment process is defaulted in the contract, that is, during the execution of a contract, the balance in the contract will decrease. If the balance is insufficient due to execution consumption, the contract will be suspended.

2 keys and 21 EIPs for Ethereum Gas fee

image description

Later, Gavin began to participate in Ethereum, and after entering, he modified the payment mechanism of Gas, from this contract execution payment to transferer payment, that is, contract executor payment. Vitalik describes the move from a contract pays approach to a sender pays approach, in lieu of taking a little ETH at once for each individual transaction step.

2 keys and 21 EIPs for Ethereum Gas fee

image description

In the early days of Ethereum, Vitalik and Gavin were on the mini-hackathon, and the master in the middle was Jeffrey

This is an easier-to-understand gas fee payment. If we dissect more detailed parts, we have to look at the related part of Gas in the Yellow Paper.

Gas is the unit of calculation for all calculations in Ethereum. The more calculations you want to perform on Ethereum, the more Gas you have to pay.

This mode of user payment can avoid resource abuse. It can be understood that once developers pay for each operation, they will write the code as concisely and efficiently as possible. In addition, the existence of Gas can also prevent attackers from passing invalid operations (so many operations will cost Gas). The Flooding attack is carried out on the Fang network. An EIP counted below is to increase the Gas value for account access to reduce the possibility of attack.

In addition to knowing where to pay Gas, we also need to understand GasPrice and GasLimit.

GasPrice is the price that the transaction sender is willing to pay per unit of Gas (measured in Wei), and the transaction sender can customize the price per unit of Gas that the transaction sender is willing to pay. Assuming that a transaction costs 10 Gas and the sender is willing to pay 3 Wei/Gas, the total cost of the transaction is 30 Wei. There will be advanced options to adjust the Gas fee in the wallets we use.

In addition, GasLimit can also be defined as prepaid Gas. When the node is verifying the transaction, first calculate the fixed cost of the transaction by multiplying GasPrice by GasLimit. If the transaction senders account balance is less than the transactions fixed cost, the transaction is considered invalid. After the transaction is executed, the remaining Gas will be returned to the senders account, which is why when we use MetMask to execute the contract, we estimate that Gas is very expensive, but the execution price is not so high.

2 keys and 21 EIPs for Ethereum Gas fee

image description

content contained in a block

This is the inherent content in a block. In the transaction part, there are 237 transfers and 39 internal contract transactions. If you look at the transactions specifically, you can see more detailed gas costs. You can also see that the gas limit is 12493113. In the EIP-3382 mentioned at the beginning of the article, the Gas limit of each block is limited to 12500000, which is this part. In this way, the sum of the rewards obtained in each block will be more controllable.

inherent cost =

Gtransaction+Gtxdatazero*Nzeros+Gtxdatanonzero* Nnonzeros+Gtxcreate

in:

Gtransaction=21,000Wei

Gtxcreate=32,000Wei

Gtxdatazero=4Wei

in:

You can take a seat on the following opcodes.

2 keys and 21 EIPs for Ethereum Gas fee

image description

According to the above introduction, the basic understanding we can get is that the Gas fee is generated by using the resources on the Ethereum chain. The more calculations, the higher the Gas. In the smart contract contract operation, each individual step needs to be paid Gas. In addition, it should be added that if the sender sets Gas to be very high, the miners will give priority to executing transactions, because miners can choose to package certain transactions first.

secondary title

20 EIPs closely related to Gas fees

Next, we can take a detailed look at the EIP proposal on Gas. Proposals are arranged approximately in chronological order.

EIP-5: Adjust the Gas usage of RETURN and CALL

This EIP makes it possible to call functions that RETURN strings and other dynamically sized arrays. Currently, when calling another contract/function from within the Ethereum Virtual Machine, the size of the output must be pre-specified. You also have to pay for unwritten memory, which makes returning dynamically sized data so expensive and inflexible that its practically unusable. The solution proposed in this EIP is to only pay for the memory actually written when the CALL returns.

EIP-150: Gas cost changes for a large number of IO operations

Increased gas cost for EXTCODESIZE from 20 to 700.

Increased base gas cost of EXTCODECOPY from 20 to 700.

Increased the gas cost of BALANCE from 20 to 400.

Increased SLOAD gas cost from 50 to 200.

Increase the gas fee of CALL, DELEGATECALL, CALLCODE from 40 to 700.

Increased the gas cost of SELFDESTRUCT from 0 to 5000.

Increased suggested gas limit target to 5.5 million.

EIP-158: State Cleanup

EIP-158: State Cleanup

In any case, the account whose call balance is 0 will no longer consume the cost of 25,000 account creation Gas.

EIP-1108: Reduce alt_bn128 precompiled Gas cost

Precompiled elliptic curve calculations are currently overpriced. Repricing precompilations would go a long way towards many privacy and scaling solutions on Ethereum. For Ethereum-based zk-SNARK-based protocols, EIP-1108 will not only greatly reduce the gas cost of verifying zk-SNARKs, but also help to combine multiple zk-SNARK proofs in batches. This is also a technique that can be used to split a monolithic zk-SNARK circuit into a batch of zk-SNARKs with smaller individual circuit sizes, which makes both zk-SNARKs easier to construct and deploy.

Currently, these transactions cost around 6,000,000 Gas. This EIP can reduce it to 1,000,000Gas, which makes the protocol more practical.

EIP-1283: Gas adjustment for SSTORE opcode

This EIP proposes metering changes to the SSTORE opcode to enable new uses of contract storage and reduce excessive gas costs where it does not match how most implementations work. This could serve as an alternative to EIP-1087, where it tried to be friendlier to implementations that use different optimization strategies for changing caches.

EIP-2028: Reducing transaction data gas costs

It is recommended to reduce the Gas cost of Calldata (GTXDATANONZERO) from the current 68 bytes to 16 bytes, and support it through mathematical modeling and empirical estimation.

EIP-2200: Structural Definition of Net Gas Metering

This EIP provides a structured definition of net gas metering changes for the SSTORE opcode, enabling new uses of contract storage and reducing excessive gas costs where it doesnt match how most implementations work. This can be considered as a combination of EIP-1283 and EIP-1706.

EIP-2565: ModExpGas cost

In order to accurately reflect the actual operation cost of ModExp precompilation, this EIP specifies an algorithm for calculating the Gas cost. The algorithm estimates the multiplication complexity cost and multiplies it by an approximation of the number of iterations required to perform the exponentiation.

EIP-1559: Fee Market Changes for the ETH 1.0 Chain

Ethereum uses a simple auction mechanism to price transaction fees at historical prices, users send transactions in bids (“Gasprices”), miners select the transaction with the highest bid, and included transactions are paid at the specified bid. This leads to inefficiencies.

The proposal in this EIP is to start with a base fee amount that is adjusted downward by the protocol based on the congestion of the network. The base fee increases slightly when the network exceeds the target usage per block of Gas, and decreases slightly when the capacity falls below the target amount.

Since the variation of these base fees is limited, the maximum difference in base fees between different blocks is predictable. This then allows the wallet to automatically set the gas fee for the user in a highly reliable manner. It is expected that most users will not have to manually adjust gas fees even during periods of active network activity. For most users, the base fee will be estimated by their wallet.

EIP-2929: Increased gas cost for state access opcodes

Increased Gas cost SLOAD (0x54) to 2100, and *CALL opcode family (0xf1, f2, f4, fA), BALANCE 0x31 and EXT* opcode family (0x3b, 0x3c, 0x3f), and 2600 CD-free (i) Precompiled. Additionally, SSTORE metering could be reformed to ensure correct pricing of the actual storage load inherent in these SELFDESTRUCT opcodes.

Typically, the main function of an opcodes gas cost is to estimate the time it will take to process that opcode, with the goal of making the gas limit correspond to a limit on the time it takes to process a block. However, the storage access opcodes (SLOAD, and the *CALL, BALANCE, and EXT* opcodes) have historically been underestimated. In the 2016 Shanghai DoS attack, after fixing the most serious client-side bug, one of the tactics used by the attackers that has always worked was simply sending transactions that could access or call a large number of accounts.

The proposed EIP increases the cost of these opcodes by a factor of about 3, reducing the worst-case processing time to about 7-27 seconds. Improvements to the database layout involving redesigning the client to directly read the store instead of jumping to the Merkle tree should further reduce this, although these technologies may take a long time to fully roll out, and even with this technology, access Storage IO overhead will also remain substantial.

EIP-1077: Gas relay for contract calls

The main obstacle to the adoption of DApps is the need for multiple tokens to perform chain operations. Users are allowed to sign messages to show intent to execute, but allowing third-party relayers to execute messages avoids this problem, although Ethereum transactions always require ETH, smart contracts can adopt EIP-191 signatures and forward payment incentives to be untrusted with ETH Party executes the transaction. A common format in which they can be standardized, and the way users allow transactions to be paid for in tokens, offers a lot of flexibility to application developers and can become the primary way application users interact with the blockchain.

EIP-1087: Gas metering for SSTORE operations

This EIP proposes changes to the gas charging method for EVMSSTORE operations to reduce unnecessary gas costs and provide new use cases for contract storage.

EIP-1285: Add GcallstipendGas to CALL opcode

Gcallstipend increases the fee parameter in the CALL opcode from 2,300 to 3,500 Gas units.

EIP-1380: Reduced the Gas cost of internal calls

Smart contract languages ​​such as Solidity and Vyper will greatly benefit from reducing the gas cost of internal calls, so that they can use CALL instead of JUMP internal operation calls to use opcodes.

EIP-1613: Gas station network

Make smart contracts (e.g. dapps) accessible to non-ETH users by allowing contracts to accept COI and pay for Gas.

Communicating with dapps currently requires gas fees to be paid in ETH, which limits dapp adoption to Ethereum users only. Therefore, contract owners may wish to pay for gas to increase user acquisition, or have their users pay for gas in fiat currency. Alternatively, a third party may wish to subsidize the gas cost of certain contracts. A solution as described in EIP-1077 could allow transactions from addresses that do not contain ETH.

EIP-1930: CALL with strict gas semantics. Revert if not enough Gas

Add smart contract functionality to execute a CALL with a specific amount of Gas. If this is not possible, execution should be returned.

EIP-2045: Granular gas cost for EVM opcodes

Compute EVM opcodes (ADD, SUB, MUL, etc.) are usually overestimated relative to I/O used to store opcodes (SLOAD, SSTORE, etc.). Currently, the smallest gas cost is 1 (i.e. a unit of gas), and most compute opcodes have a cost close to 1 (e.g. 3, 5, or 8), so there is a limit to where the cost can be reduced. A new minimum gas unit, called a granule, which is a fraction of a gas, will expand the range of gas costs so they can be lowered below the current minimum.

EIP-2046: Reduced gas cost for static calls to precompile

Reduced the base gas cost of calling precompiled STATICCALL from 700 to 40. This will allow for more efficient use of precompilations as well as precompilations with a total cost of less than 700.

EIP-2542: New opcodes TXGASLIMIT and CALLGASLIMIT

Allows smart contracts to access information about gas limits for the current transaction and execution frame. With concepts such as relays, meta-transactions, gas fees, and account abstractions gaining popularity, it becomes critical for certain contracts to be able to track gas spending with absolute precision.

EIP-3322: Account Gas storage opcode

Gas supply elasticity and price stability are brought about by moving Gas from blocks with less demand to blocks with greater demand. Unfortunately, this rewards unnecessary state growth. By introducing an advanced gas storage mechanism, the gas market will require less storage and computation.

EIP-2780: Reduce internal transaction gas

Reduced the cost of internal transactions from 21,000 to 7,000 Gas.

The current gas cost of 21,000 transactions makes sending ETH very expensive, and the cost of small batches (tens of dollars) is usually prohibitively high. While other EIPs (e.g. EIP-1559) also account for gas price and first price auction changes, it would be positive to drastically reduce the cost of sending ETH and enable a larger number of such transactions if done in a secure manner.

The second key: Rollup and Gas

The early Gas story was about the formulation of the Ethereum Gas fee model. At present, in addition to reducing the Gas fee, the best way to expand and reduce the Gas fee is to compress transaction data.

This has a lot to do with Rollup.

A simple Ethereum transaction (sending ETH) takes about 110 bytes. However, the ETH transmission in Rollup only takes 12 bytes, so Rollup may increase the scalability of the base chain by about 10 times, and in specific calculations, the scalability can even be increased by more than 100 times by using Rollup.

This is an absolutely impressive achievement, which is why Eth2.0 has become a Rollup-centric development route.

Original article, author:白计划。Reprint/Content Collaboration/For Reporting, Please Contact report@odaily.email;Illegal reprinting must be punished by law.

ODAILY reminds readers to establish correct monetary and investment concepts, rationally view blockchain, and effectively improve risk awareness; We can actively report and report any illegal or criminal clues discovered to relevant departments.

Recommended Reading
Editor’s Picks