@@ -26,13 +26,14 @@ use itertools::{Itertools, chain, enumerate, izip};
2626use multilinear_extensions:: {
2727 Expression , WitnessId , fmt,
2828 mle:: { ArcMultilinearExtension , IntoMLEs , MultilinearExtension } ,
29+ util:: ceil_log2,
2930 utils:: { eval_by_expr, eval_by_expr_with_fixed, eval_by_expr_with_instance} ,
3031} ;
3132use p3:: field:: { Field , FieldAlgebra } ;
3233use rand:: thread_rng;
3334use std:: {
3435 cmp:: max,
35- collections:: { BTreeSet , HashMap , HashSet } ,
36+ collections:: { BTreeMap , BTreeSet , HashMap , HashSet } ,
3637 fmt:: Debug ,
3738 fs:: File ,
3839 hash:: Hash ,
@@ -978,6 +979,16 @@ Hints:
978979 let mut fixed_mles = HashMap :: new ( ) ;
979980 let mut num_instances = HashMap :: new ( ) ;
980981
982+ let circuit_index_fixed_num_instances: BTreeMap < String , usize > = fixed_trace
983+ . circuit_fixed_traces
984+ . iter ( )
985+ . map ( |( circuit_name, rmm) | {
986+ (
987+ circuit_name. clone ( ) ,
988+ rmm. as_ref ( ) . map ( |rmm| rmm. num_instances ( ) ) . unwrap_or ( 0 ) ,
989+ )
990+ } )
991+ . collect ( ) ;
981992 let mut lkm_tables = LkMultiplicityRaw :: < E > :: default ( ) ;
982993 let mut lkm_opcodes = LkMultiplicityRaw :: < E > :: default ( ) ;
983994
@@ -992,11 +1003,20 @@ Hints:
9921003 . get_opcode_witness ( circuit_name)
9931004 . or_else ( || witnesses. get_table_witness ( circuit_name) )
9941005 . unwrap_or_else ( || panic ! ( "witness for {} should not be None" , circuit_name) ) ;
995- let num_rows = witness. num_instances ( ) ;
1006+ let num_rows = if witness. num_instances ( ) > 0 {
1007+ witness. num_instances ( )
1008+ } else if structural_witness. num_instances ( ) > 0 {
1009+ structural_witness. num_instances ( )
1010+ } else if composed_cs. is_static_circuit ( ) {
1011+ circuit_index_fixed_num_instances
1012+ . get ( circuit_name)
1013+ . copied ( )
1014+ . unwrap_or ( 0 )
1015+ } else {
1016+ 0
1017+ } ;
9961018
997- if witness. num_instances ( ) + structural_witness. num_instances ( ) == 0
998- && ( !composed_cs. is_static_circuit ( ) )
999- {
1019+ if num_rows == 0 {
10001020 wit_mles. insert ( circuit_name. clone ( ) , vec ! [ ] ) ;
10011021 structural_wit_mles. insert ( circuit_name. clone ( ) , vec ! [ ] ) ;
10021022 fixed_mles. insert ( circuit_name. clone ( ) , vec ! [ ] ) ;
@@ -1136,15 +1156,14 @@ Hints:
11361156 if * num_rows == 0 {
11371157 continue ;
11381158 }
1139-
11401159 let w_selector: ArcMultilinearExtension <_> =
11411160 if let Some ( w_selector) = & cs. w_selector {
11421161 structural_witness[ w_selector. selector_expr( ) . id( ) ] . clone( )
11431162 } else {
11441163 let mut selector = vec![ E :: BaseField :: ONE ; * num_rows] ;
1145- selector. resize( witness [ 0 ] . evaluations ( ) . len ( ) , E :: BaseField :: ZERO ) ;
1164+ selector. resize( next_pow2_instance_padding ( * num_rows ) , E :: BaseField :: ZERO ) ;
11461165 MultilinearExtension :: from_evaluation_vec_smart(
1147- witness [ 0 ] . num_vars ( ) ,
1166+ ceil_log2 ( next_pow2_instance_padding ( * num_rows ) ) ,
11481167 selector,
11491168 )
11501169 . into( )
@@ -1241,9 +1260,9 @@ Hints:
12411260 structural_witness[ r_selector. selector_expr( ) . id( ) ] . clone( )
12421261 } else {
12431262 let mut selector = vec![ E :: BaseField :: ONE ; * num_rows] ;
1244- selector. resize( witness [ 0 ] . evaluations ( ) . len ( ) , E :: BaseField :: ZERO ) ;
1263+ selector. resize( next_pow2_instance_padding ( * num_rows ) , E :: BaseField :: ZERO ) ;
12451264 MultilinearExtension :: from_evaluation_vec_smart(
1246- witness [ 0 ] . num_vars ( ) ,
1265+ ceil_log2 ( next_pow2_instance_padding ( * num_rows ) ) ,
12471266 selector,
12481267 )
12491268 . into( )
0 commit comments