@@ -122,21 +122,14 @@ pub(crate) fn prepare_sidecar_with_proof(
122122 state_diff : & [ Vec < u8 > ] ,
123123 trusted_setup : & KzgSettings ,
124124) -> EyreResult < BlobTransactionSidecarVariant > {
125- let mut sidecar_blobs = vec ! [ ] ;
126- let mut sidecar_commitments = vec ! [ ] ;
125+ // Prepare Blobs and Commitments from State Diff
126+ let ( sidecar_blobs , sidecar_commitments) = get_blobs_and_commitments ( state_diff , trusted_setup ) ? ;
127127 let mut sidecar_proofs = vec ! [ ] ;
128128
129- for blob_data in state_diff {
129+ for ( blob_data, commitment ) in state_diff. iter ( ) . zip ( & sidecar_commitments ) {
130130 let fixed_size_blob: [ u8 ; BYTES_PER_BLOB ] = blob_data. as_slice ( ) . try_into ( ) ?;
131-
132131 let blob = Blob :: new ( fixed_size_blob) ;
133-
134- let commitment = trusted_setup. blob_to_kzg_commitment ( & blob) ?;
135-
136132 let proof = trusted_setup. compute_blob_kzg_proof ( & blob, & commitment. to_bytes ( ) ) ?;
137-
138- sidecar_blobs. push ( FixedBytes :: new ( fixed_size_blob) ) ;
139- sidecar_commitments. push ( FixedBytes :: new ( commitment. to_bytes ( ) . into_inner ( ) ) ) ;
140133 sidecar_proofs. push ( FixedBytes :: new ( proof. to_bytes ( ) . into_inner ( ) ) ) ;
141134 }
142135
@@ -148,25 +141,18 @@ pub(crate) fn prepare_sidecar_with_proof(
148141}
149142
150143// Function to prepare sidecar for EIP 7594 transaction
151- #[ allow( clippy:: type_complexity) ]
152144pub fn prepare_sidecar_with_cells (
153145 state_diff : & [ Vec < u8 > ] ,
154146 trusted_setup : & KzgSettings ,
155147) -> EyreResult < BlobTransactionSidecarVariant > {
156- let mut sidecar_blobs = vec ! [ ] ;
157- let mut sidecar_commitments = vec ! [ ] ;
148+ // Prepare Blobs and Commitments from State Diff
149+ let ( sidecar_blobs , sidecar_commitments) = get_blobs_and_commitments ( state_diff , trusted_setup ) ? ;
158150 let mut all_cell_proofs = vec ! [ ] ; // Vec of Vec because each blob has CELLS_PER_EXT_BLOB proofs
159151
160152 for blob_data in state_diff {
161153 let fixed_size_blob: [ u8 ; BYTES_PER_BLOB ] = blob_data. as_slice ( ) . try_into ( ) ?;
162-
163154 let blob = Blob :: new ( fixed_size_blob) ;
164155
165- let commitment = trusted_setup. blob_to_kzg_commitment ( & blob) ?;
166-
167- sidecar_blobs. push ( FixedBytes :: new ( fixed_size_blob) ) ;
168- sidecar_commitments. push ( FixedBytes :: new ( commitment. to_bytes ( ) . into_inner ( ) ) ) ;
169-
170156 // Compute cells and KZG proofs for this blob
171157 // This returns ALL cell proofs (including extension cells)
172158 let ( _, proofs) = trusted_setup. compute_cells_and_kzg_proofs ( & blob) ?;
@@ -188,6 +174,30 @@ pub fn prepare_sidecar_with_cells(
188174 ) ) )
189175}
190176
177+ pub fn get_blobs_and_commitments (
178+ state_diff : & [ Vec < u8 > ] ,
179+ trusted_setup : & KzgSettings ,
180+ ) -> EyreResult < ( ( Vec < FixedBytes < BYTES_PER_BLOB > > , Vec < FixedBytes < 48 > > ) ) > {
181+ let mut sidecar_blobs = vec ! [ ] ;
182+ let mut sidecar_commitments = vec ! [ ] ;
183+
184+ for blob_data in state_diff {
185+ let fixed_size_blob: [ u8 ; BYTES_PER_BLOB ] = blob_data. as_slice ( ) . try_into ( ) ?;
186+
187+ let blob = Blob :: new ( fixed_size_blob) ;
188+
189+ let commitment = trusted_setup. blob_to_kzg_commitment ( & blob) ?;
190+
191+ sidecar_blobs. push ( FixedBytes :: new ( fixed_size_blob) ) ;
192+ sidecar_commitments. push ( FixedBytes :: new ( commitment. to_bytes ( ) . into_inner ( ) ) ) ;
193+ }
194+
195+ assert_eq ! ( state_diff. len( ) , sidecar_blobs. len( ) ) ;
196+ assert_eq ! ( state_diff. len( ) , sidecar_commitments. len( ) ) ;
197+
198+ Ok ( ( sidecar_blobs, sidecar_commitments) )
199+ }
200+
191201/// Convert hex string data into Vec<u8>
192202pub fn hex_string_to_u8_vec ( hex_str : & str ) -> color_eyre:: Result < Vec < u8 > > {
193203 // Remove any spaces or non-hex characters from the input string
0 commit comments