From 7fa35db3ac65c566eaf39b0cd41953dc9219f36a Mon Sep 17 00:00:00 2001 From: j-berman Date: Tue, 12 Jul 2022 07:12:40 -0700 Subject: [PATCH 1/2] view tags & bp+ (hf v15) --- src/UniversalIdentifier.cpp | 115 +++++++++++++++++++++++------------- 1 file changed, 74 insertions(+), 41 deletions(-) diff --git a/src/UniversalIdentifier.cpp b/src/UniversalIdentifier.cpp index aee3d1e..7ed4ab5 100644 --- a/src/UniversalIdentifier.cpp +++ b/src/UniversalIdentifier.cpp @@ -119,13 +119,10 @@ Output::identify(transaction const& tx, { // i will act as output indxes in the tx - if (tx.vout[i].target.type() != typeid(txout_to_key)) + public_key out_pub_key; + if (!cryptonote::get_output_public_key(tx.vout[i], out_pub_key)) continue; - // get tx input key - txout_to_key const& txout_key - = boost::get(tx.vout[i].target); - uint64_t amount = tx.vout[i].amount; // calculate public spendkey using derivation @@ -145,9 +142,30 @@ Output::identify(transaction const& tx, // outputs std::unique_ptr subaddr_idx; - hwdev.derive_subaddress_public_key( - txout_key.key, derivation, i, - subaddress_spendkey); + boost::optional out_vt; + out_vt = cryptonote::get_output_view_tag(tx.vout[i]); + + // since view tags were added, we check the + // output's view tag against the derived view tag. + // If they match, we continue with deriving + // the subaddress spend key and checking if it + // matches one of ours. If no view tag match, + // we know the output isn't ours and can skip + // the expensive subaddress spend key derivation. + bool output_can_be_mine = true; + if (out_vt) + { + crypto::view_tag vt; + crypto::derive_view_tag(derivation, i, vt); + output_can_be_mine = *out_vt == vt; + } + + if (output_can_be_mine) + { + hwdev.derive_subaddress_public_key( + out_pub_key, derivation, i, + subaddress_spendkey); + } // this derivation is going to be saved // it can be one of addiitnal derivations @@ -157,48 +175,62 @@ Output::identify(transaction const& tx, bool mine_output {false}; - if (!pacc) + if (output_can_be_mine) { - // if pacc is not given, we check generated - // subaddress_spendkey against the spendkey - // of the address for which the Output identifier - // was instantiated - mine_output = (pub_spend_key == subaddress_spendkey); - } - else - { - // if pacc is given, we are going to use its - // subaddress unordered map to check if generated - // subaddress_spendkey is one of its keys. this is - // because the map can contain spendkeys of subaddreses - // assiciated with primary address. primary address's - // spendkey will be one of the keys as a special case - - subaddr_idx = pacc->has_subaddress(subaddress_spendkey); - - mine_output = bool {subaddr_idx}; + if (!pacc) + { + // if pacc is not given, we check generated + // subaddress_spendkey against the spendkey + // of the address for which the Output identifier + // was instantiated + mine_output = (pub_spend_key == subaddress_spendkey); + } + else + { + // if pacc is given, we are going to use its + // subaddress unordered map to check if generated + // subaddress_spendkey is one of its keys. this is + // because the map can contain spendkeys of subaddreses + // assiciated with primary address. primary address's + // spendkey will be one of the keys as a special case + + subaddr_idx = pacc->has_subaddress(subaddress_spendkey); + + mine_output = bool {subaddr_idx}; + } } auto with_additional = false; if (!mine_output && !additional_tx_pub_keys.empty()) { - // check for output using additional tx public keys - hwdev.derive_subaddress_public_key( - txout_key.key, additional_derivations[i], - i, - subaddress_spendkey); - - // do same comparison as above depending of the - // avaliabity of the PrimaryAddress Account - if (!pacc) + if (out_vt) { - mine_output = (pub_spend_key == subaddress_spendkey); + // check view tag using additional tx public keys + crypto::view_tag vt; + crypto::derive_view_tag(additional_derivations[i], i, vt); + output_can_be_mine = *out_vt == vt; } - else + + if (output_can_be_mine) { - subaddr_idx = pacc->has_subaddress(subaddress_spendkey); - mine_output = bool {subaddr_idx}; + // check for output using additional tx public keys + hwdev.derive_subaddress_public_key( + out_pub_key, additional_derivations[i], + i, + subaddress_spendkey); + + // do same comparison as above depending of the + // avaliabity of the PrimaryAddress Account + if (!pacc) + { + mine_output = (pub_spend_key == subaddress_spendkey); + } + else + { + subaddr_idx = pacc->has_subaddress(subaddress_spendkey); + mine_output = bool {subaddr_idx}; + } } with_additional = true; @@ -268,7 +300,7 @@ Output::identify(transaction const& tx, identified_outputs.emplace_back( info{ - txout_key.key, amount, i, + out_pub_key, amount, i, derivation_to_save, rtc_outpk, rtc_mask, rtc_amount, subaddress_spendkey @@ -329,6 +361,7 @@ Output::decode_ringct(rct::rctSig const& rv, case rct::RCTTypeBulletproof: case rct::RCTTypeBulletproof2: case rct::RCTTypeCLSAG: + case rct::RCTTypeBulletproofPlus: amount = rct::decodeRctSimple(rv, rct::sk2rct(scalar1), i, From b5252e1c50c4de508d7345fa25fab5fdfd382c58 Mon Sep 17 00:00:00 2001 From: j-berman Date: Tue, 12 Jul 2022 15:13:00 -0700 Subject: [PATCH 2/2] Use hepler view tag checker --- src/UniversalIdentifier.cpp | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/src/UniversalIdentifier.cpp b/src/UniversalIdentifier.cpp index 7ed4ab5..5e55920 100644 --- a/src/UniversalIdentifier.cpp +++ b/src/UniversalIdentifier.cpp @@ -142,8 +142,8 @@ Output::identify(transaction const& tx, // outputs std::unique_ptr subaddr_idx; - boost::optional out_vt; - out_vt = cryptonote::get_output_view_tag(tx.vout[i]); + boost::optional vt; + vt = cryptonote::get_output_view_tag(tx.vout[i]); // since view tags were added, we check the // output's view tag against the derived view tag. @@ -152,15 +152,10 @@ Output::identify(transaction const& tx, // matches one of ours. If no view tag match, // we know the output isn't ours and can skip // the expensive subaddress spend key derivation. - bool output_can_be_mine = true; - if (out_vt) - { - crypto::view_tag vt; - crypto::derive_view_tag(derivation, i, vt); - output_can_be_mine = *out_vt == vt; - } + bool out_can_be_mine = cryptonote::out_can_be_to_acc( + vt, derivation, i); - if (output_can_be_mine) + if (out_can_be_mine) { hwdev.derive_subaddress_public_key( out_pub_key, derivation, i, @@ -175,7 +170,7 @@ Output::identify(transaction const& tx, bool mine_output {false}; - if (output_can_be_mine) + if (out_can_be_mine) { if (!pacc) { @@ -204,15 +199,11 @@ Output::identify(transaction const& tx, if (!mine_output && !additional_tx_pub_keys.empty()) { - if (out_vt) - { - // check view tag using additional tx public keys - crypto::view_tag vt; - crypto::derive_view_tag(additional_derivations[i], i, vt); - output_can_be_mine = *out_vt == vt; - } + // check view tag using additional tx public keys + out_can_be_mine = cryptonote::out_can_be_to_acc( + vt, additional_derivations[i], i); - if (output_can_be_mine) + if (out_can_be_mine) { // check for output using additional tx public keys hwdev.derive_subaddress_public_key(