Skip to content

fix(zetaclient): evm chains: use gasLimit from CCTX#3680

Merged
skosito merged 4 commits intodevelopfrom
remove-min-gas-limit-check
Mar 10, 2025
Merged

fix(zetaclient): evm chains: use gasLimit from CCTX#3680
skosito merged 4 commits intodevelopfrom
remove-min-gas-limit-check

Conversation

@skosito
Copy link
Member

@skosito skosito commented Mar 10, 2025

Description

Hardcoding evm gas limit for simple transfers doesn't work anymore due to variable arbitrum behavior.
So we can increase gas limit in arbitrum gas zrc20, and use that instead. We don't need minimum gas limit check anymore, we can just use gas limit provided in callOptions.gasLimit.

For erc20s zrc20s it is 100k already and for gas tokens 21k, with exception of arbitrum where we will bump to 100k on smart contract level.

For contracts it would be caller responsibility to put adequate value.

How Has This Been Tested?

  • Tested CCTX in localnet
  • Tested in development environment
  • Go unit tests
  • Go integration tests
  • Tested via GitHub Actions

Summary by CodeRabbit

  • Refactor

    • Improved the management of transaction gas limits by removing static defaults and streamlining validation to focus on capping excessive values.
  • Bug Fixes

    • Updated warning messages to accurately indicate when the gas limit exceeds acceptable thresholds.
  • Tests

    • Revised test cases to align with the new dynamic gas limit determination.

@skosito skosito added the no-changelog Skip changelog CI check label Mar 10, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 10, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

The changes remove predefined gas limit constants and simplify gas limit validation logic across the EVM chain code. The constant EthTransferGasLimit has been removed from the common constants and its usage eliminated in transaction signing. Similarly, the constant minGasLimit has been removed from the gas handling function, which now only enforces a maximum gas limit. Accordingly, test cases have been updated by removing low gas limit scenarios and by standardizing the gas limit value against a dynamic parameter in outbound transactions.

Changes

File(s) Change Summary
zetaclient/chains/evm/common/constant.go
zetaclient/chains/evm/signer/sign.go
Removed the EthTransferGasLimit constant and its explicit assignment in transaction signing functions.
zetaclient/chains/evm/signer/gas.go Removed the minGasLimit constant and streamlined the gasFromCCTX function to only check if the gas limit exceeds maxGasLimit.
zetaclient/chains/evm/signer/gas_test.go Deleted test cases for low gas limits and updated remaining tests to use a fixed gas limit of 21,000.
zetaclient/chains/evm/signer/outbound_data_test.go Modified the gas limit assertion to compare against the dynamic gas limit from the current outbound parameters rather than a static value.

Sequence Diagram(s)

sequenceDiagram
    participant TX as "Transaction Request"
    participant GasHandler as "gasFromCCTX Function"
    participant Signer as "Transaction Signer"

    TX->>GasHandler: Provide gas limit from context
    alt Gas limit exceeds maxGasLimit
       GasHandler->>TX: Return adjusted gas limit (maxGasLimit)
    else 
       GasHandler->>TX: Return provided gas limit
    end
    TX->>Signer: Sign transaction with finalized gas limit
Loading

Possibly related PRs

Suggested labels

bug, UPGRADE_TESTS

Suggested reviewers

  • kingpinXD
  • fbac
  • ws4charlie
  • lumtis

🪧 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.
  • @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

@swift1337 swift1337 left a comment

Choose a reason for hiding this comment

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

LGTM

@swift1337 swift1337 changed the title fix: remove min gas limit check fix(zetaclient): evm chains: use gasLimit from CCTX Mar 10, 2025
@skosito skosito marked this pull request as ready for review March 10, 2025 14:24
@skosito skosito requested a review from a team as a code owner March 10, 2025 14:24
@codecov
Copy link

codecov bot commented Mar 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 64.58%. Comparing base (b12179b) to head (2edc22c).
Report is 1 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3680      +/-   ##
===========================================
- Coverage    64.59%   64.58%   -0.01%     
===========================================
  Files          470      470              
  Lines        32935    32927       -8     
===========================================
- Hits         21275    21267       -8     
  Misses       10692    10692              
  Partials       968      968              
Files with missing lines Coverage Δ
zetaclient/chains/evm/signer/gas.go 85.07% <100.00%> (-1.23%) ⬇️
zetaclient/chains/evm/signer/sign.go 62.58% <ø> (-0.48%) ⬇️
🚀 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 (1)
zetaclient/chains/evm/signer/gas.go (1)

69-75: Gas limit validation simplified to only check upper bound.

