133{
135 bool r;
136
139#ifdef NO_MULTISIG
141#endif
143
144
145 --creator;
146 for (size_t &signer: signers)
147 --signer;
148
150 for (size_t signer: signers)
152
153#ifdef NO_MULTISIG
159 account_base miner_account[5] = {acc0, acc1, acc2, acc3, acc4};
160#else
162#endif
163
165
166
167
168 constexpr size_t n_coinbases = 8;
169 cryptonote::account_base miner_accounts[n_coinbases];
170 const cryptonote::block *prev_block = &blk_0;
171 cryptonote::block blocks[n_coinbases];
172 for (size_t n = 0; n < n_coinbases; ++n) {
173
175 account_base &account = n < inputs ? miner_account[creator] : miner_accounts[n];
179 crypto::hash(), 0, transaction(), std::vector<crypto::hash>(), 0, 1, 4),
180 false, "Failed to generate block");
181 events.push_back(blocks[n]);
182 prev_block = blocks + n;
185 }
186
187
188 cryptonote::block blk_r, blk_last;
189 {
190 blk_last = blocks[n_coinbases - 1];
192 {
193 cryptonote::block blk;
197 crypto::hash(), 0, transaction(), std::vector<crypto::hash>(), 0, 1, 4),
198 false, "Failed to generate block");
199 events.push_back(blk);
200 blk_last = blk;
201 }
202 blk_r = blk_last;
203 }
204
205 cryptonote::keypair in_ephemeral;
208 for (size_t n = 0; n < n_coinbases; ++n)
209 {
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);
214 }
215
216 std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses;
218
219#ifndef NO_MULTISIG
220
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)
227 {
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");
230
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)
237 {
238 account_L[msidx][tdidx].resize(nlr);
239 account_R[msidx][tdidx].resize(nlr);
240 for (size_t n = 0; n < nlr; ++n)
241 {
242 account_k[msidx][tdidx].push_back(rct::rct2sk(
rct::skGen()));
244 }
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)
248 {
251 }
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)
258 {
259 MDEBUG(
"k: " << account_k[msidx][tdidx][n]);
260 MDEBUG(
"L: " << account_L[msidx][tdidx][n]);
261 MDEBUG(
"R: " << account_R[msidx][tdidx][n]);
262 }
263 for (const auto &ki: account_ki[msidx][tdidx])
265 }
266 }
267#endif
268
269
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)
273 {
274 kLRkis.push_back(rct::multisig_kLRki());
275 rct::multisig_kLRki &kLRki = kLRkis.back();
276#ifdef NO_MULTISIG
278#else
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)
286 {
287 if (msidx == creator)
288 continue;
289 if (std::find(signers.begin(), signers.end(), msidx) == signers.end())
290 continue;
291 for (size_t lr = 0; lr < account_L[msidx][tdidx].size(); ++lr)
292 {
293 if (used_L.find(account_L[msidx][tdidx][lr]) == used_L.end())
294 {
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]);
298 rct::addKeys((rct::key&)kLRki.
L, kLRki.
L, rct::pk2rct(account_L[msidx][tdidx][lr]));
299 rct::addKeys((rct::key&)kLRki.
R, kLRki.
R, rct::pk2rct(account_R[msidx][tdidx][lr]));
300 break;
301 }
302 }
303 }
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)
314 {
315 rct::key ki;
319 }
320 }
321#endif
322
323
324 std::vector<tx_source_entry> sources;
325 for (size_t n = 0; n < inputs; ++n)
326 {
327 sources.resize(sources.size() + 1);
328 tx_source_entry& src = sources.back();
329
337
338 for (size_t m = 0; m <= mixin; ++m)
339 {
340 rct::ctkey ctkey;
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));
345 }
346 }
347
348
349 tx_destination_entry td;
350 td.
addr = miner_account[creator].get_keys().m_account_address;
352 std::vector<tx_destination_entry> destinations;
353 destinations.push_back(td);
354
355 if (pre_tx)
356 pre_tx(sources, destinations);
357
358 transaction tx;
360#ifdef NO_MULTISIG
361 rct::multisig_out *msoutp = NULL;
362#else
363 rct::multisig_out msout;
364 rct::multisig_out *msoutp = &msout;
365#endif
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);
370
371#ifndef NO_MULTISIG
372
373 std::vector<size_t> ins_order;
374 for (size_t n = 0; n < sources.size(); ++n)
375 {
376 for (size_t idx = 0; idx < sources_copy.size(); ++idx)
377 {
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);
382 }
383 }
384 CHECK_AND_ASSERT_MES(ins_order.size() == sources.size(),
false,
"Failed to work out sources permutation");
385#endif
386
387#ifndef NO_MULTISIG
388
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)
394 {
396 const std::vector<crypto::secret_key> &msk1 = miner_account[signer].get_multisig_keys();
397 for (size_t n = 0; n < msk1.size(); ++n)
398 {
400 if (used_keys.find(sk1) == used_keys.end())
401 {
402 used_keys.insert(sk1);
404 }
405 }
407 std::vector<unsigned int> indices;
408 for (const auto &src: sources_copy)
411 for (size_t tdidx = 0; tdidx < inputs; ++tdidx)
412 {
414 for (size_t n = 0; n < account_k[signer][tdidx].size(); ++n)
415 {
418 if (used_L.find(L) != used_L.end())
419 {
420 sc_add(k.back().bytes, k.back().bytes, rct::sk2rct(account_k[signer][tdidx][n]).bytes);
421 }
422 }
424 }
427
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());
437 }
438#endif
439
440
446 std::vector<crypto::key_derivation> additional_derivations;
447 for (
size_t n = 0; n < tx.
vout.size(); ++n)
448 {
451 {
452 ++n_outs;
454 rct::key Ctmp;
463 }
464 }
467
468 if (post_tx)
469 post_tx(tx);
470
471 if (!valid)
473 events.push_back(tx);
475
476 return true;
477}
#define MAKE_GENESIS_BLOCK(VEC_EVENTS, BLK_NAME, MINER_ACC, TS)
#define DO_CALLBACK(VEC_EVENTS, CB_NAME)
#define GENERATE_MULTISIG_ACCOUNT(account, threshold, total)
#define GENERATE_ACCOUNT(account)
crypto::secret_key generate(const crypto::secret_key &recovery_key=crypto::secret_key(), bool recover=false, bool two_random=false)
const account_keys & get_keys() const
std::vector< tx_out > vout
rct::rctSig rct_signatures
void sc_add(unsigned char *, const unsigned char *, const unsigned char *)
#define DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN
#define CRYPTONOTE_MINED_ETN_UNLOCK_WINDOW
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
epee::mlocked< tools::scrubbed< ec_scalar > > secret_key
bool generate_key_derivation(const public_key &key1, const secret_key &key2, key_derivation &derivation)
void derivation_to_scalar(const key_derivation &derivation, size_t output_index, ec_scalar &res)
std::string obj_to_json_str(T &obj)
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 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 generate_multisig_key_image(const account_keys &keys, size_t multisig_key_index, const crypto::public_key &out_key, crypto::key_image &ki)
crypto::public_key get_tx_pub_key_from_extra(const std::vector< uint8_t > &tx_extra, size_t pk_index)
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)
void generate_multisig_LR(const crypto::public_key pkey, const crypto::secret_key &k, crypto::public_key &L, crypto::public_key &R)
device & get_device(const std::string &device_descriptor)
void scalarmultBase(key &aG, const key &a)
etn_amount h2d(const key &test)
void addKeys(key &AB, const key &A, const key &B)
bool signMultisig(rctSig &rv, const std::vector< unsigned int > &indices, const keyV &k, const multisig_out &msout, const key &secret_key)
void ecdhDecode(ecdhTuple &masked, const key &sharedSec, bool v2)
void addKeys2(key &aGbB, const key &a, const key &b, const key &B)
bool equalKeys(const key &a, const key &b)
key commit(etn_amount amount, const key &mask)
unsigned __int64 uint64_t
account_public_address m_account_address
crypto::public_key m_spend_public_key
account_public_address addr
crypto::public_key real_out_tx_key
rct::multisig_kLRki multisig_kLRki
std::vector< output_entry > outputs
size_t real_output_in_tx_index
std::vector< ecdhTuple > ecdhInfo