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: improve revert handling #361

Merged
merged 23 commits into from
Sep 27, 2024
Merged

feat: improve revert handling #361

merged 23 commits into from
Sep 27, 2024

Conversation

skosito
Copy link
Contributor

@skosito skosito commented Sep 25, 2024

  • removes revert from UniversalContract interface
  • prevents calling onRevert in arbitrary call in GatewayEVM
  • adds sender to RevertContext

base is auth call branch, please dont merge until that one is merged

Summary by CodeRabbit

  • New Features

    • Enhanced revert operation context by adding the sender's address to the revert structure.
    • Introduced specific error handling for unauthorized calls to the onRevert method.
  • Bug Fixes

    • Improved security by restricting unauthorized access to critical functions.
  • Tests

    • Updated tests to include the sender field in revert context for better error handling and debugging.
    • Added new test cases to ensure proper handling of unauthorized revert calls.

Copy link
Contributor

coderabbitai bot commented Sep 25, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes in this pull request involve multiple modifications across several Solidity files, primarily focusing on enhancing the RevertContext struct by adding a sender field to capture the address of the initiating account. Additionally, the GatewayEVM contract's function for validating calls has been renamed and its logic altered to improve security. The UniversalContract interface has had the onRevert function removed, and error handling has been improved with the addition of a new error in the IGatewayEVMErrors interface.

Changes

File Path Change Summary
v2/contracts/Revert.sol Added address sender field to RevertContext struct.
v2/contracts/evm/GatewayEVM.sol Renamed revertIfAuthenticatedCall to revertIfOnCallOrOnRevert and updated its logic.
v2/contracts/evm/interfaces/IGatewayEVM.sol Added new error NotAllowedToCallOnRevert to the interface.
v2/contracts/zevm/GatewayZEVM.sol Updated calls from UniversalContract to Revertable in executeRevert and deposit functions.
v2/contracts/zevm/interfaces/UniversalContract.sol Removed onRevert function from the UniversalContract interface.
v2/test/ERC20Custody.t.sol Updated revertContext initialization to include sender.
v2/test/GatewayEVM.t.sol Updated revertContext to include sender and added new test for unauthorized onRevert calls.
v2/test/GatewayZEVM.t.sol Updated revertContext initialization to include sender.
v2/test/ZetaConnectorNative.t.sol Updated revertContext initialization to include sender.
v2/test/ZetaConnectorNonNative.t.sol Updated revertContext initialization to include sender.
v2/test/utils/TestUniversalContract.sol Updated class signature to inherit from Revertable in addition to UniversalContract.

Possibly related issues

Possibly related PRs

Suggested reviewers

  • fadeev
  • CharlieMc0
  • andresaiello
  • brewmaster012
  • lumtis
  • fbac

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.

@codecov-commenter
Copy link

codecov-commenter commented Sep 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.10%. Comparing base (7175604) to head (42c1ede).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #361      +/-   ##
==========================================
+ Coverage   83.00%   83.10%   +0.09%     
==========================================
  Files           8        8              
  Lines         359      361       +2     
  Branches      117      118       +1     
==========================================
+ Hits          298      300       +2     
  Misses         61       61              

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

Copy link
Member

@lumtis lumtis left a comment

Choose a reason for hiding this comment

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

LGTM

@skosito skosito requested a review from fadeev September 25, 2024 12:36
Base automatically changed from protocol-integration-auth-call to main September 27, 2024 11:36
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

🧹 Outside diff range and nitpick comments (6)
v2/test/utils/TestUniversalContract.sol (1)

Line range hint 1-70: Overall impact: Revert handling capability added

The changes to this contract are minimal and focused on adding revert-handling capabilities through the implementation of the Revertable interface. The existing onRevert function seems to align with this new interface, but this should be verified. As no other changes were made to the contract's functionality, it appears that existing behavior should remain intact.

To ensure the contract's integrity:

  1. Verify that the onRevert function fully complies with the Revertable interface requirements.
  2. Conduct thorough testing of all existing functionality to confirm that the addition of Revertable hasn't introduced any unintended side effects.
  3. Add new test cases specifically for the revert-handling capabilities introduced by implementing Revertable.
v2/contracts/evm/interfaces/IGatewayEVM.sol (1)

87-88: LGTM! Consider adding a comment for clarity.

