@@ -131,18 +131,23 @@ pub enum HashFunction {
131131///
132132/// Returns an error if block encoding fails
133133pub fn encode_block (
134- block_hdr_cbor : EncodedBlockHeader , block_data : & EncodedBlockData ,
135- validator_keys : & ValidatorKeys , hasher : & HashFunction ,
134+ block_hdr : EncodedBlockHeader , block_data : & EncodedBlockData , validator_keys : & ValidatorKeys ,
135+ hasher : & HashFunction ,
136136) -> anyhow:: Result < EncodedBlock > {
137+ // Ensure block header is cbor encoded
138+ let binding = block_hdr. 0 . clone ( ) ;
139+ let mut block_hdr_cbor_encoding_check = minicbor:: Decoder :: new ( & binding) ;
140+ let _ = block_hdr_cbor_encoding_check. bytes ( ) ?;
141+
137142 // Enforce block data to be cbor encoded in the form of CBOR byte strings
138143 // which are just (ordered) series of bytes without further interpretation
139144 let binding = block_data. 0 . clone ( ) ;
140145 let mut block_data_cbor_encoding_check = minicbor:: Decoder :: new ( & binding) ;
141146 let _ = block_data_cbor_encoding_check. bytes ( ) ?;
142147
143148 let hashed_block_header = match hasher {
144- HashFunction :: Blake3 => blake3 ( & block_hdr_cbor . 0 ) ?. to_vec ( ) ,
145- HashFunction :: Blake2b => blake2b_512 ( & block_hdr_cbor . 0 ) ?. to_vec ( ) ,
149+ HashFunction :: Blake3 => blake3 ( & block_hdr . 0 ) ?. to_vec ( ) ,
150+ HashFunction :: Blake2b => blake2b_512 ( & block_hdr . 0 ) ?. to_vec ( ) ,
146151 } ;
147152
148153 // validator_signature MUST be a signature of the hashed block_header bytes
@@ -173,7 +178,7 @@ pub fn encode_block(
173178
174179 let block_data_with_sigs = encoder. writer ( ) . clone ( ) ;
175180 // block hdr + block data + sigs
176- let encoded_block = [ block_hdr_cbor . 0 , block_data_with_sigs] . concat ( ) ;
181+ let encoded_block = [ block_hdr . 0 , block_data_with_sigs] . concat ( ) ;
177182
178183 Ok ( encoded_block)
179184}
0 commit comments