详述EIP-7706并梳理最新的Ethereum的Gas机制

币圈资讯 阅读:29 2024-05-15 19:27:31 评论:0
美化布局示例

欧易(OKX)最新版本

【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   全球官网 大陆官网

币安(Binance)最新版本

币安交易所app【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址

火币HTX最新版本

火币老牌交易所【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址
以太坊Gas机制变迁

作者:@Web3Mario

引言

Vitalik在2024年5月13日发布了EIP-7706提案,提出了对现有Gas模型的补充方案,将calldata的gas计算单独剥离出来,并定制了类似Blob gas的base fee定价机制,进一步降低L2的运行成本。与之相关的提案还需要追溯到2022年2月提出的EIP-4844,相隔时间甚久,因此查阅相关资料,希望对最新的Ethereum Gas机制做一个综述,方便大家快速了解。

当前已支持的Ethereum Gas模型——EIP-1559和EIP-4844

在最初的设计中,Ethereum采用了一个简单的拍卖机制对交易费用进行定价,这需要用户主动为自己的交易出价,也就是设置gas price,通常情况下,由于用户付出的交易费将归属于矿工,所以矿工将根据经济最优的原则,按照出价高低来决定交易打包顺序,注意这是在忽略MEV的情况下。在当时核心开发者看来这个机制面临着以下四个方面的问题:

  • 交易费用水平的波动性与交易的共识成本之间的不匹配对于处在活跃状态的区块链中,交易的打包需求充足,这意味着区块可以被轻易填满,但这往往也意味着整体费用的波动性极大。例如当平均Gas Price为10 Gwei时,网络因在一个区块中再接受一笔交易而产生的边际成本是平均Gas Price为1 Gwei时的 10 倍,这是不可接受的。

  • 对用户来说不必要的延迟:由于每个区块有gas limit的硬性限制,加上历史交易量的自然波动,交易通常会等待几个区块才能被打包,但这对整体网络来说是低效的;即不存在允许一个区块更大而下一个区块更小的“松弛”机制来满足逐个区块的需求差异。

  • 定价效率低下:由于采用简单的拍卖机制导致了公允价格发现的效率较低,这意味着对于用户来说,给出一个合理的定价将是困难的,这也就意味着有非常多情况下,用户付高了手续费。

  • 无区块奖励的区块链不稳定:当取消挖矿带来的区块奖励并采取单纯的手续费模型时,可能会导致很多不稳定,例如激励挖掘窃取交易费用的“姐妹块”,开启更强大的自私挖掘攻击向量等。

直到EIP-1559的提出与执行,Gas模型有个第一次迭代,EIP-1559时Vitalik等核心开发者在2019年4月13日提出的,并在2021年8月5日的London升级中被采用,该机制摒弃了拍卖机制,转而采用了一种Base fee和Priority fee的双定价模型,其中Base fee将根据父区块中已产生的gas消耗情况与一个浮动且递归的gas target之间的关系通过一个既定的数学模型定量计算,直观的效果为若上一个区块中gas使用情况超过了预定的gas target时,则上调base fee,若不及gas target,则下调base fee,这样做既可以比较好的反应供需关系,又可以使得对于合理gas的预测变得更加精准,不至于出现由于误操作导致的天价Gas Price,因为base fee的计算是直接由系统决定的而非用户自由指定。具体的代码如下:


