@@ -139,10 +139,6 @@ pub trait CircuitsParams: Debug + Copy {
139
139
fn set_total_chunk ( & mut self , total_chunks : usize ) ;
140
140
/// Return the maximun Rw
141
141
fn max_rws ( & self ) -> Option < usize > ;
142
- /// Return whether the parameters are dynamic.
143
- /// If true, the `total_chunks` and `max_rws` will serve as a target value for chunking
144
- /// and [`FixedCParams`] will be recomputed from each generated chunk witness.
145
- fn dynamic_update ( & self ) -> bool ;
146
142
}
147
143
148
144
impl CircuitsParams for FixedCParams {
@@ -155,9 +151,6 @@ impl CircuitsParams for FixedCParams {
155
151
fn max_rws ( & self ) -> Option < usize > {
156
152
Some ( self . max_rws )
157
153
}
158
- fn dynamic_update ( & self ) -> bool {
159
- false
160
- }
161
154
}
162
155
impl CircuitsParams for DynamicCParams {
163
156
fn total_chunks ( & self ) -> usize {
@@ -169,9 +162,6 @@ impl CircuitsParams for DynamicCParams {
169
162
fn max_rws ( & self ) -> Option < usize > {
170
163
None
171
164
}
172
- fn dynamic_update ( & self ) -> bool {
173
- true
174
- }
175
165
}
176
166
177
167
impl Default for DynamicCParams {
@@ -257,7 +247,7 @@ impl<'a, C: CircuitsParams> CircuitInputBuilder<C> {
257
247
block,
258
248
chunks,
259
249
block_ctx : BlockContext :: new ( ) ,
260
- chunk_ctx : ChunkContext :: new ( total_chunks, params . dynamic_update ( ) ) ,
250
+ chunk_ctx : ChunkContext :: new ( total_chunks) ,
261
251
circuits_params : params,
262
252
feature_config,
263
253
}
@@ -354,12 +344,12 @@ impl<'a, C: CircuitsParams> CircuitInputBuilder<C> {
354
344
return Ok ( ( ) ) ;
355
345
}
356
346
let is_last_tx = tx_ctx. is_last_tx ( ) ;
357
- let dynamic = self . chunk_ctx . dynamic_update ;
347
+ let is_dynamic_max_row = self . circuits_params . max_rws ( ) . is_none ( ) ;
358
348
let mut gen_chunk =
359
349
// No lookahead, if chunk_rws exceed max just chunk then update param
360
- ( dynamic && self . chunk_rws ( ) > self . circuits_params . max_rws ( ) . unwrap_or_default ( ) - self . rws_reserve ( ) )
350
+ ( is_dynamic_max_row && self . chunk_rws ( ) > self . circuits_params . max_rws ( ) . unwrap_or_default ( ) . saturating_sub ( self . rws_reserve ( ) ) )
361
351
// Lookahead, chunk_rws should never exceed, never update param
362
- || ( !dynamic && self . chunk_rws ( ) + RW_BUFFER >= self . circuits_params . max_rws ( ) . unwrap_or_default ( ) - self . rws_reserve ( ) ) ;
352
+ || ( !is_dynamic_max_row && self . chunk_rws ( ) + RW_BUFFER >= self . circuits_params . max_rws ( ) . unwrap_or_default ( ) . saturating_sub ( self . rws_reserve ( ) ) ) ;
363
353
364
354
if gen_chunk {
365
355
// Optain the first op of the next GethExecStep, for fixed case also lookahead
@@ -382,10 +372,14 @@ impl<'a, C: CircuitsParams> CircuitInputBuilder<C> {
382
372
// Check again, 1) if dynamic keep chunking 2) if fixed chunk when lookahead exceed
383
373
// 3) gen chunk steps there're more chunks after
384
374
gen_chunk = !self . chunk_ctx . is_last_chunk ( )
385
- && ( dynamic
375
+ && ( is_dynamic_max_row
386
376
|| cib. chunk_rws ( )
387
- > self . circuits_params . max_rws ( ) . unwrap_or_default ( ) - cib. rws_reserve ( ) ) ;
388
- if dynamic {
377
+ > self
378
+ . circuits_params
379
+ . max_rws ( )
380
+ . unwrap_or_default ( )
381
+ . saturating_sub ( cib. rws_reserve ( ) ) ) ;
382
+ if is_dynamic_max_row {
389
383
self . cur_chunk_mut ( ) . fixed_param = self . compute_param ( & self . block . eth_block ) ;
390
384
}
391
385
if gen_chunk {
@@ -687,8 +681,9 @@ impl CircuitInputBuilder<FixedCParams> {
687
681
println ! ( "--------------{:?}" , self . circuits_params) ;
688
682
// accumulates gas across all txs in the block
689
683
let last_call = self . begin_handle_block ( eth_block, geth_traces) ?;
684
+
690
685
// At the last chunk fixed param also need to be updated
691
- if self . chunk_ctx . dynamic_update {
686
+ if self . circuits_params . max_rws ( ) . is_none ( ) {
692
687
self . cur_chunk_mut ( ) . fixed_param = self . compute_param ( & self . block . eth_block ) ;
693
688
} else {
694
689
self . cur_chunk_mut ( ) . fixed_param = self . circuits_params ;
@@ -918,7 +913,7 @@ impl CircuitInputBuilder<DynamicCParams> {
918
913
block : self . block ,
919
914
chunks : self . chunks ,
920
915
block_ctx : self . block_ctx ,
921
- chunk_ctx : ChunkContext :: new ( total_chunks, true ) ,
916
+ chunk_ctx : ChunkContext :: new ( total_chunks) ,
922
917
circuits_params : target_params,
923
918
feature_config : self . feature_config ,
924
919
} ;
0 commit comments