https://eips.ethereum.org/EIPS/eip-4844
BLOB_TX_TYPE
: 0x03BYTES_PER_FIELD_ELEMENT
: 32 2^5FIELD_ELEMENTS_PER_BLOB
: 4096 2^12there 2^17 bytes per blob, 131071 bytes
BLS_MODULUS
: 52435875175126190479447740508185965837690552500527637822603658699938581184513order of BLS12-381's \mathbb{G_1} and \mathbb{G_2}
VERSIONED_HASH_VERSION_KZG
: 0x01POINT_EVALUATION_PRECOMPILE_ADDRESS
: 0x0ABLS12-381 的验证 pair 的预编译合约地址
POINT_EVALUATION_PRECOMPILE_GAS
: 50000MAX_BLOB_GAS_PER_BLOCK
: 786432TARGET_BLOB_GAS_PER_BLOCK
: 393216 = 786432/2MIN_BLOB_GASPRICE
: 1BLOB_GASPRICE_UPDATE_FRACTION
: 分母,计算预估 gas 的GAS_PER_BLOB
: 2^17HASH_OPCODE_BYTE
: 0x49,blobhash 调用的操纵码HASH_OPCODE_GAS
: 3MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS
: 4096Blob
: [u8; 2^17]VersionedHash
: Bytes32KZGCommitment
: Bytes48KZGProof
: Bytes48
def kzg_to_versioned_hash(commitment: KZGCommitment) -> VersionedHash:
return VERSIONED_HASH_VERSION_KZG + sha256(commitment)[1:]
[chain_id, nonce, max_priority_fee_per_gas, max_fee_per_gas, gas_limit, to, value, data, access_list, max_fee_per_blob_gas, blob_versioned_hashes, y_parity, r, s]
to
can't be nil
max_fee_per_blob_gas
: u256blob_versioned_hashes
: vec[kzg_to_versioned_hash]keccak256(BLOB_TX_TYPE || rlp([chain_id, nonce, max_priority_fee_per_gas, max_fee_per_gas, gas_limit, to, value, data, access_list, max_fee_per_blob_gas, blob_versioned_hashes])).
blob_gas_used
excess_blob_gas
def calc_data_fee(header: Header, tx: Transaction) -> int:
return get_total_blob_gas(tx) * get_blob_gasprice(header)
def get_total_blob_gas(tx: Transaction) -> int:
return GAS_PER_BLOB * len(tx.blob_versioned_hashes)
# MIN_BLOB_GASPRICE * e ** (excess_blob_gas / BLOB_GASPRICE_UPDATE_FRACTION)
def get_blob_gasprice(header: Header) -> int:
return fake_exponential(
MIN_BLOB_GASPRICE,
header.excess_blob_gas,
BLOB_GASPRICE_UPDATE_FRACTION
)
BLOBHASH
的 opcode 是: HASH_OPCODE_BYTE输入index,返回 tx.blob_versioned_hashes[index],超出返回 全0
def point_evaluation_precompile(input: Bytes) -> Bytes:
"""
Verify p(z) = y given commitment that corresponds to the polynomial p(x) and a KZG proof.
Also verify that the provided commitment matches the provided versioned_hash.
"""
# The data is encoded as follows: versioned_hash | z | y | commitment | proof | with z and y being padded 32 byte big endian values
assert len(input) == 192
versioned_hash = input[:32]
z = input[32:64]
y = input[64:96]
commitment = input[96:144]
proof = input[144:192]
# Verify commitment matches versioned_hash
assert kzg_to_versioned_hash(commitment) == versioned_hash
# Verify KZG proof with z and y in big endian format
assert verify_kzg_proof(commitment, z, y, proof)
# Return FIELD_ELEMENTS_PER_BLOB and BLS_MODULUS as padded 32 byte big endian values
return Bytes(U256(FIELD_ELEMENTS_PER_BLOB).to_be_bytes32() + U256(BLS_MODULUS).to_be_bytes32())