BTC
ETH
HTX
SOL
BNB
View Market
简中
繁中
English
日本語
한국어
ภาษาไทย
Tiếng Việt

EIP-3529: Reduce gas return

ECN以太坊中国
特邀专栏作者
This article is about 3498 words, reading the full article takes about 5 minutes
How London’s upgraded EIP-3529 will optimize EVM by modifying gas return
AI Summary
Expand
How London’s upgraded EIP-3529 will optimize EVM by modifying gas return

Source | eips.ethereum.org

brief summary

brief summary

reason

reason

The gas return of SSTORE and SELFDESTRUCT was originally introduced to encourage application developers to practice "good state hygiene" when writing applications, and clean up storage slots and contracts that are no longer needed. However, it turns out that the efficiency brought by this technology is much lower than expected, and the gas return has several unanticipated harmful consequences:

➤ Gas return causes GASToken to appear. GasToken is good for moving gas space from low-fee phases to high-fee phases, but it is also bad for the network, especially exacerbating state size inflation (since state slots are effectively used as "batteries" to accumulate gas) and inefficient clogging Blockchain gas usage.

parameter

specification

parameter

For blocks with block.number >= FORK_BLOCK, the following changes are required.

1. Remove return of SELFDESTRUCT

2. Replace SSTORE_CLEARS_SCHEDULE (defined by EIP-2200) with SSTORE_RESET_GAS + ACCESS_LIST_STORAGE_KEY_COST (4,800 gas under the combined force of EIP-2929 + EIP-2930)

first level title

Principle explanation

EIP-2200 introduces three cases of rebate:

1. If the original value is non-zero and the new value is zero, add the gas amount of SSTORE_CLEARS_SCHEDULE (currently 15,000) to the refund calculator

2. If the original value is zero, the current value is non-zero, and the new value is zero, add the gas amount of SSTORE_SET_GAS - SLOAD_GAS (currently 19,900) to the refund calculator

3. If the original value is non-zero, the current value is a different non-zero value, and the new value is equal to the original value, add the gas of SSTORE_RESET_GAS - SLOAD_GAS (currently 4,900) to the return calculator

In these three cases, only (1) will activate the gastoken and allow the block to consume more gas than the block gas limit on execution. (2) does not have this feature, because to get the 19,900 gas refund, the same storage slot must have previously changed from zero to non-zero, which costs 20,000 gas. The inability to get gas from one slot and use it to edit another means it cannot be used as a gas token. In addition, obtaining the refund requires recovery of storage writes and expansions so that the returned gas does not increase the client's workload in processing blocks. (3) is similar: the 4,900 gas rebate is only granted if the same slot has previously consumed 5,000 gas.

This EIP handles the first case. We can use a similar "pairing" argument to determine the conditions under which gastokens are not available (for example, you cannot get more gas in a slot than your input), converting each Returns the previous spend of the same storage slot mapped to the same transaction. When the original value of a storage slot is non-zero, if it is changed to 0, there are two possibilities:

1. This may be the first time the memory slot has been set to zero. In this case, we can pair this time with the minimal overhead of SSTORE_RESET_GAS + ACCESS_LIST_STORAGE_KEY_COST for first reading and editing a storage slot.

2. This may be the case when the memory slot is set to zero for the second time or after it has been set to zero. In this case, we can pair this event with the last time the value changed from zero to something else, and the gas of SSTORE_CLEARS_SCHEDULE was removed from the return.

For the second and later cases, it doesn't matter what the value of SSTORE_CLEARS_SCHEDULE is, because that gas-sized return matches a clear return of the same size. This leaves only the first case. To ensure that the total amount of gas consumed on a storage slot is positive, we need SSTORE_CLEARS_SCHEDULE <= SSTORE_RESET_GAS + ACCESS_LIST_STORAGE_KEY_COST. Therefore, this EIP simply reduces SSTORE_CLEARS_SCHEDULE to the sum of those two overheads.

backward compatibility

backward compatibility

Returns are currently only applied after transaction execution, so cannot affect any specific available call frames in execution. Therefore, clearing them will not break the execution of any code, although it will make some applications economically unviable.

Gas token will become worthless. DeFi arbitrage bots today often use either an existing gas token scheme or a custom one to reduce on-chain overhead, thanks to rewriting their code to clean up calls to gas storage mechanisms that are no longer useful.

However, keeping the return fully in new = original = 0 != current , and keeping some return in the other nonzero -> zero cases ensures that some key use cases that receive (and deserve) better gas overhead treatment will continue to be beneficial. For example, zero -> nonzero -> zero storage configuration mode remains only consumes about 100 gas. These patterns include two important instances:

➤ Anti-reentrant lock (usually changes from 0 to 1 before a subcall starts, and then changes back to 0 when the subcall ends)

➤ ERC20 authorization and sending (when the token transfer is authorized,"authorized value"secondary title

Impact on Clear Storage Incentives

A criticism of the previous EIPs for removal rebates (EIP-3298 and EIP-3403) is that these EIPs completely remove the incentive to set a value to zero, effectively encouraging users not to completely clear a slot (even if they wanted to) ), even though the chances of them wanting to use that slot again are minimal.

As an example, if you have one unit of ERC20 tokens and you want to give away or sell your entire balance, you can just give 0.999999 units and keep the rest. If you want to re-put more of this token into the same account in the future, you only need to pay 5,000 gas for SSTORE (2,100 for reading + 2,900 for non-zero to non-zero setting) instead of 22,100 ( 20,000 for settings from zero to non-zero values). Today, this part of the gas is offset by the 15,000 gas refund for clearing storage, so if you have more than 15000 / 17100 = 87.7% certainty that you will use this storage slot again, you will have an incentive to do so; per EIP 3298 Or the setting of EIP 3403, the part of offset incentive does not exist, so if the possibility of you using the storage slot again is greater than 0, it is better to set it to a non-zero value.

For the remaining 4,800 gas rebates, if you feel that the chance of using a slot again is greater than 4800 / 17100 = 28.1%, you have an incentive to keep that slot non-zero. It's not perfect, but it's probably higher than the average person's odds of regaining the same tokens at the same address after wiping their entire balance.

first level title

secondary title

Gas overhead for EIP-2929

secondary title

After the reduced return

security considerations

security considerations

Returns are not visible to transactional execution, so this does not have any impact on transactional execution logic.

ECN's translation work aims to deliver high-quality information and learning resources for the Chinese Ethereum community. The copyright of the article belongs to the original author, and the source of the original text and the ETH Chinese website must be indicated when reprinting. For long-term reprinting, please contact eth@ecn.co for authorization.

Original link:https://eips.ethereum.org/EIPS/eip-3529

ECN's translation work aims to deliver high-quality information and learning resources for the Chinese Ethereum community. The copyright of the article belongs to the original author, and the source of the original text and the ETH Chinese website must be indicated when reprinting. For long-term reprinting, please contact eth@ecn.co for authorization.

Official Account: ETH Chinese Station

Website: ethereum.cn

ETH
Welcome to Join Odaily Official Community