feat: add kzg_to_versioned_hash (#4085)

Co-authored-by: Dan Cline <6798349+Rjected@users.noreply.github.com>
This commit is contained in:
PatStiles
2023-08-10 12:56:03 -05:00
committed by GitHub
parent 2338720b68
commit c412f3935d
7 changed files with 53 additions and 36 deletions

View File

@ -1,11 +1,11 @@
//! Collection of methods for block validation.
use reth_interfaces::{consensus::ConsensusError, Result as RethResult};
use reth_primitives::{
blobfee::calculate_excess_blob_gas,
constants::{
self,
eip4844::{DATA_GAS_PER_BLOB, MAX_DATA_GAS_PER_BLOCK},
},
eip4844::calculate_excess_blob_gas,
BlockNumber, ChainSpec, Hardfork, Header, InvalidTransactionError, SealedBlock, SealedHeader,
Transaction, TransactionSignedEcRecovered, TxEip1559, TxEip2930, TxEip4844, TxLegacy,
};

View File

@ -61,6 +61,7 @@ once_cell = "1.17.0"
zstd = { version = "0.12", features = ["experimental"] }
paste = "1.0"
tempfile = "3.3"
sha2 = "0.10.7"
# proof related
triehash = "0.8"

View File

@ -37,3 +37,6 @@ pub static KZG_TRUSTED_SETUP: Lazy<Arc<KzgSettings>> = Lazy::new(|| {
file.write_all(TRUSTED_SETUP_RAW.as_bytes()).unwrap();
Arc::new(KzgSettings::load_trusted_setup_file(file.path().into()).unwrap())
});
/// Commitment version of a KZG commitment
pub const VERSIONED_HASH_VERSION_KZG: u8 = 0x01;

View File

@ -1,6 +1,19 @@
//! Helpers for working with EIP-4844 blob fee
use crate::{
constants::eip4844::{TARGET_DATA_GAS_PER_BLOCK, VERSIONED_HASH_VERSION_KZG},
kzg::KzgCommitment,
H256,
};
use sha2::{Digest, Sha256};
use crate::constants::eip4844::TARGET_DATA_GAS_PER_BLOCK;
/// Calculates the versioned hash for a KzgCommitment
///
/// Specified in [EIP-4844](https://eips.ethereum.org/EIPS/eip-4844#header-extension)
pub fn kzg_to_versioned_hash(commitment: KzgCommitment) -> H256 {
let mut res = Sha256::digest(commitment.as_slice());
res[0] = VERSIONED_HASH_VERSION_KZG;
H256::from_slice(&res)
}
/// Calculates the excess data gas for the next block, after applying the current set of blobs on
/// top of the excess data gas.

View File

@ -1,6 +1,6 @@
use crate::{
basefee::calculate_next_block_base_fee,
blobfee::calculate_excess_blob_gas,
eip4844::calculate_excess_blob_gas,
keccak256,
proofs::{EMPTY_LIST_HASH, EMPTY_ROOT},
BaseFeeParams, BlockBodyRoots, BlockHash, BlockNumHash, BlockNumber, Bloom, Bytes, H160, H256,

View File

@ -23,13 +23,13 @@ pub mod abi;
mod account;
pub mod basefee;
mod bits;
pub mod blobfee;
mod block;
pub mod bloom;
mod chain;
mod compression;
pub mod constants;
pub mod contract;
pub mod eip4844;
mod forkid;
pub mod fs;
mod genesis;