ACP-176: Dynamic Evm Gas Limit And Price Discovery Updates

Details for Avalanche Community Proposal 176: Dynamic Evm Gas Limit And Price Discovery Updates

ACP176
TitleDynamic EVM Gas Limits and Price Discovery Updates
Author(s)Stephen Buttolph (@StephenButtolph), Michael Kaplan (@michaelkaplan13)
StatusActivated (Discussion)
TrackStandards

Abstract

Proposes that the C-Chain and Subnet-EVM chains adopt a dynamic fee mechanism similar to the one introduced on the P-Chain as part of ACP-103, with modifications to allow for block proposers (i.e. validators) to dynamically adjust the target gas consumption per unit time.

Motivation

Currently, the C-Chain has a static gas target of 15,000,000 gas per 10 second rolling window, and uses a modified version of the EIP-1559 dynamic fee mechanism to adjust the base fee of blocks based on the gas consumed in the previous 10 second window. This has two notable drawbacks:

  1. The windower mechanism used to determine the base fee of blocks can lead to outsized spikes in the gas price when there is a large block. This is because after a large block that uses all of its gas limit, blocks that follow in the same window continue to result in increased gas prices even if they are relatively small blocks that are under the target gas consumption.
  2. The static gas target necessitates a required network upgrade in order to modify. This is cumbersome and makes it difficult for the network to adjust its capacity in response to performance optimizations or hardware requirement increases.

To better position Avalanche EVM chains, including the C-Chain, to be able to handle future increases in load, we propose replacing the above mechanism with one that better handles blocks that consume a large amount of gas, and that allows for validators to dynamically adjust the target rate of consumption.

Specification

Gas Price Determination

The mechanism to determine the base fee of a block is the same as the one used in ACP-103 to determine the gas price of a block on the P-Chain. This mechanism calculates the gas price for a given block bb based on the following parameters:

TTthe target gas consumed per second
MMminimum gas price
KKgas price update constant
CCmaximum gas capacity
RRgas capacity added per second

Making TT Dynamic

As noted above, the gas price determination mechanism relies on a target gas consumption per second, TT, in order to calculate the gas price for a given block. TT will be adjusted dynamically according to the following specification.

Let qq be a non-negative integer that is initialized to 0 upon activation of this mechanism. Let the target gas consumption per second be expressed as:

T=PeqDT = P \cdot e^{\frac{q}{D}}

where PP is the global minimum allowed target gas consumption rate for the network, and DD is a constant that helps control the rate of change of the target gas consumption.

After the execution of transactions in block bb, the value of qq can be increased or decreased up to QQ. It must be the case that ΔqQ\left|\Delta q\right| \leq Q, or block bb is considered invalid. The amount by which qq changes after executing block bb is specified by the block builder.

Block builders (i.e. validators), may set their desired value for TT (i.e. their desired gas consumption rate) in their configuration, and their desired value for qq can then be calculated as:

qdesired=Dln(TdesiredP)q_{desired} = D \cdot ln\left(\frac{T_{desired}}{P}\right)

Note that since qdesiredq_{desired} is only used locally and can be different for each node, it is safe for implementations to approximate the value of ln(TdesiredP)ln\left(\frac{T_{desired}}{P}\right), and round the resulting value to the nearest integer.

When building a block, builders can calculate their next preferred value for qq based on the network's current value (q_current) according to:

# Calculates a node's new desired value for q given for a given block
def calc_next_q(q_current: int, q_desired: int, max_change: int) -> int:
  if q_desired > q_current:
      return q_current + min(q_desired - q_current, max_change)
  else:
      return q_current - min(q_current - q_desired, max_change)

As qq is updated after the execution of transactions within the block, TT is also updated such that T=PeqDT = P \cdot e^{\frac{q}{D}} at all times. As the value of TT adjusts, the value of RR (capacity added per second) is also updated such that:

R=2TR = 2 \cdot T

This ensures that the gas price can increase and decrease at the same rate.

The value of CC must also adjust proportionately, so we set:

C=10TC = 10 \cdot T

This means that the maximum stored gas capacity would be reached after 5 seconds where no blocks have been accepted.

In order to keep roughly constant the time it takes for the gas price to double at sustained maximum network capacity usage, the value of KK used in the gas price determination mechanism must be updated proportionally to TT such that:

K=87TK = 87 \cdot T

In order to have the gas price not be directly impacted by the change in KK, we also update xx (excess gas consumption) proportionally. When updating xx after executing a block, instead of setting x=x+Gx = x + G as specified in ACP-103, we set:

xn+1=(x+G)Kn+1Knx_{n+1} = (x + G) \cdot \frac{K_{n+1}}{K_{n}}

Note that the value of qq (and thus also TT, RR, CC, KK, and xx) are updated after the execution of block bb, which means they only take effect in determining the gas price of block b+1b+1. The change to each of these values in block bb does not effect the gas price for transactions included in block bb itself.

Allowing block builders to adjust the target gas consumption rate in blocks that they produce makes it such that the effective target gas consumption rate should converge over time to the point where 50% of the voting stake weight wants it increased and 50% of the voting stake weight wants it decreased. This is because the number of blocks each validator produces is proportional to their stake weight.