The author's introduction to the change of Ethereum mechanism released a proposal on March, and put forward a supplementary scheme to the existing model, and separated the calculation separately and customized a similar pricing mechanism to further reduce the operating cost. The related proposal still needs to be traced back to June, and the time interval is very long, so I hope to make a summary of the latest mechanism so that everyone can quickly understand the currently supported model and adopt a simple auction mechanism to enter the transaction cost in the initial design. Line pricing This requires users to actively bid for their own transactions, that is, setting. Usually, because the transaction fees paid by users will belong to miners, miners will decide the transaction packaging order according to the bid level according to the principle of economic optimization. Note that this is neglected. In the eyes of core developers at that time, this mechanism faced the following four problems: the mismatch between the fluctuation of transaction fees and the consensus cost of transactions. The demand for packages is sufficient, which means that blocks can be easily filled, but it often means that the overall cost fluctuates greatly. For example, when the average is equal, the marginal cost of the network for accepting another transaction in a block is twice as high as the average. This is unacceptable and unnecessary delay for users. Due to the hard restrictions of each block and the natural fluctuation of historical transaction volume, transactions usually wait for several blocks to be packaged, but this is inefficient for the whole network, that is, there is no permission. The relaxation mechanism that one block is bigger and the next block is smaller to meet the demand difference block by block. The pricing efficiency is low. Because of the simple auction mechanism, the efficiency of fair price discovery is low, which means that it will be difficult for users to give a reasonable pricing, which means that in many cases, the blockchain without block reward will be unstable. When the block reward brought by mining is cancelled and a simple fee model is adopted, it may lead to a lot. Instability, such as encouraging sister blocks that steal transaction costs to open more powerful selfish mining attack vectors, until the first iteration of the proposed and executed model, was proposed by the core developers on, and was adopted in the upgrade on, and this mechanism abandoned the auction mechanism and adopted a sum double pricing model, in which the intuitive effect will be quantitatively calculated through an established mathematical model according to the relationship between the consumption situation in the parent block and a floating and recursive one. If the usage in the last block exceeds the predetermined value, it will be adjusted upwards, otherwise it will be adjusted downwards. This can not only better reflect the relationship between supply and demand, but also make the reasonable prediction more accurate and avoid the sky-high price caused by misoperation, because the calculation is directly determined by the system rather than freely specified by the user. The specific code is as follows. 比特币今日价格行情网_okx交易所app_永续合约_比特币怎么买卖交易_虚拟币交易所平台

MD8HccZ79p.jpg

以太坊更新:Base Fee调整及Rollup发展

以太坊更新:Base Fee调整及Rollup发展

最新的以太坊协议更新带来了一系列重要变化,其中包括对Base Fee的调整以及Rollup技术的发展。

根据最新的更新,当父区块的Gas使用量超过了目标值时,当前区块的Base Fee将会相对于上一个区块的Base Fee增加一个偏移量。这个偏移量是通过将父区块的Base Fee乘以上一个区块的总Gas使用量与Gas目标的偏移量的余数与1的最大值来计算的。反之,相似的逻辑也适用。

另外,Base Fee不再作为矿工的奖励,而是直接销毁。这一举措使得以太坊的经济模型进入通缩状态,有利于价值的稳定。与此同时,Priority Fee则相当于用户给予矿工的小费,用户可以自行设定价格。这在一定程度上促使矿工排序算法的复用。

随着时间推进至2021年,Rollup技术逐渐成熟。无论是Optimistic Rollup还是Zero-Knowledge Rollup,都需要将Layer 2的数据进行压缩处理,并通过calldata上传至链上以实现数据的可用性,或者直接提交至链上进行验证。然而,这些操作导致Rollup方案在维护Layer 2的最终性时面临着巨大的Gas成本。而这些成本最终都转嫁给了用户,导致大部分Layer 2协议的使用成本并不低。

与此同时,以太坊也面临着区块空间竞争的挑战。每个区块都有一个Gas限制,即当前区块中所有交易的Gas消耗总和不得超过该值。以当前的Gas限制为例,理论上每个区块最多可以容纳的数据大小约为1,875,000字节,其中16表示EVM处理每个calldata字节所需的Gas单位数。

