@@ -40,6 +40,8 @@ pub struct CircuitInputStateRef<'a> {
40
40
pub tx : & ' a mut Transaction ,
41
41
/// Transaction Context
42
42
pub tx_ctx : & ' a mut TransactionContext ,
43
+ /// Max rw number limit
44
+ pub max_rws : Option < usize > ,
43
45
}
44
46
45
47
impl < ' a > CircuitInputStateRef < ' a > {
@@ -114,7 +116,7 @@ impl<'a> CircuitInputStateRef<'a> {
114
116
/// reference to the stored operation ([`OperationRef`]) inside the
115
117
/// bus-mapping instance of the current [`ExecStep`]. Then increase the
116
118
/// block_ctx [`RWCounter`](crate::operation::RWCounter) by one.
117
- pub fn push_op < T : Op > ( & mut self , step : & mut ExecStep , rw : RW , op : T ) {
119
+ pub fn push_op < T : Op > ( & mut self , step : & mut ExecStep , rw : RW , op : T ) -> Result < ( ) , Error > {
118
120
if let OpEnum :: Account ( op) = op. clone ( ) . into_enum ( ) {
119
121
self . check_update_sdb_account ( rw, & op)
120
122
}
@@ -123,6 +125,20 @@ impl<'a> CircuitInputStateRef<'a> {
123
125
. container
124
126
. insert ( Operation :: new ( self . block_ctx . rwc . inc_pre ( ) , rw, op) ) ;
125
127
step. bus_mapping_instance . push ( op_ref) ;
128
+ self . check_rw_num_limit ( )
129
+ }
130
+
131
+ /// Check whether rws will overflow circuit limit.
132
+ pub fn check_rw_num_limit ( & self ) -> Result < ( ) , Error > {
133
+ if let Some ( max_rws) = self . max_rws {
134
+ let rwc = self . block_ctx . rwc . 0 ;
135
+ if rwc > max_rws {
136
+ log:: error!( "rwc > max_rws, rwc={}, max_rws={}" , rwc, max_rws) ;
137
+ return Err ( Error :: RwsNotEnough ( max_rws, rwc) ) ;
138
+ } ;
139
+ }
140
+
141
+ Ok ( ( ) )
126
142
}
127
143
128
144
/// Push a read type [`CallContextOp`] into the
@@ -137,14 +153,14 @@ impl<'a> CircuitInputStateRef<'a> {
137
153
call_id : usize ,
138
154
field : CallContextField ,
139
155
value : Word ,
140
- ) {
156
+ ) -> Result < ( ) , Error > {
141
157
let op = CallContextOp {
142
158
call_id,
143
159
field,
144
160
value,
145
161
} ;
146
162
147
- self . push_op ( step, RW :: READ , op) ;
163
+ self . push_op ( step, RW :: READ , op)
148
164
}
149
165
150
166
/// Push a write type [`CallContextOp`] into the
@@ -159,14 +175,14 @@ impl<'a> CircuitInputStateRef<'a> {
159
175
call_id : usize ,
160
176
field : CallContextField ,
161
177
value : Word ,
162
- ) {
178
+ ) -> Result < ( ) , Error > {
163
179
let op = CallContextOp {
164
180
call_id,
165
181
field,
166
182
value,
167
183
} ;
168
184
169
- self . push_op ( step, RW :: WRITE , op) ;
185
+ self . push_op ( step, RW :: WRITE , op)
170
186
}
171
187
172
188
/// Push an [`Operation`](crate::operation::Operation) with reversible to be
@@ -203,7 +219,7 @@ impl<'a> CircuitInputStateRef<'a> {
203
219
. push ( ( self . tx . steps ( ) . len ( ) , op_ref) ) ;
204
220
}
205
221
206
- Ok ( ( ) )
222
+ self . check_rw_num_limit ( )
207
223
}
208
224
209
225
/// Push a read type [`MemoryOp`] into the
@@ -219,7 +235,7 @@ impl<'a> CircuitInputStateRef<'a> {
219
235
value : u8 ,
220
236
) -> Result < ( ) , Error > {
221
237
let call_id = self . call ( ) ?. call_id ;
222
- self . push_op ( step, RW :: READ , MemoryOp :: new ( call_id, address, value) ) ;
238
+ self . push_op ( step, RW :: READ , MemoryOp :: new ( call_id, address, value) ) ? ;
223
239
Ok ( ( ) )
224
240
}
225
241
@@ -236,7 +252,7 @@ impl<'a> CircuitInputStateRef<'a> {
236
252
value : u8 ,
237
253
) -> Result < ( ) , Error > {
238
254
let call_id = self . call ( ) ?. call_id ;
239
- self . push_op ( step, RW :: WRITE , MemoryOp :: new ( call_id, address, value) ) ;
255
+ self . push_op ( step, RW :: WRITE , MemoryOp :: new ( call_id, address, value) ) ? ;
240
256
Ok ( ( ) )
241
257
}
242
258
@@ -253,7 +269,7 @@ impl<'a> CircuitInputStateRef<'a> {
253
269
value : Word ,
254
270
) -> Result < ( ) , Error > {
255
271
let call_id = self . call ( ) ?. call_id ;
256
- self . push_op ( step, RW :: WRITE , StackOp :: new ( call_id, address, value) ) ;
272
+ self . push_op ( step, RW :: WRITE , StackOp :: new ( call_id, address, value) ) ? ;
257
273
Ok ( ( ) )
258
274
}
259
275
@@ -270,7 +286,7 @@ impl<'a> CircuitInputStateRef<'a> {
270
286
value : Word ,
271
287
) -> Result < ( ) , Error > {
272
288
let call_id = self . call ( ) ?. call_id ;
273
- self . push_op ( step, RW :: READ , StackOp :: new ( call_id, address, value) ) ;
289
+ self . push_op ( step, RW :: READ , StackOp :: new ( call_id, address, value) ) ? ;
274
290
Ok ( ( ) )
275
291
}
276
292
@@ -352,9 +368,9 @@ impl<'a> CircuitInputStateRef<'a> {
352
368
address : Address ,
353
369
field : AccountField ,
354
370
value : Word ,
355
- ) {
371
+ ) -> Result < ( ) , Error > {
356
372
let op = AccountOp :: new ( address, field, value, value) ;
357
- self . push_op ( step, RW :: READ , op) ;
373
+ self . push_op ( step, RW :: READ , op)
358
374
}
359
375
360
376
/// Push a write type [`AccountOp`] into the
@@ -376,7 +392,7 @@ impl<'a> CircuitInputStateRef<'a> {
376
392
if reversible {
377
393
self . push_op_reversible ( step, op) ?;
378
394
} else {
379
- self . push_op ( step, RW :: WRITE , op) ;
395
+ self . push_op ( step, RW :: WRITE , op) ? ;
380
396
}
381
397
Ok ( ( ) )
382
398
}
@@ -400,8 +416,7 @@ impl<'a> CircuitInputStateRef<'a> {
400
416
step,
401
417
RW :: WRITE ,
402
418
TxLogOp :: new ( tx_id, log_id, field, index, value) ,
403
- ) ;
404
- Ok ( ( ) )
419
+ )
405
420
}
406
421
407
422
/// Push a read type [`TxReceiptOp`] into the
@@ -425,8 +440,7 @@ impl<'a> CircuitInputStateRef<'a> {
425
440
field,
426
441
value,
427
442
} ,
428
- ) ;
429
- Ok ( ( ) )
443
+ )
430
444
}
431
445
432
446
/// Push a write type [`TxReceiptOp`] into the
@@ -450,8 +464,7 @@ impl<'a> CircuitInputStateRef<'a> {
450
464
field,
451
465
value,
452
466
} ,
453
- ) ;
454
- Ok ( ( ) )
467
+ )
455
468
}
456
469
457
470
/// Push a write type [`TxAccessListAccountOp`] into the
@@ -477,8 +490,7 @@ impl<'a> CircuitInputStateRef<'a> {
477
490
is_warm,
478
491
is_warm_prev,
479
492
} ,
480
- ) ;
481
- Ok ( ( ) )
493
+ )
482
494
}
483
495
484
496
/// Add address to access list for the current transaction.
@@ -542,7 +554,7 @@ impl<'a> CircuitInputStateRef<'a> {
542
554
value : sender_balance,
543
555
value_prev : sender_balance_prev,
544
556
} ,
545
- ) ;
557
+ ) ? ;
546
558
sender_balance_prev = sender_balance;
547
559
}
548
560
let sender_balance = sender_balance_prev - value;
@@ -766,29 +778,39 @@ impl<'a> CircuitInputStateRef<'a> {
766
778
}
767
779
768
780
/// read reversion info
769
- pub ( crate ) fn reversion_info_read ( & mut self , step : & mut ExecStep , call : & Call ) {
781
+ pub ( crate ) fn reversion_info_read (
782
+ & mut self ,
783
+ step : & mut ExecStep ,
784
+ call : & Call ,
785
+ ) -> Result < ( ) , Error > {
770
786
for ( field, value) in [
771
787
(
772
788
CallContextField :: RwCounterEndOfReversion ,
773
789
call. rw_counter_end_of_reversion . to_word ( ) ,
774
790
) ,
775
791
( CallContextField :: IsPersistent , call. is_persistent . to_word ( ) ) ,
776
792
] {
777
- self . call_context_read ( step, call. call_id , field, value) ;
793
+ self . call_context_read ( step, call. call_id , field, value) ? ;
778
794
}
795
+ Ok ( ( ) )
779
796
}
780
797
781
798
/// write reversion info
782
- pub ( crate ) fn reversion_info_write ( & mut self , step : & mut ExecStep , call : & Call ) {
799
+ pub ( crate ) fn reversion_info_write (
800
+ & mut self ,
801
+ step : & mut ExecStep ,
802
+ call : & Call ,
803
+ ) -> Result < ( ) , Error > {
783
804
for ( field, value) in [
784
805
(
785
806
CallContextField :: RwCounterEndOfReversion ,
786
807
call. rw_counter_end_of_reversion . to_word ( ) ,
787
808
) ,
788
809
( CallContextField :: IsPersistent , call. is_persistent . to_word ( ) ) ,
789
810
] {
790
- self . call_context_write ( step, call. call_id , field, value) ;
811
+ self . call_context_write ( step, call. call_id , field, value) ? ;
791
812
}
813
+ Ok ( ( ) )
792
814
}
793
815
794
816
/// Check if address is a precompiled or not.
@@ -1128,7 +1150,7 @@ impl<'a> CircuitInputStateRef<'a> {
1128
1150
call. call_id ,
1129
1151
CallContextField :: IsSuccess ,
1130
1152
0u64 . into ( ) ,
1131
- ) ;
1153
+ ) ? ;
1132
1154
1133
1155
// Even call.rw_counter_end_of_reversion is zero for now, it will set in
1134
1156
// set_value_ops_call_context_rwc_eor later
@@ -1139,7 +1161,7 @@ impl<'a> CircuitInputStateRef<'a> {
1139
1161
call. call_id ,
1140
1162
CallContextField :: RwCounterEndOfReversion ,
1141
1163
call. rw_counter_end_of_reversion . into ( ) ,
1142
- ) ;
1164
+ ) ? ;
1143
1165
1144
1166
if call. is_root {
1145
1167
return Ok ( ( ) ) ;
@@ -1155,7 +1177,7 @@ impl<'a> CircuitInputStateRef<'a> {
1155
1177
call. call_id ,
1156
1178
CallContextField :: CallerId ,
1157
1179
caller. call_id . into ( ) ,
1158
- ) ;
1180
+ ) ? ;
1159
1181
1160
1182
let [ last_callee_return_data_offset, last_callee_return_data_length] =
1161
1183
if exec_step. error . is_some ( ) {
@@ -1233,7 +1255,7 @@ impl<'a> CircuitInputStateRef<'a> {
1233
1255
self . caller_ctx ( ) ?. reversible_write_counter . into ( ) ,
1234
1256
) ,
1235
1257
] {
1236
- self . call_context_read ( exec_step, caller. call_id , field, value) ;
1258
+ self . call_context_read ( exec_step, caller. call_id , field, value) ? ;
1237
1259
}
1238
1260
1239
1261
// EIP-211: CREATE/CREATE2 call successful case should set RETURNDATASIZE = 0
@@ -1258,7 +1280,7 @@ impl<'a> CircuitInputStateRef<'a> {
1258
1280
} ,
1259
1281
) ,
1260
1282
] {
1261
- self . call_context_write ( exec_step, caller. call_id , field, value) ;
1283
+ self . call_context_write ( exec_step, caller. call_id , field, value) ? ;
1262
1284
}
1263
1285
1264
1286
Ok ( ( ) )
@@ -1547,7 +1569,7 @@ impl<'a> CircuitInputStateRef<'a> {
1547
1569
exec_step,
1548
1570
RW :: READ ,
1549
1571
MemoryOp :: new ( self . call ( ) ?. caller_id , addr. into ( ) , byte) ,
1550
- ) ;
1572
+ ) ? ;
1551
1573
}
1552
1574
byte
1553
1575
} else {
0 commit comments