Example #1
0
    def test_many_generators(self):
        def all_powers(e):
            d = e.discriminant()
            e0 = e
            items = []
            while e0 not in items:
                items.append(e0)
                self.assertEqual(e0 * e0, e0.square())
                e0 *= e
                e0 = e0.normalized()
                if e0.discriminant() != d:
                    import pdb
                    pdb.set_trace()
            return items

        for _ in range(1000):
            D = -7 - _ * 8
            e_id = ClassGroup.identity_for_discriminant(D)
            self.assertEqual(e_id, (1, 1, 2 + 2 * _))
            e_id_inv = e_id.inverse()
            self.assertEqual(e_id, e_id_inv)
            e0 = ClassGroup.from_ab_discriminant(2, 1, D)
            e1 = e0.inverse()
            p0 = all_powers(e0)
            p1 = all_powers(e1)
            assert len(p0) == len(p1)
            assert e_id == p0[-1]
            assert e_id == p1[-1]
            for _0, _1 in zip(p0, p1):
                _ = _0 * _1
                assert _ == e_id
            print("discriminant = %d; group order = %d" % (D, len(p0)))
Example #2
0
def bench_pietrzak():
    iterations = 10000
    discriminant_length = 512
    discriminant = create_discriminant(b"seed", discriminant_length)
    delta = 8

    x = ClassGroup.from_ab_discriminant(2, 1, discriminant)
    powers_to_calculate = proof_pietrzak.cache_indeces_for_count(iterations)
    start_t = time.time() * time_multiplier
    powers = iterate_squarings(x, powers_to_calculate)
    vdf_time = round(time.time() * time_multiplier - start_t)

    y = powers[iterations]
    identity = ClassGroup.identity_for_discriminant(discriminant)

    start_t = time.time() * time_multiplier
    start_bench()
    for _ in range(5):
        proof = proof_pietrzak.generate_proof(x, iterations, delta, y, powers,
                                              identity, generate_r_value,
                                              discriminant_length)
    end_bench(
        "Pietrzak  " + str(discriminant_length) + "b class group, " +
        str(iterations) + " iterations, proof", 10)
    proof_time = round((time.time() * time_multiplier - start_t) / 10)
    print("    - Percentage of VDF time:", (proof_time / vdf_time) * 100, "%")

    start_bench()
    for _ in range(10):
        assert (proof_pietrzak.verify_proof(x, y, proof, iterations, delta,
                                            generate_r_value,
                                            discriminant_length))
    end_bench(
        "Pietrzak " + str(discriminant_length) + "b class group, " +
        str(iterations) + " iterations, verification", 10)
Example #3
0
 def test_inverse(self):
     for _ in range(1000):
         D = -7 - _ * 8
         e_id = ClassGroup.identity_for_discriminant(D)
         e_gen = ClassGroup.from_ab_discriminant(2, 1, D)
         e_gen_inv = e_gen.inverse()
         e_prod = e_gen * e_gen_inv
         self.assertEqual(e_prod, e_id)
Example #4
0
 def test_pow(self):
     for _ in range(100):
         D = -7 - _ * 8
         e_gen = ClassGroup.from_ab_discriminant(2, 1, D)
         p = ClassGroup.identity_for_discriminant(D)
         for _ in range(10):
             self.assertEqual(pow(e_gen, _), p)
             p *= e_gen
Example #5
0
 def test_generator_element(self):
     D = -103
     e_id = ClassGroup.identity_for_discriminant(D)
     self.assertEqual(e_id.discriminant(), D)
     self.assertEqual(e_id, (1, 1, 26))
     e = ClassGroup.from_ab_discriminant(2, 1, D)
     self.assertEqual(e.discriminant(), D)
     self.assertEqual(e, (2, 1, 13))
     e_inv = e.inverse()
     self.assertEqual(e_inv.discriminant(), D)
     self.assertEqual(e_inv, (2, -1, 13))
     self.assertEqual(e * e_inv, e_id)
     e2 = e.square()
     self.assertEqual(e2, (4, -3, 7))
     assert e2 == e * e
     e4 = e2.square()
     self.assertEqual(e4, (13, 1, 2))
     self.assertEqual(e4, e2 * e2)
Example #6
0
def bench_wesolowski():
    iterations = 10000
    discriminant_length = 512
    discriminant = create_discriminant(b"seed", discriminant_length)
    L, k, _ = proof_wesolowski.approximate_parameters(iterations)

    x = ClassGroup.from_ab_discriminant(2, 1, discriminant)
    powers_to_calculate = [
        i * k * L for i in range(0,
                                 math.ceil(iterations / (k * L)) + 1)
    ]
    powers_to_calculate += [iterations]
    start_t = time.time() * time_multiplier
    powers = iterate_squarings(x, powers_to_calculate)
    vdf_time = round(time.time() * time_multiplier - start_t)

    y = powers[iterations]
    identity = ClassGroup.identity_for_discriminant(discriminant)

    start_t = time.time() * time_multiplier
    start_bench()
    for _ in range(5):
        proof = proof_wesolowski.generate_proof(identity, x, y, iterations, k,
                                                L, powers)
    end_bench(
        "Wesolowski  " + str(discriminant_length) + "b class group, " +
        str(iterations) + " iterations, proof", 5)
    proof_time = round((time.time() * time_multiplier - start_t) / 5)
    print("    - Percentage of VDF time:", (proof_time / vdf_time) * 100, "%")

    start_bench()
    for _ in range(10):
        assert (proof_wesolowski.verify_proof(x, y, proof, iterations))
    end_bench(
        "Wesolowski " + str(discriminant_length) + "b class group, " +
        str(iterations) + " iterations, verification", 10)
Example #7
0
 def test_identity(self):
     for _ in range(1000):
         D = -7 - _ * 8
         e_id = ClassGroup.identity_for_discriminant(D)
         e_prod = e_id * e_id
         self.assertEqual(e_prod, e_id)