8000 feat(contracts-rfq): Multicall in FastBridgeV2 [SLT-369] by ChiTimesChi · Pull Request #3315 · synapsecns/sanguine · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(contracts-rfq): Multicall in FastBridgeV2 [SLT-369] #3315

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

Merged
merged 4 commits into from
Oct 28, 2024

Conversation

ChiTimesChi
Copy link
Collaborator
@ChiTimesChi ChiTimesChi commented Oct 21, 2024

Description
A clear and concise description of the features you're adding in this pull request.

Additional context
Add any other context about the problem you're solving.

Metadata

  • Fixes #[Link to Issue]

Summary by CodeRabbit

  • New Features

    • Enhanced FastBridgeV2 contract with multicall capabilities for improved transaction handling.
    • Added support for detailed transaction specifications with the new BridgeParamsV2.
    • Introduced a new testing contract to facilitate the deployment and configuration of FastBridgeV2.
  • Bug Fixes

    • Improved error handling and validation in multiple functions to ensure only valid requests are processed.
  • Tests

    • Introduced new tests for FastBridgeV2 to validate the updated functionality and transaction encoding.
    • Enhanced test cases for better clarity and efficiency in transaction management.

Copy link
Contributor
coderabbitai bot commented Oct 21, 2024

Walkthrough

The FastBridgeV2 contract has been significantly modified to incorporate the MulticallTarget as a base class, enhancing its functionality with multicall capabilities. Key changes include updated function signatures to accept new parameters, refined error handling, and improved validation logic. Additionally, a new test contract has been introduced to facilitate integration testing, while existing tests have been adjusted to accommodate the new transaction handling approach, focusing on encoded data for bridge transactions.

Changes

File Change Summary
packages/contracts-rfq/contracts/FastBridgeV2.sol - Updated contract inheritance to include MulticallTarget.
- Modified bridge, relay, prove, claim, and getBridgeTransaction functions to accept new parameters and enhance functionality.
- Improved error handling and validation in multiple functions.
packages/contracts-rfq/test/integration/FastBridgeV2.MulticallTarget.t.sol - Added FastBridgeV2MulticallTargetTest contract with methods for deploying FastBridgeV2 and encoding bridge transactions.
packages/contracts-rfq/test/integration/MulticallTarget.t.sol - Enhanced MulticallTargetIntegrationTest by adding internal byte arrays for encoded transactions.
- Updated prove function to accept encoded transaction data instead of a structure.

Possibly related PRs

Suggested labels

needs-go-generate-services/rfq

Suggested reviewers

  • ChiTimesChi
  • parodime
  • aureliusbtc

Poem

In the meadow where bridges gleam,
FastBridgeV2 dances, a coder's dream.
With multicalls and params anew,
It hops along, making transactions true.
So let’s cheer for the code, oh what a sight,
As we leap through the changes, all feels just right! 🐇✨


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 confi 8000 guration 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.

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
codecov bot commented Oct 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 28.74454%. Comparing base (6415acd) to head (b6b8708).
Report is 36 commits behind head on master.

Additional details and impacted files
@@                 Coverage Diff                 @@
##              master       #3315         +/-   ##
===================================================
- Coverage   31.92469%   28.74454%   -3.18015%     
===================================================
  Files            238         184         -54     
  Lines          14553       12131       -2422     
  Branches         356          82        -274     
