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(contracts-rfq): Zaps [SLT-351] #3300

Merged
merged 11 commits into from
Oct 28, 2024
Merged

Conversation

ChiTimesChi
Copy link
Collaborator

@ChiTimesChi ChiTimesChi commented Oct 16, 2024

Description
This PR updates the terminology in FastBridgeV2:

  • NATIVE_GAS_TOKEN is used instead of ETH_ADDRESS to avoid confusion on chains where ETH is not a native gas token.
  • Zap is used instead of the older placeholder "arbitrary call" name.
    • zapNative is used to signal the amount of additional native gas token requested by the recipient.
    • zapData is used to signal the data to be passed to the recipient, when a Zap is triggered on the destination chain.
  • IZapRecipient is used instead of IFastBridgeRecipient.
  • Zap is triggered via a new function signature:
    function zap(address token, uint256 amount, bytes memory zapData) external payable returns (bytes4);

Additional context

Summary by CodeRabbit

  • New Features

    • Introduced zap functionality for enhanced bridge transactions.
    • Added a new interface IZapRecipient for improved contract interactions.
  • Bug Fixes

    • Updated error handling to align with new zap functionality, including the removal of outdated error declarations.
  • Documentation

    • Enhanced documentation comments for clarity on new parameters and structures.
  • Tests

    • Updated tests to reflect changes in naming and functionality related to zap transactions.

Copy link
Contributor

coderabbitai bot commented Oct 16, 2024

Walkthrough

The changes in this pull request involve significant updates to the FastBridgeV2 contract and related interfaces to incorporate a new zap functionality. Key modifications include replacing the IFastBridgeRecipient interface with IZapRecipient, updating method signatures and constants, and introducing new structures for handling bridge transactions. The changes also extend to various test contracts, which have been renamed and updated to reflect the new terminology and functionality.

Changes

File Path Change Summary
packages/contracts-rfq/contracts/FastBridgeV2.sol Replaced IFastBridgeRecipient with IZapRecipient, updated constants and method signatures to use zapNative and zapData, modified refund logic, and adjusted transaction handling functions.
packages/contracts-rfq/contracts/interfaces/IFastBridgeV2.sol Updated BridgeParamsV2 and BridgeTransactionV2 structs to use zapNative and zapData, with documentation comments revised for clarity.
packages/contracts-rfq/contracts/interfaces/IFastBridgeV2Errors.sol Removed two error declarations and added three new errors related to zap functionality.
packages/contracts-rfq/contracts/interfaces/IZapRecipient.sol Introduced new interface IZapRecipient with a zap function for handling zap interactions.
packages/contracts-rfq/contracts/libs/BridgeTransactionV2.sol Renamed fields and constants in BridgeTransactionV2Lib to align with zap functionality, updated validation and encoding functions accordingly.
packages/contracts-rfq/test/FastBridgeV2.Dst.Zap.t.sol Renamed test contract and updated constants and function names to reflect zap context.
packages/contracts-rfq/test/FastBridgeV2.Dst.t.sol Updated constants and function signatures to use zap terminology.
packages/contracts-rfq/test/FastBridgeV2.Encoding.t.sol Updated function signatures to compare zapNative and zapData instead of the previous parameters.
packages/contracts-rfq/test/FastBridgeV2.GasBench.Dst.Zap.t.sol Renamed test contract and updated function names to reflect zap functionality.
packages/contracts-rfq/test/FastBridgeV2.GasBench.Encoding.t.sol Updated test function names and internal logic to incorporate zap terminology.
packages/contracts-rfq/test/mocks/ExcessiveReturnValueRecipient.sol Updated to implement IZapRecipient, replacing the previous interface and renaming method to zap.
packages/contracts-rfq/test/mocks/IncorrectReturnValueRecipient.sol Updated to implement IZapRecipient, renaming method to zap.
packages/contracts-rfq/test/mocks/NoReturnValueRecipient.sol Renamed method fastBridgeTransferReceived to zap.
packages/contracts-rfq/test/mocks/NonPayableRecipient.sol Replaced fastBridgeTransferReceived method with zap.
packages/contracts-rfq/test/mocks/RecipientMock.sol Updated to implement IZapRecipient, replacing the previous interface and renaming method to zap.

Possibly related PRs

Suggested reviewers

  • aureliusbtc
  • parodime
  • trajan0x

🐰 In the meadow, changes bloom,
With zaps and bridges, there's plenty of room.
New paths to hop, with data in tow,
A dance of contracts, watch them flow!
With every update, we leap and cheer,
For brighter futures, the zaps draw near! 🌼


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between f55e6e1 and 5e51cfe.

📒 Files selected for processing (1)
  • packages/contracts-rfq/contracts/interfaces/IZapRecipient.sol (1 hunks)
🔇 Additional comments (3)
packages/contracts-rfq/contracts/interfaces/IZapRecipient.sol (3)

1-2: LGTM! Appropriate license and pragma version.

The MIT license is suitable, and the Solidity version ^0.8.20 is recent and secure.


4-6: Well-designed interface following best practices.

The interface is clean, follows Solidity best practices, and properly implements the new Zap functionality:

  • External visibility is correctly used
  • Payable modifier allows handling native gas token
  • Return type bytes4 suggests standard interface detection

4-6: Verify consistent implementation across the codebase.

Let's ensure all implementations of this interface are consistent.

✅ Verification successful

Let me try a different search strategy to find implementations of this interface.


Let me check the actual implementations in the found files to verify the consistency.


Interface implementation verification completed

The interface is consistently implemented across the codebase. The mock contracts in the test directory intentionally implement variations for testing purposes:

  • RecipientMock.sol: Correct implementation with matching signature and return value
  • IncorrectReturnValueRecipient.sol: Tests incorrect return value scenario
  • ExcessiveReturnValueRecipient.sol: Tests excessive return value scenario

These variations are expected as they are test mocks designed to verify the contract's behavior with different implementations.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all contracts implementing IZapRecipient interface
# and verify their zap function signatures

# Find all contract implementations
echo "Searching for IZapRecipient implementations..."
rg -l "contract.*implements.*IZapRecipient" 

# Find all zap function implementations
echo -e "\nVerifying zap function signatures..."
ast-grep --pattern 'function zap(address token, uint256 amount, bytes memory zapData) $$$'

Length of output: 330


Script:

#!/bin/bash
# Search for contract files that mention IZapRecipient
echo "Files referencing IZapRecipient:"
rg -l "IZapRecipient"

# Search for zap function implementations with context
echo -e "\nZap function implementations:"
rg -A 3 "function zap\s*\(address\s+token,\s*uint256\s+amount,\s*bytes\s+memory\s+zapData\)"

Length of output: 797


Script:

#!/bin/bash
# Check implementation in FastBridgeV2
echo "FastBridgeV2 implementation:"
rg -A 5 "function zap" packages/contracts-rfq/contracts/FastBridgeV2.sol

# Check implementations in mock files
echo -e "\nMock implementations:"
rg -A 5 "function zap" packages/contracts-rfq/test/mocks/IncorrectReturnValueRecipient.sol
rg -A 5 "function zap" packages/contracts-rfq/test/mocks/ExcessiveReturnValueRecipient.sol
rg -A 5 "function zap" packages/contracts-rfq/test/mocks/RecipientMock.sol

Length of output: 930


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.

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.

@ChiTimesChi ChiTimesChi changed the title refactor(contracts-rfq): Zaps refactor(contracts-rfq): Zaps [SLT-351] Oct 16, 2024
Copy link

github-actions bot commented Oct 16, 2024

Changes to gas cost

Generated at commit: aae4e7f8b5db29a2861f03f828d277916ce35d34, compared to commit: 2c1840981546a1cd0b27524f8abab0f55222b190

🧾 Summary (50% most significant diffs)

Contract Method Avg (+/-) %
FastBridgeV2 bridgeProofs
bridgeRelayDetails
canClaim
getBridgeTransaction
getBridgeTransactionV2
protocolFees
refund
senderNonces
+44 ❌
-111 ✅
+22 ❌
-67 ✅
-89 ✅
+22 ❌
-89 ✅
+22 ❌
+7.31%
-14.92%
+0.73%
-1.57%
-3.45%
+1.96%
-0.18%
+1.96%

Full diff report 👇
Contract Deployment Cost (+/-) Method Min (+/-) % Avg (+/-) % Median (+/-) % Max (+/-) % # Calls (+/-)
FastBridgeV2 3,209,186 (+9,716) GOVERNOR_ROLE
REFUNDER_ROLE
RELAYER_ROLE
bridge
bridgeProofs
bridgeRelayDetails
canClaim
claim(bytes)
claim(bytes,address)
dispute
getBridgeTransaction
getBridgeTransactionV2
grantRole
nonce
protocolFees
prove(bytes,bytes32)
prove(bytes32,bytes32,address)
refund
relay(bytes)
relay(bytes,address)
senderNonces
setProtocolFeeRate
316 (+22)
351 (+44)
329 (+44)
69,001 (+22)
646 (+44)
633 (-111)
3,033 (+22)
40,060 (+22)
42,923 (+22)
31,114 (+22)
4,193 (-67)
1,061 (-89)
101,427 (+22)
240 (-110)
645 (+22)
34,676 (+44)
32,083 (+22)
44,313 (-89)
61,348 (-87)
61,888 (+44)
647 (+22)
47,399 (+22)
+7.48%
+14.33%
+15.44%
+0.03%
+7.31%
-14.92%
+0.73%
+0.05%
+0.05%
+0.07%
-1.57%
-7.74%
+0.02%
-31.43%
+3.53%
+0.13%
+0.07%
-0.20%
-0.14%
+0.07%
+3.52%
+0.05%
316 (+22)
351 (+44)
329 (+44)
80,421 (+22)
646 (+44)
633 (-111)
3,033 (+22)
46,971 (+22)
48,584 (+22)
31,122 (+22)
4,193 (-67)
2,488 (-89)
114,559 (+22)
240 (-110)
1,145 (+22)
34,989 (+44)
32,091 (+22)
48,284 (-89)
67,790 (-84)
68,330 (+47)
1,147 (+22)
47,399 (+22)
+7.48%
+14.33%
+15.44%
+0.03%
+7.31%
-14.92%
+0.73%
+0.05%
+0.05%
+0.07%
-1.57%
-3.45%
+0.02%
-31.43%
+1.96%
+0.13%
+0.07%
-0.18%
-0.12%
+0.07%
+1.96%
+0.05%
316 (+22)
351 (+44)
329 (+44)
81,060 (+22)
646 (+44)
633 (-111)
3,033 (+22)
47,555 (+22)
49,168 (+22)
31,126 (+22)
4,193 (-67)
3,125 (-89)
118,527 (+22)
240 (-110)
645 (+22)
34,700 (+44)
32,095 (+22)
48,419 (-89)
67,725 (-83)
68,265 (+48)
647 (+22)
47,399 (+22)
+7.48%
+14.33%
+15.44%
+0.03%
+7.31%
-14.92%
+0.73%
+0.05%
+0.04%
+0.07%
-1.57%
-2.77%
+0.02%
-31.43%
+3.53%
+0.13%
+0.07%
-0.18%
-0.12%
+0.07%
+3.52%
+0.05%
316 (+22)
351 (+44)
329 (+44)
93,143 (+22)
646 (+44)
633 (-111)
3,033 (+22)
55,014 (+22)
55,377 (+22)
31,126 (+22)
4,193 (-67)
3,278 (-89)
118,527 (+22)
240 (-110)
2,645 (+22)
35,640 (+44)
32,095 (+22)
52,525 (-89)
76,918 (-78)
77,458 (+53)
2,647 (+22)
47,399 (+22)
+7.48%
+14.33%
+15.44%
+0.02%
+7.31%
-14.92%
+0.73%
+0.04%
+0.04%
+0.07%
-1.57%
-2.64%
+0.02%
-31.43%
+0.84%
+0.12%
+0.07%
-0.17%
-0.10%
+0.07%
+0.84%
+0.05%
21 (0)
67 (0)
134 (0)
260 (0)
12 (0)
12 (0)
12 (0)
6 (0)
6 (0)
6 (0)
1 (0)
3 (0)
289 (0)
4 (0)
536 (0)
68 (0)
68 (0)
12 (0)
6 (0)
6 (0)
248 (0)
21 (0)

Copy link

codecov bot commented Oct 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 34.85584%. Comparing base (f9da790) to head (5e51cfe).
Report is 15 commits behind head on master.

Additional details and impacted files
@@                 Coverage Diff                 @@
##              master       #3300         +/-   ##
===================================================
- Coverage   34.85970%   34.85584%   -0.00386%     
===================================================
  Files            529         529                 
  Lines          33784       33782          -2     
  Branches          82          82                 
===================================================
- Hits           11777       11775          -2     
  Misses         20987       20987                 
  Partials        1020        1020                 
Flag Coverage Δ
packages 90.44834% <ø> (ø)
solidity 98.64865% <100.00000%> (-0.00907%) ⬇️

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

🧹 Outside diff range and nitpick comments (19)
packages/contracts-rfq/test/mocks/NonPayableRecipient.sol (1)

11-12: Function updated to align with new terminology.

The fastBridgeTransferReceived function has been correctly replaced with zap, aligning with the PR objectives. The function signature and return type remain the same, ensuring compatibility. The return statement has been appropriately updated to use the new function selector.

However, consider adding a comment explaining why this function is intentionally not payable, as it might not be immediately clear to other developers that this is a mock for testing incorrect implementations.

 /// @notice Incorrectly implemented - method is not payable.
+/// @dev This function is intentionally not payable to test handling of incorrect implementations.
 function zap(address, uint256, bytes memory) external pure returns (bytes4) {
     return NonPayableRecipient.zap.selector;
 }
packages/contracts-rfq/contracts/interfaces/IFastBridgeV2Errors.sol (1)

Line range hint 1-28: Overall changes look good, consider adding comments

The modifications to the IFastBridgeV2Errors interface are consistent with the PR objectives and maintain the interface's structure and purpose. The new error declarations provide clear indications of their use cases related to Zap functionality.

Consider adding brief comments above each error declaration to explain when these errors are thrown. This would enhance the interface's self-documentation and make it easier for developers to understand and use these errors correctly.

Example:

/// @dev Thrown when the length of zapData exceeds the maximum allowed
error ZapDataLengthAboveMax();

/// @dev Thrown when a zap with native token is attempted but not supported
error ZapNativeNotSupported();
packages/contracts-rfq/test/mocks/RecipientMock.sol (1)

15-18: LGTM: Zap function implemented correctly with a minor suggestion.

The zap function has been correctly implemented to replace the fastBridgeTransferReceived function. It properly returns the selector for interface compliance and includes the payable modifier.

For improved clarity, consider adding parameter names even if they're unused:

-    function zap(address, uint256, bytes memory) external payable returns (bytes4) {
+    function zap(address token, uint256 amount, bytes memory data) external payable returns (bytes4) {
         return IZapRecipient.zap.selector;
     }

This change would make the function signature more self-documenting without affecting its behavior.

packages/contracts-rfq/test/mocks/ExcessiveReturnValueRecipient.sol (1)

16-18: LGTM: zap function implemented correctly for testing purposes.

The new zap function correctly replaces the old fastBridgeTransferReceived function and aligns with the new zap functionality. The implementation is suitable for its purpose as a mock contract for testing.

Consider updating the comment above the function to reflect the new zap functionality:

-    /// @notice Incorrectly implemented - method returns excessive bytes.
+    /// @notice Incorrectly implemented zap function - method returns excessive bytes for testing purposes.
packages/contracts-rfq/test/mocks/IncorrectReturnValueRecipient.sol (2)

8-8: LGTM: Contract declaration updated correctly.

The contract declaration has been properly updated to implement the new IZapRecipient interface, which is consistent with the PR objectives.

Consider updating the contract comment to reflect the new Zap terminology:

- /// @notice Incorrectly implemented recipient mock for testing purposes. DO NOT USE IN PRODUCTION.
+ /// @notice Incorrectly implemented Zap recipient mock for testing purposes. DO NOT USE IN PRODUCTION.

16-18: LGTM: Zap function implemented correctly.

The zap function has been properly implemented to replace the previous fastBridgeTransferReceived function. The changes are consistent with the new IZapRecipient interface and maintain the intentional incorrect behavior for testing purposes.

Consider updating the function comment to reflect the new Zap terminology:

- /// @notice Incorrectly implemented - method returns incorrect value.
+ /// @notice Incorrectly implemented Zap function - method returns incorrect value.
packages/contracts-rfq/test/FastBridgeV2.GasBench.Src.Zap.t.sol (1)

11-20: LGTM: createFixturesV2 implementation is correct and comprehensive.

The createFixturesV2 function correctly overrides the parent implementation and extends it with Zap-specific data. The creation and setting of mockZapData for various transaction types ensure thorough testing of the Zap functionality.

Consider extracting the keccak256("Random ID") into a constant or a function parameter for better maintainability and flexibility in testing different scenarios.

packages/contracts-rfq/test/FastBridgeV2.GasBench.Dst.Zap.t.sol (1)

27-29: LGTM: Variable and method names updated to use "Zap" terminology.

The changes in the createFixturesV2 function are consistent with the shift to "Zap" terminology:

  1. Variable renamed from mockCallParams to mockZapData.
  2. Method calls updated to setTokenTestZapData and setEthTestZapData.

These changes maintain consistency while preserving the existing data structure.

Consider adding a brief comment explaining the structure of mockZapData to improve code readability. For example:

// mockZapData structure: (address user, bytes32 randomId)
bytes memory mockZapData = abi.encode(userA, keccak256("Random ID"));
packages/contracts-rfq/test/libs/BridgeTransactionV2.t.sol (2)

32-37: LGTM! Consider adding comments for clarity.

The changes correctly update the field names from callValue to zapNative and callParams to zapData, aligning with the new terminology introduced in the PR objectives.

Consider adding a brief comment explaining the purpose of zapNative and zapData for improved readability:

+       // Assert the amount of additional native gas token requested by the recipient
        assertEq(a.zapNative, b.zapNative);
        assertEq(a.deadline, b.deadline);
        assertEq(a.nonce, b.nonce);
        assertEq(a.exclusivityRelayer, b.exclusivityRelayer);
        assertEq(a.exclusivityEndTime, b.exclusivityEndTime);
+       // Assert the data to be sent to the recipient when a Zap is activated
        assertEq(a.zapData, b.zapData);

57-57: LGTM! Consider adding a comment for consistency.

The change from callParams to zapData correctly aligns with the new terminology introduced in the PR objectives. This update accurately reflects the changes in the BridgeTransactionV2 structure.

For consistency with the earlier suggestion, consider adding a brief comment explaining the purpose of zapData:

        assertEq(harness.exclusivityRelayer(encodedTx), bridgeTx.exclusivityRelayer);
        assertEq(harness.exclusivityEndTime(encodedTx), bridgeTx.exclusivityEndTime);
+       // Assert the data to be sent to the recipient when a Zap is activated
        assertEq(harness.zapData(encodedTx), bridgeTx.zapData);
packages/contracts-rfq/test/FastBridgeV2.Encoding.t.sol (1)

59-59: LGTM: Correct implementation of V2 to V1 mapping

The updated assignment correctly maps the zapNative field from V2 to the sendChainGas field in V1, aligning with the explanation in the comment. This change ensures proper compatibility between the two versions.

For improved readability, consider using a named constant for the comparison:

- expectedTx.sendChainGas = bridgeTxV2.zapNative > 0;
+ const uint256 NO_ZAP = 0;
+ expectedTx.sendChainGas = bridgeTxV2.zapNative > NO_ZAP;

This makes the intention clearer and easier to maintain if the definition of "no zap" changes in the future.

packages/contracts-rfq/contracts/interfaces/IFastBridgeV2.sol (3)

33-38: LGTM! Consider adding more context to the zapNative comment.

The new comments provide clear explanations for the zapNative and zapData fields. The restriction on zapNative usage is important to prevent misuse.

Consider expanding the comment for zapNative to explain why it can't be used with the native token:

/// @param zapNative                ETH value to send to the recipient (if any). Can't be used with native token to prevent double-spending.

60-60: LGTM! Consider clarifying the comment for better understanding.

The renaming of callValue to zapNative is consistent with the changes in BridgeParamsV2. The added comment provides useful context about the replacement of V1's sendChainGas flag.

Consider slightly rewording the comment for clarity:

uint256 zapNative; // ETH value to send to the recipient (if any) - replaces V1's sendChainGas functionality

65-65: LGTM! Consider adding a comment for consistency.

The renaming of callParams to zapData is consistent with the changes in BridgeParamsV2.

For consistency with the BridgeParamsV2 struct, consider adding a comment to explain the zapData field:

bytes zapData; // Parameters for the Zap to the destination recipient (if any)
packages/contracts-rfq/test/FastBridgeV2.t.sol (3)

164-165: LGTM: Terminology updated as per PR objectives.

The replacement of "callValue" with "zapNative" and "callParams" with "zapData" in both tokenParamsV2 and ethParamsV2 structures aligns with the PR objectives. This consistent update enhances code clarity.

Consider adding a brief comment explaining the purpose of zapNative and zapData for better documentation, especially for developers new to the concept of "Zaps".

Also applies to: 171-172


219-226: LGTM: Ethereum-related functions updated consistently.

The Ethereum-related functions have been updated in line with the token-related functions, maintaining consistency across the codebase. The changes from "callParams" to "zapData" and "callValue" to "zapNative" are applied correctly.

For consistency with the token-related functions, consider adding brief comments explaining the purpose of zapNative and zapData in the Ethereum context as well.


Line range hint 1-300: Overall assessment: Changes are consistent and align with PR objectives.

The modifications in this file successfully update the terminology from "call" to "zap" across various functions and structures. These changes are consistent with the PR objectives and improve the clarity of the code. The test file has been updated appropriately without unnecessary modifications to test utility contracts, respecting the retrieved learning.

Consider adding a brief comment at the beginning of the file explaining the transition from "call" to "zap" terminology. This would provide context for the changes and help future developers understand the rationale behind the new naming conventions.

packages/contracts-rfq/test/FastBridgeV2.Src.Zap.t.sol (2)

6-6: Consider providing justification for disabling Solhint rules.

The directive // solhint-disable func-name-mixedcase, ordering disables linting for function naming and ordering conventions. Adding a comment to explain why these rules are disabled can enhance code clarity and maintainability.


8-9: Add comments to clarify the purpose of constants.

Including comments for ZAP_DATA and ZAP_NATIVE would improve readability by explaining their roles in the test scenarios.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 5bce10b and f8665f5.

📒 Files selected for processing (24)
  • packages/contracts-rfq/contracts/FastBridgeV2.sol (14 hunks)
  • packages/contracts-rfq/contracts/interfaces/IFastBridgeRecipient.sol (0 hunks)
  • packages/contracts-rfq/contracts/interfaces/IFastBridgeV2.sol (2 hunks)
  • packages/contracts-rfq/contracts/interfaces/IFastBridgeV2Errors.sol (1 hunks)
  • packages/contracts-rfq/contracts/interfaces/IZapRecipient.sol (1 hunks)
  • packages/contracts-rfq/contracts/libs/BridgeTransactionV2.sol (6 hunks)
  • packages/contracts-rfq/test/FastBridgeV2.Dst.Zap.t.sol (11 hunks)
  • packages/contracts-rfq/test/FastBridgeV2.Dst.t.sol (7 hunks)
  • packages/contracts-rfq/test/FastBridgeV2.Encoding.t.sol (1 hunks)
  • packages/contracts-rfq/test/FastBridgeV2.GasBench.Dst.Zap.t.sol (2 hunks)
  • packages/contracts-rfq/test/FastBridgeV2.GasBench.Encoding.t.sol (1 hunks)
  • packages/contracts-rfq/test/FastBridgeV2.GasBench.Src.ArbitraryCall.t.sol (0 hunks)
  • packages/contracts-rfq/test/FastBridgeV2.GasBench.Src.Zap.t.sol (1 hunks)
  • packages/contracts-rfq/test/FastBridgeV2.Src.ArbitraryCall.t.sol (0 hunks)
  • packages/contracts-rfq/test/FastBridgeV2.Src.Zap.t.sol (1 hunks)
  • packages/contracts-rfq/test/FastBridgeV2.Src.t.sol (1 hunks)
  • packages/contracts-rfq/test/FastBridgeV2.t.sol (4 hunks)
  • packages/contracts-rfq/test/harnesses/BridgeTransactionV2Harness.sol (2 hunks)
  • packages/contracts-rfq/test/libs/BridgeTransactionV2.t.sol (2 hunks)
  • packages/contracts-rfq/test/mocks/ExcessiveReturnValueRecipient.sol (2 hunks)
  • packages/contracts-rfq/test/mocks/IncorrectReturnValueRecipient.sol (1 hunks)
  • packages/contracts-rfq/test/mocks/NoReturnValueRecipient.sol (1 hunks)
  • packages/contracts-rfq/test/mocks/NonPayableRecipient.sol (1 hunks)
  • packages/contracts-rfq/test/mocks/RecipientMock.sol (1 hunks)
💤 Files with no reviewable changes (3)
  • packages/contracts-rfq/contracts/interfaces/IFastBridgeRecipient.sol
  • packages/contracts-rfq/test/FastBridgeV2.GasBench.Src.ArbitraryCall.t.sol
  • packages/contracts-rfq/test/FastBridgeV2.Src.ArbitraryCall.t.sol
🧰 Additional context used
📓 Learnings (6)
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/contracts/interfaces/IFastBridgeV2.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/FastBridgeV2.Encoding.t.sol (1)
Learnt from: ChiTimesChi
PR: synapsecns/sanguine#3284
File: packages/contracts-rfq/test/FastBridgeV2.Src.Base.t.sol:97-97
Timestamp: 2024-10-14T13:23:04.509Z
Learning: In `packages/contracts-rfq/test/FastBridgeV2.t.sol`, when testing expected revert behaviors, `abi.encodeWithSelector` is used with custom errors and should not be replaced with `BridgeTransactionV2Lib.encodeV2`.
packages/contracts-rfq/test/FastBridgeV2.GasBench.Src.Zap.t.sol (2)
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.
packages/contracts-rfq/test/FastBridgeV2.Src.t.sol (5)
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.
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.
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.Src.Base.t.sol:97-97
Timestamp: 2024-10-14T13:23:04.509Z
Learning: In `packages/contracts-rfq/test/FastBridgeV2.t.sol`, when testing expected revert behaviors, `abi.encodeWithSelector` is used with custom errors and should not be replaced with `BridgeTransactionV2Lib.encodeV2`.
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.
packages/contracts-rfq/test/FastBridgeV2.t.sol (1)
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.
🪛 GitHub Check: Slither
packages/contracts-rfq/contracts/libs/BridgeTransactionV2.sol

[warning] 227-232: Assembly usage
BridgeTransactionV2Lib.zapNative(bytes) (contracts/libs/BridgeTransactionV2.sol#227-232) uses assembly
- INLINE ASM (contracts/libs/BridgeTransactionV2.sol#229-231)

🔇 Additional comments (71)
packages/contracts-rfq/contracts/interfaces/IZapRecipient.sol (3)

1-2: LGTM: Appropriate license and Solidity version.

The file header correctly specifies the MIT license and uses a recent Solidity version (^0.8.0), which is suitable for this project.


4-4: LGTM: Well-defined interface name.

The IZapRecipient interface is appropriately named, following the convention of prefixing interfaces with 'I'. This aligns with the PR objectives of updating terminology and introducing the Zap functionality.


5-5: LGTM: Well-defined zap function, with a minor clarification needed.

The zap function signature is well-defined and aligns with the PR objectives:

  • It includes parameters for token, amount, and zapData as described in the PR summary.
  • The payable modifier allows it to receive native tokens, consistent with the zapNative concept.

However, could you please clarify the purpose of the bytes4 return type? Is this intended for selector compatibility or another specific use case?

To ensure consistency across the codebase, let's check for other occurrences of similar function signatures:

✅ Verification successful

To accurately search for zap function signatures in Solidity files, please execute the following script:


Verified: zap function signature is consistent across the codebase.

  • The zap function in IZapRecipient.sol and its mock implementations consistently use the bytes4 return type for selector compatibility.
  • No additional implementations outside of test mocks were found, ensuring no conflicting signatures.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for similar zap function signatures in the codebase
rg --type solidity 'function\s+zap\s*\(' -A 3

Length of output: 80


Script:

#!/bin/bash
# Search for similar zap function signatures in Solidity files
rg 'function\s+zap\s*\(' --glob '*.sol' -A 3

Length of output: 2073

packages/contracts-rfq/test/mocks/NoReturnValueRecipient.sol (2)

Line range hint 1-15: Reminder: Maintain mock contract integrity.

While not directly related to the changes, it's important to note:

  1. The contract is correctly marked as "DO NOT USE IN PRODUCTION" in the comments.
  2. The empty testNoReturnValueRecipient function serves to exclude this contract from coverage reports.

These features are crucial for maintaining the integrity and purpose of this mock contract. Ensure they are preserved in future modifications.


14-14: Function renamed to align with new terminology.

The function has been correctly renamed from fastBridgeTransferReceived to zap, which aligns with the PR objectives of updating terminology. The function signature and implementation remain the same, maintaining its purpose as an incorrectly implemented mock for testing.

To ensure consistency across the codebase, let's verify the usage of this new function name:

✅ Verification successful

Function renaming verified successfully.

No references to fastBridgeTransferReceived were found. The zap function is consistently used across relevant contracts.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining references to 'fastBridgeTransferReceived' and new uses of 'zap'

echo "Checking for any remaining references to 'fastBridgeTransferReceived':"
rg --type solidity 'fastBridgeTransferReceived'

echo "Checking for new uses of 'zap' function:"
rg --type solidity 'function zap\('

Length of output: 405


Script:

#!/bin/bash
# Description: Check for any remaining references to 'fastBridgeTransferReceived' and new uses of 'zap' function in Solidity files

echo "Checking for any remaining references to 'fastBridgeTransferReceived':"
rg 'fastBridgeTransferReceived' -g '*.sol'

echo "Checking for new uses of 'zap' function:"
rg 'function zap\(' -g '*.sol'

Length of output: 1218

packages/contracts-rfq/contracts/interfaces/IFastBridgeV2Errors.sol (1)

11-12: LGTM: New error declarations align with PR objectives

The new error declarations ZapDataLengthAboveMax() and ZapNativeNotSupported() are well-aligned with the PR objectives of introducing Zap functionality and updating terminology. These errors effectively replace the removed CallParamsLengthAboveMax() and NativeTokenCallValueNotSupported(), maintaining the interface's error handling capabilities while reflecting the new Zap-related concepts.

packages/contracts-rfq/test/mocks/RecipientMock.sol (2)

8-8: LGTM: Contract signature updated correctly.

The contract now implements the IZapRecipient interface, which is consistent with the PR objectives to update terminology and introduce new zap functionality.


4-4: LGTM: Import statement updated correctly.

The import statement has been properly updated to reflect the new IZapRecipient interface, which aligns with the PR objectives.

To ensure the import path is correct, please run the following command:

✅ Verification successful

✅ Verified: Import statement correctly updated.

The IZapRecipient interface exists, confirming that the import path is accurate and functional.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify the existence and content of the IZapRecipient interface file
fd -e sol -x cat {} | rg -U "interface IZapRecipient"

Length of output: 83

packages/contracts-rfq/test/mocks/ExcessiveReturnValueRecipient.sol (2)

4-4: LGTM: Import statement updated correctly.

The import statement has been appropriately updated to use IZapRecipient, which aligns with the new zap functionality introduced in this PR.


Line range hint 1-20: Overall changes are appropriate and consistent.

The modifications to this mock contract align well with the PR objectives:

  1. The import statement has been updated to use IZapRecipient.
  2. The fastBridgeTransferReceived function has been replaced with a zap function, maintaining the same purpose of returning excessive bytes for testing.
  3. The rest of the contract, including its name, receive function, and test function, remains unchanged.

These changes appropriately reflect the new zap functionality while maintaining the contract's purpose as a mock for testing.

packages/contracts-rfq/test/mocks/IncorrectReturnValueRecipient.sol (1)

4-4: LGTM: Import statement updated correctly.

The import statement has been properly updated to reflect the new IZapRecipient interface, which aligns with the PR objectives of introducing Zap functionality.

packages/contracts-rfq/test/FastBridgeV2.GasBench.Src.Zap.t.sol (2)

6-7: LGTM: Contract declaration and inheritance are appropriate.

The contract name FastBridgeV2GasBenchmarkSrcZapTest clearly indicates its purpose as a Zap-specific extension of the existing gas benchmark test. The inheritance from FastBridgeV2GasBenchmarkSrcTest is correct, allowing for the addition of Zap-related functionality while maintaining the base test structure.


8-9: LGTM: Empty test function serves its purpose.

The testFastBridgeV2GasBenchmarkSrcZapTest function, although empty, serves a specific purpose as explained in the comment. It prevents this contract from appearing in the coverage report, which is a valid approach for specialized test contracts like this one.

packages/contracts-rfq/test/FastBridgeV2.GasBench.Dst.Zap.t.sol (3)

8-8: LGTM: Contract name updated to reflect new functionality.

The contract name change from FastBridgeV2GasBenchmarkDstArbitraryCallTest to FastBridgeV2GasBenchmarkDstZapTest accurately reflects the shift from "arbitrary call" to "Zap" functionality, aligning with the PR objectives.


9-11: LGTM: Comments updated to reflect new terminology.

The comments have been appropriately updated to replace "arbitrary call" with "Zap", maintaining consistency with the new terminology while preserving the clarity of the explanation.


16-16: LGTM: Test function name updated.

The function name change from testFastBridgeV2GasBenchmarkDstArbitraryCallTest to testFastBridgeV2GasBenchmarkDstZapTest is consistent with the contract name change and maintains its purpose as a placeholder for coverage reports.

packages/contracts-rfq/test/libs/BridgeTransactionV2.t.sol (2)

52-52: LGTM! Correct update to new terminology.

The change from callValue to zapNative is consistent with the new terminology introduced in the PR objectives. This update correctly reflects the changes in the BridgeTransactionV2 structure.


Line range hint 1-67: Summary: Successful update of terminology in test contract

The changes in this file consistently update the terminology from callValue to zapNative and callParams to zapData throughout the test contract. These updates align well with the PR objectives of introducing new zap functionality and enhancing clarity.

Key points:

  1. The assertEq function has been updated to compare the new fields.
  2. The test_roundtrip function now asserts the new zapNative and zapData fields.
  3. The overall structure and logic of the tests remain intact, ensuring that existing functionality is still properly tested.

These changes successfully reflect the updates made to the BridgeTransactionV2 structure while maintaining the integrity of the test suite.

packages/contracts-rfq/test/harnesses/BridgeTransactionV2Harness.sol (3)

75-77: LGTM! Verify the corresponding library function.

The change from callParams to zapData aligns with the PR objectives and maintains the same behavior. The implementation looks correct.

To ensure consistency, let's verify the corresponding library function:

#!/bin/bash
# Description: Verify the existence and signature of zapData function in BridgeTransactionV2Lib

# Test: Search for the zapData function in BridgeTransactionV2Lib
ast-grep --lang solidity --pattern 'function zapData(bytes calldata encodedTx) internal pure returns (bytes calldata) { $$$$ }'

Line range hint 1-77: Overall changes look good. Consider checking for consistency across the project.

The updates in this file accurately reflect the new terminology (zap instead of call) as outlined in the PR objectives. The changes are minimal and focused, which is good for maintainability.

To ensure project-wide consistency, let's check for any remaining instances of the old terminology:

#!/bin/bash
# Description: Check for any remaining instances of 'callValue' or 'callParams' in Solidity files

# Test: Search for 'callValue' and 'callParams' in all Solidity files
rg --type solidity -e 'callValue' -e 'callParams'

If this search returns any results, consider updating those instances as well to maintain consistency across the project.


55-57: LGTM! Verify the corresponding library function.

The change from callValue to zapNative aligns with the PR objectives and maintains the same behavior. The implementation looks correct.

To ensure consistency, let's verify the corresponding library function:

packages/contracts-rfq/test/FastBridgeV2.Encoding.t.sol (1)

53-54: LGTM: Clear and informative comment update

The updated comment provides a clear explanation of the relationship between sendChainGas in V1 and zapNative in V2 of the bridge transaction structure. This helps developers understand the changes in the data structure and the expected behavior.

packages/contracts-rfq/contracts/interfaces/IFastBridgeV2.sol (1)

43-44: LGTM! Field names updated to reflect new terminology.

The renaming of callValue to zapNative and callParams to zapData aligns well with the new terminology introduced in the PR objectives. These changes enhance clarity and consistency within the codebase.

packages/contracts-rfq/test/FastBridgeV2.t.sol (3)

80-83: LGTM: Updated comments align with new terminology.

The changes in these comments accurately reflect the transition from "callParams" to "zapData", which is consistent with the PR objectives. The comments provide clear explanations for creating invalid and mock requests, enhancing code readability.


200-202: LGTM: Function updated to use new "zapData" terminology.

The function setTokenTestZapData has been correctly updated to reflect the new terminology. It properly sets the zapData for both tokenParamsV2 and tokenTx, maintaining consistency with the PR objectives.


205-207: LGTM: Function updated to use new "zapNative" terminology.

The function setTokenTestZapNative has been appropriately updated to align with the new terminology. It correctly sets the zapNative value for both tokenParamsV2 and tokenTx, maintaining consistency with the PR objectives.

packages/contracts-rfq/test/FastBridgeV2.Dst.t.sol (13)

26-26: Constant renamed from CALL_VALUE to ZAP_NATIVE

The constant CALL_VALUE has been renamed to ZAP_NATIVE. This change improves clarity by using terminology consistent with the new "Zap" functionality.


60-61: Function renamed from assertEmptyCallParams to assertEmptyZapData

The function assertEmptyCallParams has been renamed to assertEmptyZapData. This change aligns with the new terminology and improves code readability.


72-72: Updated chainGasAmount calculation

The calculation of chainGasAmount now uses bridgeTx.zapNative instead of bridgeTx.callValue. This change is consistent with the new terminology and functionality.


161-168: New test case for token relay with ZapNative

This new test case verifies the behavior of relaying a token transaction with a non-zero ZapNative value. It checks if the correct amount is transferred to the recipient.


171-178: New test case for token relay with RelayerAddress and ZapNative

This test case is similar to the previous one but includes a relayer address. It verifies that the correct amount is transferred to the recipient when using both a relayer address and a non-zero ZapNative value.


183-184: Updated test cases for excessive return value recipient

These test cases have been updated to use zapData instead of callParams. They now include checks to ensure that the tests succeed when zapData is empty and are set up to be overridden in derived tests where zapData is present.

Also applies to: 186-187, 192-196, 201-205, 208-215, 218-219, 224-228


235-236: Updated test cases for incorrect return value recipient

Similar to the excessive return value recipient tests, these test cases have been updated to use zapData instead of callParams. They are set up to succeed when zapData is empty and can be overridden in derived tests.

Also applies to: 238-239, 244-248, 253-257, 260-267, 270-271, 276-280


298-302: New test cases for non-payable recipient with ZapNative

These new test cases verify that attempting to relay a token transaction with a non-zero ZapNative value to a non-payable recipient results in a revert. This is important for ensuring correct behavior when dealing with non-payable contracts.

Also applies to: 305-309


326-327: Updated test cases for no-op recipient

These test cases have been updated to use zapData instead of callParams. They are set up to succeed when zapData is empty and can be overridden in derived tests where zapData is present.

Also applies to: 329-330, 335-336, 341-345, 348-352, 355-356, 361-362


369-370: Updated test cases for no return value recipient

These test cases have been updated to use zapData instead of callParams. They are set up to succeed when zapData is empty and can be overridden in derived tests where zapData is present.

Also applies to: 372-373, 378-379, 384-388, 391-398, 401-402, 407-408


494-503: New test cases for token relay with ZapNative reverts

These new test cases verify that attempting to relay a token transaction with incorrect ZapNative values (zero, lower, or higher than expected) results in a revert. This ensures that the contract correctly handles invalid ZapNative amounts.

Also applies to: 506-509, 512-521, 524-527


530-538: New test cases for ETH relay with ZapNative reverts

These new test cases verify that attempting to relay an ETH transaction with a non-zero ZapNative value results in a revert. This is important as ZapNative is not supported for ETH transactions.

Also applies to: 541-552


Line range hint 1-638: Overall assessment of changes

The modifications in this file are comprehensive and align well with the introduction of the "Zap" functionality. Key points:

  1. Consistent renaming from CALL_VALUE to ZAP_NATIVE and callParams to zapData.
  2. New test cases added to cover ZapNative functionality for both token and ETH transactions.
  3. Existing test cases updated to accommodate the new terminology and potential zapData presence.
  4. Edge cases and error conditions are well-covered, especially for non-payable recipients and incorrect ZapNative values.

These changes enhance the test coverage and ensure that the new "Zap" functionality is thoroughly validated. The code maintains good readability and follows consistent naming conventions.

packages/contracts-rfq/test/FastBridgeV2.Src.t.sol (1)

47-47: LGTM. Verify consistent usage of zapNative across the codebase.

The change from bridgeTx.callValue > 0 to bridgeTx.zapNative > 0 for determining sendChainGas aligns with the new zap functionality introduced in this PR. This modification appears to be correct and consistent with the PR objectives.

To ensure this change is applied consistently, please run the following script to check for any remaining instances of callValue that might need to be updated:

packages/contracts-rfq/test/FastBridgeV2.Src.Zap.t.sol (2)

32-44: Ensure correct error handling for zapData length exceeding maximum.

The tests correctly expect a revert with ZapDataLengthAboveMax.selector when zapData exceeds the maximum allowed length. Verify that this behavior aligns with the contract's intended functionality and that the error message provides clear guidance.


86-96: Verify the handling of zapNative in ETH bridging scenarios.

The tests correctly expect a revert with ZapNativeNotSupported.selector when attempting to bridge ETH with zapNative. Ensure that this restriction is intentional and documented in the contract's specifications.

packages/contracts-rfq/contracts/libs/BridgeTransactionV2.sol (7)

25-26: Offsets for zapNative and zapData are correctly defined

The offsets for the new fields zapNative and zapData in the packed BridgeTransactionV2 struct are accurately specified, ensuring proper data alignment.


42-43: Constants for new offsets are appropriately added

The constants OFFSET_ZAP_NATIVE and OFFSET_ZAP_DATA are defined with correct values corresponding to the struct layout.


53-53: Validation length check updated to include new fields

The validateV2 function's length check now accounts for the new zapData field, ensuring that the encoded transaction is of sufficient length.


83-85: encodeV2 function correctly includes new Zap fields

The encodeV2 function now includes bridgeTx.zapNative and bridgeTx.zapData, ensuring the new Zap fields are encoded properly.


110-111: decodeV2 function properly decodes new Zap fields

The decodeV2 function has been updated to decode zapNative and zapData, correctly populating the bridgeTx struct with the new fields.


226-230: Efficient extraction of zapNative using assembly

The zapNative function uses inline assembly to efficiently extract the zapNative value from the encoded transaction. The assembly code is correctly implemented.


234-236: zapData extraction via slicing is accurate

The zapData function correctly extracts the zapData from the encoded transaction using slicing, handling variable-length data appropriately.

packages/contracts-rfq/test/FastBridgeV2.Dst.Zap.t.sol (7)

11-12: Contract and constant renamed to reflect Zap functionality.

The renaming of the contract to FastBridgeV2DstZapTest and the constant to ZAP_DATA aligns with the updated terminology and enhances code clarity.


24-25: Fixture setup methods updated with ZapData.

The calls to setTokenTestZapData(ZAP_DATA) and setEthTestZapData(ZAP_DATA) correctly update the test setup to use ZAP_DATA, ensuring the tests are configured for the new Zap functionality.


52-53: Expected calldata updated for Zap function call.

The getExpectedCalldata function now correctly encodes the call to RecipientMock.zap with the updated parameters, matching the new function signature and ensuring accurate test assertions.


Line range hint 84-234: Test function names updated to reflect ZapData usage.

The renaming of test functions from "CallParams" to "ZapData" throughout the file enhances consistency and accurately reflects the updated functionality. This change improves code readability and maintains alignment with the new terminology.


Line range hint 242-282: Test cases for no return value recipient updated appropriately.

The updates to test functions handling noReturnValueRecipient cases with ZapData ensure that scenarios where the recipient does not return a value are properly tested under the new Zap functionality.


306-317: Added tests for recipient reverts with ZapNative.

The inclusion of tests that handle recipient reverts when ZapNative is present strengthens the test suite by covering additional edge cases, ensuring robust error handling in the contract.


332-342: Updated tests for relaying ETH without ZapData.

The tests test_relay_eth_noZapData_revert_recipientReverts and test_relay_eth_withRelayerAddress_noZapData_revert_recipientReverts have been appropriately updated to handle cases where no ZapData is provided, verifying the contract's behavior in these scenarios.

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

14-14: Importing IZapRecipient interface is appropriate.

The import statement correctly includes the IZapRecipient interface, which is necessary for implementing the new Zap functionality in the contract.


22-23: Define NATIVE_GAS_TOKEN constant appropriately.

The NATIVE_GAS_TOKEN constant is set to the commonly used placeholder address 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE, representing the native gas token on various networks. Ensure this address is used consistently across all contracts and aligns with any external libraries or standards used.


34-35: MAX_ZAP_DATA_LENGTH is appropriately defined.

The maximum length of zapData is set to 2 ** 16 - 1 (65535 bytes), which should be sufficient for the intended use cases. This limit helps prevent excessively large data payloads that could increase gas costs or processing time.


62-63: Initialize zapNative and zapData with default values in legacy bridge function.

The legacy bridge function sets zapNative to 0 and zapData to an empty byte array. This ensures backward compatibility and prevents unintended behavior when the new parameters are not provided.


Line range hint 122-126: Refund logic correctly handles native gas token and ERC20 tokens.

In the refund function, the contract appropriately checks if the token is the NATIVE_GAS_TOKEN and uses Address.sendValue for native token refunds and IERC20.safeTransfer for ERC20 tokens. This ensures that refunds are handled safely and correctly based on the token type.


Line range hint 140-157: getBridgeTransaction maintains backward compatibility.

The getBridgeTransaction function attempts to decode the request into a V2 transaction. If successful, it maps the V2 structure to the V1 format, handling zapNative as a zero/non-zero flag and ignoring zapData. This approach maintains backward compatibility with existing interfaces while introducing new functionality.


206-207: Include zapNative and zapData in bridge transaction encoding.

The bridge function correctly incorporates zapNative and zapData from paramsV2 when encoding the bridge transaction. This integration ensures that the new Zap functionality is properly included in the transaction data.


222-222: Update sendChainGas flag based on zapNative in BridgeRequested event.

In the emit BridgeRequested statement, the sendChainGas parameter is set to true when zapNative is non-zero. This accurately reflects whether additional native gas token is requested by the recipient.


236-240: Extract zapNative from the request for use in relay processing.

The zapNative value is correctly retrieved from the request using request.zapNative(). This value is essential for determining if additional native gas token should be forwarded during the relay process.


252-252: Set chainGasAmount in BridgeRelayed event based on zapNative.

The chainGasAmount parameter in the BridgeRelayed event is accurately set to zapNative, indicating the amount of additional native gas token involved in the relay.


257-259: Correctly disallow zapNative when token is NATIVE_GAS_TOKEN.

The contract checks if token is the NATIVE_GAS_TOKEN and reverts with ZapNativeNotSupported() if zapNative is not zero. This ensures that additional native gas token is not incorrectly requested when the destination token is already the native gas token.


284-289: Handle scenarios where zapData is missing but msg.value is sent.

The code appropriately transfers the full msg.value to the recipient when zapData is absent but msg.value is non-zero. This accounts for cases where the recipient expects additional native gas token without invoking a Zap.


Line range hint 333-337: Ensure safe transfer of tokens in claim function.

In the claim function, the contract correctly handles the transfer of tokens to the relayer. It uses Address.sendValue for the NATIVE_GAS_TOKEN and IERC20.safeTransfer for ERC20 tokens, ensuring safe execution based on the token type.


361-365: Correctly handle NATIVE_GAS_TOKEN in _takeBridgedUserAsset.

When the token is the NATIVE_GAS_TOKEN, the function verifies that msg.value matches the amount and assigns amountTaken accordingly. This ensures accurate accounting for the native gas token in the bridging process.


429-431: Validate zapData length and disallow zapNative with NATIVE_GAS_TOKEN.

The contract verifies that the length of zapData does not exceed MAX_ZAP_DATA_LENGTH, reverting with ZapDataLengthAboveMax() if it does. It also ensures that zapNative is zero when params.destToken is the NATIVE_GAS_TOKEN, preventing unsupported scenarios.

Copy link

cloudflare-workers-and-pages bot commented Oct 18, 2024

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5e51cfe
Status: ✅  Deploy successful!
Preview URL: https://6618cbec.sanguine-fe.pages.dev
Branch Preview URL: https://refactor-fbv2-zaps.sanguine-fe.pages.dev

View logs

@ChiTimesChi
Copy link
Collaborator Author

This branch has been rebased on top of #3284 merge conflict changes to make the commit history here cleaner.

Base automatically changed from feat/FbV2-version-encoding to master October 18, 2024 17:13
@ChiTimesChi
Copy link
Collaborator Author

ChiTimesChi commented Oct 18, 2024

This branch has been rebased on top of master once #3284 got merged in. Commits stay the same as before, plus added 58f8578

@ChiTimesChi ChiTimesChi marked this pull request as ready for review October 18, 2024 18:04
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 (7)
packages/contracts-rfq/contracts/libs/BridgeTransactionV2.sol (1)

234-237: LGTM with suggestion: New zapData getter function.

The new zapData function correctly extracts the Zap's data using a slice operation, which is appropriate for variable-length data. The comment accurately describes its purpose.

Suggestion: Consider adding a check to ensure that OFFSET_ZAP_DATA is not out of bounds before slicing. This would prevent potential issues if the encoded transaction is shorter than expected.

Here's a suggested improvement:

 function zapData(bytes calldata encodedTx) internal pure returns (bytes calldata zapData_) {
+    require(encodedTx.length >= OFFSET_ZAP_DATA, "BridgeTransactionV2: Invalid encoded transaction length");
     zapData_ = encodedTx[OFFSET_ZAP_DATA:];
 }
packages/contracts-rfq/test/FastBridgeV2.Dst.Zap.t.sol (2)

333-333: LGTM: ETH transfer test setup updated, with a suggestion

The test setup for ETH transfer scenarios has been correctly updated to use setEthTestZapData("") instead of the previous implementation. This change is consistent with the new terminology and functionality.

Consider extracting the empty string "" to a named constant like NO_ZAP_DATA to improve readability and maintain consistency if this value is used in multiple places. For example:

bytes public constant NO_ZAP_DATA = "";

// Then in the test functions:
setEthTestZapData(NO_ZAP_DATA);

This change would make the intent clearer and easier to maintain if the concept of "no zap data" is used elsewhere in the tests.

Also applies to: 342-342


Line range hint 1-349: Overall LGTM with suggestions for improvement

The changes in this file successfully implement the transition from "arbitrary call" to "zap" terminology. The updates are consistent throughout the test suite, covering various scenarios including token transfers, ETH transfers, and different recipient behaviors. The introduction of ZAP_NATIVE functionality is well-tested across different cases.

To further improve the code:

  1. Consider adding comments or documentation to explain the ZAP_NATIVE concept and its implications, especially if it represents a significant change in the contract's behavior.

  2. It might be beneficial to add a brief comment at the beginning of the file explaining the overall change from "arbitrary call" to "zap" to provide context for future readers.

  3. If ZAP_NATIVE is a constant or a significant value, consider defining it as a named constant at the contract level for better readability and maintenance.

These suggestions would enhance the code's clarity and make it easier for other developers to understand the changes and new functionality.

packages/contracts-rfq/test/FastBridgeV2.Dst.t.sol (4)

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

The constant name change from CALL_VALUE to ZAP_NATIVE aligns well with the new terminology. However, the purpose of this specific value (1_337_420) is not immediately clear.

Consider adding a brief comment explaining the significance or purpose of this value, especially if it's used for testing scenarios.


183-184: LGTM! Comments updated to reflect new terminology. Consider adding more context.

The comments have been correctly updated to mention zapData instead of callParams, aligning with the new terminology. This change maintains consistency throughout the test file.

Consider expanding these comments slightly to provide more context about the significance of empty zapData and why the tests behave differently when zapData is present. This could improve the understanding for future developers working on these tests.

Also applies to: 235-236, 326-327, 369-370


494-509: LGTM! Comprehensive new tests for ZAP_NATIVE functionality. Consider adding comments.

New test functions have been added to cover important edge cases and error conditions related to the ZAP_NATIVE functionality:

  1. Tests for reverting behavior with incorrect ZAP_NATIVE values in token transactions.
  2. Tests for reverting behavior when using ZAP_NATIVE with ETH transactions.

These additions improve the test coverage and help ensure the correct implementation of the new functionality.

Consider adding brief comments before each group of new test functions to explain their purpose and the specific scenarios they are testing. This would enhance the readability and maintainability of the test suite.

Also applies to: 530-553


Line range hint 1-624: Overall LGTM! Comprehensive and consistent updates to implement new zap functionality.

This update to the FastBridgeV2.Dst.t.sol test file successfully implements the new "zap" terminology and functionality:

  1. Consistent renaming of variables, functions, and comments from "call" to "zap" related terms.
  2. Addition of new test cases to cover the ZAP_NATIVE functionality, including edge cases and error conditions.
  3. Preservation of existing test logic while updating to the new terminology.

The changes align well with the PR objectives and maintain a high standard of test coverage. The consistency in applying these changes across the entire file is commendable.

As the zap functionality introduces new complexity, consider adding a brief comment at the beginning of the file explaining the concept of "zaps" and how they differ from the previous "call" functionality. This would provide valuable context for developers who may be new to the project or revisiting this code in the future.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between f8665f5 and 58f8578.

📒 Files selected for processing (24)
  • packages/contracts-rfq/contracts/FastBridgeV2.sol (14 hunks)
  • packages/contracts-rfq/contracts/interfaces/IFastBridgeRecipient.sol (0 hunks)
  • packages/contracts-rfq/contracts/interfaces/IFastBridgeV2.sol (2 hunks)
  • packages/contracts-rfq/contracts/interfaces/IFastBridgeV2Errors.sol (1 hunks)
  • packages/contracts-rfq/contracts/interfaces/IZapRecipient.sol (1 hunks)
  • packages/contracts-rfq/contracts/libs/BridgeTransactionV2.sol (6 hunks)
  • packages/contracts-rfq/test/FastBridgeV2.Dst.Zap.t.sol (11 hunks)
  • packages/contracts-rfq/test/FastBridgeV2.Dst.t.sol (7 hunks)
  • packages/contracts-rfq/test/FastBridgeV2.Encoding.t.sol (1 hunks)
  • packages/contracts-rfq/test/FastBridgeV2.GasBench.Dst.Zap.t.sol (2 hunks)
  • packages/contracts-rfq/test/FastBridgeV2.GasBench.Encoding.t.sol (1 hunks)
  • packages/contracts-rfq/test/FastBridgeV2.GasBench.Src.ArbitraryCall.t.sol (0 hunks)
  • packages/contracts-rfq/test/FastBridgeV2.GasBench.Src.Zap.t.sol (1 hunks)
  • packages/contracts-rfq/test/FastBridgeV2.Src.ArbitraryCall.t.sol (0 hunks)
  • packages/contracts-rfq/test/FastBridgeV2.Src.Zap.t.sol (1 hunks)
  • packages/contracts-rfq/test/FastBridgeV2.Src.t.sol (1 hunks)
  • packages/contracts-rfq/test/FastBridgeV2.t.sol (4 hunks)
  • packages/contracts-rfq/test/harnesses/BridgeTransactionV2Harness.sol (2 hunks)
  • packages/contracts-rfq/test/libs/BridgeTransactionV2.t.sol (2 hunks)
  • packages/contracts-rfq/test/mocks/ExcessiveReturnValueRecipient.sol (2 hunks)
  • packages/contracts-rfq/test/mocks/IncorrectReturnValueRecipient.sol (1 hunks)
  • packages/contracts-rfq/test/mocks/NoReturnValueRecipient.sol (1 hunks)
  • packages/contracts-rfq/test/mocks/NonPayableRecipient.sol (1 hunks)
  • packages/contracts-rfq/test/mocks/RecipientMock.sol (1 hunks)
💤 Files with no reviewable changes (3)
  • packages/contracts-rfq/contracts/interfaces/IFastBridgeRecipient.sol
  • packages/contracts-rfq/test/FastBridgeV2.GasBench.Src.ArbitraryCall.t.sol
  • packages/contracts-rfq/test/FastBridgeV2.Src.ArbitraryCall.t.sol
🚧 Files skipped from review as they are similar to previous changes (16)
  • packages/contracts-rfq/contracts/interfaces/IFastBridgeV2.sol
  • packages/contracts-rfq/contracts/interfaces/IFastBridgeV2Errors.sol
  • packages/contracts-rfq/contracts/interfaces/IZapRecipient.sol
  • packages/contracts-rfq/test/FastBridgeV2.Encoding.t.sol
  • packages/contracts-rfq/test/FastBridgeV2.GasBench.Dst.Zap.t.sol
  • packages/contracts-rfq/test/FastBridgeV2.GasBench.Encoding.t.sol
  • packages/contracts-rfq/test/FastBridgeV2.GasBench.Src.Zap.t.sol
  • packages/contracts-rfq/test/FastBridgeV2.Src.t.sol
  • packages/contracts-rfq/test/FastBridgeV2.t.sol
  • packages/contracts-rfq/test/harnesses/BridgeTransactionV2Harness.sol
  • packages/contracts-rfq/test/libs/BridgeTransactionV2.t.sol
  • packages/contracts-rfq/test/mocks/ExcessiveReturnValueRecipient.sol
  • packages/contracts-rfq/test/mocks/IncorrectReturnValueRecipient.sol
  • packages/contracts-rfq/test/mocks/NoReturnValueRecipient.sol
  • packages/contracts-rfq/test/mocks/NonPayableRecipient.sol
  • packages/contracts-rfq/test/mocks/RecipientMock.sol
🧰 Additional context used
🔇 Additional comments (51)
packages/contracts-rfq/contracts/libs/BridgeTransactionV2.sol (6)

25-26: LGTM: Updated comments for new fields.

The comments accurately describe the new zapNative and zapData fields and their positions in the packed struct. The use of *** for the end of zapData correctly implies it's a variable-length field.


42-43: LGTM: New offset constants for Zap fields.

The new constants OFFSET_ZAP_NATIVE and OFFSET_ZAP_DATA are correctly defined and consistent with the comments above. The naming convention aligns with other offset constants in the library.


53-53: LGTM: Updated minimum length check in validateV2.

The minimum length check now correctly uses OFFSET_ZAP_DATA, ensuring that the encoded transaction includes all static fields, including the new Zap fields. The error message remains appropriate for the unchanged error condition.


83-85: LGTM: Updated encodeV2 to include Zap fields.

The encodeV2 function has been correctly updated to include the new zapNative and zapData fields at the end of the packed encoding. The comment accurately describes these as "New V2 fields: Zap".


110-111: LGTM: Updated decodeV2 to extract Zap fields.

The decodeV2 function has been correctly updated to extract the new zapNative and zapData fields using their corresponding getter functions. The order of extraction matches the encoding order, ensuring consistency.


226-232: LGTM: New zapNative getter function.

The new zapNative function correctly extracts the Zap's native value using inline assembly. The implementation is consistent with other getter functions in the library, and the comment accurately describes its purpose.

packages/contracts-rfq/test/FastBridgeV2.Dst.Zap.t.sol (12)

11-12: LGTM: Contract and constant renaming is consistent

The contract name change from FastBridgeV2DstArbitraryCallTest to FastBridgeV2DstZapTest and the constant renaming from CALL_PARAMS to ZAP_DATA are consistent with the overall shift in terminology from "arbitrary call" to "zap". This improves clarity and aligns well with the new functionality.


24-25: LGTM: Fixture setup methods updated correctly

The changes in the createFixturesV2 function, replacing setTokenTestCallParams and setEthTestCallParams with setTokenTestZapData and setEthTestZapData respectively, are consistent with the new "zap" terminology. This ensures that the test fixtures are set up correctly for the updated functionality.


28-30: LGTM: Comment updated to reflect new terminology

The comment for the expectBridgeRelayed function has been correctly updated to mention "Zap" instead of "arbitrary call". This change maintains consistency with the new terminology and accurately describes the function's purpose.


52-53: LGTM: Expected calldata updated for new zap functionality

The getExpectedCalldata function has been correctly updated to use RecipientMock.zap instead of RecipientMock.fastBridgeTransferReceived. This change aligns with the new "zap" functionality and ensures that the test is checking for the correct method call.


84-84: LGTM: Test function names updated consistently

The test function names have been systematically updated to include "ZapDataPresent" instead of "CallParamsPresent". This change maintains consistency with the new terminology and clearly communicates the purpose of each test. The updates cover various scenarios including token transfers, relayer addresses, and ETH transfers.

Also applies to: 90-90, 100-100, 111-111, 122-122, 128-128


198-198: LGTM: No-op recipient test function names updated consistently

The test function names for no-op recipient scenarios have been systematically updated to include "ZapDataPresent" instead of "CallParamsPresent". This change maintains consistency with the new terminology across all test cases, including those for no-op recipients.

Also applies to: 204-204, 210-210, 217-217, 228-228, 234-234


211-211: LGTM: ZAP_NATIVE parameter added to no-op recipient tests

The ZAP_NATIVE parameter has been consistently added to the no-op recipient test functions. This change ensures that the new zap functionality is thoroughly tested across different scenarios, including cases where the recipient contract doesn't implement the expected behavior.

Also applies to: 214-214, 222-222, 225-225


242-242: LGTM: No return value recipient test function names updated consistently

The test function names for no return value recipient scenarios have been systematically updated to include "ZapDataPresent" instead of "CallParamsPresent". This change maintains consistency with the new terminology across all test cases, including those for recipients that don't return a value.

Also applies to: 248-248, 258-258, 265-265, 276-276, 282-282


259-259: LGTM: ZAP_NATIVE parameter added to no return value recipient tests

The ZAP_NATIVE parameter has been consistently added to the no return value recipient test functions. This change ensures that the new zap functionality is thoroughly tested across different scenarios, including cases where the recipient contract doesn't return a value.

Also applies to: 262-262, 270-270, 273-273


306-317: LGTM: New test functions added for ZAP_NATIVE in recipient reverts scenarios

New test functions have been added to cover scenarios where the recipient contract reverts when ZAP_NATIVE is used. These additions enhance the test coverage by including important edge cases:

  1. test_relay_token_withZapNative_revert_recipientReverts
  2. test_relay_token_withRelayerAddressZapNative_revert_recipientReverts

These tests ensure that the contract behaves correctly when a recipient reverts during a zap operation with native token transfer.


332-332: LGTM: ETH transfer test function names updated consistently

The test function names for ETH transfer scenarios have been updated from "noCallParams" to "noZapData":

  1. test_relay_eth_noZapData_revert_recipientReverts
  2. test_relay_eth_withRelayerAddress_noZapData_revert_recipientReverts

These changes maintain consistency with the new terminology and accurately reflect the scenarios being tested.

Also applies to: 341-341


105-105: LGTM: New ZAP_NATIVE parameter introduced

The test functions have been updated to include a new ZAP_NATIVE parameter, which replaces the previous callValue. This change appears to be related to the new zap functionality and is consistently applied across relevant test cases.

Could you please provide more information about the ZAP_NATIVE parameter? Specifically:

  1. What does it represent in the context of a zap operation?
  2. How is it different from the previous callValue?
  3. Are there any specific conditions or constraints for its usage?

To help verify the usage of ZAP_NATIVE, let's search for its definition and other occurrences:

Also applies to: 108-108, 116-116, 119-119

packages/contracts-rfq/test/FastBridgeV2.Dst.t.sol (5)

60-62: LGTM! Function updated to reflect new terminology.

The function has been correctly renamed from assertEmptyCallParams to assertEmptyZapData, and the parameter name has been updated accordingly. The assertion logic remains correct, and the error message has been appropriately updated.


72-72: LGTM! Variable name updated to reflect new terminology.

The condition for chainGasAmount has been correctly updated to use bridgeTx.zapNative instead of bridgeTx.callValue. This change aligns with the new terminology while maintaining the original logic.


161-168: LGTM! Function and variable names updated to new terminology.

The test function has been correctly renamed from test_relay_token_withCallValue to test_relay_token_withZapNative. All instances of CALL_VALUE have been replaced with ZAP_NATIVE. These changes consistently apply the new terminology while maintaining the original test logic.


171-178: LGTM! Function and variable names consistently updated.

The test function has been appropriately renamed from test_relay_token_withRelayerAddressCallValue to test_relay_token_withRelayerAddressZapNative. All occurrences of CALL_VALUE have been replaced with ZAP_NATIVE. These changes maintain consistency with the new terminology while preserving the original test logic.


186-187: LGTM! Consistent terminology updates across test functions.

The test function names and their contents have been systematically updated to use the new "zap" terminology:

  1. Function names now include "zapData" instead of "callParams".
  2. Function bodies now use assertEmptyZapData instead of assertEmptyCallParams.
  3. setTokenTestCallValue has been renamed to setTokenTestZapNative.

These changes maintain consistency with the new terminology while preserving the original test logic and structure.

Also applies to: 192-196, 201-205, 208-215, 218-219, 224-228, 238-239, 244-248, 253-257, 260-267, 270-271, 276-280, 329-330, 335-336, 341-345, 348-352, 355-356, 361-362, 372-373, 378-379, 384-388, 391-398, 401-402, 407-408

packages/contracts-rfq/test/FastBridgeV2.Src.Zap.t.sol (14)

8-9: Constants are defined clearly and enhance readability

The constants ZAP_DATA and ZAP_NATIVE are well-defined and their usage promotes clarity and maintainability in the test code.


11-15: Test fixtures are correctly initialized with zap data

The createFixturesV2 function properly overrides the parent implementation and initializes the test fixtures with the specified zap data for both token and ETH tests.


20-24: Token bridging supports maximum zapData length

The test test_bridge_token_zapDataLengthMax() effectively verifies that the token bridging function can handle the maximum allowed zapData length of 2 ** 16 - 1 bytes without errors.


26-30: ETH bridging supports maximum zapData length

The test test_bridge_eth_zapDataLengthMax() accurately confirms that the ETH bridging function accepts zapData up to the maximum length, ensuring consistency with token bridging.


32-37: Properly handling zapData length exceeding maximum for tokens

The test test_bridge_token_revert_zapDataLengthAboveMax() correctly expects a revert when the zapData length exceeds the maximum limit, ensuring that the contract enforces this constraint for token bridging.


39-44: Properly handling zapData length exceeding maximum for ETH

The test test_bridge_eth_revert_zapDataLengthAboveMax() ensures that ETH bridging operations revert when provided zapData exceeds the maximum allowed length, maintaining contract integrity.


48-52: Token bridging with zapNative and no zapData operates as expected

The function test_bridge_token_withZapNative_noZapData() correctly tests token bridging when zapNative is specified and zapData is empty, confirming that the bridging logic handles this scenario appropriately.


54-58: Token bridging from a different sender with zapNative and no zapData

The test test_bridge_token_diffSender_withZapNative_noZapData() verifies that token bridging functions correctly when initiated by a different sender, with zapNative specified and no zapData.


60-65: ETH bridging with zapNative and no zapData correctly reverts

The function test_bridge_eth_withZapNative_noZapData_revert() appropriately expects a revert due to ZapNativeNotSupported, ensuring that the contract disallows unsupported operations for ETH bridging.


67-72: ETH bridging from a different sender with zapNative and no zapData correctly reverts

The test test_bridge_eth_diffSender_withZapNative_noZapData_revert() confirms that attempting ETH bridging with zapNative from a different sender correctly reverts, enforcing the intended contract restrictions.


76-79: Token bridging with zapNative and zapData functions correctly

The test test_bridge_token_withZapNative_withZapData() successfully verifies that token bridging works as expected when both zapNative and zapData are provided.


81-84: Token bridging from a different sender with zapNative and zapData

The function test_bridge_token_diffSender_withZapNative_withZapData() ensures that token bridging initiated by a different sender operates correctly when both zapNative and zapData are specified.


86-90: ETH bridging with zapNative and zapData correctly reverts

The test test_bridge_eth_withZapNative_withZapData_revert() accurately expects a revert due to ZapNativeNotSupported, confirming that the contract properly restricts unsupported ETH bridging operations.


92-96: ETH bridging from a different sender with zapNative and zapData correctly reverts

The function test_bridge_eth_diffSender_withZapNative_withZapData_revert() confirms that ETH bridging with both zapNative and zapData from a different sender correctly results in a revert, upholding contract constraints.

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

14-14: Import IZapRecipient interface for zap functionality

The import statement correctly includes IZapRecipient, which is necessary for the new zap functionality introduced in this update.


34-35: Set MAX_ZAP_DATA_LENGTH constant correctly

The maximum length for zapData is set to 2 ** 16 - 1 (65535 bytes), which seems appropriate to prevent excessively large data payloads.


62-63: Initialize zapNative and zapData with default values in legacy bridge function

In the legacy bridge function, setting zapNative to 0 and zapData to an empty byte string ensures backward compatibility with existing implementations.


Line range hint 127-131: Handle native gas token refunds correctly

The refund logic now checks against NATIVE_GAS_TOKEN to determine if the token is the native gas token and uses Address.sendValue to refund accordingly. This ensures accurate handling of refunds for both ERC20 tokens and the native gas token.


147-148: Update getBridgeTransaction comments for V2 parameters

The comments accurately reflect how zapNative and zapData are handled in getBridgeTransaction, noting that zapNative is reported as a zero/non-zero flag and zapData is ignored for backward compatibility.


164-164: Set sendChainGas flag based on zapNative in getBridgeTransaction

The sendChainGas flag is correctly determined by checking if zapNative is non-zero, aligning with the updated logic for zap functionality.


213-214: Include zapNative and zapData in bridge transaction encoding

The parameters zapNative and zapData are properly included in the BridgeTransactionV2Lib.encodeV2 call, ensuring they are transmitted and processed correctly in the bridging process.


229-229: Set sendChainGas flag in BridgeRequested event

The sendChainGas parameter in the BridgeRequested event is correctly set based on whether zapNative is non-zero, providing accurate event data for listeners.


247-247: Retrieve zapNative from request in relay function

Extracting zapNative from the request ensures that the relay function has access to the necessary data to process the zap on the destination chain.


264-275: Handle zapNative and msg.value correctly in relay function

The relay function correctly differentiates between native gas tokens and ERC20 tokens, enforcing that zapNative is zero when dealing with the native gas token and checking msg.value appropriately. This prevents incorrect usage and potential errors.


285-296: Process zapData and msg.value appropriately

The logic ensures that when zapData is present, the _triggerZapWithChecks function is called to handle the zap. If zapData is absent but msg.value is non-zero, the value is transferred directly to the recipient. This correctly accommodates both scenarios.


379-380: Verify msg.value for native gas token in _takeBridgedUserAsset

The function correctly checks that msg.value matches the amount specified when the token is the native gas token, ensuring accurate asset transfer.


396-411: Return data validation in _triggerZapWithChecks remains unaddressed

The issue raised in the previous review about relying on returnData length and contents for validation in _triggerZapWithChecks still stands. It's recommended to modify the IZapRecipient.zap interface to return a bool indicating success and adjust the validation accordingly.


447-449: Validate zapData length and disallow zapNative with native gas token

The added checks ensure that zapData does not exceed MAX_ZAP_DATA_LENGTH and that zapNative is not used when destToken is the native gas token. This prevents unsupported configurations and potential errors.

Comment on lines +22 to +23
/// @notice Address reserved for native gas token (ETH on Ethereum and most L2s, AVAX on Avalanche, etc)
address public constant NATIVE_GAS_TOKEN = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Remaining references to UniversalTokenLib.ETH_ADDRESS detected. Please ensure all instances are updated to use NATIVE_GAS_TOKEN.

🔗 Analysis chain

Define NATIVE_GAS_TOKEN constant appropriately

The constant NATIVE_GAS_TOKEN is defined to represent the native gas token (e.g., ETH, AVAX) across different networks. This enhances clarity and replaces previous references to UniversalTokenLib.ETH_ADDRESS.

To ensure all references to UniversalTokenLib.ETH_ADDRESS have been updated, you can run:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining references to `UniversalTokenLib.ETH_ADDRESS`
rg 'UniversalTokenLib\.ETH_ADDRESS' --type solidity

Length of output: 86


Script:

#!/bin/bash
# Description: Check for any remaining references to `UniversalTokenLib.ETH_ADDRESS` in Solidity files
rg 'UniversalTokenLib\.ETH_ADDRESS' --glob '*.sol'

Length of output: 5843

Copy link
Collaborator

@parodime parodime left a comment

Choose a reason for hiding this comment

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

i think UniversalTokenLib & its import can just be removed at this point?

all else LGTM

@ChiTimesChi
Copy link
Collaborator Author

@parodime that's a good call, thanks. Removed in 2ab2f6e

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

🧹 Outside diff range and nitpick comments (2)
packages/contracts-rfq/contracts/interfaces/IFastBridgeV2Errors.sol (1)

11-13: LGTM! Consider minor naming consistency improvement.

The new error declarations align well with the PR objectives of introducing Zap functionality and updating terminology. The changes are appropriate and consistent with the overall refactoring described in the PR summary.

For improved naming consistency, consider renaming TokenNotContract to TokenNotContractAddress to match the verbosity of other error names in the interface.

packages/contracts-rfq/test/FastBridgeV2.Src.t.sol (1)

258-262: Excellent addition: New test enhances error handling.

This new test function effectively validates that the contract correctly handles cases where the originToken is not a contract address. It's a valuable addition that improves the robustness of the contract by ensuring proper input validation.

Some suggestions to consider:

  1. You might want to add similar tests for other address parameters (e.g., destToken) to ensure comprehensive validation.
  2. Consider adding a positive test case where originToken is a valid contract address to ensure the check doesn't incorrectly reject valid inputs.
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 58f8578 and 2ab2f6e.

📒 Files selected for processing (4)
  • packages/contracts-rfq/contracts/FastBridgeV2.sol (13 hunks)
  • packages/contracts-rfq/contracts/interfaces/IFastBridgeV2Errors.sol (1 hunks)
  • packages/contracts-rfq/test/FastBridgeV2.Src.FBRV2.t.sol (0 hunks)
  • packages/contracts-rfq/test/FastBridgeV2.Src.t.sol (3 hunks)
💤 Files with no reviewable changes (1)
  • packages/contracts-rfq/test/FastBridgeV2.Src.FBRV2.t.sol
🧰 Additional context used
📓 Learnings (1)
packages/contracts-rfq/test/FastBridgeV2.Src.t.sol (4)
Learnt from: ChiTimesChi
PR: synapsecns/sanguine#3284
File: packages/contracts-rfq/test/FastBridgeV2.Src.Base.t.sol:97-97
Timestamp: 2024-10-14T13:23:04.509Z
Learning: In `packages/contracts-rfq/test/FastBridgeV2.t.sol`, when testing expected revert behaviors, `abi.encodeWithSelector` is used with custom errors and should not be replaced with `BridgeTransactionV2Lib.encodeV2`.
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.
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/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.
🔇 Additional comments (6)
packages/contracts-rfq/test/FastBridgeV2.Src.t.sol (1)

48-48: LGTM: Updated expectation aligns with new zap functionality.

The change from bridgeTx.callValue to bridgeTx.zapNative in the sendChainGas parameter check is consistent with the PR objectives. This update correctly reflects the new zap functionality introduced in the FastBridgeV2 contract.

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

60-61: Confirm Default Parameters in Overloaded bridge Function.

In the overloaded bridge function, zapNative and zapData are set to default values of 0 and bytes("") respectively. Ensure that these defaults correctly handle scenarios where zap functionality is not required and do not introduce unintended behavior.


Line range hint 246-265: Review zapNative Restrictions in relay Function.

The relay function reverts if zapNative is not zero when dealing with the native gas token:

if (zapNative != 0) revert ZapNativeNotSupported();

Verify that this restriction aligns with the business logic and that no valid use cases are being inadvertently blocked.


404-415: Note: Previous Issue Regarding Return Data Validation Remains Unresolved.

The method _triggerZapWithChecks still checks the return data length and value in a way that may not reliably confirm successful execution:

if (returnData.length != 32) revert RecipientIncorrectReturnValue();
if (bytes32(returnData) != bytes32(IZapRecipient.zap.selector)) {
    revert RecipientIncorrectReturnValue();
}

As previously suggested, consider updating IZapRecipient.zap to return a boolean value indicating success and decode the return data accordingly.


128-129: 🛠️ Refactor suggestion

Verify Security in refund Function Token Transfers.

When refunding users, the function handles both native gas tokens and ERC20 tokens. Confirm that:

  • The use of Address.sendValue for native tokens is safe against reentrancy attacks.
  • The safeTransfer method is appropriate for ERC20 tokens.

Consider implementing reentrancy guards if necessary.


19-21: 💡 Codebase verification

Inconsistent Replacement of ETH_ADDRESS with NATIVE_GAS_TOKEN Detected

The following files still contain references to ETH_ADDRESS and need to be updated to NATIVE_GAS_TOKEN:

  • services/explorer/contracts/contracts/SynapseRFQV2_flat.sol
  • services/explorer/contracts/contracts/SynapseRFQV1_flat.sol
  • services/explorer/contracts/contracts/testcontracts/TestSynapseBridgeV1.sol
  • services/explorer/contracts/contracts/testcontracts/TestSynapseBridgeV2.sol
  • packages/contracts-rfq/test/FastBridgeV2.t.sol
  • packages/contracts-rfq/test/FastBridgeV2.Src.t.sol
  • packages/contracts-rfq/test/FastBridgeV2.Dst.t.sol
  • packages/contracts-rfq/test/integration/MulticallTarget.t.sol
  • packages/contracts-rfq/test/UniversalTokenLibHarness.sol
  • packages/contracts-rfq/test/UniversalTokenLib.t.sol
  • packages/contracts-rfq/test/FastBridgeV2.Src.Exclusivity.t.sol
  • packages/contracts-rfq/test/FastBridgeV2.Src.Exclusivity.Negative.t.sol
  • packages/contracts-rfq/test/FastBridgeV2.Src.Base.t.sol
  • packages/contracts-rfq/test/FastBridgeV2.Management.t.sol
  • packages/contracts-rfq/test/FastBridge.t.sol
  • packages/contracts-rfq/contracts/libs/UniversalToken.sol
  • packages/contracts-rfq/contracts/legacy/router/DefaultRouter.sol
  • packages/contracts-rfq/contracts/legacy/rfq/FastBridgeRouterV2.sol
  • packages/contracts-rfq/contracts/legacy/router/libs/UniversalToken.sol
  • packages/contracts-rfq/contracts/FastBridge.sol
  • packages/contracts-rfq/contracts/legacy/rfq/interfaces/IFastBridgeRouter.sol
  • packages/contracts-rfq/contracts/legacy/router/interfaces/IRouterAdapter.sol
  • packages/contracts-rfq/contracts/legacy/router/adapters/DefaultAdapter.sol
🔗 Analysis chain

Ensure Consistent Replacement of ETH_ADDRESS with NATIVE_GAS_TOKEN.

The introduction of NATIVE_GAS_TOKEN is meant to replace ETH_ADDRESS to prevent confusion on networks where ETH is not the native gas token. Please verify that all instances of ETH_ADDRESS have been updated throughout the codebase to maintain consistency.

You can run the following script to check for any remaining references:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find any remaining references to `ETH_ADDRESS` in Solidity files.

rg 'ETH_ADDRESS' --glob '*.sol'

Length of output: 18591

⛔ Skipped due to learnings
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.

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.

3 participants