@@ -145,9 +145,47 @@ pub enum OsStateDiff {
145
145
PartialCommitment ( PartialCommitmentOsStateDiff ) ,
146
146
}
147
147
148
+ pub ( crate ) type KzgCommitment = ( Felt , Felt ) ;
149
+ pub ( crate ) type PointEvaluation = ( Felt , Felt ) ;
150
+
151
+ #[ cfg_attr( feature = "deserialize" , derive( serde:: Deserialize , serde:: Serialize ) ) ]
152
+ #[ derive( Debug , PartialEq ) ]
153
+ pub ( crate ) struct OsKzgCommitmentInfo {
154
+ z : Felt ,
155
+ n_blobs : usize ,
156
+ commitments : Vec < KzgCommitment > ,
157
+ evals : Vec < PointEvaluation > ,
158
+ }
159
+
160
+ impl TryFromOutputIter for OsKzgCommitmentInfo {
161
+ fn try_from_output_iter < It : Iterator < Item = Felt > > (
162
+ output_iter : & mut It ,
163
+ ) -> Result < Self , OsOutputError > {
164
+ let kzg_z = wrap_missing ( output_iter. next ( ) , "kzg_z" ) ?;
165
+ let n_blobs: usize = wrap_missing_as ( output_iter. next ( ) , "n_blobs" ) ?;
166
+
167
+ let mut commitments = Vec :: with_capacity ( n_blobs) ;
168
+ for i in 0 ..n_blobs {
169
+ // Each commitment is two felts.
170
+ let low = wrap_missing ( output_iter. next ( ) , & format ! ( "kzg_commitment_low_{i}" ) ) ?;
171
+ let high = wrap_missing ( output_iter. next ( ) , & format ! ( "kzg_commitment_high_{i}" ) ) ?;
172
+ commitments. push ( ( low, high) ) ;
173
+ }
174
+
175
+ let mut evals = Vec :: with_capacity ( n_blobs) ;
176
+ for i in 0 ..n_blobs {
177
+ // Each evaluation is two felts.
178
+ let low = wrap_missing ( output_iter. next ( ) , & format ! ( "point_evaluation_low_{i}" ) ) ?;
179
+ let high = wrap_missing ( output_iter. next ( ) , & format ! ( "point_evaluation_high_{i}" ) ) ?;
180
+ evals. push ( ( low, high) ) ;
181
+ }
182
+ Ok ( Self { z : kzg_z, n_blobs, commitments, evals } )
183
+ }
184
+ }
185
+
148
186
struct OutputIterParsedData {
149
187
common_os_output : CommonOsOutput ,
150
- kzg_commitment_info : Option < Vec < Felt > > ,
188
+ kzg_commitment_info : Option < OsKzgCommitmentInfo > ,
151
189
full_output : bool ,
152
190
}
153
191
@@ -168,11 +206,7 @@ impl TryFromOutputIter for OutputIterParsedData {
168
206
let full_output = wrap_missing_as_bool ( output_iter. next ( ) , "full_output" ) ?;
169
207
170
208
let kzg_commitment_info = if use_kzg_da {
171
- // Read KZG data into a vec.
172
- let kzg_z = wrap_missing ( output_iter. next ( ) , "kzg_z" ) ?;
173
- let n_blobs: usize = wrap_missing_as ( output_iter. next ( ) , "n_blobs" ) ?;
174
- let commitments = output_iter. take ( 2 * 2 * n_blobs) ;
175
- Some ( [ kzg_z, n_blobs. into ( ) ] . into_iter ( ) . chain ( commitments) . collect :: < Vec < _ > > ( ) )
209
+ Some ( OsKzgCommitmentInfo :: try_from_output_iter ( output_iter) ?)
176
210
} else {
177
211
None
178
212
} ;
0 commit comments