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

Don't cut bytes from non-address topics + account for empty topics #108

Merged
merged 1 commit into from
Oct 25, 2024

Conversation

catalyst17
Copy link
Contributor

@catalyst17 catalyst17 commented Oct 18, 2024

TL;DR

Improved handling of topic values in the getTopicValueFormat function.

What changed?

  • Modified the getTopicValueFormat function to handle empty topic strings.
  • Updated the logic for processing non-empty topics:
    • Now uses ethereum.FromHex to convert the topic to bytes
      • ⚠️ prev. used ethereum.HexToAddress was wrong in this context cause topics are not necessarily addresses)
    • Ensures the byte slice is exactly 32 bytes by left-padding with zeros.
    • Converts the padded bytes to a hash and returns the hexadecimal representation.

How to test?

  1. Test the function with an empty string input to ensure it returns an empty string.
  2. Test with various non-empty topic strings, including:
    • Short strings (less than 32 bytes)
    • Exactly 32-byte strings
    • Strings longer than 32 bytes
  3. Verify that the output is always a 32-byte hexadecimal string (or empty for empty input).

Why make this change?

This change improves the robustness of topic value handling:

  • It correctly handles empty topics, which are stored as empty strings by the indexer.
  • It ensures consistent 32-byte padding for all non-empty topics, regardless of their original length.
  • This approach aligns better with Ethereum's topic encoding standards, potentially fixing issues related to topic matching or filtering.

@catalyst17 catalyst17 changed the title fix: don't cut bytes from non-address topics + account for empty topics Don't cut bytes from non-address topics + account for empty topics Oct 18, 2024
Copy link
Contributor Author

catalyst17 commented Oct 18, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @catalyst17 and the rest of your teammates on Graphite Graphite

@catalyst17 catalyst17 marked this pull request as ready for review October 18, 2024 14:34
@catalyst17 catalyst17 force-pushed the arsenii/fix-topic-value-format branch from 6912e8c to bd55ca1 Compare October 18, 2024 14:37
@catalyst17 catalyst17 force-pushed the arsenii/fix-topic-value-format branch from bd55ca1 to a55695d Compare October 24, 2024 13:52
@catalyst17 catalyst17 requested review from iuwqyir and removed request for iuwqyir October 25, 2024 15:01
Copy link
Contributor Author

catalyst17 commented Oct 25, 2024

Merge activity

  • Oct 25, 11:01 AM EDT: A user started a stack merge that includes this pull request via Graphite.
  • Oct 25, 11:02 AM EDT: A user merged this pull request with Graphite.

@catalyst17 catalyst17 merged commit 2f29801 into main Oct 25, 2024
5 checks passed
@catalyst17 catalyst17 deleted the arsenii/fix-topic-value-format branch October 25, 2024 15:02
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