Exemplo n.º 1
0
def run_pairing_negation_contract(client):
    g1 = G1.random()
    g2 = G2.random()
    # e(g1, g2) * e(g1, g2^-1) = 1
    args = [(g1, g2), (g1, G2.neg(g2))]
    # check if equality holds
    result = pairing_check(args)
    assert result

    stack_args = [(G1.to_hex(g1), G2.to_hex(g2)) for g1, g2 in args]
    stack_args = [f'Pair {g1} {g2}' for g1, g2 in stack_args]
    stack_args = f'{{ {"; ".join(stack_args)} }}'
    print("CONTRACT: ", CONTRACTS['pairing_check'])
    print("STACK ARGS: ", stack_args)
    check_contract(client, CONTRACTS['pairing_check'], stack_args, result)
def run_pairing_property_contract(client):
    g1 = G1.random()
    g2 = G2.random()
    a = Fr.random()
    b = Fr.random()
    ab = a * b
    # e(g1^a, g2^b) * e(g1, g2^-ab) = 1
    args = [(G1.mul(g1, a), G2.mul(g2, b)), (g1, G2.neg(G2.mul(g2, ab)))]

    # check if equality holds
    result = pairing_check(args)
    assert result

    stack_args = [(G1.to_hex(g1), G2.to_hex(g2)) for g1, g2 in args]
    stack_args = [f'Pair {g1} {g2}' for g1, g2 in stack_args]
    stack_args = f'{{ {"; ".join(stack_args)} }}'
    print("CONTRACT: ", CONTRACTS['pairing_check'])
    print("STACK ARGS: ", stack_args)
    check_contract(client, CONTRACTS['pairing_check'], stack_args, result)
def check_pairing_check(client, args):
    res = pairing_check(args)
    args = [(G1.to_hex(g1), G2.to_hex(g2)) for g1, g2 in args]
    args = [f'Pair {g1} {g2}' for g1, g2 in args]
    args = f'{{ {"; ".join(args)} }}'
    check_contract(client, 'pairing_check', args, res)