Skip to content

Commit

Permalink
Bluebox fix. (#64)
Browse files Browse the repository at this point in the history
* Initial commit.

* Fix compile error.
  • Loading branch information
fchirica authored Mar 2, 2021
1 parent 5825ec0 commit 1a200b5
Show file tree
Hide file tree
Showing 4 changed files with 11 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 @@ -46,10 +47,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 @@ -59,7 +60,7 @@ int main(int argc, char const* argv[]) try
form proof_form = DeserializeForm(D, proof.proof.data(), proof.proof.size());
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
11 changes: 5 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 @@ -198,9 +198,8 @@ 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));

form f = DeserializeForm(D, (uint8_t *)initial_form_s, sizeof(initial_form_s));
// Tell client that I'm ready to get the challenges.
boost::asio::write(sock, boost::asio::buffer("OK", 2));

Expand All @@ -210,10 +209,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 1a200b5

Please sign in to comment.