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

solhint warning fixes [SLT-287] #3207

Merged
merged 2 commits into from
Oct 1, 2024
Merged

Conversation

parodime
Copy link
Collaborator

@parodime parodime commented Sep 30, 2024

solhint warning fixes for Fastbridge v2 canonical ordering. Rearranged everything to the enforced order.

Had to ignore FastBridgeV2 "not used" warning on tests - removing this reference caused forge test errors because it is actually used

Summary by CodeRabbit

  • New Features

    • Introduced new functions for managing bridge transactions: claim, refund, and dispute.
    • Enhanced functionality for claiming transactions with defaults for relayers and improved refund checks.
  • Bug Fixes

    • Removed outdated functions to streamline transaction status retrieval.
  • Refactor

    • Restructured the _pullToken function for better clarity and maintainability.
    • Modified the relay and prove functions to include additional validation checks.
  • Tests

    • Enhanced testing framework for the FastBridgeV2 contract with structured setup for bridge transactions.

Copy link
Contributor

coderabbitai bot commented Sep 30, 2024

Walkthrough

The FastBridgeV2 contract has been restructured to improve its functionality and maintainability. Key changes include the removal of certain functions, the introduction of new mechanisms for managing bridge transactions, and updates to existing function signatures. The testing framework for the contract has also been enhanced to support these modifications.

Changes

File Change Summary
packages/contracts-rfq/contracts/FastBridgeV2.sol - Removed functions: bridgeStatuses and bridgeProofs.
- Added functions: claim, refund, dispute, and canClaim.
- Updated signatures for relay and prove functions.
packages/contracts-rfq/test/FastBridgeV2.t.sol - Added import for IFastBridgeV2 interface.
- Declared public variables for testing.
- Defined several virtual functions for setup and transaction creation.

Possibly related PRs

Suggested labels

Sol, Typescript

Suggested reviewers

  • ChiTimesChi
  • trajan0x
  • abtestingalpha

Poem

🐰 In the meadow where bridges gleam,
FastBridgeV2 reigns supreme.
With claims and refunds now in sight,
Our hops are swift, our future bright!
No more old paths, we leap and bound,
In code and contracts, joy is found! 🌟


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 Sep 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.66774%. Comparing base (f0b13bc) to head (95daba4).
Report is 18 commits behind head on master.

Additional details and impacted files
@@                 Coverage Diff                  @@
##              master       #3207          +/-   ##
====================================================
+ Coverage   40.97804%   90.66774%   +49.68969%     
====================================================
  Files            459          60         -399     
  Lines          25643        1243       -24400     
  Branches         343         148         -195     
====================================================
- Hits           10508        1127        -9381     
+ Misses         14383         112       -14271     
+ Partials         752           4         -748     
Flag Coverage Δ
cctp-relayer ?
core ?
ethergo ?
git-changes-action ?
omnirpc ?
opbot ?
packages 90.56974% <ø> (ø)
screener-api ?
scribe ?
solidity 91.11111% <100.00000%> (-3.59562%) ⬇️
tools ?

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

cloudflare-workers-and-pages bot commented Sep 30, 2024

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 95daba4
Status: ✅  Deploy successful!
Preview URL: https://614fe45d.sanguine-fe.pages.dev
Branch Preview URL: https://feat-fbv2-solhint-warnings-6nc6.sanguine-fe.pages.dev

View logs

Comment on lines +109 to +122
function dispute(bytes32 transactionId) external onlyRole(GUARD_ROLE) {
if (bridgeTxDetails[transactionId].status != BridgeStatus.RELAYER_PROVED) revert StatusIncorrect();
if (_timeSince(bridgeTxDetails[transactionId].proofBlockTimestamp) > DISPUTE_PERIOD) {
revert DisputePeriodPassed();
}

// @dev relayer gets slashed effectively if dest relay has gone thru
bridgeTxDetails[transactionId].status = BridgeStatus.REQUESTED;
bridgeTxDetails[transactionId].proofRelayer = address(0);
bridgeTxDetails[transactionId].proofBlockTimestamp = 0;
bridgeTxDetails[transactionId].proofBlockNumber = 0;

emit BridgeProofDisputed(transactionId, msg.sender);
}

Check notice

Code scanning / Slither

Block timestamp Low