The new error NotAllowedToCallOnRevert is a logical addition to the interface, complementing the existing NotAllowedToCallOnCall error. It aligns well with the PR objective of preventing the invocation of the onRevert function during arbitrary calls in the GatewayEVM.

Consider adding a brief comment explaining when this error is thrown, similar to other errors in the interface. For example:

/// @notice Error when trying to call onRevert method using arbitrary call.
error NotAllowedToCallOnRevert();
v2/test/ZetaConnectorNative.t.sol (1)

Line range hint 1-365: Enhance testWithdrawAndRevert() to verify the 'sender' field

While the change in the setUp() function doesn't introduce any breaking changes, it provides an opportunity to enhance the testWithdrawAndRevert() function. Consider adding an assertion to verify that the 'sender' field in the RevertContext is correctly set and used during the test.

Add the following assertion to the testWithdrawAndRevert() function:

assertEq(revertContext.sender, owner, "RevertContext sender should be set to owner");

This will ensure that the 'sender' field is correctly initialized and maintained throughout the test execution.

v2/contracts/zevm/GatewayZEVM.sol (1)

Line range hint 1-502: Consider updating other functions for consistency

While the changes made align with the PR objectives, it's worth considering if other functions that still use UniversalContract (e.g., execute and depositAndCall) should also be updated for consistency. This depends on whether these functions are intended to handle revert operations or if they serve different purposes.

v2/contracts/evm/GatewayEVM.sol (2)

Line range hint 432-446: Refactor to remove inline assembly for safer code

The revertIfOnCallOrOnRevert function uses inline assembly to extract the function selector from data. Using Solidity's built-in functions can improve readability and safety by eliminating low-level code.

Apply this diff to refactor the function without inline assembly:

 function revertIfOnCallOrOnRevert(bytes calldata data) private pure {
     if (data.length >= 4) {
-        bytes4 functionSelector;
-        assembly {
-            functionSelector := calldataload(data.offset)
-        }
+        bytes4 functionSelector = bytes4(data[:4]);
 
         if (functionSelector == Callable.onCall.selector) {
             revert NotAllowedToCallOnCall();
         }
 
-        
         if (functionSelector == Revertable.onRevert.selector) {
             revert NotAllowedToCallOnRevert();
         }
     }
 }

This change enhances code safety and maintainability by utilizing high-level Solidity features.


Line range hint 432-446: Optimize conditional statements to avoid redundant checks

Currently, both if conditions are checked independently, even though only one can be true at a time. Combining them using else if can slightly improve efficiency.

Apply this diff to optimize the conditional logic:

 function revertIfOnCallOrOnRevert(bytes calldata data) private pure {
     if (data.length >= 4) {
         bytes4 functionSelector = bytes4(data[:4]);
         if (functionSelector == Callable.onCall.selector) {
             revert NotAllowedToCallOnCall();
-        }
-
-        if (functionSelector == Revertable.onRevert.selector) {
+        } else if (functionSelector == Revertable.onRevert.selector) {
             revert NotAllowedToCallOnRevert();
         }
     }
 }

This adjustment prevents the second condition from being evaluated if the first condition is true.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 7175604 and ed3bd44.