The validation logic has been streamlined to only enforce a maximum gas limit, removing the previous minimum gas limit check. This change effectively addresses the PR objective of using the gas limit from CCTX instead of hardcoded values, particularly for Arbitrum's variable behavior.

Consider adding a comment explaining the design decision to not enforce a minimum gas limit, making it explicit that the caller is responsible for providing an adequate value, as mentioned in the PR objectives:

 	if limit > maxGasLimit {
 		limit = maxGasLimit
 		logger.Warn().
 			Uint64("cctx.initial_gas_limit", params.CallOptions.GasLimit).
 			Uint64("cctx.gas_limit", limit).
 			Msgf("Gas limit is too high; Setting to the maximum (%d)", maxGasLimit)
 	}
+	// No minimum gas limit is enforced - the caller is responsible for providing an adequate gas value
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b12179b and 852a7c6.

📒 Files selected for processing (5)
  • zetaclient/chains/evm/common/constant.go (0 hunks)
  • zetaclient/chains/evm/signer/gas.go (2 hunks)
  • zetaclient/chains/evm/signer/gas_test.go (1 hunks)
  • zetaclient/chains/evm/signer/outbound_data_test.go (1 hunks)
  • zetaclient/chains/evm/signer/sign.go (0 hunks)
💤 Files with no reviewable changes (2)
  • zetaclient/chains/evm/common/constant.go
  • zetaclient/chains/evm/signer/sign.go
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.go`: Review the Go code, point out issues relative to ...

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

  • zetaclient/chains/evm/signer/outbound_data_test.go
  • zetaclient/chains/evm/signer/gas.go
  • zetaclient/chains/evm/signer/gas_test.go
🔇 Additional comments (5)
zetaclient/chains/evm/signer/gas.go (1)

13-13: Renamed constant clarifies system constraints.

With the removal of minGasLimit, the codebase now only enforces a maximum gas limit, aligning with the approach to use gas limits from the CCTX directly.

zetaclient/chains/evm/signer/outbound_data_test.go (1)

50-50: Test assertion updated to use dynamic gas limit.

The test now correctly verifies that the gas limit in the outbound data matches the one from the CCTX parameters, reflecting the shift from hardcoded minimum values to dynamic limits from the transaction context.

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

32-33: Test case updated with standardized gas limit value.

The pre-London gas test now uses a standardized gas limit of 21,000 rather than a value related to the removed minimum gas limit constant. This change properly reflects the new approach of using the gas limit directly from the CCTX.


44-45: Post-London gas test updated with standardized gas limit.

Similar to the pre-London gas test, this test case has been updated to use the standardized gas limit of 21,000, aligning with the new gas limit handling approach.


24-93:

Details

✅ Verification successful

Test cases simplified by removing minimum gas limit checks.

The test suite has been appropriately updated by removing the test cases that verified behavior related to gas limits being too low, as this validation is no longer performed in the code. The remaining test cases sufficiently cover the current functionality.

This change aligns with the PR objective of relying on the gas limit specified in the CCTX rather than enforcing minimum values, particularly for Arbitrum's variable behavior.


🏁 Script executed:

#!/bin/bash
# Check if there are any remaining references to minimum gas limits across the codebase that might need to be updated

echo "Searching for any remaining references to minimum gas limits..."
rg -i "min.*gas.*limit" --type go

echo "Checking for any hardcoded gas limit values in EVM chain code..."
rg -A 2 -B 2 "(21000|21_000|100000|100_000)" --type go zetaclient/chains/evm/

Length of output: 2566


Approved: Removal of Minimum Gas Limit Checks Confirmed

The gas test suite changes align with the PR objective. Our verification shows that the test file in zetaclient/chains/evm/signer/gas_test.go now focuses solely on the intended behaviors (legacy vs. post-London logic, ceiling enforcement on high gas limits, and proper error handling) without any checks enforcing a minimum gas limit. References to minimum gas limits in other parts of the repository are unrelated to this test and were not intended to be covered by these changes.

  • The removed test cases for gas limits being too low are correct since that validation has been moved.
  • The remaining tests verify that the gas limit specified in the CCTX is correctly used, particularly for Arbitrum’s variable behavior.

Copy link
Contributor

@ws4charlie ws4charlie left a comment

Choose a reason for hiding this comment

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

lgtm. Minor comment

@skosito skosito added this pull request to the merge queue Mar 10, 2025
Merged via the queue into develop with commit e8cd199 Mar 10, 2025
45 checks passed
@skosito skosito deleted the remove-min-gas-limit-check branch March 10, 2025 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chain:evm no-changelog Skip changelog CI check

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants