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(evm)!: correct EIP55 addr encoding #2187

Merged
merged 3 commits into from
Jan 31, 2025
Merged

Conversation

k-yang
Copy link
Member

@k-yang k-yang commented Jan 30, 2025

Purpose / Abstract

At some point between RC14 and RC19, EIP55 address encoding changed and broke state reads. This PR fixes the proto and JSON marshaling functions.

I tested the PR by first spinning up a localnet with RC14, creating and converting some funtokens, then hot swapping to the binary on this branch. Funtoken conversions continued to succeed, whereas with RC19 they would've failed.

Note: it may break downstream ts-sdk clients, which will unfortunately have to be fixed in TypeScript. Looking at https://github.com/cosmos/gogoproto/blob/v1.5.0/custom_types.md, we follow Alternative 2) which "makes it harder to generate protobuf code in other languages". We are simply experiencing the downstream effects of decisions we made for our protobufs earlier on.

Related PRs:

Copy link
Contributor

coderabbitai bot commented Jan 30, 2025

📝 Walkthrough

Walkthrough

This pull request focuses on improving EIP-55 address encoding in the Nibiru project. The changes primarily involve modifications to the eth/eip55.go file, updating serialization and deserialization methods for Ethereum addresses. The implementation now uses byte representations directly, eliminating unnecessary string conversions. Corresponding test cases in eth/eip55_test.go have been updated to reflect these changes, including renaming functions and adding new test cases to verify the new implementation.

Changes

File Change Summary
CHANGELOG.md Added entry for fix in EIP-55 address encoding (PR #2187)
eth/eip55.go - Updated Marshal() to return byte representation directly
- Modified MarshalTo() to use byte copying
- Simplified Unmarshal() method
- Streamlined UnmarshalJSON() error handling
- Changed Size() method to return byte length
eth/eip55_test.go - Renamed MustNewEIP55AddrFromStr() to mustNewEIP55AddrFromStr
- Renamed TestProtobufEncoding() to TestJsonEncoding()
- Added TestSize() method
- Renamed TestIsEIP55Address() to TestHexAddress()

Possibly related PRs

Suggested labels

x: evm

Poem

🐰 Hop, hop, through the EIP-55 lane,
Addresses dancing, no longer in pain!
Bytes leap and bound with precision so neat,
Encoding magic now complete and sweet 🌟
A rabbit's fix makes blockchain bright! 🚀


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5d1f87b and b7622ba.

📒 Files selected for processing (3)
  • CHANGELOG.md (1 hunks)
  • eth/eip55.go (4 hunks)
  • eth/eip55_test.go (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: integration-tests
🔇 Additional comments (9)
eth/eip55.go (5)

39-39: Efficient byte representation for Marshal.

The change to use h.Bytes() directly is more efficient as it avoids unnecessary string conversions while maintaining EIP-55 compliance.


54-55: Consistent byte handling in MarshalTo.

The implementation correctly uses byte operations for copying data, maintaining consistency with the Marshal function and improving efficiency.


61-62: Simplified and robust Unmarshal implementation.

Direct conversion from bytes to address using gethcommon.BytesToAddress is more efficient and reduces potential parsing errors.


71-71: Simplified error handling in UnmarshalJSON.

Direct error return improves error handling clarity while preserving the original error information.


84-84: Accurate size calculation using byte length.

Using len(h.Bytes()) provides the correct size for protocol buffer serialization, consistent with the byte-based approach.

eth/eip55_test.go (3)

107-136: Well-structured JSON encoding tests.

The JSON encoding tests properly verify the marshaling and unmarshaling of EIP55 addresses with good test coverage and clear assertions.


138-167: Comprehensive Protobuf encoding tests.

The Protobuf encoding tests verify the byte-level operations with appropriate test cases and expected binary representations.


169-191: Added Size method verification.

New test cases properly verify that EIP55 addresses consistently return the correct size of 20 bytes.

CHANGELOG.md (1)

96-97: Clear and well-placed changelog entry.

The changelog entry properly documents the EIP55 address encoding fix with the correct PR reference.

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@k-yang k-yang marked this pull request as ready for review January 30, 2025 18:34
@k-yang k-yang requested a review from a team as a code owner January 30, 2025 18:34
Copy link

codecov bot commented Jan 30, 2025

Codecov Report

Attention: Patch coverage is 66.66667% with 2 lines in your changes missing coverage. Please review.

Project coverage is 65.01%. Comparing base (5d1f87b) to head (b7622ba).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
eth/eip55.go 66.66% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2187      +/-   ##
==========================================
+ Coverage   64.99%   65.01%   +0.01%     
==========================================
  Files         277      277              
  Lines       22346    22341       -5     
==========================================
  Hits        14524    14524              
+ Misses       6832     6828       -4     
+ Partials      990      989       -1     
Files with missing lines Coverage Δ
eth/eip55.go 75.00% <66.66%> (+9.14%) ⬆️

@k-yang k-yang requested review from CalicoNino, onikonychev and Unique-Divine and removed request for a team January 30, 2025 19:53
@k-yang k-yang self-assigned this Jan 30, 2025
@k-yang k-yang added P: Urgent / High prio x: evm Relates to Nibiru EVM or the EVM Module labels Jan 30, 2025
@k-yang k-yang merged commit fda9778 into main Jan 31, 2025
23 checks passed
@k-yang k-yang deleted the fix/eth/eip55-addr-marshalling branch January 31, 2025 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P: Urgent / High prio x: evm Relates to Nibiru EVM or the EVM Module
Projects
Status: ✅ Completed
Development

Successfully merging this pull request may close these issues.

bug(evm testnet): funtokens created before r19 need state migration (EIP55)
2 participants