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

no empty sender recip [SLT-184] #3171

Merged
merged 4 commits into from
Sep 26, 2024
Merged

Conversation

parodime
Copy link
Collaborator

@parodime parodime commented Sep 23, 2024

Description
Don’t allow empty sender/recipient addresses on bridge()

Summary by CodeRabbit

  • New Features

    • Enhanced input validation in the FastBridgeV2 contract to prevent transactions with zero addresses for key parameters.
  • Bug Fixes

    • Updated tests to ensure they run correctly, validating behavior when sender or recipient addresses are zero.

Copy link
Contributor

coderabbitai bot commented Sep 23, 2024

Walkthrough

The changes in this pull request enhance the input validation within the FastBridgeV2 contract by adding checks for zero addresses in multiple parameters. Specifically, the contract now verifies that params.sender and params.to are not zero addresses, alongside the existing checks for params.originToken and params.destToken. Additionally, tests related to these checks have been updated to ensure they run without being skipped.

Changes

File Change Summary
packages/contracts-rfq/contracts/FastBridgeV2.sol Added checks for zero addresses in params.sender and params.to.
packages/contracts-rfq/test/FastBridgeV2.Src.t.sol Removed vm.skip(true); from tests to allow validation of zero address checks.
packages/contracts-rfq/contracts/interfaces/IFastBridgeV2.sol Removed a blank line, no functional changes.

Possibly related PRs

Suggested labels

M-contracts, needs-go-generate-services/rfq, size/s

Suggested reviewers

  • trajan0x
  • ChiTimesChi

Poem

In the code where bunnies play,
We check for zeros every day.
No empty paths, no lost intent,
Each address clear, our code's well-spent.
With tests now running, all is bright,
Hop along, the future's light! 🐇✨


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between ffac31a and 0b2fcc6.

📒 Files selected for processing (2)
  • packages/contracts-rfq/contracts/FastBridgeV2.sol (1 hunks)
  • packages/contracts-rfq/test/FastBridgeV2.Src.t.sol (0 hunks)
💤 Files not reviewed due to no reviewable changes (1)
  • packages/contracts-rfq/test/FastBridgeV2.Src.t.sol
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/contracts-rfq/contracts/FastBridgeV2.sol

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
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)

82-87: Approve changes with a minor suggestion for readability

The added checks for zero addresses in params.sender and params.to align well with the PR objectives and improve the contract's security. This change prevents transactions with invalid addresses, which is a good practice.

For improved readability, consider using a helper function for zero address checks. This can make the code more concise and easier to maintain. Here's a suggestion:

function _isZeroAddress(address addr) private pure returns (bool) {
    return addr == address(0);
}

// In the bridge function:
if (
    _isZeroAddress(params.originToken) ||
    _isZeroAddress(params.destToken) ||
    _isZeroAddress(params.sender) ||
    _isZeroAddress(params.to)
) revert ZeroAddress();

This change is optional and up to your team's coding standards and preferences.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between faf9387 and 5e69efa.

Files selected for processing (2)
  • packages/contracts-rfq/contracts/FastBridgeV2.sol (1 hunks)
  • packages/contracts-rfq/test/FastBridgeV2.Src.t.sol (0 hunks)
Files not reviewed due to no reviewable changes (1)
  • packages/contracts-rfq/test/FastBridgeV2.Src.t.sol
Additional comments not posted (2)
packages/contracts-rfq/contracts/FastBridgeV2.sol (2)

Line range hint 1-391: Summary of changes and impact

The changes in this PR successfully address the objective of preventing empty sender and recipient addresses in the bridge function. This improvement enhances the security and robustness of the contract by ensuring that all critical address parameters are valid before proceeding with the bridge operation.

Key points:

  1. The implementation is correct and consistent with the existing code style.
  2. The changes are localized to the bridge function and do not introduce breaking changes.
  3. The additional checks may slightly increase gas costs, but this is offset by the security benefits.

The changes are approved and ready for merging, pending the verification of gas costs and any documentation updates as suggested in previous comments.


82-87: Verify gas cost impact and update documentation

The additional checks for zero addresses slightly increase the gas cost of the bridge function. While this increase is likely negligible, it's good practice to verify and document it.

Run the following script to compare gas costs before and after the change:

Consider updating the contract's documentation or comments to reflect this change in behavior. This could include:

  1. Adding a comment above the bridge function explaining the zero address checks.
  2. Updating any external documentation or specifications that describe the bridge function's behavior.

Copy link

codecov bot commented Sep 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 38.42159%. Comparing base (f0b13bc) to head (0b2fcc6).
Report is 2 commits behind head on master.

Additional details and impacted files
@@                 Coverage Diff                 @@
##              master       #3171         +/-   ##
===================================================
- Coverage   40.97804%   38.42159%   -2.55645%     
===================================================
  Files            459         424         -35     
  Lines          25643       24455       -1188     
  Branches         343         148        -195     
===================================================
- Hits           10508        9396       -1112     
+ Misses         14383       14318         -65     
+ Partials         752         741         -11     
Flag Coverage Δ
packages 90.56974% <ø> (ø)
solidity 90.86758% <100.00000%> (-3.83915%) ⬇️

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
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 with a minor styling nit

params.destToken == address(0) ||
params.sender == address(0) ||
params.to == address(0)
) revert ZeroAddress();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does two independent checks make more sense to you here? If not, this needs a // forgefmt: disable-next-item before this statement to avoid being formatted in a very ugly way (try doing forge fmt and the result is much less readable than what it is now).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

makes sense to me for readability with forge fmt in mind, but not logical sense :)

i went ahead and made it 2 lines. Also confirmed via forge tests that it only increases gas by a couple units

Copy link
Collaborator

Choose a reason for hiding this comment

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

lgtm

Copy link

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

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 0b2fcc6
Status: ✅  Deploy successful!
Preview URL: https://f0145e09.sanguine-fe.pages.dev
Branch Preview URL: https://feat-fbv2-noemptysenderrecip.sanguine-fe.pages.dev

View logs

Copy link

codecov bot commented Sep 25, 2024

Bundle Report

Changes will increase total bundle size by 251.65kB (0.7%) ⬆️. 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-server-cjs 1.47MB 147.19kB (-9.11%) ⬇️
widget-esm-cjs 273.3kB 10.65kB (-3.75%) ⬇️

Copy link

Changes to gas cost

Generated at commit: 63671fb7541451024184d5239a27d54364c9d218, compared to commit: f0b13bc456620004a1787f62e87f404d95272356

🧾 Summary (50% most significant diffs)

Contract Method Avg (+/-) %
FastBridgeV2 bridge +102 ❌ +0.11%

Full diff report 👇
Contract Deployment Cost (+/-) Method Min (+/-) % Avg (+/-) % Median (+/-) % Max (+/-) % # Calls (+/-)
FastBridgeV2 2,348,531 (+14,474) bridge 63,840 (+102) +0.16% 89,753 (+102) +0.11% 102,342 (+102) +0.10% 122,502 (+102) +0.08% 4,715 (0)

@parodime parodime merged commit e897b18 into master Sep 26, 2024
52 checks passed
@parodime parodime deleted the feat/FbV2-noEmptySenderRecip branch September 26, 2024 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants