diff --git a/src/snark/libsnark/algebra/curves/alt_bn128/alt_bn128_pairing.cpp b/src/snark/libsnark/algebra/curves/alt_bn128/alt_bn128_pairing.cpp index db556c5b2..07b6a8c71 100644 --- a/src/snark/libsnark/algebra/curves/alt_bn128/alt_bn128_pairing.cpp +++ b/src/snark/libsnark/algebra/curves/alt_bn128/alt_bn128_pairing.cpp @@ -324,7 +324,7 @@ alt_bn128_ate_G2_precomp alt_bn128_ate_precompute_G2(const alt_bn128_G2& Q) bool found_one = false; alt_bn128_ate_ell_coeffs c; - for (long i = loop_count.max_bits(); i >= 0; --i) + for (int64_t i = loop_count.max_bits(); i >= 0; --i) { const bool bit = loop_count.test_bit(i); if (!found_one) @@ -378,7 +378,7 @@ alt_bn128_Fq12 alt_bn128_ate_miller_loop(const alt_bn128_ate_G1_precomp &prec_P, const bigint &loop_count = alt_bn128_ate_loop_count; alt_bn128_ate_ell_coeffs c; - for (long i = loop_count.max_bits(); i >= 0; --i) + for (int64_t i = loop_count.max_bits(); i >= 0; --i) { const bool bit = loop_count.test_bit(i); if (!found_one) @@ -432,7 +432,7 @@ alt_bn128_Fq12 alt_bn128_ate_double_miller_loop(const alt_bn128_ate_G1_precomp & size_t idx = 0; const bigint &loop_count = alt_bn128_ate_loop_count; - for (long i = loop_count.max_bits(); i >= 0; --i) + for (int64_t i = loop_count.max_bits(); i >= 0; --i) { const bool bit = loop_count.test_bit(i); if (!found_one) diff --git a/src/snark/libsnark/algebra/curves/curve_utils.tcc b/src/snark/libsnark/algebra/curves/curve_utils.tcc index 251d75d8b..38140cd48 100644 --- a/src/snark/libsnark/algebra/curves/curve_utils.tcc +++ b/src/snark/libsnark/algebra/curves/curve_utils.tcc @@ -16,7 +16,7 @@ GroupT scalar_mul(const GroupT &base, const bigint &scalar) GroupT result = GroupT::zero(); bool found_one = false; - for (long i = scalar.max_bits() - 1; i >= 0; --i) + for (int64_t i = scalar.max_bits() - 1; i >= 0; --i) { if (found_one) { diff --git a/src/snark/libsnark/algebra/exponentiation/exponentiation.tcc b/src/snark/libsnark/algebra/exponentiation/exponentiation.tcc index 5c775abde..7ac3bf5d3 100644 --- a/src/snark/libsnark/algebra/exponentiation/exponentiation.tcc +++ b/src/snark/libsnark/algebra/exponentiation/exponentiation.tcc @@ -25,7 +25,7 @@ FieldT power(const FieldT &base, const bigint &exponent) bool found_one = false; - for (long i = exponent.max_bits() - 1; i >= 0; --i) + for (int64_t i = exponent.max_bits() - 1; i >= 0; --i) { if (found_one) { diff --git a/src/snark/libsnark/algebra/fields/bigint.tcc b/src/snark/libsnark/algebra/fields/bigint.tcc index 87b2c7344..7a59233d4 100644 --- a/src/snark/libsnark/algebra/fields/bigint.tcc +++ b/src/snark/libsnark/algebra/fields/bigint.tcc @@ -105,7 +105,7 @@ template size_t bigint::num_bits() const { /* - for (long i = max_bits(); i >= 0; --i) + for (int64_t i = max_bits(); i >= 0; --i) { if (this->test_bit(i)) { @@ -115,7 +115,7 @@ size_t bigint::num_bits() const return 0; */ - for (long i = n-1; i >= 0; --i) + for (int64_t i = n-1; i >= 0; --i) { mp_limb_t x = this->data[i]; if (x == 0) @@ -124,7 +124,8 @@ size_t bigint::num_bits() const } else { - return ((i+1) * GMP_NUMB_BITS) - __builtin_clzl(x); + static_assert(GMP_NUMB_MAX <= ULLONG_MAX, "coercing limb to unsigned long long might truncate"); + return ((i+1) * GMP_NUMB_BITS) - __builtin_clzll(x); } } return 0; diff --git a/src/snark/libsnark/algebra/fields/field_utils.tcc b/src/snark/libsnark/algebra/fields/field_utils.tcc index 13197b226..66b532345 100644 --- a/src/snark/libsnark/algebra/fields/field_utils.tcc +++ b/src/snark/libsnark/algebra/fields/field_utils.tcc @@ -171,7 +171,7 @@ void batch_invert(std::vector &vec) FieldT acc_inverse = acc.inverse(); - for (long i = vec.size()-1; i >= 0; --i) + for (int64_t i = vec.size()-1; i >= 0; --i) { const FieldT old_el = vec[i]; vec[i] = acc_inverse * prod[i]; diff --git a/src/snark/libsnark/algebra/fields/fp.hpp b/src/snark/libsnark/algebra/fields/fp.hpp index ef145b5ac..af9eb0b9a 100644 --- a/src/snark/libsnark/algebra/fields/fp.hpp +++ b/src/snark/libsnark/algebra/fields/fp.hpp @@ -67,7 +67,7 @@ public: Fp_model() {}; Fp_model(const bigint &b); - Fp_model(const long x, const bool is_unsigned=false); + Fp_model(const int64_t x, const bool is_unsigned=false); void set_uint64(const uint64_t x); diff --git a/src/snark/libsnark/algebra/fields/fp.tcc b/src/snark/libsnark/algebra/fields/fp.tcc index 7556e0140..02baf6274 100644 --- a/src/snark/libsnark/algebra/fields/fp.tcc +++ b/src/snark/libsnark/algebra/fields/fp.tcc @@ -194,7 +194,7 @@ Fp_model::Fp_model(const bigint &b) } template& modulus> -Fp_model::Fp_model(const long x, const bool is_unsigned) +Fp_model::Fp_model(const int64_t x, const bool is_unsigned) { if (is_unsigned || x >= 0) { @@ -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] &= ~(((mp_limb_t) 1)< Fp12_2over3over2_model::cyclotomic Fp12_2over3over2_model res = Fp12_2over3over2_model::one(); bool found_one = false; - for (long i = m-1; i >= 0; --i) + for (int64_t i = m-1; i >= 0; --i) { - for (long j = GMP_NUMB_BITS - 1; j >= 0; --j) + for (int64_t j = GMP_NUMB_BITS - 1; j >= 0; --j) { if (found_one) { diff --git a/src/snark/libsnark/algebra/scalar_multiplication/multiexp.tcc b/src/snark/libsnark/algebra/scalar_multiplication/multiexp.tcc index 080e4cf23..e1783a881 100644 --- a/src/snark/libsnark/algebra/scalar_multiplication/multiexp.tcc +++ b/src/snark/libsnark/algebra/scalar_multiplication/multiexp.tcc @@ -40,7 +40,7 @@ public: #if defined(__x86_64__) && defined(USE_ASM) if (n == 3) { - long res; + int64_t res; __asm__ ("// check for overflow \n\t" "mov $0, %[res] \n\t" @@ -58,7 +58,7 @@ public: } else if (n == 4) { - long res; + int64_t res; __asm__ ("// check for overflow \n\t" "mov $0, %[res] \n\t" @@ -77,7 +77,7 @@ public: } else if (n == 5) { - long res; + int64_t res; __asm__ ("// check for overflow \n\t" "mov $0, %[res] \n\t" @@ -389,7 +389,7 @@ size_t get_exp_window_size(const size_t num_scalars) #endif } size_t window = 1; - for (long i = T::fixed_base_exp_window_table.size()-1; i >= 0; --i) + for (int64_t i = T::fixed_base_exp_window_table.size()-1; i >= 0; --i) { #ifdef DEBUG if (!inhibit_profiling_info) diff --git a/src/snark/libsnark/algebra/scalar_multiplication/wnaf.hpp b/src/snark/libsnark/algebra/scalar_multiplication/wnaf.hpp index a7ecd598e..d6c43267e 100644 --- a/src/snark/libsnark/algebra/scalar_multiplication/wnaf.hpp +++ b/src/snark/libsnark/algebra/scalar_multiplication/wnaf.hpp @@ -18,7 +18,7 @@ namespace libsnark { * Find the wNAF representation of the given scalar relative to the given window size. */ template -std::vector find_wnaf(const size_t window_size, const bigint &scalar); +std::vector find_wnaf(const size_t window_size, const bigint &scalar); /** * In additive notation, use wNAF exponentiation (with the given window size) to compute scalar * base. diff --git a/src/snark/libsnark/algebra/scalar_multiplication/wnaf.tcc b/src/snark/libsnark/algebra/scalar_multiplication/wnaf.tcc index 12c8c76e3..4f2e4072c 100644 --- a/src/snark/libsnark/algebra/scalar_multiplication/wnaf.tcc +++ b/src/snark/libsnark/algebra/scalar_multiplication/wnaf.tcc @@ -17,15 +17,15 @@ namespace libsnark { template -std::vector find_wnaf(const size_t window_size, const bigint &scalar) +std::vector find_wnaf(const size_t window_size, const bigint &scalar) { const size_t length = scalar.max_bits(); // upper bound - std::vector res(length+1); + std::vector res(length+1); bigint c = scalar; - long j = 0; + int64_t j = 0; while (!c.is_zero()) { - long u; + int64_t u; if ((c.data[0] & 1) == 1) { u = c.data[0] % (1u << (window_size+1)); @@ -59,7 +59,7 @@ std::vector find_wnaf(const size_t window_size, const bigint &scalar) template 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 naf = find_wnaf(window_size, scalar); std::vector table(UINT64_C(1)<<(window_size-1)); T tmp = base; T dbl = base.dbl(); @@ -71,7 +71,7 @@ T fixed_window_wnaf_exp(const size_t window_size, const T &base, const bigint T res = T::zero(); bool found_nonzero = false; - for (long i = naf.size()-1; i >= 0; --i) + for (int64_t i = naf.size()-1; i >= 0; --i) { if (found_nonzero) { @@ -99,7 +99,7 @@ template T opt_window_wnaf_exp(const T &base, const bigint &scalar, const size_t scalar_bits) { size_t best = 0; - for (long i = T::wnaf_window_table.size() - 1; i >= 0; --i) + for (int64_t i = T::wnaf_window_table.size() - 1; i >= 0; --i) { if (scalar_bits >= T::wnaf_window_table[i]) { 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 eff9ee06a..29ce1b8ac 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 @@ -144,7 +144,7 @@ void test_merkle_tree_check_read_gadget() bit_vector address_bits; size_t address = 0; - for (long level = tree_depth-1; level >= 0; --level) + for (int64_t level = tree_depth-1; level >= 0; --level) { const bool computed_is_right = (std::rand() % 2); address |= (computed_is_right ? UINT64_C(1) << (tree_depth-1-level) : 0); 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 b3b238a15..507c7526d 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 @@ -197,7 +197,7 @@ void test_merkle_tree_check_update_gadget() bit_vector address_bits; size_t address = 0; - for (long level = tree_depth-1; level >= 0; --level) + for (int64_t level = tree_depth-1; level >= 0; --level) { const bool computed_is_right = (std::rand() % 2); address |= (computed_is_right ? UINT64_C(1) << (tree_depth-1-level) : 0); diff --git a/src/snark/libsnark/relations/variable.hpp b/src/snark/libsnark/relations/variable.hpp index 8c2c704a3..84c65e810 100644 --- a/src/snark/libsnark/relations/variable.hpp +++ b/src/snark/libsnark/relations/variable.hpp @@ -26,7 +26,7 @@ namespace libsnark { * Mnemonic typedefs. */ typedef size_t var_index_t; -typedef long integer_coeff_t; +typedef int64_t integer_coeff_t; /** * Forward declaration.