Skip to content

refactor: extend min gas limit check (develop)#3848

Merged
lumtis merged 4 commits intodevelopfrom
refactor/gas-limit-min-develop
May 7, 2025
Merged

refactor: extend min gas limit check (develop)#3848
lumtis merged 4 commits intodevelopfrom
refactor/gas-limit-min-develop

Conversation

@lumtis
Copy link
Contributor

@lumtis lumtis commented May 6, 2025

Description

Integrate #3846

Summary by CodeRabbit

  • Refactor
    • Improved gas limit checks for contract calls to prevent issues with low gas limits during transaction broadcasting.
  • Tests
    • Expanded test coverage to verify gas limit adjustments for various transaction scenarios.

@lumtis lumtis requested a review from a team as a code owner May 6, 2025 08:45
@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 6, 2025

📝 Walkthrough

Walkthrough

The changes introduce a stricter minimum gas limit enforcement for contract calls in the EVM signer logic. The adjustment replaces a previous special-case check for a 21,000 gas limit with a more general rule, ensuring contract-related transactions have at least 100,000 gas. Corresponding tests were expanded to cover these new scenarios, and the changelog was updated accordingly.

Changes

File(s) Change Summary
changelog.md Added an entry under "Refactor" for the unreleased section, referencing PR #3848, documenting the extension of the minimum gas limit check to prevent intrinsic low gas limit issues.
zetaclient/chains/evm/signer/gas.go Removed the gasTransferGasLimit constant (21,000), introduced contractCallMinGasLimit (100,000). Refactored the gas limit adjustment logic in gasFromCCTX to enforce the new minimum for contract calls and certain revert scenarios, replacing the previous check for exactly 21,000 gas. Updated comments to clarify the rationale for the minimum gas limit enforcement.
zetaclient/chains/evm/signer/gas_test.go Expanded the TestGasFromCCTX test with new helper functions and test cases to validate the updated gas limit logic for various transaction types and call contexts. Ensured the minimum gas limit is enforced only in appropriate scenarios and verified correct gas struct outputs. Updated imports to support new tests.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant GasSigner
    participant CCTX

    Client->>GasSigner: Request gas calculation (gasFromCCTX)
    GasSigner->>CCTX: Inspect transaction type and call context
    alt Coin is not native gas OR isWithdrawWithNoCall OR isRevertWithNoCall
        alt Gas limit < contractCallMinGasLimit
            GasSigner->>GasSigner: Set gas limit = contractCallMinGasLimit
        else Gas limit >= contractCallMinGasLimit
            GasSigner->>GasSigner: Use provided gas limit
        end
    else
        GasSigner->>GasSigner: Use provided gas limit
    end
    GasSigner-->>Client: Return Gas struct with enforced minimum if applicable
Loading
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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
Copy link

codecov bot commented May 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 64.44%. Comparing base (4772c64) to head (bd6be24).
Report is 2 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3848      +/-   ##
===========================================
+ Coverage    64.40%   64.44%   +0.03%     
===========================================
  Files          465      465              
  Lines        33716    33719       +3     
===========================================
+ Hits         21714    21729      +15     
+ Misses       10993    10982      -11     
+ Partials      1009     1008       -1     
Files with missing lines Coverage Δ
zetaclient/chains/evm/signer/gas.go 87.65% <100.00%> (+15.85%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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 (2)
zetaclient/chains/evm/signer/gas.go (1)

83-89: Logic extended to handle more cases appropriately.

The enhanced condition properly handles different scenarios (coin type, cross-chain calls, and revert calls) to determine when to apply the minimum gas limit.

However, there appears to be a minor typo in the comment at line 87:

-		// TODO: gas limit that is too low should now block outbound at all
+		// TODO: gas limit that is too low should not block outbound at all
changelog.md (1)

32-32: Appropriate changelog entry with typo in PR reference.

The changelog entry accurately describes the purpose of the change, but contains a typo in the PR reference.

-* [3848g](https://github.com/zeta-chain/node/pull/3848) - extend min gas limit check to prevent intrinsic low gas limit
+* [3848](https://github.com/zeta-chain/node/pull/3848) - extend min gas limit check to prevent intrinsic low gas limit
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4772c64 and bd6be24.

📒 Files selected for processing (3)
  • changelog.md (1 hunks)
  • zetaclient/chains/evm/signer/gas.go (2 hunks)
  • zetaclient/chains/evm/signer/gas_test.go (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.go`: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

**/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

  • zetaclient/chains/evm/signer/gas.go
  • zetaclient/chains/evm/signer/gas_test.go
🧬 Code Graph Analysis (2)
zetaclient/chains/evm/signer/gas.go (3)
testutil/sample/crosschain.go (1)
  • InboundParams (176-191)
e2e/contracts/gatewayzevmcaller/GatewayZEVMCaller.go (1)
  • CallOptions (33-36)
pkg/contracts/sui/coin.go (1)
  • CoinType (4-4)
zetaclient/chains/evm/signer/gas_test.go (2)
testutil/sample/crosschain.go (3)
  • CrossChainTx (266-280)
  • InboundParams (176-191)
  • OutboundParams (209-227)
zetaclient/chains/evm/signer/gas.go (1)
  • Gas (28-37)
🔇 Additional comments (8)
zetaclient/chains/evm/signer/gas.go (2)

17-18: Clear and descriptive constant for contract calls.

The introduction of contractCallMinGasLimit with a value of 100,000 serves as an appropriate threshold to prevent intrinsic gas limit errors in contract interactions.


74-75: Good flag implementation for conditional logic.

These boolean flags improve readability by clearly defining the conditions that determine when the minimum gas limit should be applied.

zetaclient/chains/evm/signer/gas_test.go (6)

26-75: Well-structured helper functions for comprehensive test coverage.

These helper functions provide a clean way to generate different test scenarios for the various conditions in the gas limit adjustment logic.


83-94: Thorough test for ERC20 withdrawal gas limit adjustment.

This test case correctly verifies that the gas limit is raised to the minimum threshold for ERC20 withdrawals when it falls below the required minimum.


95-106: Proper verification for gas withdrawals exemption.

This test confirms that gas withdrawals (without cross-chain calls) correctly bypass the minimum gas limit requirement, allowing the transaction to proceed with its original limit.


107-118: Important coverage for gas withdrawals with cross-chain calls.

This test validates that gas withdrawals with cross-chain calls have their gas limit properly adjusted to the minimum when necessary.


119-130: Appropriate exemption test for reverted gas withdrawals.

The test confirms that simple gas withdrawal reverts (without call-on-revert) maintain their original gas limit.


131-142: Comprehensive test for reverted gas withdrawals with call-on-revert.

This test ensures that gas withdrawals that are reverted with call-on-revert have their gas limit raised to the minimum threshold.

@lumtis lumtis added this pull request to the merge queue May 7, 2025
Merged via the queue into develop with commit a8da267 May 7, 2025
49 checks passed
@lumtis lumtis deleted the refactor/gas-limit-min-develop branch May 7, 2025 11:36
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.

3 participants