diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2017-09-26 23:16:25 +0100 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2017-12-17 16:12:15 +0000 |
commit | 66e34e85b1ef3e49ea9290bd69cce2974840fc32 (patch) | |
tree | 618a7336e476189da36fb62f0df06e0fdb7b3809 /tests/core_tests/chaingen.h | |
parent | N-1/N multisig (diff) | |
download | monero-66e34e85b1ef3e49ea9290bd69cce2974840fc32.tar.xz |
add multisig core test and factor multisig building blocks
Diffstat (limited to 'tests/core_tests/chaingen.h')
-rw-r--r-- | tests/core_tests/chaingen.h | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/core_tests/chaingen.h b/tests/core_tests/chaingen.h index 0dcbc7f0c..939b88109 100644 --- a/tests/core_tests/chaingen.h +++ b/tests/core_tests/chaingen.h @@ -505,6 +505,54 @@ 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::hash vkh; \ + crypto::cn_fast_hash(&account[msidx_inner].get_keys().m_view_secret_key, sizeof(crypto::secret_key), vkh); \ + view_keys[msidx].push_back((const crypto::secret_key&)vkh); \ + spend_keys[msidx].push_back(account[msidx_inner].get_keys().m_account_address.m_spend_public_key); \ + } \ + } \ + } \ + 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(); \ |