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

Feat/fb v2 sender nonce [SLT-183] #3212

Closed
wants to merge 2 commits into from
Closed

Conversation

parodime
Copy link
Collaborator

@parodime parodime commented Oct 1, 2024

Description
Replace chain-scoped nonce with one that increments per-sender

Additional context
Reduces risk of reorgs resulting in a different nonce

Summary by CodeRabbit

  • New Features
    • Enhanced nonce management for improved security in bridge transactions.
    • New events added for better tracking of bridge operations.
  • Bug Fixes
    • Expanded tests to cover edge cases and ensure correct handling of various scenarios in bridging tokens and ETH.
  • Documentation
    • Added comments for clarity on the new nonce mapping functionality.

@parodime parodime requested a review from ChiTimesChi as a code owner October 1, 2024 19:45
Copy link
Contributor

coderabbitai bot commented Oct 1, 2024

Walkthrough

The changes in this pull request primarily enhance the nonce management and transaction handling within the FastBridgeV2 contract. A mapping for sender-specific nonces has replaced the single nonce variable, improving security against replay attacks. The related test contract has also been updated to include new events and expanded test cases for various bridging scenarios, ensuring robust validation of the contract's functionality.

Changes

File Path Change Summary
packages/contracts-rfq/contracts/FastBridgeV2.sol Replaced global nonce with mapping(address => uint256) public senderNonces; added deprecated nonce() function returning zero. Updated bridge function for sender-specific nonce management.
packages/contracts-rfq/test/FastBridgeV2.Src.t.sol Added new events for bridge operations; expanded tests for various scenarios, including edge cases for bridging and claiming processes.

Possibly related PRs

Suggested labels

go, size/m, M-synapse-interface, M-deps

Suggested reviewers

  • traian0x
  • ChiTimesChi

🐇 In the land of code where rabbits hop,
Nonces now track each sender's stop.
With events to cheer and tests that gleam,
FastBridgeV2 is now a coder's dream!
Hopping through edges, we claim and dispute,
Secure and robust, our changes are cute! 🐇


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.

@parodime parodime changed the title Feat/fb v2 sender nonce Feat/fb v2 sender nonce [SLT-183] Oct 1, 2024
Copy link

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 66c3611
Status: ✅  Deploy successful!
Preview URL: https://b444d76e.sanguine-fe.pages.dev
Branch Preview URL: https://feat-fbv2-sendernonce.sanguine-fe.pages.dev

View logs

Copy link

codecov bot commented Oct 1, 2024

Codecov Report

Attention: Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Project coverage is 90.59486%. Comparing base (f0b13bc) to head (66c3611).
Report is 34 commits behind head on master.

Files with missing lines Patch % Lines
packages/contracts-rfq/contracts/FastBridgeV2.sol 0.00000% 1 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                  @@
##              master       #3212          +/-   ##
====================================================
+ Coverage   40.97804%   90.59486%   +49.61682%     
====================================================
  Files            459          60         -399     
  Lines          25643        1244       -24399     
  Branches         343         148         -195     
====================================================
- Hits           10508        1127        -9381     
+ Misses         14383         113       -14270     
+ Partials         752           4         -748     
Flag Coverage Δ
cctp-relayer ?
core ?
ethergo ?
git-changes-action ?
omnirpc ?
opbot ?
screener-api ?
scribe ?
solidity 90.70796% <0.00000%> (-3.99877%) ⬇️
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
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 a9956da and 66c3611.

📒 Files selected for processing (2)
  • packages/contracts-rfq/contracts/FastBridgeV2.sol (3 hunks)
  • packages/contracts-rfq/test/FastBridgeV2.Src.t.sol (1 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
packages/contracts-rfq/contracts/FastBridgeV2.sol

[warning] 161-161: packages/contracts-rfq/contracts/FastBridgeV2.sol#L161
Added line #L161 was not covered by tests

🔇 Additional comments (4)
packages/contracts-rfq/test/FastBridgeV2.Src.t.sol (2)

141-142: Correct verification of per-sender nonce initialization

The assertions accurately confirm that after userA performs a bridge, their nonce is incremented to 1, while userB's nonce remains at 0. This validates that nonces are tracked individually per sender.


150-151: Proper nonce incrementation for userB after bridging

The assertions correctly ensure that after userB performs a bridge transaction, their nonce is incremented to 1, while userA's nonce remains unchanged at 1. This verifies independent nonce incrementation for each sender.

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

31-32: Good implementation of per-sender nonce tracking

The introduction of the senderNonces mapping effectively implements per-sender nonce tracking, enhancing security against replay attacks as outlined in the PR objectives.


73-73: Verify nonce incrementation safety

The use of senderNonces[params.sender]++ increments the nonce for the sender after it's used in the transaction. While this is generally acceptable, it's important to ensure that there are no potential reentrancy vulnerabilities that could exploit the nonce incrementation.

To confirm that the nonce incrementation is secure and not susceptible to reentrancy attacks, please run the following script:

@parodime parodime closed this Oct 2, 2024
@parodime parodime deleted the feat/FbV2-senderNonce branch October 2, 2024 16:07
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.

1 participant