Skip to content

Commit 871c26a

Browse files
committed
sanity check pairing precompile test
1 parent eb7cd5e commit 871c26a

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

eth/precompiles/bls.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ def _parse_g1_point(data: bytes) -> G1Point:
4343
return point
4444

4545

46+
def _serialize_g1(result: G1Point) -> bytes:
47+
return b"".join(
48+
(
49+
int(result[0]).to_bytes(64, byteorder="big"),
50+
int(result[1]).to_bytes(64, byteorder="big"),
51+
)
52+
)
53+
54+
4655
def g1_add(computation: BaseComputation,
4756
gas_cost: int = constants.GAS_BLS_G1_ADD) -> BaseComputation:
4857
raise NotImplementedError()

tests/core/precompiles/test_bls.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from py_ecc.optimized_bls12_381.optimized_curve import G1, G2, neg, FQ12
2+
from eth.precompiles.bls import _pairing, _serialize_g2, _serialize_g1
3+
4+
def test_pairing_precompile():
5+
# assert pairing(G1, G2) * pairing(neg(G1), G2) == FQ12.one()
6+
serialized_G1 = _serialize_g1(G1)
7+
serialized_G2 = _serialize_g2(G2)
8+
serialized_neg_G1 = _serialize_g1(neg(G1))
9+
input_data = serialized_G1 + serialized_G2 + serialized_neg_G1 + serialized_G2
10+
assert _pairing(input_data)

0 commit comments

Comments
 (0)