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): bridge callback #527

Merged
merged 1 commit into from
May 29, 2024
Merged

Conversation

zakir-code
Copy link
Contributor

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

Summary by CodeRabbit

  • New Features

    • Introduced a refund mechanism in bridge calls, replacing the receiver parameter with a refund parameter for better clarity and functionality.
  • Refactor

    • Updated function signatures and event parameters across various contracts to use _refund instead of _receiver.
    • Renamed verifyBridgeCall to verifySubmitBridgeCall to better reflect its purpose.
    • Simplified token handling in BridgeCallbackTest by removing SafeERC20Upgradeable usage.
  • Tests

    • Adjusted test scripts to reflect the new refund parameter and updated logic for handling refunds.

Copy link

coderabbitai bot commented May 29, 2024

Walkthrough

The changes primarily involve renaming the _receiver parameter to _refund across multiple Solidity contracts, Go interfaces, and test files. This update affects function signatures, event definitions, and struct fields to reflect the new parameter name. Additionally, there are adjustments to the compile.sh script and some simplifications in the token handling logic within the BridgeCallbackTest contract.

Changes

Files/Paths Change Summary
contract/IBridgeCallback.go Modified ABI and BridgeCallback functions to replace _receiver with _refund.
contract/ICrossChain.go Renamed _receiver to _refund in BridgeCall function signatures.
contract/compile.sh Removed IBridgeCallback from core contracts; added ERC1967Proxy to 3rd party contracts.
solidity/contracts/bridge/FxBridgeLogic.sol Renamed receiver to refund in struct, events, and functions; updated event parameters.
solidity/contracts/bridge/FxBridgeLogicETH.sol Similar changes as FxBridgeLogic.sol with adjustments for ETH-specific logic.
solidity/contracts/bridge/IBridgeCall.sol, IBridgeCallback.sol Renamed _receiver to _refund in function parameters.
solidity/contracts/bridge/IFxBridgeLogic.sol Updated BridgeCallData struct, function parameters, and event definitions to use refund.
solidity/contracts/test/BridgeCallbackTest.sol Removed SafeERC20Upgradeable usage and token transfer logic from bridgeCallback function.
solidity/test/submit_bridge_call.ts Modified test logic to use refund parameter instead of receiver.
x/evm/precompiles/crosschain/bridge_call_test.go Renamed Receiver to Refund in the Args struct and test function.

Poem

🐇 In the code where bridges span,
Refunds now take the plan.
Receivers bid adieu,
As refunds come anew.
Solidity and Go in tune,
Simplifying soon!
Hopping forward, code refined,
A seamless bridge we now 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 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.

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

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 576743c and 83cf767.
Files selected for processing (12)
  • contract/IBridgeCallback.go (2 hunks)
  • contract/ICrossChain.go (2 hunks)
  • contract/IFxBridgeLogic.go (10 hunks)
  • contract/compile.sh (1 hunks)
  • solidity/contracts/bridge/FxBridgeLogic.sol (12 hunks)
  • solidity/contracts/bridge/FxBridgeLogicETH.sol (12 hunks)
  • solidity/contracts/bridge/IBridgeCall.sol (1 hunks)
  • solidity/contracts/bridge/IBridgeCallback.sol (1 hunks)
  • solidity/contracts/bridge/IFxBridgeLogic.sol (4 hunks)
  • solidity/contracts/test/BridgeCallbackTest.sol (2 hunks)
  • solidity/test/submit_bridge_call.ts (11 hunks)
  • x/evm/precompiles/crosschain/bridge_call_test.go (3 hunks)
Files not summarized due to errors (1)
  • contract/IFxBridgeLogic.go: Error: Message exceeds token limit
Files skipped from review due to trivial changes (2)
  • solidity/contracts/bridge/IBridgeCall.sol
  • solidity/contracts/test/BridgeCallbackTest.sol
Additional Context Used
Biome (13)
solidity/test/submit_bridge_call.ts (13)

37-113: This function expression can be turned into an arrow function.


164-180: This function expression can be turned into an arrow function.


182-218: This function expression can be turned into an arrow function.


220-244: This function expression can be turned into an arrow function.


252-306: This function expression can be turned into an arrow function.


308-324: This function expression can be turned into an arrow function.


326-346: This function expression can be turned into an arrow function.


348-369: This function expression can be turned into an arrow function.


246-370: This function expression can be turned into an arrow function.


18-371: This function expression can be turned into an arrow function.


1-2: All these imports are only used as types.


3-9: All these imports are only used as types.


27-27: This let declares a variable that is only assigned once.

Additional comments not posted (27)
solidity/contracts/bridge/IBridgeCallback.sol (1)

7-7: The parameter renaming from _receiver to _refund is consistent with the PR objectives and improves clarity.

contract/compile.sh (1)

34-34: Adding IBridgeCallback to the contracts array ensures that the ABI and Go bindings are generated for the updated contract.

