diff --git a/src/gtest/test_merkletree.cpp b/src/gtest/test_merkletree.cpp index 67b08030f..23c39c044 100644 --- a/src/gtest/test_merkletree.cpp +++ b/src/gtest/test_merkletree.cpp @@ -143,7 +143,7 @@ void test_tree( size_t path_index = convertVectorToInt(path.index); commitment.bits.fill_with_bits(pb, bit_vector(commitment_bv)); - positions.fill_with_bits_of_ulong(pb, path_index); + positions.fill_with_bits_of_uint64(pb, path_index); authvars.generate_r1cs_witness(path_index, path.authentication_path); auth.generate_r1cs_witness(); diff --git a/src/snark/libsnark/algebra/curves/alt_bn128/alt_bn128_g1.cpp b/src/snark/libsnark/algebra/curves/alt_bn128/alt_bn128_g1.cpp index bf7f43d6f..2c6206056 100644 --- a/src/snark/libsnark/algebra/curves/alt_bn128/alt_bn128_g1.cpp +++ b/src/snark/libsnark/algebra/curves/alt_bn128/alt_bn128_g1.cpp @@ -10,8 +10,8 @@ namespace libsnark { #ifdef PROFILE_OP_COUNTS -long long alt_bn128_G1::add_cnt = 0; -long long alt_bn128_G1::dbl_cnt = 0; +int64_t alt_bn128_G1::add_cnt = 0; +int64_t alt_bn128_G1::dbl_cnt = 0; #endif std::vector alt_bn128_G1::wnaf_window_table; diff --git a/src/snark/libsnark/algebra/curves/alt_bn128/alt_bn128_g1.hpp b/src/snark/libsnark/algebra/curves/alt_bn128/alt_bn128_g1.hpp index da11a2e8c..7053fe688 100644 --- a/src/snark/libsnark/algebra/curves/alt_bn128/alt_bn128_g1.hpp +++ b/src/snark/libsnark/algebra/curves/alt_bn128/alt_bn128_g1.hpp @@ -20,8 +20,8 @@ std::istream& operator>>(std::istream &, alt_bn128_G1&); class alt_bn128_G1 { public: #ifdef PROFILE_OP_COUNTS - static long long add_cnt; - static long long dbl_cnt; + static int64_t add_cnt; + static int64_t dbl_cnt; #endif static std::vector wnaf_window_table; static std::vector fixed_base_exp_window_table; diff --git a/src/snark/libsnark/algebra/curves/alt_bn128/alt_bn128_g2.cpp b/src/snark/libsnark/algebra/curves/alt_bn128/alt_bn128_g2.cpp index c4152e437..4b592e804 100644 --- a/src/snark/libsnark/algebra/curves/alt_bn128/alt_bn128_g2.cpp +++ b/src/snark/libsnark/algebra/curves/alt_bn128/alt_bn128_g2.cpp @@ -10,8 +10,8 @@ namespace libsnark { #ifdef PROFILE_OP_COUNTS -long long alt_bn128_G2::add_cnt = 0; -long long alt_bn128_G2::dbl_cnt = 0; +int64_t alt_bn128_G2::add_cnt = 0; +int64_t alt_bn128_G2::dbl_cnt = 0; #endif std::vector alt_bn128_G2::wnaf_window_table; diff --git a/src/snark/libsnark/algebra/curves/alt_bn128/alt_bn128_g2.hpp b/src/snark/libsnark/algebra/curves/alt_bn128/alt_bn128_g2.hpp index a996a2d1a..d6fa6a10d 100644 --- a/src/snark/libsnark/algebra/curves/alt_bn128/alt_bn128_g2.hpp +++ b/src/snark/libsnark/algebra/curves/alt_bn128/alt_bn128_g2.hpp @@ -20,8 +20,8 @@ std::istream& operator>>(std::istream &, alt_bn128_G2&); class alt_bn128_G2 { public: #ifdef PROFILE_OP_COUNTS - static long long add_cnt; - static long long dbl_cnt; + static int64_t add_cnt; + static int64_t dbl_cnt; #endif static std::vector wnaf_window_table; static std::vector fixed_base_exp_window_table; diff --git a/src/snark/libsnark/algebra/evaluation_domain/domains/basic_radix2_domain_aux.tcc b/src/snark/libsnark/algebra/evaluation_domain/domains/basic_radix2_domain_aux.tcc index 138b82dbc..79f2ffec7 100644 --- a/src/snark/libsnark/algebra/evaluation_domain/domains/basic_radix2_domain_aux.tcc +++ b/src/snark/libsnark/algebra/evaluation_domain/domains/basic_radix2_domain_aux.tcc @@ -74,11 +74,11 @@ void _basic_serial_radix2_FFT(std::vector &a, const FieldT &omega) template void _basic_parallel_radix2_FFT_inner(std::vector &a, const FieldT &omega, const size_t log_cpus) { - const size_t num_cpus = 1ul< &a, const FieldT &omeg std::vector > tmp(num_cpus); for (size_t j = 0; j < num_cpus; ++j) { - tmp[j].resize(1ul<<(log_m-log_cpus), FieldT::zero()); + tmp[j].resize(UINT64_C(1)<<(log_m-log_cpus), FieldT::zero()); } #ifdef MULTICORE @@ -102,7 +102,7 @@ void _basic_parallel_radix2_FFT_inner(std::vector &a, const FieldT &omeg const FieldT omega_step = omega^(j<<(log_m - log_cpus)); FieldT elt = FieldT::one(); - for (size_t i = 0; i < 1ul<<(log_m - log_cpus); ++i) + for (size_t i = 0; i < UINT64_C(1)<<(log_m - log_cpus); ++i) { for (size_t s = 0; s < num_cpus; ++s) { @@ -135,7 +135,7 @@ void _basic_parallel_radix2_FFT_inner(std::vector &a, const FieldT &omeg #endif for (size_t i = 0; i < num_cpus; ++i) { - for (size_t j = 0; j < 1ul<<(log_m - log_cpus); ++j) + for (size_t j = 0; j < UINT64_C(1)<<(log_m - log_cpus); ++j) { // now: i = idx >> (log_m - log_cpus) and j = idx % (1u << (log_m - log_cpus)), for idx = ((i<<(log_m-log_cpus))+j) % (1u << log_m) a[(j< > get_evaluation_domain(const size_t m } else { - const size_t big = 1ul<<(log2(min_size)-1); + const size_t big = UINT64_C(1)<<(log2(min_size)-1); const size_t small = min_size - big; - const size_t rounded_small = (1ul< FieldT power(const FieldT &base, const bigint &exponent); template -FieldT power(const FieldT &base, const unsigned long exponent); +FieldT power(const FieldT &base, const uint64_t exponent); } // libsnark diff --git a/src/snark/libsnark/algebra/exponentiation/exponentiation.tcc b/src/snark/libsnark/algebra/exponentiation/exponentiation.tcc index dd557eb12..5c775abde 100644 --- a/src/snark/libsnark/algebra/exponentiation/exponentiation.tcc +++ b/src/snark/libsnark/algebra/exponentiation/exponentiation.tcc @@ -43,7 +43,7 @@ FieldT power(const FieldT &base, const bigint &exponent) } template -FieldT power(const FieldT &base, const unsigned long exponent) +FieldT power(const FieldT &base, const uint64_t exponent) { return power(base, bigint<1>(exponent)); } diff --git a/src/snark/libsnark/algebra/fields/bigint.hpp b/src/snark/libsnark/algebra/fields/bigint.hpp index 50f78b780..d17e9a7bb 100644 --- a/src/snark/libsnark/algebra/fields/bigint.hpp +++ b/src/snark/libsnark/algebra/fields/bigint.hpp @@ -33,7 +33,7 @@ public: mp_limb_t data[n] = {0}; bigint() = default; - bigint(const unsigned long x); /// Initialize from a small integer + bigint(const uint64_t x); /// Initalize from a small integer bigint(const char* s); /// Initialize from a string containing an integer in decimal notation bigint(const mpz_t r); /// Initialize from MPZ element @@ -46,7 +46,7 @@ public: size_t max_bits() const { return n * GMP_NUMB_BITS; } size_t num_bits() const; - unsigned long as_ulong() const; /* return the last limb of the integer */ + uint64_t as_uint64() const; /* return the last limb of the integer */ void to_mpz(mpz_t r) const; bool test_bit(const std::size_t bitno) const; diff --git a/src/snark/libsnark/algebra/fields/bigint.tcc b/src/snark/libsnark/algebra/fields/bigint.tcc index 81befd96a..87b2c7344 100644 --- a/src/snark/libsnark/algebra/fields/bigint.tcc +++ b/src/snark/libsnark/algebra/fields/bigint.tcc @@ -17,9 +17,9 @@ namespace libsnark { template -bigint::bigint(const unsigned long x) /// Initialize from a small integer +bigint::bigint(const uint64_t x) /// Initialize from a small integer { - static_assert(ULONG_MAX <= GMP_NUMB_MAX, "unsigned long does not fit in a GMP limb"); + static_assert(UINT64_MAX <= GMP_NUMB_MAX, "uint64_t does not fit in a GMP limb"); this->data[0] = x; } @@ -131,7 +131,7 @@ size_t bigint::num_bits() const } template -unsigned long bigint::as_ulong() const +uint64_t bigint::as_uint64() const { return this->data[0]; } diff --git a/src/snark/libsnark/algebra/fields/fp.hpp b/src/snark/libsnark/algebra/fields/fp.hpp index 9679275d1..ef145b5ac 100644 --- a/src/snark/libsnark/algebra/fields/fp.hpp +++ b/src/snark/libsnark/algebra/fields/fp.hpp @@ -44,11 +44,11 @@ public: static const mp_size_t num_limbs = n; static const constexpr bigint& mod = modulus; #ifdef PROFILE_OP_COUNTS - static long long add_cnt; - static long long sub_cnt; - static long long mul_cnt; - static long long sqr_cnt; - static long long inv_cnt; + static int64_t add_cnt; + static int64_t sub_cnt; + static int64_t mul_cnt; + static int64_t sqr_cnt; + static int64_t inv_cnt; #endif static size_t num_bits; static bigint euler; // (modulus-1)/2 @@ -69,7 +69,7 @@ public: Fp_model(const bigint &b); Fp_model(const long x, const bool is_unsigned=false); - void set_ulong(const unsigned long x); + void set_uint64(const uint64_t x); void mul_reduce(const bigint &other); @@ -80,9 +80,9 @@ public: would return bigint(2) */ bigint as_bigint() const; /* Return the last limb of the standard representation of the - field element. E.g. on 64-bit architectures Fp(123).as_ulong() - and Fp(2^64+123).as_ulong() would both return 123. */ - unsigned long as_ulong() const; + field element. E.g. on 64-bit architectures Fp(123).as_uint64() + and Fp(2^64+123).as_uint64() would both return 123. */ + uint64_t as_uint64() const; bool operator==(const Fp_model& other) const; bool operator!=(const Fp_model& other) const; @@ -93,7 +93,7 @@ public: Fp_model& operator+=(const Fp_model& other); Fp_model& operator-=(const Fp_model& other); Fp_model& operator*=(const Fp_model& other); - Fp_model& operator^=(const unsigned long pow); + Fp_model& operator^=(const uint64_t pow); template Fp_model& operator^=(const bigint &pow); @@ -107,7 +107,7 @@ public: Fp_model inverse() const; Fp_model sqrt() const; // HAS TO BE A SQUARE (else does not terminate) - Fp_model operator^(const unsigned long pow) const; + Fp_model operator^(const uint64_t pow) const; template Fp_model operator^(const bigint &pow) const; @@ -125,19 +125,19 @@ public: #ifdef PROFILE_OP_COUNTS template& modulus> -long long Fp_model::add_cnt = 0; +int64_t Fp_model::add_cnt = 0; template& modulus> -long long Fp_model::sub_cnt = 0; +int64_t Fp_model::sub_cnt = 0; template& modulus> -long long Fp_model::mul_cnt = 0; +int64_t Fp_model::mul_cnt = 0; template& modulus> -long long Fp_model::sqr_cnt = 0; +int64_t Fp_model::sqr_cnt = 0; template& modulus> -long long Fp_model::inv_cnt = 0; +int64_t Fp_model::inv_cnt = 0; #endif template& modulus> diff --git a/src/snark/libsnark/algebra/fields/fp.tcc b/src/snark/libsnark/algebra/fields/fp.tcc index 566e99324..7f17650ad 100644 --- a/src/snark/libsnark/algebra/fields/fp.tcc +++ b/src/snark/libsnark/algebra/fields/fp.tcc @@ -210,7 +210,7 @@ Fp_model::Fp_model(const long x, const bool is_unsigned) } template& modulus> -void Fp_model::set_ulong(const unsigned long x) +void Fp_model::set_uint64(const uint64_t x) { this->mont_repr.clear(); this->mont_repr.data[0] = x; @@ -237,9 +237,9 @@ bigint Fp_model::as_bigint() const } template& modulus> -unsigned long Fp_model::as_ulong() const +uint64_t Fp_model::as_uint64() const { - return this->as_bigint().as_ulong(); + return this->as_bigint().as_uint64(); } template& modulus> @@ -502,7 +502,7 @@ Fp_model& Fp_model::operator*=(const Fp_model& } template& modulus> -Fp_model& Fp_model::operator^=(const unsigned long pow) +Fp_model& Fp_model::operator^=(const uint64_t pow) { (*this) = power >(*this, pow); return (*this); @@ -538,7 +538,7 @@ Fp_model Fp_model::operator*(const Fp_model& ot } template& modulus> -Fp_model Fp_model::operator^(const unsigned long pow) const +Fp_model Fp_model::operator^(const uint64_t pow) const { Fp_model r(*this); return (r ^= pow); @@ -690,7 +690,7 @@ Fp_model Fp_model::random_element() /// returns random el const std::size_t part = bitno/GMP_NUMB_BITS; const std::size_t bit = bitno - (GMP_NUMB_BITS*part); - r.mont_repr.data[part] &= ~(1ul< Fp12_2over3over2_model::inverse() c } template& modulus> -Fp12_2over3over2_model Fp12_2over3over2_model::Frobenius_map(unsigned long power) const +Fp12_2over3over2_model Fp12_2over3over2_model::Frobenius_map(uint64_t power) const { return Fp12_2over3over2_model(c0.Frobenius_map(power), Frobenius_coeffs_c1[power % 12] * c1.Frobenius_map(power)); @@ -348,7 +348,7 @@ Fp12_2over3over2_model Fp12_2over3over2_model::cyclotomic res = res.cyclotomic_squared(); } - if (exponent.data[i] & (1ul< Fp2_model::inverse() const } template& modulus> -Fp2_model Fp2_model::Frobenius_map(unsigned long power) const +Fp2_model Fp2_model::Frobenius_map(uint64_t power) const { return Fp2_model(c0, Frobenius_coeffs_c1[power % 2] * c1); diff --git a/src/snark/libsnark/algebra/fields/fp6_3over2.hpp b/src/snark/libsnark/algebra/fields/fp6_3over2.hpp index 335d61c53..912c58a74 100644 --- a/src/snark/libsnark/algebra/fields/fp6_3over2.hpp +++ b/src/snark/libsnark/algebra/fields/fp6_3over2.hpp @@ -63,7 +63,7 @@ public: Fp6_3over2_model operator-() const; Fp6_3over2_model squared() const; Fp6_3over2_model inverse() const; - Fp6_3over2_model Frobenius_map(unsigned long power) const; + Fp6_3over2_model Frobenius_map(uint64_t power) const; static my_Fp2 mul_by_non_residue(const my_Fp2 &elt); diff --git a/src/snark/libsnark/algebra/fields/fp6_3over2.tcc b/src/snark/libsnark/algebra/fields/fp6_3over2.tcc index f4fffde04..86b864ef0 100644 --- a/src/snark/libsnark/algebra/fields/fp6_3over2.tcc +++ b/src/snark/libsnark/algebra/fields/fp6_3over2.tcc @@ -149,7 +149,7 @@ Fp6_3over2_model Fp6_3over2_model::inverse() const } template& modulus> -Fp6_3over2_model Fp6_3over2_model::Frobenius_map(unsigned long power) const +Fp6_3over2_model Fp6_3over2_model::Frobenius_map(uint64_t power) const { return Fp6_3over2_model(c0.Frobenius_map(power), Frobenius_coeffs_c1[power % 6] * c1.Frobenius_map(power), diff --git a/src/snark/libsnark/algebra/fields/tests/test_bigint.cpp b/src/snark/libsnark/algebra/fields/tests/test_bigint.cpp index d2da59e73..731403ec7 100644 --- a/src/snark/libsnark/algebra/fields/tests/test_bigint.cpp +++ b/src/snark/libsnark/algebra/fields/tests/test_bigint.cpp @@ -13,7 +13,6 @@ using namespace libsnark; TEST(algebra, bigint) { - static_assert(ULONG_MAX == 0xFFFFFFFFFFFFFFFFul, "unsigned long not 64-bit"); static_assert(GMP_NUMB_BITS == 64, "GMP limb not 64-bit"); const char *b1_decimal = "76749407"; @@ -26,11 +25,11 @@ TEST(algebra, bigint) bigint<1> b1 = bigint<1>(b1_decimal); bigint<2> b2 = bigint<2>(b2_decimal); - EXPECT_EQ(b0.as_ulong(), 0ul); + EXPECT_EQ(b0.as_uint64(), 0ul); EXPECT_TRUE(b0.is_zero()); - EXPECT_EQ(b1.as_ulong(), 76749407ul); + EXPECT_EQ(b1.as_uint64(), 76749407ul); EXPECT_FALSE(b1.is_zero()); - EXPECT_EQ(b2.as_ulong(), 15747124762497195938ul); + EXPECT_EQ(b2.as_uint64(), 15747124762497195938ul); EXPECT_FALSE(b2.is_zero()); EXPECT_NE(b0, b1); EXPECT_FALSE(b0 == b1); @@ -61,7 +60,7 @@ TEST(algebra, bigint) bigint<2> remainder; bigint<3>::div_qr(quotient, remainder, b3, b2); EXPECT_LT(quotient.num_bits(), GMP_NUMB_BITS); - EXPECT_EQ(quotient.as_ulong(), b1.as_ulong()); + EXPECT_EQ(quotient.as_uint64(), b1.as_uint64()); bigint<1> b1inc = bigint<1>("76749408"); bigint<1> b1a = quotient.shorten(b1inc, "test"); EXPECT_EQ(b1a, b1); @@ -79,9 +78,9 @@ TEST(algebra, bigint) bigint<3>::div_qr(quotient, remainder, b3, b2); EXPECT_LT(quotient.num_bits(), GMP_NUMB_BITS); - EXPECT_EQ(quotient.as_ulong(), b1.as_ulong()); + EXPECT_EQ(quotient.as_uint64(), b1.as_uint64()); EXPECT_LT(remainder.num_bits(), GMP_NUMB_BITS); - EXPECT_EQ(remainder.as_ulong(), 42); + EXPECT_EQ(remainder.as_uint64(), 42); b3a.clear(); EXPECT_TRUE(b3a.is_zero()); diff --git a/src/snark/libsnark/algebra/scalar_multiplication/multiexp.tcc b/src/snark/libsnark/algebra/scalar_multiplication/multiexp.tcc index a6b14c4df..da59e2f21 100644 --- a/src/snark/libsnark/algebra/scalar_multiplication/multiexp.tcc +++ b/src/snark/libsnark/algebra/scalar_multiplication/multiexp.tcc @@ -214,7 +214,7 @@ T multi_exp_inner(typename std::vector::const_iterator vec_start, const size_t bbits = b.r.num_bits(); const size_t limit = (abits-bbits >= 20 ? 20 : abits-bbits); - if (bbits < 1ul< get_window_table(const size_t scalar_size, const size_t window, const T &g) { - const size_t in_window = 1ul< T fixed_window_wnaf_exp(const size_t window_size, const T &base, const bigint &scalar) { std::vector naf = find_wnaf(window_size, scalar); - std::vector table(1ul<<(window_size-1)); + std::vector table(UINT64_C(1)<<(window_size-1)); T tmp = base; T dbl = base.dbl(); - for (size_t i = 0; i < 1ul<<(window_size-1); ++i) + for (size_t i = 0; i < UINT64_C(1)<<(window_size-1); ++i) { table[i] = tmp; tmp = tmp + dbl; diff --git a/src/snark/libsnark/common/data_structures/merkle_tree.tcc b/src/snark/libsnark/common/data_structures/merkle_tree.tcc index 281700b33..ce28b124f 100644 --- a/src/snark/libsnark/common/data_structures/merkle_tree.tcc +++ b/src/snark/libsnark/common/data_structures/merkle_tree.tcc @@ -66,14 +66,14 @@ merkle_tree::merkle_tree(const size_t depth, assert(log2(contents_as_vector.size()) <= depth); for (size_t address = 0; address < contents_as_vector.size(); ++address) { - const size_t idx = address + (1ul< 0; --layer) { @@ -100,13 +100,13 @@ merkle_tree::merkle_tree(const size_t depth, if (!contents.empty()) { - assert(contents.rbegin()->first < 1ul<first < UINT64_C(1)<first; const bit_vector value = it->second; - const size_t idx = address + (1ul<::set_value(const size_t address, const bit_vector &value) { assert(log2(address) <= depth); - size_t idx = address + (1ul<::get_path(con { typename HashT::merkle_authentication_path_type result(depth); assert(log2(address) <= depth); - size_t idx = address + (1ul< 0; --layer) { @@ -209,7 +209,7 @@ typename HashT::merkle_authentication_path_type merkle_tree::get_path(con auto it = hashes.find(sibling_idx); if (layer == depth) { - auto it2 = values.find(sibling_idx - ((1ul<second); result[layer-1].resize(digest_size); } @@ -227,7 +227,7 @@ typename HashT::merkle_authentication_path_type merkle_tree::get_path(con template void merkle_tree::dump() const { - for (size_t i = 0; i < 1ul< ", i); diff --git a/src/snark/libsnark/common/profiling.cpp b/src/snark/libsnark/common/profiling.cpp index 23f27ce13..e66856673 100644 --- a/src/snark/libsnark/common/profiling.cpp +++ b/src/snark/libsnark/common/profiling.cpp @@ -28,14 +28,14 @@ namespace libsnark { -long long get_nsec_time() +int64_t get_nsec_time() { auto timepoint = std::chrono::high_resolution_clock::now(); return std::chrono::duration_cast(timepoint.time_since_epoch()).count(); } /* Return total CPU time consumed by all threads of the process, in nanoseconds. */ -long long get_nsec_cpu_time() +int64_t get_nsec_cpu_time() { ::timespec ts; if ( ::clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts) ) @@ -45,10 +45,10 @@ long long get_nsec_cpu_time() return ts.tv_sec * 1000000000ll + ts.tv_nsec; } -static long long start_time; -static long long last_time; -static long long start_cpu_time; -static long long last_cpu_time; +static int64_t start_time; +static int64_t last_time; +static int64_t start_cpu_time; +static int64_t last_cpu_time; void start_profiling() { @@ -59,20 +59,20 @@ void start_profiling() } std::map invocation_counts; -static std::map enter_times; -std::map last_times; -std::map cumulative_times; +static std::map enter_times; +std::map last_times; +std::map cumulative_times; //TODO: Instead of analogous maps for time and cpu_time, use a single struct-valued map -static std::map enter_cpu_times; -static std::map last_cpu_times; -static std::map, long long> op_counts; -static std::map, long long> cumulative_op_counts; // ((msg, data_point), value) +static std::map enter_cpu_times; +static std::map last_cpu_times; +static std::map, int64_t> op_counts; +static std::map, int64_t> cumulative_op_counts; // ((msg, data_point), value) // TODO: Convert op_counts and cumulative_op_counts from pair to structs static size_t indentation = 0; static std::vector block_names; -static std::list > op_data_points = { +static std::list > op_data_points = { #ifdef PROFILE_OP_COUNTS std::make_pair("Fradd", &Fr::add_cnt), std::make_pair("Frsub", &Fr::sub_cnt), @@ -100,7 +100,7 @@ void clear_profiling_counters() cumulative_times.clear(); } -void print_cumulative_time_entry(const std::string &key, const long long factor) +void print_cumulative_time_entry(const std::string &key, const int64_t factor) { const double total_ms = (cumulative_times.at(key) * 1e-6); const size_t cnt = invocation_counts.at(key); @@ -108,7 +108,7 @@ void print_cumulative_time_entry(const std::string &key, const long long factor) printf(" %-45s: %12.5fms = %lld * %0.5fms (%zu invocations, %0.5fms = %lld * %0.5fms per invocation)\n", key.c_str(), total_ms, factor, total_ms/factor, cnt, avg_ms, factor, avg_ms/factor); } -void print_cumulative_times(const long long factor) +void print_cumulative_times(const int64_t factor) { printf("Dumping times:\n"); for (auto& kv : cumulative_times) @@ -157,7 +157,7 @@ void print_op_profiling(const std::string &msg) printf("(opcounts) = ("); bool first = true; - for (std::pair p : op_data_points) + for (std::pair p : op_data_points) { if (!first) { @@ -173,14 +173,14 @@ void print_op_profiling(const std::string &msg) #endif } -static void print_times_from_last_and_start(long long now, long long last, - long long cpu_now, long long cpu_last) +static void print_times_from_last_and_start(int64_t now, int64_t last, + int64_t cpu_now, int64_t cpu_last) { - long long time_from_start = now - start_time; - long long time_from_last = now - last; + int64_t time_from_start = now - start_time; + int64_t time_from_last = now - last; - long long cpu_time_from_start = cpu_now - start_cpu_time; - long long cpu_time_from_last = cpu_now - cpu_last; + int64_t cpu_time_from_start = cpu_now - start_cpu_time; + int64_t cpu_time_from_last = cpu_now - cpu_last; if (time_from_last != 0) { double parallelism_from_last = 1.0 * cpu_time_from_last / time_from_last; @@ -201,8 +201,8 @@ void print_time(const char* msg) return; } - long long now = get_nsec_time(); - long long cpu_now = get_nsec_cpu_time(); + int64_t now = get_nsec_time(); + int64_t cpu_now = get_nsec_cpu_time(); printf("%-35s\t", msg); print_times_from_last_and_start(now, last_time, cpu_now, last_cpu_time); @@ -233,7 +233,7 @@ void print_indent() void op_profiling_enter(const std::string &msg) { - for (std::pair p : op_data_points) + for (std::pair p : op_data_points) { op_counts[std::make_pair(msg, p.first)] = *(p.second); } @@ -247,9 +247,9 @@ void enter_block(const std::string &msg, const bool indent) } block_names.emplace_back(msg); - long long t = get_nsec_time(); + int64_t t = get_nsec_time(); enter_times[msg] = t; - long long cpu_t = get_nsec_cpu_time(); + int64_t cpu_t = get_nsec_cpu_time(); enter_cpu_times[msg] = cpu_t; if (inhibit_profiling_info) @@ -290,15 +290,15 @@ void leave_block(const std::string &msg, const bool indent) ++invocation_counts[msg]; - long long t = get_nsec_time(); + int64_t t = get_nsec_time(); last_times[msg] = (t - enter_times[msg]); cumulative_times[msg] += (t - enter_times[msg]); - long long cpu_t = get_nsec_cpu_time(); + int64_t cpu_t = get_nsec_cpu_time(); last_cpu_times[msg] = (cpu_t - enter_cpu_times[msg]); #ifdef PROFILE_OP_COUNTS - for (std::pair p : op_data_points) + for (std::pair p : op_data_points) { cumulative_op_counts[std::make_pair(msg, p.first)] += *(p.second)-op_counts[std::make_pair(msg, p.first)]; } diff --git a/src/snark/libsnark/common/profiling.hpp b/src/snark/libsnark/common/profiling.hpp index 9619117f4..4a496107b 100644 --- a/src/snark/libsnark/common/profiling.hpp +++ b/src/snark/libsnark/common/profiling.hpp @@ -22,7 +22,7 @@ namespace libsnark { void start_profiling(); -long long get_nsec_time(); +int64_t get_nsec_time(); void print_time(const char* msg); void print_header(const char* msg); @@ -31,13 +31,13 @@ void print_indent(); extern bool inhibit_profiling_info; extern bool inhibit_profiling_counters; extern std::map invocation_counts; -extern std::map last_times; -extern std::map cumulative_times; +extern std::map last_times; +extern std::map cumulative_times; void clear_profiling_counters(); -void print_cumulative_time_entry(const std::string &key, const long long factor=1); -void print_cumulative_times(const long long factor=1); +void print_cumulative_time_entry(const std::string &key, const int64_t factor=1); +void print_cumulative_times(const int64_t factor=1); void print_cumulative_op_counts(const bool only_fq=false); void enter_block(const std::string &msg, const bool indent=true); diff --git a/src/snark/libsnark/common/utils.cpp b/src/snark/libsnark/common/utils.cpp index dd114fdf0..06af6eff8 100644 --- a/src/snark/libsnark/common/utils.cpp +++ b/src/snark/libsnark/common/utils.cpp @@ -16,7 +16,7 @@ namespace libsnark { size_t log2(size_t n) -/* returns ceil(log2(n)), so 1ul< &l, const size_t wordsize) +bit_vector int_list_to_bits(const std::initializer_list &l, const size_t wordsize) { bit_vector res(wordsize*l.size()); for (size_t i = 0; i < l.size(); ++i) { for (size_t j = 0; j < wordsize; ++j) { - res[i*wordsize + j] = (*(l.begin()+i) & (1ul<<(wordsize-1-j))); + res[i*wordsize + j] = (*(l.begin()+i) & (UINT64_C(1)<<(wordsize-1-j))); } } return res; } -long long div_ceil(long long x, long long y) +int64_t div_ceil(int64_t x, int64_t y) { return (x + (y-1)) / y; } diff --git a/src/snark/libsnark/common/utils.hpp b/src/snark/libsnark/common/utils.hpp index d7d9e8947..505f67410 100644 --- a/src/snark/libsnark/common/utils.hpp +++ b/src/snark/libsnark/common/utils.hpp @@ -20,14 +20,14 @@ namespace libsnark { typedef std::vector bit_vector; -/// returns ceil(log2(n)), so 1ul< &l, const size_t wordsize); -long long div_ceil(long long x, long long y); +bit_vector int_list_to_bits(const std::initializer_list &l, const size_t wordsize); +int64_t div_ceil(int64_t x, int64_t y); bool is_little_endian(); diff --git a/src/snark/libsnark/gadgetlib1/gadgets/basic_gadgets.tcc b/src/snark/libsnark/gadgetlib1/gadgets/basic_gadgets.tcc index 213b1906f..46db45532 100644 --- a/src/snark/libsnark/gadgetlib1/gadgets/basic_gadgets.tcc +++ b/src/snark/libsnark/gadgetlib1/gadgets/basic_gadgets.tcc @@ -275,11 +275,11 @@ void test_disjunction_gadget(const size_t n) disjunction_gadget d(pb, inputs, output, "d"); d.generate_r1cs_constraints(); - for (size_t w = 0; w < 1ul< c(pb, inputs, output, "c"); c.generate_r1cs_constraints(); - for (size_t w = 0; w < 1ul< cmp(pb, n, A, B, less, less_or_eq, "cmp"); cmp.generate_r1cs_constraints(); - for (size_t a = 0; a < 1ul< g(pb, A, B, result, "g"); g.generate_r1cs_constraints(); - for (size_t i = 0; i < 1ul<::generate_r1cs_witness() { /* assumes that idx can be fit in ulong; true for our purposes for now */ const bigint valint = this->pb.val(index).as_bigint(); - unsigned long idx = valint.as_ulong(); + uint64_t idx = valint.as_uint64(); const bigint arrsize(arr.size()); if (idx >= arr.size() || mpn_cmp(valint.data, arrsize.data, FieldT::num_limbs) >= 0) @@ -619,7 +619,7 @@ void test_loose_multiplexing_gadget(const size_t n) protoboard pb; pb_variable_array arr; - arr.allocate(pb, 1ul< index, result, success_flag; index.allocate(pb, "index"); result.allocate(pb, "result"); @@ -628,20 +628,20 @@ void test_loose_multiplexing_gadget(const size_t n) loose_multiplexing_gadget g(pb, arr, index, result, success_flag, "g"); g.generate_r1cs_constraints(); - for (size_t i = 0; i < 1ul<::generate_r1cs_witness() { for (size_t i = 0; i < 32; ++i) { - const long v = (this->pb.lc_val(X[i]) + this->pb.lc_val(Y[i]) + this->pb.lc_val(Z[i])).as_ulong(); + const uint64_t v = (this->pb.lc_val(X[i]) + this->pb.lc_val(Y[i]) + this->pb.lc_val(Z[i])).as_uint64(); this->pb.val(result_bits[i]) = FieldT(v / 2); } diff --git a/src/snark/libsnark/gadgetlib1/gadgets/hashes/sha256/sha256_components.tcc b/src/snark/libsnark/gadgetlib1/gadgets/hashes/sha256/sha256_components.tcc index e8f233a54..ec02172de 100644 --- a/src/snark/libsnark/gadgetlib1/gadgets/hashes/sha256/sha256_components.tcc +++ b/src/snark/libsnark/gadgetlib1/gadgets/hashes/sha256/sha256_components.tcc @@ -16,7 +16,7 @@ namespace libsnark { -const unsigned long SHA256_K[64] = { +const uint32_t SHA256_K[64] = { 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, @@ -27,7 +27,7 @@ const unsigned long SHA256_K[64] = { 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 }; -const unsigned long SHA256_H[8] = { +const uint32_t SHA256_H[8] = { 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 }; diff --git a/src/snark/libsnark/gadgetlib1/gadgets/hashes/sha256/sha256_gadget.tcc b/src/snark/libsnark/gadgetlib1/gadgets/hashes/sha256/sha256_gadget.tcc index fc7ac982a..3004f9e83 100644 --- a/src/snark/libsnark/gadgetlib1/gadgets/hashes/sha256/sha256_gadget.tcc +++ b/src/snark/libsnark/gadgetlib1/gadgets/hashes/sha256/sha256_gadget.tcc @@ -117,7 +117,7 @@ void sha256_compression_function_gadget::generate_r1cs_witness() printf("Input:\n"); for (size_t j = 0; j < 16; ++j) { - printf("%lx ", this->pb.val(packed_W[j]).as_ulong()); + printf("%lx ", this->pb.val(packed_W[j]).as_uint64()); } printf("\n"); #endif @@ -142,7 +142,7 @@ void sha256_compression_function_gadget::generate_r1cs_witness() printf("Output:\n"); for (size_t j = 0; j < 8; ++j) { - printf("%lx ", this->pb.val(reduced_output[j]).as_ulong()); + printf("%lx ", this->pb.val(reduced_output[j]).as_uint64()); } printf("\n"); #endif diff --git a/src/snark/libsnark/gadgetlib1/gadgets/merkle_tree/merkle_authentication_path_variable.tcc b/src/snark/libsnark/gadgetlib1/gadgets/merkle_tree/merkle_authentication_path_variable.tcc index d773051ab..b3d805d8e 100644 --- a/src/snark/libsnark/gadgetlib1/gadgets/merkle_tree/merkle_authentication_path_variable.tcc +++ b/src/snark/libsnark/gadgetlib1/gadgets/merkle_tree/merkle_authentication_path_variable.tcc @@ -41,7 +41,7 @@ void merkle_authentication_path_variable::generate_r1cs_witness(c for (size_t i = 0; i < tree_depth; ++i) { - if (address & (1ul << (tree_depth-1-i))) + if (address & (UINT64_C(1) << (tree_depth-1-i))) { left_digests[i].generate_r1cs_witness(path[i]); } @@ -58,7 +58,7 @@ merkle_authentication_path merkle_authentication_path_variable::g merkle_authentication_path result; for (size_t i = 0; i < tree_depth; ++i) { - if (address & (1ul << (tree_depth-1-i))) + if (address & (UINT64_C(1) << (tree_depth-1-i))) { result.emplace_back(left_digests[i].get_digest()); } diff --git a/src/snark/libsnark/gadgetlib1/gadgets/merkle_tree/merkle_tree_check_read_gadget.tcc b/src/snark/libsnark/gadgetlib1/gadgets/merkle_tree/merkle_tree_check_read_gadget.tcc index 6002a5886..eff9ee06a 100644 --- a/src/snark/libsnark/gadgetlib1/gadgets/merkle_tree/merkle_tree_check_read_gadget.tcc +++ b/src/snark/libsnark/gadgetlib1/gadgets/merkle_tree/merkle_tree_check_read_gadget.tcc @@ -147,7 +147,7 @@ void test_merkle_tree_check_read_gadget() for (long level = tree_depth-1; level >= 0; --level) { const bool computed_is_right = (std::rand() % 2); - address |= (computed_is_right ? 1ul << (tree_depth-1-level) : 0); + address |= (computed_is_right ? UINT64_C(1) << (tree_depth-1-level) : 0); address_bits.push_back(computed_is_right); bit_vector other(digest_len); std::generate(other.begin(), other.end(), [&]() { return std::rand() % 2; }); @@ -175,7 +175,7 @@ void test_merkle_tree_check_read_gadget() ml.generate_r1cs_constraints(); address_bits_va.fill_with_bits(pb, address_bits); - assert(address_bits_va.get_field_element_from_bits(pb).as_ulong() == address); + assert(address_bits_va.get_field_element_from_bits(pb).as_uint64() == address); leaf_digest.generate_r1cs_witness(leaf); path_var.generate_r1cs_witness(address, path); ml.generate_r1cs_witness(); diff --git a/src/snark/libsnark/gadgetlib1/gadgets/merkle_tree/merkle_tree_check_update_gadget.tcc b/src/snark/libsnark/gadgetlib1/gadgets/merkle_tree/merkle_tree_check_update_gadget.tcc index 1ac08edbb..b3b238a15 100644 --- a/src/snark/libsnark/gadgetlib1/gadgets/merkle_tree/merkle_tree_check_update_gadget.tcc +++ b/src/snark/libsnark/gadgetlib1/gadgets/merkle_tree/merkle_tree_check_update_gadget.tcc @@ -200,7 +200,7 @@ void test_merkle_tree_check_update_gadget() for (long level = tree_depth-1; level >= 0; --level) { const bool computed_is_right = (std::rand() % 2); - address |= (computed_is_right ? 1ul << (tree_depth-1-level) : 0); + address |= (computed_is_right ? UINT64_C(1) << (tree_depth-1-level) : 0); address_bits.push_back(computed_is_right); bit_vector other(digest_len); std::generate(other.begin(), other.end(), [&]() { return std::rand() % 2; }); @@ -240,7 +240,7 @@ void test_merkle_tree_check_update_gadget() mls.generate_r1cs_constraints(); address_bits_va.fill_with_bits(pb, address_bits); - assert(address_bits_va.get_field_element_from_bits(pb).as_ulong() == address); + assert(address_bits_va.get_field_element_from_bits(pb).as_uint64() == address); prev_leaf_digest.generate_r1cs_witness(loaded_leaf); prev_path_var.generate_r1cs_witness(address, prev_path); next_leaf_digest.generate_r1cs_witness(stored_leaf); diff --git a/src/snark/libsnark/gadgetlib1/pb_variable.hpp b/src/snark/libsnark/gadgetlib1/pb_variable.hpp index fdf64d014..caa44cec1 100644 --- a/src/snark/libsnark/gadgetlib1/pb_variable.hpp +++ b/src/snark/libsnark/gadgetlib1/pb_variable.hpp @@ -59,7 +59,7 @@ public: void fill_with_field_elements(protoboard &pb, const std::vector& vals) const; void fill_with_bits(protoboard &pb, const bit_vector& bits) const; - void fill_with_bits_of_ulong(protoboard &pb, const unsigned long i) const; + void fill_with_bits_of_uint64(protoboard &pb, const uint64_t i) const; void fill_with_bits_of_field_element(protoboard &pb, const FieldT &r) const; std::vector get_vals(const protoboard &pb) const; @@ -120,7 +120,7 @@ public: void fill_with_field_elements(protoboard &pb, const std::vector& vals) const; void fill_with_bits(protoboard &pb, const bit_vector& bits) const; - void fill_with_bits_of_ulong(protoboard &pb, const unsigned long i) const; + void fill_with_bits_of_uint64(protoboard &pb, const uint64_t i) const; void fill_with_bits_of_field_element(protoboard &pb, const FieldT &r) const; std::vector get_vals(const protoboard &pb) const; diff --git a/src/snark/libsnark/gadgetlib1/pb_variable.tcc b/src/snark/libsnark/gadgetlib1/pb_variable.tcc index b36b3f8d7..b4c6ad4f9 100644 --- a/src/snark/libsnark/gadgetlib1/pb_variable.tcc +++ b/src/snark/libsnark/gadgetlib1/pb_variable.tcc @@ -65,7 +65,7 @@ void pb_variable_array::fill_with_bits_of_field_element(protoboard -void pb_variable_array::fill_with_bits_of_ulong(protoboard &pb, const unsigned long i) const +void pb_variable_array::fill_with_bits_of_uint64(protoboard &pb, const uint64_t i) const { this->fill_with_bits_of_field_element(pb, FieldT(i, true)); } @@ -232,7 +232,7 @@ void pb_linear_combination_array::fill_with_bits_of_field_element(protob } template -void pb_linear_combination_array::fill_with_bits_of_ulong(protoboard &pb, const unsigned long i) const +void pb_linear_combination_array::fill_with_bits_of_uint64(protoboard &pb, const uint64_t i) const { this->fill_with_bits_of_field_element(pb, FieldT(i)); } diff --git a/src/snark/libsnark/relations/arithmetic_programs/qap/tests/test_qap.cpp b/src/snark/libsnark/relations/arithmetic_programs/qap/tests/test_qap.cpp index e20f589c9..3c7b87057 100644 --- a/src/snark/libsnark/relations/arithmetic_programs/qap/tests/test_qap.cpp +++ b/src/snark/libsnark/relations/arithmetic_programs/qap/tests/test_qap.cpp @@ -92,13 +92,13 @@ TEST(relations, qap) enter_block("Test QAP with binary input"); - test_qap >(1ul << 21, num_inputs, true); + test_qap >(UINT64_C(1) << 21, num_inputs, true); leave_block("Test QAP with binary input"); enter_block("Test QAP with field input"); - test_qap >(1ul << 21, num_inputs, false); + test_qap >(UINT64_C(1) << 21, num_inputs, false); leave_block("Test QAP with field input"); } diff --git a/src/zcash/circuit/merkle.tcc b/src/zcash/circuit/merkle.tcc index ca89adbed..09f02ae9f 100644 --- a/src/zcash/circuit/merkle.tcc +++ b/src/zcash/circuit/merkle.tcc @@ -52,7 +52,7 @@ public: // number thing in its API. size_t path_index = convertVectorToInt(path.index); - positions.fill_with_bits_of_ulong(this->pb, path_index); + positions.fill_with_bits_of_uint64(this->pb, path_index); authvars->generate_r1cs_witness(path_index, path.authentication_path); auth->generate_r1cs_witness();