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

exclusivityEndtime default 0 [SLT-391] #3336

Merged
merged 6 commits into from
Oct 28, 2024
Merged

Conversation

parodime
Copy link
Collaborator

@parodime parodime commented Oct 25, 2024

Previously if bridge was not intended to be exclusive it would still end up with exclusivityEndtime = block.timestamp as a default from excl offset being 0.

This is generally fine & efficient, except it adds reorg risk to even non-exclusive relays whereby the bridge params are dependent upon block.timestamp and will change if reorged into a different block.

This approach will instead pay slightly more gas to default to a static exclusivityEndtime value (0) if no exclusivity is intended - inferred by quoteRelayer being address 0

Summary by CodeRabbit

  • New Features

    • Enhanced handling of bridge transaction exclusivity with updated conditions for exclusivityEndTime.
  • Bug Fixes

    • Improved validation logic for exclusivity parameters during bridge transactions.
  • Tests

    • Refined test function names for clarity regarding exclusivity checks.
    • Adjusted handling of exclusivity end times in gas benchmarking tests.

@parodime parodime requested a review from ChiTimesChi as a code owner October 25, 2024 16:44
Copy link
Contributor

coderabbitai bot commented Oct 25, 2024

Walkthrough

The changes in this pull request focus on the FastBridgeV2 contract, specifically refining the handling of bridge transactions and exclusivity parameters. The bridge function now conditionally sets exclusivityEndTime based on the presence of a relayer address. The validation logic in _validateBridgeParams has also been updated to enforce stricter conditions. Additionally, modifications were made to the test contracts, adjusting how exclusivityEndTime is initialized and altering test function names for clarity.

Changes

File Change Summary
packages/contracts-rfq/contracts/FastBridgeV2.sol Modified bridge and _validateBridgeParams functions to refine logic for exclusivityEndTime.
packages/contracts-rfq/test/FastBridgeV2.GasBench.Src.t.sol Removed createFixturesV2 function, affecting exclusivityEndTime initialization for transaction objects.
packages/contracts-rfq/test/FastBridgeV2.Src.Exclusivity.Negative.t.sol Renamed test functions for clarity and removed revert expectations related to exclusivity parameters.
packages/contracts-rfq/test/FastBridgeV2.t.sol Adjusted exclusivityEndTime for tokenTx and ethTx from block.timestamp to 0.

Possibly related PRs

Suggested labels

size/s

Suggested reviewers

  • trajan0x
  • parodime

🐇 In the realm of bridges, we hop with glee,
Exclusivity's end time, now clearer to see.
With tests refined, and logic so bright,
Our transactions will dance in the soft moonlight! 🌙
Hooray for the changes, let’s celebrate,
For every new feature, we eagerly await! 🎉


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.

Copy link

codecov bot commented Oct 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 34.85109%. Comparing base (0651118) to head (4d77ec2).
Report is 9 commits behind head on master.

Additional details and impacted files
@@                 Coverage Diff                 @@
##              master       #3336         +/-   ##
===================================================
+ Coverage   33.25951%   34.85109%   +1.59158%     
===================================================
  Files            543         529         -14     
  Lines          34769       33778        -991     
  Branches          82          82                 
===================================================
+ Hits           11564       11772        +208     
+ Misses         22182       20986       -1196     
+ Partials        1023        1020          -3     
Flag Coverage Δ
packages 90.44834% <ø> (ø)
promexporter ?
solidity 98.66667% <100.00000%> (?)

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

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

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 42c0079 and 48954d9.

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

37-40: ETH bridge test consistently updated with token bridge test.

The ETH bridge test mirrors the changes made to the token bridge test, ensuring consistent behavior verification across both token and ETH bridges.


26-29: Test name and behavior updated to reflect new requirements.

The test has been correctly updated to verify that setting quoteExclusivitySeconds to -block.timestamp is now a valid operation, aligning with the PR's objective of allowing exclusivityEndtime to be 0 for non-exclusive bridges.

Let's verify the test coverage for this new behavior:

✅ Verification successful

Let me try a different approach to verify the test coverage and implementation.


Test changes correctly align with contract implementation

The verification results show that:

  1. The contract explicitly handles zero exclusivity by setting exclusivityEndTime = 0 when quoteRelayer is not set (FastBridgeV2.sol)
  2. The interface documentation confirms this behavior: "quoteRelayer and quoteExclusivitySeconds are either both zero (indicating no exclusivity) or both non-zero"
  3. The test changes align with this implementation by verifying that setting quoteExclusivitySeconds to -block.timestamp results in valid non-exclusive bridge operations
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if there are corresponding positive test cases for the new behavior
# and verify the contract implementation matches the test assumptions

# Search for related test cases
echo "Searching for related test cases..."
rg -l "quoteExclusivitySeconds.*block\.timestamp" --type sol

# Search for the contract implementation
echo "Checking contract implementation..."
ast-grep --pattern 'function _validateBridgeParams($$$) {
  $$$
  if ($exclusivityEndTime == 0) {
    $$$
  }
  $$$
}'

Length of output: 373


Script:

#!/bin/bash
# Search for related test cases and implementation with ripgrep
echo "Searching for test cases and implementation..."
rg -g "*.{sol,t.sol}" "quoteExclusivitySeconds" -A 3

echo -e "\nChecking for exclusivity validation..."
rg -g "*.sol" "exclusivityEndTime.*0" -A 3

Length of output: 10977

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

176-176: LGTM! Changes align with PR objectives.

