예제 #1
0
def test_sloth_empty_init():
    s = sloth.Sloth()
    assert s.data is None
    assert s.bits == 2048
    assert s.iterations == 50000
    assert s.final_hash is None
    assert s.witness is None
예제 #2
0
def test_sloth_compute():
    s = sloth.Sloth(data=ValidSloth.INPUT,
                    bits=ValidSloth.BITS,
                    iterations=ValidSloth.ITERATIONS)
    s.compute()
    s.wait()
    assert s.final_hash
    assert s.witness
예제 #3
0
def verify_sloth(inp, out, witness, bits, iterations):
    s = sloth.Sloth(data=inp,
                    final_hash=out,
                    witness=witness,
                    bits=bits,
                    iterations=iterations)
    s.verify()
    s.wait()
    return s.valid
예제 #4
0
def test_sloth_verify_bad_witness():
    s = sloth.Sloth(data=InvalidWitness.INPUT,
                    final_hash=InvalidWitness.OUTPUT,
                    witness=InvalidWitness.WITNESS,
                    bits=InvalidWitness.BITS,
                    iterations=InvalidWitness.ITERATIONS)
    s.verify()
    s.wait()
    assert not s.valid
예제 #5
0
def test_sloth_compute_verify():
    s = sloth.Sloth(data=ValidSloth.INPUT,
                    bits=ValidSloth.BITS,
                    iterations=ValidSloth.ITERATIONS)
    s.compute()
    s.wait()
    s.verify()
    s.wait()
    assert s.valid
예제 #6
0
def test_sloth_predef_verify():
    s = sloth.Sloth(data=ValidSloth.INPUT,
                    final_hash=ValidSloth.OUTPUT,
                    witness=ValidSloth.WITNESS,
                    bits=ValidSloth.BITS,
                    iterations=ValidSloth.ITERATIONS)
    s.verify()
    s.wait()
    assert s.valid
예제 #7
0
def test_sloth_init():
    s = sloth.Sloth(data=ValidSloth.INPUT,
                    final_hash=ValidSloth.OUTPUT,
                    witness=ValidSloth.WITNESS,
                    bits=ValidSloth.BITS,
                    iterations=ValidSloth.ITERATIONS)
    assert s.data == ValidSloth.INPUT
    assert s.bits == ValidSloth.BITS
    assert s.iterations == ValidSloth.ITERATIONS
    assert s.final_hash == ValidSloth.OUTPUT
    assert s.witness == ValidSloth.WITNESS
예제 #8
0
def test_sloth_iteration_time():
    import time
    s = sloth.Sloth(data=b'test', bits=1024, iterations=1000)
    start_t = time.time()
    s.compute()
    s.wait()
    t_1000iter = time.time() - start_t

    s = sloth.Sloth(data=b'test', bits=1024, iterations=2000)
    start_t = time.time()
    s.compute()
    s.wait()
    t_2000iter = time.time() - start_t

    s = sloth.Sloth(data=b'test', bits=1024, iterations=5000)
    start_t = time.time()
    s.compute()
    s.wait()
    t_5000iter = time.time() - start_t

    assert t_1000iter < t_2000iter < t_5000iter, "Increase in bits does not increase time!"
예제 #9
0
def test_sloth_bits_time():
    import time
    s = sloth.Sloth(data=b'test', bits=512, iterations=1000)
    start_t = time.time()
    s.compute()
    s.wait()
    t_512bits = time.time() - start_t

    s = sloth.Sloth(data=b'test', bits=1024, iterations=1000)
    start_t = time.time()
    s.compute()
    s.wait()
    t_1024bits = time.time() - start_t

    s = sloth.Sloth(data=b'test', bits=2048, iterations=1000)
    start_t = time.time()
    s.compute()
    s.wait()
    t_2048bits = time.time() - start_t

    assert t_512bits < t_1024bits < t_2048bits, "Increase in bits does not increase time!"
예제 #10
0
def sloth_timing(bits, iterations):
    sum_comp = 0
    sum_veri = 0
    for i in range(LOOPS):
        print("Loop", i + 1, "of", LOOPS)
        s = sloth.Sloth(data=urandom(64), bits=bits, iterations=iterations)

        sum_comp += timed_task(s, 'compute')
        assert s.final_hash is not None
        for _ in range(VERIFICATION_LOOPS):
            sum_veri += timed_task(s, 'verify')
        if not s.valid:
            print("NOT VALID", "\n{}\n{}".format(s.final_hash, s.witness))
            print("USED INPUT ->", s.data)
    avg_comp = sum_comp / LOOPS
    avg_veri = sum_veri / (LOOPS + VERIFICATION_LOOPS)
    print("Avg. time:\n\tcomputation -> {}\n\tverification -> {}".format(
        avg_comp, avg_veri))
    if TIME_LOG:
        with open(TIME_LOG, 'a+') as logf:
            print(",{},{}".format(avg_comp, avg_veri), file=logf)