aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/core_proxy/core_proxy.cpp2
-rw-r--r--tests/core_tests/CMakeLists.txt3
-rw-r--r--tests/core_tests/chaingen.h52
-rw-r--r--tests/core_tests/chaingen_main.cpp19
-rw-r--r--tests/core_tests/chaingen_tests_list.h1
-rw-r--r--tests/core_tests/multisig.cpp523
-rw-r--r--tests/core_tests/multisig.h199
-rw-r--r--tests/crypto/CMakeLists.txt1
-rw-r--r--tests/data/fuzz/base58/ENC10
-rw-r--r--tests/data/fuzz/base58/ENC21
-rw-r--r--tests/data/fuzz/http-client/RESP18
-rw-r--r--tests/data/fuzz/levin/LEVIN1bin0 -> 33 bytes
-rw-r--r--tests/data/fuzz/load-from-binary/BINARY1bin0 -> 10 bytes
-rw-r--r--tests/data/fuzz/load-from-json/JSON11
-rw-r--r--tests/data/fuzz/parse-url/URL11
-rw-r--r--tests/data/fuzz/parse-url/URL21
-rw-r--r--tests/functional_tests/main.cpp1
-rw-r--r--tests/fuzz/CMakeLists.txt77
-rw-r--r--tests/fuzz/base58.cpp74
-rw-r--r--tests/fuzz/block.cpp2
-rw-r--r--tests/fuzz/cold-outputs.cpp2
-rw-r--r--tests/fuzz/cold-transaction.cpp2
-rw-r--r--tests/fuzz/fuzzer.cpp34
-rw-r--r--tests/fuzz/http-client.cpp98
-rw-r--r--tests/fuzz/levin.cpp345
-rw-r--r--tests/fuzz/load_from_binary.cpp76
-rw-r--r--tests/fuzz/load_from_json.cpp76
-rw-r--r--tests/fuzz/parse_url.cpp74
-rw-r--r--tests/fuzz/signature.cpp2
-rw-r--r--tests/fuzz/transaction.cpp2
-rw-r--r--tests/performance_tests/cn_slow_hash.h1
-rw-r--r--tests/unit_tests/CMakeLists.txt4
-rw-r--r--tests/unit_tests/ban.cpp5
-rw-r--r--tests/unit_tests/blockchain_db.cpp1
-rw-r--r--tests/unit_tests/http.cpp3
-rw-r--r--tests/unit_tests/main.cpp11
-rw-r--r--tests/unit_tests/memwipe.cpp64
-rw-r--r--tests/unit_tests/multisig.cpp188
-rw-r--r--tests/unit_tests/ringct.cpp18
-rw-r--r--tests/unit_tests/serialization.cpp2
-rw-r--r--tests/unit_tests/slow_memmem.cpp4
-rw-r--r--tests/unit_tests/vercmp.cpp2
42 files changed, 1927 insertions, 53 deletions
diff --git a/tests/core_proxy/core_proxy.cpp b/tests/core_proxy/core_proxy.cpp
index fd07a5d2e..d6c89fc39 100644
--- a/tests/core_proxy/core_proxy.cpp
+++ b/tests/core_proxy/core_proxy.cpp
@@ -42,8 +42,10 @@
#include "common/command_line.h"
#include "console_handler.h"
#include "p2p/net_node.h"
+#include "p2p/net_node.inl"
//#include "cryptonote_core/cryptonote_core.h"
#include "cryptonote_protocol/cryptonote_protocol_handler.h"
+#include "cryptonote_protocol/cryptonote_protocol_handler.inl"
#include "core_proxy.h"
#include "version.h"
diff --git a/tests/core_tests/CMakeLists.txt b/tests/core_tests/CMakeLists.txt
index 68f2e9816..d80d62135 100644
--- a/tests/core_tests/CMakeLists.txt
+++ b/tests/core_tests/CMakeLists.txt
@@ -36,6 +36,7 @@ set(core_tests_sources
chaingen_main.cpp
double_spend.cpp
integer_overflow.cpp
+ multisig.cpp
ring_signature_1.cpp
transaction_tests.cpp
tx_validation.cpp
@@ -52,6 +53,7 @@ set(core_tests_headers
double_spend.h
double_spend.inl
integer_overflow.h
+ multisig.h
ring_signature_1.h
transaction_tests.h
tx_validation.h
@@ -63,6 +65,7 @@ add_executable(core_tests
${core_tests_headers})
target_link_libraries(core_tests
PRIVATE
+ multisig
cryptonote_core
p2p
version
diff --git a/tests/core_tests/chaingen.h b/tests/core_tests/chaingen.h
index 7cad04047..9fed95183 100644
--- a/tests/core_tests/chaingen.h
+++ b/tests/core_tests/chaingen.h
@@ -467,7 +467,7 @@ inline bool do_replay_events(std::vector<test_event_entry>& events)
// FIXME: make sure that vm has arg_testnet_on set to true or false if
// this test needs for it to be so.
get_test_options<t_test_class> gto;
- if (!c.init(vm, &gto.test_options))
+ if (!c.init(vm, NULL, &gto.test_options))
{
MERROR("Failed to init core");
return false;
@@ -505,6 +505,56 @@ inline bool do_replay_file(const std::string& filename)
cryptonote::account_base account; \
account.generate();
+#define GENERATE_MULTISIG_ACCOUNT(account, threshold, total) \
+ CHECK_AND_ASSERT_MES(threshold >= 2 && threshold <= total, false, "Invalid multisig scheme"); \
+ std::vector<cryptonote::account_base> account(total); \
+ do \
+ { \
+ for (size_t msidx = 0; msidx < total; ++msidx) \
+ account[msidx].generate(); \
+ std::unordered_set<crypto::public_key> all_multisig_keys; \
+ std::vector<std::vector<crypto::secret_key>> view_keys(total); \
+ std::vector<std::vector<crypto::public_key>> spend_keys(total); \
+ for (size_t msidx = 0; msidx < total; ++msidx) \
+ { \
+ for (size_t msidx_inner = 0; msidx_inner < total; ++msidx_inner) \
+ { \
+ if (msidx_inner != msidx) \
+ { \
+ crypto::secret_key vkh = cryptonote::get_multisig_blinded_secret_key(account[msidx_inner].get_keys().m_view_secret_key); \
+ view_keys[msidx].push_back(vkh); \
+ crypto::secret_key skh = cryptonote::get_multisig_blinded_secret_key(account[msidx_inner].get_keys().m_spend_secret_key); \
+ crypto::public_key pskh; \
+ crypto::secret_key_to_public_key(skh, pskh); \
+ spend_keys[msidx].push_back(pskh); \
+ } \
+ } \
+ } \
+ for (size_t msidx = 0; msidx < total; ++msidx) \
+ { \
+ std::vector<crypto::secret_key> multisig_keys; \
+ crypto::secret_key spend_skey; \
+ crypto::public_key spend_pkey; \
+ if (threshold == total) \
+ cryptonote::generate_multisig_N_N(account[msidx].get_keys(), spend_keys[msidx], multisig_keys, (rct::key&)spend_skey, (rct::key&)spend_pkey); \
+ else \
+ cryptonote::generate_multisig_N1_N(account[msidx].get_keys(), spend_keys[msidx], multisig_keys, (rct::key&)spend_skey, (rct::key&)spend_pkey); \
+ crypto::secret_key view_skey = cryptonote::generate_multisig_view_secret_key(account[msidx].get_keys().m_view_secret_key, view_keys[msidx]); \
+ account[msidx].make_multisig(view_skey, spend_skey, spend_pkey, multisig_keys); \
+ for (const auto &k: multisig_keys) \
+ all_multisig_keys.insert(rct::rct2pk(rct::scalarmultBase(rct::sk2rct(k)))); \
+ } \
+ if (threshold < total) \
+ { \
+ std::vector<crypto::public_key> spend_public_keys; \
+ for (const auto &k: all_multisig_keys) \
+ spend_public_keys.push_back(k); \
+ crypto::public_key spend_pkey = cryptonote::generate_multisig_N1_N_spend_public_key(spend_public_keys); \
+ for (size_t msidx = 0; msidx < total; ++msidx) \
+ account[msidx].finalize_multisig(spend_pkey); \
+ } \
+ } while(0)
+
#define MAKE_ACCOUNT(VEC_EVENTS, account) \
cryptonote::account_base account; \
account.generate(); \
diff --git a/tests/core_tests/chaingen_main.cpp b/tests/core_tests/chaingen_main.cpp
index 9eba347cd..95284c11a 100644
--- a/tests/core_tests/chaingen_main.cpp
+++ b/tests/core_tests/chaingen_main.cpp
@@ -199,6 +199,25 @@ int main(int argc, char* argv[])
GENERATE_AND_PLAY(gen_rct_tx_pre_rct_altered_extra);
GENERATE_AND_PLAY(gen_rct_tx_rct_altered_extra);
+ GENERATE_AND_PLAY(gen_multisig_tx_valid_22_1_2);
+ GENERATE_AND_PLAY(gen_multisig_tx_valid_22_1_2_many_inputs);
+ GENERATE_AND_PLAY(gen_multisig_tx_valid_22_2_1);
+ GENERATE_AND_PLAY(gen_multisig_tx_valid_33_1_23);
+ GENERATE_AND_PLAY(gen_multisig_tx_valid_33_3_21);
+ GENERATE_AND_PLAY(gen_multisig_tx_valid_23_1_2);
+ GENERATE_AND_PLAY(gen_multisig_tx_valid_23_1_3);
+ GENERATE_AND_PLAY(gen_multisig_tx_valid_23_2_1);
+ GENERATE_AND_PLAY(gen_multisig_tx_valid_23_2_3);
+ GENERATE_AND_PLAY(gen_multisig_tx_valid_45_1_234);
+ GENERATE_AND_PLAY(gen_multisig_tx_valid_45_4_135_many_inputs);
+ GENERATE_AND_PLAY(gen_multisig_tx_valid_89_3_1245789);
+ GENERATE_AND_PLAY(gen_multisig_tx_invalid_23_1__no_threshold);
+ GENERATE_AND_PLAY(gen_multisig_tx_invalid_45_5_23_no_threshold);
+ GENERATE_AND_PLAY(gen_multisig_tx_invalid_22_1__no_threshold);
+ GENERATE_AND_PLAY(gen_multisig_tx_invalid_33_1__no_threshold);
+ GENERATE_AND_PLAY(gen_multisig_tx_invalid_33_1_2_no_threshold);
+ GENERATE_AND_PLAY(gen_multisig_tx_invalid_33_1_3_no_threshold);
+
el::Level level = (failed_tests.empty() ? el::Level::Info : el::Level::Error);
MLOG(level, "\nREPORT:");
MLOG(level, " Test run: " << tests_count);
diff --git a/tests/core_tests/chaingen_tests_list.h b/tests/core_tests/chaingen_tests_list.h
index 26f88dddb..b9bbf03b4 100644
--- a/tests/core_tests/chaingen_tests_list.h
+++ b/tests/core_tests/chaingen_tests_list.h
@@ -41,6 +41,7 @@
#include "tx_validation.h"
#include "v2_tests.h"
#include "rct.h"
+#include "multisig.h"
/************************************************************************/
/* */
/************************************************************************/
diff --git a/tests/core_tests/multisig.cpp b/tests/core_tests/multisig.cpp
new file mode 100644
index 000000000..79a3a7cf4
--- /dev/null
+++ b/tests/core_tests/multisig.cpp
@@ -0,0 +1,523 @@
+// Copyright (c) 2017, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
+
+#include "ringct/rctSigs.h"
+#include "cryptonote_basic/cryptonote_basic.h"
+#include "multisig/multisig.h"
+#include "common/apply_permutation.h"
+#include "chaingen.h"
+#include "multisig.h"
+
+using namespace epee;
+using namespace crypto;
+using namespace cryptonote;
+
+//#define NO_MULTISIG
+
+//----------------------------------------------------------------------------------------------------------------------
+// Tests
+
+bool gen_multisig_tx_validation_base::generate_with(std::vector<test_event_entry>& events,
+ size_t inputs, size_t mixin, uint64_t amount_paid, bool valid,
+ size_t threshold, size_t total, size_t creator, std::vector<size_t> signers,
+ const std::function<void(std::vector<tx_source_entry> &sources, std::vector<tx_destination_entry> &destinations)> &pre_tx,
+ const std::function<void(transaction &tx)> &post_tx) const
+{
+ uint64_t ts_start = 1338224400;
+ bool r;
+
+ CHECK_AND_ASSERT_MES(total >= 2, false, "Bad scheme");
+ CHECK_AND_ASSERT_MES(threshold <= total, false, "Bad scheme");
+ CHECK_AND_ASSERT_MES(threshold >= total - 1, false, "Unsupported scheme");
+#ifdef NO_MULTISIG
+ CHECK_AND_ASSERT_MES(total <= 5, false, "Unsupported scheme");
+#endif
+ CHECK_AND_ASSERT_MES(inputs >= 1 && inputs <= 8, false, "Inputs should between 1 and 8");
+
+ // given as 1 based for clarity
+ --creator;
+ for (size_t &signer: signers)
+ --signer;
+
+ CHECK_AND_ASSERT_MES(creator < total, false, "invalid creator");
+ for (size_t signer: signers)
+ CHECK_AND_ASSERT_MES(signer < total, false, "invalid signer");
+
+#ifdef NO_MULTISIG
+ GENERATE_ACCOUNT(acc0);
+ GENERATE_ACCOUNT(acc1);
+ GENERATE_ACCOUNT(acc2);
+ GENERATE_ACCOUNT(acc3);
+ GENERATE_ACCOUNT(acc4);
+ account_base miner_account[5] = {acc0, acc1, acc2, acc3, acc4};
+#else
+ GENERATE_MULTISIG_ACCOUNT(miner_account, threshold, total);
+#endif
+
+ MAKE_GENESIS_BLOCK(events, blk_0, miner_account[creator], ts_start);
+
+ // create 8 miner accounts, and have them mine the next 8 blocks
+ // they will have a coinbase with a single out that's pseudo rct
+ constexpr size_t n_coinbases = 8;
+ cryptonote::account_base miner_accounts[n_coinbases];
+ const cryptonote::block *prev_block = &blk_0;
+ cryptonote::block blocks[n_coinbases];
+ for (size_t n = 0; n < n_coinbases; ++n) {
+ // the first block goes to the multisig account
+ miner_accounts[n].generate();
+ account_base &account = n < inputs ? miner_account[creator] : miner_accounts[n];
+ CHECK_AND_ASSERT_MES(generator.construct_block_manually(blocks[n], *prev_block, account,
+ test_generator::bf_major_ver | test_generator::bf_minor_ver | test_generator::bf_timestamp | test_generator::bf_hf_version | test_generator::bf_max_outs,
+ 4, 4, prev_block->timestamp + DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN * 2, // v2 has blocks twice as long
+ crypto::hash(), 0, transaction(), std::vector<crypto::hash>(), 0, 1, 4),
+ false, "Failed to generate block");
+ events.push_back(blocks[n]);
+ prev_block = blocks + n;
+ LOG_PRINT_L0("Initial miner tx " << n << ": " << obj_to_json_str(blocks[n].miner_tx));
+ LOG_PRINT_L0("in block: " << obj_to_json_str(blocks[n]));
+ }
+
+ // rewind
+ cryptonote::block blk_r, blk_last;
+ {
+ blk_last = blocks[n_coinbases - 1];
+ for (size_t i = 0; i < CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW; ++i)
+ {
+ cryptonote::block blk;
+ CHECK_AND_ASSERT_MES(generator.construct_block_manually(blk, blk_last, miner_accounts[0],
+ test_generator::bf_major_ver | test_generator::bf_minor_ver | test_generator::bf_timestamp | test_generator::bf_hf_version | test_generator::bf_max_outs,
+ 4, 4, blk_last.timestamp + DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN * 2, // v2 has blocks twice as long
+ crypto::hash(), 0, transaction(), std::vector<crypto::hash>(), 0, 1, 4),
+ false, "Failed to generate block");
+ events.push_back(blk);
+ blk_last = blk;
+ }
+ blk_r = blk_last;
+ }
+
+ cryptonote::keypair in_ephemeral;
+ crypto::public_key tx_pub_key[n_coinbases];
+ crypto::public_key output_pub_key[n_coinbases];
+ for (size_t n = 0; n < n_coinbases; ++n)
+ {
+ tx_pub_key[n] = get_tx_pub_key_from_extra(blocks[n].miner_tx);
+ MDEBUG("tx_pub_key: " << tx_pub_key);
+ output_pub_key[n] = boost::get<txout_to_key>(blocks[n].miner_tx.vout[0].target).key;
+ MDEBUG("output_pub_key: " << output_pub_key);
+ }
+
+ std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses;
+ subaddresses[miner_account[0].get_keys().m_account_address.m_spend_public_key] = {0,0};
+
+#ifndef NO_MULTISIG
+ // create k/L/R/ki for that output we're going to spend
+ std::vector<std::vector<std::vector<crypto::secret_key>>> account_k(total);
+ std::vector<std::vector<std::vector<crypto::public_key>>> account_L(total);
+ std::vector<std::vector<std::vector<crypto::public_key>>> account_R(total);
+ std::vector<std::vector<std::vector<crypto::key_image>>> account_ki(total);
+ std::vector<crypto::public_key> additional_tx_keys;
+ for (size_t msidx = 0; msidx < total; ++msidx)
+ {
+ CHECK_AND_ASSERT_MES(miner_account[msidx].get_keys().m_account_address.m_spend_public_key == miner_account[0].get_keys().m_account_address.m_spend_public_key,
+ false, "Mismatched spend public keys");
+
+ size_t nlr = threshold < total ? threshold - 1 : 1;
+ account_k[msidx].resize(inputs);
+ account_L[msidx].resize(inputs);
+ account_R[msidx].resize(inputs);
+ account_ki[msidx].resize(inputs);
+ for (size_t tdidx = 0; tdidx < inputs; ++tdidx)
+ {
+ account_L[msidx][tdidx].resize(nlr);
+ account_R[msidx][tdidx].resize(nlr);
+ for (size_t n = 0; n < nlr; ++n)
+ {
+ account_k[msidx][tdidx].push_back(rct::rct2sk(rct::skGen()));
+ cryptonote::generate_multisig_LR(output_pub_key[tdidx], account_k[msidx][tdidx][n], account_L[msidx][tdidx][n], account_R[msidx][tdidx][n]);
+ }
+ size_t numki = miner_account[msidx].get_multisig_keys().size();
+ account_ki[msidx][tdidx].resize(numki);
+ for (size_t kiidx = 0; kiidx < numki; ++kiidx)
+ {
+ r = cryptonote::generate_multisig_key_image(miner_account[msidx].get_keys(), kiidx, output_pub_key[tdidx], account_ki[msidx][tdidx][kiidx]);
+ CHECK_AND_ASSERT_MES(r, false, "Failed to generate multisig export key image");
+ }
+ MDEBUG("Party " << msidx << ":");
+ MDEBUG("spend: sec " << miner_account[msidx].get_keys().m_spend_secret_key << ", pub " << miner_account[msidx].get_keys().m_account_address.m_spend_public_key);
+ MDEBUG("view: sec " << miner_account[msidx].get_keys().m_view_secret_key << ", pub " << miner_account[msidx].get_keys().m_account_address.m_view_public_key);
+ for (const auto &k: miner_account[msidx].get_multisig_keys())
+ MDEBUG("msk: " << k);
+ for (size_t n = 0; n < account_k[msidx][tdidx].size(); ++n)
+ {
+ MDEBUG("k: " << account_k[msidx][tdidx][n]);
+ MDEBUG("L: " << account_L[msidx][tdidx][n]);
+ MDEBUG("R: " << account_R[msidx][tdidx][n]);
+ }
+ for (const auto &ki: account_ki[msidx][tdidx])
+ MDEBUG("ki: " << ki);
+ }
+ }
+#endif
+
+ // create kLRki
+ std::vector<rct::multisig_kLRki> kLRkis;
+ std::unordered_set<crypto::public_key> used_L;
+ for (size_t tdidx = 0; tdidx < inputs; ++tdidx)
+ {
+ kLRkis.push_back(rct::multisig_kLRki());
+ rct::multisig_kLRki &kLRki = kLRkis.back();
+#ifdef NO_MULTISIG
+ kLRki = {rct::zero(), rct::zero(), rct::zero(), rct::zero()};
+#else
+ kLRki.k = rct::sk2rct(account_k[creator][tdidx][0]);
+ kLRki.L = rct::pk2rct(account_L[creator][tdidx][0]);
+ kLRki.R = rct::pk2rct(account_R[creator][tdidx][0]);
+ MDEBUG("Starting with k " << kLRki.k);
+ MDEBUG("Starting with L " << kLRki.L);
+ MDEBUG("Starting with R " << kLRki.R);
+ for (size_t msidx = 0; msidx < total; ++msidx)
+ {
+ if (msidx == creator)
+ continue;
+ if (std::find(signers.begin(), signers.end(), msidx) == signers.end())
+ continue;
+ for (size_t lr = 0; lr < account_L[msidx][tdidx].size(); ++lr)
+ {
+ if (used_L.find(account_L[msidx][tdidx][lr]) == used_L.end())
+ {
+ used_L.insert(account_L[msidx][tdidx][lr]);
+ MDEBUG("Adding L " << account_L[msidx][tdidx][lr] << " (for k " << account_k[msidx][tdidx][lr] << ")");
+ MDEBUG("Adding R " << account_R[msidx][tdidx][lr]);
+ rct::addKeys((rct::key&)kLRki.L, kLRki.L, rct::pk2rct(account_L[msidx][tdidx][lr]));
+ rct::addKeys((rct::key&)kLRki.R, kLRki.R, rct::pk2rct(account_R[msidx][tdidx][lr]));
+ break;
+ }
+ }
+ }
+ std::vector<crypto::key_image> pkis;
+ for (size_t msidx = 0; msidx < total; ++msidx)
+ for (size_t n = 0; n < account_ki[msidx][tdidx].size(); ++n)
+ pkis.push_back(account_ki[msidx][tdidx][n]);
+ r = cryptonote::generate_multisig_composite_key_image(miner_account[0].get_keys(), subaddresses, output_pub_key[tdidx], tx_pub_key[tdidx], additional_tx_keys, 0, pkis, (crypto::key_image&)kLRki.ki);
+ CHECK_AND_ASSERT_MES(r, false, "Failed to generate composite key image");
+ MDEBUG("composite ki: " << kLRki.ki);
+ MDEBUG("L: " << kLRki.L);
+ MDEBUG("R: " << kLRki.R);
+ for (size_t n = 1; n < total; ++n)
+ {
+ rct::key ki;
+ r = cryptonote::generate_multisig_composite_key_image(miner_account[n].get_keys(), subaddresses, output_pub_key[tdidx], tx_pub_key[tdidx], additional_tx_keys, 0, pkis, (crypto::key_image&)ki);
+ CHECK_AND_ASSERT_MES(r, false, "Failed to generate composite key image");
+ CHECK_AND_ASSERT_MES(kLRki.ki == ki, false, "Composite key images do not match");
+ }
+ }
+#endif
+
+ // create a tx: we have 8 outputs, all from coinbase, so "fake" rct - use 2
+ std::vector<tx_source_entry> sources;
+ for (size_t n = 0; n < inputs; ++n)
+ {
+ sources.resize(sources.size() + 1);
+ tx_source_entry& src = sources.back();
+
+ src.real_output = n;
+ src.amount = blocks[n].miner_tx.vout[0].amount;
+ src.real_out_tx_key = tx_pub_key[n];
+ src.real_output_in_tx_index = 0;
+ src.mask = rct::identity();
+ src.rct = true;
+ src.multisig_kLRki = kLRkis[n];
+
+ for (size_t m = 0; m <= mixin; ++m)
+ {
+ rct::ctkey ctkey;
+ ctkey.dest = rct::pk2rct(boost::get<txout_to_key>(blocks[m].miner_tx.vout[0].target).key);
+ MDEBUG("using " << (m == n ? "real" : "fake") << " input " << ctkey.dest);
+ ctkey.mask = rct::commit(blocks[m].miner_tx.vout[0].amount, rct::identity()); // since those are coinbases, the masks are known
+ src.outputs.push_back(std::make_pair(m, ctkey));
+ }
+ }
+
+ //fill outputs entry
+ tx_destination_entry td;
+ td.addr = miner_account[creator].get_keys().m_account_address;
+ td.amount = amount_paid;
+ std::vector<tx_destination_entry> destinations;
+ destinations.push_back(td);
+
+ if (pre_tx)
+ pre_tx(sources, destinations);
+
+ transaction tx;
+ crypto::secret_key tx_key;
+#ifdef NO_MULTISIG
+ rct::multisig_out *msoutp = NULL;
+#else
+ rct::multisig_out msout;
+ rct::multisig_out *msoutp = &msout;
+#endif
+ std::vector<crypto::secret_key> additional_tx_secret_keys;
+ auto sources_copy = sources;
+ r = construct_tx_and_get_tx_key(miner_account[creator].get_keys(), subaddresses, sources, destinations, boost::none, std::vector<uint8_t>(), tx, 0, tx_key, additional_tx_secret_keys, true, false, msoutp);
+ CHECK_AND_ASSERT_MES(r, false, "failed to construct transaction");
+
+#ifndef NO_MULTISIG
+ // work out the permutation done on sources
+ std::vector<size_t> ins_order;
+ for (size_t n = 0; n < sources.size(); ++n)
+ {
+ for (size_t idx = 0; idx < sources_copy.size(); ++idx)
+ {
+ CHECK_AND_ASSERT_MES((size_t)sources_copy[idx].real_output < sources_copy[idx].outputs.size(),
+ false, "Invalid real_output");
+ if (sources_copy[idx].outputs[sources_copy[idx].real_output].second.dest == sources[n].outputs[sources[n].real_output].second.dest)
+ ins_order.push_back(idx);
+ }
+ }
+ CHECK_AND_ASSERT_MES(ins_order.size() == sources.size(), false, "Failed to work out sources permutation");
+#endif
+
+#ifndef NO_MULTISIG
+ // sign
+ std::unordered_set<crypto::secret_key> used_keys;
+ const std::vector<crypto::secret_key> &msk0 = miner_account[creator].get_multisig_keys();
+ for (const auto &sk: msk0)
+ used_keys.insert(sk);
+ for (size_t signer: signers)
+ {
+ rct::key skey = rct::zero();
+ const std::vector<crypto::secret_key> &msk1 = miner_account[signer].get_multisig_keys();
+ for (size_t n = 0; n < msk1.size(); ++n)
+ {
+ const crypto::secret_key &sk1 = msk1[n];
+ if (used_keys.find(sk1) == used_keys.end())
+ {
+ used_keys.insert(sk1);
+ sc_add(skey.bytes, skey.bytes, rct::sk2rct(sk1).bytes);
+ }
+ }
+ CHECK_AND_ASSERT_MES(!(skey == rct::zero()), false, "failed to find secret multisig key to sign transaction");
+ std::vector<unsigned int> indices;
+ for (const auto &src: sources_copy)
+ indices.push_back(src.real_output);
+ rct::keyV k;
+ for (size_t tdidx = 0; tdidx < inputs; ++tdidx)
+ {
+ k.push_back(rct::zero());
+ for (size_t n = 0; n < account_k[signer][tdidx].size(); ++n)
+ {
+ crypto::public_key L;
+ rct::scalarmultBase((rct::key&)L, rct::sk2rct(account_k[signer][tdidx][n]));
+ if (used_L.find(L) != used_L.end())
+ {
+ sc_add(k.back().bytes, k.back().bytes, rct::sk2rct(account_k[signer][tdidx][n]).bytes);
+ }
+ }
+ CHECK_AND_ASSERT_MES(!(k.back() == rct::zero()), false, "failed to find k to sign transaction");
+ }
+ tools::apply_permutation(ins_order, indices);
+ tools::apply_permutation(ins_order, k);
+
+ MDEBUG("signing with k size " << k.size());
+ MDEBUG("signing with k " << k.back());
+ MDEBUG("signing with sk " << skey);
+ for (const auto &sk: used_keys)
+ MDEBUG(" created with sk " << sk);
+ MDEBUG("signing with c size " << msout.c.size());
+ MDEBUG("signing with c " << msout.c.back());
+ r = rct::signMultisig(tx.rct_signatures, indices, k, msout, skey);
+ CHECK_AND_ASSERT_MES(r, false, "failed to sign transaction");
+ }
+#endif
+
+ // verify this tx is really to the expected address
+ const crypto::public_key tx_pub_key2 = get_tx_pub_key_from_extra(tx, 0);
+ crypto::key_derivation derivation;
+ r = crypto::generate_key_derivation(tx_pub_key2, miner_account[creator].get_keys().m_view_secret_key, derivation);
+ CHECK_AND_ASSERT_MES(r, false, "Failed to generate derivation");
+ uint64_t n_outs = 0, amount = 0;
+ std::vector<crypto::key_derivation> additional_derivations;
+ for (size_t n = 0; n < tx.vout.size(); ++n)
+ {
+ CHECK_AND_ASSERT_MES(typeid(txout_to_key) == tx.vout[n].target.type(), false, "Unexpected tx out type");
+ if (is_out_to_acc_precomp(subaddresses, boost::get<txout_to_key>(tx.vout[n].target).key, derivation, additional_derivations, n))
+ {
+ ++n_outs;
+ CHECK_AND_ASSERT_MES(tx.vout[n].amount == 0, false, "Destination amount is not zero");
+ rct::key Ctmp;
+ crypto::secret_key scalar1;
+ crypto::derivation_to_scalar(derivation, n, scalar1);
+ rct::ecdhTuple ecdh_info = tx.rct_signatures.ecdhInfo[n];
+ rct::ecdhDecode(ecdh_info, rct::sk2rct(scalar1));
+ rct::key C = tx.rct_signatures.outPk[n].mask;
+ rct::addKeys2(Ctmp, ecdh_info.mask, ecdh_info.amount, rct::H);
+ CHECK_AND_ASSERT_MES(rct::equalKeys(C, Ctmp), false, "Failed to decode amount");
+ amount += rct::h2d(ecdh_info.amount);
+ }
+ }
+ CHECK_AND_ASSERT_MES(n_outs == 1, false, "Not exactly 1 output was received");
+ CHECK_AND_ASSERT_MES(amount == amount_paid, false, "Amount paid was not the expected amount");
+
+ if (post_tx)
+ post_tx(tx);
+
+ if (!valid)
+ DO_CALLBACK(events, "mark_invalid_tx");
+ events.push_back(tx);
+ LOG_PRINT_L0("Test tx: " << obj_to_json_str(tx));
+
+ return true;
+}
+
+bool gen_multisig_tx_valid_22_1_2::generate(std::vector<test_event_entry>& events) const
+{
+ const size_t mixin = 4;
+ const uint64_t amount_paid = 10000;
+ return generate_with(events, 2, mixin, amount_paid, true, 2, 2, 1, {2}, NULL, NULL);
+}
+
+bool gen_multisig_tx_valid_22_1_2_many_inputs::generate(std::vector<test_event_entry>& events) const
+{
+ const size_t mixin = 4;
+ const uint64_t amount_paid = 10000;
+ return generate_with(events, 4, mixin, amount_paid, true, 2, 2, 1, {2}, NULL, NULL);
+}
+
+bool gen_multisig_tx_valid_22_2_1::generate(std::vector<test_event_entry>& events) const
+{
+ const size_t mixin = 4;
+ const uint64_t amount_paid = 10000;
+ return generate_with(events, 2, mixin, amount_paid, true, 2, 2, 2, {1}, NULL, NULL);
+}
+
+bool gen_multisig_tx_valid_33_1_23::generate(std::vector<test_event_entry>& events) const
+{
+ const size_t mixin = 4;
+ const uint64_t amount_paid = 10000;
+ return generate_with(events, 2, mixin, amount_paid, true, 3, 3, 1, {2, 3}, NULL, NULL);
+}
+
+bool gen_multisig_tx_valid_33_3_21::generate(std::vector<test_event_entry>& events) const
+{
+ const size_t mixin = 4;
+ const uint64_t amount_paid = 10000;
+ return generate_with(events, 2, mixin, amount_paid, true, 3, 3, 3, {2, 1}, NULL, NULL);
+}
+
+bool gen_multisig_tx_valid_23_1_2::generate(std::vector<test_event_entry>& events) const
+{
+ const size_t mixin = 4;
+ const uint64_t amount_paid = 10000;
+ return generate_with(events, 2, mixin, amount_paid, true, 2, 3, 1, {2}, NULL, NULL);
+}
+
+bool gen_multisig_tx_valid_23_1_3::generate(std::vector<test_event_entry>& events) const
+{
+ const size_t mixin = 4;
+ const uint64_t amount_paid = 10000;
+ return generate_with(events, 2, mixin, amount_paid, true, 2, 3, 1, {3}, NULL, NULL);
+}
+
+bool gen_multisig_tx_valid_23_2_1::generate(std::vector<test_event_entry>& events) const
+{
+ const size_t mixin = 4;
+ const uint64_t amount_paid = 10000;
+ return generate_with(events, 2, mixin, amount_paid, true, 2, 3, 2, {1}, NULL, NULL);
+}
+
+bool gen_multisig_tx_valid_23_2_3::generate(std::vector<test_event_entry>& events) const
+{
+ const size_t mixin = 4;
+ const uint64_t amount_paid = 10000;
+ return generate_with(events, 2, mixin, amount_paid, true, 2, 3, 2, {3}, NULL, NULL);
+}
+
+bool gen_multisig_tx_valid_45_1_234::generate(std::vector<test_event_entry>& events) const
+{
+ const size_t mixin = 4;
+ const uint64_t amount_paid = 10000;
+ return generate_with(events, 2, mixin, amount_paid, true, 4, 5, 1, {2, 3, 4}, NULL, NULL);
+}
+
+bool gen_multisig_tx_valid_45_4_135_many_inputs::generate(std::vector<test_event_entry>& events) const
+{
+ const size_t mixin = 4;
+ const uint64_t amount_paid = 10000;
+ return generate_with(events, 4, mixin, amount_paid, true, 4, 5, 4, {1, 3, 5}, NULL, NULL);
+}
+
+bool gen_multisig_tx_valid_89_3_1245789::generate(std::vector<test_event_entry>& events) const
+{
+ const size_t mixin = 4;
+ const uint64_t amount_paid = 10000;
+ return generate_with(events, 2, mixin, amount_paid, true, 8, 9, 3, {1, 2, 4, 5, 7, 8, 9}, NULL, NULL);
+}
+
+bool gen_multisig_tx_invalid_22_1__no_threshold::generate(std::vector<test_event_entry>& events) const
+{
+ const size_t mixin = 4;
+ const uint64_t amount_paid = 10000;
+ return generate_with(events, 2, mixin, amount_paid, false, 2, 2, 1, {}, NULL, NULL);
+}
+
+bool gen_multisig_tx_invalid_33_1__no_threshold::generate(std::vector<test_event_entry>& events) const
+{
+ const size_t mixin = 4;
+ const uint64_t amount_paid = 10000;
+ return generate_with(events, 2, mixin, amount_paid, false, 3, 3, 1, {}, NULL, NULL);
+}
+
+bool gen_multisig_tx_invalid_33_1_2_no_threshold::generate(std::vector<test_event_entry>& events) const
+{
+ const size_t mixin = 4;
+ const uint64_t amount_paid = 10000;
+ return generate_with(events, 2, mixin, amount_paid, false, 3, 3, 1, {2}, NULL, NULL);
+}
+
+bool gen_multisig_tx_invalid_33_1_3_no_threshold::generate(std::vector<test_event_entry>& events) const
+{
+ const size_t mixin = 4;
+ const uint64_t amount_paid = 10000;
+ return generate_with(events, 2, mixin, amount_paid, false, 3, 3, 1, {3}, NULL, NULL);
+}
+
+bool gen_multisig_tx_invalid_23_1__no_threshold::generate(std::vector<test_event_entry>& events) const
+{
+ const size_t mixin = 4;
+ const uint64_t amount_paid = 10000;
+ return generate_with(events, 2, mixin, amount_paid, false, 2, 3, 1, {}, NULL, NULL);
+}
+
+bool gen_multisig_tx_invalid_45_5_23_no_threshold::generate(std::vector<test_event_entry>& events) const
+{
+ const size_t mixin = 4;
+ const uint64_t amount_paid = 10000;
+ return generate_with(events, 2, mixin, amount_paid, false, 4, 5, 5, {2, 3}, NULL, NULL);
+}
diff --git a/tests/core_tests/multisig.h b/tests/core_tests/multisig.h
new file mode 100644
index 000000000..62a1c6a35
--- /dev/null
+++ b/tests/core_tests/multisig.h
@@ -0,0 +1,199 @@
+// Copyright (c) 2017, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
+
+#pragma once
+#include "chaingen.h"
+
+struct gen_multisig_tx_validation_base : public test_chain_unit_base
+{
+ gen_multisig_tx_validation_base()
+ : m_invalid_tx_index(0)
+ , m_invalid_block_index(0)
+ {
+ REGISTER_CALLBACK_METHOD(gen_multisig_tx_validation_base, mark_invalid_tx);
+ REGISTER_CALLBACK_METHOD(gen_multisig_tx_validation_base, mark_invalid_block);
+ }
+
+ bool check_tx_verification_context(const cryptonote::tx_verification_context& tvc, bool tx_added, size_t event_idx, const cryptonote::transaction& /*tx*/)
+ {
+ if (m_invalid_tx_index == event_idx)
+ return tvc.m_verifivation_failed;
+ else
+ return !tvc.m_verifivation_failed && tx_added;
+ }
+
+ bool check_block_verification_context(const cryptonote::block_verification_context& bvc, size_t event_idx, const cryptonote::block& /*block*/)
+ {
+ if (m_invalid_block_index == event_idx)
+ return bvc.m_verifivation_failed;
+ else
+ return !bvc.m_verifivation_failed;
+ }
+
+ bool mark_invalid_block(cryptonote::core& /*c*/, size_t ev_index, const std::vector<test_event_entry>& /*events*/)
+ {
+ m_invalid_block_index = ev_index + 1;
+ return true;
+ }
+
+ bool mark_invalid_tx(cryptonote::core& /*c*/, size_t ev_index, const std::vector<test_event_entry>& /*events*/)
+ {
+ m_invalid_tx_index = ev_index + 1;
+ return true;
+ }
+
+ bool generate_with(std::vector<test_event_entry>& events, size_t inputs, size_t mixin,
+ uint64_t amount_paid, bool valid,
+ size_t threshold, size_t total, size_t creator, std::vector<size_t> signers,
+ const std::function<void(std::vector<cryptonote::tx_source_entry> &sources, std::vector<cryptonote::tx_destination_entry> &destinations)> &pre_tx,
+ const std::function<void(cryptonote::transaction &tx)> &post_tx) const;
+
+private:
+ size_t m_invalid_tx_index;
+ size_t m_invalid_block_index;
+};
+
+template<>
+struct get_test_options<gen_multisig_tx_validation_base> {
+ const std::pair<uint8_t, uint64_t> hard_forks[3] = {std::make_pair(1, 0), std::make_pair(4, 1), std::make_pair(0, 0)};
+ const cryptonote::test_options test_options = {
+ hard_forks
+ };
+};
+
+// valid
+struct gen_multisig_tx_valid_22_1_2: public gen_multisig_tx_validation_base
+{
+ bool generate(std::vector<test_event_entry>& events) const;
+};
+template<> struct get_test_options<gen_multisig_tx_valid_22_1_2>: public get_test_options<gen_multisig_tx_validation_base> {};
+
+struct gen_multisig_tx_valid_22_1_2_many_inputs: public gen_multisig_tx_validation_base
+{
+ bool generate(std::vector<test_event_entry>& events) const;
+};
+template<> struct get_test_options<gen_multisig_tx_valid_22_1_2_many_inputs>: public get_test_options<gen_multisig_tx_validation_base> {};
+
+struct gen_multisig_tx_valid_22_2_1: public gen_multisig_tx_validation_base
+{
+ bool generate(std::vector<test_event_entry>& events) const;
+};
+template<> struct get_test_options<gen_multisig_tx_valid_22_2_1>: public get_test_options<gen_multisig_tx_validation_base> {};
+
+struct gen_multisig_tx_valid_33_1_23: public gen_multisig_tx_validation_base
+{
+ bool generate(std::vector<test_event_entry>& events) const;
+};
+template<> struct get_test_options<gen_multisig_tx_valid_33_1_23>: public get_test_options<gen_multisig_tx_validation_base> {};
+
+struct gen_multisig_tx_valid_33_3_21: public gen_multisig_tx_validation_base
+{
+ bool generate(std::vector<test_event_entry>& events) const;
+};
+template<> struct get_test_options<gen_multisig_tx_valid_33_3_21>: public get_test_options<gen_multisig_tx_validation_base> {};
+
+struct gen_multisig_tx_valid_23_1_2: public gen_multisig_tx_validation_base
+{
+ bool generate(std::vector<test_event_entry>& events) const;
+};
+template<> struct get_test_options<gen_multisig_tx_valid_23_1_2>: public get_test_options<gen_multisig_tx_validation_base> {};
+
+struct gen_multisig_tx_valid_23_1_3: public gen_multisig_tx_validation_base
+{
+ bool generate(std::vector<test_event_entry>& events) const;
+};
+template<> struct get_test_options<gen_multisig_tx_valid_23_1_3>: public get_test_options<gen_multisig_tx_validation_base> {};
+
+struct gen_multisig_tx_valid_23_2_1: public gen_multisig_tx_validation_base
+{
+ bool generate(std::vector<test_event_entry>& events) const;
+};
+template<> struct get_test_options<gen_multisig_tx_valid_23_2_1>: public get_test_options<gen_multisig_tx_validation_base> {};
+
+struct gen_multisig_tx_valid_23_2_3: public gen_multisig_tx_validation_base
+{
+ bool generate(std::vector<test_event_entry>& events) const;
+};
+template<> struct get_test_options<gen_multisig_tx_valid_23_2_3>: public get_test_options<gen_multisig_tx_validation_base> {};
+
+struct gen_multisig_tx_valid_45_1_234: public gen_multisig_tx_validation_base
+{
+ bool generate(std::vector<test_event_entry>& events) const;
+};
+template<> struct get_test_options<gen_multisig_tx_valid_45_1_234>: public get_test_options<gen_multisig_tx_validation_base> {};
+
+struct gen_multisig_tx_valid_45_4_135_many_inputs: public gen_multisig_tx_validation_base
+{
+ bool generate(std::vector<test_event_entry>& events) const;
+};
+template<> struct get_test_options<gen_multisig_tx_valid_45_4_135_many_inputs>: public get_test_options<gen_multisig_tx_validation_base> {};
+
+struct gen_multisig_tx_valid_89_3_1245789: public gen_multisig_tx_validation_base
+{
+ bool generate(std::vector<test_event_entry>& events) const;
+};
+template<> struct get_test_options<gen_multisig_tx_valid_89_3_1245789>: public get_test_options<gen_multisig_tx_validation_base> {};
+
+// invalid
+struct gen_multisig_tx_invalid_22_1__no_threshold: public gen_multisig_tx_validation_base
+{
+ bool generate(std::vector<test_event_entry>& events) const;
+};
+template<> struct get_test_options<gen_multisig_tx_invalid_22_1__no_threshold>: public get_test_options<gen_multisig_tx_validation_base> {};
+
+struct gen_multisig_tx_invalid_33_1__no_threshold: public gen_multisig_tx_validation_base
+{
+ bool generate(std::vector<test_event_entry>& events) const;
+};
+template<> struct get_test_options<gen_multisig_tx_invalid_33_1__no_threshold>: public get_test_options<gen_multisig_tx_validation_base> {};
+
+struct gen_multisig_tx_invalid_33_1_2_no_threshold: public gen_multisig_tx_validation_base
+{
+ bool generate(std::vector<test_event_entry>& events) const;
+};
+template<> struct get_test_options<gen_multisig_tx_invalid_33_1_2_no_threshold>: public get_test_options<gen_multisig_tx_validation_base> {};
+
+struct gen_multisig_tx_invalid_33_1_3_no_threshold: public gen_multisig_tx_validation_base
+{
+ bool generate(std::vector<test_event_entry>& events) const;
+};
+template<> struct get_test_options<gen_multisig_tx_invalid_33_1_3_no_threshold>: public get_test_options<gen_multisig_tx_validation_base> {};
+
+struct gen_multisig_tx_invalid_23_1__no_threshold: public gen_multisig_tx_validation_base
+{
+ bool generate(std::vector<test_event_entry>& events) const;
+};
+template<> struct get_test_options<gen_multisig_tx_invalid_23_1__no_threshold>: public get_test_options<gen_multisig_tx_validation_base> {};
+
+struct gen_multisig_tx_invalid_45_5_23_no_threshold: public gen_multisig_tx_validation_base
+{
+ bool generate(std::vector<test_event_entry>& events) const;
+};
+template<> struct get_test_options<gen_multisig_tx_invalid_45_5_23_no_threshold>: public get_test_options<gen_multisig_tx_validation_base> {};
diff --git a/tests/crypto/CMakeLists.txt b/tests/crypto/CMakeLists.txt
index 573c62ad4..f4abb3a9a 100644
--- a/tests/crypto/CMakeLists.txt
+++ b/tests/crypto/CMakeLists.txt
@@ -42,6 +42,7 @@ add_executable(cncrypto-tests
${crypto_headers})
target_link_libraries(cncrypto-tests
PRIVATE
+ common
${Boost_SYSTEM_LIBRARY}
${EXTRA_LIBRARIES})
set_property(TARGET cncrypto-tests
diff --git a/tests/data/fuzz/base58/ENC1 b/tests/data/fuzz/base58/ENC1
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/data/fuzz/base58/ENC1
diff --git a/tests/data/fuzz/base58/ENC2 b/tests/data/fuzz/base58/ENC2
new file mode 100644
index 000000000..73da627e4
--- /dev/null
+++ b/tests/data/fuzz/base58/ENC2
@@ -0,0 +1 @@
+9zZBkWRgMNPEnVofRFqWK9MKBwgXNyKELBJSttxb1t2UhDM114URntt5iYcXzXusoHZygfSojsbviXZhnP9pJ4p2SDcv81L \ No newline at end of file
diff --git a/tests/data/fuzz/http-client/RESP1 b/tests/data/fuzz/http-client/RESP1
new file mode 100644
index 000000000..3046dc886
--- /dev/null
+++ b/tests/data/fuzz/http-client/RESP1
@@ -0,0 +1,8 @@
+HTTP/1.1 200 Ok
+Server: Epee-based
+Content-Length: 5
+Content-Type: text/plain
+Last-Modified: Mon, 11 Dec 2017 09:03:03 GMT
+Accept-Ranges: bytes
+
+foo
diff --git a/tests/data/fuzz/levin/LEVIN1 b/tests/data/fuzz/levin/LEVIN1
new file mode 100644
index 000000000..51a640c61
--- /dev/null
+++ b/tests/data/fuzz/levin/LEVIN1
Binary files differ
diff --git a/tests/data/fuzz/load-from-binary/BINARY1 b/tests/data/fuzz/load-from-binary/BINARY1
new file mode 100644
index 000000000..c99d7e7bc
--- /dev/null
+++ b/tests/data/fuzz/load-from-binary/BINARY1
Binary files differ
diff --git a/tests/data/fuzz/load-from-json/JSON1 b/tests/data/fuzz/load-from-json/JSON1
new file mode 100644
index 000000000..9e26dfeeb
--- /dev/null
+++ b/tests/data/fuzz/load-from-json/JSON1
@@ -0,0 +1 @@
+{} \ No newline at end of file
diff --git a/tests/data/fuzz/parse-url/URL1 b/tests/data/fuzz/parse-url/URL1
new file mode 100644
index 000000000..e56ea71e3
--- /dev/null
+++ b/tests/data/fuzz/parse-url/URL1
@@ -0,0 +1 @@
+127.0.0.1 \ No newline at end of file
diff --git a/tests/data/fuzz/parse-url/URL2 b/tests/data/fuzz/parse-url/URL2
new file mode 100644
index 000000000..b66e7de9a
--- /dev/null
+++ b/tests/data/fuzz/parse-url/URL2
@@ -0,0 +1 @@
+iframe_test.html?api_url=http://api.vk.com/api.php&api_id=3289090&api_settings=1&viewer_id=562964060&viewer_type=0&sid=0aad8d1c5713130f9ca0076f2b7b47e532877424961367d81e7fa92455f069be7e21bc3193cbd0be11895&secret=368ebbc0ef&access_token=668bc03f43981d883f73876ffff4aa8564254b359cc745dfa1b3cde7bdab2e94105d8f6d8250717569c0a7&user_id=0&group_id=0&is_app_user=1&auth_key=d2f7a895ca5ff3fdb2a2a8ae23fe679a&language=0&parent_language=0&ad_info=ElsdCQBaQlxiAQRdFUVUXiN2AVBzBx5pU1BXIgZUJlIEAWcgAUoLQg==&referrer=unknown&lc_name=9834b6a3&hash= \ No newline at end of file
diff --git a/tests/functional_tests/main.cpp b/tests/functional_tests/main.cpp
index 35a0bb9bd..9fd24cc06 100644
--- a/tests/functional_tests/main.cpp
+++ b/tests/functional_tests/main.cpp
@@ -31,6 +31,7 @@
#include <boost/program_options.hpp>
#include "include_base_utils.h"
+#include "string_tools.h"
using namespace epee;
#include "common/command_line.h"
diff --git a/tests/fuzz/CMakeLists.txt b/tests/fuzz/CMakeLists.txt
index 853d46a12..5d58f9a3c 100644
--- a/tests/fuzz/CMakeLists.txt
+++ b/tests/fuzz/CMakeLists.txt
@@ -89,3 +89,80 @@ set_property(TARGET cold-transaction_fuzz_tests
PROPERTY
FOLDER "tests")
+add_executable(load-from-binary_fuzz_tests load_from_binary.cpp fuzzer.cpp)
+target_link_libraries(load-from-binary_fuzz_tests
+ PRIVATE
+ common
+ epee
+ ${Boost_PROGRAM_OPTIONS_LIBRARY}
+ ${CMAKE_THREAD_LIBS_INIT}
+ ${EXTRA_LIBRARIES})
+set_property(TARGET load-from-binary_fuzz_tests
+ PROPERTY
+ FOLDER "tests")
+
+add_executable(load-from-json_fuzz_tests load_from_json.cpp fuzzer.cpp)
+target_link_libraries(load-from-json_fuzz_tests
+ PRIVATE
+ common
+ epee
+ ${Boost_PROGRAM_OPTIONS_LIBRARY}
+ ${CMAKE_THREAD_LIBS_INIT}
+ ${EXTRA_LIBRARIES})
+set_property(TARGET load-from-json_fuzz_tests
+ PROPERTY
+ FOLDER "tests")
+
+add_executable(base58_fuzz_tests base58.cpp fuzzer.cpp)
+target_link_libraries(base58_fuzz_tests
+ PRIVATE
+ common
+ epee
+ ${Boost_PROGRAM_OPTIONS_LIBRARY}
+ ${CMAKE_THREAD_LIBS_INIT}
+ ${EXTRA_LIBRARIES})
+set_property(TARGET base58_fuzz_tests
+ PROPERTY
+ FOLDER "tests")
+
+add_executable(parse-url_fuzz_tests parse_url.cpp fuzzer.cpp)
+target_link_libraries(parse-url_fuzz_tests
+ PRIVATE
+ epee
+ ${Boost_REGEX_LIBRARY}
+ ${Boost_PROGRAM_OPTIONS_LIBRARY}
+ ${Boost_SYSTEM_LIBRARY}
+ ${CMAKE_THREAD_LIBS_INIT}
+ ${EXTRA_LIBRARIES})
+set_property(TARGET parse-url_fuzz_tests
+ PROPERTY
+ FOLDER "tests")
+
+add_executable(http-client_fuzz_tests http-client.cpp fuzzer.cpp)
+target_link_libraries(http-client_fuzz_tests
+ PRIVATE
+ epee
+ ${Boost_THREAD_LIBRARY}
+ ${Boost_REGEX_LIBRARY}
+ ${Boost_PROGRAM_OPTIONS_LIBRARY}
+ ${Boost_SYSTEM_LIBRARY}
+ ${CMAKE_THREAD_LIBS_INIT}
+ ${EXTRA_LIBRARIES})
+set_property(TARGET http-client_fuzz_tests
+ PROPERTY
+ FOLDER "tests")
+
+add_executable(levin_fuzz_tests levin.cpp fuzzer.cpp)
+target_link_libraries(levin_fuzz_tests
+ PRIVATE
+ common
+ epee
+ ${Boost_THREAD_LIBRARY}
+ ${Boost_REGEX_LIBRARY}
+ ${Boost_PROGRAM_OPTIONS_LIBRARY}
+ ${CMAKE_THREAD_LIBS_INIT}
+ ${EXTRA_LIBRARIES})
+set_property(TARGET levin_fuzz_tests
+ PROPERTY
+ FOLDER "tests")
+
diff --git a/tests/fuzz/base58.cpp b/tests/fuzz/base58.cpp
new file mode 100644
index 000000000..aea62f721
--- /dev/null
+++ b/tests/fuzz/base58.cpp
@@ -0,0 +1,74 @@
+// Copyright (c) 2017, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "include_base_utils.h"
+#include "file_io_utils.h"
+#include "common/base58.h"
+#include "fuzzer.h"
+
+class Base58Fuzzer: public Fuzzer
+{
+public:
+ Base58Fuzzer() {}
+ virtual int init();
+ virtual int run(const std::string &filename);
+};
+
+int Base58Fuzzer::init()
+{
+ return 0;
+}
+
+int Base58Fuzzer::run(const std::string &filename)
+{
+ std::string s;
+
+ if (!epee::file_io_utils::load_file_to_string(filename, s))
+ {
+ std::cout << "Error: failed to load file " << filename << std::endl;
+ return 1;
+ }
+ try
+ {
+ std::string data;
+ tools::base58::decode(s, data);
+ }
+ catch (const std::exception &e)
+ {
+ std::cerr << "Failed to load from binary: " << e.what() << std::endl;
+ return 1;
+ }
+ return 0;
+}
+
+int main(int argc, const char **argv)
+{
+ Base58Fuzzer fuzzer;
+ return run_fuzzer(argc, argv, fuzzer);
+}
+
diff --git a/tests/fuzz/block.cpp b/tests/fuzz/block.cpp
index 03751fc14..ce8785cc3 100644
--- a/tests/fuzz/block.cpp
+++ b/tests/fuzz/block.cpp
@@ -28,7 +28,7 @@
#include "include_base_utils.h"
#include "file_io_utils.h"
-#include "cryptonote_protocol/blobdatatype.h"
+#include "cryptonote_basic/blobdatatype.h"
#include "cryptonote_basic/cryptonote_basic.h"
#include "cryptonote_basic/cryptonote_format_utils.h"
#include "fuzzer.h"
diff --git a/tests/fuzz/cold-outputs.cpp b/tests/fuzz/cold-outputs.cpp
index e585b4b13..2785db05d 100644
--- a/tests/fuzz/cold-outputs.cpp
+++ b/tests/fuzz/cold-outputs.cpp
@@ -28,7 +28,7 @@
#include "include_base_utils.h"
#include "file_io_utils.h"
-#include "cryptonote_protocol/blobdatatype.h"
+#include "cryptonote_basic/blobdatatype.h"
#include "cryptonote_basic/cryptonote_basic.h"
#include "cryptonote_basic/cryptonote_format_utils.h"
#include "wallet/wallet2.h"
diff --git a/tests/fuzz/cold-transaction.cpp b/tests/fuzz/cold-transaction.cpp
index 25a80fc68..f0b4b26d6 100644
--- a/tests/fuzz/cold-transaction.cpp
+++ b/tests/fuzz/cold-transaction.cpp
@@ -28,7 +28,7 @@
#include "include_base_utils.h"
#include "file_io_utils.h"
-#include "cryptonote_protocol/blobdatatype.h"
+#include "cryptonote_basic/blobdatatype.h"
#include "cryptonote_basic/cryptonote_basic.h"
#include "cryptonote_basic/cryptonote_format_utils.h"
#include "wallet/wallet2.h"
diff --git a/tests/fuzz/fuzzer.cpp b/tests/fuzz/fuzzer.cpp
index 756a8c847..686a5e5f0 100644
--- a/tests/fuzz/fuzzer.cpp
+++ b/tests/fuzz/fuzzer.cpp
@@ -28,6 +28,7 @@
#include <boost/program_options.hpp>
#include "include_base_utils.h"
+#include "string_tools.h"
#include "common/command_line.h"
#include "common/util.h"
#include "fuzzer.h"
@@ -43,41 +44,11 @@ static int __AFL_LOOP(int)
}
#endif
-using namespace epee;
-using namespace boost::program_options;
-
int run_fuzzer(int argc, const char **argv, Fuzzer &fuzzer)
{
- TRY_ENTRY();
- tools::on_startup();
- string_tools::set_module_name_and_folder(argv[0]);
-
- //set up logging options
- mlog_configure(mlog_get_default_log_path("fuzztests.log"), true);
- mlog_set_log("*:FATAL,logging:none");
-
- options_description desc_options("Allowed options");
- command_line::add_arg(desc_options, command_line::arg_help);
-
- variables_map vm;
- bool r = command_line::handle_error_helper(desc_options, [&]()
- {
- store(parse_command_line(argc, argv, desc_options), vm);
- notify(vm);
- return true;
- });
- if (!r)
- return 1;
-
- if (command_line::get_arg(vm, command_line::arg_help))
- {
- std::cout << desc_options << std::endl;
- return 0;
- }
-
if (argc < 2)
{
- std::cout << desc_options << std::endl;
+ std::cout << "usage: " << argv[0] << " " << "<filename>" << std::endl;
return 1;
}
@@ -93,6 +64,5 @@ int run_fuzzer(int argc, const char **argv, Fuzzer &fuzzer)
return ret;
}
- CATCH_ENTRY_L0("fuzzer_main", 1);
return 0;
}
diff --git a/tests/fuzz/http-client.cpp b/tests/fuzz/http-client.cpp
new file mode 100644
index 000000000..21560df21
--- /dev/null
+++ b/tests/fuzz/http-client.cpp
@@ -0,0 +1,98 @@
+// Copyright (c) 2017, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "include_base_utils.h"
+#include "file_io_utils.h"
+#include "net/http_client.h"
+#include "fuzzer.h"
+
+class dummy_client
+{
+public:
+ bool connect(const std::string& addr, int port, std::chrono::milliseconds timeout, bool ssl = false, const std::string& bind_ip = "0.0.0.0") { return true; }
+ bool connect(const std::string& addr, const std::string& port, std::chrono::milliseconds timeout, bool ssl = false, const std::string& bind_ip = "0.0.0.0") { return true; }
+ bool disconnect() { return true; }
+ bool send(const std::string& buff, std::chrono::milliseconds timeout) { return true; }
+ bool send(const void* data, size_t sz) { return true; }
+ bool is_connected() { return true; }
+ bool recv(std::string& buff, std::chrono::milliseconds timeout)
+ {
+ buff = data;
+ data.clear();
+ return true;
+ }
+
+ void set_test_data(const std::string &s) { data = s; }
+
+private:
+ std::string data;
+};
+
+class HTTPClientFuzzer: public Fuzzer
+{
+public:
+ HTTPClientFuzzer() {}
+ virtual int init();
+ virtual int run(const std::string &filename);
+
+private:
+ epee::net_utils::http::http_simple_client_template<dummy_client> client;
+};
+
+int HTTPClientFuzzer::init()
+{
+ return 0;
+}
+
+int HTTPClientFuzzer::run(const std::string &filename)
+{
+ std::string s;
+
+ if (!epee::file_io_utils::load_file_to_string(filename, s))
+ {
+ std::cout << "Error: failed to load file " << filename << std::endl;
+ return 1;
+ }
+ try
+ {
+ client.test(s, std::chrono::milliseconds(1000));
+ }
+ catch (const std::exception &e)
+ {
+ std::cerr << "Failed to test http client: " << e.what() << std::endl;
+ return 1;
+ }
+ return 0;
+}
+
+int main(int argc, const char **argv)
+{
+ HTTPClientFuzzer fuzzer;
+ return run_fuzzer(argc, argv, fuzzer);
+}
+
diff --git a/tests/fuzz/levin.cpp b/tests/fuzz/levin.cpp
new file mode 100644
index 000000000..2fd60ae50
--- /dev/null
+++ b/tests/fuzz/levin.cpp
@@ -0,0 +1,345 @@
+// Copyright (c) 2017, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "include_base_utils.h"
+#include "file_io_utils.h"
+#include "net/net_utils_base.h"
+#include "net/abstract_tcp_server2.h"
+#include "storages/levin_abstract_invoke2.h"
+#include "net/levin_protocol_handler_async.h"
+#include "fuzzer.h"
+
+namespace
+{
+ class call_counter
+ {
+ public:
+ call_counter() : m_counter(0) { }
+
+ // memory_order_relaxed is enough for call counter
+ void inc() volatile { m_counter.fetch_add(1, std::memory_order_relaxed); }
+ size_t get() volatile const { return m_counter.load(std::memory_order_relaxed); }
+ void reset() volatile { m_counter.store(0, std::memory_order_relaxed); }
+
+ private:
+ std::atomic<size_t> m_counter;
+ };
+
+ struct test_levin_connection_context : public epee::net_utils::connection_context_base
+ {
+ };
+
+ typedef epee::levin::async_protocol_handler_config<test_levin_connection_context> test_levin_protocol_handler_config;
+ typedef epee::levin::async_protocol_handler<test_levin_connection_context> test_levin_protocol_handler;
+
+ struct test_levin_commands_handler : public epee::levin::levin_commands_handler<test_levin_connection_context>
+ {
+ test_levin_commands_handler()
+ : m_return_code(LEVIN_OK)
+ , m_last_command(-1)
+ {
+ }
+
+ virtual int invoke(int command, const std::string& in_buff, std::string& buff_out, test_levin_connection_context& context)
+ {
+ m_invoke_counter.inc();
+ boost::unique_lock<boost::mutex> lock(m_mutex);
+ m_last_command = command;
+ m_last_in_buf = in_buff;
+ buff_out = m_invoke_out_buf;
+ return m_return_code;
+ }
+
+ virtual int notify(int command, const std::string& in_buff, test_levin_connection_context& context)
+ {
+ m_notify_counter.inc();
+ boost::unique_lock<boost::mutex> lock(m_mutex);
+ m_last_command = command;
+ m_last_in_buf = in_buff;
+ return m_return_code;
+ }
+
+ virtual void callback(test_levin_connection_context& context)
+ {
+ m_callback_counter.inc();
+ //std::cout << "test_levin_commands_handler::callback()" << std::endl;
+ }
+
+ virtual void on_connection_new(test_levin_connection_context& context)
+ {
+ m_new_connection_counter.inc();
+ //std::cout << "test_levin_commands_handler::on_connection_new()" << std::endl;
+ }
+
+ virtual void on_connection_close(test_levin_connection_context& context)
+ {
+ m_close_connection_counter.inc();
+ //std::cout << "test_levin_commands_handler::on_connection_close()" << std::endl;
+ }
+
+ size_t invoke_counter() const { return m_invoke_counter.get(); }
+ size_t notify_counter() const { return m_notify_counter.get(); }
+ size_t callback_counter() const { return m_callback_counter.get(); }
+ size_t new_connection_counter() const { return m_new_connection_counter.get(); }
+ size_t close_connection_counter() const { return m_close_connection_counter.get(); }
+
+ int return_code() const { return m_return_code; }
+ void return_code(int v) { m_return_code = v; }
+
+ const std::string& invoke_out_buf() const { return m_invoke_out_buf; }
+ void invoke_out_buf(const std::string& v) { m_invoke_out_buf = v; }
+
+ int last_command() const { return m_last_command; }
+ const std::string& last_in_buf() const { return m_last_in_buf; }
+
+ private:
+ call_counter m_invoke_counter;
+ call_counter m_notify_counter;
+ call_counter m_callback_counter;
+ call_counter m_new_connection_counter;
+ call_counter m_close_connection_counter;
+
+ boost::mutex m_mutex;
+
+ int m_return_code;
+ std::string m_invoke_out_buf;
+
+ int m_last_command;
+ std::string m_last_in_buf;
+ };
+
+ class test_connection : public epee::net_utils::i_service_endpoint
+ {
+ public:
+ test_connection(boost::asio::io_service& io_service, test_levin_protocol_handler_config& protocol_config)
+ : m_io_service(io_service)
+ , m_protocol_handler(this, protocol_config, m_context)
+ , m_send_return(true)
+ {
+ }
+
+ void start()
+ {
+ m_protocol_handler.after_init_connection();
+ }
+
+ // Implement epee::net_utils::i_service_endpoint interface
+ virtual bool do_send(const void* ptr, size_t cb)
+ {
+ m_send_counter.inc();
+ boost::unique_lock<boost::mutex> lock(m_mutex);
+ m_last_send_data.append(reinterpret_cast<const char*>(ptr), cb);
+ return m_send_return;
+ }
+
+ virtual bool close() { return true; }
+ virtual bool call_run_once_service_io() { return true; }
+ virtual bool request_callback() { return true; }
+ virtual boost::asio::io_service& get_io_service() { return m_io_service; }
+ virtual bool add_ref() { return true; }
+ virtual bool release() { return true; }
+
+ size_t send_counter() const { return m_send_counter.get(); }
+
+ const std::string& last_send_data() const { return m_last_send_data; }
+ void reset_last_send_data() { boost::unique_lock<boost::mutex> lock(m_mutex); m_last_send_data.clear(); }
+
+ bool send_return() const { return m_send_return; }
+ void send_return(bool v) { m_send_return = v; }
+
+ public:
+ test_levin_connection_context m_context;
+ test_levin_protocol_handler m_protocol_handler;
+
+ private:
+ boost::asio::io_service& m_io_service;
+
+ call_counter m_send_counter;
+ boost::mutex m_mutex;
+
+ std::string m_last_send_data;
+
+ bool m_send_return;
+ };
+
+#if 0
+ class async_protocol_handler_test : public ::testing::Test
+ {
+ public:
+ const static uint64_t invoke_timeout = 5 * 1000;
+ const static size_t max_packet_size = 10 * 1024 * 1024;
+
+ typedef std::unique_ptr<test_connection> test_connection_ptr;
+
+ async_protocol_handler_test():
+ m_pcommands_handler(new test_levin_commands_handler()),
+ m_commands_handler(*m_pcommands_handler)
+ {
+ m_handler_config.set_handler(m_pcommands_handler, [](epee::levin::levin_commands_handler<test_levin_connection_context> *handler) { delete handler; });
+ m_handler_config.m_invoke_timeout = invoke_timeout;
+ m_handler_config.m_max_packet_size = max_packet_size;
+ }
+
+ virtual void SetUp()
+ {
+ }
+
+ protected:
+ test_connection_ptr create_connection(bool start = true)
+ {
+ test_connection_ptr conn(new test_connection(m_io_service, m_handler_config));
+ if (start)
+ {
+ conn->start();
+ }
+ return conn;
+ }
+
+ protected:
+ boost::asio::io_service m_io_service;
+ test_levin_protocol_handler_config m_handler_config;
+ test_levin_commands_handler *m_pcommands_handler, &m_commands_handler;
+ };
+
+ class positive_test_connection_to_levin_protocol_handler_calls : public async_protocol_handler_test
+ {
+ };
+
+ class test_levin_protocol_handler__hanle_recv_with_invalid_data : public async_protocol_handler_test
+ {
+ public:
+ static const int expected_command = 5615871;
+ static const int expected_return_code = 782546;
+
+ test_levin_protocol_handler__hanle_recv_with_invalid_data()
+ : m_expected_invoke_out_buf(512, 'y')
+ {
+ }
+
+ virtual void SetUp()
+ {
+ async_protocol_handler_test::SetUp();
+
+ m_conn = create_connection();
+
+ m_in_data.assign(256, 't');
+
+ m_req_head.m_signature = LEVIN_SIGNATURE;
+ m_req_head.m_cb = m_in_data.size();
+ m_req_head.m_have_to_return_data = true;
+ m_req_head.m_command = expected_command;
+ m_req_head.m_return_code = LEVIN_OK;
+ m_req_head.m_flags = LEVIN_PACKET_REQUEST;
+ m_req_head.m_protocol_version = LEVIN_PROTOCOL_VER_1;
+
+ m_commands_handler.return_code(expected_return_code);
+ m_commands_handler.invoke_out_buf(m_expected_invoke_out_buf);
+ }
+
+ protected:
+ void prepare_buf()
+ {
+ m_buf.assign(reinterpret_cast<const char*>(&m_req_head), sizeof(m_req_head));
+ m_buf += m_in_data;
+ }
+
+ protected:
+ test_connection_ptr m_conn;
+ epee::levin::bucket_head2 m_req_head;
+ std::string m_in_data;
+ std::string m_buf;
+ std::string m_expected_invoke_out_buf;
+ };
+#endif
+}
+
+class LevinFuzzer: public Fuzzer
+{
+public:
+ LevinFuzzer() {} //: handler(endpoint, config, context) {}
+ virtual int init();
+ virtual int run(const std::string &filename);
+
+private:
+ //epee::net_utils::connection_context_base context;
+ //epee::levin::async_protocol_handler<> handler;
+};
+
+int LevinFuzzer::init()
+{
+ return 0;
+}
+
+int LevinFuzzer::run(const std::string &filename)
+{
+ std::string s;
+
+//
+ epee::levin::bucket_head2 req_head;
+ req_head.m_signature = LEVIN_SIGNATURE;
+ req_head.m_cb = 0;
+ req_head.m_have_to_return_data = true;
+ req_head.m_command = 2000;
+ req_head.m_flags = LEVIN_PACKET_REQUEST;
+ req_head.m_protocol_version = LEVIN_PROTOCOL_VER_1;
+ FILE *f=fopen("/tmp/out.levin", "w");
+ fwrite(&req_head,sizeof(req_head),1, f);
+ fclose(f);
+//
+ if (!epee::file_io_utils::load_file_to_string(filename, s))
+ {
+ std::cout << "Error: failed to load file " << filename << std::endl;
+ return 1;
+ }
+ try
+ {
+ //std::unique_ptr<test_connection> conn = new test();
+ boost::asio::io_service io_service;
+ test_levin_protocol_handler_config m_handler_config;
+ test_levin_commands_handler *m_pcommands_handler = new test_levin_commands_handler();
+ m_handler_config.set_handler(m_pcommands_handler, [](epee::levin::levin_commands_handler<test_levin_connection_context> *handler) { delete handler; });
+ std::unique_ptr<test_connection> conn(new test_connection(io_service, m_handler_config));
+ conn->start();
+ //m_commands_handler.invoke_out_buf(expected_out_data);
+ //m_commands_handler.return_code(expected_return_code);
+ conn->m_protocol_handler.handle_recv(s.data(), s.size());
+ }
+ catch (const std::exception &e)
+ {
+ std::cerr << "Failed to test http client: " << e.what() << std::endl;
+ return 1;
+ }
+ return 0;
+}
+
+int main(int argc, const char **argv)
+{
+ LevinFuzzer fuzzer;
+ return run_fuzzer(argc, argv, fuzzer);
+}
+
diff --git a/tests/fuzz/load_from_binary.cpp b/tests/fuzz/load_from_binary.cpp
new file mode 100644
index 000000000..3c8dd177b
--- /dev/null
+++ b/tests/fuzz/load_from_binary.cpp
@@ -0,0 +1,76 @@
+// Copyright (c) 2017, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "include_base_utils.h"
+#include "file_io_utils.h"
+#include "serialization/keyvalue_serialization.h"
+#include "storages/portable_storage_template_helper.h"
+#include "storages/portable_storage_base.h"
+#include "fuzzer.h"
+
+class PortableStorageFuzzer: public Fuzzer
+{
+public:
+ PortableStorageFuzzer() {}
+ virtual int init();
+ virtual int run(const std::string &filename);
+};
+
+int PortableStorageFuzzer::init()
+{
+ return 0;
+}
+
+int PortableStorageFuzzer::run(const std::string &filename)
+{
+ std::string s;
+
+ if (!epee::file_io_utils::load_file_to_string(filename, s))
+ {
+ std::cout << "Error: failed to load file " << filename << std::endl;
+ return 1;
+ }
+ try
+ {
+ epee::serialization::portable_storage ps;
+ ps.load_from_binary(s);
+ }
+ catch (const std::exception &e)
+ {
+ std::cerr << "Failed to load from binary: " << e.what() << std::endl;
+ return 1;
+ }
+ return 0;
+}
+
+int main(int argc, const char **argv)
+{
+ PortableStorageFuzzer fuzzer;
+ return run_fuzzer(argc, argv, fuzzer);
+}
+
diff --git a/tests/fuzz/load_from_json.cpp b/tests/fuzz/load_from_json.cpp
new file mode 100644
index 000000000..5d39c89a6
--- /dev/null
+++ b/tests/fuzz/load_from_json.cpp
@@ -0,0 +1,76 @@
+// Copyright (c) 2017, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "include_base_utils.h"
+#include "file_io_utils.h"
+#include "serialization/keyvalue_serialization.h"
+#include "storages/portable_storage_template_helper.h"
+#include "storages/portable_storage_base.h"
+#include "fuzzer.h"
+
+class PortableStorageFuzzer: public Fuzzer
+{
+public:
+ PortableStorageFuzzer() {}
+ virtual int init();
+ virtual int run(const std::string &filename);
+};
+
+int PortableStorageFuzzer::init()
+{
+ return 0;
+}
+
+int PortableStorageFuzzer::run(const std::string &filename)
+{
+ std::string s;
+
+ if (!epee::file_io_utils::load_file_to_string(filename, s))
+ {
+ std::cout << "Error: failed to load file " << filename << std::endl;
+ return 1;
+ }
+ try
+ {
+ epee::serialization::portable_storage ps;
+ ps.load_from_json(s);
+ }
+ catch (const std::exception &e)
+ {
+ std::cerr << "Failed to load from binary: " << e.what() << std::endl;
+ return 1;
+ }
+ return 0;
+}
+
+int main(int argc, const char **argv)
+{
+ PortableStorageFuzzer fuzzer;
+ return run_fuzzer(argc, argv, fuzzer);
+}
+
diff --git a/tests/fuzz/parse_url.cpp b/tests/fuzz/parse_url.cpp
new file mode 100644
index 000000000..bf3a3bdd4
--- /dev/null
+++ b/tests/fuzz/parse_url.cpp
@@ -0,0 +1,74 @@
+// Copyright (c) 2017, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "include_base_utils.h"
+#include "file_io_utils.h"
+#include "net/net_parse_helpers.h"
+#include "fuzzer.h"
+
+class ParseURLFuzzer: public Fuzzer
+{
+public:
+ ParseURLFuzzer() {}
+ virtual int init();
+ virtual int run(const std::string &filename);
+};
+
+int ParseURLFuzzer::init()
+{
+ return 0;
+}
+
+int ParseURLFuzzer::run(const std::string &filename)
+{
+ std::string s;
+
+ if (!epee::file_io_utils::load_file_to_string(filename, s))
+ {
+ std::cout << "Error: failed to load file " << filename << std::endl;
+ return 1;
+ }
+ try
+ {
+ epee::net_utils::http::url_content url;
+ epee::net_utils::parse_url(s, url);
+ }
+ catch (const std::exception &e)
+ {
+ std::cerr << "Failed to load from binary: " << e.what() << std::endl;
+ return 1;
+ }
+ return 0;
+}
+
+int main(int argc, const char **argv)
+{
+ ParseURLFuzzer fuzzer;
+ return run_fuzzer(argc, argv, fuzzer);
+}
+
diff --git a/tests/fuzz/signature.cpp b/tests/fuzz/signature.cpp
index 42a8fa997..7ec4434e6 100644
--- a/tests/fuzz/signature.cpp
+++ b/tests/fuzz/signature.cpp
@@ -28,7 +28,7 @@
#include "include_base_utils.h"
#include "file_io_utils.h"
-#include "cryptonote_protocol/blobdatatype.h"
+#include "cryptonote_basic/blobdatatype.h"
#include "cryptonote_basic/cryptonote_basic.h"
#include "cryptonote_basic/cryptonote_format_utils.h"
#include "wallet/wallet2.h"
diff --git a/tests/fuzz/transaction.cpp b/tests/fuzz/transaction.cpp
index 9e2b9f2cb..294676404 100644
--- a/tests/fuzz/transaction.cpp
+++ b/tests/fuzz/transaction.cpp
@@ -28,7 +28,7 @@
#include "include_base_utils.h"
#include "file_io_utils.h"
-#include "cryptonote_protocol/blobdatatype.h"
+#include "cryptonote_basic/blobdatatype.h"
#include "cryptonote_basic/cryptonote_basic.h"
#include "cryptonote_basic/cryptonote_format_utils.h"
#include "fuzzer.h"
diff --git a/tests/performance_tests/cn_slow_hash.h b/tests/performance_tests/cn_slow_hash.h
index 7b04d5bcc..bf9eb7501 100644
--- a/tests/performance_tests/cn_slow_hash.h
+++ b/tests/performance_tests/cn_slow_hash.h
@@ -30,6 +30,7 @@
#pragma once
+#include "string_tools.h"
#include "crypto/crypto.h"
#include "cryptonote_basic/cryptonote_basic.h"
diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt
index 4073a17dc..cfacd5688 100644
--- a/tests/unit_tests/CMakeLists.txt
+++ b/tests/unit_tests/CMakeLists.txt
@@ -50,8 +50,10 @@ set(unit_tests_sources
hashchain.cpp
http.cpp
main.cpp
+ memwipe.cpp
mnemonics.cpp
mul_div.cpp
+ multisig.cpp
parse_amount.cpp
serialization.cpp
sha256.cpp
@@ -101,6 +103,8 @@ if (NOT MSVC)
COMPILE_FLAGS " -Wno-undef -Wno-sign-compare")
endif ()
+SET_PROPERTY(SOURCE memwipe.cpp PROPERTY COMPILE_FLAGS -Ofast)
+
add_test(
NAME unit_tests
COMMAND unit_tests --data-dir "${TEST_DATA_DIR}")
diff --git a/tests/unit_tests/ban.cpp b/tests/unit_tests/ban.cpp
index 242e5fe1c..5af514643 100644
--- a/tests/unit_tests/ban.cpp
+++ b/tests/unit_tests/ban.cpp
@@ -31,7 +31,9 @@
#include "gtest/gtest.h"
#include "cryptonote_core/cryptonote_core.h"
#include "p2p/net_node.h"
+#include "p2p/net_node.inl"
#include "cryptonote_protocol/cryptonote_protocol_handler.h"
+#include "cryptonote_protocol/cryptonote_protocol_handler.inl"
#define MAKE_IPV4_ADDRESS(a,b,c,d) epee::net_utils::ipv4_network_address{MAKE_IP(a,b,c,d),0}
@@ -79,6 +81,7 @@ public:
cryptonote::difficulty_type get_block_cumulative_difficulty(uint64_t height) const { return 0; }
bool fluffy_blocks_enabled() const { return false; }
uint64_t prevalidate_block_hashes(uint64_t height, const std::list<crypto::hash> &hashes) { return 0; }
+ void stop() {}
};
typedef nodetool::node_server<cryptonote::t_cryptonote_protocol_handler<test_core>> Server;
@@ -184,3 +187,5 @@ TEST(ban, add)
ASSERT_TRUE(t >= 4);
}
+namespace nodetool { template class node_server<cryptonote::t_cryptonote_protocol_handler<test_core>>; }
+namespace cryptonote { template class t_cryptonote_protocol_handler<test_core>; }
diff --git a/tests/unit_tests/blockchain_db.cpp b/tests/unit_tests/blockchain_db.cpp
index 5592106cb..4ccd9c1c8 100644
--- a/tests/unit_tests/blockchain_db.cpp
+++ b/tests/unit_tests/blockchain_db.cpp
@@ -35,6 +35,7 @@
#include "gtest/gtest.h"
+#include "string_tools.h"
#include "blockchain_db/blockchain_db.h"
#include "blockchain_db/lmdb/db_lmdb.h"
#ifdef BERKELEY_DB
diff --git a/tests/unit_tests/http.cpp b/tests/unit_tests/http.cpp
index 8d8a0965e..5e427f064 100644
--- a/tests/unit_tests/http.cpp
+++ b/tests/unit_tests/http.cpp
@@ -30,6 +30,7 @@
#include "net/http_auth.h"
#include <boost/algorithm/string/predicate.hpp>
+#include <boost/algorithm/string/join.hpp>
#include <boost/fusion/adapted/std_pair.hpp>
#include <boost/range/algorithm/find_if.hpp>
#include <boost/range/iterator_range_core.hpp>
@@ -211,7 +212,7 @@ std::string get_a1(const http::login& user, const fields& src)
{
const std::string& realm = src.at(u8"realm");
return boost::join(
- std::vector<std::string>{user.username, realm, user.password}, u8":"
+ std::vector<std::string>{user.username, realm, std::string(user.password.data(), user.password.size())}, u8":"
);
}
diff --git a/tests/unit_tests/main.cpp b/tests/unit_tests/main.cpp
index 95ea67410..073ac20fd 100644
--- a/tests/unit_tests/main.cpp
+++ b/tests/unit_tests/main.cpp
@@ -30,10 +30,16 @@
#include "gtest/gtest.h"
-#include <boost/filesystem.hpp>
+#include <boost/filesystem/path.hpp>
+#include <boost/filesystem/operations.hpp>
#include <boost/program_options.hpp>
+#include "p2p/net_node.h"
+#include "p2p/net_node.inl"
+#include "cryptonote_protocol/cryptonote_protocol_handler.h"
+#include "cryptonote_protocol/cryptonote_protocol_handler.inl"
#include "include_base_utils.h"
+#include "string_tools.h"
#include "common/command_line.h"
#include "common/util.h"
#include "unit_tests_utils.h"
@@ -42,6 +48,9 @@ namespace po = boost::program_options;
boost::filesystem::path unit_test::data_dir;
+namespace nodetool { template class node_server<cryptonote::t_cryptonote_protocol_handler<cryptonote::core>>; }
+namespace cryptonote { template class t_cryptonote_protocol_handler<cryptonote::core>; }
+
int main(int argc, char** argv)
{
tools::on_startup();
diff --git a/tests/unit_tests/memwipe.cpp b/tests/unit_tests/memwipe.cpp
new file mode 100644
index 000000000..b2b19fbf5
--- /dev/null
+++ b/tests/unit_tests/memwipe.cpp
@@ -0,0 +1,64 @@
+// Copyright (c) 2017, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "gtest/gtest.h"
+
+#include <stdint.h>
+#include "misc_log_ex.h"
+#include "common/memwipe.h"
+
+// Probably won't catch the optimized out case, but at least we test
+// it works in the normal case
+static void test(bool wipe)
+{
+ char *foo = (char*)malloc(4);
+ ASSERT_TRUE(foo != NULL);
+ intptr_t foop = (intptr_t)foo;
+ strcpy(foo, "bar");
+ void *bar = wipe ? memwipe(foo, 3) : memset(foo, 0, 3);
+ ASSERT_EQ(foo, bar);
+ free(foo);
+ char *quux = (char*)malloc(4); // same size, just after free, so we're likely to get the same, depending on the allocator
+ if ((intptr_t)quux == foop)
+ {
+ MDEBUG(std::hex << std::setw(8) << std::setfill('0') << *(uint32_t*)quux);
+ if (wipe) ASSERT_TRUE(!memcmp(quux, "\0\0\0", 3));
+ }
+ else MWARNING("We did not get the same location, cannot check");
+ free(quux);
+}
+
+TEST(memwipe, control)
+{
+ test(false);
+}
+
+TEST(memwipe, works)
+{
+ test(true);
+}
diff --git a/tests/unit_tests/multisig.cpp b/tests/unit_tests/multisig.cpp
new file mode 100644
index 000000000..8b2c7e5f8
--- /dev/null
+++ b/tests/unit_tests/multisig.cpp
@@ -0,0 +1,188 @@
+// Copyright (c) 2017, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "gtest/gtest.h"
+
+#include <cstdint>
+
+#include "wallet/wallet2.h"
+
+static const struct
+{
+ const char *address;
+ const char *spendkey;
+} test_addresses[] =
+{
+ {
+ "9uvjbU54ZJb8j7Dcq1h3F1DnBRkxXdYUX4pbJ7mE3ghM8uF3fKzqRKRNAKYZXcNLqMg7MxjVVD2wKC2PALUwEveGSC3YSWD",
+ "2dd6e34a234c3e8b5d29a371789e4601e96dee4ea6f7ef79224d1a2d91164c01"
+ },
+ {
+ "9ywDBAyDbb6QKFiZxDJ4hHZqZEQXXCR5EaYNcndUpqPDeE7rEgs6neQdZnhcDrWbURYK8xUjhuG2mVjJdmknrZbcG7NnbaB",
+ "fac47aecc948ce9d3531aa042abb18235b1df632087c55a361b632ffdd6ede0c"
+ },
+ {
+ "9t6Hn946u3eah5cuncH1hB5hGzsTUoevtf4SY7MHN5NgJZh2SFWsyVt3vUhuHyRKyrCQvr71Lfc1AevG3BXE11PQFoXDtD8",
+ "bbd3175ef9fd9f5eefdc43035f882f74ad14c4cf1799d8b6f9001bc197175d02"
+ }
+};
+
+static void make_wallet(unsigned int idx, tools::wallet2 &wallet)
+{
+ ASSERT_TRUE(idx < sizeof(test_addresses) / sizeof(test_addresses[0]));
+
+ crypto::secret_key spendkey;
+ epee::string_tools::hex_to_pod(test_addresses[idx].spendkey, spendkey);
+
+ try
+ {
+ wallet.init("");
+ wallet.set_subaddress_lookahead(1, 1);
+ wallet.generate("", "", spendkey, true, false);
+ ASSERT_TRUE(test_addresses[idx].address == wallet.get_account().get_public_address_str(true));
+ }
+ catch (const std::exception &e)
+ {
+ MFATAL("Error creating test wallet: " << e.what());
+ ASSERT_TRUE(0);
+ }
+}
+
+static void make_M_2_wallet(tools::wallet2 &wallet0, tools::wallet2 &wallet1, unsigned int M)
+{
+ ASSERT_TRUE(M <= 2);
+
+ make_wallet(0, wallet0);
+ make_wallet(1, wallet1);
+
+ std::vector<crypto::secret_key> sk0(1), sk1(1);
+ std::vector<crypto::public_key> pk0(1), pk1(1);
+
+ std::string mi0 = wallet0.get_multisig_info();
+ std::string mi1 = wallet1.get_multisig_info();
+
+ ASSERT_TRUE(tools::wallet2::verify_multisig_info(mi1, sk0[0], pk0[0]));
+ ASSERT_TRUE(tools::wallet2::verify_multisig_info(mi0, sk1[0], pk1[0]));
+
+ ASSERT_FALSE(wallet0.multisig() || wallet1.multisig());
+ wallet0.make_multisig("", sk0, pk0, M);
+ wallet1.make_multisig("", sk1, pk1, M);
+
+ ASSERT_TRUE(wallet0.get_account().get_public_address_str(true) == wallet1.get_account().get_public_address_str(true));
+
+ bool ready;
+ uint32_t threshold, total;
+ ASSERT_TRUE(wallet0.multisig(&ready, &threshold, &total));
+ ASSERT_TRUE(ready);
+ ASSERT_TRUE(threshold == M);
+ ASSERT_TRUE(total == 2);
+ ASSERT_TRUE(wallet1.multisig(&ready, &threshold, &total));
+ ASSERT_TRUE(ready);
+ ASSERT_TRUE(threshold == M);
+ ASSERT_TRUE(total == 2);
+}
+
+static void make_M_3_wallet(tools::wallet2 &wallet0, tools::wallet2 &wallet1, tools::wallet2 &wallet2, unsigned int M)
+{
+ ASSERT_TRUE(M <= 3);
+
+ make_wallet(0, wallet0);
+ make_wallet(1, wallet1);
+ make_wallet(2, wallet2);
+
+ std::vector<crypto::secret_key> sk0(2), sk1(2), sk2(2);
+ std::vector<crypto::public_key> pk0(2), pk1(2), pk2(2);
+
+ std::string mi0 = wallet0.get_multisig_info();
+ std::string mi1 = wallet1.get_multisig_info();
+ std::string mi2 = wallet2.get_multisig_info();
+
+ ASSERT_TRUE(tools::wallet2::verify_multisig_info(mi1, sk0[0], pk0[0]));
+ ASSERT_TRUE(tools::wallet2::verify_multisig_info(mi2, sk0[1], pk0[1]));
+ ASSERT_TRUE(tools::wallet2::verify_multisig_info(mi0, sk1[0], pk1[0]));
+ ASSERT_TRUE(tools::wallet2::verify_multisig_info(mi2, sk1[1], pk1[1]));
+ ASSERT_TRUE(tools::wallet2::verify_multisig_info(mi0, sk2[0], pk2[0]));
+ ASSERT_TRUE(tools::wallet2::verify_multisig_info(mi1, sk2[1], pk2[1]));
+
+ ASSERT_FALSE(wallet0.multisig() || wallet1.multisig() || wallet2.multisig());
+ std::string mxi0 = wallet0.make_multisig("", sk0, pk0, M);
+ std::string mxi1 = wallet1.make_multisig("", sk1, pk1, M);
+ std::string mxi2 = wallet2.make_multisig("", sk2, pk2, M);
+
+ const size_t nset = !mxi0.empty() + !mxi1.empty() + !mxi2.empty();
+ ASSERT_TRUE((M < 3 && nset == 3) || (M == 3 && nset == 0));
+
+ if (nset > 0)
+ {
+ std::unordered_set<crypto::public_key> pkeys;
+ std::vector<crypto::public_key> signers(3, crypto::null_pkey);
+ ASSERT_TRUE(tools::wallet2::verify_extra_multisig_info(mxi0, pkeys, signers[0]));
+ ASSERT_TRUE(tools::wallet2::verify_extra_multisig_info(mxi1, pkeys, signers[1]));
+ ASSERT_TRUE(tools::wallet2::verify_extra_multisig_info(mxi2, pkeys, signers[2]));
+ ASSERT_TRUE(pkeys.size() == 3);
+ ASSERT_TRUE(wallet0.finalize_multisig("", pkeys, signers));
+ ASSERT_TRUE(wallet1.finalize_multisig("", pkeys, signers));
+ ASSERT_TRUE(wallet2.finalize_multisig("", pkeys, signers));
+ }
+
+ ASSERT_TRUE(wallet0.get_account().get_public_address_str(true) == wallet1.get_account().get_public_address_str(true));
+ ASSERT_TRUE(wallet0.get_account().get_public_address_str(true) == wallet2.get_account().get_public_address_str(true));
+
+ bool ready;
+ uint32_t threshold, total;
+ ASSERT_TRUE(wallet0.multisig(&ready, &threshold, &total));
+ ASSERT_TRUE(ready);
+ ASSERT_TRUE(threshold == M);
+ ASSERT_TRUE(total == 3);
+ ASSERT_TRUE(wallet1.multisig(&ready, &threshold, &total));
+ ASSERT_TRUE(ready);
+ ASSERT_TRUE(threshold == M);
+ ASSERT_TRUE(total == 3);
+ ASSERT_TRUE(wallet2.multisig(&ready, &threshold, &total));
+ ASSERT_TRUE(ready);
+ ASSERT_TRUE(threshold == M);
+ ASSERT_TRUE(total == 3);
+}
+
+TEST(multisig, make_2_2)
+{
+ tools::wallet2 wallet0, wallet1;
+ make_M_2_wallet(wallet0, wallet1, 2);
+}
+
+TEST(multisig, make_3_3)
+{
+ tools::wallet2 wallet0, wallet1, wallet2;
+ make_M_3_wallet(wallet0, wallet1, wallet2, 3);
+}
+
+TEST(multisig, make_2_3)
+{
+ tools::wallet2 wallet0, wallet1, wallet2;
+ make_M_3_wallet(wallet0, wallet1, wallet2, 2);
+}
diff --git a/tests/unit_tests/ringct.cpp b/tests/unit_tests/ringct.cpp
index ef6151efb..6956179c1 100644
--- a/tests/unit_tests/ringct.cpp
+++ b/tests/unit_tests/ringct.cpp
@@ -111,7 +111,7 @@ TEST(ringct, MG_sigs)
sk[j] = xm[ind][j];
}
key message = identity();
- mgSig IIccss = MLSAG_Gen(message, P, sk, ind, R);
+ mgSig IIccss = MLSAG_Gen(message, P, sk, NULL, NULL, ind, R);
ASSERT_TRUE(MLSAG_Ver(message, P, IIccss, R));
//#MG sig: false one
@@ -132,7 +132,7 @@ TEST(ringct, MG_sigs)
sk[j] = xx[ind][j];
}
sk[2] = skGen();//asume we don't know one of the private keys..
- IIccss = MLSAG_Gen(message, P, sk, ind, R);
+ IIccss = MLSAG_Gen(message, P, sk, NULL, NULL, ind, R);
ASSERT_FALSE(MLSAG_Ver(message, P, IIccss, R));
}
@@ -171,7 +171,7 @@ TEST(ringct, range_proofs)
destinations.push_back(Pk);
//compute rct data with mixin 500
- rctSig s = genRct(rct::zero(), sc, pc, destinations, amounts, amount_keys, 3);
+ rctSig s = genRct(rct::zero(), sc, pc, destinations, amounts, amount_keys, NULL, NULL, 3);
//verify rct data
ASSERT_TRUE(verRct(s));
@@ -188,7 +188,7 @@ TEST(ringct, range_proofs)
//compute rct data with mixin 500
- s = genRct(rct::zero(), sc, pc, destinations, amounts, amount_keys, 3);
+ s = genRct(rct::zero(), sc, pc, destinations, amounts, amount_keys, NULL, NULL, 3);
//verify rct data
ASSERT_FALSE(verRct(s));
@@ -235,7 +235,7 @@ TEST(ringct, range_proofs_with_fee)
destinations.push_back(Pk);
//compute rct data with mixin 500
- rctSig s = genRct(rct::zero(), sc, pc, destinations, amounts, amount_keys, 3);
+ rctSig s = genRct(rct::zero(), sc, pc, destinations, amounts, amount_keys, NULL, NULL, 3);
//verify rct data
ASSERT_TRUE(verRct(s));
@@ -252,7 +252,7 @@ TEST(ringct, range_proofs_with_fee)
//compute rct data with mixin 500
- s = genRct(rct::zero(), sc, pc, destinations, amounts, amount_keys, 3);
+ s = genRct(rct::zero(), sc, pc, destinations, amounts, amount_keys, NULL, NULL, 3);
//verify rct data
ASSERT_FALSE(verRct(s));
@@ -310,7 +310,7 @@ TEST(ringct, simple)
//compute sig with mixin 2
xmr_amount txnfee = 1;
- rctSig s = genRctSimple(message, sc, pc, destinations,inamounts, outamounts, amount_keys, txnfee, 2);
+ rctSig s = genRctSimple(message, sc, pc, destinations,inamounts, outamounts, amount_keys, NULL, NULL, txnfee, 2);
//verify ring ct signature
ASSERT_TRUE(verRctSimple(s));
@@ -344,7 +344,7 @@ static rct::rctSig make_sample_rct_sig(int n_inputs, const uint64_t input_amount
}
}
- return genRct(rct::zero(), sc, pc, destinations, amounts, amount_keys, 3);;
+ return genRct(rct::zero(), sc, pc, destinations, amounts, amount_keys, NULL, NULL, 3);;
}
static rct::rctSig make_sample_simple_rct_sig(int n_inputs, const uint64_t input_amounts[], int n_outputs, const uint64_t output_amounts[], uint64_t fee)
@@ -370,7 +370,7 @@ static rct::rctSig make_sample_simple_rct_sig(int n_inputs, const uint64_t input
destinations.push_back(Pk);
}
- return genRctSimple(rct::zero(), sc, pc, destinations, inamounts, outamounts, amount_keys, fee, 3);;
+ return genRctSimple(rct::zero(), sc, pc, destinations, inamounts, outamounts, amount_keys, NULL, NULL, fee, 3);;
}
static bool range_proof_test(bool expected_valid,
diff --git a/tests/unit_tests/serialization.cpp b/tests/unit_tests/serialization.cpp
index 0750ab7d1..9e76efadf 100644
--- a/tests/unit_tests/serialization.cpp
+++ b/tests/unit_tests/serialization.cpp
@@ -591,7 +591,7 @@ TEST(Serialization, serializes_ringct_types)
rct::skpkGen(Sk, Pk);
destinations.push_back(Pk);
//compute rct data with mixin 500
- s0 = rct::genRct(rct::zero(), sc, pc, destinations, amounts, amount_keys, 3);
+ s0 = rct::genRct(rct::zero(), sc, pc, destinations, amounts, amount_keys, NULL, NULL, 3);
mg0 = s0.p.MGs[0];
ASSERT_TRUE(serialization::dump_binary(mg0, blob));
diff --git a/tests/unit_tests/slow_memmem.cpp b/tests/unit_tests/slow_memmem.cpp
index 0312019be..6e1dcb85f 100644
--- a/tests/unit_tests/slow_memmem.cpp
+++ b/tests/unit_tests/slow_memmem.cpp
@@ -81,7 +81,6 @@ static const struct {
{1,"x",1,"x",0},
{2,"x",1,"",1},
{1,"x",1,"",0},
- {1,"x",2,"",0},
{1,"x",2,"x",0},
{2,"ax",2,"x",0},
{1,"xx",2,"xx",0},
@@ -103,7 +102,7 @@ static const struct {
{8,"xxxxxxab",3,"xyz",0},
{8,"xxxxxxab",6,"abcdef",0},
{9,"\0xxxxxab",3,"ab",6},
- {4,"\0\0a",3,"\0a",1},
+ {4,"\0\0a",3,"\0a",1}, //
};
TEST(slowmem,Success)
@@ -122,7 +121,6 @@ TEST(slowmem,Success)
free(pat);
free(buf);
ASSERT_EQ(res,T[n].res);
-ASSERT_EQ(1,1);
#ifdef VERBOSE
if (res!=T[n].res) printf("failed (got %zu, expected %zu)",res,T[n].res); else printf("ok");
printf("\n");
diff --git a/tests/unit_tests/vercmp.cpp b/tests/unit_tests/vercmp.cpp
index d48dfdf7c..8f359585d 100644
--- a/tests/unit_tests/vercmp.cpp
+++ b/tests/unit_tests/vercmp.cpp
@@ -40,4 +40,6 @@ TEST(vercmp, two_one) { ASSERT_TRUE(tools::vercmp("2", "1") > 0); }
TEST(vercmp, ten_nine) { ASSERT_TRUE(tools::vercmp("10", "9") > 0); }
TEST(vercmp, one_dot_ten_one_dot_nine) { ASSERT_TRUE(tools::vercmp("1.10", "1.9") > 0); }
TEST(vercmp, one_one_dot_nine) { ASSERT_TRUE(tools::vercmp("1", "1.9") < 0); }
+TEST(vercmp, to_master) { ASSERT_TRUE(tools::vercmp("1.0", "1.0-master") < 0); }
+TEST(vercmp, from_master) { ASSERT_TRUE(tools::vercmp("1.0-master", "1.1") < 0); }