Skip to content

Commit

Permalink
Misc cosmetic changes (#202)
Browse files Browse the repository at this point in the history
* Cosmetics: typo

* Cosmetics: formatting

* Cosmetics: unused var

* Cosmetics: declaration grouping
  • Loading branch information
xearl4 authored Oct 8, 2024
1 parent 32319db commit 7233821
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 33 deletions.
4 changes: 2 additions & 2 deletions src/proof_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ const int B_bits = 264;
const int B_bytes = (B_bits + 7) / 8;


// Generates a random psuedoprime using the hash and check method:
// Generates a random pseudoprime using the hash and check method:
// Randomly chooses x with bit-length `length`, then applies a mask
// (for b in bitmask) { x |= (1 << b) }.
// Then return x if it is a psuedoprime, otherwise repeat.
// Then return x if it is a pseudoprime, otherwise repeat.
integer HashPrime(std::vector<uint8_t> seed, int length, vector<int> bitmask) {
assert (length % 8 == 0);
std::vector<uint8_t> hash(picosha2::k_digest_size); // output of sha256
Expand Down
14 changes: 7 additions & 7 deletions src/vdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,17 @@ bool two_weso = false;

//always works
void repeated_square_original(vdf_original &vdfo, form& f, const integer& D, const integer& L, uint64 base, uint64 iterations, INUDUPLListener *nuduplListener) {
vdf_original::form f_in,*f_res;
f_in.a[0]=f.a.impl[0];
f_in.b[0]=f.b.impl[0];
f_in.c[0]=f.c.impl[0];
f_res=&f_in;
vdf_original::form f_in, *f_res;
f_in.a[0] = f.a.impl[0];
f_in.b[0] = f.b.impl[0];
f_in.c[0] = f.c.impl[0];
f_res = &f_in;

for (uint64_t i=0; i < iterations; i++) {
f_res = vdfo.square(*f_res);

if(nuduplListener!=NULL)
nuduplListener->OnIteration(NL_FORM,f_res,base+i);
nuduplListener->OnIteration(NL_FORM, f_res, base + i);
}

mpz_set(f.a.impl, f_res->a);
Expand Down Expand Up @@ -171,7 +171,7 @@ void repeated_square(uint64_t iterations, form f, const integer& D, const intege
//this will also reduce f if the fast algorithm terminated because it was too big
repeated_square_original(*weso->vdfo, f, D, L, num_iterations+actual_iterations, 1, weso);

#ifdef VDF_TEST
#ifdef VDF_TEST
++num_iterations_slow;
if (vdf_test_correctness) {
assert(actual_iterations==0);
Expand Down
42 changes: 19 additions & 23 deletions src/vdf_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ using boost::asio::ip::tcp;
const int max_length = 2048;
std::mutex socket_mutex;

int process_number;
// Segments are 2^16, 2^18, ..., 2^30
// Best case it'll be able to proof for up to 2^36 due to 64-wesolowski restriction.
int segments = 8;
Expand All @@ -22,6 +21,8 @@ char disc[350];
char disc_size[5];
int disc_int_size;

uint8_t initial_form_s[BQFC_FORM_SIZE];

void WriteProof(uint64_t iteration, Proof& result, tcp::socket& sock) {
// Writes the number of iterations
uint8_t int_bytes[8];
Expand Down Expand Up @@ -78,13 +79,11 @@ void CreateAndWriteProofTwoWeso(integer& D, form f, uint64_t iters, TwoWesolowsk
WriteProof(iters, result, sock);
}

uint8_t initial_form_s[BQFC_FORM_SIZE];

void InitSession(tcp::socket& sock) {
boost::system::error_code error;

memset(disc,0x00,sizeof(disc)); // For null termination
memset(disc_size,0x00,sizeof(disc_size)); // For null termination
memset(disc, 0x00, sizeof(disc)); // For null termination
memset(disc_size, 0x00, sizeof(disc_size)); // For null termination

boost::asio::read(sock, boost::asio::buffer(disc_size, 3), error);
disc_int_size = atoi(disc_size);
Expand All @@ -99,14 +98,14 @@ void InitSession(tcp::socket& sock) {
else if (error)
throw boost::system::system_error(error); // Some other error.

if (getenv( "warn_on_corruption_in_production" )!=nullptr) {
warn_on_corruption_in_production=true;
if (getenv("warn_on_corruption_in_production") != nullptr) {
warn_on_corruption_in_production = true;
}
if (is_vdf_test) {
PrintInfo( "=== Test mode ===" );
PrintInfo("=== Test mode ===");
}
if (warn_on_corruption_in_production) {
PrintInfo( "=== Warn on corruption enabled ===" );
PrintInfo("=== Warn on corruption enabled ===");
}
assert(is_vdf_test); //assertions should be disabled in VDF_MODE==0
set_rounding_mode();
Expand All @@ -123,7 +122,7 @@ void FinishSession(tcp::socket& sock) {
boost::asio::write(sock, boost::asio::buffer("STOP", 4));

char ack[5];
memset(ack,0x00,sizeof(ack));
memset(ack, 0x00, sizeof(ack));
boost::asio::read(sock, boost::asio::buffer(ack, 3), error);
assert (strncmp(ack, "ACK", 3) == 0);
} catch (std::exception& e) {
Expand All @@ -149,7 +148,7 @@ void SessionFastAlgorithm(tcp::socket& sock) {
InitSession(sock);
try {
integer D(disc);
integer L=root(-D, 4);
integer L = root(-D, 4);
PrintInfo("Discriminant = " + to_string(D.impl));
form f = DeserializeForm(D, initial_form_s, sizeof(initial_form_s));
PrintInfo("Initial form: " + to_string(f.a.impl) + " " + to_string(f.b.impl));
Expand Down Expand Up @@ -197,7 +196,7 @@ void SessionOneWeso(tcp::socket& sock) {
InitSession(sock);
try {
integer D(disc);
integer L=root(-D, 4);
integer L = root(-D, 4);
PrintInfo("Discriminant = " + to_string(D.impl));
form f = DeserializeForm(D, initial_form_s, sizeof(initial_form_s));
// Tell client that I'm ready to get the challenges.
Expand Down Expand Up @@ -233,7 +232,7 @@ void SessionTwoWeso(tcp::socket& sock) {
InitSession(sock);
try {
integer D(disc);
integer L=root(-D, 4);
integer L = root(-D, 4);
PrintInfo("Discriminant = " + to_string(D.impl));
form f = DeserializeForm(D, initial_form_s, sizeof(initial_form_s));

Expand Down Expand Up @@ -308,22 +307,19 @@ void SessionTwoWeso(tcp::socket& sock) {
FinishSession(sock);
}

int gcd_base_bits=50;
int gcd_128_max_iter=3;
int gcd_base_bits = 50;
int gcd_128_max_iter = 3;

int main(int argc, char* argv[]) try
{
int main(int argc, char* argv[]) try {
init_gmp();
if (argc != 4)
{
if (argc != 4) {
std::cerr << "Usage: ./vdf_client <host> <port> <counter>\n";
return 1;
}

if(hasAVX2())
{
gcd_base_bits=63;
gcd_128_max_iter=2;
if(hasAVX2()) {
gcd_base_bits = 63;
gcd_128_max_iter = 2;
}

boost::asio::io_service io_service;
Expand Down
2 changes: 1 addition & 1 deletion src/vdf_fast.h
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,7 @@ class INUDUPLListener{

//this should never have an infinite loop
//the gcd loops all have maximum counters after which they'll error out, and the thread_state loops also have a maximum spin counter
void repeated_square_fast_work(square_state_type &square_state,bool is_slave, uint64 base, uint64 iterations, INUDUPLListener *nuduplListener) {
void repeated_square_fast_work(square_state_type &square_state, bool is_slave, uint64 base, uint64 iterations, INUDUPLListener *nuduplListener) {
c_thread_state.reset();
c_thread_state.is_slave=is_slave;
c_thread_state.pairindex=square_state.pairindex;
Expand Down

0 comments on commit 7233821

Please sign in to comment.