diff --git a/configure.ac b/configure.ac index 96382acd7..b4ee70551 100644 --- a/configure.ac +++ b/configure.ac @@ -483,8 +483,9 @@ if test x$use_hardening != xno; then HARDENED_CPPFLAGS="$HARDENED_CPPFLAGS -D_FORTIFY_SOURCE=2" ],[AC_MSG_ERROR(Cannot enable -D_FORTIFY_SOURCE=2)]) - if test x$BUILD_OS = xdarwin; then + if test x$BUILD_OS = xdarwin || test x$TARGET_OS = xwindows; then # Xcode's ld (at least ld64-302.3) doesn't support -z + # mingw-w64's ld (at least mingw-w64 4.0.4-2) also appears to not support -z AX_CHECK_LINK_FLAG([[-Wl,-z,relro]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,relro"],[AC_MSG_WARN(Cannot enable RELRO)]) AX_CHECK_LINK_FLAG([[-Wl,-z,now]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,now"],[AC_MSG_WARN(Cannot enable BIND_NOW)]) else @@ -732,7 +733,14 @@ AC_CHECK_LIB([gmp],[[__gmpn_sub_n]],GMP_LIBS=-lgmp, [AC_MSG_ERROR(libgmp missing AC_CHECK_HEADER([gmpxx.h],,AC_MSG_ERROR(libgmpxx headers missing)) AC_CHECK_LIB([gmpxx],[main],GMPXX_LIBS=-lgmpxx, [AC_MSG_ERROR(libgmpxx missing)]) -RUST_LIBS="-lrustzcash -ldl" +RUST_LIBS="-lrustzcash" +case $host in + *mingw*) + ;; + *) + RUST_LIBS="$RUST_LIBS -ldl" + ;; +esac dnl Check for OpenMP support AX_OPENMP( diff --git a/depends/hosts/darwin.mk b/depends/hosts/darwin.mk index 4e58bec74..939988197 100644 --- a/depends/hosts/darwin.mk +++ b/depends/hosts/darwin.mk @@ -8,7 +8,7 @@ darwin_CXX=clang++ -target $(host) -mmacosx-version-min=$(OSX_MIN_VERSION) --sys darwin_CFLAGS=-pipe darwin_CXXFLAGS=$(darwin_CFLAGS) -darwin_release_CFLAGS=-O2 +darwin_release_CFLAGS=-O1 darwin_release_CXXFLAGS=$(darwin_release_CFLAGS) darwin_debug_CFLAGS=-O1 diff --git a/depends/hosts/mingw32.mk b/depends/hosts/mingw32.mk index dbfb62fdc..2248973a1 100644 --- a/depends/hosts/mingw32.mk +++ b/depends/hosts/mingw32.mk @@ -1,7 +1,7 @@ mingw32_CFLAGS=-pipe mingw32_CXXFLAGS=$(mingw32_CFLAGS) -mingw32_release_CFLAGS=-O2 +mingw32_release_CFLAGS=-O1 mingw32_release_CXXFLAGS=$(mingw32_release_CFLAGS) mingw32_debug_CFLAGS=-O1 diff --git a/depends/packages/bdb.mk b/depends/packages/bdb.mk index bbb07889e..6b385f2ab 100644 --- a/depends/packages/bdb.mk +++ b/depends/packages/bdb.mk @@ -13,6 +13,7 @@ $(package)_cxxflags=-std=c++11 endef define $(package)_preprocess_cmds + sed -i.old 's/WinIoCtl.h/winioctl.h/g' src/dbinc/win_db.h && \ sed -i.old 's/__atomic_compare_exchange\\(/__atomic_compare_exchange_db(/' src/dbinc/atomic.h && \ sed -i.old 's/atomic_init/atomic_init_db/' src/dbinc/atomic.h src/mp/mp_region.c src/mp/mp_mvcc.c src/mp/mp_fget.c src/mutex/mut_method.c src/mutex/mut_tas.c endef diff --git a/depends/packages/googletest.mk b/depends/packages/googletest.mk index b10ce89eb..ad42d5b9c 100644 --- a/depends/packages/googletest.mk +++ b/depends/packages/googletest.mk @@ -5,9 +5,14 @@ $(package)_file_name=$(package)-$($(package)_version).tar.gz $(package)_download_file=release-$($(package)_version).tar.gz $(package)_sha256_hash=58a6f4277ca2bc8565222b3bbd58a177609e9c488e8a72649359ba51450db7d8 +define $(package)_set_vars +$(package)_cxxflags+=-std=c++11 +$(package)_cxxflags_linux=-fPIC +endef + define $(package)_build_cmds - $(MAKE) -C googlemock/make CXXFLAGS=-fPIC gmock.a && \ - $(MAKE) -C googletest/make CXXFLAGS=-fPIC gtest.a + $(MAKE) -C googlemock/make CC="$($(package)_cc)" CXX="$($(package)_cxx)" AR="$($(package)_ar)" CXXFLAGS="$($(package)_cxxflags)" gmock.a && \ + $(MAKE) -C googletest/make CC="$($(package)_cc)" CXX="$($(package)_cxx)" AR="$($(package)_ar)" CXXFLAGS="$($(package)_cxxflags)" gtest.a endef define $(package)_stage_cmds diff --git a/depends/packages/librustzcash.mk b/depends/packages/librustzcash.mk index 46cf909f1..728378732 100644 --- a/depends/packages/librustzcash.mk +++ b/depends/packages/librustzcash.mk @@ -8,18 +8,29 @@ $(package)_git_commit=f5d2afb4eabac29b1b1cc860d66e45a5b48b4f88 $(package)_dependencies=rust $(rust_crates) $(package)_patches=cargo.config +ifeq ($(host_os),mingw32) +$(package)_library_file=target/x86_64-pc-windows-gnu/release/rustzcash.lib +else +$(package)_library_file=target/release/librustzcash.a +endif + +define $(package)_set_vars +$(package)_build_opts=--frozen --release +$(package)_build_opts_mingw32=--target=x86_64-pc-windows-gnu +endef + define $(package)_preprocess_cmds mkdir .cargo && \ cat $($(package)_patch_dir)/cargo.config | sed 's|CRATE_REGISTRY|$(host_prefix)/$(CRATE_REGISTRY)|' > .cargo/config endef define $(package)_build_cmds - cargo build --frozen --release + cargo build $($(package)_build_opts) endef define $(package)_stage_cmds mkdir $($(package)_staging_dir)$(host_prefix)/lib/ && \ mkdir $($(package)_staging_dir)$(host_prefix)/include/ && \ - cp target/release/librustzcash.a $($(package)_staging_dir)$(host_prefix)/lib/ && \ + cp $($(package)_library_file) $($(package)_staging_dir)$(host_prefix)/lib/ && \ cp include/librustzcash.h $($(package)_staging_dir)$(host_prefix)/include/ endef diff --git a/depends/packages/rust.mk b/depends/packages/rust.mk index 9340a6a8d..7c2e313ab 100644 --- a/depends/packages/rust.mk +++ b/depends/packages/rust.mk @@ -5,10 +5,36 @@ $(package)_file_name_linux=rust-$($(package)_version)-x86_64-unknown-linux-gnu.t $(package)_sha256_hash_linux=2a1390340db1d24a9498036884e6b2748e9b4b057fc5219694e298bdaa37b810 $(package)_file_name_darwin=rust-$($(package)_version)-x86_64-apple-darwin.tar.gz $(package)_sha256_hash_darwin=5d7a70ed4701fe9410041c1eea025c95cad97e5b3d8acc46426f9ac4f9f02393 -$(package)_file_name_mingw32=rust-mingw-$($(package)_version)-x86_64-pc-windows-gnu.tar.gz -$(package)_sha256_hash_mingw32=17effb289f53af43c36be48635364db7eed68c5a411410216eb75a57c39219e3 +$(package)_file_name_mingw32=rust-$($(package)_version)-x86_64-pc-windows-gnu.tar.gz +$(package)_sha256_hash_mingw32=55c07426f791c51c8a2b6934b35784175c4abb4e03f123f3e847109c4dc1ad8b +ifeq ($(host_os),mingw32) +$(package)_build_subdir=buildos +$(package)_extra_sources = $($(package)_file_name_$(build_os)) + +define $(package)_fetch_cmds +$(call fetch_file,$(package),$($(package)_download_path),$($(package)_download_file),$($(package)_file_name),$($(package)_sha256_hash)) && \ +$(call fetch_file,$(package),$($(package)_download_path),$($(package)_file_name_$(build_os)),$($(package)_file_name_$(build_os)),$($(package)_sha256_hash_$(build_os))) +endef + +define $(package)_extract_cmds + mkdir -p $($(package)_extract_dir) && \ + echo "$($(package)_sha256_hash) $($(package)_source)" > $($(package)_extract_dir)/.$($(package)_file_name).hash && \ + echo "$($(package)_sha256_hash_$(build_os)) $($(package)_source_dir)/$($(package)_file_name_$(build_os))" >> $($(package)_extract_dir)/.$($(package)_file_name).hash && \ + $(build_SHA256SUM) -c $($(package)_extract_dir)/.$($(package)_file_name).hash && \ + mkdir mingw32 && \ + tar --strip-components=1 -xf $($(package)_source) -C mingw32 && \ + mkdir buildos && \ + tar --strip-components=1 -xf $($(package)_source_dir)/$($(package)_file_name_$(build_os)) -C buildos +endef + +define $(package)_stage_cmds + ./install.sh --destdir=$($(package)_staging_dir) --prefix=$(host_prefix)/native --disable-ldconfig && \ + cp -r ../mingw32/rust-std-x86_64-pc-windows-gnu/lib/rustlib/x86_64-pc-windows-gnu $($(package)_staging_dir)$(host_prefix)/native/lib/rustlib +endef +else define $(package)_stage_cmds ./install.sh --destdir=$($(package)_staging_dir) --prefix=$(host_prefix)/native --disable-ldconfig endef +endif diff --git a/depends/patches/librustzcash/cargo.config b/depends/patches/librustzcash/cargo.config index 7696632a1..a54c9a4a8 100644 --- a/depends/patches/librustzcash/cargo.config +++ b/depends/patches/librustzcash/cargo.config @@ -13,3 +13,6 @@ replace-with = "vendored-sources" [source.vendored-sources] directory = "CRATE_REGISTRY" + +[target.x86_64-pc-windows-gnu] +linker = "x86_64-w64-mingw32-gcc" diff --git a/src/Makefile.am b/src/Makefile.am index e3a4b60a0..4af45a0cd 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -54,7 +54,7 @@ endif $(LIBSECP256K1): $(wildcard secp256k1/src/*) $(wildcard secp256k1/include/*) $(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C $(@D) $(@F) -LIBSNARK_CXXFLAGS = -fPIC -DBINARY_OUTPUT -DNO_PT_COMPRESSION=1 -fstack-protector-all +LIBSNARK_CXXFLAGS = $(AM_CXXFLAGS) $(PIC_FLAGS) -DBINARY_OUTPUT -DNO_PT_COMPRESSION=1 -fstack-protector-all LIBSNARK_CONFIG_FLAGS = CURVE=ALT_BN128 NO_PROCPS=1 NO_DOCS=1 STATIC=1 NO_SUPERCOP=1 FEATUREFLAGS=-DMONTGOMERY_OUTPUT NO_COPY_DEPINST=1 NO_COMPILE_LIBGTEST=1 if HAVE_OPENMP LIBSNARK_CONFIG_FLAGS += MULTICORE=1 @@ -64,10 +64,10 @@ LIBSNARK_CONFIG_FLAGS += PLATFORM=darwin endif $(LIBSNARK): $(wildcard snark/src/*) - $(AM_V_at) CXXFLAGS="$(LIBSNARK_CXXFLAGS)" $(MAKE) $(AM_MAKEFLAGS) -C snark/ DEPINST="$(LIBSNARK_DEPINST)" $(LIBSNARK_CONFIG_FLAGS) OPTFLAGS="-O2 -march=x86-64" + $(AM_V_at) CC="$(CC)" CXX="$(CXX)" AR="$(AR)" CXXFLAGS="$(LIBSNARK_CXXFLAGS)" $(MAKE) $(AM_MAKEFLAGS) -C snark/ DEPINST="$(LIBSNARK_DEPINST)" $(LIBSNARK_CONFIG_FLAGS) OPTFLAGS="-O2 -march=x86-64" libsnark-tests: $(wildcard snark/src/*) - $(AM_V_at) CXXFLAGS="$(LIBSNARK_CXXFLAGS)" $(MAKE) $(AM_MAKEFLAGS) -C snark/ check DEPINST="$(LIBSNARK_DEPINST)" $(LIBSNARK_CONFIG_FLAGS) OPTFLAGS="-O2 -march=x86-64" + $(AM_V_at) CC="$(CC)" CXX="$(CXX)" AR="$(AR)" CXXFLAGS="$(LIBSNARK_CXXFLAGS)" $(MAKE) $(AM_MAKEFLAGS) -C snark/ check DEPINST="$(LIBSNARK_DEPINST)" $(LIBSNARK_CONFIG_FLAGS) OPTFLAGS="-O2 -march=x86-64" $(LIBUNIVALUE): $(wildcard univalue/lib/*) $(wildcard univalue/include/*) $(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C $(@D) $(@F) @@ -527,11 +527,9 @@ libzcash_a_SOURCES = \ zcash/circuit/prfs.tcc \ zcash/circuit/utils.tcc -libzcash_a_CPPFLAGS = -fPIC -DBINARY_OUTPUT -DCURVE_ALT_BN128 -DBOOST_SPIRIT_THREADSAFE -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS $(HARDENED_CPPFLAGS) $(HARDENED_CXXFLAGS) $(HARDENED_LDFLAGS) -pipe $(SAN_LDFLAGS) -O1 -g -Wstack-protector $(SAN_CXXFLAGS) -fstack-protector-all -fPIE -fvisibility=hidden -DSTATIC $(BITCOIN_INCLUDES) - -libzcash_a_CXXFLAGS = $(SAN_CXXFLAGS) $(HARDENED_CXXFLAGS) -fwrapv -fno-strict-aliasing - -libzcash_a_LDFLAGS = $(SAN_LDFLAGS) $(HARDENED_LDFLAGS) +libzcash_a_CPPFLAGS = $(AM_CPPFLAGS) $(PIC_FLAGS) -DBINARY_OUTPUT -DCURVE_ALT_BN128 -DBOOST_SPIRIT_THREADSAFE -fvisibility=hidden -DSTATIC $(BITCOIN_INCLUDES) +libzcash_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) +libzcash_a_LDFLAGS = $(AM_LDFLAGS) libzcash_a_CPPFLAGS += -DMONTGOMERY_OUTPUT 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/gtest/test_paymentdisclosure.cpp b/src/gtest/test_paymentdisclosure.cpp index ce1322dbb..c166cdbe1 100644 --- a/src/gtest/test_paymentdisclosure.cpp +++ b/src/gtest/test_paymentdisclosure.cpp @@ -99,7 +99,7 @@ TEST(paymentdisclosure, mainnet) { boost::filesystem::create_directories(pathTemp); mapArgs["-datadir"] = pathTemp.string(); - std::cout << "Test payment disclosure database created in folder: " << pathTemp.native() << std::endl; + std::cout << "Test payment disclosure database created in folder: " << pathTemp.string() << std::endl; PaymentDisclosureDBTest mydb(pathTemp); diff --git a/src/metrics.cpp b/src/metrics.cpp index 23f005a3e..680b74bb5 100644 --- a/src/metrics.cpp +++ b/src/metrics.cpp @@ -16,7 +16,11 @@ #include #include #include +#ifdef WIN32 +#include +#else #include +#endif #include void AtomicTimer::start() @@ -410,6 +414,30 @@ int printInitMessage() return 2; } +#ifdef WIN32 +#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004 + +bool enableVTMode() +{ + // Set output mode to handle virtual terminal sequences + HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); + if (hOut == INVALID_HANDLE_VALUE) { + return false; + } + + DWORD dwMode = 0; + if (!GetConsoleMode(hOut, &dwMode)) { + return false; + } + + dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; + if (!SetConsoleMode(hOut, dwMode)) { + return false; + } + return true; +} +#endif + void ThreadShowMetricsScreen() { // Make this thread recognisable as the metrics screen thread @@ -421,6 +449,10 @@ void ThreadShowMetricsScreen() int64_t nRefresh = GetArg("-metricsrefreshtime", isTTY ? 1 : 600); if (isScreen) { +#ifdef WIN32 + enableVTMode(); +#endif + // Clear screen std::cout << "\e[2J"; @@ -444,11 +476,18 @@ void ThreadShowMetricsScreen() // Get current window size if (isTTY) { +#ifdef WIN32 + CONSOLE_SCREEN_BUFFER_INFO csbi; + if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi) != 0) { + cols = csbi.srWindow.Right - csbi.srWindow.Left + 1; + } +#else struct winsize w; w.ws_col = 0; if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) != -1 && w.ws_col != 0) { cols = w.ws_col; } +#endif } if (isScreen) { @@ -473,7 +512,13 @@ void ThreadShowMetricsScreen() if (isScreen) { // Explain how to exit - std::cout << "[" << _("Press Ctrl+C to exit") << "] [" << _("Set 'showmetrics=0' to hide") << "]" << std::endl; + std::cout << "["; +#ifdef WIN32 + std::cout << _("'zcash-cli.exe stop' to exit"); +#else + std::cout << _("Press Ctrl+C to exit"); +#endif + std::cout << "] [" << _("Set 'showmetrics=0' to hide") << "]" << std::endl; } else { // Print delineator std::cout << "----------------------------------------" << std::endl; 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..7556e0140 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..24832ed51 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"; @@ -22,21 +21,21 @@ TEST(algebra, bigint) const char *b2_binary = "0000000000000000000000000000010101111101101000000110100001011010" "1101101010001001000001101000101000100110011001110001111110100010"; - bigint<1> b0 = bigint<1>(0ul); + bigint<1> b0 = bigint<1>(UINT64_C(0)); 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(), UINT64_C(0)); EXPECT_TRUE(b0.is_zero()); - EXPECT_EQ(b1.as_ulong(), 76749407ul); + EXPECT_EQ(b1.as_uint64(), UINT64_C(76749407)); EXPECT_FALSE(b1.is_zero()); - EXPECT_EQ(b2.as_ulong(), 15747124762497195938ul); + EXPECT_EQ(b2.as_uint64(), UINT64_C(15747124762497195938)); EXPECT_FALSE(b2.is_zero()); EXPECT_NE(b0, b1); EXPECT_FALSE(b0 == b1); - EXPECT_EQ(b2.max_bits(), 128); - EXPECT_EQ(b2.num_bits(), 99); + EXPECT_EQ(b2.max_bits(), 128u); + EXPECT_EQ(b2.num_bits(), 99u); for (size_t i = 0; i < 128; i++) { EXPECT_EQ(b2.test_bit(i), (b2_binary[127-i] == '1')); } @@ -60,8 +59,8 @@ TEST(algebra, bigint) bigint<2> quotient; 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_LT(quotient.num_bits(), static_cast(GMP_NUMB_BITS)); + 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); @@ -78,14 +77,14 @@ TEST(algebra, bigint) EXPECT_FALSE(b3a > b3); 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_LT(remainder.num_bits(), GMP_NUMB_BITS); - EXPECT_EQ(remainder.as_ulong(), 42); + EXPECT_LT(quotient.num_bits(), static_cast(GMP_NUMB_BITS)); + EXPECT_EQ(quotient.as_uint64(), b1.as_uint64()); + EXPECT_LT(remainder.num_bits(), static_cast(GMP_NUMB_BITS)); + EXPECT_EQ(remainder.as_uint64(), 42u); b3a.clear(); EXPECT_TRUE(b3a.is_zero()); - EXPECT_EQ(b3a.num_bits(), 0); + EXPECT_EQ(b3a.num_bits(), 0u); EXPECT_FALSE(b3.is_zero()); bigint<4> bx = bigint<4>().randomize(); diff --git a/src/snark/libsnark/algebra/fields/tests/test_fields.cpp b/src/snark/libsnark/algebra/fields/tests/test_fields.cpp index 969800d8b..2101fad9d 100644 --- a/src/snark/libsnark/algebra/fields/tests/test_fields.cpp +++ b/src/snark/libsnark/algebra/fields/tests/test_fields.cpp @@ -88,7 +88,7 @@ void test_Frobenius() template void test_unitary_inverse() { - EXPECT_EQ(FieldT::extension_degree() % 2, 0); + EXPECT_EQ(FieldT::extension_degree() % 2, 0u); FieldT a = FieldT::random_element(); FieldT aqcubed_minus1 = a.Frobenius_map(FieldT::extension_degree()/2) * a.inverse(); EXPECT_EQ(aqcubed_minus1.inverse(), aqcubed_minus1.unitary_inverse()); diff --git a/src/snark/libsnark/algebra/scalar_multiplication/multiexp.tcc b/src/snark/libsnark/algebra/scalar_multiplication/multiexp.tcc index a6b14c4df..080e4cf23 100644 --- a/src/snark/libsnark/algebra/scalar_multiplication/multiexp.tcc +++ b/src/snark/libsnark/algebra/scalar_multiplication/multiexp.tcc @@ -190,7 +190,7 @@ T multi_exp_inner(typename std::vector::const_iterator vec_start, if (vec_len != odd_vec_len) { g.emplace_back(T::zero()); - opt_q.emplace_back(ordered_exponent(odd_vec_len - 1, bigint(0ul))); + opt_q.emplace_back(ordered_exponent(odd_vec_len - 1, bigint(UINT64_C(0)))); } assert(g.size() % 2 == 1); assert(opt_q.size() == g.size()); @@ -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..e6f1f4525 100644 --- a/src/snark/libsnark/common/profiling.cpp +++ b/src/snark/libsnark/common/profiling.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -28,14 +29,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 +46,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 +60,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,15 +101,15 @@ 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); const double avg_ms = total_ms / cnt; - 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); + printf(" %-45s: %12.5fms = %" PRId64 " * %0.5fms (%zu invocations, %0.5fms = %" PRId64 " * %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 +158,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 +174,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 +202,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 +234,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 +248,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 +291,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..4e2d9fce3 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_constraints() template void loose_multiplexing_gadget::generate_r1cs_witness() { - /* assumes that idx can be fit in ulong; true for our purposes for now */ + /* assumes that idx can be fit in uint64_t; 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.hpp b/src/snark/libsnark/gadgetlib1/gadgets/hashes/sha256/sha256_components.hpp index c2f31e3af..2f7e71e35 100644 --- a/src/snark/libsnark/gadgetlib1/gadgets/hashes/sha256/sha256_components.hpp +++ b/src/snark/libsnark/gadgetlib1/gadgets/hashes/sha256/sha256_components.hpp @@ -78,7 +78,7 @@ public: pb_linear_combination_array g; pb_linear_combination_array h; pb_variable W; - long K; + uint32_t K; pb_linear_combination_array new_a; pb_linear_combination_array new_e; @@ -92,7 +92,7 @@ public: const pb_linear_combination_array &g, const pb_linear_combination_array &h, const pb_variable &W, - const long &K, + const uint32_t &K, const pb_linear_combination_array &new_a, const pb_linear_combination_array &new_e, const std::string &annotation_prefix); 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..41ad20883 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 }; @@ -149,7 +149,7 @@ sha256_round_function_gadget::sha256_round_function_gadget(protoboard &g, const pb_linear_combination_array &h, const pb_variable &W, - const long &K, + const uint32_t &K, const pb_linear_combination_array &new_a, const pb_linear_combination_array &new_e, const std::string &annotation_prefix) : 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/test/rpc_wallet_tests.cpp b/src/test/rpc_wallet_tests.cpp index edbcb6552..119acc0c3 100644 --- a/src/test/rpc_wallet_tests.cpp +++ b/src/test/rpc_wallet_tests.cpp @@ -421,7 +421,7 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_z_exportwallet) BOOST_CHECK_THROW(CallRPC(string("z_exportwallet ") + tmpfilename.string()), runtime_error); // set exportdir - mapArgs["-exportdir"] = tmppath.native(); + mapArgs["-exportdir"] = tmppath.string(); // run some tests BOOST_CHECK_THROW(CallRPC("z_exportwallet"), runtime_error); @@ -501,7 +501,7 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_z_importwallet) // write test data to file boost::filesystem::path temp = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path(); - const std::string path = temp.native(); + const std::string path = temp.string(); std::ofstream file(path); file << testWalletDump; file << std::flush; 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(); diff --git a/zcutil/build.sh b/zcutil/build.sh index f10d68d74..c3bea9ea9 100755 --- a/zcutil/build.sh +++ b/zcutil/build.sh @@ -33,14 +33,6 @@ if [[ -z "${HOST-}" ]]; then HOST="$BUILD" fi -# Allow override to $CC and $CXX for porters. Most users will not need it. -if [[ -z "${CC-}" ]]; then - CC=gcc -fi -if [[ -z "${CXX-}" ]]; then - CXX=g++ -fi - # Allow users to set arbitrary compile flags. Most users will not need this. if [[ -z "${CONFIGURE_FLAGS-}" ]]; then CONFIGURE_FLAGS="" @@ -105,15 +97,11 @@ then shift fi -PREFIX="$(pwd)/depends/$BUILD/" - eval "$MAKE" --version -eval "$CC" --version -eval "$CXX" --version as --version ld -v HOST="$HOST" BUILD="$BUILD" NO_PROTON="$PROTON_ARG" "$MAKE" "$@" -C ./depends/ V=1 ./autogen.sh -CC="$CC" CXX="$CXX" ./configure --prefix="${PREFIX}" --host="$HOST" --build="$BUILD" "$HARDENING_ARG" "$LCOV_ARG" "$TEST_ARG" "$MINING_ARG" "$PROTON_ARG" $CONFIGURE_FLAGS --enable-werror CXXFLAGS='-g' +CONFIG_SITE="$PWD/depends/$HOST/share/config.site" ./configure "$HARDENING_ARG" "$LCOV_ARG" "$TEST_ARG" "$MINING_ARG" "$PROTON_ARG" $CONFIGURE_FLAGS CXXFLAGS='-g' "$MAKE" "$@" V=1