x/evm/precompiles/crosschain/bridge_call_test.go (1)

23-23: The renaming of the parameter from Receiver to Refund in the test setup and assertions is correctly implemented and consistent with the changes in the contract interfaces.

Also applies to: 33-33, 47-47

solidity/contracts/bridge/IFxBridgeLogic.sol (1)

52-52: The renaming of receiver to refund across struct fields, function parameters, and event parameters is consistent with the PR objectives and correctly implemented.

Also applies to: 185-185, 229-229, 242-242

solidity/test/submit_bridge_call.ts (1)

117-117: The renaming of the parameter from receiver to refund in the test setup and assertions is correctly implemented and consistent with the changes in the contract interfaces.

Also applies to: 129-129, 144-144, 172-172, 233-233, 234-234, 316-316, 338-338, 361-361

contract/IBridgeCallback.go (1)

34-34: The update of the ABI definition and function signatures from _receiver to _refund is consistent with the changes in the Solidity contracts and correctly implemented.

Also applies to: 186-186, 193-193, 200-200

solidity/contracts/bridge/FxBridgeLogic.sol (6)

66-66: Renaming receiver to refund in BridgeCallData struct aligns with the PR objectives.


Line range hint 294-305: Ensure that the refund address is validated before processing in bridgeCall.


504-504: The bridgeCallSigHash function correctly includes the refund parameter in the data hash. This is a critical change for transaction integrity.


576-598: The _transferAndBridgeCallback function now correctly handles the refund parameter. Ensure that the logic correctly distinguishes between to and refund addresses based on eventNonce.


457-457: The function verifySubmitBridgeCall is crucial for security. Ensure that all validations are robust and consider edge cases.

Verification successful

The verifySubmitBridgeCall function includes several robust validations:

  • Ensures the nonce is unique.
  • Validates that the timeout is greater than the current block height.
  • Checks that the lengths of tokens and amounts match.
  • Verifies the consistency of the oracle set.
  • Confirms the validity of the oracle set checkpoint.

These validations appear comprehensive and cover critical security aspects. However, it is always good practice to review these checks periodically and consider any new potential edge cases or vulnerabilities that may arise.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the robustness of validations in `verifySubmitBridgeCall`.

# Test: Search for the function usage and review its logic.
ast-grep --lang solidity --pattern $'function verifySubmitBridgeCall($_, $_, $_, $_, $_, $_, $_) {
  $$$
}'

Length of output: 225



Script:

#!/bin/bash
# Description: Verify the robustness of validations in `verifySubmitBridgeCall`.

# Search for the function definition in Solidity files
rg 'function verifySubmitBridgeCall' --glob '*.sol'

# Search for the function usage across the codebase
rg 'verifySubmitBridgeCall' --glob '*.sol'

Length of output: 581



Script:

#!/bin/bash
# Description: Extract the implementation of `verifySubmitBridgeCall` from both Solidity files for review.

# Extract the function implementation from FxBridgeLogic.sol
rg -A 20 'function verifySubmitBridgeCall' solidity/contracts/bridge/FxBridgeLogic.sol

# Extract the function implementation from FxBridgeLogicETH.sol
rg -A 20 'function verifySubmitBridgeCall' solidity/contracts/bridge/FxBridgeLogicETH.sol

Length of output: 1502



Script:

#!/bin/bash
# Description: Extract the complete implementation of `verifySubmitBridgeCall` from both Solidity files for review.

# Extract more lines from the function implementation in FxBridgeLogic.sol
rg -A 40 'function verifySubmitBridgeCall' solidity/contracts/bridge/FxBridgeLogic.sol

# Extract more lines from the function implementation in FxBridgeLogicETH.sol
rg -A 40 'function verifySubmitBridgeCall' solidity/contracts/bridge/FxBridgeLogicETH.sol

Length of output: 2816


Line range hint 814-827: The events BridgeCallEvent and SubmitBridgeCallEvent have been updated to use the new refund parameter and _txOrigin. This change should be propagated to all event listeners.

solidity/contracts/bridge/FxBridgeLogicETH.sol (8)

77-77: Renaming receiver to refund in BridgeCallData struct aligns with the PR objectives and is consistent with changes in FxBridgeLogic.sol.


Line range hint 330-341: Ensure that the refund address is validated before processing in bridgeCall. This is consistent with the changes in the other contract file.


540-540: The bridgeCallSigHash function correctly includes the refund parameter in the data hash. This is a critical change for transaction integrity.


612-634: The _transferAndBridgeCallback function now correctly handles the refund parameter. Ensure that the logic correctly distinguishes between to and refund addresses based on eventNonce.


351-351: The event BridgeCallEvent now logs _refund instead of _receiver. Ensure this change is reflected in all handlers of this event.

Verification successful

The search results show that the BridgeCallEvent is indeed being emitted with _refund as a parameter instead of _receiver. This confirms that the change has been made in the event emission.

  • Instances of BridgeCallEvent emission:
    • _msgSender()
    • _refund
    • _to

