11use crate :: BlockProcessingError ;
2- use eth2_hashing:: { hash , hash_fixed} ;
2+ use eth2_hashing:: hash_fixed;
33use itertools:: { EitherOrBoth , Itertools } ;
44use ssz:: Decode ;
55use ssz_types:: VariableList ;
6- use std:: slice:: Iter ;
7- use std:: vec:: IntoIter ;
86use types:: consts:: eip4844:: { BLOB_TX_TYPE , VERSIONED_HASH_VERSION_KZG } ;
97use types:: {
108 AbstractExecPayload , BeaconBlockBodyRef , EthSpec , ExecPayload , FullPayload , FullPayloadRef ,
@@ -47,9 +45,21 @@ pub fn verify_kzg_commitments_against_transactions<T: EthSpec>(
4745 // Need to use `itertools::zip_longest` here because just zipping hides if one iter is shorter
4846 // and `itertools::zip_eq` panics.
4947 . zip_longest ( kzg_commitments. into_iter ( ) )
50- . map ( |next| match next {
51- EitherOrBoth :: Both ( hash, commitmnet) => Ok ( ( hash?, commitmnet) ) ,
52- _ => Err ( BlockProcessingError :: BlobVersionHashMismatch ) ,
48+ . enumerate ( )
49+ . map ( |( index, next) | match next {
50+ EitherOrBoth :: Both ( hash, commitment) => Ok ( ( hash?, commitment) ) ,
51+ // The number of versioned hashes from the blob transactions exceeds the number of
52+ // commitments in the block.
53+ EitherOrBoth :: Left ( _) => Err ( BlockProcessingError :: BlobNumCommitmentsMismatch {
54+ commitments_processed_in_block : index,
55+ commitments_processed_in_transactions : index + 1 ,
56+ } ) ,
57+ // The number of commitments in the block exceeds the number of versioned hashes
58+ // in the blob transactions.
59+ EitherOrBoth :: Right ( _) => Err ( BlockProcessingError :: BlobNumCommitmentsMismatch {
60+ commitments_processed_in_block : index + 1 ,
61+ commitments_processed_in_transactions : index,
62+ } ) ,
5363 } ) ;
5464
5565 itertools:: process_results ( zipped_iter, |mut iter| {
@@ -60,6 +70,7 @@ pub fn verify_kzg_commitments_against_transactions<T: EthSpec>(
6070 } ) ?
6171}
6272
73+ /// Only transactions of type `BLOB_TX_TYPE` should be passed into this function.
6374fn tx_peek_blob_versioned_hashes < T : EthSpec > (
6475 opaque_tx : & Transaction < T :: MaxBytesPerTransaction > ,
6576) -> Result <
@@ -90,12 +101,13 @@ fn tx_peek_blob_versioned_hashes<T: EthSpec>(
90101 let num_hashes = ( tx_len - blob_versioned_hashes_offset as usize ) / 32 ;
91102
92103 Ok ( ( 0 ..num_hashes) . into_iter ( ) . map ( move |i| {
93- let bytes = opaque_tx. get ( i..i + 32 ) . ok_or (
94- BlockProcessingError :: BlobVersionHashIndexOutOfBounds {
104+ let next_version_hash_index = blob_versioned_hashes_offset as usize + ( i * 32 ) ;
105+ let bytes = opaque_tx
106+ . get ( next_version_hash_index..next_version_hash_index + 32 )
107+ . ok_or ( BlockProcessingError :: BlobVersionHashIndexOutOfBounds {
95108 length : tx_len,
96- index : i + 32 ,
97- } ,
98- ) ?;
109+ index : next_version_hash_index as usize + 32 ,
110+ } ) ?;
99111 Ok ( VersionedHash :: from_slice ( bytes) )
100112 } ) )
101113}
0 commit comments