-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Move new algorithm into chiavdf * Fix prover test, move FAST_MACHINE define in makefile * Decide at runtime if to use FAST_MACHINE * Better support long VDF runs * Add documentation * Add Lipa's document * Catch some overflows * Move prover test * Attempt to catch runtime error. * Initial commit 1weso * Let timelord decide between 1weso and nweso use. * Typos * 1weso: Ignore all iters, except for 1st one and stop signal * Fix typos. * Initial commit refactor * Small reorg. * Added back pybind submodules * Pin pybind11 to v.2.5.0 * Update gitignore to master * Fix verifier test * Catch some race conditions. * 2weso working! * Fast Nweso working * Keep only 1 test. * Fix module name. * Try to fix test. * Some fixes. * Fix typo. * Better stopping. * LGTMs * LGTM - add const references. * Comment flake8/mypy since there's no python left. * Document running the vdf_client tests. * Try to catch more LGTMs. * Remove some const ref, as it experimentally works faster. * Try better locking. * Fix 1weso test. * Typo. Co-authored-by: Gene Hoffman <[email protected]>
- Loading branch information
Showing
29 changed files
with
1,976 additions
and
957 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ __pycache__/ | |
|
||
# Generated assembly file | ||
/asm_compiled.s | ||
/avx2_asm_compiled.s | ||
|
||
# Makefiles | ||
CMakeFiles/ | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include "vdf.h" | ||
#include "create_discriminant.h" | ||
#include "verifier.h" | ||
|
||
int segments = 7; | ||
int thread_count = 3; | ||
|
||
Proof CreateProof(ProverManager& pm, uint64_t iteration) { | ||
return pm.Prove(iteration); | ||
} | ||
|
||
int gcd_base_bits=50; | ||
int gcd_128_max_iter=3; | ||
|
||
int main() { | ||
debug_mode = true; | ||
if(hasAVX2()) | ||
{ | ||
gcd_base_bits=63; | ||
gcd_128_max_iter=2; | ||
} | ||
std::vector<uint8_t> challenge_hash({0, 0, 1, 2, 3, 3, 4, 4}); | ||
integer D = CreateDiscriminant(challenge_hash, 1024); | ||
|
||
if (getenv( "warn_on_corruption_in_production" )!=nullptr) { | ||
warn_on_corruption_in_production=true; | ||
} | ||
assert(is_vdf_test); //assertions should be disabled in VDF_MODE==0 | ||
init_gmp(); | ||
allow_integer_constructor=true; //make sure the old gmp allocator isn't used | ||
set_rounding_mode(); | ||
|
||
integer L=root(-D, 4); | ||
form f=form::generator(D); | ||
|
||
bool stopped = false; | ||
fast_algorithm = false; | ||
|
||
uint64_t iter = 1000000; | ||
OneWesolowskiCallback* weso = new OneWesolowskiCallback(D, iter); | ||
FastStorage* fast_storage = NULL; | ||
std::thread vdf_worker(repeated_square, f, D, L, weso, fast_storage, std::ref(stopped)); | ||
Proof proof = ProveOneWesolowski(iter, D, (OneWesolowskiCallback*)weso, stopped); | ||
stopped = true; | ||
vdf_worker.join(); | ||
free(weso); | ||
|
||
bool is_valid; | ||
form x_init = form::generator(D); | ||
form y, proof_form; | ||
y = form::from_abd( | ||
ConvertBytesToInt(proof.y.data(), 0, 129), | ||
ConvertBytesToInt(proof.y.data(), 129, 2*129), | ||
D | ||
); | ||
proof_form = form::from_abd( | ||
ConvertBytesToInt(proof.proof.data(), 0, 65), | ||
ConvertBytesToInt(proof.proof.data(), 65, 2*65), | ||
D | ||
); | ||
VerifyWesolowskiProof(D, x_init, y, proof_form, iter, is_valid); | ||
std::cout << "Verify result: " << is_valid << "\n"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#include "vdf.h" | ||
#include "create_discriminant.h" | ||
#include "verifier.h" | ||
|
||
int segments = 7; | ||
int thread_count = 3; | ||
|
||
int gcd_base_bits=50; | ||
int gcd_128_max_iter=3; | ||
|
||
void CheckProof(integer& D, Proof& proof, uint64_t iteration) { | ||
form x = form::generator(D); | ||
std::vector<unsigned char> bytes; | ||
bytes.insert(bytes.end(), proof.y.begin(), proof.y.end()); | ||
bytes.insert(bytes.end(), proof.proof.begin(), proof.proof.end()); | ||
if (CheckProofOfTimeNWesolowski(D, x, bytes.data(), bytes.size(), iteration, proof.witness_type)) { | ||
std::cout << "Correct proof\n"; | ||
} else { | ||
std::cout << "Incorrect proof\n"; | ||
} | ||
} | ||
|
||
int main() { | ||
debug_mode = true; | ||
if(hasAVX2()) | ||
{ | ||
gcd_base_bits=63; | ||
gcd_128_max_iter=2; | ||
} | ||
std::vector<uint8_t> challenge_hash({0, 0, 1, 2, 3, 3, 4, 4}); | ||
integer D = CreateDiscriminant(challenge_hash, 1024); | ||
|
||
if (getenv( "warn_on_corruption_in_production" )!=nullptr) { | ||
warn_on_corruption_in_production=true; | ||
} | ||
assert(is_vdf_test); //assertions should be disabled in VDF_MODE==0 | ||
init_gmp(); | ||
allow_integer_constructor=true; //make sure the old gmp allocator isn't used | ||
set_rounding_mode(); | ||
|
||
integer L=root(-D, 4); | ||
form f=form::generator(D); | ||
|
||
bool stopped = false; | ||
fast_algorithm = false; | ||
two_weso = true; | ||
TwoWesolowskiCallback* weso = new TwoWesolowskiCallback(D); | ||
FastStorage* fast_storage = NULL; | ||
std::thread vdf_worker(repeated_square, f, D, L, weso, fast_storage, std::ref(stopped)); | ||
// Test 1 - 1 million iters. | ||
uint64_t iteration = 1000000; | ||
Proof proof = ProveTwoWeso(D, f, 1000000, 0, weso, 0, stopped); | ||
CheckProof(D, proof, iteration); | ||
// Test 2 - 15 million iters. | ||
iteration = 15000000; | ||
proof = ProveTwoWeso(D, f, iteration, 0, weso, 0, stopped); | ||
CheckProof(D, proof, iteration); | ||
// Test 3 - 100 million iters. | ||
iteration = 100000000; | ||
proof = ProveTwoWeso(D, f, iteration, 0, weso, 0, stopped); | ||
CheckProof(D, proof, iteration); | ||
// Test stopping gracefully. | ||
stopped = true; | ||
vdf_worker.join(); | ||
free(weso); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.