Пример #1
0
 def F(x):
     """ public polynomial
     """
     result = public_coefficients[0]
     for j, coef in enumerate(public_coefficients[1:]):
         result = add(result, multiply(coef, pow(x, j + 1, CURVE_ORDER)))
     return result
Пример #2
0
def recover_point(id_and_point_list: List[Tuple[int, PointG1]]) -> PointG1:
    ids = [j for j, _ in id_and_point_list]
    i, sig = id_and_point_list[0]
    result = multiply(sig, lagrange_coefficient(i, ids))
    for i, sig in id_and_point_list[1:]:
        t = multiply(sig, lagrange_coefficient(i, ids))
        result = add(result, t)
    return result
Пример #3
0
def tally():
    ballots = []
    with open('ballots.csv', 'r') as file:
        for line in file:
            _, a, b = line.strip().split(',')
            ballots.append((int(a), int(b)))

    a, b = crypto.add(ballots)
    total = crypto.decrypt(sk, a, b)
    return str(total)
Пример #4
0
def dleq_verify(g1: PointG1, h1: PointG1, g2: PointG1, h2: PointG1,
                challenge: int, response: int):
    a1 = add(multiply(g1, response), multiply(h1, challenge))
    a2 = add(multiply(g2, response), multiply(h2, challenge))
    c = soliditySha3(  # pylint: disable=E1120
        abi_types=["uint256"] * 12,  # 12,
        values=[
            a1[0],
            a1[1],
            a2[0],
            a2[1],
            g1[0],
            g1[1],
            h1[0],
            h1[1],
            g2[0],
            g2[1],
            h2[0],
            h2[1],
        ],
    )
    c = int.from_bytes(c, "big")
    return c == challenge
Пример #5
0
def tally():
    ballots = []
    with open('ballots.csv', 'r') as file:
        for line in file:
            line = line.strip().split(',')
            ballots.append((int(line[1]), int(line[2])))

    a, b = crypto.add(ballots)
    yes = crypto.decrypt(sk, a, b)
    proof = crypto.correct_decryption_proof(pk, sk, a, b)
    response = {
        'yes': yes,
        'no': len(ballots) - yes,
        'cipher': [a, b],
        'proof': proof
    }
    return json.dumps(response)
Пример #6
0
def verify_sk_knowledge(pk: PointG1,
                        challenge: int,
                        response: int,
                        account: str = None) -> bool:

    t = add(multiply(G1, response), multiply(pk, challenge))

    types = ["uint256"] * 6
    values = list(G1 + pk + t)
    if account is not None:
        types.append("address")
        values.append(account)

    c = soliditySha3(abi_types=types, values=values)
    c = int.from_bytes(c, "big")

    print("values", values)

    print("t", t)
    print("c", c)

    return c == challenge
def test_add():
    a = multiply(G1, 5)
    b = multiply(G1, 10)
    s = add(a, b)
    assert contract.bn128_add([a[0], a[1], b[0], b[1]]) == list(s)