As noted in ACP-103, the maximum gas consumed in a given period of time Δt\Delta{t}, is r+RΔtr + R \cdot \Delta{t}, where rr is the remaining gas capacity at the end of previous block execution. The upper bound across all Δt\Delta{t} is C+RΔtC + R \cdot \Delta{t}. Phrased differently, the maximum amount of gas that can be consumed by any given block bb is:

gasLimitb=min(r+RΔt,C)gasLimit_{b} = min(r + R \cdot \Delta{t}, C)

Configuration Parameters

As noted above, the gas price determination mechanism depends on the values of TT, MM, KK, CC, and RR to be set as parameters. TT is adjusted dynamically from its initial value based on DD and PP, and the values of RR and CC are derived from TT.

Parameters at activation on the C-Chain are:

ParameterDescriptionC-Chain Configuration
PPminimum target gas consumption per second1,000,0001,000,000
DDtarget gas consumption rate update constant2252^{25}
QQtarget gas consumption rate update factor change limit2152^{15}
MMminimum gas price110181*10^{-18} AVAX
KKinitial gas price update factor87,000,00087,000,000

PP was chosen as a safe bound on the minimum target gas usage on the C-Chain. The current gas target of the C-Chain is 1,500,0001,500,000 per second. The target gas consumption rate will only stay at PP if the majority of stake weight of the network specifies PP as their desired gas consumption rate target.

DD and QQ were chosen to give each block builder the ability to adjust the value of TT by roughly 11024\frac{1}{1024} of its current value, which matches the gas limit bound divisor that Ethereum currently uses to limit the amount that validators can change the execution layer gas limit in a single block. DD and QQ were scaled up by a factor of 2152^{15} to provide block builders more granularity in the adjustments to TT that they can make.

MM was chosen as the minimum possible denomination of the native EVM asset, such that the gas price will be more likely to consistently be in a range of price discovery. The price discovery mechanism has already been battle tested on the P-Chain (and prior to that on Ethereum for blob gas prices as defined by EIP-4844), giving confidence that it will correctly react to any increase in network usage in order to prevent a DOS attack.

KK was chosen such that at sustained maximum capacity (T2T*2 gas/second), the fee rate will double every ~60.3 seconds. For comparison, EIP-1559 can double about ~70 seconds, and the C-Chain's current implementation can double about every ~50 seconds, depending on the time between blocks.

The maximum instantaneous price multiplier is:

eCK=e10T87T=e10871.12e^\frac{C}{K} = e^\frac{10 \cdot T}{87 \cdot T} = e^\frac{10}{87} \simeq 1.12

Choosing TdesiredT_{desired}

As mentioned above, this new mechanism allows for validators to specify their desired target gas consumption rate (TdesiredT_{desired}) in their configuration, and the value that they set impacts the effective target gas consumption rate of the network over time. The higher the value of TT, the more resources (storage, compute, etc) that are able to be used by the network. When choosing what value makes sense for them, validators should consider the resources that are required to properly support that level of gas consumption, the utility the network provides by having higher transaction per second throughput, and the stability of network should it reach that level of utilization.

While Avalanche Network Clients can set default configuration values for the desired target gas consumption rate, each validator can choose to set this value independently based on their own considerations.

Backwards Compatibility

The changes proposed in this ACP require a required network upgrade in order to take effect. Prior to its activation, the current gas limit and price discovery mechanisms will continue to be used. Its activation should have relatively minor compatibility effects on any developer tooling. Notably, transaction formats, and thus wallets, are not impacted. After its activation, given that the value of CC is dynamically adjusted, the maximum possible gas consumed by an individual block, and thus maximum possible consumed by an individual transaction, will also dynamically adjust. The upper bound on the amount of gas consumed by a single transaction fluctuating means that transactions that are considered invalid at one time may be considered valid at a different point in time, and vice versa. While potentially unintuitive, as long as the minimum gas consumption rate is set sufficiently high this should not have significant practical impact, and is also currently the case on the Ethereum mainnet.

[!NOTE] After the activation of this ACP, concerns were raised around the latency of inclusion for large transactions when the fee is increasing. To address these concerns, block producers SHOULD only produce blocks when there is sufficient capacity to include large transactions. Prior to this ACP, the maximum size of a transaction was 1515 million gas. Therefore, the recommended heuristic is to only produce blocks when there is at least min(8T,15 million)\min(8 \cdot T, 15 \text{ million}) capacity. At the time of writing, this ensures transactions with up to 12.8 million gas will be able to bid for block space.

Reference Implementation

This ACP was implemented and merged into Coreth behind the Fortuna upgrade flag. The full implementation can be found in [email protected].

Security Considerations

This ACP changes the mechanism for determining the gas price on Avalanche EVM chains. The gas price is meant to adapt dynamically to respond to changes in demand for using the chain. If it does not react as expected, the chain could be at risk for a DOS attack (if the usage price is too low), or over charge users during period of low activity. This price discovery mechanism has already been employed on the P-Chain, but should again be thoroughly tested for use on the C-Chain prior to activation on the Avalanche Mainnet.

Further, this ACP also introduces a mechanism for validators to change the gas limit of the C-Chain. If this limit is set too high, it is possible that validator nodes will not be able to keep up in the processing of blocks. An upper bound on the maximum possible gas limit could be considered to try to mitigate this risk, though it would then take further required network upgrades to scale the network past that limit.

Acknowledgments

Thanks to the following non-exhaustive list of individuals for input, discussion, and feedback on this ACP.

Copyright and related rights waived via CC0.

Is this guide helpful?