Skip to content

Commit 7233821

Browse files
authored
Misc cosmetic changes (#202)
* Cosmetics: typo * Cosmetics: formatting * Cosmetics: unused var * Cosmetics: declaration grouping
1 parent 32319db commit 7233821

File tree

4 files changed

+29
-33
lines changed

4 files changed

+29
-33
lines changed

src/proof_common.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ const int B_bits = 264;
77
const int B_bytes = (B_bits + 7) / 8;
88

99

10-
// Generates a random psuedoprime using the hash and check method:
10+
// Generates a random pseudoprime using the hash and check method:
1111
// Randomly chooses x with bit-length `length`, then applies a mask
1212
// (for b in bitmask) { x |= (1 << b) }.
13-
// Then return x if it is a psuedoprime, otherwise repeat.
13+
// Then return x if it is a pseudoprime, otherwise repeat.
1414
integer HashPrime(std::vector<uint8_t> seed, int length, vector<int> bitmask) {
1515
assert (length % 8 == 0);
1616
std::vector<uint8_t> hash(picosha2::k_digest_size); // output of sha256

src/vdf.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,17 @@ bool two_weso = false;
8181

8282
//always works
8383
void repeated_square_original(vdf_original &vdfo, form& f, const integer& D, const integer& L, uint64 base, uint64 iterations, INUDUPLListener *nuduplListener) {
84-
vdf_original::form f_in,*f_res;
85-
f_in.a[0]=f.a.impl[0];
86-
f_in.b[0]=f.b.impl[0];
87-
f_in.c[0]=f.c.impl[0];
88-
f_res=&f_in;
84+
vdf_original::form f_in, *f_res;
85+
f_in.a[0] = f.a.impl[0];
86+
f_in.b[0] = f.b.impl[0];
87+
f_in.c[0] = f.c.impl[0];
88+
f_res = &f_in;
8989

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

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

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

174-
#ifdef VDF_TEST
174+
#ifdef VDF_TEST
175175
++num_iterations_slow;
176176
if (vdf_test_correctness) {
177177
assert(actual_iterations==0);

src/vdf_client.cpp

+19-23
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ using boost::asio::ip::tcp;
77
const int max_length = 2048;
88
std::mutex socket_mutex;
99

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

24+
uint8_t initial_form_s[BQFC_FORM_SIZE];
25+
2526
void WriteProof(uint64_t iteration, Proof& result, tcp::socket& sock) {
2627
// Writes the number of iterations
2728
uint8_t int_bytes[8];
@@ -78,13 +79,11 @@ void CreateAndWriteProofTwoWeso(integer& D, form f, uint64_t iters, TwoWesolowsk
7879
WriteProof(iters, result, sock);
7980
}
8081

81-
uint8_t initial_form_s[BQFC_FORM_SIZE];
82-
8382
void InitSession(tcp::socket& sock) {
8483
boost::system::error_code error;
8584

86-
memset(disc,0x00,sizeof(disc)); // For null termination
87-
memset(disc_size,0x00,sizeof(disc_size)); // For null termination
85+
memset(disc, 0x00, sizeof(disc)); // For null termination
86+
memset(disc_size, 0x00, sizeof(disc_size)); // For null termination
8887

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

102-
if (getenv( "warn_on_corruption_in_production" )!=nullptr) {
103-
warn_on_corruption_in_production=true;
101+
if (getenv("warn_on_corruption_in_production") != nullptr) {
102+
warn_on_corruption_in_production = true;
104103
}
105104
if (is_vdf_test) {
106-
PrintInfo( "=== Test mode ===" );
105+
PrintInfo("=== Test mode ===");
107106
}
108107
if (warn_on_corruption_in_production) {
109-
PrintInfo( "=== Warn on corruption enabled ===" );
108+
PrintInfo("=== Warn on corruption enabled ===");
110109
}
111110
assert(is_vdf_test); //assertions should be disabled in VDF_MODE==0
112111
set_rounding_mode();
@@ -123,7 +122,7 @@ void FinishSession(tcp::socket& sock) {
123122
boost::asio::write(sock, boost::asio::buffer("STOP", 4));
124123

125124
char ack[5];
126-
memset(ack,0x00,sizeof(ack));
125+
memset(ack, 0x00, sizeof(ack));
127126
boost::asio::read(sock, boost::asio::buffer(ack, 3), error);
128127
assert (strncmp(ack, "ACK", 3) == 0);
129128
} catch (std::exception& e) {
@@ -149,7 +148,7 @@ void SessionFastAlgorithm(tcp::socket& sock) {
149148
InitSession(sock);
150149
try {
151150
integer D(disc);
152-
integer L=root(-D, 4);
151+
integer L = root(-D, 4);
153152
PrintInfo("Discriminant = " + to_string(D.impl));
154153
form f = DeserializeForm(D, initial_form_s, sizeof(initial_form_s));
155154
PrintInfo("Initial form: " + to_string(f.a.impl) + " " + to_string(f.b.impl));
@@ -197,7 +196,7 @@ void SessionOneWeso(tcp::socket& sock) {
197196
InitSession(sock);
198197
try {
199198
integer D(disc);
200-
integer L=root(-D, 4);
199+
integer L = root(-D, 4);
201200
PrintInfo("Discriminant = " + to_string(D.impl));
202201
form f = DeserializeForm(D, initial_form_s, sizeof(initial_form_s));
203202
// Tell client that I'm ready to get the challenges.
@@ -233,7 +232,7 @@ void SessionTwoWeso(tcp::socket& sock) {
233232
InitSession(sock);
234233
try {
235234
integer D(disc);
236-
integer L=root(-D, 4);
235+
integer L = root(-D, 4);
237236
PrintInfo("Discriminant = " + to_string(D.impl));
238237
form f = DeserializeForm(D, initial_form_s, sizeof(initial_form_s));
239238

@@ -308,22 +307,19 @@ void SessionTwoWeso(tcp::socket& sock) {
308307
FinishSession(sock);
309308
}
310309

311-
int gcd_base_bits=50;
312-
int gcd_128_max_iter=3;
310+
int gcd_base_bits = 50;
311+
int gcd_128_max_iter = 3;
313312

314-
int main(int argc, char* argv[]) try
315-
{
313+
int main(int argc, char* argv[]) try {
316314
init_gmp();
317-
if (argc != 4)
318-
{
315+
if (argc != 4) {
319316
std::cerr << "Usage: ./vdf_client <host> <port> <counter>\n";
320317
return 1;
321318
}
322319

323-
if(hasAVX2())
324-
{
325-
gcd_base_bits=63;
326-
gcd_128_max_iter=2;
320+
if(hasAVX2()) {
321+
gcd_base_bits = 63;
322+
gcd_128_max_iter = 2;
327323
}
328324

329325
boost::asio::io_service io_service;

src/vdf_fast.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,7 @@ class INUDUPLListener{
10041004

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

0 commit comments

Comments
 (0)