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: account is contract #523

Merged
merged 1 commit into from
May 29, 2024
Merged

fix: account is contract #523

merged 1 commit into from
May 29, 2024

Conversation

zakir-code
Copy link
Contributor

@zakir-code zakir-code commented May 28, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced contract validation by ensuring target addresses are valid contracts before executing operations.
  • Bug Fixes

    • Improved reliability by adding checks for nil addresses and non-contract targets in cross-chain bridge calls.
  • Refactor

    • Replaced the GetAccount method with IsContract in various components for more accurate contract verification.

Copy link

coderabbitai bot commented May 28, 2024

Walkthrough

The recent updates focus on enhancing the BridgeCallTransferAndCallEvm and HandleOutgoingBridgeCallRefund functions by introducing a check to verify if a target address is a contract using the new IsContract method in the EVMKeeper. This change ensures that operations are only performed on valid contract addresses, improving robustness and preventing errors.

Changes

Files/Paths Change Summaries
x/crosschain/keeper/bridge_call_in.go Added condition to check if the target address is nil or not a contract before proceeding with the call.
x/crosschain/keeper/bridge_call_in_test.go Updated tests to include expectations for the IsContract method.
x/crosschain/keeper/bridge_call_refund.go Modified logic to use IsContract method for checking if an account is a contract.
x/crosschain/mock/expected_keepers_mocks.go Replaced GetAccount with IsContract in MockEVMKeeper.
x/crosschain/types/expected_keepers.go Updated EVMKeeper interface to replace GetAccount with IsContract.
x/evm/keeper/statedb.go Added IsContract method to Keeper struct to check if an account is a contract.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant User
    participant BridgeModule
    participant EVMKeeper

    User ->> BridgeModule: Initiates Bridge Call
    BridgeModule ->> EVMKeeper: IsContract(to)
    EVMKeeper -->> BridgeModule: true/false
    alt Is Contract
        BridgeModule ->> EVMKeeper: Proceed with Call
        EVMKeeper -->> BridgeModule: Call Success/Failure
    else Not a Contract
        BridgeModule -->> User: Error: Not a Contract
    end
Loading

In fields of code, where logic blooms,
A rabbit prances, avoiding doom.
Contracts checked with careful eye,
Errors caught before they fly.
With every hop, the code's refined,
Robust and strong, a joy to find.
🐇✨


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 full the 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 3ab89c8 and bc5d786.
Files selected for processing (6)
  • x/crosschain/keeper/bridge_call_in.go (1 hunks)
  • x/crosschain/keeper/bridge_call_in_test.go (1 hunks)
  • x/crosschain/keeper/bridge_call_refund.go (1 hunks)
  • x/crosschain/mock/expected_keepers_mocks.go (2 hunks)
  • x/crosschain/types/expected_keepers.go (2 hunks)
  • x/evm/keeper/statedb.go (1 hunks)
Additional comments not posted (6)
x/evm/keeper/statedb.go (1)

61-64: The implementation of IsContract appears correct and efficient.

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

47-47: Ensure the new contract check integrates well with the rest of the system.

Verification successful

The IsContract check within HandleOutgoingBridgeCallRefund ensures that operations are only performed on contract addresses. The usages in abci.go and bridge_call_out.go rely on this check and do not require additional handling for non-contract addresses.

  • x/crosschain/keeper/abci.go
  • x/crosschain/keeper/bridge_call_out.go
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify integration of IsContract check in HandleOutgoingBridgeCallRefund.

# Test: Search for usage of HandleOutgoingBridgeCallRefund. Expect: Proper handling of non-contract addresses.
rg --type go $'HandleOutgoingBridgeCallRefund'

Length of output: 604



Script:

#!/bin/bash
# Description: Verify handling of non-contract addresses in HandleOutgoingBridgeCallRefund usage.

# Inspect usage in abci.go
rg --type go --context 5 'HandleOutgoingBridgeCallRefund' x/crosschain/keeper/abci.go

# Inspect usage in bridge_call_out.go
rg --type go --context 5 'HandleOutgoingBridgeCallRefund' x/crosschain/keeper/bridge_call_out.go

Length of output: 884

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

48-48: The addition of the IsContract expectation in the test is appropriate. Consider adding more comprehensive tests around this functionality.

x/crosschain/types/expected_keepers.go (1)

77-77: The update to the EVMKeeper interface is consistent with the new functionality.

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

83-85: The addition of the contract check in BridgeCallTransferAndCallEvm is crucial for ensuring that operations are only performed on contract addresses.

Verification successful

The IsContract method in x/evm/keeper/statedb.go correctly identifies contract addresses by checking if the account is not nil and if it is a contract. This ensures that the BridgeCallTransferAndCallEvm function only operates on valid contract addresses.

  • x/evm/keeper/statedb.go:61-64: Implementation of IsContract method.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify integration of IsContract check in BridgeCallTransferAndCallEvm.

# Test: Search for usage of BridgeCallTransferAndCallEvm. Expect: Proper handling of non-contract addresses.
rg --type go $'BridgeCallTransferAndCallEvm'

Length of output: 320



Script:

#!/bin/bash
# Description: Locate the implementation of the IsContract method.

# Search for the IsContract method in the codebase.
ast-grep --lang go --pattern $'func (k Keeper) IsContract(ctx sdk.Context, address sdk.AccAddress) bool {
  $$$
}'

Length of output: 115



Script:

#!/bin/bash
# Description: Locate the implementation of the IsContract method with a broader search pattern.

# Search for the IsContract method in the codebase.
rg --type go 'func.*IsContract'

Length of output: 387



Script:

#!/bin/bash
# Description: Extract and review the implementation of the IsContract method in x/evm/keeper/statedb.go.

# Extract the implementation of the IsContract method.
ast-grep --lang go --pattern $'func (k *Keeper) IsContract(ctx sdk.Context, account common.Address) bool {
  $$$
}' x/evm/keeper/statedb.go

Length of output: 414

x/crosschain/mock/expected_keepers_mocks.go (1)

660-664: The implementation of IsContract in MockEVMKeeper and its recorder appears correctly aligned with GoMock conventions.

Also applies to: 668-671

@fx0x55
Copy link
Contributor

fx0x55 commented May 29, 2024

mg

@zakir-code zakir-code merged commit c472c05 into main May 29, 2024
9 checks passed
@zakir-code zakir-code deleted the fx0x55/call branch May 29, 2024 02:06
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.

None yet

2 participants