Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions tests/byzantium/eip196_ec_add_mul/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ class Spec:
0x269D2516BF8C4F5798CC1267162E59ADD561E5537A328FE0F28A252FA287A72A,
)

# Sample point used by the legacy pointMulAdd2 tests
SAMPLE_G1 = PointG1(
0x0CCBEC17235F5B9CC5E42F3DF6364A76ECDD0101DDDA8FC5DC0BA0B59C0E5628,
0x069EF5E376C0A1EA82F9DFC2E0001A7F385D655EEF9A6F976C7A5D2C493EA3AD,
)

# Invalid point: S1 with a different x coordinate (not on curve)
S1_INVALID = PointG1(
0x0F25919BCB43D5A57391564615C9E70A992B10EAFA4DB109709649CF48C50DD2,
Expand Down
179 changes: 161 additions & 18 deletions tests/byzantium/eip196_ec_add_mul/test_ecadd.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
"""Tests the ecadd precompiled contract."""

import pytest
from execution_testing import (
Alloc,
Environment,
StateTestFiller,
Transaction,
)
from execution_testing import Alloc, StateTestFiller, Transaction

from .spec import PointG1, Spec, ref_spec_196

Expand Down Expand Up @@ -137,6 +132,162 @@
Spec.S1,
id="single_s1",
),
# Ported from pointMulAdd / pointMulAdd2 (ECADD vs ECMUL)
pytest.param(
Spec.S1x2 + Spec.S1,
Spec.S1x3,
id="s1x2_plus_s1",
),
pytest.param(
PointG1(Spec.S1x3.x, Spec.P - Spec.S1x3.y) + Spec.S1x3,
Spec.INF_G1,
id="neg_s1x3_plus_s1x3",
),
pytest.param(
PointG1(Spec.S1x3.x, Spec.P - Spec.S1x3.y)
+ PointG1(Spec.S1x3.x, Spec.P - Spec.S1x3.y),
PointG1(
0x255E468453D7636CC1563E43F7521755F95E6C56043C7321B4AE04E772945FB0,
0x225C5F1623620FD84BFBAB2D861A9D1E570F7727C540F403085998EBAF407C4,
),
id="neg_s1x3_doubled",
),
pytest.param(
PointG1(Spec.S1x3.x, Spec.P - Spec.S1x3.y) + Spec.INF_G1,
PointG1(Spec.S1x3.x, Spec.P - Spec.S1x3.y),
id="neg_s1x3_plus_inf",
),
pytest.param(
Spec.S1x2 + Spec.INF_G1,
Spec.S1x2,
id="s1x2_plus_inf",
),
pytest.param(
Spec.G1 + PointG1(Spec.G1.x, Spec.P - Spec.G1.y),
Spec.INF_G1,
id="generator_plus_neg_generator",
),
pytest.param(
PointG1(Spec.G1.x, Spec.P - Spec.G1.y)
+ PointG1(Spec.G1.x, Spec.P - Spec.G1.y),
PointG1(Spec.G1x2.x, Spec.P - Spec.G1x2.y),
id="neg_generator_doubled",
),
pytest.param(
PointG1(Spec.G1x2.x, Spec.P - Spec.G1x2.y)
+ PointG1(Spec.G1.x, Spec.P - Spec.G1.y),
PointG1(
0x769BF9AC56BEA3FF40232BCB1B6BD159315D84715B8E679F2D355961915ABF0,
0x5ACB4B400E90C0063006A39F478F3E865E306DD5CD56F356E2E8CD8FE7EDAE6,
),
id="neg_g1x2_plus_neg_generator",
),
pytest.param(
PointG1(Spec.G1.x, Spec.P - Spec.G1.y) + Spec.INF_G1,
PointG1(Spec.G1.x, Spec.P - Spec.G1.y),
id="neg_generator_plus_inf",
),
pytest.param(
Spec.SAMPLE_G1 + PointG1(Spec.G1.x, Spec.P - Spec.G1.y),
PointG1(
0x113AECCECDAF57CD8C0AACE591774949DCDAF892555FA86726FA7E679B89C067,
0xBFFBA84127A19ABDE488A8251A9A3FCE33B34A76F96AAFB11AB4A6CEF3E9979,
),
id="sample_plus_neg_generator",
),
pytest.param(
Spec.SAMPLE_G1 + Spec.SAMPLE_G1,
PointG1(
0x1FD3B816D9951DCB9AA9797D25E51A865987703AE83CD69C4658679F0350AE2B,
0x29CE3D80A74DDC13784BEB25CA9FBFD048A3265A32C6F38B92060C5093A0E7A7,
),
id="sample_doubled",
),
pytest.param(
Spec.SAMPLE_G1 + Spec.INF_G1,
Spec.SAMPLE_G1,
id="sample_plus_inf",
),
pytest.param(
PointG1(Spec.G1x2_256_1.x, Spec.P - Spec.G1x2_256_1.y)
+ PointG1(Spec.G1.x, Spec.P - Spec.G1.y),
PointG1(
0x1D78954C630B3895FBBFAFAC1294F2C0158879FDC70BFE18222890E7BFB66FBA,
0x101C3346E98B136A7078AEBD427DCED763722D77E3D7985342E0BFFCC6EA4D56,
),
id="neg_g1x2_256_1_plus_neg_generator",
),
pytest.param(
PointG1(Spec.G1x2_256_1.x, Spec.P - Spec.G1x2_256_1.y)
+ PointG1(Spec.G1x2_256_1.x, Spec.P - Spec.G1x2_256_1.y),
PointG1(
0x2FA739D4CDE056D8FD75427345CBB34159856E06A4FFAD64159C4773F23FBF4B,
0x1EED5D5325C31FC89DD541A13D7F63B981FAE8D4BF78A6B08A38A601FCFEA97B,
),
id="neg_g1x2_256_1_doubled",
),
pytest.param(
PointG1(Spec.G1x2_256_1.x, Spec.P - Spec.G1x2_256_1.y)
+ Spec.INF_G1,
PointG1(Spec.G1x2_256_1.x, Spec.P - Spec.G1x2_256_1.y),
id="neg_g1x2_256_1_plus_inf",
),
pytest.param(
Spec.G1x2 + Spec.G1,
PointG1(
0x769BF9AC56BEA3FF40232BCB1B6BD159315D84715B8E679F2D355961915ABF0,
0x2AB799BEE0489429554FDB7C8D086475319E63B40B9C5B57CDF1FF3DD9FE2261,
),
id="g1x2_plus_generator",
),
pytest.param(
PointG1(Spec.G1.x, Spec.P - Spec.G1.y) + Spec.G1,
Spec.INF_G1,
id="neg_generator_plus_generator",
),
pytest.param(
PointG1(Spec.SAMPLE_G1.x, Spec.P - Spec.SAMPLE_G1.y) + Spec.G1,
PointG1(
0x113AECCECDAF57CD8C0AACE591774949DCDAF892555FA86726FA7E679B89C067,
0x246493EECEB7867DDA07BB342FD7B460B44635E9F8DB1F922A7541A9E93E63CE,
),
id="neg_sample_plus_generator",
),
pytest.param(
PointG1(Spec.SAMPLE_G1.x, Spec.P - Spec.SAMPLE_G1.y)
+ PointG1(Spec.SAMPLE_G1.x, Spec.P - Spec.SAMPLE_G1.y),
PointG1(
0x1FD3B816D9951DCB9AA9797D25E51A865987703AE83CD69C4658679F0350AE2B,
0x69610F239E3C41640045A90B6E1988D4EDE443735AAD701AA1A7FC644DC15A0,
),
id="neg_sample_doubled",
),
pytest.param(
PointG1(Spec.SAMPLE_G1.x, Spec.P - Spec.SAMPLE_G1.y) + Spec.INF_G1,
PointG1(Spec.SAMPLE_G1.x, Spec.P - Spec.SAMPLE_G1.y),
id="neg_sample_plus_inf",
),
pytest.param(
Spec.G1x2_256_1 + Spec.G1,
PointG1(
0x1D78954C630B3895FBBFAFAC1294F2C0158879FDC70BFE18222890E7BFB66FBA,
0x20481B2BF7A68CBF47D796F93F038986340F3D19849A3239F93FCC1A1192AFF1,
),
id="g1x2_256_1_plus_generator",
),
pytest.param(
Spec.G1x2_256_1 + Spec.G1x2_256_1,
PointG1(
0x2FA739D4CDE056D8FD75427345CBB34159856E06A4FFAD64159C4773F23FBF4B,
0x1176F11FBB6E80611A7B04154401F4A4158681BCA8F923DCB1E7E614DB7E53CC,
),
id="g1x2_256_1_doubled",
),
pytest.param(
Spec.G1x2_256_1 + Spec.INF_G1,
Spec.G1x2_256_1,
id="g1x2_256_1_plus_inf",
),
],
)
@pytest.mark.ported_from(
Expand Down Expand Up @@ -171,6 +322,8 @@
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stZeroKnowledge2/ecadd_1145-3932_1145-4651_25000_192Filler.json",
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stZeroKnowledge2/ecadd_1145-3932_2969-1336_21000_128Filler.json",
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stZeroKnowledge2/ecadd_1145-3932_2969-1336_25000_128Filler.json",
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stZeroKnowledge/pointMulAddFiller.json",
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stZeroKnowledge/pointMulAdd2Filler.json",
],
pr=[
"https://github.com/ethereum/execution-specs/pull/1935",
Expand All @@ -184,12 +337,7 @@ def test_valid(
tx: Transaction,
) -> None:
"""Test the valid inputs to the ECADD precompile."""
state_test(
env=Environment(),
pre=pre,
tx=tx,
post=post,
)
state_test(pre=pre, tx=tx, post=post)


@pytest.mark.parametrize(
Expand Down Expand Up @@ -313,9 +461,4 @@ def test_invalid(
tx: Transaction,
) -> None:
"""Test the invalid inputs to the ECADD precompile."""
state_test(
env=Environment(),
pre=pre,
tx=tx,
post=post,
)
state_test(pre=pre, tx=tx, post=post)
Loading
Loading