Skip to content

test_valid()

Documentation for tests/byzantium/eip196_ec_add_mul/test_ecmul.py::test_valid@b314d18e.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/byzantium/eip196_ec_add_mul/test_ecmul.py::test_valid --fork Amsterdam

Test the valid inputs to the ECMUL precompile.

Source code in tests/byzantium/eip196_ec_add_mul/test_ecmul.py
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
@pytest.mark.parametrize(
    "input_data, expected_output",
    [
        pytest.param(
            Spec.G1 + Scalar(0),
            Spec.INF_G1,
            id="generator_times_zero",
        ),
        pytest.param(
            Spec.G1 + Scalar(1),
            Spec.G1,
            id="generator_times_one",
        ),
        pytest.param(
            Spec.G1 + Scalar(2),
            Spec.G1x2,
            id="generator_times_two",
        ),
        pytest.param(
            Spec.G1 + Scalar(9),
            Spec.G1x9,
            id="generator_times_nine",
        ),
        pytest.param(
            Spec.G1 + Scalar(2**128),
            Spec.G1x2_128,
            id="generator_times_2_pow_128",
        ),
        pytest.param(
            Spec.G1 + Scalar(2**256 - 1),
            Spec.G1x2_256_1,
            id="generator_times_2_pow_256_minus_1",
        ),
        pytest.param(
            Spec.G1 + Scalar(Spec.N - 1),
            PointG1(1, Spec.P - 2),
            id="generator_times_group_order_minus_one",
        ),
        pytest.param(
            Spec.G1 + Scalar(Spec.N),
            Spec.INF_G1,
            id="generator_times_group_order",
        ),
        pytest.param(
            Spec.G1 + Scalar(Spec.N + 1),
            Spec.G1,
            id="generator_times_group_order_plus_one",
        ),
        pytest.param(
            Spec.G1 + Scalar(2 * Spec.N - 1),
            PointG1(1, Spec.P - 2),
            id="generator_times_double_group_order_minus_one",
        ),
        pytest.param(
            Spec.G1 + Scalar(2 * Spec.N),
            Spec.INF_G1,
            id="generator_times_double_group_order",
        ),
        pytest.param(
            Spec.G1 + Scalar(2 * Spec.N + 1),
            Spec.G1,
            id="generator_times_double_group_order_plus_one",
        ),
        pytest.param(
            Spec.T1 + Scalar(0),
            Spec.INF_G1,
            id="t1_point_times_zero",
        ),
        pytest.param(
            Spec.T1 + Scalar(1),
            Spec.T1,
            id="t1_point_times_one",
        ),
        pytest.param(
            Spec.T1 + Scalar(2),
            Spec.T1x2,
            id="t1_point_times_two",
        ),
        pytest.param(
            Spec.T1 + Scalar(9),
            Spec.T1x9,
            id="t1_point_times_nine",
        ),
        pytest.param(
            Spec.T1 + Scalar(2**128),
            Spec.T1x2_128,
            id="t1_point_times_2_pow_128",
        ),
        pytest.param(
            Spec.T1 + Scalar(2**256 - 1),
            Spec.T1x2_256_1,
            id="t1_point_times_2_pow_256_minus_1",
        ),
        pytest.param(
            Spec.T1 + Scalar(Spec.N - 1),
            PointG1(Spec.T1.x, Spec.P - Spec.T1.y),
            id="t1_point_times_group_order_minus_one",
        ),
        pytest.param(
            Spec.T1 + Scalar(Spec.N),
            Spec.INF_G1,
            id="t1_point_times_group_order",
        ),
        pytest.param(
            Spec.P1 + Scalar(0),
            Spec.INF_G1,
            id="p1_times_zero",
        ),
        pytest.param(
            Spec.P1 + Scalar(1),
            Spec.P1,
            id="p1_times_one",
        ),
        pytest.param(
            Spec.INF_G1 + Scalar(0),
            Spec.INF_G1,
            id="inf_times_zero",
        ),
        pytest.param(
            Spec.INF_G1 + Scalar(1),
            Spec.INF_G1,
            id="inf_times_one",
        ),
        pytest.param(
            Spec.INF_G1 + Scalar(2),
            Spec.INF_G1,
            id="inf_times_two",
        ),
        pytest.param(
            Spec.INF_G1 + Scalar(9),
            Spec.INF_G1,
            id="inf_times_nine",
        ),
        pytest.param(
            Spec.INF_G1 + Scalar(2**128),
            Spec.INF_G1,
            id="inf_times_2_pow_128",
        ),
        pytest.param(
            Spec.INF_G1 + Scalar(2**256 - 1),
            Spec.INF_G1,
            id="inf_times_2_pow_256_minus_1",
        ),
        pytest.param(
            Spec.INF_G1 + Scalar(Spec.N - 1),
            Spec.INF_G1,
            id="inf_times_group_order_minus_one",
        ),
        pytest.param(
            Spec.INF_G1 + Scalar(Spec.N),
            Spec.INF_G1,
            id="inf_times_group_order",
        ),
        # Extra data (>96 bytes)
        pytest.param(
            Spec.G1 + Scalar(1) + b"\0",
            Spec.G1,
            id="generator_times_one-single_extra_byte_0x00",
        ),
        pytest.param(
            Spec.G1 + Scalar(1) + b"\xff",
            Spec.G1,
            id="generator_times_one-single_extra_byte_0xff",
        ),
        pytest.param(
            Spec.G1 + Scalar(1) + b"\0" * 32,
            Spec.G1,
            id="generator_times_one-32_extra_byte_0x00",
        ),
        pytest.param(
            Spec.G1 + Scalar(1) + b"\xff" * 32,
            Spec.G1,
            id="generator_times_one-32_extra_byte_0xff",
        ),
        pytest.param(
            Spec.INF_G1 + Scalar(0) + b"\0" * 32,
            Spec.INF_G1,
            id="generator_times_zero-32_extra_byte_0x00",
        ),
        # Shorter data (<96 bytes)
        pytest.param(
            (Spec.G1 + Scalar(0))[:80],
            Spec.INF_G1,
            id="generator_times_zero-length_80",
        ),
        pytest.param(
            (Spec.G1 + Scalar(2**128))[:80],
            Spec.G1x2_128,
            id="generator_times_2_pow_128-length_80",
        ),
        pytest.param(
            (Spec.G1 + Scalar(2**128))[:95],
            Spec.G1x2_128,
            id="generator_times_2_pow_128-length_95",
        ),
        pytest.param(
            b"",
            Spec.INF_G1,
            id="empty",
        ),
        pytest.param(
            Spec.INF_G1,
            Spec.INF_G1,
            id="inf_no_scalar",
        ),
        pytest.param(
            bytes(Spec.INF_G1)[:40],
            Spec.INF_G1,
            id="inf-length_40",
        ),
        pytest.param(
            bytes(Spec.INF_G1)[:80],
            Spec.INF_G1,
            id="inf-length_80",
        ),
        pytest.param(
            Spec.G1,
            Spec.INF_G1,
            id="generator_no_scalar",
        ),
    ],
)
@pytest.mark.ported_from(
    [
        "https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge/ecmul_1-2_2_21000_96Filler.json",
        "https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge/ecmul_1-2_340282366920938463463374607431768211456_21000_96Filler.json",
        "https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge/ecmul_1-2_2_21000_128Filler.json",
        "https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge/ecmul_1-2_5616_21000_128Filler.json",
        "https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge/ecmul_1-2_5616_21000_96Filler.json",
        "https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge/ecmul_1-2_616_21000_96Filler.json",
        "https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge/ecmul_1-2_5617_21000_128Filler.json",
        "https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge/ecmul_1-2_5617_21000_96Filler.json",
        "https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge/ecmul_1-2_9935_21000_128Filler.json",
        "https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge/ecmul_1-2_9935_21000_96Filler.json",
        "https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge/ecmul_1-2_9_21000_128Filler.json",
        "https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge/ecmul_1-2_9_21000_96Filler.json",
        "https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge/ecmul_1-2_340282366920938463463374607431768211456_21000_80Filler.json",
        "https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge/ecmul_7827-6598_0_21000_96Filler.json",
        "https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge/ecmul_7827-6598_1456_21000_96Filler.json",
        "https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge/ecmul_7827-6598_1_21000_96Filler.json",
        "https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge/ecmul_7827-6598_2_21000_96Filler.json",
        "https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge/ecmul_7827-6598_5616_21000_96Filler.json",
        "https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge/ecmul_7827-6598_5617_21000_96Filler.json",
        "https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge/ecmul_7827-6598_9935_21000_96Filler.json",
        "https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge/ecmul_0-0_0_21000_96Filler.json",
        "https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge/ecmul_0-0_0_21000_0Filler.json",
        "https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge/ecmul_0-0_0_21000_128Filler.json",
        "https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge/ecmul_0-0_1_21000_96Filler.json",
        "https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge/ecmul_0-0_2_21000_96Filler.json",
        "https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge/ecmul_0-0_9_21000_96Filler.json",
        "https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge/ecmul_0-0_340282366920938463463374607431768211456_21000_96Filler.json",
        "https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge/ecmul_0-0_5616_21000_96Filler.json",
        "https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge/ecmul_0-0_5617_21000_96Filler.json",
        "https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge/ecmul_0-0_9935_21000_96Filler.json",
        "https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge/ecmul_0-0_0_21000_40Filler.json",
        "https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge/ecmul_0-0_0_21000_80Filler.json",
        "https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge2/ecmul_1-2_0_21000_64Filler.json",
        "https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge2/ecmul_1-2_0_21000_80Filler.json",
        "https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge2/ecmul_1-2_0_21000_96Filler.json",
        "https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge2/ecmul_1-2_1_21000_128Filler.json",
        "https://github.com/ethereum/legacytests/tree/master/Cancun/GeneralStateTests/stZeroKnowledge2/ecmul_1-2_1_21000_96Filler.json",
    ],
    pr=["https://github.com/ethereum/execution-specs/pull/2403"],
)
def test_valid(
    state_test: StateTestFiller,
    pre: Alloc,
    post: dict,
    tx: Transaction,
) -> None:
    """Test the valid inputs to the ECMUL precompile."""
    state_test(
        env=Environment(),
        pre=pre,
        tx=tx,
        post=post,
    )

Parametrized Test Cases

This test generates 43 parametrized test cases across 12 forks.