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

refactor(solidity): rename token to tokenName #784

Merged
merged 1 commit into from
Oct 28, 2024
Merged

Conversation

zakir-code
Copy link
Contributor

@zakir-code zakir-code commented Oct 25, 2024

Summary by CodeRabbit

  • New Features

    • Updated contract to use tokenName instead of token, enhancing clarity in token representation.
    • Improved handling of token names across various functions and structures.
  • Bug Fixes

    • Renamed error types for better accuracy in error handling related to token names.
  • Documentation

    • Adjusted test suite to reflect new token name handling, ensuring consistency and clarity in tests.

Copy link

coderabbitai bot commented Oct 25, 2024

Walkthrough

The pull request includes significant modifications across several Solidity files related to the IBridgeFeeQuote contract and its associated components. Key changes involve renaming the Token field to TokenName in various structs and updating method signatures to reflect this new naming convention. The ABI metadata has also been adjusted accordingly. Additionally, the BridgeFeeQuote contract has seen changes in error types and the transition from using address arrays to string arrays for token representations. These updates enhance clarity and consistency in the contract's interface and functionality.

Changes

File Path Change Summary
contract/ibridge_fee_quote.sol.go Renamed Token to TokenName in IBridgeFeeQuoteQuoteInfo and IBridgeFeeQuoteQuoteInput structs. Updated ABI and method signatures to reflect the new parameter name.
solidity/contracts/bridge/BridgeFeeQuote.sol Renamed error types from TokenInvalid to TokenNameInvalid and TokenAlreadyExists to TokenNameAlreadyExists. Changed address[] tokens to string[] tokenNames in Asset struct and updated related function signatures.
solidity/contracts/bridge/IBridgeFee.sol Renamed token to tokenName in QuoteInput and QuoteInfo structs. Updated function signatures to accept string memory _tokenName instead of address _token.
solidity/test/bridge_fee_quote.ts Removed AddressLike type, changed token1 and token2 from any to string, and updated function signatures to use tokenName instead of token.

Possibly related PRs

🐰 In the meadow where tokens play,
A name change brightens up the day.
From Token to TokenName, we cheer,
Clarity blossoms, the path is clear!
With quotes and fees all in line,
Hoppy coding, how divine! 🌼✨


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 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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (3)
solidity/contracts/bridge/IBridgeFee.sol (1)

37-37: Consider renaming functions for consistency.

While the parameter changes from _token to _tokenName are good, the function name getQuoteByToken still uses the old terminology. For complete consistency, consider renaming it to getQuoteByTokenName.

Here's the suggested change:

