|
| 1 | +#include "vdf.h" |
| 2 | +#include "create_discriminant.h" |
| 3 | +#include "verifier.h" |
| 4 | + |
| 5 | +int segments = 7; |
| 6 | +int thread_count = 3; |
| 7 | + |
| 8 | +int gcd_base_bits=50; |
| 9 | +int gcd_128_max_iter=3; |
| 10 | + |
| 11 | +void CheckProof(integer& D, Proof& proof, uint64_t iteration) { |
| 12 | + form x = form::generator(D); |
| 13 | + std::vector<unsigned char> bytes; |
| 14 | + bytes.insert(bytes.end(), proof.y.begin(), proof.y.end()); |
| 15 | + bytes.insert(bytes.end(), proof.proof.begin(), proof.proof.end()); |
| 16 | + if (CheckProofOfTimeNWesolowski(D, x, bytes.data(), bytes.size(), iteration, proof.witness_type)) { |
| 17 | + std::cout << "Correct proof\n"; |
| 18 | + } else { |
| 19 | + std::cout << "Incorrect proof\n"; |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +int main() { |
| 24 | + debug_mode = true; |
| 25 | + if(hasAVX2()) |
| 26 | + { |
| 27 | + gcd_base_bits=63; |
| 28 | + gcd_128_max_iter=2; |
| 29 | + } |
| 30 | + std::vector<uint8_t> challenge_hash({0, 0, 1, 2, 3, 3, 4, 4}); |
| 31 | + integer D = CreateDiscriminant(challenge_hash, 1024); |
| 32 | + |
| 33 | + if (getenv( "warn_on_corruption_in_production" )!=nullptr) { |
| 34 | + warn_on_corruption_in_production=true; |
| 35 | + } |
| 36 | + assert(is_vdf_test); //assertions should be disabled in VDF_MODE==0 |
| 37 | + init_gmp(); |
| 38 | + allow_integer_constructor=true; //make sure the old gmp allocator isn't used |
| 39 | + set_rounding_mode(); |
| 40 | + |
| 41 | + integer L=root(-D, 4); |
| 42 | + form f=form::generator(D); |
| 43 | + |
| 44 | + bool stopped = false; |
| 45 | + fast_algorithm = false; |
| 46 | + two_weso = true; |
| 47 | + TwoWesolowskiCallback* weso = new TwoWesolowskiCallback(D); |
| 48 | + FastStorage* fast_storage = NULL; |
| 49 | + std::thread vdf_worker(repeated_square, f, D, L, weso, fast_storage, std::ref(stopped)); |
| 50 | + // Test 1 - 1 million iters. |
| 51 | + uint64_t iteration = 1000000; |
| 52 | + Proof proof = ProveTwoWeso(D, f, 1000000, 0, weso, 0, stopped); |
| 53 | + CheckProof(D, proof, iteration); |
| 54 | + // Test 2 - 15 million iters. |
| 55 | + iteration = 15000000; |
| 56 | + proof = ProveTwoWeso(D, f, iteration, 0, weso, 0, stopped); |
| 57 | + CheckProof(D, proof, iteration); |
| 58 | + // Test 3 - 100 million iters. |
| 59 | + iteration = 100000000; |
| 60 | + proof = ProveTwoWeso(D, f, iteration, 0, weso, 0, stopped); |
| 61 | + CheckProof(D, proof, iteration); |
| 62 | + // Test stopping gracefully. |
| 63 | + stopped = true; |
| 64 | + vdf_worker.join(); |
| 65 | + free(weso); |
| 66 | +} |
0 commit comments