Example #1
0
def testKeyAggregation():
    n = 20
    startPK = 35
    pks = [x for x in range(startPK, startPK + 35)]

    pubs = [multiply(G2, x) for x in pks]
    for i in range(len(pubs)):
        print([pubs[i]], "\n")
    print(pubs)

    pubKeyAgg = pubs[0]
    for i in range(1, 35):
        pubKeyAgg = add(pubKeyAgg, pubs[i])

    h = 12312312345
    H = multiply(G1, h)
    sigs = []
    for i in range(0, 35):
        sigs.append(multiply(H, pks[i]))

    aggSign = sigs[0]
    for i in range(1, 35):
        aggSign = add(aggSign, sigs[i])

        # G2, G1
    pairing1 = pairing(pubKeyAgg, H)
    # G2 , G1
    pairing2 = pairing(G2, aggSign)
    assert pairing1 == pairing2  # test sign Aggregation

    print("yey")
Example #2
0
def powers_of_tau(_secret, depth):
    g_1 = [G1]
    g_2 = [G2, multiply(G2, _secret)]
    secret = _secret
    for i in range(0, depth):
        g_1.append(multiply(G1, secret))
        secret = secret * _secret
    return (g_1, g_2)
Example #3
0
def poly_commit(poly, g):
    res = None
    for i, x in enumerate(poly):
        # deal with negitive numbers
        if (x) < 0:
            x = x * -1
            res = add(res, neg(multiply(g[i], x)))
        else:
            res = add(res, multiply(g[i], x))
    return res
Example #4
0
def test_mul():
    secret_1 = 1232
    secret_2 = 123123

    a = multiply(G1, secret_1)
    a = multiply(a, secret_2)

    b = multiply(G1, secret_2)
    b = multiply(b, secret_1)

    ## its homomorphic
    assert a == b
Example #5
0
def test_pairing():
    secret_1 = 1232
    secret_2 = 123123

    g_1 = multiply(G1, secret_1)

    g_2 = multiply(G2, secret_2)

    res = pairing(g_2, g_1)

    g_1 = multiply(G1, secret_2)

    g_2 = multiply(G2, secret_1)

    # we flip it and it still equals its homomorphic.
    assert res == pairing(g_2, g_1)
Example #6
0
def testKeyAggregation():
    privKey1 = 31
    privKey2 = 35
    privKey3 = 37

    pubKey1 = multiply(G1, privKey1)
    pubKey2 = multiply(G1, privKey2)
    pubKey3 = multiply(G1, privKey3)

    pubKeyAgg = add(add(pubKey1, pubKey2), pubKey3)

    h = 12312312345
    H = multiply(G2, h)

    sign1 = multiply(H, privKey1)
    sign2 = multiply(H, privKey2)
    sign3 = multiply(H, privKey3)

    aggSign = add(add(sign1, sign2), sign3)

    pairing1 = pairing(H, pubKeyAgg)
    pairing2 = pairing(aggSign, G1)
    assert pairing1 == pairing2  # test sign Aggregation
    # for 400/n validators
    # n = 400
    # startPK = 500
    # pks = [x for x in range(startPK, startPK + n)]
    #
    # pubs = [multiply(G1, x) for x in pks]
    # # for i in range(len(pubs)):
    # #     print([pubs[i]], "\n")
    # # print(pubs)
    #
    # pubKeyAgg = pubs[0]
    # for i in range(1, n):
    #     pubKeyAgg = add(pubKeyAgg, pubs[i])
    # h = 12312312345
    # H = multiply(G2, h)
    # sigs = []
    # for i in range(0, n):
    #     sigs.append(multiply(H,pks[i]))
    #
    #
    # aggSign = sigs[0]
    # for i in range(1, n):
    #     aggSign = add(aggSign, sigs[i])
    #
    # pairing1 = pairing(H, pubKeyAgg)
    # pairing2 = pairing(aggSign, G1)

    # assert pairing1 == pairing2  # test sign Aggregation
    # x = pubKeyAgg

    print("yey")