@@ -220,9 +220,10 @@ impl<F: Field> SubCircuit<F> for SigCircuit<F> {
220
220
type Config = SigCircuitConfig < F > ;
221
221
222
222
fn new_from_block ( block : & crate :: witness:: Block < F > ) -> Self {
223
+ assert ! ( block. circuits_params. max_txs <= MAX_NUM_SIG ) ;
224
+
223
225
SigCircuit {
224
- // TODO: seperate max_verif with max_txs?
225
- max_verif : block. circuits_params . max_txs ,
226
+ max_verif : MAX_NUM_SIG ,
226
227
signatures : block. get_sign_data ( true ) ,
227
228
_marker : Default :: default ( ) ,
228
229
}
@@ -257,13 +258,22 @@ impl<F: Field> SubCircuit<F> for SigCircuit<F> {
257
258
fn min_num_rows_block ( block : & crate :: witness:: Block < F > ) -> ( usize , usize ) {
258
259
let row_num = Self :: min_num_rows ( ) ;
259
260
260
- let tx_count = block. txs . len ( ) ;
261
- let max_tx_count = block. circuits_params . max_txs ;
261
+ let ecdsa_verif_count = block
262
+ . txs
263
+ . iter ( )
264
+ . filter ( |tx| !tx. tx_type . is_l1_msg ( ) )
265
+ . count ( )
266
+ + block. precompile_events . get_ecrecover_events ( ) . len ( ) ;
267
+ // Reserve one ecdsa verification for padding tx such that the bad case in which some tx
268
+ // calls MAX_NUM_SIG - 1 ecrecover precompile won't happen. If that case happens, the sig
269
+ // circuit won't have more space for the padding tx's ECDSA verification. Then the
270
+ // prover won't be able to produce any valid proof.
271
+ let max_num_verif = MAX_NUM_SIG - 1 ;
262
272
263
273
// Instead of showing actual minimum row usage,
264
274
// halo2-lib based circuits use min_row_num to represent a percentage of total-used capacity
265
275
// This functionality allows l2geth to decide if additional ops can be added.
266
- let min_row_num = ( row_num / max_tx_count ) * tx_count ;
276
+ let min_row_num = ( row_num / max_num_verif ) * ecdsa_verif_count ;
267
277
268
278
( min_row_num, row_num)
269
279
}
0 commit comments