-    function getQuoteByToken(
+    function getQuoteByTokenName(
         string memory _chainName,
         string memory _tokenName
     ) external view returns (QuoteInfo[] memory quotes);

Also applies to: 42-42

solidity/test/bridge_fee_quote.ts (1)

176-180: Consider using more realistic token names in tests.

While the current implementation works, using more realistic token names (e.g., "USDT", "DAI", "WETH") would make the tests more representative of real-world scenarios.

-        tokens.push("test" + i.toString());
+        tokens.push(["USDT", "DAI", "WETH", "USDC", "WBTC"][i]);
contract/ibridge_fee_quote.sol.go (1)

Line range hint 1-2: Reminder: This is a generated file.

As indicated by the header comment, this is an auto-generated binding file. Any changes should be made to the source Solidity contract instead of this file.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between b4ac384 and 12614a4.

📒 Files selected for processing (4)
  • contract/ibridge_fee_quote.sol.go (8 hunks)
  • solidity/contracts/bridge/BridgeFeeQuote.sol (17 hunks)
  • solidity/contracts/bridge/IBridgeFee.sol (3 hunks)
  • solidity/test/bridge_fee_quote.ts (16 hunks)
🔇 Additional comments (11)
solidity/contracts/bridge/IBridgeFee.sol (2)

20-20: LGTM! Consistent with QuoteInput changes.

The change maintains consistency with the QuoteInput struct, ensuring a uniform approach to token representation across the interface.


8-8: Verify the migration plan for the breaking change.

The change from address token to string tokenName in QuoteInput is a good improvement for cross-chain compatibility and readability. However, this is a breaking change that requires careful migration.

Let's verify the impact on existing implementations:

✅ Verification successful

Breaking change is properly handled across the codebase

The verification shows that the migration from token to tokenName is consistently implemented:

  • The BridgeFeeQuote.sol implementation properly handles the QuoteInput struct with the new tokenName field in its functions (quote, verifyInput, verifySignature)
  • The test file bridge_fee_quote.ts has been updated to use the new tokenName field in all test cases and helper functions
  • No other conflicting struct definitions with token field were found that would need similar changes
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all contract implementations and tests that might be affected
# by the QuoteInput struct change

# Search for QuoteInput usage in contracts and tests
rg -l "QuoteInput" --type solidity --type typescript

Length of output: 85


Script:

#!/bin/bash
# Let's try a more generic search without file type restrictions
# to find all files containing QuoteInput
rg -l "QuoteInput"

# Also search for potential implementations of IBridgeFee
rg -l "IBridgeFee"

Length of output: 411


Script:

#!/bin/bash
# Let's examine the implementation and test files to see how they handle the change
# Check BridgeFeeQuote implementation
rg "QuoteInput" solidity/contracts/bridge/BridgeFeeQuote.sol -B 2 -A 2

# Check the test file
rg "QuoteInput" solidity/test/bridge_fee_quote.ts -B 2 -A 2

# Check if there are any other struct definitions that might need similar changes
rg "struct.*token" solidity/contracts/ -A 3

Length of output: 1570

solidity/test/bridge_fee_quote.ts (3)

21-22: LGTM: Variable declarations and setup changes are consistent.

The changes correctly implement the transition from address-like types to string representations for tokens, with appropriate test values and consistent method naming.

Also applies to: 29-30, 59-59


Line range hint 1-329: Overall changes look good and maintain test coverage.

The modifications consistently implement the transition from address-based tokens to string-based token names across all test cases and helper functions, maintaining comprehensive test coverage for the contract's functionality.


277-278: Verify signature compatibility with contract.

The signature generation has been updated to use string token names. Please ensure this matches the contract's signature verification logic.

✅ Verification successful

Let me analyze the contract's signature verification logic by searching for the relevant code.


Let me try a different search pattern to find the signature verification logic.


Based on the code found, I can now verify the signature compatibility. The contract's signature verification logic matches the test implementation:

  1. The test generates a signature using generateSignature() with parameters: [chainName, tokenName, fee, gasLimit, expiry]
  2. The contract verifies using verifySignature() which:
    • Creates the same message hash using makeMessageHash() with identical parameters in the same order
    • Uses standard Ethereum signature recovery with toEthSignedMessageHash().recover()
    • Verifies the recovered signer matches the oracle address

The signature generation and verification are compatible since:

  • Both use the same parameters in the same order
  • Both use standard Ethereum personal message signing/recovery
  • The contract's makeMessageHash() uses abi.encode() which matches the test's encoding

No changes needed - signature generation and verification are properly aligned.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify signature verification logic in contract matches test implementation

# Test: Search for signature verification in contract
ast-grep --pattern 'function verify$$$($$$) {
  $$$
  keccak256($$$)
  $$$
}'

# Test: Search for any other signature-related functions
rg -A 5 'signature|verify|hash'

Length of output: 494517


Script:

#!/bin/bash
# Search for signature verification in BridgeFeeQuote contract
ast-grep --pattern 'function verifySignature($$$) {
  $$$
}'

# Search for makeMessageHash function that creates the hash for signature verification
ast-grep --pattern 'function makeMessageHash($$$) {
  $$$
}'

Length of output: 125


Script:

#!/bin/bash
# Search for signature verification in BridgeFeeQuote contract
rg -A 10 "verifySignature" solidity/contracts/bridge/

# Search for makeMessageHash function
rg -A 10 "makeMessageHash" solidity/contracts/bridge/

Length of output: 3484

solidity/contracts/bridge/BridgeFeeQuote.sol (3)