Comment on lines +125 to +150
function refund(bytes memory request) external {
bytes32 transactionId = keccak256(request);

BridgeTransaction memory transaction = getBridgeTransaction(request);

if (bridgeTxDetails[transactionId].status != BridgeStatus.REQUESTED) revert StatusIncorrect();

if (hasRole(REFUNDER_ROLE, msg.sender)) {
// Refunder can refund if deadline has passed
if (block.timestamp <= transaction.deadline) revert DeadlineNotExceeded();
} else {
// Permissionless refund is allowed after REFUND_DELAY
if (block.timestamp <= transaction.deadline + REFUND_DELAY) revert DeadlineNotExceeded();
}

// if all checks passed, set to REFUNDED status
bridgeTxDetails[transactionId].status = BridgeStatus.REFUNDED;

// transfer origin collateral back to original sender
address to = transaction.originSender;
address token = transaction.originToken;
uint256 amount = transaction.originAmount + transaction.originFeeAmount;
token.universalTransfer(to, amount);

emit BridgeDepositRefunded(transactionId, to, token, amount);
}

Check notice

Code scanning / Slither

Reentrancy vulnerabilities Low

Comment on lines +125 to +150
function refund(bytes memory request) external {
bytes32 transactionId = keccak256(request);

BridgeTransaction memory transaction = getBridgeTransaction(request);

if (bridgeTxDetails[transactionId].status != BridgeStatus.REQUESTED) revert StatusIncorrect();

if (hasRole(REFUNDER_ROLE, msg.sender)) {
// Refunder can refund if deadline has passed
if (block.timestamp <= transaction.deadline) revert DeadlineNotExceeded();
} else {
// Permissionless refund is allowed after REFUND_DELAY
if (block.timestamp <= transaction.deadline + REFUND_DELAY) revert DeadlineNotExceeded();
}

// if all checks passed, set to REFUNDED status
bridgeTxDetails[transactionId].status = BridgeStatus.REFUNDED;

// transfer origin collateral back to original sender
address to = transaction.originSender;
address token = transaction.originToken;
uint256 amount = transaction.originAmount + transaction.originFeeAmount;
token.universalTransfer(to, amount);

emit BridgeDepositRefunded(transactionId, to, token, amount);
}

Check notice

Code scanning / Slither

Block timestamp Low

Comment on lines 153 to 157
function canClaim(bytes32 transactionId, address relayer) external view returns (bool) {
if (bridgeTxDetails[transactionId].status != BridgeStatus.RELAYER_PROVED) revert StatusIncorrect();
if (bridgeTxDetails[transactionId].proofRelayer != relayer) revert SenderIncorrect();
return _timeSince(bridgeTxDetails[transactionId].proofBlockTimestamp) > DISPUTE_PERIOD;
}

Check notice

Code scanning / Slither

Block timestamp Low

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/test/FastBridgeV2.t.sol (1)

6-6: Approved: solhint disable comment is correctly added.

The solhint disable comment for 'no-unused-import' is properly formatted and aligns with the PR objectives. It addresses the "not used" warning for FastBridgeV2 in the tests.

Consider adding an explanatory comment for future maintainers, explaining why this import is necessary despite appearing unused. For example:

// solhint-disable-next-line no-unused-import
// This import is required for forge tests, removing it causes errors
import {IFastBridgeV2} from "../contracts/interfaces/IFastBridgeV2.sol";
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 44338be and 72e5e88.

📒 Files selected for processing (2)
  • packages/contracts-rfq/contracts/FastBridgeV2.sol (2 hunks)
  • packages/contracts-rfq/test/FastBridgeV2.t.sol (1 hunks)
🔇 Additional comments (4)
packages/contracts-rfq/test/FastBridgeV2.t.sol (2)

5-5: LGTM: New import statement is correctly added.

The import statement for the IFastBridgeV2 interface is properly formatted and imported from the correct relative path. This import is necessary for the contract's functionality.


Line range hint 1-146: Summary: Changes align well with PR objectives.

The modifications in this file effectively address the solhint warnings related to the Fastbridge v2 canonical ordering. The new import statement for IFastBridgeV2 and the associated solhint disable comment are correctly implemented and justified.

These changes align perfectly with the PR objectives, which aimed to fix solhint warnings and handle the "not used" warning for FastBridgeV2 in the tests. The author's decision to keep the import despite the warning is well-explained and necessary for the proper functioning of the forge tests.

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

98-101: Function prove correctly forwards the call

The prove function correctly computes the transactionId from the request and forwards the call to the overloaded prove function with msg.sender as the relayer.


104-106: Function claim correctly delegates with default parameter

The claim function properly delegates to the internal claim function, using address(0) as the default to address, allowing for permissionless claims by defaulting to the relayer.

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 once the single comment is resolved

