1
1
//! Execution step related module.
2
2
3
- use std:: {
4
- marker:: PhantomData ,
5
- ops:: { Add , Mul , Neg } ,
6
- } ;
3
+ use std:: ops:: { Add , Mul , Neg } ;
7
4
8
5
use crate :: {
9
6
circuit_input_builder:: CallContext ,
@@ -27,6 +24,7 @@ use halo2_proofs::{
27
24
} ,
28
25
plonk:: Expression ,
29
26
} ;
27
+ use strum_macros:: EnumIter ;
30
28
31
29
/// An execution step of the EVM.
32
30
#[ derive( Clone , Debug ) ]
@@ -206,14 +204,15 @@ impl ExecState {
206
204
}
207
205
208
206
/// Defines the various source/destination types for a copy event.
209
- #[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
207
+ #[ derive( Clone , Copy , Debug , PartialEq , Eq , EnumIter , Default ) ]
210
208
pub enum CopyDataType {
211
209
/// When we need to pad the Copy rows of the circuit up to a certain maximum
212
210
/// with rows that are not "useful".
213
211
Padding ,
214
212
/// When the source for the copy event is the bytecode table.
215
213
Bytecode ,
216
214
/// When the source/destination for the copy event is memory.
215
+ #[ default]
217
216
Memory ,
218
217
/// When the source for the copy event is tx's calldata.
219
218
TxCalldata ,
@@ -235,79 +234,6 @@ impl CopyDataType {
235
234
/// How many bits are necessary to represent a copy data type.
236
235
pub const N_BITS : usize = 3usize ;
237
236
}
238
- const NUM_COPY_DATA_TYPES : usize = 8usize ;
239
- pub struct CopyDataTypeIter {
240
- idx : usize ,
241
- back_idx : usize ,
242
- marker : PhantomData < ( ) > ,
243
- }
244
- impl CopyDataTypeIter {
245
- fn get ( & self , idx : usize ) -> Option < CopyDataType > {
246
- match idx {
247
- 0usize => Some ( CopyDataType :: Padding ) ,
248
- 1usize => Some ( CopyDataType :: Bytecode ) ,
249
- 2usize => Some ( CopyDataType :: Memory ) ,
250
- 3usize => Some ( CopyDataType :: TxCalldata ) ,
251
- 4usize => Some ( CopyDataType :: TxLog ) ,
252
- 5usize => Some ( CopyDataType :: RlcAcc ) ,
253
- 6usize => Some ( CopyDataType :: AccessListAddresses ) ,
254
- 7usize => Some ( CopyDataType :: AccessListStorageKeys ) ,
255
- _ => None ,
256
- }
257
- }
258
- }
259
- impl strum:: IntoEnumIterator for CopyDataType {
260
- type Iterator = CopyDataTypeIter ;
261
- fn iter ( ) -> CopyDataTypeIter {
262
- CopyDataTypeIter {
263
- idx : 0 ,
264
- back_idx : 0 ,
265
- marker : PhantomData ,
266
- }
267
- }
268
- }
269
- impl Iterator for CopyDataTypeIter {
270
- type Item = CopyDataType ;
271
- fn next ( & mut self ) -> Option < <Self as Iterator >:: Item > {
272
- #[ allow( clippy:: iter_nth_zero) ]
273
- self . nth ( 0 )
274
- }
275
- fn size_hint ( & self ) -> ( usize , Option < usize > ) {
276
- let t = if self . idx + self . back_idx >= NUM_COPY_DATA_TYPES {
277
- 0
278
- } else {
279
- NUM_COPY_DATA_TYPES - self . idx - self . back_idx
280
- } ;
281
- ( t, Some ( t) )
282
- }
283
- fn nth ( & mut self , n : usize ) -> Option < <Self as Iterator >:: Item > {
284
- let idx = self . idx + n + 1 ;
285
- if idx + self . back_idx > NUM_COPY_DATA_TYPES {
286
- self . idx = NUM_COPY_DATA_TYPES ;
287
- None
288
- } else {
289
- self . idx = idx;
290
- self . get ( idx - 1 )
291
- }
292
- }
293
- }
294
- impl ExactSizeIterator for CopyDataTypeIter {
295
- fn len ( & self ) -> usize {
296
- self . size_hint ( ) . 0
297
- }
298
- }
299
- impl DoubleEndedIterator for CopyDataTypeIter {
300
- fn next_back ( & mut self ) -> Option < <Self as Iterator >:: Item > {
301
- let back_idx = self . back_idx + 1 ;
302
- if self . idx + back_idx > NUM_COPY_DATA_TYPES {
303
- self . back_idx = NUM_COPY_DATA_TYPES ;
304
- None
305
- } else {
306
- self . back_idx = back_idx;
307
- self . get ( NUM_COPY_DATA_TYPES - self . back_idx )
308
- }
309
- }
310
- }
311
237
312
238
impl From < CopyDataType > for usize {
313
239
fn from ( t : CopyDataType ) -> Self {
@@ -339,12 +265,6 @@ impl From<&CopyDataType> for u64 {
339
265
}
340
266
}
341
267
342
- impl Default for CopyDataType {
343
- fn default ( ) -> Self {
344
- Self :: Memory
345
- }
346
- }
347
-
348
268
impl_expr ! ( CopyDataType , u64 :: from) ;
349
269
350
270
/// Defines a single copy step in a copy event. This type is unified over the
0 commit comments