synapsecns / sanguine

Synapse Monorepo
MIT License
43 stars 31 forks source link

feat(contracts-rfq): arbitrary calls without additional native value [SLT-233] #3215

Closed ChiTimesChi closed 1 month ago

ChiTimesChi commented 2 months ago

Description This is the first of the two PRs for the "Arbitrary Call" (final name pending) feature. The first PR adds the option to invoke a special function hook once the tokens have been transferred to the recipient:

https://github.com/synapsecns/sanguine/blob/ad7044902e50154faac6022df7d6eae756c699db/packages/contracts-rfq/contracts/interfaces/IFastBridgeRecipient.sol#L4-L13

The origin sender is given an option to provide callParams when initiating a bridge on the source chain.

The transactions with a hook function call will revert in one of these cases (this does not affect the legacy transactions):

The reverts do not put Relayer or Recipient funds at risk, in fact the transaction is only completed if the tokens are transferred to the recipient AND the hook call is successful (as reported by the recipient itself using the magic return value). The relayers are expected to simulate the transaction prior its submission to minimise the chances of the on-chain reverts.

Summary by CodeRabbit

coderabbitai[bot] commented 2 months ago

Walkthrough

The changes in this pull request enhance the FastBridgeV2 contract by introducing new functionalities and parameters. A constant MAX_CALL_PARAMS_LENGTH is added, and the bridge function is modified to include a callParams field in the BridgeParamsV2 struct. The relay function is updated to handle this new field, while a new _checkedCallRecipient method is introduced for safe recipient interactions. Additionally, a new interface IFastBridgeRecipient is created, and various mock contracts are added for testing purposes, expanding the testing framework for different recipient scenarios.

Changes

File Change Summary
packages/contracts-rfq/contracts/FastBridgeV2.sol - Added constant MAX_CALL_PARAMS_LENGTH.
- Updated bridge function to include callParams in BridgeParamsV2.
- Modified relay function to handle callParams.
- Introduced _checkedCallRecipient method.
packages/contracts-rfq/contracts/interfaces/IFastBridgeRecipient.sol - Added interface IFastBridgeRecipient.
- Introduced method fastBridgeTransferReceived with parameters for handling token transfers.
packages/contracts-rfq/contracts/interfaces/IFastBridgeV2.sol - Updated BridgeParamsV2 and BridgeTransactionV2 structs to include callParams.
packages/contracts-rfq/contracts/interfaces/IFastBridgeV2Errors.sol - Added new error declarations: CallParamsLengthAboveMax, RecipientIncorrectReturnValue, RecipientNoReturnValue.
packages/contracts-rfq/test/FastBridgeV2.Dst.ArbitraryCall.t.sol - Added contract FastBridgeV2DstArbitraryCallTest for testing various recipient behaviors with callParams.
packages/contracts-rfq/test/FastBridgeV2.GasBench.Dst.Excl.t.sol - Modified createFixturesV2 to include callParams in BridgeParamsV2.
packages/contracts-rfq/test/FastBridgeV2.Src.ArbitraryCall.t.sol - Introduced FastBridgeV2SrcArbitraryCallTest for testing callParams behavior and constraints.
packages/contracts-rfq/test/FastBridgeV2.Src.Exclusivity.t.sol - Refactored createFixturesV2 to utilize setTokenTestExclusivityParams and setEthTestExclusivityParams for setting parameters.
packages/contracts-rfq/test/FastBridgeV2.t.sol - Updated createFixturesV2 to initialize BridgeParamsV2 with callParams.
packages/contracts-rfq/test/mocks/ExcessiveReturnValueRecipient.sol - Added mock contract to simulate excessive return values in recipient behavior.
packages/contracts-rfq/test/mocks/IncorrectReturnValueRecipient.sol - Added mock contract to simulate incorrect return values in recipient behavior.
packages/contracts-rfq/test/mocks/NoOpContract.sol - Introduced a mock contract that accepts ETH without additional logic.
packages/contracts-rfq/test/mocks/NoReturnValueRecipient.sol - Added mock contract that simulates a recipient that does not return a value.
packages/contracts-rfq/test/mocks/NonPayableRecipient.sol - Introduced mock contract that simulates a non-payable recipient.
packages/contracts-rfq/test/mocks/RecipientMock.sol - Added mock contract implementing IFastBridgeRecipient for testing transfers.

Possibly related PRs

Suggested labels

needs-go-generate-services/rfq, javascript, Sol, Typescript

Suggested reviewers

Poem

In the meadow, where bunnies play,
FastBridgeV2 hops in a new way.
With callParams, it leaps so high,
Handling tokens that flutter and fly.
Errors caught with a gentle grace,
In our code, we find our place! πŸ‡βœ¨


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 - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
πŸͺ§ Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit , 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](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
github-actions[bot] commented 2 months ago

Changes to gas cost

Generated at commit: 60adda7d462c4d242c1494eb5f29a663598f37d2, compared to commit: 74e16906f3563e8592da5f88364ca51b532aaa4b

🧾 Summary (50% most significant diffs)

Contract Method Avg (+/-) %
FastBridgeV2 bridgeProofs
bridgeRelayDetails
claim(bytes)
claim(bytes,address)
getBridgeTransactionV2
protocolFees
refund
-22 βœ…
+111 ❌
+1,175 ❌
+1,197 ❌
+1,101 ❌
-22 βœ…
+1,175 ❌
-3.41%
+17.54%
+2.34%
+2.31%
+35.37%
-1.92%
+2.34%

Full diff report πŸ‘‡
| Contract | Deployment Cost (+/-) | Method | Min (+/-) | % | Avg (+/-) | % | Median (+/-) | % | Max (+/-) | % | # Calls (+/-) | |:-|-:|:-|-:|-:|-:|-:|-:|-:|-:|-:|-:| | **FastBridgeV2** | 2,863,912 (+163,236) | _GOVERNOR_ROLE_
_RELAYER_ROLE_
_bridge((uint32,address,address,address,address,uint256,uint256,bool,uint256))_
_bridgeProofs_
_bridgeRelayDetails_
_canClaim_
_claim(bytes)_
_claim(bytes,address)_
_dispute_
_getBridgeTransaction_
_getBridgeTransactionV2_
_nonce_
_protocolFees_
_prove(bytes,bytes32)_
_prove(bytes32,bytes32,address)_
_refund_
_relay(bytes)_
_relay(bytes,address)_
_setProtocolFeeRate_ | 294 (-22)
307 (-22)
68,530 (+1,363)
624 (-22)
744 (+111)
3,163 (-22)
43,909 (+1,155)
46,762 (+1,177)
31,284 (+110)
2,963 (+37)
4,214 (+1,101)
240 (-22)
623 (-22)
35,583 (+494)
32,116 (-24)
47,669 (+1,155)
64,685 (-800)
65,102 (-820)
47,399 (-22) | **-6.96%**
**-6.69%**
**+2.03%**
**-3.41%**
**+17.54%**
**-0.69%**
**+2.70%**
**+2.58%**
**+0.35%**
**+1.26%**
**+35.37%**
**-8.40%**
**-3.41%**
**+1.41%**
**-0.07%**
**+2.48%**
**-1.22%**
**-1.24%**
**-0.05%** | 294 (-22)
307 (-22)
83,548 (+1,383)
624 (-22)
744 (+111)
3,163 (-22)
51,463 (+1,175)
53,066 (+1,197)
31,284 (+110)
2,963 (+37)
4,214 (+1,101)
240 (-22)
1,123 (-22)
35,610 (+494)
32,139 (-1)
51,395 (+1,175)
70,600 (-780)
71,017 (-800)
47,399 (-22) | **-6.96%**
**-6.69%**
**+1.68%**
**-3.41%**
**+17.54%**
**-0.69%**
**+2.34%**
**+2.31%**
**+0.35%**
**+1.26%**
**+35.37%**
**-8.40%**
**-1.92%**
**+1.41%**
**-0.00%**
**+2.34%**
**-1.09%**
**-1.11%**
**-0.05%** | 294 (-22)
307 (-22)
79,383 (+1,383)
624 (-22)
744 (+111)
3,163 (-22)
51,472 (+1,175)
53,075 (+1,197)
31,284 (+110)
2,963 (+37)
4,214 (+1,101)
240 (-22)
623 (-22)
35,613 (+494)
32,140 (0)
51,404 (+1,175)
70,600 (-780)
71,017 (-800)
47,399 (-22) | **-6.96%**
**-6.69%**
**+1.77%**
**-3.41%**
**+17.54%**
**-0.69%**
**+2.34%**
**+2.31%**
**+0.35%**
**+1.26%**
**+35.37%**
**-8.40%**
**-3.41%**
**+1.41%**
**0.00%**
**+2.34%**
**-1.09%**
**-1.11%**
**-0.05%** | 294 (-22)
307 (-22)
107,337 (+1,404)
624 (-22)
744 (+111)
3,163 (-22)
59,000 (+1,196)
59,353 (+1,218)
31,284 (+110)
2,963 (+37)
4,214 (+1,101)
240 (-22)
2,623 (-22)
35,727 (+494)
32,140 (0)
55,104 (+1,196)
76,516 (-760)
76,933 (-780)
47,399 (-22) | **-6.96%**
**-6.69%**
**+1.33%**
**-3.41%**
**+17.54%**
**-0.69%**
**+2.07%**
**+2.10%**
**+0.35%**
**+1.26%**
**+35.37%**
**-8.40%**
**-0.83%**
**+1.40%**
**0.00%**
**+2.22%**
**-0.98%**
**-1.00%**
**-0.05%** | 19 (0)
82 (0)
156 (0)
8 (0)
4 (0)
8 (0)
4 (0)
4 (0)
4 (0)
1 (0)
1 (0)
3 (0)
328 (0)
42 (0)
42 (0)
8 (0)
2 (0)
2 (0)
19 (0) |
codecov[bot] commented 2 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 90.78014%. Comparing base (ad48cb0) to head (02ba663). Report is 37 commits behind head on master.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #3215 +/- ## ==================================================== + Coverage 24.92918% 90.78014% +65.85096% ==================================================== Files 198 60 -138 Lines 13061 1269 -11792 Branches 82 154 +72 ==================================================== - Hits 3256 1152 -2104 + Misses 9523 114 -9409 + Partials 282 3 -279 ``` | [Flag](https://app.codecov.io/gh/synapsecns/sanguine/pull/3215/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=synapsecns) | Coverage Ξ” | | |---|---|---| | [opbot](https://app.codecov.io/gh/synapsecns/sanguine/pull/3215/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=synapsecns) | `?` | | | [packages](https://app.codecov.io/gh/synapsecns/sanguine/pull/3215/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=synapsecns) | `90.45764% <ΓΈ> (-0.11210%)` | :arrow_down: | | [promexporter](https://app.codecov.io/gh/synapsecns/sanguine/pull/3215/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=synapsecns) | `?` | | | [rfq](https://app.codecov.io/gh/synapsecns/sanguine/pull/3215/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=synapsecns) | `?` | | | [solidity](https://app.codecov.io/gh/synapsecns/sanguine/pull/3215/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=synapsecns) | `92.14876% <100.00000%> (?)` | | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=synapsecns#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

cloudflare-workers-and-pages[bot] commented 2 months ago

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 02ba663
Status: βœ…  Deploy successful!
Preview URL: https://fc715868.sanguine-fe.pages.dev
Branch Preview URL: https://feat-fbv2-arbitrary-call.sanguine-fe.pages.dev

View logs

codecov[bot] commented 2 months ago

Bundle Report

Bundle size has no change :white_check_mark: