From 0744587cf000c42811341c71c916d579f0920f64 Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Tue, 17 Jan 2017 17:07:14 +0800 Subject: [PATCH 1/4] searching for mixins with outputs started --- src/page.h | 68 +++++++++++++++++++++++------------ src/templates/my_outputs.html | 45 ++++++++++++----------- 2 files changed, 70 insertions(+), 43 deletions(-) diff --git a/src/page.h b/src/page.h index 66ec4ca..58aa8c2 100644 --- a/src/page.h +++ b/src/page.h @@ -1322,8 +1322,10 @@ public: // we can also test ouputs used in mixins for key images // this can show possible spending. Only possible, because // without a spend key, we cant know for sure. It might be - // that our output was used by someelse for their mixin. - // for this we can look in our custom db, for efficiencly + // that our output was used by someone else for their mixins. + // For this we can look in our custom db, for efficiencly + + bool show_key_images {false}; unique_ptr mylmdb; @@ -1341,6 +1343,7 @@ public: if (!mylmdb) { + show_key_images = false; break; } @@ -1378,13 +1381,13 @@ public: // to store our mixins found for the given key image vector> our_mixins_found; - // for each found output public key find check if its ours or not + // for each found output public key check if its ours or not for (const cryptonote::output_data_t& output_data: mixin_outputs) { string out_pub_key_str = pod_to_hex(output_data.pubkey); - //cout << "out_pub_key_str: " << out_pub_key_str << endl; + cout << "out_pub_key_str: " << out_pub_key_str << endl; // this will be txs where the outputs come from vector found_tx_hashes; @@ -1396,19 +1399,26 @@ public: mixins.push_back(mstch::map{ - {"mixin_pub_key", out_pub_key_str}, - make_pair(string("mixin_outputs"), mstch::array{}) + {"mixin_pub_key" , out_pub_key_str}, + {"mixin_outputs" , mstch::array{}}, + {"has_mixin_outputs", false} }); mstch::array& mixin_outputs = boost::get( boost::get(mixins.back())["mixin_outputs"] ); - // for each output transaction, check if its ours + mstch::node& has_mixin_outputs + = boost::get(mixins.back())["has_mixin_outputs"]; + + + bool found_something {false}; + + + // for each mixin output transaction, check if its ours // as before for (string tx_hash_str: found_tx_hashes) { - crypto::hash tx_hash; hex_to_pod(tx_hash_str, tx_hash); @@ -1422,17 +1432,17 @@ public: } - public_key tx_pub_key + public_key mixin_tx_pub_key = xmreg::get_tx_pub_key_from_received_outs(mixin_tx); - // public transaction key is combined with our viewkey + // public transaction key is combined with our viewkey // to create, so called, derived key. key_derivation derivation; - if (!generate_key_derivation(tx_pub_key, prv_view_key, derivation)) + if (!generate_key_derivation(mixin_tx_pub_key, prv_view_key, derivation)) { cerr << "Cant get derived key for: " << "\n" - << "pub_tx_key: " << tx_pub_key << " and " + << "pub_tx_key: " << mixin_tx_pub_key << " and " << "prv_view_key" << prv_view_key << endl; continue; @@ -1444,14 +1454,17 @@ public: output_pub_keys = xmreg::get_ouputs_tuple(mixin_tx); mixin_outputs.push_back(mstch::map{ - {"mix_tx_hash" , tx_hash_str}, - make_pair(string("found_outputs"), mstch::array{}) + {"mix_tx_hash" , tx_hash_str}, + {"found_outputs" , mstch::array{}}, + {"has_found_outputs", false} }); mstch::array& found_outputs = boost::get( boost::get(mixin_outputs.back())["found_outputs"] ); + mstch::node& has_found_outputs + = boost::get(mixin_outputs.back())["has_found_outputs"]; // for each output in mixin tx, find the one from key_image // and check if its ours. @@ -1462,10 +1475,14 @@ public: uint64_t amount = std::get<1>(mix_out); uint64_t output_idx_in_tx = std::get<2>(mix_out); - //@todo fix this for loop - continue; + cout << " - " << pod_to_hex(txout_k.key) << endl; -// if (mix_out.first.key != output_data.pubkey) +// //@todo fix this for loop +// continue; + +// // analyze only those output keys +// // that were used in mixins +// if (txout_k.key != output_data.pubkey) // { // continue; // } @@ -1492,10 +1509,10 @@ public: bool r; r = decode_ringct(mixin_tx.rct_signatures, - txout_k.key, + mixin_tx_pub_key, prv_view_key, output_idx_in_tx, - mixin_tx.rct_signatures.ecdhInfo[output_idx].mask, + mixin_tx.rct_signatures.ecdhInfo[output_idx_in_tx].mask, rct_amount); if (!r) @@ -1524,20 +1541,27 @@ public: if (mine_output) { - - // cout << " - " << pod_to_hex(txout_k.key) // <<": " << mine_output << " amount: " // << xmreg::xmr_amount_to_str(amount) // << endl; + + found_something = true; + } } // for (const pair& mix_out: txd.output_pub_keys) + has_found_outputs = !found_outputs.empty(); + } // for (string tx_hash_str: found_tx_hashes) + has_mixin_outputs = found_something; + } // for (const cryptonote::output_data_t& output_data: mixin_outputs) + show_key_images = true; + } // for (const txin_to_key& in_key: input_key_imgs) @@ -1545,7 +1569,7 @@ public: context["sum_xmr"] = xmreg::xmr_amount_to_str(sum_xmr); context.emplace("inputs", inputs); - context["show_inputs"] = false; + context["show_inputs"] = show_key_images; // read my_outputs.html string my_outputs_html = xmreg::read(TMPL_MY_OUTPUTS); diff --git a/src/templates/my_outputs.html b/src/templates/my_outputs.html index 185599c..3325329 100644 --- a/src/templates/my_outputs.html +++ b/src/templates/my_outputs.html @@ -75,29 +75,32 @@ {{#inputs}}

Key image: {{key_image}}, amount {{key_image_amount}}

{{#mixins}} -
Mixin of pub key: {{mixin_pub_key}}
- {{#mixin_outputs}} -
- uses outputs from tx: - {{mix_tx_hash}} -
- {{#found_outputs}} + {{#has_mixin_outputs}} +
Mixin of pub key: {{mixin_pub_key}}
+ {{#mixin_outputs}} +
+ uses outputs from tx: + {{mix_tx_hash}} +
+ {{#has_found_outputs}} + {{#found_outputs}} -
- Output public key: {{my_public_key}}, - amount: {{amount}}, - is ours: - {{#mine_output}} - {{mine_output}} - {{/mine_output}} - {{^mine_output}} - {{mine_output}} - {{/mine_output}} -
- - {{/found_outputs}} - {{/mixin_outputs}} +
+ Output public key: {{my_public_key}}, + amount: {{amount}}, + is ours: + {{#mine_output}} + {{mine_output}} + {{/mine_output}} + {{^mine_output}} + {{mine_output}} + {{/mine_output}} +
+ {{/found_outputs}} + {{/has_found_outputs}} + {{/mixin_outputs}} + {{/has_mixin_outputs}} {{/mixins}} {{/inputs}} From 88e753bce816395d4621e24380e2988a8d78100a Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Wed, 18 Jan 2017 05:19:13 +0000 Subject: [PATCH 2/4] my_outputs.html modified --- src/templates/my_outputs.html | 54 ++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/src/templates/my_outputs.html b/src/templates/my_outputs.html index 3325329..fe70e86 100644 --- a/src/templates/my_outputs.html +++ b/src/templates/my_outputs.html @@ -76,29 +76,43 @@

Key image: {{key_image}}, amount {{key_image_amount}}

{{#mixins}} {{#has_mixin_outputs}} -
Mixin of pub key: {{mixin_pub_key}}
{{#mixin_outputs}} -
- uses outputs from tx: - {{mix_tx_hash}} -
+
+ + + + {{#has_found_outputs}} - {{#found_outputs}} - -
- Output public key: {{my_public_key}}, - amount: {{amount}}, - is ours: - {{#mine_output}} - {{mine_output}} - {{/mine_output}} - {{^mine_output}} - {{mine_output}} - {{/mine_output}} -
- - {{/found_outputs}} + {{/has_found_outputs}} +
+ Mixin {{mixin_pub_key}}
might use our outputs from tx: {{mix_tx_hash}} +
+
+ + + + + + + {{#found_outputs}} + + + + + + {{/found_outputs}} +
output public keyamountis ours?
{{my_public_key}}{{amount}} + {{#mine_output}} + {{mine_output}} + {{/mine_output}} + {{^mine_output}} + {{mine_output}} + {{/mine_output}} +
+
+
+
{{/mixin_outputs}} {{/has_mixin_outputs}} {{/mixins}} From 7a3046c200a5b0ca6eaedc0c7fcd179ed1d197f2 Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Wed, 18 Jan 2017 06:35:12 +0000 Subject: [PATCH 3/4] my_outputs.html modified --- src/page.h | 17 ++++++++--------- src/templates/my_outputs.html | 6 +++--- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/page.h b/src/page.h index 58aa8c2..02f704f 100644 --- a/src/page.h +++ b/src/page.h @@ -1387,7 +1387,7 @@ public: string out_pub_key_str = pod_to_hex(output_data.pubkey); - cout << "out_pub_key_str: " << out_pub_key_str << endl; + //cout << "out_pub_key_str: " << out_pub_key_str << endl; // this will be txs where the outputs come from vector found_tx_hashes; @@ -1401,7 +1401,7 @@ public: mixins.push_back(mstch::map{ {"mixin_pub_key" , out_pub_key_str}, {"mixin_outputs" , mstch::array{}}, - {"has_mixin_outputs", false} + {"has_mixin_outputs" , false} }); mstch::array& mixin_outputs = boost::get( @@ -1431,10 +1431,11 @@ public: continue; } - public_key mixin_tx_pub_key = xmreg::get_tx_pub_key_from_received_outs(mixin_tx); + string mixin_tx_pub_key_str = pod_to_hex(mixin_tx_pub_key); + // public transaction key is combined with our viewkey // to create, so called, derived key. key_derivation derivation; @@ -1455,6 +1456,7 @@ public: mixin_outputs.push_back(mstch::map{ {"mix_tx_hash" , tx_hash_str}, + {"mix_tx_pub_key" , mixin_tx_pub_key_str}, {"found_outputs" , mstch::array{}}, {"has_found_outputs", false} }); @@ -1475,10 +1477,7 @@ public: uint64_t amount = std::get<1>(mix_out); uint64_t output_idx_in_tx = std::get<2>(mix_out); - cout << " - " << pod_to_hex(txout_k.key) << endl; - -// //@todo fix this for loop -// continue; + //cout << " - " << pod_to_hex(txout_k.key) << endl; // // analyze only those output keys // // that were used in mixins @@ -1547,7 +1546,7 @@ public: // << endl; found_something = true; - + show_key_images = true; } } // for (const pair& mix_out: txd.output_pub_keys) @@ -1560,7 +1559,7 @@ public: } // for (const cryptonote::output_data_t& output_data: mixin_outputs) - show_key_images = true; + } // for (const txin_to_key& in_key: input_key_imgs) diff --git a/src/templates/my_outputs.html b/src/templates/my_outputs.html index fe70e86..0b8189a 100644 --- a/src/templates/my_outputs.html +++ b/src/templates/my_outputs.html @@ -68,8 +68,6 @@ {{#show_inputs}} -
-

Inputs

{{#inputs}} @@ -81,7 +79,9 @@ {{#has_found_outputs}} From 67f361f47c0d96f589b55da97c68a89d3c7d4b75 Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Wed, 18 Jan 2017 06:46:50 +0000 Subject: [PATCH 4/4] refactoring started --- src/page.h | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/src/page.h b/src/page.h index 02f704f..5dd7324 100644 --- a/src/page.h +++ b/src/page.h @@ -1381,22 +1381,53 @@ public: // to store our mixins found for the given key image vector> our_mixins_found; + // mixin counter + size_t count = 0; + // for each found output public key check if its ours or not - for (const cryptonote::output_data_t& output_data: mixin_outputs) + //for (const cryptonote::output_data_t& output_data: mixin_outputs) + for (const uint64_t& abs_offset: absolute_offsets) { + // get basic information about mixn's output + cryptonote::output_data_t output_data = mixin_outputs.at(count); + + tx_out_index tx_out_idx; + + try + { + // get pair pair where first is tx hash + // and second is local index of the output i in that tx + tx_out_idx = core_storage->get_db() + .get_output_tx_and_index(in_key.amount, abs_offset); + } + catch (const OUTPUT_DNE& e) + { + + string out_msg = fmt::format( + "Output with amount {:d} and index {:d} does not exist!", + in_key.amount, abs_offset + ); + + cerr << out_msg << endl; + + break; + } + string out_pub_key_str = pod_to_hex(output_data.pubkey); //cout << "out_pub_key_str: " << out_pub_key_str << endl; - // this will be txs where the outputs come from - vector found_tx_hashes; + // get mixin transaction + transaction mixin_tx; - mylmdb->search(out_pub_key_str, - found_tx_hashes, - "output_public_keys"); + if (!mcore->get_tx(tx_out_idx.first, mixin_tx)) + { + cerr << "Cant get tx: " << tx_out_idx.first << endl; + break; + } mixins.push_back(mstch::map{ {"mixin_pub_key" , out_pub_key_str},
- Mixin {{mixin_pub_key}}
might use our outputs from tx: {{mix_tx_hash}} + Mixin {{mixin_pub_key}} might use our outputs +
+ from tx of public key: {{mix_tx_pub_key}}