@@ -43,64 +43,75 @@ def test_vectors_from_file(
43
43
)
44
44
45
45
46
- @pytest .mark .parametrize (
47
- "modexp_input,modexp_expected,call_succeeds" ,
48
- [
46
+ def create_modexp_input (
47
+ bsize : int , esize : int , msize : int , e_data : str = "" , m_data : str = "" , b_data : str = ""
48
+ ) -> bytes :
49
+ """
50
+ Create ModExp input data with specified sizes and data.
51
+
52
+ Args:
53
+ bsize: Base size in bytes
54
+ esize: Exponent size in bytes
55
+ msize: Modulus size in bytes
56
+ e_data: Exponent data (hex string, if not provided, will be padded with FF)
57
+ m_data: Modulus data (hex string, if not provided, will be padded with FF)
58
+ b_data: Base data (hex string, if not provided, will be padded with FF)
59
+
60
+ Returns:
61
+ ModExp input as bytes
62
+
63
+ """
64
+ e_padded = "FF" * esize if not e_data else e_data
65
+ m_padded = "FF" * msize if not m_data else m_data
66
+ b_padded = "FF" * bsize if not b_data else b_data
67
+
68
+ # Format sizes as 32-byte hex strings
69
+ bsize_hex = format (bsize , "032x" )
70
+ esize_hex = format (esize , "032x" )
71
+ msize_hex = format (msize , "032x" )
72
+
73
+ # Concatenate all parts
74
+ input_hex = bsize_hex + esize_hex + msize_hex + e_padded + m_padded + b_padded
75
+ return bytes .fromhex (input_hex )
76
+
77
+
78
+ def generate_invalid_inputs_cases ():
79
+ """Generate test cases for invalid ModExp inputs."""
80
+ return [
49
81
pytest .param (bytes (), bytes (), False , id = "zero-length-calldata" ),
50
82
pytest .param (
51
- bytes .fromhex (
52
- format (10 , "032x" ) # Bsize
53
- + format (11 , "032x" ) # Esize
54
- + format (12 , "032x" ) # Msize
55
- + "FF" * 9 # E
56
- + "FF" * 11 # M
57
- + "FF" * 12 # B
58
- ),
83
+ create_modexp_input (10 , 11 , 12 , b_data = "FF" * 9 ),
59
84
bytes (),
60
85
False ,
61
86
id = "b-too-short" ,
62
87
),
63
88
pytest .param (
64
- bytes .fromhex (
65
- format (10 , "032x" ) # Bsize
66
- + format (11 , "032x" ) # Esize
67
- + format (12 , "032x" ) # Msize
68
- + "FF" * 10 # E
69
- + "FF" * 10 # M
70
- + "FF" * 12 # B
71
- ),
89
+ create_modexp_input (10 , 11 , 12 , m_data = "FF" * 10 ),
72
90
bytes (),
73
91
False ,
74
92
id = "m-too-short" ,
75
93
),
76
94
pytest .param (
77
- bytes .fromhex (
78
- format (10 , "032x" ) # Bsize
79
- + format (11 , "032x" ) # Esize
80
- + format (12 , "032x" ) # Msize
81
- + "FF" * 10 # E
82
- + "FF" * 11 # M
83
- + "FF" * 11 # B
84
- ),
95
+ create_modexp_input (10 , 11 , 12 , e_data = "FF" * 11 ),
85
96
bytes (),
86
97
False ,
87
98
id = "e-too-short" ,
88
99
),
89
- # Not sure if this is valid
90
100
pytest .param (
91
- bytes .fromhex (
92
- format (0 , "032x" ) # Bsize
93
- + format (0 , "032x" ) # Esize
94
- + format (0 , "032x" ) # Msize
95
- ),
101
+ create_modexp_input (0 , 0 , 0 ),
96
102
bytes (),
97
103
False ,
98
104
id = "all-zeros" ,
99
105
),
100
- ],
106
+ ]
107
+
108
+
109
+ @pytest .mark .parametrize (
110
+ "modexp_input,modexp_expected,call_succeeds" ,
111
+ generate_invalid_inputs_cases (),
101
112
)
102
113
@EIPChecklist .Precompile .Test .Inputs .AllZeros
103
- def test_modexp_invalid (
114
+ def test_modexp_invalid_inputs (
104
115
state_test : StateTestFiller ,
105
116
pre : Alloc ,
106
117
tx : Transaction ,
0 commit comments