This indicates that the change from _receiver to _refund has been correctly applied in the event emission.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify all handlers of `BridgeCallEvent` are updated to use `_refund`.

# Test: Search for the event usage. Expect: Only occurances with the new parameter.
rg --type solidity $'BridgeCallEvent'

Length of output: 69



Script:

#!/bin/bash
# Description: Verify all handlers of `BridgeCallEvent` are updated to use `_refund`.

# Find all Solidity files and search for the event usage within them.
fd -e sol -x rg 'BridgeCallEvent' {}

Length of output: 385



Script:

#!/bin/bash
# Description: Verify all handlers of `BridgeCallEvent` are updated to use `_refund`.

# Find all Solidity files and search for the emission of `BridgeCallEvent` with surrounding lines for context.
fd -e sol -x rg -C 3 'emit BridgeCallEvent' {}

Length of output: 422


Line range hint 854-867: The events BridgeCallEvent and SubmitBridgeCallEvent have been updated to use the new refund parameter and _txOrigin. This change should be propagated to all event listeners.

Verification successful

The verification confirms that the emit statements for BridgeCallEvent and SubmitBridgeCallEvent in the files FxBridgeLogicETH.sol and FxBridgeLogic.sol have been updated to include the new parameters _refund and _txOrigin.

  • BridgeCallEvent includes _msgSender(), _refund, _to, and tx.origin.
  • SubmitBridgeCallEvent includes tx.origin, _nonceArray[1], state_lastEventNonce, and success.

These changes are consistent across the relevant files.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify all listeners of `BridgeCallEvent` and `SubmitBridgeCallEvent` handle the new parameters.

# Test: Search for the event usage. Expect: Only occurances with the new parameters.
rg --type solidity $'BridgeCallEvent|SubmitBridgeCallEvent'

Length of output: 93



Script:

#!/bin/bash
# Description: Verify all listeners of `BridgeCallEvent` and `SubmitBridgeCallEvent` handle the new parameters.

# Test: Search for the event usage. Expect: Only occurrences with the new parameters.
rg 'BridgeCallEvent|SubmitBridgeCallEvent' --glob '*.sol'

Length of output: 902



Script:

#!/bin/bash
# Description: Verify the parameters used in the `emit` statements for `BridgeCallEvent` and `SubmitBridgeCallEvent`.

# Extract lines where `BridgeCallEvent` is emitted
rg 'emit BridgeCallEvent' --glob '*.sol' -n

# Extract lines where `SubmitBridgeCallEvent` is emitted
rg 'emit SubmitBridgeCallEvent' --glob '*.sol' -n

Length of output: 435



Script:

#!/bin/bash
# Description: Verify the parameters used in the `emit` statements for `BridgeCallEvent` and `SubmitBridgeCallEvent`.

# Extract lines around the `emit BridgeCallEvent` statements
rg 'emit BridgeCallEvent' --glob '*.sol' -A 5 -B 5

# Extract lines around the `emit SubmitBridgeCallEvent` statements
rg 'emit SubmitBridgeCallEvent' --glob '*.sol' -A 5 -B 5

Length of output: 3469


493-493: The function verifySubmitBridgeCall is crucial for security. Ensure that all validations are robust and consider edge cases.


553-553: The verifySubmitBridgeCall function's internal logic appears to be correctly updated to handle the new refund parameter. Ensure comprehensive testing to avoid security risks.

contract/ICrossChain.go (2)

34-34: The ABI update correctly reflects the renaming of _receiver to _refund. Ensure all dependent systems are updated to accommodate this change.


216-218: The BridgeCall function signature has been correctly updated across all bindings to use _refund instead of _receiver. This change is consistent and well-implemented.

Also applies to: 223-225, 230-232

contract/IFxBridgeLogic.go (5)

35-35: Renamed field from Receiver to Refund in IFxBridgeLogicBridgeCallData struct aligns with the PR's objective to standardize terminology.


62-62: Updated ABI in IFxBridgeLogicMetaData to reflect the renaming of parameters from _receiver to _refund. This change is consistent with the overall goal of the PR.


770-772: The bridgeCallCheckpoint function signature has been updated to use _refund. This change is consistent and correctly implemented according to the PR description.

Also applies to: 777-779, 784-786


1218-1218: The BridgeCallEvent struct now uses _refund instead of _receiver, aligning with the changes made throughout the contract. This is a necessary update to maintain consistency in event parameters.


749-751: The bridgeCall function signature has been correctly updated to use _refund instead of _receiver. Ensure that all calls to this function across the codebase are updated to match this new signature.

Also applies to: 756-758, 763-765

@zakir-code zakir-code merged commit d7342c6 into main May 29, 2024
15 checks passed
@zakir-code zakir-code deleted the nulnut/bridge-callback branch May 29, 2024 09:20
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