EIP-7703 · Stagnant(停滞) · Core(核心) · 2024-05-07
EIP-7703: Increase calldata cost
提议将 calldata 的 gas 提高到三倍(零字节 4→12,非零字节 16→48),以缩小最坏情况下的区块大小,从而可以安全地提高 gas 上限。
它解决什么问题?
以太坊区块在字节数上的最大可能值,是在区块被廉价的 calldata 填满时达到的。大区块在网络中传播更慢,因此这种最坏情况,而不是典型使用,是阻碍提高区块 gas 上限的因素之一。
EIP-7703 采取了最直接的办法:让 calldata 贵三倍。在 gas 上限不变的情况下,最大区块大小缩小约三分之二,这就为提高 gas 上限留出了空间,同时不会让最坏情况变得更糟。
它如何运作
这个提案只改动两个常量,其他一概不动:
| 常量 | 现在 | EIP-7703 |
|---|---|---|
G_CALLDATAZERO(每个零字节) |
4 | 12 |
G_CALLDATANONZERO(每个非零字节) |
16 | 48 |
每笔交易都要按 data 的每个字节支付这笔费用,作为其 intrinsic gas 的一部分。执行 gas、存储和 blob 定价(EIP-4844)都不受影响。
由于这一改动比较粗暴,它会提高所有携带 calldata 的交易的成本,包括普通的合约调用,而不仅仅是数据密集型交易。
示例代码
变更前后的 intrinsic calldata 成本(TypeScript,无依赖):
function calldataGas(data: Uint8Array, zero: number, nonZero: number): number {
let gas = 0;
for (const b of data) gas += b === 0 ? zero : nonZero;
return gas;
}
const hex = "a9059cbb000000000000000000000000d8da6bf26964af9d7eed9e10e5d4ba5f1c42e8f20000000000000000000000000000000000000000000000000de0b6b3a7640000";
const data = Uint8Array.from(hex.match(/../g)!.map((h) => parseInt(h, 16)));
console.log("today: ", calldataGas(data, 4, 16)); // 21000 + this = intrinsic gas
console.log("EIP-7703:", calldataGas(data, 12, 48)); // exactly 3x
仅由 calldata 填满时的最大区块大小粗略估算:
gas_limit = 30_000_000 # illustrative gas limit
print(gas_limit // 16) # ~1.87 MB of non-zero calldata today
print(gas_limit // 48) # ~0.62 MB under EIP-7703