Comment on lines 99 to 100
bytes32 transactionId = keccak256(request);
prove(transactionId, destTxHash, msg.sender);
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 use named variables syntax here (and in relay/claim) for easier maintainability. This wasn't really required when the overload function was literally a few lines away, but with the function ordering enforced that would be helpful:

Suggested change
bytes32 transactionId = keccak256(request);
prove(transactionId, destTxHash, msg.sender);
prove({transactionId: keccak256(request), destTxHash: destTxHash, relayer: msg.sender});

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 (3)
packages/contracts-rfq/contracts/FastBridgeV2.sol (3)

95-101: Approved: Improved relay and prove functions

The modifications to relay and prove functions enhance flexibility and improve relayer handling. The use of named parameters in function calls increases readability.

For consistency, consider using named parameters in the relay function call as well:

-        relay({request: request, relayer: msg.sender});
+        relay({request: request, relayer: msg.sender});

108-122: Approved: New dispute function with proper checks

The dispute function is a valuable addition that allows authorized guards to challenge potentially fraudulent transactions. The implementation includes appropriate status checks and a time-based dispute window.

However, the comment on line 115 needs clarification:

-        // @dev relayer gets slashed effectively if dest relay has gone thru
+        // @dev relayer loses their claim to the bridged funds if the destination relay has already been executed

This change more accurately describes the consequence for the relayer, as there's no explicit slashing mechanism in the current implementation.


124-150: Approved: Comprehensive refund function with role-based checks

The refund function is well-implemented with appropriate checks for transaction status, roles, and deadlines. It provides a mechanism for both authorized and permissionless refunds after different time periods.

Consider a minor optimization:

-        uint256 amount = transaction.originAmount + transaction.originFeeAmount;
-        token.universalTransfer(to, amount);
+        token.universalTransfer(to, transaction.originAmount + transaction.originFeeAmount);

This change reduces the number of local variables and slightly improves gas efficiency.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 72e5e88 and 95daba4.

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

34-34: Approved: Addition of nonce variable for replay protection

The introduction of a public nonce variable is a good practice for preventing replay attacks in bridge transactions. This ensures that each transaction has a unique identifier.


103-106: Approved: New claim function for permissionless claims

The addition of this claim function enhances the contract's functionality by allowing permissionless claims. This aligns with the improvements mentioned in the PR summary and increases the flexibility of the bridging process.


152-156: Approved: Efficient canClaim function for claim eligibility checks

The canClaim function is a well-implemented view function that efficiently checks if a transaction can be claimed by a specific relayer. It performs the necessary status and relayer checks, and correctly uses the _timeSince function to verify if the dispute period has passed.


251-258: Approved: Useful getter functions for bridge transaction details

The addition of bridgeStatuses and bridgeProofs functions provides a convenient way to query important details about bridge transactions. These functions enhance the contract's transparency and allow external contracts or off-chain systems to easily access transaction statuses and proof information.


260-263: Approved: Efficient bridgeRelays function for relay status checks

The bridgeRelays function is a well-implemented view function that efficiently checks if a transaction has been relayed. It provides a simple boolean return, making it easy for external contracts or off-chain systems to verify the relay status of a transaction.

Copy link

github-actions bot commented Oct 1, 2024

Changes to gas cost

Generated at commit: afd430aea67852ce2b19d6ebf8dfa1ee85d08a2a, compared to commit: 0240714b0c7bcaca40574c430239ea3e1b7927f7

🧾 Summary (50% most significant diffs)

Contract Method Avg (+/-) %
FastBridgeV2 prove(bytes,bytes32) -2 ✅ -0.01%

Full diff report 👇
Contract Deployment Cost (+/-) Method Min (+/-) % Avg (+/-) % Median (+/-) % Max (+/-) % # Calls (+/-)
FastBridgeV2 2,379,803 (0) prove(bytes,bytes32) 34,729 (-2) -0.01% 34,757 (-2) -0.01% 34,759 (-2) -0.01% 34,873 (-2) -0.01% 36 (0)

Copy link

codecov bot commented Oct 1, 2024

Bundle Report

Changes will increase total bundle size by 407.74kB (1.14%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
sdk-router-@synapsecns/sdk-router-cjs 526.74kB 409.5kB (349.29%) ⬆️
synapse-interface-client-array-push* 7.28MB 147 bytes (0.0%) ⬆️
synapse-interface-server-cjs 1.49MB 127 bytes (0.01%) ⬆️
widget-cjs-esm 271.27kB 2.03kB (-0.74%) ⬇️

ℹ️ *Bundle size includes cached data from a previous commit

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