EIP-4844 (又名 Proto-Danksharding) 通过引入 blob 携带交易来降低 Layer2 Rollup 的数据成本。Blob 是临时的链下数据块,存储在以太坊共识层上约 18 天。它将L2的交易费用降低了 10-100 倍,提高了可扩展性,同时保持了去中心化,为完全 Danksharding 奠定了基础。
以太坊的可扩展性长期以来一直是一个障碍。高昂的 gas 费用和有限的交易吞吐量(layer-1 上为 15 TPS)已将开发者推向 layer-2 rollups,例如 Optimism、Arbitrum 和 zkSync。这些 rollups 在链下批量处理交易,但依赖以太坊的 layer-1 (L1) 来实现 数据可用性——确保数据可以访问以进行验证。从历史上看,rollups 使用 calldata 将数据发布到 L1,这既昂贵(1,000 美元/MB)又永久存储,即使 rollups 仅需要临时数据(例如,用于欺诈证明)。
EIP-4844 或 Proto-Danksharding 通过引入 携带 Blob 的交易 来解决这个问题。Blob 是大型的、临时的以太坊数据块储存在以太坊的共识层(Beacon Chain),而不是执行层(EVM)。这大大降低了成本,使 L2 交易更便宜,并使以太坊能够处理更多数据——为 full Danksharding 铺平了道路,其目标是 100,000 TPS。
本文深入探讨了 EIP-4844 的机制、实施、代码示例及其对以太坊生态系统的变革性影响。
EIP-4844 引入了一种新的交易类型,携带 Blob 的交易,它携带 blob——存储在 Beacon Chain 上的临时 128 KB 数据块。以下是关键组件的细分:
maxFeePerBlobGas
和 blobVersionedHashes
等字段。// Example Blob Transaction Structure
struct BlobTx {
uint256 chainId;
uint256 nonce;
uint256 maxFeePerGas;
uint256 maxPriorityFeePerGas;
uint64 gasLimit;
address to;
uint256 value;
bytes data;
AccessList accessList;
uint256 maxFeePerBlobGas; // Fee for blob inclusion
bytes32[] blobVersionedHashes; // KZG commitment hashes
bytes signature;
}
// Query Blob Base Fee
function getBlobBaseFee() external view returns (uint256) {
return block.blobBaseFee; // Uses BLOBBASEFEE opcode
}
以下是 EIP-4844 如何集成到以太坊生态系统中:
// SPDX-License-Identifier: MIT
import { ethers } from 'ethers';
async function sendBlobTx() {
const provider = new ethers.providers.JsonRpcProvider('https://mainnet.infura.io/v3/YOUR_API_KEY');
const wallet = new ethers.Wallet('PRIVATE_KEY', provider);
const blobData = ethers.utils.hexlify(ethers.utils.randomBytes(128 * 1024)); // 128 KB blob
const kzgCommitment = '0x...'; // Generated off-chain (KZG ceremony output)
const tx = {
type: 3, // Blob transaction type
to: '0xYourContractAddress',
value: ethers.utils.parseEther('0.01'),
data: '0x',
maxFeePerGas: ethers.utils.parseUnits('30', 'gwei'),
maxPriorityFeePerGas: ethers.utils.parseUnits('1', 'gwei'),
maxFeePerBlobGas: ethers.utils.parseUnits('1', 'gwei'),
blobVersionedHashes: [kzgCommitment],
gasLimit: 21000
};
const sentTx = await wallet.sendTransaction(tx);
console.log('Blob Transaction Hash:', sentTx.hash);
}
注意:Blob 数据在链下提交到共识层;只有 commitment 包含在交易中。
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract BlobTransactionHandler {
event BlobProcessed(bytes32 commitment);
struct BlobData {
bytes32 commitment;
uint256 timestamp;
}
mapping(bytes32 => BlobData) public processedBlobs;
function processBlob(bytes32 _commitment) external {
require(_commitment != bytes32(0), "Invalid commitment");
require(block.blobBaseFee <= 1 gwei, "Blob gas price too high");
processedBlobs[_commitment] = BlobData({
commitment: _commitment,
timestamp: block.timestamp
});
emit BlobProcessed(_commitment);
}
function getBlobBaseFee() external view returns (uint256) {
return block.blobBaseFee; // Query blob gas price
}
}
const { expect } = require('chai');
const { ethers } = require('hardhat');
describe('BlobTransactionHandler', function () {
let handler, owner;
beforeEach(async function () {
const BlobHandler = await ethers.getContractFactory('BlobTransactionHandler');
handler = await BlobHandler.deploy();
[owner] = await ethers.getSigners();
});
it('Should process blob commitment', async function () {
const commitment = ethers.utils.formatBytes32String('test_blob');
await expect(handler.processBlob(commitment))
.to.emit(handler, 'BlobProcessed')
.withArgs(commitment);
const blobData = await handler.processedBlobs(commitment);
expect(blobData.commitment).to.equal(commitment);
expect(blobData.timestamp).to.be.gt(0);
});
});
EIP-4844,部署在 Dencun hard fork(2024 年 3 月 13 日)中,已经重塑了以太坊的可扩展性格局:
2. 可扩展性提升:
3. L2 采用:
4. 挑战:
EIP-4844 在可扩展性与以太坊的核心原则之间取得了平衡:
EIP-4844 是通往 full Danksharding 的 过渡步骤,它将:
使用 EIP-4844 的 Rollups 将需要进行最少的更改才能适应 full Danksharding,从而确保平稳过渡。
BLOBBASEFEE
监控 blob gas 价格。## Python: Optimize Batch Size
def optimize_batch_size(current_price, target_delay):
cost_per_byte = current_price / (128 * 1024) # 128 KB blob
optimal_size = min(
MAX_BATCH_SIZE,
max(MIN_BATCH_SIZE, calculate_size_for_delay(target_delay, cost_per_byte))
)
return optimal_size
2. 集成:
3. 测试:
EIP-4844 是以太坊的 游戏规则改变者。通过引入携带 blob 的交易,它削减了 L2 成本,提高了吞吐量,并为 full Danksharding 奠定了基础。开发者现在可以构建更经济实惠的 dApp,用户可以享受更便宜的交易,以太坊也越来越接近其 可扩展的、去中心化的世界计算机 的愿景。
下一步是什么?
- 原文链接: medium.com/@ankitacode11...
- 登链社区 AI 助手,为大家转译优秀英文文章,如有翻译不通的地方,还请包涵~
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!