From ee3fa7020e8f11940d0e437f6aa974f19e09e371 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Sat, 27 Oct 2018 17:15:32 +1300 Subject: [PATCH] Pass parameter paths as native strings to librustzcash --- depends/packages/librustzcash.mk | 4 ++-- src/gtest/main.cpp | 30 ++++++++++++++++++------------ src/init.cpp | 24 +++++++++++++++--------- src/test/test_bitcoin.cpp | 18 ++++++++++++------ 4 files changed, 47 insertions(+), 29 deletions(-) diff --git a/depends/packages/librustzcash.mk b/depends/packages/librustzcash.mk index c3437120a..f2953dc8d 100644 --- a/depends/packages/librustzcash.mk +++ b/depends/packages/librustzcash.mk @@ -3,8 +3,8 @@ $(package)_version=0.1 $(package)_download_path=https://github.com/zcash/$(package)/archive/ $(package)_file_name=$(package)-$($(package)_git_commit).tar.gz $(package)_download_file=$($(package)_git_commit).tar.gz -$(package)_sha256_hash=d2f0d93876b490f9c20060d28dcad833eb85e0609163a1106f540153e1b459c9 -$(package)_git_commit=041671f6425563bdef43c7c907a8396da76f8f21 +$(package)_sha256_hash=9909ec59fa7a411c2071d6237b3363a0bc6e5e42358505cf64b7da0f58a7ff5a +$(package)_git_commit=06da3b9ac8f278e5d4ae13088cf0a4c03d2c13f5 $(package)_dependencies=rust $(rust_crates) $(package)_patches=cargo.config 0001-Start-using-cargo-clippy-for-CI.patch remove-dev-dependencies.diff diff --git a/src/gtest/main.cpp b/src/gtest/main.cpp index 00700d05b..5f32b5fef 100644 --- a/src/gtest/main.cpp +++ b/src/gtest/main.cpp @@ -34,19 +34,25 @@ int main(int argc, char **argv) { boost::filesystem::path sapling_output = ZC_GetParamsDir() / "sapling-output.params"; boost::filesystem::path sprout_groth16 = ZC_GetParamsDir() / "sprout-groth16.params"; - std::string sapling_spend_str = sapling_spend.string(); - std::string sapling_output_str = sapling_output.string(); - std::string sprout_groth16_str = sprout_groth16.string(); + static_assert( + sizeof(boost::filesystem::path::value_type) == sizeof(codeunit), + "librustzcash not configured correctly"); + auto sapling_spend_str = sapling_spend.native(); + auto sapling_output_str = sapling_output.native(); + auto sprout_groth16_str = sprout_groth16.native(); + + librustzcash_init_zksnark_params( + reinterpret_cast(sapling_spend_str.c_str()), + sapling_spend_str.length(), + "8270785a1a0d0bc77196f000ee6d221c9c9894f55307bd9357c3f0105d31ca63991ab91324160d8f53e2bbd3c2633a6eb8bdf5205d822e7f3f73edac51b2b70c", + reinterpret_cast(sapling_output_str.c_str()), + sapling_output_str.length(), + "657e3d38dbb5cb5e7dd2970e8b03d69b4787dd907285b5a7f0790dcc8072f60bf593b32cc2d1c030e00ff5ae64bf84c5c3beb84ddc841d48264b4a171744d028", + reinterpret_cast(sprout_groth16_str.c_str()), + sprout_groth16_str.length(), + "e9b238411bd6c0ec4791e9d04245ec350c9c5744f5610dfcce4365d5ca49dfefd5054e371842b3f88fa1b9d7e8e075249b3ebabd167fa8b0f3161292d36c180a" + ); - librustzcash_init_zksnark_params( - sapling_spend_str.c_str(), - "8270785a1a0d0bc77196f000ee6d221c9c9894f55307bd9357c3f0105d31ca63991ab91324160d8f53e2bbd3c2633a6eb8bdf5205d822e7f3f73edac51b2b70c", - sapling_output_str.c_str(), - "657e3d38dbb5cb5e7dd2970e8b03d69b4787dd907285b5a7f0790dcc8072f60bf593b32cc2d1c030e00ff5ae64bf84c5c3beb84ddc841d48264b4a171744d028", - sprout_groth16_str.c_str(), - "e9b238411bd6c0ec4791e9d04245ec350c9c5744f5610dfcce4365d5ca49dfefd5054e371842b3f88fa1b9d7e8e075249b3ebabd167fa8b0f3161292d36c180a" - ); - testing::InitGoogleMock(&argc, argv); auto ret = RUN_ALL_TESTS(); diff --git a/src/init.cpp b/src/init.cpp index 0c6cc31a6..086c6beb8 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -718,21 +718,27 @@ static void ZC_LoadParams( elapsed = float(tv_end.tv_sec-tv_start.tv_sec) + (tv_end.tv_usec-tv_start.tv_usec)/float(1000000); LogPrintf("Loaded verifying key in %fs seconds.\n", elapsed); - std::string sapling_spend_str = sapling_spend.string(); - std::string sapling_output_str = sapling_output.string(); - std::string sprout_groth16_str = sprout_groth16.string(); + static_assert( + sizeof(boost::filesystem::path::value_type) == sizeof(codeunit), + "librustzcash not configured correctly"); + auto sapling_spend_str = sapling_spend.native(); + auto sapling_output_str = sapling_output.native(); + auto sprout_groth16_str = sprout_groth16.native(); - LogPrintf("Loading Sapling (Spend) parameters from %s\n", sapling_spend_str.c_str()); - LogPrintf("Loading Sapling (Output) parameters from %s\n", sapling_output_str.c_str()); - LogPrintf("Loading Sapling (Sprout Groth16) parameters from %s\n", sprout_groth16_str.c_str()); + LogPrintf("Loading Sapling (Spend) parameters from %s\n", sapling_spend.string().c_str()); + LogPrintf("Loading Sapling (Output) parameters from %s\n", sapling_output.string().c_str()); + LogPrintf("Loading Sapling (Sprout Groth16) parameters from %s\n", sprout_groth16.string().c_str()); gettimeofday(&tv_start, 0); librustzcash_init_zksnark_params( - sapling_spend_str.c_str(), + reinterpret_cast(sapling_spend_str.c_str()), + sapling_spend_str.length(), "8270785a1a0d0bc77196f000ee6d221c9c9894f55307bd9357c3f0105d31ca63991ab91324160d8f53e2bbd3c2633a6eb8bdf5205d822e7f3f73edac51b2b70c", - sapling_output_str.c_str(), + reinterpret_cast(sapling_output_str.c_str()), + sapling_output_str.length(), "657e3d38dbb5cb5e7dd2970e8b03d69b4787dd907285b5a7f0790dcc8072f60bf593b32cc2d1c030e00ff5ae64bf84c5c3beb84ddc841d48264b4a171744d028", - sprout_groth16_str.c_str(), + reinterpret_cast(sprout_groth16_str.c_str()), + sprout_groth16_str.length(), "e9b238411bd6c0ec4791e9d04245ec350c9c5744f5610dfcce4365d5ca49dfefd5054e371842b3f88fa1b9d7e8e075249b3ebabd167fa8b0f3161292d36c180a" ); diff --git a/src/test/test_bitcoin.cpp b/src/test/test_bitcoin.cpp index 2b4acad84..ce1442b09 100644 --- a/src/test/test_bitcoin.cpp +++ b/src/test/test_bitcoin.cpp @@ -45,16 +45,22 @@ JoinSplitTestingSetup::JoinSplitTestingSetup() boost::filesystem::path sapling_output = ZC_GetParamsDir() / "sapling-output.params"; boost::filesystem::path sprout_groth16 = ZC_GetParamsDir() / "sprout-groth16.params"; - std::string sapling_spend_str = sapling_spend.string(); - std::string sapling_output_str = sapling_output.string(); - std::string sprout_groth16_str = sprout_groth16.string(); + static_assert( + sizeof(boost::filesystem::path::value_type) == sizeof(codeunit), + "librustzcash not configured correctly"); + auto sapling_spend_str = sapling_spend.native(); + auto sapling_output_str = sapling_output.native(); + auto sprout_groth16_str = sprout_groth16.native(); librustzcash_init_zksnark_params( - sapling_spend_str.c_str(), + reinterpret_cast(sapling_spend_str.c_str()), + sapling_spend_str.length(), "8270785a1a0d0bc77196f000ee6d221c9c9894f55307bd9357c3f0105d31ca63991ab91324160d8f53e2bbd3c2633a6eb8bdf5205d822e7f3f73edac51b2b70c", - sapling_output_str.c_str(), + reinterpret_cast(sapling_output_str.c_str()), + sapling_output_str.length(), "657e3d38dbb5cb5e7dd2970e8b03d69b4787dd907285b5a7f0790dcc8072f60bf593b32cc2d1c030e00ff5ae64bf84c5c3beb84ddc841d48264b4a171744d028", - sprout_groth16_str.c_str(), + reinterpret_cast(sprout_groth16_str.c_str()), + sprout_groth16_str.length(), "e9b238411bd6c0ec4791e9d04245ec350c9c5744f5610dfcce4365d5ca49dfefd5054e371842b3f88fa1b9d7e8e075249b3ebabd167fa8b0f3161292d36c180a" ); }