```html 以太坊网络升级新特性介绍

近期以太坊网络升级引入了两项重要的新特性,旨在优化网络交易处理效率和Gas消耗模型。

首先,随着区块链数据规模不断增大,主链的交易确认速度受到了影响。特别是L2排序器产生的Rollup相关数据通常规模庞大,导致主链上的交易确认竞争激烈,限制了单个区块可打包的交易量,从而影响了主链的TPS(每秒交易数)。为解决这一问题,核心开发者们提出了EIP-4844提案,于2024年二季度初的Dencun升级后得到了实施。

该提案引入了一种新的交易类型,名为Blob Transaction。与传统交易类型相比,Blob Transaction引入了一种新的数据类型,即Blob data。Blob data与calldata不同,不可直接访问,而只能访问其hash,也称为VersionedHash。此外,Blob Transaction的GC周期更短,以避免区块数据过于臃肿。Blob data具有原生的Gas机制,类似于EIP-1559,但采用了自然指数函数,使其在应对交易规模波动时更稳定。这种函数的斜率亦为自然指数函数,意味着无论网络交易规模如何变化,都能更有效地调节Gas费用。

针对每个Blob gas的base fee的计算公式为:

base_fee_per_blob_gas = MIN_BASE_FEE_PER_BLOB_GAS * e**(excess_blob_gas / BLOB_BASE_FEE_UPDATE_FRACTION)

其中,MIN_BASE_FEE_PER_BLOB_GAS和BLOB_BASE_FEE_UPDATE_FRACTION为常量,excess_blob_gas由父区块中总的blob gas消耗与目标值之间的差值决定。

这一改进使得以太坊网络能够以较低成本处理大规模数据,而不会影响区块的交易打包能力。例如,Rollup排序器可通过Blob Transaction将L2的关键信息封装到Blob data中,并在EVM中实现链上验证的逻辑。

k785PjpLJ7.jpg

需要注意的是,目前的设置限制了每个区块平均处理3个Blob(0.375 MB)的目标和最多处理6个Blob(0.75 MB)。这些限制旨在减少EIP对网络造成的压力,随着网络在较大区块下展现可靠性,预计未来的升级中会逐步调整。

对Gas消耗模型的进一步细化——EIP-7706

另一项重要的升级是EIP-7706,旨在优化Gas消耗模型。该提案由Vitalik于2024年5月13日提出。

与Blob data类似,EIP-7706剥离了另一个特殊数据字段calldata的Gas模型,并优化了相应的代码实现逻辑。Calldata的base fee计算逻辑与Blob data相同,均采用了指数函数,并根据实际gas消耗值与目标值的偏差来计算base fee的缩放比例。

Z8eH8e6DX3.jpg ``` ```html

近日,有一个新的参数设计引起了关注,即LIMIT_TARGET_RATIOS=[2,2,4]。这个参数包括了三个值,分别表示了执行操作类Gas的目标比率、Blob data类Gas的目标比率以及calldata类Gas的目标比率。这个参数的引入将用于计算父区块中三类gas对应的gas target值。

94GJRfSro0.jpg

具体的计算逻辑如下:对gas limit分别使用LIMIT_TARGET_RATIOS进行整除操作。

其中gas_limits的设定逻辑如下:

gas_limits[0]必须遵循现有的调整公式

gas_limits[1]必须等于MAX_BLOB_GAS_PER_BLOCK

gas_limits[2]必须等于gas_limits[0] // CALLDATA_GAS_LIMIT_RATIO

据了解,当前gas_limits[0]为30000000,CALLDATA_GAS_LIMIT_RATIO被预设为4。这意味着当前calldata gas target约为30000000 // 4 // 4 = 1875000。根据当前的calldata gas计算逻辑,每个非零Bytes消耗16 Gas,零Bytes消耗4 Gas。假设某段calldata中非零与零Bytes的分布各占50%,则平均处理1 Bytes的calldata需要消耗10 Gas。因此,当前的calldata gas target应对应187500 bytes的calldata数据,约为当前平均用量的2倍。

这样的设计有利于大大减少calldata达到gas limit的情况发生的概率,通过经济模型使calldata的用量保持在一个较为始终的状态。同时,也杜绝了对calldata的滥用。这一设计的初衷是为了推动L2的发展,搭配blob data,使得排序器成本进一步降低。

```

文字格式和图片示例

注册有任何问题请添加 微信:MVIP619 拉你进入群

弹窗与图片大小一致 文章转载注明 网址:https://netpsp.com/?id=64007

美化布局示例

欧易(OKX)最新版本

【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   全球官网 大陆官网

币安(Binance)最新版本

币安交易所app【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址

火币HTX最新版本

火币老牌交易所【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址
可以去百度分享获取分享代码输入这里。
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

发表评论
平台列表
美化布局示例

欧易(OKX)

  全球官网 大陆官网

币安(Binance)

  官网

火币(HTX)

  官网

Gate.io

  官网

Bitget

  官网

deepcoin

  官网
关注我们

若遇到问题,加微信客服---清歌

搜索
排行榜
扫一扫,加我为微信好友加我为微信好友