# eip-4844 https://eips.ethereum.org/EIPS/eip-4844 https://www.eip4844.com/ ## Parameters - `BLOB_TX_TYPE`: 0x03 - `BYTES_PER_FIELD_ELEMENT`: 32 2^5 - `FIELD_ELEMENTS_PER_BLOB`: 4096 2^12 there 2^17 bytes per blob, 131071 bytes - `BLS_MODULUS`: 52435875175126190479447740508185965837690552500527637822603658699938581184513 order of BLS12-381's \mathbb{G_1} and \mathbb{G_2} - `VERSIONED_HASH_VERSION_KZG`: 0x01 - `POINT_EVALUATION_PRECOMPILE_ADDRESS`: 0x0A BLS12-381 的验证 pair 的预编译合约地址 - `POINT_EVALUATION_PRECOMPILE_GAS`: 50000 - `MAX_BLOB_GAS_PER_BLOCK`: 786432 - `TARGET_BLOB_GAS_PER_BLOCK`: 393216 = 786432/2 - `MIN_BLOB_GASPRICE`: 1 - `BLOB_GASPRICE_UPDATE_FRACTION`: 分母,计算预估 gas 的 - `GAS_PER_BLOB`: 2^17 - `HASH_OPCODE_BYTE`: 0x49,blobhash 调用的操纵码 - `HASH_OPCODE_GAS`: 3 - `MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS`: 4096 ## Types aliases - `Blob`: [u8; 2^17] - `VersionedHash`: Bytes32 - `KZGCommitment`: Bytes48 - `KZGProof`: Bytes48 ## Cryptographic Helpers ```python= def kzg_to_versioned_hash(commitment: KZGCommitment) -> VersionedHash: return VERSIONED_HASH_VERSION_KZG + sha256(commitment)[1:] ``` ## Blob transaction ``` [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`: u256 - `blob_versioned_hashes`: vec[kzg_to_versioned_hash] ## signature ``` 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])). ``` ## Block Header - `blob_gas_used` - `excess_blob_gas` ## Gas accounting ```python= 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 ) ``` ## Opcode to get versioned hashes - `BLOBHASH` 的 opcode 是: HASH_OPCODE_BYTE 输入index,返回 tx.blob_versioned_hashes[index],超出返回 全0 # Point evaluation precompile ```python= 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()) ``` ##