예제 #1
0
def test_verify_single():
    msg = b"\x00\x00\x00\x01"
    #
    priv = new_priv_key()
    pub = priv_to_pub(priv)
    sig = sign(msg, priv)
    #
    assert verify(sig, msg, pub)
예제 #2
0
def test_common_message_verify():
    msg = b"\x00\x00\x00\x01"
    #
    priv1 = new_priv_key()
    pub1 = priv_to_pub(priv1)
    sig1 = sign(msg, priv1)
    #
    priv2 = new_priv_key()
    pub2 = priv_to_pub(priv2)
    sig2 = sign(msg, priv2)
    #
    priv3 = new_priv_key()
    pub3 = priv_to_pub(priv3)
    sig3 = sign(msg, priv3)
    #
    sig = agg_sigs([sig1, sig2, sig3])
    assert verify_agg_common_msg(sig, msg, [pub1, pub2, pub3])
예제 #3
0
def test_distinct_messages_verify():
    msg1 = b"\x00\x00\x00\x01"
    msg2 = b"\x00\x00\x00\x02"
    msg3 = b"\x00\x00\x00\x04"
    #
    priv1 = new_priv_key()
    pub1 = priv_to_pub(priv1)
    sig1 = sign(msg1, priv1)
    #
    priv2 = new_priv_key()
    pub2 = priv_to_pub(priv2)
    sig2 = sign(msg2, priv2)
    #
    priv3 = new_priv_key()
    pub3 = priv_to_pub(priv3)
    sig3 = sign(msg3, priv3)
    #
    sig = agg_sigs([sig1, sig2, sig3])
    assert verify_agg(sig, [msg1, msg2, msg3], [pub1, pub2, pub3])
예제 #4
0
def test_verify_multi_common(BLSG2):
    msg = b"\x00\x00\x00\x01"
    #
    priv1 = new_priv_key()
    pub1, sig1 = priv_to_pub(priv1), sign(msg, priv1)
    priv2 = new_priv_key()
    pub2, sig2 = priv_to_pub(priv2), sign(msg, priv2)
    priv3 = new_priv_key()
    pub3, sig3 = priv_to_pub(priv3), sign(msg, priv3)
    sig = agg_sigs([sig1, sig2, sig3])
    assert verify_agg_common_msg(sig, msg, [pub1, pub2, pub3])

    _msg = hash_to_g1(msg)
    pubs = []
    for pub in [pub1, pub2, pub3]:
        pubs.append(pubkey_to_sol(pub))

    tx = BLSG2.verifyMultipleCommonMessage(
        signature_to_sol(sig), pubs, msg_to_sol(_msg),
    )

    assert tx.events["DebugVerification"]["verified"]
예제 #5
0
def test_verify_multi(BLSG2):
    msg1, msg2, msg3 = b"\x00\x00\x00\x01", b"\x00\x00\x00\x02", b"\x00\x00\x00\x04"
    #
    priv1 = new_priv_key()
    pub1, sig1 = priv_to_pub(priv1), sign(msg1, priv1)
    priv2 = new_priv_key()
    pub2, sig2 = priv_to_pub(priv2), sign(msg2, priv2)
    priv3 = new_priv_key()
    pub3, sig3 = priv_to_pub(priv3), sign(msg3, priv3)
    sig = agg_sigs([sig1, sig2, sig3])
    assert verify_agg(sig, [msg1, msg2, msg3], [pub1, pub2, pub3])

    pubs = []
    for pub in [pub1, pub2, pub3]:
        pubs.append(pubkey_to_sol(pub))

    msgs = []
    for msg in [msg1, msg2, msg3]:
        msgs.append(msg_to_sol(hash_to_g1(msg)))

    tx = BLSG2.verifyMultiple(signature_to_sol(sig), pubs, msgs, {"gas_limit": 1000000})

    assert tx.events["DebugVerification"]["verified"]
예제 #6
0
def test_verify_single(BLSG2):

    msg = b"\x00\x00\x00\x01"
    priv = new_priv_key()
    pub = priv_to_pub(priv)
    sig = sign(msg, priv)
    assert verify(sig, msg, pub)

    _msg = hash_to_g1(msg)

    tx = BLSG2.verifySingle(
        signature_to_sol(sig), pubkey_to_sol(pub), msg_to_sol(_msg),
    )

    assert tx.events["DebugVerification"]["verified"]
예제 #7
0
def test_verify_multi_raw(BLSG2, size):
    msgx = b"\x00\x00\x00\x01"  #  pretend like messages are different
    msgs = [msgx] * size
    pubs, sigs = [], []
    for i in range(0, size):
        sk = new_priv_key()
        pub, sig = priv_to_pub(sk), sign(msgx, sk)
        pubs.append(pub)
        sigs.append(sig)

    sig = agg_sigs(sigs)
    # assert verify_agg(sig, msgs, pubs)

    _pubs = []
    for pub in pubs:
        _pubs.append(pubkey_to_sol(pub))

    tx = BLSG2.verifyMultipleRawMessages(
        signature_to_sol(sig), _pubs, msgs, {"gas_limit": 9995000}
    )

    assert tx.events["DebugVerification"]["verified"]
예제 #8
0
def rand_pubkey():
    sk = new_priv_key()
    return priv_to_pub(sk)