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(precompile): migrate cross-chain logic to cosmos code #741

Merged
merged 1 commit into from
Oct 14, 2024

Conversation

zakir-code
Copy link
Contributor

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

Summary by CodeRabbit

  • New Features

    • Enhanced cross-chain functionality with support for multiple blockchain networks.
    • New methods for managing bridge calls and cross-chain transactions.
    • Added TotalSupply method for querying total ERC20 token supply.
  • Bug Fixes

    • Streamlined BridgeCoinByDenom method for improved efficiency.
  • Testing Enhancements

    • Updated test suite with a new mock keeper for EVM ERC20 interactions.
  • Deprecations

    • Deprecated CrossChainMethod struct in favor of BridgeCallMethod.

Copy link

coderabbitai bot commented Oct 14, 2024

Walkthrough

The changes in this pull request enhance cross-chain functionality and ERC20 token management across multiple files. Key modifications include updates to the AppKeepers structure, the addition of new methods in various keeper files, and improvements to the query server. The interfaces for Erc20Keeper, BankKeeper, and CrosschainKeeper have been significantly altered, with deprecated methods and new functionalities introduced. Additionally, testing capabilities have been expanded, and several outdated components have been removed to streamline the codebase.

Changes

File Path Change Summary
app/keepers/keepers.go Expanded AppKeepers structure; updated NewAppKeeper function; added GetSubspace method.
x/crosschain/keeper/* Added new methods for handling bridge calls and cross-chain transactions; updated BridgeCoinByDenom method.
x/crosschain/types/expected_keepers.go Modified Erc20Keeper interface; added new methods for IBC transfer relations.
x/crosschain/precompile/* Deprecated CrossChainMethod; added new methods in bridge_call.go and erc20.go.
x/crosschain/keeper/keeper_test.go Updated test suite with new mock keeper for EVM ERC20 keeper.
x/crosschain/types/key.go Removed GetBridgeCallFromMsgKey method.
x/evm/keeper/erc20.go Added TotalSupply method for querying ERC20 token supply.

Possibly related PRs

🐇 In the meadow, hops a bright hare,
With changes aplenty, there's joy in the air.
Bridge calls are stronger, and tokens now flow,
Cross-chain adventures, oh, what a show!
With keepers enhanced, let the transactions soar,
A leap into the future, we couldn't ask for more! 🌟


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: 20

🧹 Outside diff range and nitpick comments (17)
x/crosschain/precompile/router.go (1)

57-62: LGTM with suggestions: New method GetRouteWithIBC added correctly.

The new GetRouteWithIBC method enhances the router's functionality by handling IBC targets, which aligns with the PR objectives. However, consider the following improvements:

  1. Add a comment explaining the purpose and behavior of this method.
  2. Consider adding error handling for the case where ParseFxTarget might fail.

Here's a suggested implementation with comments and error handling:

// GetRouteWithIBC retrieves the CrosschainKeeper for a given target,
// handling IBC targets by mapping them to the eth module.
func (rtr *Router) GetRouteWithIBC(target string) (CrosschainKeeper, bool) {
	parsedTarget, err := fxtypes.ParseFxTarget(target)
	if err != nil {
		// Handle the error appropriately, e.g., log it or return a default value
		return nil, false
	}
	if parsedTarget.IsIBC() {
		target = ethtypes.ModuleName
	}
	return rtr.GetRoute(target)
}
x/crosschain/keeper/keeper.go (2)

31-31: LGTM! Consider adding a comment for the new field.

The addition of the evmErc20Keeper field aligns well with the PR objective of migrating cross-chain logic. It follows the existing naming conventions and uses an interface type, which is good for maintainability.

Consider adding a brief comment explaining the purpose of this new keeper, similar to other fields in the struct. For example:

// evmErc20Keeper manages EVM ERC20 token interactions
evmErc20Keeper     types.EvmERC20Keeper

41-41: LGTM! Consider updating the comment for consistency.

The update to the NewKeeper function signature correctly incorporates the new evmErc20Keeper parameter. The placement and grouping of parameters improve readability.

For consistency, consider updating the function comment to include the new parameter:

// NewKeeper returns a new instance of the crosschain keeper
func NewKeeper(cdc codec.BinaryCodec, moduleName string, storeKey storetypes.StoreKey,
	stakingKeeper types.StakingKeeper, stakingMsgServer types.StakingMsgServer, distributionKeeper types.DistributionMsgServer,
	bankKeeper types.BankKeeper, ibcTransferKeeper types.IBCTransferKeeper, erc20Keeper types.Erc20Keeper, ak types.AccountKeeper,
	evmKeeper types.EVMKeeper, evmErc20Keeper types.EvmERC20Keeper, authority string,
) Keeper {
	// ... (existing implementation)
}
x/crosschain/precompile/bridge_coin_amount_test.go (1)

59-59: Improved error message, consider minor enhancement.

The updated error message provides more specific information about the failure condition, which is a good improvement. It now clearly states that the token pair was not found and that the coins are invalid.

Consider standardizing the error message format across the codebase. For example:

fmt.Errorf("token pair not found for %s: invalid coins (evm transaction execution failed)", token.String())

This format separates the main error message from additional context and the underlying cause, making it easier to parse and understand.

x/evm/keeper/erc20.go (1)

49-55: Approve changes with a minor suggestion for consistency.

The implementation of the TotalSupply method looks good and aligns well with the existing codebase. It correctly queries the ERC20 contract for the total supply and handles potential errors.

For consistency with other methods in this file, consider initializing the return value to big.NewInt(0) in case of an error. This would make it behave similarly to the ERC20BalanceOf method.

Here's a suggested minor modification:

 func (k *Keeper) TotalSupply(ctx context.Context, contractAddr common.Address) (*big.Int, error) {
 	var totalSupplyRes struct{ Value *big.Int }
 	if err := k.QueryContract(sdk.UnwrapSDKContext(ctx), k.module, contractAddr, contract.GetFIP20().ABI, "totalSupply", &totalSupplyRes); err != nil {
-		return nil, err
+		return big.NewInt(0), err
 	}
 	return totalSupplyRes.Value, nil
 }
x/crosschain/keeper/keeper_test.go (1)

52-52: LGTM! Consider adding a comment for clarity.

The addition of evmErc20Keeper to the KeeperMockSuite struct is appropriate and consistent with the existing structure. This change enhances the test suite's capability to simulate interactions with the EVM ERC20 keeper.

Consider adding a brief comment above this field to explain its purpose, maintaining consistency with any existing field documentation in the struct.

x/crosschain/keeper/grpc_query.go (1)

298-302: Approve changes with a suggestion for improved error handling

The simplification of the BridgeCoinByDenom method is a good improvement. It reduces unnecessary checks and makes the code more concise. However, there's a potential issue with error handling.

Consider improving the error handling to distinguish between "denom not found" and other potential errors:

 supply, err := k.BridgeCoinSupply(sdk.UnwrapSDKContext(c), req.GetDenom(), req.GetChainName())
 if err != nil {
-    return nil, status.Error(codes.NotFound, "denom")
+    if errors.Is(err, types.ErrUnknownDenom) {
+        return nil, status.Error(codes.NotFound, "denom not found")
+    }
+    return nil, status.Error(codes.Internal, fmt.Sprintf("failed to get bridge coin supply: %v", err))
 }

This change assumes that BridgeCoinSupply returns a specific error type (types.ErrUnknownDenom) when the denomination is not found. If this is not the case, you may need to adjust the error checking accordingly.

x/crosschain/precompile/keeper.go (2)

24-25: Handle Specific Errors from GetBaseDenomByErc20

Currently, any error from crossChainKeeper.GetBaseDenomByErc20 results in returning an empty sdk.Coin and the error. Consider handling specific error cases to provide more informative feedback to the caller, which can aid in debugging and improve user experience.


51-52: Add Logging for Error Handling

When sending coins from the module to the account, adding logging statements for errors can enhance observability and aid in debugging. This will provide more context in case of failures and make troubleshooting more efficient.

x/crosschain/precompile/bridge_coin_amount.go (1)

50-50: Provide a more descriptive error message

The error message "invalid router" may not offer enough context for debugging. Consider refining it to be more descriptive, such as "crosschain module not found in router".

Apply this diff to improve the error message:

	if !found {
-		return nil, errors.New("invalid router")
+		return nil, errors.New("crosschain module not found in router")
	}
x/crosschain/precompile/bridge_call.go (1)

69-69: Enhance error message for better clarity

Consider providing more context in the error message to aid in debugging. Including the destination chain can help identify issues quickly.

Apply this diff to improve the error message:

 import (
 	"errors"
+	"fmt"
 	"math/big"

-		return errors.New("invalid router")
+		return fmt.Errorf("invalid router for destination chain: %s", args.DstChain)
x/crosschain/types/expected_keepers.go (2)

61-62: Re-evaluate the placement of IBC-related methods in Erc20Keeper

The methods SetIBCTransferRelation and DeleteIBCTransferRelation pertain to IBC transfer relations, which may not be directly related to the core responsibilities of the Erc20Keeper interface focused on ERC20 token operations.

Suggestion:

Consider moving these methods to a dedicated interface that handles IBC transfer functionalities, such as an IBCTransferKeeper or a new interface specific to cross-chain transfer relations. This will promote better separation of concerns and adhere to the Single Responsibility Principle.


93-95: Add documentation for the new EvmERC20Keeper interface

The newly introduced EvmERC20Keeper interface lacks documentation comments.

Suggestion:

Add GoDoc comments to the EvmERC20Keeper interface and its TotalSupply method to enhance readability and maintainability. For example:

// EvmERC20Keeper defines the expected interface for interacting with EVM ERC20 tokens.
type EvmERC20Keeper interface {
    // TotalSupply retrieves the total supply of the ERC20 token at the specified contract address.
    TotalSupply(ctx context.Context, contractAddr common.Address) (*big.Int, error)
}
x/crosschain/keeper/bridge_token.go (2)

182-199: Add unit tests for BridgeCoinSupply function

The new BridgeCoinSupply function introduces critical functionality for managing bridge coin supplies. To ensure reliability and correctness across different scenarios (native ERC20 tokens, non-native tokens, error conditions), please consider adding comprehensive unit tests.

Would you like assistance in writing unit tests for this function?


201-207: Add unit tests for GetBaseDenomByErc20 function

To validate the behavior of GetBaseDenomByErc20 in various scenarios—including cases where the token pair exists or does not exist—it's advisable to include unit tests. This will help prevent regressions and ensure the function handles all edge cases appropriately.

x/crosschain/keeper/bridge_call_out.go (1)

300-308: Include underlying error details in address validation error messages

When validating the to address in the IBCTransfer function, the error messages currently do not include the underlying error details, which could aid in debugging by providing more context about why the address is invalid. Consider modifying the error messages to include the error information.

Apply this diff to include the error details:

 if strings.ToLower(fxTarget.Prefix) == contract.EthereumAddressPrefix {
     if err := contract.ValidateEthereumAddress(to); err != nil {
-        return 0, fmt.Errorf("invalid to address: %s", to)
+        return 0, fmt.Errorf("invalid to address '%s': %v", to, err)
     }
 } else {
     if _, err := sdk.GetFromBech32(to, fxTarget.Prefix); err != nil {
-        return 0, fmt.Errorf("invalid to address: %s", to)
+        return 0, fmt.Errorf("invalid to address '%s': %v", to, err)
     }
 }
app/keepers/keepers.go (1)

Line range hint 380-487: Refactor repetitive cross-chain keeper initialization

The initialization code for the cross-chain keepers is repetitive. Consider refactoring this code to eliminate duplication, which will improve maintainability and reduce the risk of inconsistencies.

You can create a helper function to handle the initialization. Here's an example:

func initializeCrossChainKeeper(
    moduleName string,
    storeKey storetypes.StoreKey,
    appKeepers *AppKeepers,
    appCodec codec.Codec,
    authAddr string,
) crosschainkeeper.Keeper {
    return crosschainkeeper.NewKeeper(
        appCodec,
        moduleName,
        appKeepers.keys[storeKey],
        appKeepers.StakingKeeper,
        stakingkeeper.NewMsgServerImpl(appKeepers.StakingKeeper.Keeper),
        distrkeeper.NewMsgServerImpl(appKeepers.DistrKeeper),
        appKeepers.BankKeeper,
        appKeepers.IBCTransferKeeper,
        appKeepers.Erc20Keeper,
        appKeepers.AccountKeeper,
        appKeepers.EvmKeeper,
        authAddr,
    )
}

Then initialize each keeper like:

appKeepers.BscKeeper = initializeCrossChainKeeper(bsctypes.ModuleName, bsctypes.StoreKey, appKeepers, appCodec, authAddr)

This refactoring reduces code duplication and makes it easier to maintain.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between b2e11ba and d0b6487.

📒 Files selected for processing (18)
  • app/keepers/keepers.go (9 hunks)
  • x/crosschain/keeper/bridge_call_out.go (2 hunks)
  • x/crosschain/keeper/bridge_token.go (2 hunks)
  • x/crosschain/keeper/grpc_query.go (1 hunks)
  • x/crosschain/keeper/keeper.go (3 hunks)
  • x/crosschain/keeper/keeper_test.go (3 hunks)
  • x/crosschain/mock/expected_keepers_mocks.go (4 hunks)
  • x/crosschain/precompile/bridge_call.go (1 hunks)
  • x/crosschain/precompile/bridge_coin_amount.go (2 hunks)
  • x/crosschain/precompile/bridge_coin_amount_test.go (1 hunks)
  • x/crosschain/precompile/contract.go (1 hunks)
  • x/crosschain/precompile/crosschain.go (1 hunks)
  • x/crosschain/precompile/expected_keepers.go (1 hunks)
  • x/crosschain/precompile/keeper.go (1 hunks)
  • x/crosschain/precompile/router.go (2 hunks)
  • x/crosschain/types/expected_keepers.go (3 hunks)
  • x/crosschain/types/key.go (1 hunks)
  • x/evm/keeper/erc20.go (1 hunks)
🧰 Additional context used
🔇 Additional comments (21)
x/crosschain/precompile/router.go (2)

8-8: LGTM: New imports added correctly.

The new imports for fxtypes and ethtypes are correctly added and are necessary for the new GetRouteWithIBC method.

Also applies to: 10-10


Line range hint 1-62: Overall assessment: Changes look good with minor suggestions for improvement.

The modifications to this file successfully introduce IBC target handling in the router, aligning with the PR objectives of migrating cross-chain logic. The new imports and the GetRouteWithIBC method are correctly implemented. Consider adding error handling and improving documentation as suggested in the previous comments to enhance the robustness and maintainability of the code.

x/crosschain/keeper/keeper.go (1)

31-31: Verify the usage of the new evmErc20Keeper in other files.

The changes to add the evmErc20Keeper field and update the NewKeeper function are well-implemented and align with the PR objective. However, I noticed that the new keeper is not used in any of the existing methods in this file.

To ensure the new keeper is properly integrated, please run the following script to check its usage across the codebase:

This will help verify that the new keeper is being utilized as intended in other parts of the crosschain module.

Also applies to: 41-41, 60-60

x/crosschain/precompile/bridge_coin_amount_test.go (1)

Line range hint 1-108: Overall assessment: Minor improvement to error messaging.

The change in this file is limited to updating an error message in one of the test cases. This modification enhances the clarity of the error reporting without altering the test logic or coverage. It's a positive change that contributes to better error handling practices in the codebase.

x/crosschain/keeper/keeper_test.go (2)

103-103: LGTM! Proper initialization of the new mock keeper.

The evmErc20Keeper is correctly initialized using the mock controller. This addition is consistent with the initialization of other mock keepers in the SetupTest method.


119-119: LGTM! Verify NewKeeper function signature.

The addition of s.evmErc20Keeper as a parameter to the crosschainkeeper.NewKeeper function call is appropriate and consistent with the integration of EVM ERC20 functionality.

To ensure this change is correctly implemented, let's verify the NewKeeper function signature:

✅ Verification successful

LGTM! Verified NewKeeper function signature.

The NewKeeper function now includes evmErc20Keeper as a parameter, confirming the correct integration of EVM ERC20 functionality.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the NewKeeper function signature in the crosschain keeper package.

# Test: Search for the NewKeeper function definition
rg --type go -A 5 'func NewKeeper\(' x/crosschain/keeper/

Length of output: 732

x/crosschain/precompile/expected_keepers.go (3)

6-6: Import of 'sdkmath' is necessary and appropriate

The addition of the import sdkmath "cosmossdk.io/math" is required for the use of sdkmath.Int in the BridgeCallBaseCoin method.


21-21: Addition of 'SendCoins' method enhances 'BankKeeper' interface

Including the SendCoins method provides direct coin transfer functionality between accounts, aligning with standard operations in the bank module.


29-29: Addition of 'GetBaseDenomByErc20' method is appropriate

The GetBaseDenomByErc20 method extends the CrosschainKeeper interface, allowing retrieval of the base denomination using an ERC20 address, which enhances cross-chain compatibility.

x/crosschain/precompile/keeper.go (1)

31-33: ⚠️ Potential issue

Verify Proper Initialization and Usage of erc20Call

Ensure that erc20Call is correctly initialized with the appropriate parameters before calling Burn. Additionally, confirm that the Burn operation aligns with the token's logic and that the holder has the necessary permissions to burn tokens.

To automate this verification, you can run the following script:

x/crosschain/precompile/bridge_coin_amount.go (2)

4-4: Importing the 'errors' package is necessary

The addition of the "errors" package import is appropriate and required for error handling in the updated code.


57-57: Return statement correctly packs the output

The return statement properly packs the total supply amount into the expected output format using m.PackOutput.

x/crosschain/precompile/bridge_call.go (3)

62-63: Verify the source address in SendCoins

You're using crosschaintypes.GetAddress().Bytes() as the source address to send coins to the sender. Please ensure that this address is intended to be the source of the funds and that it holds sufficient balance for the transaction.


75-75: Ensure correct mapping of tokens to amounts

When iterating over args.Tokens, verify that each token corresponds accurately to its amount in args.Amounts[i]. Any misalignment could lead to incorrect token conversions or transaction failures.


81-82: Confirm parameter order in BridgeCallBaseCoin

Double-check that the parameters passed to crosschainKeeper.BridgeCallBaseCoin are in the correct order and type, especially with the addition of originTokenAmount. Incorrect parameter placement could cause unexpected behavior.

x/crosschain/precompile/crosschain.go (3)

89-90: Confirm parameters in CrossChainBaseCoin call

Verify that all parameters passed to crosschainKeeper.CrossChainBaseCoin align with its expected signature. Specifically, ensure that target is in the correct format and type as required by the function.


81-84: ⚠️ Potential issue

Handle potential nil values from EvmTokenToBase

Ensure that totalCoin returned from m.EvmTokenToBase is not nil before using it. If there's a possibility of receiving a nil value without an error, add a check to prevent a nil pointer dereference.

Consider adding a nil check:

if totalCoin.IsNil() {
	return errors.New("received nil totalCoin from EvmTokenToBase")
}

74-75: ⚠️ Potential issue

Verify the direction of funds transfer in SendCoins

In the SendCoins call, funds are being sent from the cross-chain module account to the sender:

if err = m.bankKeeper.SendCoins(ctx, crosschaintypes.GetAddress().Bytes(), sender.Bytes(), sdk.NewCoins(totalCoin)); err != nil {
	return err
}

Please verify if this is the intended behavior. Typically, the sender should be transferring funds to the module account when initiating a cross-chain transaction. This could be a potential logic error.

To confirm if the SendCoins function is used correctly, you can run the following script:

✅ Verification successful

Direction of funds transfer in SendCoins confirmed as intended.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for usages of SendCoins where funds are sent from the module account to the sender.

# Expected result: Verify if this pattern is intentional or deviates from standard practices.

rg --type go 'SendCoins\([^,]+,\s*crosschaintypes\.GetAddress\(\)\.Bytes\(\),\s*sender\.Bytes\(\)' -A 5

Length of output: 1041


Script:

#!/bin/bash
# Description: Retrieve all usages of SendCoins to analyze fund transfer directions.

rg --type go 'SendCoins\(' -A 5

Length of output: 8645

x/crosschain/keeper/bridge_call_out.go (2)

261-286: Verify the necessity of calling BuildOutgoingTxBatch when originToken is true

In the CrossChainBaseCoin function, BuildOutgoingTxBatch is invoked regardless of the originToken value:

batchNonce, err := k.BuildOutgoingTxBatch(ctx, from, receipt, amount, fee)
if err != nil {
    return err
}

However, batchNonce is only used when !originToken:

if !originToken {
    k.erc20Keeper.SetOutgoingTransferRelation(ctx, fxTarget.GetTarget(), batchNonce)
}

Please verify whether it's necessary to build the outgoing transaction batch when originToken is true, or if the call to BuildOutgoingTxBatch should be conditioned on !originToken to avoid unnecessary processing.


237-259: ⚠️ Potential issue

Unused 'originTokenAmount' parameter in non-IBC transfers

In the BridgeCallBaseCoin function, the parameter originTokenAmount is only used in the IBC transfer path (fxTarget.IsIBC() is true), where it's checked using originTokenAmount.IsZero(). However, in the non-IBC transfer path (fxTarget.IsIBC() is false), this parameter is not utilized, and there's a TODO comment acknowledging this:

// todo record origin amount

Please ensure that originTokenAmount is appropriately handled in the non-IBC transfer scenario to avoid potential issues or confusion.

app/keepers/keepers.go (1)

341-341: Ensure precompileRouter is initialized before use

The precompileRouter is being passed to crosschainprecompile.NewPrecompiledContract. Ensure that precompileRouter is properly initialized before this call to prevent any potential nil pointer dereferences at runtime.

Run the following script to verify that precompileRouter is initialized before use:

✅ Verification successful

precompileRouter Initialization Confirmed

The precompileRouter is properly initialized at line 326 before its usage at line 341, preventing any potential nil pointer dereferences.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if `precompileRouter` is initialized before being used in NewPrecompiledContract

# Expected: Initialization of precompileRouter occurs before its usage
rg -n 'precompileRouter\s*:=\s*crosschainprecompile\.NewRouter\(\)' app/keepers/keepers.go

Length of output: 150

x/crosschain/precompile/contract.go Show resolved Hide resolved
x/crosschain/precompile/expected_keepers.go Show resolved Hide resolved
x/crosschain/precompile/expected_keepers.go Show resolved Hide resolved
x/crosschain/precompile/expected_keepers.go Show resolved Hide resolved
x/crosschain/precompile/keeper.go Show resolved Hide resolved
x/crosschain/types/key.go Show resolved Hide resolved
app/keepers/keepers.go Show resolved Hide resolved
x/crosschain/mock/expected_keepers_mocks.go Show resolved Hide resolved
x/crosschain/mock/expected_keepers_mocks.go Show resolved Hide resolved
x/crosschain/mock/expected_keepers_mocks.go Show resolved Hide resolved
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