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: add onAbort interface #450

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

feat: add onAbort interface #450

wants to merge 1 commit into from

Conversation

lumtis
Copy link
Member

@lumtis lumtis commented Jan 15, 2025

Closes: #429

AbortContext structure is to be discussed, we need context that can address all edge cases

Summary by CodeRabbit

  • New Features
    • Introduced enhanced transaction abort handling mechanism
    • Added support for detailed transaction context tracking during cross-chain operations
    • Implemented a flexible interface for managing transaction abort scenarios

@lumtis lumtis requested review from a team as code owners January 15, 2025 14:18
Copy link
Contributor

coderabbitai bot commented Jan 15, 2025

📝 Walkthrough

Walkthrough

The pull request introduces new structures and an interface in the contracts/Revert.sol file to enhance the handling of aborted transactions. The AbortContext struct provides comprehensive details about an aborted transaction, including sender address, asset address, transaction amount, transaction direction, chain ID, and a revert message. The Abortable interface defines an onAbort method that allows contracts to implement custom logic when a transaction is aborted.

Changes

File Change Summary
contracts/Revert.sol - Added AbortContext struct with detailed transaction abort information
- Added Abortable interface with onAbort(AbortContext calldata abortContext) method

Assessment against linked issues

Objective Addressed Explanation
Add interface for onAbort function [#429]
Include transaction details in abort context [#429]

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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

🧹 Nitpick comments (3)
contracts/Revert.sol (3)

32-50: LGTM! Documentation is comprehensive and clear.

The NatSpec comments effectively explain the purpose of each field, particularly the rationale for using bytes type for the sender field to support non-EVM chains.

Consider optimizing struct field ordering for gas efficiency.

The struct fields can be reordered to optimize gas costs by grouping similar-sized fields together:

struct AbortContext {
-    bytes sender;
-    address asset;
-    uint256 amount;
-    bool outgoing;
-    uint256 chainID;
-    bytes revertMessage;
+    uint256 amount;
+    uint256 chainID;
+    address asset;
+    bool outgoing;
+    bytes sender;
+    bytes revertMessage;
}

60-66: Enhance interface documentation with implementation guidance.

While the interface is well-structured, the documentation should be expanded to include:

  • Implementation requirements and constraints
  • Expected behavior on abort
  • Error handling expectations
  • Gas considerations

Example documentation improvement:

 /// @title Abortable
 /// @notice Interface for contracts that support abortable calls.
+/// @dev Implementers must:
+/// - Handle all fields in AbortContext appropriately
+/// - Never revert in onAbort implementation
+/// - Be mindful of gas consumption as this may be called in cross-chain context
+/// - Emit events for important state changes
 interface Abortable {
     /// @notice Called when a revertable call is aborted.
     /// @param abortContext Abort context to pass to onAbort.
+    /// @dev This function:
+    /// - Must not revert
+    /// - Should handle both EVM and non-EVM chain senders
+    /// - Should validate chainID against supported chains
     function onAbort(AbortContext calldata abortContext) external;
 }
🧰 Tools
🪛 GitHub Actions: Lint TS/JS/Sol

[error] 66-66: Code formatting issue detected. Line ending style mismatch in file.


66-66: Fix line ending style to match repository standards.

The pipeline failure indicates a line ending style mismatch. Ensure consistent line endings throughout the file.

🧰 Tools
🪛 GitHub Actions: Lint TS/JS/Sol

[error] 66-66: Code formatting issue detected. Line ending style mismatch in file.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7232d78 and 51557b5.

📒 Files selected for processing (1)
  • contracts/Revert.sol (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
contracts/Revert.sol (1)

Pattern contracts/**: Review the Solidity contracts for security vulnerabilities and best practices.

🪛 GitHub Actions: Lint TS/JS/Sol
contracts/Revert.sol

[error] 66-66: Code formatting issue detected. Line ending style mismatch in file.

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: slither
  • GitHub Check: test
  • GitHub Check: generate
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (1)
contracts/Revert.sol (1)

32-66: Verify integration with existing revert mechanism.

The new abort mechanism parallels the existing revert functionality. Ensure all implementers of Revertable are reviewed for potential Abortable implementation requirements.

✅ Verification successful

Existing implementations already handle revert scenarios securely

The verification shows that current implementers (GatewayEVM, GatewayZEVM, TestUniversalContract) already have robust revert handling with proper security checks. The parallel abort mechanism naturally fits into the existing pattern.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Find all contracts implementing Revertable interface
echo "Contracts implementing Revertable:"
ast-grep --pattern 'contract $_ is $$$, Revertable, $$$'

# These contracts might need to implement Abortable interface as well

Length of output: 137


Script:

#!/bin/bash
# Try different patterns to find Revertable implementations
echo "=== Searching for Revertable implementations with different patterns ==="
ast-grep --pattern 'contract $_ is Revertable'
ast-grep --pattern 'contract $_ is $_Revertable'

echo -e "\n=== Searching for onRevert function implementations ==="
ast-grep --pattern 'function onRevert(RevertContext $_) $_'

echo -e "\n=== Searching for Revertable interface usage ==="
rg "Revertable" -A 2

Length of output: 18990

🧰 Tools
🪛 GitHub Actions: Lint TS/JS/Sol

[error] 66-66: Code formatting issue detected. Line ending style mismatch in file.

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.07%. Comparing base (7232d78) to head (51557b5).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #450   +/-   ##
=======================================
  Coverage   87.07%   87.07%           
=======================================
  Files           9        9           
  Lines         526      526           
  Branches      128      128           
=======================================
  Hits          458      458           
  Misses         68       68           

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

/// token address or is empty if it's a gas token. On ZetaChain, it contains the
/// address of the ZRC20.
/// @param amount Amount specified with the transaction.
/// @param outgoing Flag to indicate if the crosschain transaction was outgoing: from ZetaChain to connected chain.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: would be wrong to use outbound here as well, or is confusing?

/// @param outgoing Flag to indicate if the crosschain transaction was outgoing: from ZetaChain to connected chain.
/// if false, the transaction was incoming: from connected chain to ZetaChain.
/// @param chainID Chain ID of the connected chain.
/// @param revertMessage Arbitrary data specified in the revert options
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add more details about revert options?

@fadeev
Copy link
Member

fadeev commented Jan 21, 2025

Should we also have chain ID in the revert context?

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.

Add interface for onAbort function on ZetaChain
4 participants