py_ecc icon indicating copy to clipboard operation
py_ecc copied to clipboard

Pairing product function which matches Ethereum opcode (EIP-212)

Open HarryR opened this issue 6 years ago • 3 comments

def pairingProd(*inputs):
    """
    The Ethereum pairing opcode works like:

       e(p1[0],p2[0]) * ... * e(p1[n],p2[n]) == 1

    See: EIP 212

    >>> assert True == pairingProd((G1, G2), (G1, neg(G2)))
    """
    product = FQ12.one()
    for p1, p2 in inputs:
        product *= pairing(p2, p1)
    return product == FQ12.one()

The G1 and G2 argument orders are swapped compared to the Pairing.sol file, whereas py_ecc uses e(G2, G1).

It would be useful to have this included in the library, and to verify this is a correct implementation.

HarryR avatar Jul 17 '18 13:07 HarryR

cc @vbuterin as this is beyond the scope of my expertise to evaluate.

pipermerriam avatar Jul 17 '18 18:07 pipermerriam

@HarryR is right. I got the wrong impression that what I was trying to do was possible using the precompiled pairing (aka BBS signature). This is misleading.

GuthL avatar Sep 02 '18 15:09 GuthL

Would someone like to open a pull request as I think that would be the easiest way to figure out how to proceed here.

pipermerriam avatar Sep 03 '18 17:09 pipermerriam