11-11: LGTM: Import and error definition changes are consistent with the refactor.

The addition of StringsUpgradeable and the renaming of errors from Token* to TokenName* maintain consistency with the token to tokenName refactoring.

Also applies to: 15-15, 22-22


325-327: Verify hash collision resistance.

The makeMessageHash function uses abi.encode which is safe against collisions. However, since we're now using strings instead of addresses, we should document the expected format of _tokenName to prevent any potential issues with different string representations of the same token.

Add a comment documenting the expected format:

 function makeMessageHash(
     string memory _chainName,
     string memory _tokenName,
     uint256 _fee,
     uint256 _gasLimit,
     uint256 _expiry
 ) public pure returns (bytes32) {
+    // _tokenName should be uppercase, alphanumeric only (e.g., "USDC", "ETH")
     return keccak256(abi.encode(_chainName, _tokenName, _fee, _gasLimit, _expiry));
 }

36-37: Verify the implications of switching from address[] to string[] for token identification.

The change from address[] tokens to string[] tokenNames represents a significant architectural shift. While this makes the contract more flexible by decoupling it from specific chain addresses, it requires careful consideration:

  1. How will these token names be mapped to actual token addresses on different chains?
  2. Is there a standardized format for these token names to ensure consistency?
  3. What prevents name collisions across different chains?

Let's verify the token name usage across the codebase:

✅ Verification successful

Based on the search results, I can now provide a comprehensive response about the architectural change:

The change from address[] to string[] for token identification is well-structured and safe.

The codebase shows a robust implementation for handling token names:

  1. Token names are managed through a structured system:

    • Each chain has an Asset struct containing tokenNames
    • Token names must be registered via registerTokenName with proper validation
    • Duplicate names are prevented via TokenNameAlreadyExists error
    • Empty names are rejected via TokenNameInvalid error
  2. The token name to quote mapping is handled securely:

    • Quotes are uniquely identified by combining chainName + tokenName + oracle + index
    • Token names are validated before use via isActiveTokenName
    • The system maintains consistency through proper packing/unpacking of asset data
  3. The architecture supports cross-chain flexibility:

    • Token names are consistently used across quote generation and verification
    • The system properly handles token name validation across different chains
    • The design allows for chain-specific token mappings
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for token name standardization or mapping patterns
rg -g '*.sol' -A 5 'tokenName.*mapping'

Length of output: 41


Script:

#!/bin/bash
# Let's search for token name usage patterns more broadly
rg -g '*.sol' -B 2 -A 5 'tokenNames?' 

# Also search for any token to address mapping patterns
rg -g '*.sol' -B 2 -A 5 'mapping.*token'

# Look for functions that might handle token name to address conversion
ast-grep --pattern 'function $_($$$) {
  $$$
  tokenName
  $$$
}'

Length of output: 24974

contract/ibridge_fee_quote.sol.go (3)

57-57: LGTM! ABI changes are consistent.

The ABI has been correctly updated to reflect the parameter type changes from address _token to string _tokenName across all method signatures.


Line range hint 206-234: LGTM! Method signatures and documentation are properly updated.

The changes to method signatures and their documentation are consistent across all binding types (Caller, Session, CallerSession) and align with the new parameter types. The following methods have been correctly updated:

  • GetQuote
  • GetQuoteByToken
  • Quote

Also applies to: 268-296, 330-348


36-36: Verify the impact of struct field changes.

The change from Token common.Address to TokenName string is a breaking change that affects both IBridgeFeeQuoteQuoteInfo and IBridgeFeeQuoteQuoteInput structs. This will require updates in any code that constructs or consumes these structs.

Also applies to: 46-46

solidity/contracts/bridge/BridgeFeeQuote.sol Show resolved Hide resolved
solidity/contracts/bridge/BridgeFeeQuote.sol Show resolved Hide resolved
@zakir-code zakir-code merged commit d2ea753 into main Oct 28, 2024
10 checks passed
@zakir-code zakir-code deleted the todd/token-name branch October 28, 2024 02:10
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.

2 participants