46 std::vector<crypto::secret_key> all_view_keys;
47 std::vector<std::vector<crypto::public_key>> derivations(account.size());
49 std::unordered_set<crypto::public_key> exchanging_keys;
51 for (
size_t msidx = 0; msidx < account.size(); ++msidx)
54 all_view_keys.push_back(vkh);
60 derivations[msidx].push_back(pskh);
61 exchanging_keys.insert(pskh);
69 std::vector<std::vector<crypto::secret_key>> multisig_keys(account.size());
70 std::vector<crypto::secret_key> spend_skey(account.size());
71 std::vector<crypto::public_key> spend_pkey(account.size());
72 for (
uint32_t round = 0; round < roundsTotal; ++round)
74 std::unordered_set<crypto::public_key> roundKeys;
75 for (
size_t msidx = 0; msidx < account.size(); ++msidx)
78 auto myKeys = exchanging_keys;
79 for (
const auto& d: derivations[msidx])
89 roundKeys.insert(derivations[msidx].begin(), derivations[msidx].end());
93 exchanging_keys = roundKeys;
97 std::unordered_set<crypto::public_key> all_multisig_keys;
98 for (
size_t msidx = 0; msidx < account.size(); ++msidx)
100 std::unordered_set<crypto::secret_key> view_keys(all_view_keys.begin(), all_view_keys.end());
101 view_keys.erase(all_view_keys[msidx]);
109 account[msidx].make_multisig(view_skey, spend_skey[msidx], spend_pkey[msidx], multisig_keys[msidx]);
110 for (
const auto &k: multisig_keys[msidx]) {
117 std::vector<crypto::public_key> public_keys(std::vector<crypto::public_key>(all_multisig_keys.begin(), all_multisig_keys.end()));
120 for (
size_t msidx = 0; msidx < account.size(); ++msidx)
121 account[msidx].finalize_multisig(spend_pkey);
129 size_t inputs,
size_t mixin,
uint64_t amount_paid,
bool valid,
130 size_t threshold,
size_t total,
size_t creator, std::vector<size_t> signers,
131 const std::function<
void(std::vector<tx_source_entry> &sources, std::vector<tx_destination_entry> &destinations)> &pre_tx,
132 const std::function<
void(
transaction &tx)> &post_tx)
const 146 for (
size_t &signer: signers)
150 for (
size_t signer: signers)
159 account_base miner_account[5] = {acc0, acc1, acc2, acc3, acc4};
168 constexpr
size_t n_coinbases = 8;
172 for (
size_t n = 0; n < n_coinbases; ++n) {
175 account_base &account = n < inputs ? miner_account[creator] : miner_accounts[n];
180 false,
"Failed to generate block");
181 events.push_back(
blocks[n]);
190 blk_last =
blocks[n_coinbases - 1];
198 false,
"Failed to generate block");
199 events.push_back(blk);
208 for (
size_t n = 0; n < n_coinbases; ++n)
211 MDEBUG(
"tx_pub_key: " << tx_pub_key);
212 output_pub_key[n] = boost::get<txout_to_key>(
blocks[n].miner_tx.vout[0].target).
key;
213 MDEBUG(
"output_pub_key: " << output_pub_key);
216 std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses;
221 std::vector<std::vector<std::vector<crypto::secret_key>>> account_k(total);
222 std::vector<std::vector<std::vector<crypto::public_key>>> account_L(total);
223 std::vector<std::vector<std::vector<crypto::public_key>>> account_R(total);
224 std::vector<std::vector<std::vector<crypto::key_image>>> account_ki(total);
225 std::vector<crypto::public_key> additional_tx_keys;
226 for (
size_t msidx = 0; msidx < total; ++msidx)
228 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,
229 false,
"Mismatched spend public keys");
232 account_k[msidx].resize(inputs);
233 account_L[msidx].resize(inputs);
234 account_R[msidx].resize(inputs);
235 account_ki[msidx].resize(inputs);
236 for (
size_t tdidx = 0; tdidx < inputs; ++tdidx)
238 account_L[msidx][tdidx].resize(nlr);
239 account_R[msidx][tdidx].resize(nlr);
240 for (
size_t n = 0; n < nlr; ++n)
242 account_k[msidx][tdidx].push_back(rct::rct2sk(
rct::skGen()));
245 size_t numki = miner_account[msidx].get_multisig_keys().size();
246 account_ki[msidx][tdidx].resize(numki);
247 for (
size_t kiidx = 0; kiidx < numki; ++kiidx)
252 MDEBUG(
"Party " << msidx <<
":");
253 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);
254 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);
255 for (
const auto &k: miner_account[msidx].get_multisig_keys())
257 for (
size_t n = 0; n < account_k[msidx][tdidx].size(); ++n)
259 MDEBUG(
"k: " << account_k[msidx][tdidx][n]);
260 MDEBUG(
"L: " << account_L[msidx][tdidx][n]);
261 MDEBUG(
"R: " << account_R[msidx][tdidx][n]);
263 for (
const auto &ki: account_ki[msidx][tdidx])
270 std::vector<rct::multisig_kLRki> kLRkis;
271 std::unordered_set<crypto::public_key> used_L;
272 for (
size_t tdidx = 0; tdidx < inputs; ++tdidx)
279 kLRki.
k = rct::sk2rct(account_k[creator][tdidx][0]);
280 kLRki.
L = rct::pk2rct(account_L[creator][tdidx][0]);
281 kLRki.
R = rct::pk2rct(account_R[creator][tdidx][0]);
282 MDEBUG(
"Starting with k " << kLRki.
k);
283 MDEBUG(
"Starting with L " << kLRki.
L);
284 MDEBUG(
"Starting with R " << kLRki.
R);
285 for (
size_t msidx = 0; msidx < total; ++msidx)
287 if (msidx == creator)
289 if (std::find(signers.begin(), signers.end(), msidx) == signers.end())
291 for (
size_t lr = 0; lr < account_L[msidx][tdidx].size(); ++lr)
293 if (used_L.find(account_L[msidx][tdidx][lr]) == used_L.end())
295 used_L.insert(account_L[msidx][tdidx][lr]);
296 MDEBUG(
"Adding L " << account_L[msidx][tdidx][lr] <<
" (for k " << account_k[msidx][tdidx][lr] <<
")");
297 MDEBUG(
"Adding R " << account_R[msidx][tdidx][lr]);
304 std::vector<crypto::key_image> pkis;
305 for (
size_t msidx = 0; msidx < total; ++msidx)
306 for (
size_t n = 0; n < account_ki[msidx][tdidx].size(); ++n)
307 pkis.push_back(account_ki[msidx][tdidx][n]);
310 MDEBUG(
"composite ki: " << kLRki.
ki);
313 for (
size_t n = 1; n < total; ++n)
324 std::vector<tx_source_entry> sources;
325 for (
size_t n = 0; n < inputs; ++n)
327 sources.resize(sources.size() + 1);
338 for (
size_t m = 0; m <= mixin; ++m)
341 ctkey.
dest = rct::pk2rct(boost::get<txout_to_key>(
blocks[m].miner_tx.vout[0].target).key);
342 MDEBUG(
"using " << (m == n ?
"real" :
"fake") <<
" input " << ctkey.
dest);
344 src.
outputs.push_back(std::make_pair(m, ctkey));
350 td.
addr = miner_account[creator].get_keys().m_account_address;
352 std::vector<tx_destination_entry> destinations;
353 destinations.push_back(td);
356 pre_tx(sources, destinations);
366 std::vector<crypto::secret_key> additional_tx_secret_keys;
367 auto sources_copy = sources;
368 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, {
rct::RangeProofBorromean, 0 }, msoutp);
373 std::vector<size_t> ins_order;
374 for (
size_t n = 0; n < sources.size(); ++n)
376 for (
size_t idx = 0; idx < sources_copy.size(); ++idx)
379 false,
"Invalid real_output");
380 if (sources_copy[idx].outputs[sources_copy[idx].real_output].second.dest == sources[n].outputs[sources[n].real_output].second.dest)
381 ins_order.push_back(idx);
384 CHECK_AND_ASSERT_MES(ins_order.size() == sources.size(),
false,
"Failed to work out sources permutation");
389 std::unordered_set<crypto::secret_key> used_keys;
390 const std::vector<crypto::secret_key> &msk0 = miner_account[creator].get_multisig_keys();
391 for (
const auto &sk: msk0)
392 used_keys.insert(sk);
393 for (
size_t signer: signers)
396 const std::vector<crypto::secret_key> &msk1 = miner_account[signer].get_multisig_keys();
397 for (
size_t n = 0; n < msk1.size(); ++n)
400 if (used_keys.find(sk1) == used_keys.end())
402 used_keys.insert(sk1);
407 std::vector<unsigned int> indices;
408 for (
const auto &src: sources_copy)
409 indices.push_back(src.real_output);
411 for (
size_t tdidx = 0; tdidx < inputs; ++tdidx)
414 for (
size_t n = 0; n < account_k[signer][tdidx].size(); ++n)
418 if (used_L.find(L) != used_L.end())
420 sc_add(k.back().bytes, k.back().bytes, rct::sk2rct(account_k[signer][tdidx][n]).
bytes);
428 MDEBUG(
"signing with k size " << k.size());
429 MDEBUG(
"signing with k " << k.back());
430 MDEBUG(
"signing with sk " << skey);
431 for (
const auto &sk: used_keys)
432 MDEBUG(
" created with sk " << sk);
433 MDEBUG(
"signing with c size " << msout.
c.size());
434 MDEBUG(
"signing with c " << msout.
c.back());
446 std::vector<crypto::key_derivation> additional_derivations;
447 for (
size_t n = 0; n < tx.
vout.size(); ++n)
473 events.push_back(tx);
481 const size_t mixin = 4;
483 return generate_with(events, 2, mixin, amount_paid,
true, 2, 2, 1, {2}, NULL, NULL);
488 const size_t mixin = 4;
490 return generate_with(events, 4, mixin, amount_paid,
true, 2, 2, 1, {2}, NULL, NULL);
495 const size_t mixin = 4;
497 return generate_with(events, 2, mixin, amount_paid,
true, 2, 2, 2, {1}, NULL, NULL);
502 const size_t mixin = 4;
504 return generate_with(events, 2, mixin, amount_paid,
true, 3, 3, 1, {2, 3}, NULL, NULL);
509 const size_t mixin = 4;
511 return generate_with(events, 2, mixin, amount_paid,
true, 3, 3, 3, {2, 1}, NULL, NULL);
516 const size_t mixin = 4;
518 return generate_with(events, 2, mixin, amount_paid,
true, 2, 3, 1, {2}, NULL, NULL);
523 const size_t mixin = 4;
525 return generate_with(events, 2, mixin, amount_paid,
true, 2, 3, 1, {3}, NULL, NULL);
530 const size_t mixin = 4;
532 return generate_with(events, 2, mixin, amount_paid,
true, 2, 3, 2, {1}, NULL, NULL);
537 const size_t mixin = 4;
539 return generate_with(events, 2, mixin, amount_paid,
true, 2, 3, 2, {3}, NULL, NULL);
544 const size_t mixin = 4;
546 return generate_with(events, 2, mixin, amount_paid,
true, 4, 5, 1, {2, 3, 4}, NULL, NULL);
551 const size_t mixin = 4;
553 return generate_with(events, 4, mixin, amount_paid,
true, 4, 5, 4, {1, 3, 5}, NULL, NULL);
558 const size_t mixin = 4;
560 return generate_with(events, 2, mixin, amount_paid,
true, 8, 9, 3, {1, 2, 4, 5, 7, 8, 9}, NULL, NULL);
565 const size_t mixin = 4;
567 return generate_with(events, 2, mixin, amount_paid,
true, 2, 4, 1, {2}, NULL, NULL);
572 const size_t mixin = 4;
574 return generate_with(events, 4, mixin, amount_paid,
true, 2, 4, 1, {2}, NULL, NULL);
579 const size_t mixin = 4;
581 return generate_with(events, 2, mixin, amount_paid,
true, 2, 5, 1, {2}, NULL, NULL);
586 const size_t mixin = 4;
588 return generate_with(events, 4, mixin, amount_paid,
true, 2, 5, 1, {2}, NULL, NULL);
593 const size_t mixin = 4;
595 return generate_with(events, 2, mixin, amount_paid,
true, 4, 8, 1, {2, 3, 4}, NULL, NULL);
600 const size_t mixin = 4;
602 return generate_with(events, 4, mixin, amount_paid,
true, 4, 8, 1, {2, 3, 4}, NULL, NULL);
607 const size_t mixin = 4;
609 return generate_with(events, 2, mixin, amount_paid,
false, 2, 2, 1, {}, NULL, NULL);
614 const size_t mixin = 4;
616 return generate_with(events, 2, mixin, amount_paid,
false, 3, 3, 1, {}, NULL, NULL);
621 const size_t mixin = 4;
623 return generate_with(events, 2, mixin, amount_paid,
false, 3, 3, 1, {2}, NULL, NULL);
628 const size_t mixin = 4;
630 return generate_with(events, 2, mixin, amount_paid,
false, 3, 3, 1, {3}, NULL, NULL);
635 const size_t mixin = 4;
637 return generate_with(events, 2, mixin, amount_paid,
false, 2, 3, 1, {}, NULL, NULL);
642 const size_t mixin = 4;
644 return generate_with(events, 2, mixin, amount_paid,
false, 4, 5, 5, {2, 3}, NULL, NULL);
649 const size_t mixin = 4;
651 return generate_with(events, 2, mixin, amount_paid,
false, 2, 4, 1, {}, NULL, NULL);
656 const size_t mixin = 4;
658 return generate_with(events, 2, mixin, amount_paid,
false, 2, 5, 1, {}, NULL, NULL);
663 const size_t mixin = 4;
665 return generate_with(events, 2, mixin, amount_paid,
false, 4, 8, 1, {}, NULL, NULL);
670 const size_t mixin = 4;
672 return generate_with(events, 2, mixin, amount_paid,
false, 4, 8, 1, {2, 3}, NULL, NULL);
void generate_multisig_LR(const crypto::public_key pkey, const crypto::secret_key &k, crypto::public_key &L, crypto::public_key &R)
bool generate(std::vector< test_event_entry > &events) const
#define CRYPTONOTE_MINED_ETN_UNLOCK_WINDOW
bool generate(std::vector< test_event_entry > &events) const
void derivation_to_scalar(const key_derivation &derivation, size_t output_index, ec_scalar &res)
bool generate(std::vector< test_event_entry > &events) const
bool generate(std::vector< test_event_entry > &events) const
bool generate(std::vector< test_event_entry > &events) const
crypto::public_key real_out_tx_key
etn_amount h2d(const key &test)
bool generate(std::vector< test_event_entry > &events) const
bool generate(std::vector< test_event_entry > &events) const
bool generate(std::vector< test_event_entry > &events) const
key commit(etn_amount amount, const key &mask)
bool generate(std::vector< test_event_entry > &events) const
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
bool generate(std::vector< test_event_entry > &events) const
bool generate(std::vector< test_event_entry > &events) const
bool generate(std::vector< test_event_entry > &events) const
bool generate(std::vector< test_event_entry > &events) const
bool generate(std::vector< test_event_entry > &events) const
std::vector< crypto::public_key > generate_multisig_derivations(const account_keys &keys, const std::vector< crypto::public_key > &derivations)
generate_multisig_derivations performs common DH key derivation. Each middle round in M/N scheme is D...
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
crypto::secret_key generate(const crypto::secret_key &recovery_key=crypto::secret_key(), bool recover=false, bool two_random=false)
bool generate(std::vector< test_event_entry > &events) const
bool generate_key_derivation(const public_key &key1, const secret_key &key2, key_derivation &derivation)
const account_keys & get_keys() const
std::vector< ecdhTuple > ecdhInfo
void generate_multisig_N_N(const account_keys &keys, const std::vector< crypto::public_key > &spend_keys, std::vector< crypto::secret_key > &multisig_keys, rct::key &spend_skey, rct::key &spend_pkey)
std::vector< tx_out > vout
Holds cryptonote related classes and helpers.
crypto::public_key generate_multisig_M_N_spend_public_key(const std::vector< crypto::public_key > &pkeys)
generate_multisig_M_N_spend_public_key calculates multisig wallet's spend public key by summing all o...
boost::optional< subaddress_receive_info > is_out_to_acc_precomp(const std::unordered_map< crypto::public_key, subaddress_index > &subaddresses, const crypto::public_key &out_key, const crypto::key_derivation &derivation, const std::vector< crypto::key_derivation > &additional_derivations, size_t output_index, hw::device &hwdev)
bool generate(std::vector< test_event_entry > &events) const
crypto::public_key m_spend_public_key
std::vector< crypto::secret_key > calculate_multisig_keys(const std::vector< crypto::public_key > &derivations)
calculate_multisig_keys. Calculates secret multisig keys from others' participants ones as follows: m...
#define GENERATE_MULTISIG_ACCOUNT(account, threshold, total)
bool generate_multisig_key_image(const account_keys &keys, size_t multisig_key_index, const crypto::public_key &out_key, crypto::key_image &ki)
rct::rctSig rct_signatures
bool generate(std::vector< test_event_entry > &events) const
device & get_device(const std::string &device_descriptor)
#define MAKE_GENESIS_BLOCK(VEC_EVENTS, BLK_NAME, MINER_ACC, TS)
std::string obj_to_json_str(T &obj)
unsigned __int64 uint64_t
bool generate(std::vector< test_event_entry > &events) const
crypto::public_key get_tx_pub_key_from_extra(const std::vector< uint8_t > &tx_extra, size_t pk_index)
crypto::secret_key get_multisig_blinded_secret_key(const crypto::secret_key &key)
bool generate_multisig_composite_key_image(const account_keys &keys, const std::unordered_map< crypto::public_key, subaddress_index > &subaddresses, const crypto::public_key &out_key, const crypto::public_key &tx_public_key, const std::vector< crypto::public_key > &additional_tx_public_keys, size_t real_output_index, const std::vector< crypto::key_image > &pkis, crypto::key_image &ki)
bool signMultisig(rctSig &rv, const std::vector< unsigned int > &indices, const keyV &k, const multisig_out &msout, const key &secret_key)
bool generate(std::vector< test_event_entry > &events) const
rct::multisig_kLRki multisig_kLRki
void ecdhDecode(ecdhTuple &masked, const key &sharedSec, bool v2)
account_public_address addr
void scalarmultBase(key &aG, const key &a)
bool generate(std::vector< test_event_entry > &events) const
account_public_address m_account_address
bool generate(std::vector< test_event_entry > &events) const
bool generate(std::vector< test_event_entry > &events) const
void make_multisig_accounts(std::vector< cryptonote::account_base > &account, uint32_t threshold)
crypto::secret_key generate_multisig_view_secret_key(const crypto::secret_key &skey, const std::vector< crypto::secret_key > &skeys)
size_t real_output_in_tx_index
void addKeys2(key &aGbB, const key &a, const key &b, const key &B)
std::vector< output_entry > outputs
void addKeys(key &AB, const key &A, const key &B)
bool secret_key_to_public_key(const secret_key &sec, public_key &pub)
#define DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN
#define GENERATE_ACCOUNT(account)
void sc_add(unsigned char *, const unsigned char *, const unsigned char *)
bool construct_tx_and_get_tx_key(const account_keys &sender_account_keys, const std::unordered_map< crypto::public_key, subaddress_index > &subaddresses, std::vector< tx_source_entry > &sources, std::vector< tx_destination_entry > &destinations, const boost::optional< cryptonote::account_public_address > &change_addr, const std::vector< uint8_t > &extra, transaction &tx, uint64_t unlock_time, crypto::secret_key &tx_key, std::vector< crypto::secret_key > &additional_tx_keys, bool rct, const rct::RCTConfig &rct_config, rct::multisig_out *msout, const uint32_t account_major_offset, const cryptonote::network_type nettype)
bool equalKeys(const key &a, const key &b)
bool generate(std::vector< test_event_entry > &events) const
#define DO_CALLBACK(VEC_EVENTS, CB_NAME)
crypto::secret_key calculate_multisig_signer_key(const std::vector< crypto::secret_key > &multisig_keys)