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

fix(crypt): Avoid expensive note commitment tree root recalculations in eq() methods #7386

Merged
merged 2 commits into from
Aug 26, 2023

Conversation

teor2345
Copy link
Collaborator

Motivation

Re-calculating note commitment tree roots can take a long time if the root isn't cached in the state, or already calculated by Zebra.

Instead, it is cheaper to compare the tree frontier, which is at most 32 roots. (Less than 1 kB of byte comparisons.)

Specifications

https://docs.rs/incrementalmerkletree/0.4.0/incrementalmerkletree/frontier/struct.NonEmptyFrontier.html#impl-PartialEq%3CNonEmptyFrontier%3CH%3E%3E-for-NonEmptyFrontier%3CH%3E

Complex Code or Requirements

This fix helps avoid weird performance bugs in the next few state upgrades. We've already seen some performance issues in this code.

Solution

If both roots are cached, compare them. Otherwise, compare the whole frontier.

Review

This might be needed to get some tests for PR #7379 to pass.

Reviewer Checklist

  • Will the PR name make sense to users?
    • Does it need extra CHANGELOG info? (new features, breaking changes, large changes)
  • Are the PR labels correct?
  • Does the code do what the ticket and PR says?
    • Does it change concurrent code, unsafe code, or consensus rules?
  • How do you know it works? Does it have tests?

@teor2345 teor2345 added C-bug Category: This is a bug P-Medium ⚡ I-slow Problems with performance or responsiveness A-cryptography Area: Cryptography related labels Aug 25, 2023
@teor2345 teor2345 requested a review from a team as a code owner August 25, 2023 02:42
@teor2345 teor2345 self-assigned this Aug 25, 2023
@teor2345 teor2345 requested review from upbqdn and removed request for a team August 25, 2023 02:42
@upbqdn upbqdn linked an issue Aug 25, 2023 that may be closed by this pull request
@upbqdn
Copy link
Member

upbqdn commented Aug 25, 2023

@Mergifyio update.

@mergify
Copy link
Contributor

mergify bot commented Aug 25, 2023

update .

✅ Branch has been successfully updated

@mergify mergify bot merged commit 67e3c26 into main Aug 26, 2023
289 checks passed
@mergify mergify bot deleted the faster-tree-eq branch August 26, 2023 01:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cryptography Area: Cryptography related C-bug Category: This is a bug I-slow Problems with performance or responsiveness
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compare note commitment trees by their frontiers if no root is present
2 participants