Setting exclusivityEndTime to 0 in test fixtures correctly reflects the new default behavior for non-exclusive bridges, which helps prevent potential issues during blockchain reorganization events by using a static value instead of block.timestamp.

Also applies to: 178-178

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

53-59: LGTM! Changes align with PR objectives.

The modification to set exclusivityEndTime to 0 for all test transactions aligns with the PR's goal to mitigate blockchain reorganization risks by using a static value instead of block.timestamp for non-exclusive bridges.


53-59: Verify test coverage for exclusivity scenarios.

While the changes to exclusivityEndTime are correct, let's ensure the test coverage is comprehensive for both exclusive and non-exclusive scenarios. The test functions test_bridge_token_withExclusivity() and test_bridge_eth_withExclusivity() cover the exclusive case, but we should verify if we need additional assertions for the non-exclusive case.

Also applies to: 174-177, 182-185

✅ Verification successful

Test coverage for exclusivity scenarios is comprehensive.

The test coverage is complete with both exclusive and non-exclusive scenarios:

  • Non-exclusive scenarios: test_bridge_token() and test_bridge_eth()
  • Exclusive scenarios: test_bridge_token_withExclusivity() and test_bridge_eth_withExclusivity()

Each test verifies the correct state after bridging using checkAfterBridgeToken() and checkAfterBridgeEth() helper functions.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check test coverage for non-exclusive bridge scenarios
# Look for test functions that verify exclusivityEndTime behavior

# Search for test functions and their assertions
rg -U "test_bridge.*\{.*\}" --type solidity

Length of output: 78


Script:

#!/bin/bash
# Search for test functions related to bridge functionality
rg -U "function test_bridge.*?\{.*?\}" -g "*.sol" -A 10

# Also search for exclusivity-related test functions
rg -U "function.*?exclusivity.*?\{.*?\}" -g "*.sol" -A 10

Length of output: 117


Script:

#!/bin/bash
# First, let's find all test files related to FastBridgeV2
fd "FastBridgeV2.*\.t\.sol$"

# Then let's look at the content of these test files
fd "FastBridgeV2.*\.t\.sol$" -x cat {}

# Additionally, search for any mentions of exclusivity in test files
rg "exclusivity" -g "*.t.sol"

Length of output: 168531


Script:

#!/bin/bash
# Search for test functions that verify both exclusive and non-exclusive scenarios
rg -B 2 -A 10 "test_bridge.*withExclusivity" packages/contracts-rfq/test/FastBridgeV2.GasBench.Src.t.sol

# Also search for test functions that verify non-exclusive scenarios
rg -B 2 -A 10 "test_bridge_token\(\)" packages/contracts-rfq/test/FastBridgeV2.GasBench.Src.t.sol
rg -B 2 -A 10 "test_bridge_eth\(\)" packages/contracts-rfq/test/FastBridgeV2.GasBench.Src.t.sol

Length of output: 2432

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

180-183: LGTM! Change aligns with PR objectives.

The modification correctly addresses the reorg risk by setting exclusivityEndTime to 0 when no exclusivity is intended (quoteRelayer is address(0)), instead of defaulting to block.timestamp.

Copy link
Collaborator

@ChiTimesChi ChiTimesChi left a comment

Choose a reason for hiding this comment

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

LGTM in terms of functionality and the tests.
Requesting a few changes: a stale comment needs to be updated + a few styling nits.

@@ -444,7 +447,7 @@ contract FastBridgeV2 is Admin, IFastBridgeV2, IFastBridgeV2Errors {
revert NativeTokenCallValueNotSupported();
}
// exclusivityEndTime must be in range (0 .. params.deadline]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's update the comment here to reflect that the range now includes zero.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i actually thought it was incorrect before (0 was not technically in range before, but was specified in the comment) - but now happens to be accurate & left it alone.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@parodime I meant purely in terms of the exclusive/inclusive range notation: (0 .. X] vs [0 .. X]

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i'm blind - thanks

packages/contracts-rfq/contracts/FastBridgeV2.sol Outdated Show resolved Hide resolved
Copy link

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

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 4d77ec2
Status: ✅  Deploy successful!
Preview URL: https://ed963cbc.sanguine-fe.pages.dev
Branch Preview URL: https://feat-fbv2-exclusoffsetdefzer.sanguine-fe.pages.dev

View logs

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

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

451-452: Update the comment to use inclusive range notation.

The comment should reflect that 0 is included in the valid range.

Apply this change:

-        // exclusivityEndTime must be in range [0 .. params.deadline]
+        // exclusivityEndTime must be in range [0 .. params.deadline]

Note: The implementation is correct as it properly validates the range including 0, but the comment's range notation could be clearer.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 4316e46 and 4d77ec2.

📒 Files selected for processing (1)
  • packages/contracts-rfq/contracts/FastBridgeV2.sol (3 hunks)
🧰 Additional context used
📓 Learnings (1)
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.
🔇 Additional comments (1)
packages/contracts-rfq/contracts/FastBridgeV2.sol (1)

180-185: LGTM! The exclusivity logic change aligns with the PR objective.

The implementation correctly addresses the reorg risk by:

  1. Defaulting exclusivityEndTime to 0 for non-exclusive bridges
  2. Only using block.timestamp when exclusivity is intended (quoteRelayer != address(0))

@parodime parodime merged commit 65b130a into master Oct 28, 2024
57 checks passed
@parodime parodime deleted the feat/FbV2-exclusOffsetDefZero branch October 28, 2024 15:48
ChiTimesChi added a commit that referenced this pull request Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants