Пример #1
0
def is_on_curve(point: Point) -> bool:
    if len(point) == 2:
        return bn128.is_on_curve(_wrap(point), bn128.b)
    elif len(point) == 4:
        return bn128.is_on_curve(_wrap(point), bn128.b2)
    else:
        assert False, "case not implemented"
Пример #2
0
def _load_g1_point(point):
    """Unserialize a G1 point, from Ethereum hex encoded 0x..."""
    if len(point) != 2:
        raise RuntimeError("Invalid G1 point - not 2 vals", point)

    out = tuple(FQ(_filter_int(_)) for _ in point)

    if not bn128.is_on_curve(out, bn128.b):
        raise ValueError("Invalid G1 point - not on curve", out)

    return out
Пример #3
0
def _load_g2_point(point):
    """Unserialize a G2 point, from Ethereum hex encoded 0x..."""
    x, y = point
    if len(x) != 2 or len(y) != 2:
        raise RuntimeError("Invalid G2 point x or y", point)

    # Points are provided as X.c1, X.c0, Y.c1, Y.c2
    # As in, each component is a 512 bit big-endian number split in two
    out = (FQ2([_filter_int(x[1]), _filter_int(x[0])]),
           FQ2([_filter_int(y[1]), _filter_int(y[0])]))

    if not bn128.is_on_curve(out, bn128.b2):
        raise ValueError("Invalid G2 point - not on curve:", out)

    # TODO: verify G2 point with another algorithm?
    #   neg(G2.one()) * p + p != G2.zero()
    return out