===================================================
- Hits            4646        3487       -1159     
+ Misses          9614        8361       -1253     
+ Partials         293         283         -10     
Flag Coverage Δ
packages 90.44834% <ø> (ø)
promexporter ?
solidity 98.65772% <ø> (+3.13638%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor
@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: 1

🧹 Outside diff range and nitpick comments (3)
packages/contracts-rfq/contracts/FastBridgeV2.sol (3)

Line range hint 110-112: Potential Integer Overflow in Exclusivity End Time Calculation.

In _validateBridgeParams, casting block.timestamp to int256 and adding paramsV2.quoteExclusivitySeconds could result in integer overflow if block.timestamp exceeds 2^255. Although this is unlikely in the near future, it's safer to use uint256 arithmetic to prevent potential issues.

Apply this diff to use uint256 instead of int256:

-function _validateBridgeParams(
-    BridgeParams memory params,
-    BridgeParamsV2 memory paramsV2,
-    int256 exclusivityEndTime
-) internal
+) internal view
+{
+    uint256 exclusivityEndTime = block.timestamp + paramsV2.quoteExclusivitySeconds;
     // Check V1 (legacy) params
     ...
-    if (exclusivityEndTime <= 0 || exclusivityEndTime > int256(params.deadline)) {
+    if (exclusivityEndTime > params.deadline) {
         revert ExclusivityParamsIncorrect();
     }
}

Line range hint 138-154: Handle Fee-on-Transfer Tokens Appropriately During Relay.

In the relay function, for tokens with transfer fees, the recipient may receive less than the expected amount, potentially causing issues if the full amount is required. Consider implementing logic to account for fee-on-transfer tokens or restricting such tokens to prevent unexpected behavior.

Would you like assistance in modifying the relay logic to handle fee-on-transfer tokens effectively?


Line range hint 180-192: Potential Reentrancy Risk in _checkedCallRecipient.

The _checkedCallRecipient function performs an external call using Address.functionCallWithValue, which could introduce reentrancy risks. Although state changes precede this call, consider adding the nonReentrant modifier or implementing reentrancy guards to enhance security.

Apply the nonReentrant modifier to the relay or _checkedCallRecipient function to mitigate potential reentrancy vulnerabilities.

+import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
...
-contract FastBridgeV2 is Admin, MulticallTarget, IFastBridgeV2, IFastBridgeV2Errors {
+contract FastBridgeV2 is Admin, MulticallTarget, ReentrancyGuard, IFastBridgeV2, IFastBridgeV2Errors {

...

-function relay(bytes calldata request, address relayer) public payable {
+function relay(bytes calldata request, address relayer) public payable nonReentrant {
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 7cf772e and e3a9428.

📒 Files selected for processing (3)
  • packages/contracts-rfq/contracts/FastBridgeV2.sol (1 hunks)
  • packages/contracts-rfq/test/integration/FastBridgeV2.MulticallTarget.t.sol (1 hunks)
  • packages/contracts-rfq/test/integration/MulticallTarget.t.sol (7 hunks)
🧰 Additional context used
📓 Learnings (2)
packages/contracts-rfq/contracts/FastBridgeV2.sol (1)
Learnt from: ChiTimesChi
PR: synapsecns/sanguine#3284
File: packages/contracts-rfq/contracts/FastBridgeV2.sol:100-118
Timestamp: 2024-10-14T14:45:57.214Z
Learning: When reviewing code in `packages/contracts-rfq/contracts/FastBridgeV2.sol` (Solidity), focus on changes introduced in the PR and avoid commenting on existing functions like `refund` if they are not modified by the PR, as such comments are considered out of scope.
packages/contracts-rfq/test/integration/FastBridgeV2.MulticallTarget.t.sol (3)
Learnt from: ChiTimesChi
PR: synapsecns/sanguine#3284
File: packages/contracts-rfq/test/FastBridgeV2.t.sol:53-56
Timestamp: 2024-10-14T13:24:45.293Z
Learning: Modifying test utility contracts in the `test` directory is unnecessary and would only pollute the code.
Learnt from: ChiTimesChi
PR: synapsecns/sanguine#3284
File: packages/contracts-rfq/test/FastBridgeV2.t.sol:53-56
Timestamp: 2024-10-14T13:24:45.293Z
Learning: In Solidity test contracts under the `test` directory, such as `FastBridgeV2.t.sol`, contracts are not deployed, so gas consumption is not a concern.
Learnt from: ChiTimesChi
PR: synapsecns/sanguine#3284
File: packages/contracts-rfq/test/FastBridgeV2.Src.t.sol:919-993
Timestamp: 2024-10-14T14:48:01.520Z
Learning: In Solidity test files for FastBridgeV2 (e.g., `packages/contracts-rfq/test/FastBridgeV2.Src.t.sol`), code duplication in test functions is acceptable to maintain readability and maintainability, even if it contradicts DRY principles.
🔇 Additional comments (12)
packages/contracts-rfq/test/integration/FastBridgeV2.MulticallTarget.t.sol (3)

11-11: Confirm the use of address(this) in FastBridgeV2 constructor.

Ensure that passing address(this) to the FastBridgeV2 constructor is appropriate in this test context. Verify that it correctly initializes the contract as intended.


22-35: Assignment of fields is acceptable per previous guidance.

While the field-by-field assignment from bridgeTx to bridgeTxV2 is repetitive, this approach aligns with previous learnings that code duplication in test functions is acceptable to maintain readability and maintainability.


34-34: Verify that exclusivityEndTime set to block.timestamp is appropriate.

Ensure that setting exclusivityEndTime to the current block timestamp reflects the intended test scenario for transaction exclusivity.

packages/contracts-rfq/test/integration/MulticallTarget.t.sol (7)

36-38: Addition of encoded bridge transaction variables is appropriate

The introduction of internal byte arrays encodedBridgedTokenTx, encodedProvenEthTx, and encodedRemoteTokenTx enhances efficiency by storing pre-encoded transaction data for use in tests, streamlining transaction handling.


53-53: Ensure all prove function calls are updated

In the setUp function, the call prove(encodedProvenEthTx); reflects the updated prove function signature accepting bytes instead of a BridgeTransaction struct. Verify that all other calls to prove within the test suite have been updated accordingly to prevent potential issues.


123-128: Computing transaction IDs from encoded data ensures consistency

Using keccak256 on the encoded transactions to compute bridgedTokenTxId, provenEthTxId, and remoteTokenTxId aligns the identifiers directly with the transaction data, promoting consistency and reducing discrepancies.


149-151: Updated prove function signature aligns with contract changes

The prove function now accepts bytes memory encodedBridgeTx, matching the updated interface in FastBridgeV2. The call to IFastBridge(fastBridge).prove(encodedBridgeTx, hex"01"); correctly passes the encoded transaction data.


156-158: Correct use of abi.encodeCall with encoded transactions

In the getData function, the use of abi.encodeCall with the encoded transactions prepares the data array appropriately for multicall operations, ensuring function calls are correctly encoded.


168-169: Function calls updated to use encoded transactions

In test_sequentialExecution, the function calls to prove and claim now use encodedBridgedTokenTx and encodedProvenEthTx, respectively, consistent with the updated function signatures and enhancing test accuracy.


98-99: ⚠️ Potential issue

Swapping originSender and destRecipient may affect test logic

In provenEthTx, swapping originSender: user and destRecipient: userRemote changes the direction of the transaction. Confirm that this change is intentional and aligns with the intended behavior of the test cases.

packages/contracts-rfq/contracts/FastBridgeV2.sol (2)

16-19: Review Security Implications of Inheriting MulticallTarget.

The addition of MulticallTarget as a base contract introduces multicall capabilities to FastBridgeV2. Ensure that this inclusion does not inadvertently expose any sensitive functions or allow unauthorized access. Review all inherited functions for potential security risks and apply appropriate access controls if necessary.


Line range hint 41-46: Ensure Access Control is Appropriately Applied to the prove Function.

The prove function now includes the onlyRole(RELAYER_ROLE) modifier. Verify that all legitimate relayers have been assigned the RELAYER_ROLE and that unauthorized parties cannot access this function. Ensure that this change aligns with the desired access control policies.

Copy link
cloudflare-workers-and-pages bot commented Oct 21, 2024

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: b6b8708
Status: ✅  Deploy successful!
Preview URL: https://82e0b3f5.sanguine-fe.pages.dev
Branch Preview URL: https://feat-fbv2-multicall.sanguine-fe.pages.dev

View logs

@ChiTimesChi ChiTimesChi changed the title feat(contracts-rfq): Multicall in FastBridgeV2 feat(contracts-rfq): Multicall in FastBridgeV2 [SLT-369] Oct 21, 2024
* add manyActions multicall test

* increase manyAction count

* comment cleanup
Copy link
Contributor
@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: 1

🧹 Outside diff range and nitpick comments (3)
packages/contracts-rfq/test/integration/MulticallTarget.t.sol (3)

73-76: Add input validation to prevent potential overflows.

While the function works correctly, consider adding validation for the amountUnits parameter to prevent potential overflows when converting to wei.

 function dealTokens(address to, uint8 amountUnits) public {
+    require(to != address(0), "Invalid address");
+    require(amountUnits > 0, "Amount must be positive");
     uint256 amountWei = amountUnits * 1 ether;
     token.mint(to, amountWei);
     deal(to, amountWei);

132-136: Add NatSpec documentation for the struct.

Consider adding NatSpec documentation to explain the purpose and usage of this struct, which will improve code maintainability.

+/// @notice A struct that combines a bridge transaction with its encoded form and transaction ID
+/// @dev Used to track and verify transaction states throughout the test suite
 struct TestBridgeTransactionWithMetadata {
     IFastBridge.BridgeTransaction transaction;
     bytes encodedData;
     bytes32 txId;
 }

13-13: Consider parameterizing chain configuration.

The contract uses hardcoded chain IDs (1337, 7331). Consider making these configurable through constructor parameters or a configuration struct to improve test suite flexibility across different environments.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e3a9428 and b6b8708.

📒 Files selected for processing (1)
  • packages/contracts-rfq/test/integration/MulticallTarget.t.sol (8 hunks)
🔇 Additional comments (1)
packages/contracts-rfq/test/integration/MulticallTarget.t.sol (1)

36-38: LGTM! Good optimization with cached encoded transactions.

Storing encoded transactions as state variables is a good practice that reduces redundant encoding operations and improves test execution efficiency.

6FD2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0