aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornaughtyfox <mail.for.milo@gmail.com>2018-07-17 12:44:46 +0300
committernaughtyfox <mail.for.milo@gmail.com>2018-10-01 19:17:34 +0300
commit9acf42d3719a3237b99bc66089b49c86fbb9b467 (patch)
tree97d226dadbece1f2669c837180aa58bbd8a9d41e
parentArbitrary M/N multisig schemes: (diff)
downloadmonero-9acf42d3719a3237b99bc66089b49c86fbb9b467.tar.xz
Multisig M/N functionality core tests added
-rw-r--r--tests/core_tests/chaingen.h43
-rw-r--r--tests/core_tests/chaingen_main.cpp10
-rw-r--r--tests/core_tests/multisig.cpp152
-rw-r--r--tests/core_tests/multisig.h60
4 files changed, 223 insertions, 42 deletions
diff --git a/tests/core_tests/chaingen.h b/tests/core_tests/chaingen.h
index c9e1640aa..6b9277a30 100644
--- a/tests/core_tests/chaingen.h
+++ b/tests/core_tests/chaingen.h
@@ -544,6 +544,7 @@ inline bool do_replay_file(const std::string& filename)
}
return do_replay_events<t_test_class>(events);
}
+
//--------------------------------------------------------------------------
#define GENERATE_ACCOUNT(account) \
cryptonote::account_base account; \
@@ -556,47 +557,7 @@ inline bool do_replay_file(const std::string& filename)
{ \
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_M_N_spend_public_key(spend_public_keys); \
- for (size_t msidx = 0; msidx < total; ++msidx) \
- account[msidx].finalize_multisig(spend_pkey); \
- } \
+ make_multisig_accounts(account, threshold); \
} while(0)
#define MAKE_ACCOUNT(VEC_EVENTS, account) \
diff --git a/tests/core_tests/chaingen_main.cpp b/tests/core_tests/chaingen_main.cpp
index abc412318..84254cfdb 100644
--- a/tests/core_tests/chaingen_main.cpp
+++ b/tests/core_tests/chaingen_main.cpp
@@ -223,6 +223,16 @@ int main(int argc, char* argv[])
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);
+ GENERATE_AND_PLAY(gen_multisig_tx_valid_24_1_2);
+ GENERATE_AND_PLAY(gen_multisig_tx_valid_24_1_2_many_inputs);
+ GENERATE_AND_PLAY(gen_multisig_tx_valid_25_1_2);
+ GENERATE_AND_PLAY(gen_multisig_tx_valid_25_1_2_many_inputs);
+ GENERATE_AND_PLAY(gen_multisig_tx_valid_48_1_234);
+ GENERATE_AND_PLAY(gen_multisig_tx_valid_48_1_234_many_inputs);
+ GENERATE_AND_PLAY(gen_multisig_tx_valid_24_1_no_signers);
+ GENERATE_AND_PLAY(gen_multisig_tx_valid_25_1_no_signers);
+ GENERATE_AND_PLAY(gen_multisig_tx_valid_48_1_no_signers);
+ GENERATE_AND_PLAY(gen_multisig_tx_valid_48_1_23_no_threshold);
GENERATE_AND_PLAY(gen_bp_tx_valid_1);
GENERATE_AND_PLAY(gen_bp_tx_invalid_1_1);
diff --git a/tests/core_tests/multisig.cpp b/tests/core_tests/multisig.cpp
index 46cc0ff35..fe5feb942 100644
--- a/tests/core_tests/multisig.cpp
+++ b/tests/core_tests/multisig.cpp
@@ -41,6 +41,87 @@ using namespace cryptonote;
//#define NO_MULTISIG
+void make_multisig_accounts(std::vector<cryptonote::account_base>& account, uint32_t threshold)
+{
+ std::vector<crypto::secret_key> all_view_keys;
+ std::vector<std::vector<crypto::public_key>> derivations(account.size());
+ //storage for all set of multisig derivations and spend public key (in first round)
+ std::unordered_set<crypto::public_key> exchanging_keys;
+
+ for (size_t msidx = 0; msidx < account.size(); ++msidx)
+ {
+ crypto::secret_key vkh = cryptonote::get_multisig_blinded_secret_key(account[msidx].get_keys().m_view_secret_key);
+ all_view_keys.push_back(vkh);
+
+ crypto::secret_key skh = cryptonote::get_multisig_blinded_secret_key(account[msidx].get_keys().m_spend_secret_key);
+ crypto::public_key pskh;
+ crypto::secret_key_to_public_key(skh, pskh);
+
+ derivations[msidx].push_back(pskh);
+ exchanging_keys.insert(pskh);
+ }
+
+ uint32_t roundsTotal = 1;
+ if (threshold < account.size())
+ roundsTotal = account.size() - threshold;
+
+ //secret multisig keys of every account
+ std::vector<std::vector<crypto::secret_key>> multisig_keys(account.size());
+ std::vector<crypto::secret_key> spend_skey(account.size());
+ std::vector<crypto::public_key> spend_pkey(account.size());
+ for (uint32_t round = 0; round < roundsTotal; ++round)
+ {
+ std::unordered_set<crypto::public_key> roundKeys;
+ for (size_t msidx = 0; msidx < account.size(); ++msidx)
+ {
+ // subtracting one's keys from set of all unique keys is the same as key exchange
+ auto myKeys = exchanging_keys;
+ for (const auto& d: derivations[msidx])
+ myKeys.erase(d);
+
+ if (threshold == account.size())
+ {
+ cryptonote::generate_multisig_N_N(account[msidx].get_keys(), std::vector<crypto::public_key>(myKeys.begin(), myKeys.end()), multisig_keys[msidx], (rct::key&)spend_skey[msidx], (rct::key&)spend_pkey[msidx]);
+ }
+ else
+ {
+ derivations[msidx] = cryptonote::generate_multisig_derivations(account[msidx].get_keys(), std::vector<crypto::public_key>(myKeys.begin(), myKeys.end()));
+ roundKeys.insert(derivations[msidx].begin(), derivations[msidx].end());
+ }
+ }
+
+ exchanging_keys = roundKeys;
+ roundKeys.clear();
+ }
+
+ std::unordered_set<crypto::public_key> all_multisig_keys;
+ for (size_t msidx = 0; msidx < account.size(); ++msidx)
+ {
+ std::unordered_set<crypto::secret_key> view_keys(all_view_keys.begin(), all_view_keys.end());
+ view_keys.erase(all_view_keys[msidx]);
+
+ crypto::secret_key view_skey = cryptonote::generate_multisig_view_secret_key(account[msidx].get_keys().m_view_secret_key, std::vector<secret_key>(view_keys.begin(), view_keys.end()));
+ if (threshold < account.size())
+ {
+ multisig_keys[msidx] = cryptonote::calculate_multisig_keys(derivations[msidx]);
+ spend_skey[msidx] = cryptonote::calculate_multisig_signer_key(multisig_keys[msidx]);
+ }
+ account[msidx].make_multisig(view_skey, spend_skey[msidx], spend_pkey[msidx], multisig_keys[msidx]);
+ for (const auto &k: multisig_keys[msidx]) {
+ all_multisig_keys.insert(rct::rct2pk(rct::scalarmultBase(rct::sk2rct(k))));
+ }
+ }
+
+ if (threshold < account.size())
+ {
+ std::vector<crypto::public_key> public_keys(std::vector<crypto::public_key>(all_multisig_keys.begin(), all_multisig_keys.end()));
+ crypto::public_key spend_pkey = cryptonote::generate_multisig_M_N_spend_public_key(public_keys);
+
+ for (size_t msidx = 0; msidx < account.size(); ++msidx)
+ account[msidx].finalize_multisig(spend_pkey);
+ }
+}
+
//----------------------------------------------------------------------------------------------------------------------
// Tests
@@ -55,7 +136,6 @@ bool gen_multisig_tx_validation_base::generate_with(std::vector<test_event_entry
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
@@ -480,6 +560,48 @@ bool gen_multisig_tx_valid_89_3_1245789::generate(std::vector<test_event_entry>&
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_valid_24_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, 4, 1, {2}, NULL, NULL);
+}
+
+bool gen_multisig_tx_valid_24_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, 4, 1, {2}, NULL, NULL);
+}
+
+bool gen_multisig_tx_valid_25_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, 5, 1, {2}, NULL, NULL);
+}
+
+bool gen_multisig_tx_valid_25_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, 5, 1, {2}, NULL, NULL);
+}
+
+bool gen_multisig_tx_valid_48_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, 8, 1, {2, 3, 4}, NULL, NULL);
+}
+
+bool gen_multisig_tx_valid_48_1_234_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, 8, 1, {2, 3, 4}, NULL, NULL);
+}
+
bool gen_multisig_tx_invalid_22_1__no_threshold::generate(std::vector<test_event_entry>& events) const
{
const size_t mixin = 4;
@@ -521,3 +643,31 @@ bool gen_multisig_tx_invalid_45_5_23_no_threshold::generate(std::vector<test_eve
const uint64_t amount_paid = 10000;
return generate_with(events, 2, mixin, amount_paid, false, 4, 5, 5, {2, 3}, NULL, NULL);
}
+
+bool gen_multisig_tx_valid_24_1_no_signers::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, 4, 1, {}, NULL, NULL);
+}
+
+bool gen_multisig_tx_valid_25_1_no_signers::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, 5, 1, {}, NULL, NULL);
+}
+
+bool gen_multisig_tx_valid_48_1_no_signers::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, 8, 1, {}, NULL, NULL);
+}
+
+bool gen_multisig_tx_valid_48_1_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, 8, 1, {2, 3}, NULL, NULL);
+}
diff --git a/tests/core_tests/multisig.h b/tests/core_tests/multisig.h
index f0157a6d1..9e4cb3a23 100644
--- a/tests/core_tests/multisig.h
+++ b/tests/core_tests/multisig.h
@@ -161,6 +161,42 @@ struct gen_multisig_tx_valid_89_3_1245789: public gen_multisig_tx_validation_bas
};
template<> struct get_test_options<gen_multisig_tx_valid_89_3_1245789>: public get_test_options<gen_multisig_tx_validation_base> {};
+struct gen_multisig_tx_valid_24_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_24_1_2>: public get_test_options<gen_multisig_tx_validation_base> {};
+
+struct gen_multisig_tx_valid_24_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_24_1_2_many_inputs>: public get_test_options<gen_multisig_tx_validation_base> {};
+
+struct gen_multisig_tx_valid_25_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_25_1_2>: public get_test_options<gen_multisig_tx_validation_base> {};
+
+struct gen_multisig_tx_valid_25_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_25_1_2_many_inputs>: public get_test_options<gen_multisig_tx_validation_base> {};
+
+struct gen_multisig_tx_valid_48_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_48_1_234>: public get_test_options<gen_multisig_tx_validation_base> {};
+
+struct gen_multisig_tx_valid_48_1_234_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_48_1_234_many_inputs>: 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
{
@@ -197,3 +233,27 @@ struct gen_multisig_tx_invalid_45_5_23_no_threshold: public gen_multisig_tx_vali
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> {};
+
+struct gen_multisig_tx_valid_24_1_no_signers: public gen_multisig_tx_validation_base
+{
+ bool generate(std::vector<test_event_entry>& events) const;
+};
+template<> struct get_test_options<gen_multisig_tx_valid_24_1_no_signers>: public get_test_options<gen_multisig_tx_validation_base> {};
+
+struct gen_multisig_tx_valid_25_1_no_signers: public gen_multisig_tx_validation_base
+{
+ bool generate(std::vector<test_event_entry>& events) const;
+};
+template<> struct get_test_options<gen_multisig_tx_valid_25_1_no_signers>: public get_test_options<gen_multisig_tx_validation_base> {};
+
+struct gen_multisig_tx_valid_48_1_no_signers: public gen_multisig_tx_validation_base
+{
+ bool generate(std::vector<test_event_entry>& events) const;
+};
+template<> struct get_test_options<gen_multisig_tx_valid_48_1_no_signers>: public get_test_options<gen_multisig_tx_validation_base> {};
+
+struct gen_multisig_tx_valid_48_1_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_valid_48_1_23_no_threshold>: public get_test_options<gen_multisig_tx_validation_base> {};