⛔ Files ignored due to path filters (119)
  • v2/docs/src/SUMMARY.md is excluded by !v2/docs/**
  • v2/docs/src/contracts/Revert.sol/interface.Revertable.md is excluded by !v2/docs/**
  • v2/docs/src/contracts/Revert.sol/struct.RevertContext.md is excluded by !v2/docs/**
  • v2/docs/src/contracts/Revert.sol/struct.RevertOptions.md is excluded by !v2/docs/**
  • v2/docs/src/contracts/evm/ERC20Custody.sol/contract.ERC20Custody.md is excluded by !v2/docs/**
  • v2/docs/src/contracts/evm/GatewayEVM.sol/contract.GatewayEVM.md is excluded by !v2/docs/**
  • v2/docs/src/contracts/evm/ZetaConnectorBase.sol/abstract.ZetaConnectorBase.md is excluded by !v2/docs/**
  • v2/docs/src/contracts/evm/ZetaConnectorNative.sol/contract.ZetaConnectorNative.md is excluded by !v2/docs/**
  • v2/docs/src/contracts/evm/ZetaConnectorNonNative.sol/contract.ZetaConnectorNonNative.md is excluded by !v2/docs/**
  • v2/docs/src/contracts/evm/interfaces/IERC20Custody.sol/interface.IERC20Custody.md is excluded by !v2/docs/**
  • v2/docs/src/contracts/evm/interfaces/IERC20Custody.sol/interface.IERC20CustodyErrors.md is excluded by !v2/docs/**
  • v2/docs/src/contracts/evm/interfaces/IERC20Custody.sol/interface.IERC20CustodyEvents.md is excluded by !v2/docs/**
  • v2/docs/src/contracts/evm/interfaces/IGatewayEVM.sol/interface.Callable.md is excluded by !v2/docs/**
  • v2/docs/src/contracts/evm/interfaces/IGatewayEVM.sol/interface.IGatewayEVM.md is excluded by !v2/docs/**
  • v2/docs/src/contracts/evm/interfaces/IGatewayEVM.sol/interface.IGatewayEVMErrors.md is excluded by !v2/docs/**
  • v2/docs/src/contracts/evm/interfaces/IGatewayEVM.sol/interface.IGatewayEVMEvents.md is excluded by !v2/docs/**
  • v2/docs/src/contracts/evm/interfaces/IGatewayEVM.sol/struct.MessageContext.md is excluded by !v2/docs/**
  • v2/docs/src/contracts/evm/interfaces/IZetaConnector.sol/interface.IZetaConnectorEvents.md is excluded by !v2/docs/**
  • v2/docs/src/contracts/evm/interfaces/IZetaNonEthNew.sol/interface.IZetaNonEthNew.md is excluded by !v2/docs/**
  • v2/docs/src/contracts/evm/interfaces/README.md is excluded by !v2/docs/**
  • v2/docs/src/contracts/zevm/GatewayZEVM.sol/contract.GatewayZEVM.md is excluded by !v2/docs/**
  • v2/docs/src/contracts/zevm/README.md is excluded by !v2/docs/**
  • v2/docs/src/contracts/zevm/SystemContract.sol/contract.SystemContract.md is excluded by !v2/docs/**
  • v2/docs/src/contracts/zevm/SystemContract.sol/interface.SystemContractErrors.md is excluded by !v2/docs/**
  • v2/docs/src/contracts/zevm/ZRC20.sol/contract.ZRC20.md is excluded by !v2/docs/**
  • v2/docs/src/contracts/zevm/ZRC20.sol/interface.ZRC20Errors.md is excluded by !v2/docs/**
  • v2/docs/src/contracts/zevm/interfaces/IGatewayZEVM.sol/interface.IGatewayZEVM.md is excluded by !v2/docs/**
  • v2/docs/src/contracts/zevm/interfaces/IGatewayZEVM.sol/interface.IGatewayZEVMErrors.md is excluded by !v2/docs/**
  • v2/docs/src/contracts/zevm/interfaces/IGatewayZEVM.sol/interface.IGatewayZEVMEvents.md is excluded by !v2/docs/**
  • v2/docs/src/contracts/zevm/interfaces/IGatewayZEVM.sol/struct.CallOptions.md is excluded by !v2/docs/**
  • v2/docs/src/contracts/zevm/interfaces/ISystem.sol/interface.ISystem.md is excluded by !v2/docs/**
  • v2/docs/src/contracts/zevm/interfaces/IWZETA.sol/interface.IWETH9.md is excluded by !v2/docs/**
  • v2/docs/src/contracts/zevm/interfaces/IZRC20.sol/enum.CoinType.md is excluded by !v2/docs/**
  • v2/docs/src/contracts/zevm/interfaces/IZRC20.sol/interface.IZRC20.md is excluded by !v2/docs/**
  • v2/docs/src/contracts/zevm/interfaces/IZRC20.sol/interface.IZRC20Metadata.md is excluded by !v2/docs/**
  • v2/docs/src/contracts/zevm/interfaces/IZRC20.sol/interface.ZRC20Events.md is excluded by !v2/docs/**
  • v2/docs/src/contracts/zevm/interfaces/README.md is excluded by !v2/docs/**
  • v2/docs/src/contracts/zevm/interfaces/UniversalContract.sol/interface.UniversalContract.md is excluded by !v2/docs/**
  • v2/docs/src/contracts/zevm/interfaces/UniversalContract.sol/interface.zContract.md is excluded by !v2/docs/**
  • v2/docs/src/contracts/zevm/interfaces/UniversalContract.sol/struct.zContext.md is excluded by !v2/docs/**
  • v2/docs/src/index.md is excluded by !v2/docs/**
  • v2/pkg/erc20custody.sol/erc20custody.go is excluded by !v2/pkg/**
  • v2/pkg/erc20custody.t.sol/erc20custodytest.go is excluded by !v2/pkg/**
  • v2/pkg/erc20custodyechidnatest.sol/erc20custodyechidnatest.go is excluded by !v2/pkg/**
  • v2/pkg/gatewayevm.sol/gatewayevm.go is excluded by !v2/pkg/**
  • v2/pkg/gatewayevm.t.sol/gatewayevminboundtest.go is excluded by !v2/pkg/**
  • v2/pkg/gatewayevm.t.sol/gatewayevmtest.go is excluded by !v2/pkg/**
  • v2/pkg/gatewayevmechidnatest.sol/gatewayevmechidnatest.go is excluded by !v2/pkg/**
  • v2/pkg/gatewayevmupgrade.t.sol/gatewayevmuupsupgradetest.go is excluded by !v2/pkg/**
  • v2/pkg/gatewayevmupgradetest.sol/gatewayevmupgradetest.go is excluded by !v2/pkg/**
  • v2/pkg/gatewayevmzevm.t.sol/gatewayevmzevmtest.go is excluded by !v2/pkg/**
  • v2/pkg/gatewayzevm.sol/gatewayzevm.go is excluded by !v2/pkg/**
  • v2/pkg/gatewayzevm.t.sol/gatewayzevminboundtest.go is excluded by !v2/pkg/**
  • v2/pkg/gatewayzevm.t.sol/gatewayzevmoutboundtest.go is excluded by !v2/pkg/**
  • v2/pkg/ierc20custody.sol/ierc20custody.go is excluded by !v2/pkg/**
  • v2/pkg/ierc20custody.sol/ierc20custodyevents.go is excluded by !v2/pkg/**
  • v2/pkg/igatewayevm.sol/igatewayevm.go is excluded by !v2/pkg/**
  • v2/pkg/igatewayevm.sol/igatewayevmerrors.go is excluded by !v2/pkg/**
  • v2/pkg/igatewayevm.sol/igatewayevmevents.go is excluded by !v2/pkg/**
  • v2/pkg/igatewayzevm.sol/igatewayzevm.go is excluded by !v2/pkg/**
  • v2/pkg/ireceiverevm.sol/ireceiverevmevents.go is excluded by !v2/pkg/**
  • v2/pkg/izetaconnector.sol/izetaconnectorevents.go is excluded by !v2/pkg/**
  • v2/pkg/receiverevm.sol/receiverevm.go is excluded by !v2/pkg/**
  • v2/pkg/revert.sol/revertable.go is excluded by !v2/pkg/**
  • v2/pkg/senderzevm.sol/senderzevm.go is excluded by !v2/pkg/**
  • v2/pkg/systemcontract.sol/systemcontract.go is excluded by !v2/pkg/**
  • v2/pkg/systemcontractmock.sol/systemcontractmock.go is excluded by !v2/pkg/**
  • v2/pkg/testuniversalcontract.sol/testuniversalcontract.go is excluded by !v2/pkg/**
  • v2/pkg/universalcontract.sol/universalcontract.go is excluded by !v2/pkg/**
  • v2/pkg/zetaconnectorbase.sol/zetaconnectorbase.go is excluded by !v2/pkg/**
  • v2/pkg/zetaconnectornative.sol/zetaconnectornative.go is excluded by !v2/pkg/**
  • v2/pkg/zetaconnectornative.t.sol/zetaconnectornativetest.go is excluded by !v2/pkg/**
  • v2/pkg/zetaconnectornonnative.sol/zetaconnectornonnative.go is excluded by !v2/pkg/**
  • v2/pkg/zetaconnectornonnative.t.sol/zetaconnectornonnativetest.go is excluded by !v2/pkg/**
  • v2/pkg/zrc20.t.sol/zrc20test.go is excluded by !v2/pkg/**
  • v2/types/ERC20Custody.ts is excluded by !v2/types/**
  • v2/types/ERC20CustodyEchidnaTest.ts is excluded by !v2/types/**
  • v2/types/GatewayEVM.ts is excluded by !v2/types/**
  • v2/types/GatewayEVMEchidnaTest.ts is excluded by !v2/types/**
  • v2/types/GatewayEVMUpgradeTest.ts is excluded by !v2/types/**
  • v2/types/GatewayZEVM.ts is excluded by !v2/types/**
  • v2/types/IERC20Custody.sol/IERC20Custody.ts is excluded by !v2/types/**
  • v2/types/IERC20Custody.sol/IERC20CustodyEvents.ts is excluded by !v2/types/**
  • v2/types/IGatewayEVM.sol/IGatewayEVM.ts is excluded by !v2/types/**
  • v2/types/IGatewayEVM.sol/IGatewayEVMEvents.ts is excluded by !v2/types/**
  • v2/types/IGatewayZEVM.sol/IGatewayZEVM.ts is excluded by !v2/types/**
  • v2/types/IReceiverEVM.sol/IReceiverEVMEvents.ts is excluded by !v2/types/**
  • v2/types/IZetaConnector.sol/IZetaConnectorEvents.ts is excluded by !v2/types/**
  • v2/types/ReceiverEVM.ts is excluded by !v2/types/**
  • v2/types/Revert.sol/Revertable.ts is excluded by !v2/types/**
  • v2/types/TestUniversalContract.ts is excluded by !v2/types/**
  • v2/types/UniversalContract.sol/UniversalContract.ts is excluded by !v2/types/**
  • v2/types/ZetaConnectorBase.ts is excluded by !v2/types/**
  • v2/types/ZetaConnectorNative.ts is excluded by !v2/types/**
  • v2/types/ZetaConnectorNonNative.ts is excluded by !v2/types/**
  • v2/types/factories/ERC20CustodyEchidnaTest__factory.ts is excluded by !v2/types/**
  • v2/types/factories/ERC20Custody__factory.ts is excluded by !v2/types/**
  • v2/types/factories/GatewayEVMEchidnaTest__factory.ts is excluded by !v2/types/**
  • v2/types/factories/GatewayEVMUpgradeTest__factory.ts is excluded by !v2/types/**
  • v2/types/factories/GatewayEVM__factory.ts is excluded by !v2/types/**
  • v2/types/factories/GatewayZEVM__factory.ts is excluded by !v2/types/**
  • v2/types/factories/IERC20Custody.sol/IERC20CustodyEvents__factory.ts is excluded by !v2/types/**
  • v2/types/factories/IERC20Custody.sol/IERC20Custody__factory.ts is excluded by !v2/types/**
  • v2/types/factories/IGatewayEVM.sol/IGatewayEVMErrors__factory.ts is excluded by !v2/types/**
  • v2/types/factories/IGatewayEVM.sol/IGatewayEVMEvents__factory.ts is excluded by !v2/types/**
  • v2/types/factories/IGatewayEVM.sol/IGatewayEVM__factory.ts is excluded by !v2/types/**
  • v2/types/factories/IGatewayZEVM.sol/IGatewayZEVM__factory.ts is excluded by !v2/types/**
  • v2/types/factories/IReceiverEVM.sol/IReceiverEVMEvents__factory.ts is excluded by !v2/types/**
  • v2/types/factories/IZetaConnector.sol/IZetaConnectorEvents__factory.ts is excluded by !v2/types/**
  • v2/types/factories/ReceiverEVM__factory.ts is excluded by !v2/types/**
  • v2/types/factories/Revert.sol/Revertable__factory.ts is excluded by !v2/types/**
  • v2/types/factories/SenderZEVM__factory.ts is excluded by !v2/types/**
  • v2/types/factories/SystemContract.sol/SystemContract__factory.ts is excluded by !v2/types/**
  • v2/types/factories/SystemContractMock.sol/SystemContractMock__factory.ts is excluded by !v2/types/**
  • v2/types/factories/TestUniversalContract__factory.ts is excluded by !v2/types/**
  • v2/types/factories/UniversalContract.sol/UniversalContract__factory.ts is excluded by !v2/types/**
  • v2/types/factories/ZetaConnectorBase__factory.ts is excluded by !v2/types/**
  • v2/types/factories/ZetaConnectorNative__factory.ts is excluded by !v2/types/**
  • v2/types/factories/ZetaConnectorNonNative__factory.ts is excluded by !v2/types/**
📒 Files selected for processing (11)
  • v2/contracts/Revert.sol (1 hunks)
  • v2/contracts/evm/GatewayEVM.sol (3 hunks)
  • v2/contracts/evm/interfaces/IGatewayEVM.sol (1 hunks)
  • v2/contracts/zevm/GatewayZEVM.sol (3 hunks)
  • v2/contracts/zevm/interfaces/UniversalContract.sol (0 hunks)
  • v2/test/ERC20Custody.t.sol (1 hunks)
  • v2/test/GatewayEVM.t.sol (2 hunks)
  • v2/test/GatewayZEVM.t.sol (1 hunks)
  • v2/test/ZetaConnectorNative.t.sol (1 hunks)
  • v2/test/ZetaConnectorNonNative.t.sol (1 hunks)
  • v2/test/utils/TestUniversalContract.sol (1 hunks)
💤 Files not reviewed due to no reviewable changes (1)
  • v2/contracts/zevm/interfaces/UniversalContract.sol
🔇 Additional comments (16)
v2/contracts/Revert.sol (2)

Line range hint 1-38: The overall structure and documentation of the file are well-maintained.

The file is well-organized with appropriate use of comments, clear struct definitions, and a concise interface declaration. The use of a recent Solidity version (0.8.26) is commendable. The MIT license is correctly specified at the beginning of the file.


19-24: LGTM! The addition of the sender field enhances the context provided during revert operations.

The new sender field in the RevertContext struct is a valuable addition. It provides more context during revert scenarios by capturing the address of the account that initiated the smart contract call. This change is well-documented with a clear and concise comment.

To ensure this change is consistently applied throughout the codebase, let's verify its usage:

✅ Verification successful

Retrying search without specifying file type for Solidity files.

To accurately verify the usage of RevertContext and the implementation of onRevert functions, let's search for .sol files directly and inspect their contents:


The addition of the sender field to RevertContext has been successfully and consistently implemented across the codebase.

The verification process shows that the RevertContext struct now includes the sender field in all relevant parts of the project, including contracts, interfaces, and generated bindings. The onRevert function implementations are correctly using the updated RevertContext structure.

No inconsistencies or uses of the old RevertContext structure were found during this verification. The change appears to have been applied thoroughly and correctly throughout the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for RevertContext usage and ensure the sender field is properly handled

# Search for RevertContext struct usage
echo "Searching for RevertContext usage:"
rg --type solidity -A 5 'RevertContext'

# Search for onRevert function implementations
echo "Searching for onRevert function implementations:"
rg --type solidity -A 10 'function onRevert\('

Length of output: 340


Script:

#!/bin/bash
# Description: Search for RevertContext usage and onRevert function implementations in Solidity files

# Find all Solidity files and search for RevertContext
echo "Searching for RevertContext usage in .sol files:"
fd --extension sol | xargs rg 'RevertContext'

# Find all Solidity files and search for onRevert function implementations
echo "Searching for onRevert function implementations in .sol files:"
fd --extension sol | xargs rg 'function onRevert\('

Length of output: 372892

v2/test/utils/TestUniversalContract.sol (2)

6-6: LGTM: Import statement updated correctly

The import statement has been properly updated to include both RevertContext and Revertable from the Revert.sol file. This change is consistent with the modifications in the contract declaration and suggests the implementation of revert-handling functionality.


12-12: LGTM: Contract inheritance updated correctly

The contract declaration has been properly updated to include inheritance from both UniversalContract and Revertable. This change is consistent with the updated import statement and suggests the implementation of additional revert-handling functionality.

To ensure full compliance with the Revertable interface, please run the following script to verify the interface implementation:

✅ Verification successful

Verified: Revertable interface implemented correctly

The TestUniversalContract correctly inherits from both UniversalContract and Revertable, and implements the onRevert function with the appropriate signature as required by the Revertable interface.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the Revertable interface implementation in TestUniversalContract

# Test 1: Check if TestUniversalContract implements all methods from Revertable
echo "Checking Revertable interface implementation:"
ast-grep --lang solidity --pattern 'interface Revertable { $$$ }'
echo "TestUniversalContract implementation:"
ast-grep --lang solidity --pattern 'contract TestUniversalContract is UniversalContract, Revertable { $$$ }'

# Test 2: Verify onRevert function signature
echo "Verifying onRevert function signature:"
ast-grep --lang solidity --pattern 'function onRevert(RevertContext calldata revertContext) external'

Length of output: 906


Script:

#!/bin/bash
# Description: Verify the Revertable interface implementation in TestUniversalContract using ripgrep

# Test 1: Check if Revertable interface exists
echo "Searching for Revertable interface definition:"
rg 'interface\s+Revertable\s*\{'

# Test 2: Check if TestUniversalContract inherits from Revertable
echo "Checking TestUniversalContract inheritance:"
rg 'contract\s+TestUniversalContract\s+is\s+UniversalContract,\s+Revertable\s*\{'

# Test 3: Verify onRevert function signature
echo "Verifying onRevert function signature in TestUniversalContract:"
rg 'function\s+onRevert\s*\(\s*RevertContext\s+calldata\s+revertContext\s*\)\s+external'

Length of output: 1137

v2/contracts/evm/interfaces/IGatewayEVM.sol (2)

Line range hint 1-88: Summary: Minimal, focused change improving revert handling.

The addition of the NotAllowedToCallOnRevert error to the IGatewayEVMErrors interface is a targeted improvement that aligns well with the PR objectives. This change:

  1. Enhances error handling capabilities for the GatewayEVM.
  2. Maintains consistency with existing error definitions.
  3. Doesn't introduce breaking changes to the interface.

The modification is minimal yet impactful, providing a clear mechanism to prevent arbitrary calls from invoking the onRevert function. This change contributes to a more robust and secure implementation of the GatewayEVM.


87-88: Verify usage of the new error in the implementation.

The new NotAllowedToCallOnRevert error has been added to the IGatewayEVMErrors interface. To ensure its effectiveness, we should verify that it's being used appropriately in the GatewayEVM implementation.

Let's check the implementation file for the usage of this new error:

This script will help us confirm that the new error is being used in the implementation, ensuring that the interface change is fully utilized.

✅ Verification successful

Further verification needed to locate NotAllowedToCallOnRevert usage correctly.


Further verification needed to locate NotAllowedToCallOnRevert usage correctly.


Usage of NotAllowedToCallOnRevert verified in the implementation.

  • The error is declared in IGatewayEVM.sol.
  • It is properly used in GatewayEVM.sol with a revert statement.
  • Tests in GatewayEVM.t.sol correctly expect this specific revert.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for the usage of NotAllowedToCallOnRevert error in the implementation file.

# Find the GatewayEVM implementation file
implementation_file=$(fd -e sol -t f GatewayEVM)

if [ -z "$implementation_file" ]; then
    echo "GatewayEVM implementation file not found."
    exit 1
fi

# Search for the usage of NotAllowedToCallOnRevert
echo "Searching for NotAllowedToCallOnRevert usage in $implementation_file:"
rg "NotAllowedToCallOnRevert" "$implementation_file"

# If not found, it might be using a require statement instead
if [ $? -ne 0 ]; then
    echo "NotAllowedToCallOnRevert not found. Searching for related require statements:"
    rg "require\(.*onRevert.*\)" "$implementation_file"
fi

Length of output: 3318


Script:

#!/bin/bash
# Description: Search for the usage of NotAllowedToCallOnRevert error across all Solidity files.

# Search for the usage of NotAllowedToCallOnRevert in all .sol files
echo "Searching for NotAllowedToCallOnRevert usage in the codebase:"
rg "NotAllowedToCallOnRevert" --type sol

# If not found, search for related require statements handling onRevert
if [ $? -ne 0 ]; then
    echo "NotAllowedToCallOnRevert not found. Searching for related require statements:"
    rg "require\(.*onRevert.*\)" --type sol
fi

Length of output: 454


Script:

#!/bin/bash
# Description: Search for the usage of NotAllowedToCallOnRevert error across all Solidity files.

# Search for the usage of NotAllowedToCallOnRevert in all .sol files
echo "Searching for NotAllowedToCallOnRevert usage in the codebase:"
rg "NotAllowedToCallOnRevert" -g "*.sol"

# If not found, search for related require statements handling onRevert
if [ $? -ne 0 ]; then
    echo "NotAllowedToCallOnRevert not found. Searching for related require statements:"
    rg "require\(.*onRevert.*\)" -g "*.sol"
fi

Length of output: 441

v2/test/ZetaConnectorNonNative.t.sol (2)

Line range hint 1-424: Overall assessment: Change aligns with PR objectives

The modification to add the 'sender' field to the RevertContext in the setUp() function aligns well with the PR objective of enhancing revert handling. The change is minimal and focused, which is a positive aspect of this update.

However, to ensure the robustness of this change:

  1. Verify that all existing tests still pass with this modification.
  2. Consider adding or updating tests that specifically validate the new 'sender' field in RevertContext, particularly in the testWithdrawAndRevert function.
  3. Ensure that this change is consistently applied across all relevant test files if there are multiple test files for related components.

79-79: LGTM: RevertContext updated with sender information

The addition of the 'sender' field to the RevertContext is consistent with the PR objectives and enhances the context provided during revert scenarios. This change appropriately sets the sender to the 'owner' address in the test setup.

To ensure this change doesn't inadvertently affect existing tests, please run the following verification:

This script will run the tests, check for any failures, and highlight any changes in RevertContext usage, which might indicate unintended side effects of this change.

v2/contracts/zevm/GatewayZEVM.sol (3)

6-6: LGTM: Import statement updated to include Revertable interface

This change aligns with the PR objective of improving revert handling by introducing the Revertable interface. It's a good practice to import only the necessary components.


477-477: LGTM: Updated executeRevert to use Revertable interface

This change is consistent with the PR objective of removing revert functionality from the UniversalContract interface. Using the Revertable interface improves the separation of concerns and makes the contract more modular.


500-500: LGTM: Updated depositAndRevert to use Revertable interface

This change is consistent with the executeRevert function modification and aligns with the PR objectives. It maintains consistency across the contract in handling revert operations using the Revertable interface.

v2/test/ERC20Custody.t.sol (1)

80-80: LGTM. Consider verifying the impact of this change.

The addition of the sender field to the RevertContext structure is a good improvement, providing more context during revert scenarios. This change aligns with the PR objectives.

To ensure this change doesn't introduce any issues, please run the following script to check for any other usages of RevertContext that might need updating:

v2/test/GatewayZEVM.t.sol (1)

560-560: LGTM. Verify impact on related tests.

The addition of the sender field to the revertContext initialization is consistent with the reported changes. This update enhances the context available during revert scenarios, which is a positive improvement.

To ensure this change doesn't negatively impact existing tests, please run the following script:

v2/contracts/evm/GatewayEVM.sol (1)

409-409: Ensure security checks are effective in _executeArbitraryCall

The addition of revertIfOnCallOrOnRevert(data); strengthens security by preventing unauthorized calls to onCall and onRevert. Confirm that this function adequately protects against malicious attempts to invoke restricted functions through arbitrary calls.

To validate the effectiveness of the security check, run the following script to search for all invocations of _executeArbitraryCall and ensure that the parameters and contexts are appropriate:

✅ Verification successful

Security checks in _executeArbitraryCall are properly implemented.

  • Verified that revertIfOnCallOrOnRevert(data); is invoked within _executeArbitraryCall.
  • No unauthorized calls detected in usage contexts.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `_executeArbitraryCall` across the codebase.

# Test: Search for all calls to `_executeArbitraryCall`. Expect: Proper usage with necessary security checks.
rg --type solidity --word-regexp '_executeArbitraryCall'

Length of output: 89


Script:

#!/bin/bash
# Description: Verify the usage of `_executeArbitraryCall` across Solidity files in the codebase.

rg --word-regexp '_executeArbitraryCall' --glob '*.sol'

Length of output: 718


Script:

#!/bin/bash
# Description: Retrieve context around each `_executeArbitraryCall` invocation in GatewayEVM.sol to verify security checks.

rg '_executeArbitraryCall' v2/contracts/evm/GatewayEVM.sol -C 3

Length of output: 1036

v2/test/GatewayEVM.t.sol (2)

79-79: Initialization of revertContext with new sender field

The revertContext is now initialized with the new sender field set to owner. This change aligns with the updated RevertContext structure, providing additional context during revert scenarios.


215-221: Addition of test testForwardCallToReceiveOnRevertFails

The new test function correctly verifies that unauthorized calls to onRevert revert with NotAllowedToCallOnRevert.selector, ensuring that the onRevert function cannot be called arbitrarily. This is consistent with the PR objective to enhance revert handling and security.

v2/test/ZetaConnectorNative.t.sol Show resolved Hide resolved
@@ -474,7 +474,7 @@ contract GatewayZEVM is
function executeRevert(address target, RevertContext calldata revertContext) external onlyProtocol whenNotPaused {
if (target == address(0)) revert ZeroAddress();

UniversalContract(target).onRevert(revertContext);
Revertable(target).onRevert(revertContext);
Copy link

Choose a reason for hiding this comment

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

Using onRevert() in the GatewayEVm seems to be missing here, but looking at the state of the main branch it seems to have been merged in another PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants