@@ -48,10 +48,10 @@ use crate::{
48
48
49
49
use self :: copy_gadgets:: {
50
50
constrain_address, constrain_bytes_left, constrain_event_rlc_acc, constrain_first_last,
51
- constrain_forward_parameters, constrain_is_memory_copy , constrain_is_pad , constrain_mask ,
52
- constrain_masked_value , constrain_must_terminate , constrain_non_pad_non_mask ,
53
- constrain_rw_counter, constrain_rw_word_complete, constrain_tag, constrain_value_rlc ,
54
- constrain_word_index, constrain_word_rlc,
51
+ constrain_forward_parameters, constrain_is_first_bytecode_table , constrain_is_memory_copy ,
52
+ constrain_is_pad , constrain_mask , constrain_masked_value , constrain_must_terminate ,
53
+ constrain_non_pad_non_mask , constrain_rw_counter, constrain_rw_word_complete, constrain_tag,
54
+ constrain_value_rlc , constrain_word_index, constrain_word_rlc,
55
55
} ;
56
56
57
57
/// The current row.
@@ -122,13 +122,19 @@ pub struct CopyCircuitConfig<F> {
122
122
pub is_word_end : IsEqualConfig < F > ,
123
123
/// non pad and non mask witness to reduce the degree of lookups.
124
124
pub non_pad_non_mask : Column < Advice > ,
125
+ #[ cfg( feature = "dual-bytecode" ) ]
126
+ /// Whether the bytecode is belong to the first bytecode sub circuit .
127
+ pub is_first_bytecode_table : Column < Advice > ,
125
128
// External tables
126
129
/// TxTable
127
130
pub tx_table : TxTable ,
128
131
/// RwTable
129
132
pub rw_table : RwTable ,
130
133
/// BytecodeTable
131
134
pub bytecode_table : BytecodeTable ,
135
+ #[ cfg( feature = "dual-bytecode" ) ]
136
+ /// BytecodeTable1
137
+ pub bytecode_table1 : BytecodeTable ,
132
138
}
133
139
134
140
/// Circuit configuration arguments
@@ -139,6 +145,9 @@ pub struct CopyCircuitConfigArgs<F: Field> {
139
145
pub rw_table : RwTable ,
140
146
/// BytecodeTable
141
147
pub bytecode_table : BytecodeTable ,
148
+ #[ cfg( feature = "dual-bytecode" ) ]
149
+ /// BytecodeTable1
150
+ pub bytecode_table1 : BytecodeTable ,
142
151
/// CopyTable
143
152
pub copy_table : CopyTable ,
144
153
/// q_enable
@@ -158,6 +167,8 @@ impl<F: Field> SubCircuitConfig<F> for CopyCircuitConfig<F> {
158
167
tx_table,
159
168
rw_table,
160
169
bytecode_table,
170
+ #[ cfg( feature = "dual-bytecode") ]
171
+ bytecode_table1,
161
172
copy_table,
162
173
q_enable,
163
174
challenges,
@@ -176,6 +187,8 @@ impl<F: Field> SubCircuitConfig<F> for CopyCircuitConfig<F> {
176
187
let [ is_pad, is_tx_calldata, is_bytecode, is_memory, is_memory_copy, is_tx_log, is_access_list_address, is_access_list_storage_key] =
177
188
array_init ( |_| meta. advice_column ( ) ) ;
178
189
let is_first = copy_table. is_first ;
190
+ #[ cfg( feature = "dual-bytecode" ) ]
191
+ let is_first_bytecode_table = meta. advice_column ( ) ;
179
192
let id = copy_table. id ;
180
193
let addr = copy_table. addr ;
181
194
let src_addr_end = copy_table. src_addr_end ;
@@ -193,6 +206,9 @@ impl<F: Field> SubCircuitConfig<F> for CopyCircuitConfig<F> {
193
206
tx_table. annotate_columns ( meta) ;
194
207
rw_table. annotate_columns ( meta) ;
195
208
bytecode_table. annotate_columns ( meta) ;
209
+ #[ cfg( feature = "dual-bytecode" ) ]
210
+ bytecode_table1. annotate_columns ( meta) ;
211
+
196
212
copy_table. annotate_columns ( meta) ;
197
213
198
214
let is_id_unchange = IsEqualChip :: configure_with_value_inv (
@@ -384,6 +400,9 @@ impl<F: Field> SubCircuitConfig<F> for CopyCircuitConfig<F> {
384
400
is_memory_copy,
385
401
) ;
386
402
constrain_rw_word_complete ( cb, is_last_step, is_rw_word_type. expr ( ) , is_word_end) ;
403
+
404
+ #[ cfg( feature = "dual-bytecode" ) ]
405
+ constrain_is_first_bytecode_table ( cb, meta, is_first_bytecode_table, is_last_col) ;
387
406
}
388
407
389
408
cb. gate ( meta. query_fixed ( q_enable, CURRENT ) )
@@ -444,11 +463,22 @@ impl<F: Field> SubCircuitConfig<F> for CopyCircuitConfig<F> {
444
463
. collect ( )
445
464
} ) ;
446
465
466
+ // lookup first bytecode table
447
467
meta. lookup_any ( "Bytecode lookup" , |meta| {
448
- let cond = meta. query_fixed ( q_enable, CURRENT )
468
+ #[ cfg( feature = "dual-bytecode" ) ]
469
+ let is_first_bytecode = meta. query_advice ( is_first_bytecode_table, CURRENT ) ;
470
+
471
+ let mut cond = meta. query_fixed ( q_enable, CURRENT )
449
472
* meta. query_advice ( is_bytecode, CURRENT )
450
473
* meta. query_advice ( non_pad_non_mask, CURRENT ) ;
451
474
475
+ #[ cfg( feature = "dual-bytecode" ) ]
476
+ {
477
+ cond = cond * is_first_bytecode. expr ( ) ;
478
+ }
479
+
480
+ let table_expr = bytecode_table. table_exprs_mini ( meta) ;
481
+
452
482
vec ! [
453
483
1 . expr( ) ,
454
484
meta. query_advice( id, CURRENT ) ,
@@ -457,12 +487,37 @@ impl<F: Field> SubCircuitConfig<F> for CopyCircuitConfig<F> {
457
487
meta. query_advice( value, CURRENT ) ,
458
488
]
459
489
. into_iter ( )
460
- . zip_eq ( bytecode_table . table_exprs_mini ( meta ) )
490
+ . zip_eq ( table_expr )
461
491
. map ( |( arg, table) | ( cond. clone ( ) * arg, table) )
462
492
. collect ( )
463
493
} ) ;
464
494
465
- meta. lookup_any ( "rw lookup" , |meta| {
495
+ // lookup second bytecode table
496
+ #[ cfg( feature = "dual-bytecode" ) ]
497
+ meta. lookup_any ( "Bytecode1 lookup" , |meta| {
498
+ let is_first_bytecode = meta. query_advice ( is_first_bytecode_table, CURRENT ) ;
499
+
500
+ let cond = meta. query_fixed ( q_enable, CURRENT )
501
+ * meta. query_advice ( is_bytecode, CURRENT )
502
+ * meta. query_advice ( non_pad_non_mask, CURRENT )
503
+ * ( 1 . expr ( ) - is_first_bytecode) ;
504
+
505
+ let table_expr = bytecode_table1. table_exprs_mini ( meta) ;
506
+
507
+ vec ! [
508
+ 1 . expr( ) ,
509
+ meta. query_advice( id, CURRENT ) ,
510
+ BytecodeFieldTag :: Byte . expr( ) ,
511
+ meta. query_advice( addr, CURRENT ) ,
512
+ meta. query_advice( value, CURRENT ) ,
513
+ ]
514
+ . into_iter ( )
515
+ . zip_eq ( table_expr)
516
+ . map ( |( arg, table) | ( cond. clone ( ) * arg, table) )
517
+ . collect ( )
518
+ } ) ;
519
+
520
+ meta. lookup_any ( "tx lookup for CallData" , |meta| {
466
521
let cond = meta. query_fixed ( q_enable, CURRENT )
467
522
* meta. query_advice ( is_tx_calldata, CURRENT )
468
523
* meta. query_advice ( non_pad_non_mask, CURRENT ) ;
@@ -604,9 +659,13 @@ impl<F: Field> SubCircuitConfig<F> for CopyCircuitConfig<F> {
604
659
is_src_end,
605
660
is_word_end,
606
661
non_pad_non_mask,
662
+ #[ cfg( feature = "dual-bytecode" ) ]
663
+ is_first_bytecode_table,
607
664
tx_table,
608
665
rw_table,
609
666
bytecode_table,
667
+ #[ cfg( feature = "dual-bytecode" ) ]
668
+ bytecode_table1,
610
669
}
611
670
}
612
671
}
@@ -624,12 +683,11 @@ impl<F: Field> CopyCircuitConfig<F> {
624
683
lt_word_end_chip : & IsEqualChip < F > ,
625
684
challenges : Challenges < Value < F > > ,
626
685
copy_event : & CopyEvent ,
686
+ bytecode_map : Option < & BTreeMap < Word , bool > > ,
627
687
) -> Result < ( ) , Error > {
628
- for ( step_idx, ( tag, table_row, circuit_row) ) in
629
- CopyTable :: assignments ( copy_event, challenges)
630
- . iter ( )
631
- . enumerate ( )
632
- {
688
+ let copy_rows = CopyTable :: assignments ( copy_event, challenges, bytecode_map) ;
689
+
690
+ for ( step_idx, ( tag, table_row, circuit_row) ) in copy_rows. iter ( ) . enumerate ( ) {
633
691
let is_read = step_idx % 2 == 0 ;
634
692
635
693
// Copy table assignments
@@ -670,6 +728,8 @@ impl<F: Field> CopyCircuitConfig<F> {
670
728
self . mask ,
671
729
self . front_mask ,
672
730
self . word_index ,
731
+ #[ cfg( feature = "dual-bytecode" ) ]
732
+ self . is_first_bytecode_table ,
673
733
]
674
734
. iter ( )
675
735
. zip_eq ( circuit_row)
@@ -787,6 +847,7 @@ impl<F: Field> CopyCircuitConfig<F> {
787
847
copy_events : & [ CopyEvent ] ,
788
848
max_copy_rows : usize ,
789
849
challenges : Challenges < Value < F > > ,
850
+ bytecode_map : Option < & BTreeMap < Word , bool > > ,
790
851
) -> Result < ( ) , Error > {
791
852
let copy_rows_needed = copy_events
792
853
. iter ( )
@@ -846,6 +907,7 @@ impl<F: Field> CopyCircuitConfig<F> {
846
907
& lt_word_end_chip,
847
908
challenges,
848
909
copy_event,
910
+ bytecode_map,
849
911
) ?;
850
912
log:: trace!( "offset after {}th copy event: {}" , ev_idx, offset) ;
851
913
}
@@ -909,6 +971,14 @@ impl<F: Field> CopyCircuitConfig<F> {
909
971
* offset,
910
972
|| Value :: known ( F :: zero ( ) ) ,
911
973
) ?;
974
+ #[ cfg( feature = "dual-bytecode" ) ]
975
+ // is_first_bytecode_table
976
+ region. assign_advice (
977
+ || format ! ( "assign is_first_bytecode_table {}" , * offset) ,
978
+ self . is_first_bytecode_table ,
979
+ * offset,
980
+ || Value :: known ( F :: zero ( ) ) ,
981
+ ) ?;
912
982
// is_last
913
983
region. assign_advice (
914
984
|| format ! ( "assign is_last {}" , * offset) ,
@@ -1105,17 +1175,25 @@ pub struct CopyCircuit<F: Field> {
1105
1175
pub copy_events : Vec < CopyEvent > ,
1106
1176
/// Max number of rows in copy circuit
1107
1177
pub max_copy_rows : usize ,
1178
+ /// map for <code_hash, bool> bool value indicates come from first
1179
+ /// bytecode circuit.
1180
+ pub bytecode_map : Option < BTreeMap < Word , bool > > ,
1108
1181
_marker : PhantomData < F > ,
1109
- /// Data for external lookup tables
1182
+ /// Data for external lookup tables, currently this field only used for testing.
1110
1183
pub external_data : ExternalData ,
1111
1184
}
1112
1185
1113
1186
impl < F : Field > CopyCircuit < F > {
1114
1187
/// Return a new CopyCircuit
1115
- pub fn new ( copy_events : Vec < CopyEvent > , max_copy_rows : usize ) -> Self {
1188
+ pub fn new (
1189
+ copy_events : Vec < CopyEvent > ,
1190
+ max_copy_rows : usize ,
1191
+ bytecode_map : Option < BTreeMap < Word , bool > > ,
1192
+ ) -> Self {
1116
1193
Self {
1117
1194
copy_events,
1118
1195
max_copy_rows,
1196
+ bytecode_map,
1119
1197
_marker : PhantomData ,
1120
1198
external_data : ExternalData :: default ( ) ,
1121
1199
}
@@ -1125,11 +1203,13 @@ impl<F: Field> CopyCircuit<F> {
1125
1203
pub fn new_with_external_data (
1126
1204
copy_events : Vec < CopyEvent > ,
1127
1205
max_copy_rows : usize ,
1206
+ bytecode_map : Option < BTreeMap < Word , bool > > ,
1128
1207
external_data : ExternalData ,
1129
1208
) -> Self {
1130
1209
Self {
1131
1210
copy_events,
1132
1211
max_copy_rows,
1212
+ bytecode_map,
1133
1213
_marker : PhantomData ,
1134
1214
external_data,
1135
1215
}
@@ -1143,6 +1223,7 @@ impl<F: Field> CopyCircuit<F> {
1143
1223
Self :: new (
1144
1224
block. copy_events . clone ( ) ,
1145
1225
block. circuits_params . max_copy_rows ,
1226
+ block. bytecode_map . clone ( ) ,
1146
1227
)
1147
1228
}
1148
1229
}
@@ -1160,6 +1241,7 @@ impl<F: Field> SubCircuit<F> for CopyCircuit<F> {
1160
1241
Self :: new_with_external_data (
1161
1242
block. copy_events . clone ( ) ,
1162
1243
block. circuits_params . max_copy_rows ,
1244
+ block. bytecode_map . clone ( ) ,
1163
1245
ExternalData {
1164
1246
max_txs : block. circuits_params . max_txs ,
1165
1247
max_calldata : block. circuits_params . max_calldata ,
@@ -1190,7 +1272,13 @@ impl<F: Field> SubCircuit<F> for CopyCircuit<F> {
1190
1272
challenges : & Challenges < Value < F > > ,
1191
1273
layouter : & mut impl Layouter < F > ,
1192
1274
) -> Result < ( ) , Error > {
1193
- config. assign_copy_events ( layouter, & self . copy_events , self . max_copy_rows , * challenges)
1275
+ config. assign_copy_events (
1276
+ layouter,
1277
+ & self . copy_events ,
1278
+ self . max_copy_rows ,
1279
+ * challenges,
1280
+ self . bytecode_map . as_ref ( ) ,
1281
+ )
1194
1282
}
1195
1283
}
1196
1284
0 commit comments