Skip to content

Commit 9ee1006

Browse files
committed
wallet2: fix derivation handling in check_tx_proof and is_out_to_acc
1 parent 243a442 commit 9ee1006

1 file changed

Lines changed: 18 additions & 9 deletions

File tree

src/wallet/wallet2.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12182,8 +12182,14 @@ bool wallet2::is_out_to_acc(const cryptonote::account_public_address &address, c
1218212182
crypto::public_key derived_out_key;
1218312183
bool found = false;
1218412184
bool r;
12185+
12186+
const auto is_null_derivation = [](const crypto::key_derivation &d) {
12187+
static const crypto::key_derivation null_derivation{};
12188+
return memcmp(&d, &null_derivation, sizeof(d)) == 0;
12189+
};
12190+
1218512191
// first run quick check if output has matching view tag, otherwise output should not belong to account
12186-
if (out_can_be_to_acc(view_tag_opt, derivation, output_index))
12192+
if (!is_null_derivation(derivation) && out_can_be_to_acc(view_tag_opt, derivation, output_index))
1218712193
{
1218812194
// if view tag match, run slower check deriving output pub key and comparing to expected
1218912195
r = crypto::derive_public_key(derivation, output_index, address.m_spend_public_key, derived_out_key);
@@ -12195,17 +12201,20 @@ bool wallet2::is_out_to_acc(const cryptonote::account_public_address &address, c
1219512201
}
1219612202
}
1219712203

12198-
if (!found && !additional_derivations.empty())
12204+
if (!found && output_index < additional_derivations.size())
1219912205
{
1220012206
const crypto::key_derivation &additional_derivation = additional_derivations[output_index];
12201-
if (out_can_be_to_acc(view_tag_opt, additional_derivation, output_index))
12207+
if (!is_null_derivation(additional_derivation))
1220212208
{
12203-
r = crypto::derive_public_key(additional_derivation, output_index, address.m_spend_public_key, derived_out_key);
12204-
THROW_WALLET_EXCEPTION_IF(!r, error::wallet_internal_error, "Failed to derive public key");
12205-
if (out_key == derived_out_key)
12209+
if (out_can_be_to_acc(view_tag_opt, additional_derivation, output_index))
1220612210
{
12207-
found = true;
12208-
found_derivation = additional_derivation;
12211+
r = crypto::derive_public_key(additional_derivation, output_index, address.m_spend_public_key, derived_out_key);
12212+
THROW_WALLET_EXCEPTION_IF(!r, error::wallet_internal_error, "Failed to derive public key");
12213+
if (out_key == derived_out_key)
12214+
{
12215+
found = true;
12216+
found_derivation = additional_derivation;
12217+
}
1220912218
}
1221012219
}
1221112220
}
@@ -12482,7 +12491,7 @@ bool wallet2::check_tx_proof(const cryptonote::transaction &tx, const cryptonote
1248212491
if (std::any_of(good_signature.begin(), good_signature.end(), [](int i) { return i > 0; }))
1248312492
{
1248412493
// obtain key derivation by multiplying scalar 1 to the shared secret
12485-
crypto::key_derivation derivation;
12494+
crypto::key_derivation derivation{};
1248612495
if (good_signature[0])
1248712496
THROW_WALLET_EXCEPTION_IF(!crypto::generate_key_derivation(shared_secret[0], rct::rct2sk(rct::I), derivation), error::wallet_internal_error, "Failed to generate key derivation");
1248812497

0 commit comments

Comments
 (0)