EIP-4895 · Final(最终) · Core(核心) · 2022-03-10
EIP-4895: Beacon chain push withdrawals as operations
让验证者的提款从信标链流入执行层,作为一种新的系统级“withdrawal”操作,无需交易也无需 gas 即可向地址入账 ETH;已在 Shanghai/Capella 升级中激活。
它解决什么问题?
合并(the Merge,EIP-3675)之后,质押者的 ETH 留在信标链上,无法回到 EVM。奖励不断累积,退出也是可能的,但这些 ETH 无法使用。
EIP-4895 定义了提取出的 ETH 如何从共识层进入执行层余额。它采用推送模型:当共识层把一笔提款从队列中取出时,执行层必须在该区块中应用它。无需任何人发送交易来领取。
它如何运作
- 一种新的负载对象 withdrawal,与用户交易分开:
[index, validator_index, address, amount]。index是全局计数器,amount以 Gwei 为单位且非零。 - 执行负载新增
withdrawals列表,区块头新增withdrawals_root,它是以与交易根相同的方式构建的 Merkle-Patricia 树根。 - 提款在区块中所有交易之后处理。每一笔只是把
address的余额增加amount × 10^9wei。 - 这种余额增加是无条件的,不得失败,不消耗 gas,也不运行任何 EVM 代码。
激活基于时间戳:FORK_TIMESTAMP = 1681338455(2023 年 4 月,执行层 Shanghai / 共识层 Capella 升级)。
为什么不用新的交易类型?提款由系统发起,而不是由用户发起。将其作为独立对象,可以避免与普通交易处理产生交互,并简化测试和安全审查。共识层限制了每个区块中出现的提款数量,因此跳过 gas 计算是安全的。
示例代码
通过 JSON-RPC 从区块中读取提款(ethers v6):
import { JsonRpcProvider, formatEther } from "ethers";
const provider = new JsonRpcProvider(process.env.RPC_URL);
const block = await provider.send("eth_getBlockByNumber", ["latest", false]);
console.log("withdrawalsRoot:", block.withdrawalsRoot);
for (const w of block.withdrawals ?? []) {
const wei = BigInt(w.amount) * 10n ** 9n; // amount is in Gwei
console.log(`#${BigInt(w.index)} validator ${BigInt(w.validatorIndex)} -> ${w.address}: ${formatEther(wei)} ETH`);
}