diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b18f3a36..157ca7a00 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,6 +65,11 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") target_link_libraries(ProofOfSpace fse) target_link_libraries(HellmanAttacks fse) target_link_libraries(RunTests fse) +elseif (WIN32) + target_link_libraries(chiapos PRIVATE fse) + target_link_libraries(ProofOfSpace fse) + target_link_libraries(HellmanAttacks fse) + target_link_libraries(RunTests fse) else() target_link_libraries(chiapos PRIVATE fse stdc++fs) target_link_libraries(ProofOfSpace fse stdc++fs) diff --git a/src/bits.hpp b/src/bits.hpp index 96dc19e6e..c78355bf7 100644 --- a/src/bits.hpp +++ b/src/bits.hpp @@ -21,8 +21,11 @@ #include #include #include "./util.hpp" -#include "./stack_allocator.h" +#include +#include +#include +using namespace std; #define kBufSize 5 @@ -33,10 +36,23 @@ struct SmallVector { typedef uint16_t size_type; - SmallVector() noexcept { + SmallVector() { + v_ = new uint128_t[5]; count_ = 0; } + SmallVector(const SmallVector &other) + { + v_ = new uint128_t[5]; + count_=other.count_; + for (size_type i = 0; i < other.count_; i++) + v_[i] = other.v_[i]; + } + + ~SmallVector() { + delete[] v_; + } + uint128_t& operator[] (const uint16_t index) { return v_[index]; } @@ -61,7 +77,7 @@ struct SmallVector { } private: - uint128_t v_[5]; + uint128_t *v_; size_type count_; }; @@ -71,10 +87,23 @@ struct SmallVector { struct ParkVector { typedef uint32_t size_type; - ParkVector() noexcept { + ParkVector() { + v_ = new uint128_t[1024]; count_ = 0; } + ParkVector(const ParkVector &other) + { + v_ = new uint128_t[1024]; + count_=other.count_; + for (size_type i = 0; i < other.count_; i++) + v_[i] = other.v_[i]; + } + + ~ParkVector() { + delete[] v_; + } + uint128_t& operator[] (const uint32_t index) { return v_[index]; } @@ -99,7 +128,7 @@ struct ParkVector { } private: - uint128_t v_[1024]; + uint128_t *v_; size_type count_; }; diff --git a/src/plotter_disk.hpp b/src/plotter_disk.hpp index 92a36a105..3300922fe 100644 --- a/src/plotter_disk.hpp +++ b/src/plotter_disk.hpp @@ -664,9 +664,17 @@ class DiskPlotter { // Sort keys represent the ordering of entries, sorted by (y, pos, offset), // but using less bits (only k+1 instead of 2k + 9, etc.) // This is a map from old position to array of sort keys (one for each R entry with this pos) - Bits old_sort_keys[kReadMinusWrite][kMaxMatchesSingleEntry]; + //Bits old_sort_keys[kReadMinusWrite][kMaxMatchesSingleEntry]; + Bits **old_sort_keys = new Bits*[kReadMinusWrite]; + for(int i = 0; i < kReadMinusWrite; ++i) { + old_sort_keys[i] = new Bits[kMaxMatchesSingleEntry]; + } // Map from old position to other positions that it matches with - uint64_t old_offsets[kReadMinusWrite][kMaxMatchesSingleEntry]; + //uint64_t old_offsets[kReadMinusWrite][kMaxMatchesSingleEntry]; + uint64_t **old_offsets = new uint64_t*[kReadMinusWrite]; + for(int i = 0; i < kReadMinusWrite; ++i) { + old_offsets[i] = new uint64_t[kMaxMatchesSingleEntry]; + } // Map from old position to count (number of times it appears) uint16_t old_counters[kReadMinusWrite]; @@ -877,6 +885,16 @@ class DiskPlotter { delete[] left_entry_buf; delete[] new_left_entry_buf; delete[] right_entry_buf; + + for(int i = 0; i < kReadMinusWrite; ++i) { + delete [] old_offsets[i]; + } + delete [] old_offsets; + + for(int i = 0; i < kReadMinusWrite; ++i) { + delete [] old_sort_keys[i]; + } + delete [] old_sort_keys; } delete[] memory; } diff --git a/src/sort_on_disk.hpp b/src/sort_on_disk.hpp index 7b156fc26..00498ffe5 100644 --- a/src/sort_on_disk.hpp +++ b/src/sort_on_disk.hpp @@ -31,21 +31,10 @@ class SortOnDiskUtils { * index, to the given index. */ inline static uint64_t ExtractNum(uint8_t* bytes, uint32_t len_bytes, uint32_t begin_bits, uint32_t take_bits) { - uint32_t start_index = begin_bits / 8; - uint32_t end_index; if ((begin_bits + take_bits) / 8 > len_bytes - 1) { - take_bits = (len_bytes) * 8 - begin_bits; + take_bits = len_bytes * 8 - begin_bits; } - end_index = (begin_bits + take_bits) / 8; - - assert(take_bits <= 64); - uint64_t sum = bytes[start_index] & ((1 << (8 - (begin_bits % 8))) - 1); - for (uint32_t i = start_index + 1; i <= end_index; i++) { - sum = (sum << 8); - if(i < len_bytes) // Fix to prevent overflow and maintain compatibility. Function may only return 57 bits in some cases - sum += bytes[i]; - } - return sum >> (8 - ((begin_bits + take_bits) % 8)); + return Util::SliceInt64FromBytes(bytes, len_bytes, begin_bits, take_bits); } /* @@ -92,10 +81,15 @@ class Disk { class FileDisk : public Disk { public: - inline explicit FileDisk(const std::string& filename) { + FileDisk(const std::string& filename) { + buf_ = new char[BUF_SIZE]; Initialize(filename); } + ~FileDisk() { + delete[] buf_; + } + inline void Close() { f_.close(); } @@ -153,7 +147,7 @@ class FileDisk : public Disk { } std::string filename_; - char buf_[BUF_SIZE]; + char *buf_; std::fstream f_; }; diff --git a/tests/test.cpp b/tests/test.cpp index 3dd0dc66d..8e537df46 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -384,9 +384,10 @@ TEST_CASE("Plotting") { TEST_CASE("Invalid plot") { SECTION("File gets deleted") { + string filename = "invalid-plot.dat"; + { DiskPlotter plotter = DiskPlotter(); uint8_t memo[5] = {1, 2, 3, 4, 5}; - string filename = "invalid-plot.dat"; uint8_t k = 22; plotter.CreatePlotDisk(".", ".", filename, k, memo, 5, plot_id_1, 32); DiskProver prover(filename); @@ -402,11 +403,12 @@ TEST_CASE("Invalid plot") { LargeBits quality = verifier.ValidateProof(plot_id_1, k, challenge, proof_data, k*8); REQUIRE(quality == qualities[index]); } + delete[] proof_data; + } REQUIRE(remove(filename.c_str()) == 0); REQUIRE_THROWS_WITH([&](){ DiskProver p(filename); }(), "Invalid file " + filename); - delete[] proof_data; } } diff --git a/tests/test_python_bindings.py b/tests/test_python_bindings.py index 75d039767..f5680aa6a 100644 --- a/tests/test_python_bindings.py +++ b/tests/test_python_bindings.py @@ -32,6 +32,7 @@ def test_k_21(self): print(f"total proofs {total_proofs} out of {iterations}\ {total_proofs / iterations}") assert total_proofs == 4647 + pr = None Path("myplot.dat").unlink() diff --git a/windows-build.sh b/windows-build.sh new file mode 100644 index 000000000..2e852bf3d --- /dev/null +++ b/windows-build.sh @@ -0,0 +1,24 @@ +#!/bin/sh -x + +# Stop in case of error +set -e + +#python -m pip install cibuildwheel==1.3.0 + + +# build just python 3.7 +export CIBW_BUILD="cp37-win_amd64" +#export CIBW_BEFORE_BUILD_WINDOWS="python -m pip install --upgrade pip" +export CIBW_TEST_REQUIRES="pytest" +export CIBW_TEST_COMMAND="py.test -v {project}/tests" + + +export PATH=$PATH:"C:\msys64\mingw64\bin\cmake.exe" +echo "PWD is $PWD" + +cmake -G "MSYS Makefiles" --build . +make +$PWD/RunTests.exe +#Test failing for windows: +py.test -v $PWD/tests/ +#pip -vv wheel .