Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Identify non-standard received legacy enotes #43

Merged
merged 3 commits into from
May 22, 2024

Conversation

SNeedlewoods
Copy link

This should address the issue #27

LegacyContextualBasicEnoteRecordV1 temp_contextual_record{};
bool found_an_enote{false};

for (std::size_t enote_index{0}; enote_index < legacy_additional_enote_ephemeral_pubkeys.size(); ++enote_index)
for (std::size_t enote_index{0}; legacy_additional_enote_ephemeral_pubkeys.size() > 0 &&
Copy link

@j-berman j-berman Apr 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (std::size_t enote_index{0}; legacy_additional_enote_ephemeral_pubkeys.size() > 0 &&
for (std::size_t enote_index{0}; enote_index < legacy_additional_enote_ephemeral_pubkeys.size() && enote_index < enotes_in_tx.size(); ++enote_index)

Otherwise it's UB it can segfault if legacy_additional_enote_ephemeral_pubkeys.size() > 0 && legacy_additional_enote_ephemeral_pubkeys.size() < enotes_in_tx.size()

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oopsie,
thanks for the review :)

// 4. check if there is a main enote ephemeral pubkey
if (legacy_main_enote_ephemeral_pubkey == rct::rct2pk(rct::I))
// 3. check if there is a main enote ephemeral pubkey
if (legacy_main_enote_ephemeral_pubkeys.front() == rct::rct2pk(rct::I))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like another mismatch to wallet2. wallet2 skips processing the transaction's enotes entirely if there is no main enote ephemeral pub key:

https://github.com/monero-project/monero/blob/ac02af92867590ca80b2779a7bbeafa99ff94dcb/src/wallet/wallet2.cpp#L2285-L2294

Can be handled in a follow-up PR, but I would suggest extract_legacy_enote_ephemeral_pubkeys_from_tx_extra can just return false if there is no main enote ephemeral pub key (don't even add rct::I), and try_find_legacy_enotes_in_tx can also return false immediately in that case too (and not process additional tx pub keys).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be clear, this comment is totally unrelated to this PR and this looks like a distinct issue already present :)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is necessary to replicate this particular quirk of wallet2's spaghetti, since it is strictly a 'feature reduction'.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya I was debating this. Fine with me to keep it

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Biggest issue I can think of is you could theoretically send dust to someone who confirms / denies receipt in order to see if they're running a Seraphis lib wallet versus wallet2

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Biggest issue I can think of is you could theoretically send dust to someone who confirms / denies receipt in order to see if they're running a Seraphis lib wallet versus wallet2

Don't think this is significant enough to warrant a change.

tests/unit_tests/seraphis_enote_scanning.cpp Outdated Show resolved Hide resolved
tests/unit_tests/seraphis_enote_scanning.cpp Outdated Show resolved Hide resolved
tests/unit_tests/seraphis_enote_scanning.cpp Outdated Show resolved Hide resolved
tests/unit_tests/seraphis_enote_scanning.cpp Outdated Show resolved Hide resolved
Copy link

@j-berman j-berman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to squash, thanks :)

@j-berman j-berman mentioned this pull request Apr 19, 2024
// 4. check if there is a main enote ephemeral pubkey
if (legacy_main_enote_ephemeral_pubkey == rct::rct2pk(rct::I))
// 3. check if there is a main enote ephemeral pubkey
if (legacy_main_enote_ephemeral_pubkeys.front() == rct::rct2pk(rct::I))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is necessary to replicate this particular quirk of wallet2's spaghetti, since it is strictly a 'feature reduction'.

Comment on lines 382 to 384
// - this step is automatically skipped if legacy_additional_enote_ephemeral_pubkeys.size() == 0
crypto::key_derivation temp_DH_derivation;
std::vector<crypto::key_derivation> temp_DH_derivations;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// - this step is automatically skipped if legacy_additional_enote_ephemeral_pubkeys.size() == 0
crypto::key_derivation temp_DH_derivation;
std::vector<crypto::key_derivation> temp_DH_derivations;
// - this step is automatically skipped if legacy_additional_enote_ephemeral_pubkeys.size() == 0
crypto::key_derivation temp_DH_derivation;
std::vector<crypto::key_derivation> temp_DH_derivations{};
temp_DH_derivations.reserve(legacy_main_enote_ephemeral_pubkeys.size());

Also, move temp_DH_derivations closer to where it will be used so this allocation is below the early-return.

Copy link
Owner

@UkoeHB UkoeHB May 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd honestly go even further and make a variant<rct::key, vec<rct::key>> for this and legacy_main_enote_ephemeral_pubkeys since most of the time there will only be one normal pubkey, and this function is right on the hot path.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to implement this suggestion, but I'm not sure about it.
E.g. the castings between crypto::key_derivation<->rct::key<->crypto::public_key seem messy.
Also I initialize the variant legacy_main_enote_ephemeral_pubkey to rct::key, but then in extract_legacy_enote_ephemeral_pubkeys_from_tx_extra() I set it to rct::keyV, because this way the function needs less changes, but not sure if that defeats the whole purpose of introducing the new variant.

src/seraphis_core/legacy_core_utils.cpp Outdated Show resolved Hide resolved
src/seraphis_main/scan_balance_recovery_utils.cpp Outdated Show resolved Hide resolved
src/seraphis_main/scan_balance_recovery_utils.cpp Outdated Show resolved Hide resolved
src/seraphis_main/scan_balance_recovery_utils.cpp Outdated Show resolved Hide resolved
@UkoeHB UkoeHB merged commit 111fe51 into UkoeHB:seraphis_lib May 22, 2024
UkoeHB pushed a commit that referenced this pull request Aug 2, 2024
---------

Co-authored-by: SNeedlewoods <sneedlewoods_1@protonmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants