Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
fchirica committed Feb 1, 2021
1 parent 1201c5c commit 4baf27c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
7 changes: 4 additions & 3 deletions src/1weso_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "verifier.h"

#include <atomic>
#include <cassert>

int segments = 7;
int thread_count = 3;
Expand Down Expand Up @@ -45,10 +46,10 @@ int main(int argc, char const* argv[]) try
fast_algorithm = false;

uint64_t iter = iter_multiplier;
OneWesolowskiCallback weso(D, iter);
OneWesolowskiCallback weso(D, f, iter);
FastStorage* fast_storage = nullptr;
std::thread vdf_worker(repeated_square, f, D, L, &weso, fast_storage, std::ref(stopped));
Proof const proof = ProveOneWesolowski(iter, D, &weso, stopped);
Proof const proof = ProveOneWesolowski(iter, D, f, &weso, stopped);
stopped = true;
vdf_worker.join();

Expand All @@ -67,7 +68,7 @@ int main(int argc, char const* argv[]) try
);
VerifyWesolowskiProof(D, x_init, y, proof_form, iter, is_valid);
std::cout << "Verify result: " << is_valid << "\n";
return is_valid ? 0 : 1;
assert(is_valid);
}
catch (std::exception const& e) {
std::cerr << "Exception " << e.what() << '\n';
Expand Down
3 changes: 1 addition & 2 deletions src/callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class WesolowskiCallback :public INUDUPLListener {

class OneWesolowskiCallback: public WesolowskiCallback {
public:
OneWesolowskiCallback(integer& D, uint64_t wanted_iter) : WesolowskiCallback(D) {
OneWesolowskiCallback(integer& D, form& f, uint64_t wanted_iter) : WesolowskiCallback(D) {
uint32_t k, l;
this->wanted_iter = wanted_iter;
if (wanted_iter >= (1 << 16)) {
Expand All @@ -84,7 +84,6 @@ class OneWesolowskiCallback: public WesolowskiCallback {
kl = k * l;
uint64_t space_needed = wanted_iter / (k * l) + 100;
forms.reset(new form[space_needed]);
form f = form::generator(D);
forms[0] = f;
}

Expand Down
3 changes: 1 addition & 2 deletions src/vdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,12 @@ void repeated_square(form f, const integer& D, const integer& L,
#endif
}

Proof ProveOneWesolowski(uint64_t iters, integer& D, OneWesolowskiCallback* weso,
Proof ProveOneWesolowski(uint64_t iters, integer& D, form f, OneWesolowskiCallback* weso,
std::atomic<bool>& stopped)
{
while (weso->iterations < iters) {
this_thread::sleep_for(1s);
}
form f = form::generator(D);
Segment sg(
/*start=*/0,
/*length=*/iters,
Expand Down
15 changes: 9 additions & 6 deletions src/vdf_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ void CreateAndWriteProof(ProverManager& pm, uint64_t iteration, std::atomic<bool
WriteProof(iteration, result, sock);
}

void CreateAndWriteProofOneWeso(uint64_t iters, integer& D, OneWesolowskiCallback* weso, std::atomic<bool>& stop_signal, tcp::socket& sock) {
Proof result = ProveOneWesolowski(iters, D, weso, stop_signal);
void CreateAndWriteProofOneWeso(uint64_t iters, integer& D, form f, OneWesolowskiCallback* weso, std::atomic<bool>& stop_signal, tcp::socket& sock) {
Proof result = ProveOneWesolowski(iters, D, f, weso, stop_signal);
if (stop_signal) {
PrintInfo("Got stop signal before completing the proof!");
return ;
Expand Down Expand Up @@ -216,9 +216,12 @@ void SessionOneWeso(tcp::socket& sock) {
try {
integer D(disc);
integer L=root(-D, 4);
form f=form::generator(D);
PrintInfo("Discriminant = " + to_string(D.impl));

integer init_A(form_a);
PrintInfo("Initial A: " + to_string(init_A.impl));
integer init_B(form_b);
PrintInfo("Initial B: " + to_string(init_B.impl));
form f = form::from_abd(init_A, init_B, D);
// Tell client that I'm ready to get the challenges.
boost::asio::write(sock, boost::asio::buffer("OK", 2));

Expand All @@ -228,10 +231,10 @@ void SessionOneWeso(tcp::socket& sock) {
return;
}
std::atomic<bool> stopped(false);
WesolowskiCallback* weso = new OneWesolowskiCallback(D, iter);
WesolowskiCallback* weso = new OneWesolowskiCallback(D, f, iter);
FastStorage* fast_storage = NULL;
std::thread vdf_worker(repeated_square, f, std::ref(D), std::ref(L), weso, fast_storage, std::ref(stopped));
std::thread th_prover(CreateAndWriteProofOneWeso, iter, std::ref(D), (OneWesolowskiCallback*)weso, std::ref(stopped), std::ref(sock));
std::thread th_prover(CreateAndWriteProofOneWeso, iter, std::ref(D), f, (OneWesolowskiCallback*)weso, std::ref(stopped), std::ref(sock));
iter = ReadIteration(sock);
while (iter != 0) {
std::cout << "Warning: did not receive stop signal\n";
Expand Down

0 comments on commit 4baf27c

Please sign in to comment.