Skip to content

fix: hardcode gas limits to avoid estimate gas calls#3602

Merged
skosito merged 3 commits intodevelopfrom
fix-gas-limits
Feb 27, 2025
Merged

fix: hardcode gas limits to avoid estimate gas calls#3602
skosito merged 3 commits intodevelopfrom
fix-gas-limits

Conversation

@skosito
Copy link
Member

@skosito skosito commented Feb 27, 2025

Description

if gas limit is nil in CallEVM, it will be estimated, which takes a lot of cosmos gas

gas limits are hardcoded in following conservative way:

  • simple setter 100k
  • a bit more logic with setter 200k
  • improve read functions consistency

also, for some depositAndCall calls, 1M is not enough, so bumping gateway limit to 1.5M (check linked issues) and fixing gas consumer test to keep that limit in

closes: #3592, #3537

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

  • Documentation

    • Added a changelog entry noting the transition to fixed gas limits.
  • Chores

    • Updated gas limits and fee configurations for various blockchain transaction operations.
    • Adjusted parameters for contract gas consumption, deposit, gateway, swap, and approval functions to enhance transaction consistency and efficiency.

@skosito skosito added ADMIN_TESTS Run make start-admin-tests SOLANA_TESTS Run make start-solana-test PERFORMANCE_TESTS Run make start-e2e-performance-test labels Feb 27, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 27, 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

This pull request introduces hardcoded gas limits to replace dynamic gas estimation. A new changelog entry documents the change for pull request [3602]. Updates span multiple files, including modifications to the compiled contract binaries and adjustments in the TestGasConsumer contract, as well as changes in various keeper modules where gas limits, gas prices, and EVM call parameters are updated from dynamic values (or nil) to explicit big.Int constants. These updates uniformly enforce fixed gas parameters within contract interactions and EVM calls.

Changes

Files Change Summary
changelog.md Added a new entry for [3602] indicating that gas limits are now hardcoded to avoid estimate gas calls.
e2e/contracts/testgasconsumer/TestGasConsumer.go, e2e/contracts/testgasconsumer/TestGasConsumer.json Updated the Bin field with new hexadecimal strings in the deployed contract bytecode.
e2e/contracts/testgasconsumer/TestGasConsumer.sol Reduced targetGas in the consumeGas function from 5000000 to 1500000, affecting gas consumption during execution.
x/fungible/keeper/evm.go, evm_gateway.go, gas_coin_and_pool.go, gas_price.go, msg_server_update_system_contract.go, system_contract.go, zrc20_methods.go Adjusted gas limits, gas prices, and EVM call parameters by replacing nil with explicit big.Int values and updating numeric constants across various gas-related operations.

Possibly related PRs

Suggested labels

breaking:cli, no-changelog, V2_TESTS

Suggested reviewers

  • fbac
  • kingpinXD
  • lumtis
  • swift1337
  • brewmaster012

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

@skosito skosito linked an issue Feb 27, 2025 that may be closed by this pull request
@skosito skosito marked this pull request as ready for review February 27, 2025 02:05
@skosito skosito requested a review from a team as a code owner February 27, 2025 02:05
@codecov
Copy link

codecov bot commented Feb 27, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 64.69%. Comparing base (4e5c732) to head (8ebdd73).
Report is 2 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #3602   +/-   ##
========================================
  Coverage    64.69%   64.69%           
========================================
  Files          466      466           
  Lines        32477    32477           
========================================
  Hits         21010    21010           
  Misses       10512    10512           
  Partials       955      955           
Files with missing lines Coverage Δ
x/fungible/keeper/evm.go 85.14% <100.00%> (ø)
x/fungible/keeper/evm_gateway.go 19.76% <ø> (ø)
x/fungible/keeper/gas_coin_and_pool.go 90.41% <100.00%> (ø)
x/fungible/keeper/gas_price.go 82.35% <100.00%> (ø)
...ngible/keeper/msg_server_update_system_contract.go 90.90% <100.00%> (ø)
x/fungible/keeper/system_contract.go 87.37% <100.00%> (ø)
x/fungible/keeper/zrc20_methods.go 55.93% <100.00%> (ø)

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)
x/fungible/keeper/zrc20_methods.go (1)

160-160: Ensure consistency for read-only operation gas handling

These changes follow the same pattern: setting gas limit to nil and changing true to false for the commit parameter in read-only operations. While this differs from the PR's overall approach of hardcoding gas limits, it may be an optimization for view functions.

Consider adding a comment explaining this pattern difference, as it's not immediately obvious why read-only operations use a different approach than write operations.

Also applies to: 218-218, 274-274, 326-326

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4e5c732 and 63cf3a9.

⛔ Files ignored due to path filters (1)
  • e2e/contracts/testgasconsumer/TestGasConsumer.bin is excluded by !**/*.bin
📒 Files selected for processing (11)
  • changelog.md (1 hunks)
  • e2e/contracts/testgasconsumer/TestGasConsumer.go (1 hunks)
  • e2e/contracts/testgasconsumer/TestGasConsumer.json (1 hunks)
  • e2e/contracts/testgasconsumer/TestGasConsumer.sol (1 hunks)
  • x/fungible/keeper/evm.go (4 hunks)
  • x/fungible/keeper/evm_gateway.go (1 hunks)
  • x/fungible/keeper/gas_coin_and_pool.go (2 hunks)
  • x/fungible/keeper/gas_price.go (3 hunks)
  • x/fungible/keeper/msg_server_update_system_contract.go (3 hunks)
  • x/fungible/keeper/system_contract.go (2 hunks)
  • x/fungible/keeper/zrc20_methods.go (9 hunks)
✅ Files skipped from review due to trivial changes (1)
  • e2e/contracts/testgasconsumer/TestGasConsumer.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.

  • x/fungible/keeper/msg_server_update_system_contract.go
  • x/fungible/keeper/evm_gateway.go
  • x/fungible/keeper/gas_coin_and_pool.go
  • x/fungible/keeper/gas_price.go
  • x/fungible/keeper/zrc20_methods.go
  • x/fungible/keeper/evm.go
  • x/fungible/keeper/system_contract.go
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: start-e2e-performance-test / e2e
🔇 Additional comments (22)
x/fungible/keeper/evm_gateway.go (1)

19-19: Increased gateway gas limit to accommodate larger transactions.

The increase from 1,000,000 to 1,500,000 gas units addresses the issue where certain depositAndCall operations were failing due to insufficient gas limits. This conservative adjustment ensures proper execution of complex cross-chain transactions while avoiding dynamic gas estimation.

changelog.md (1)

38-38: Appropriate changelog entry for gas limit hardcoding.

The entry properly documents the change made in PR #3602, providing clear context about the nature of the fix (hardcoding gas limits to avoid estimate gas calls). This maintains good transparency about system modifications.

e2e/contracts/testgasconsumer/TestGasConsumer.json (1)

49-49: Updated binary to reflect the reduced gas consumption target.

The updated contract binary reflects the compilation of the modified Solidity source code where target gas consumption was reduced. This binary change is expected and necessary to maintain synchronization between source and compiled code.

e2e/contracts/testgasconsumer/TestGasConsumer.sol (1)

29-29: Reduced target gas consumption to align with system gas limits.

The target gas consumption has been reduced from 5,000,000 to 1,500,000, bringing it in line with the gateway gas limit set in the system. This adjustment provides a more realistic test scenario and better visibility into gas limit behavior at the node level.

x/fungible/keeper/gas_price.go (3)

37-37: Approve hardcoded gas limit for SetGasPrice

The change from a dynamic gas estimate to a fixed value aligns with the PR objective to avoid excessive gas consumption during estimation. The 100,000 gas limit for this setter function should be sufficient for the operation.


73-73: Approve hardcoded gas limit for SetGasCoin

Setting a fixed gas limit of 100,000 for this setter function is appropriate and maintains consistency with other similar operations in the codebase.


109-109: Approve increased gas limit for SetGasZetaPool

The higher gas limit of 200,000 for this function is appropriate as it likely involves more complex operations than simple setters. This aligns with the conservative approach mentioned in the PR objectives.

x/fungible/keeper/gas_coin_and_pool.go (2)

114-114: Approve hardcoded gas limit for setGasZetaPool

Setting a fixed gas limit of 200,000 for the setGasZetaPool operation aligns with the more complex setter pattern established in this PR. The comment on line 22 "FIXME: add cointype and use proper gas limit based on cointype/chain" remains relevant but isn't directly affected by this change.


149-149: Approve hardcoded gas limit for approve

The 200,000 gas limit for the approve operation is consistent with other complex operations in this PR and should be sufficient for token approval interactions.

x/fungible/keeper/msg_server_update_system_contract.go (3)

61-61: Approve hardcoded gas limit for updateSystemContractAddress

The 100,000 gas limit is appropriate for this system contract update function and aligns with the pattern of using 100,000 for simple setter operations.


81-81: Approve hardcoded gas limit for setGasCoinZRC20

Using a 100,000 gas limit for this setter function maintains consistency with other similar operations in the PR.


101-101: Approve hardcoded gas limit for setGasZetaPool

The 200,000 gas limit is consistent with other instances of setGasZetaPool in the codebase, maintaining a uniform approach to gas allocation for this operation.

x/fungible/keeper/zrc20_methods.go (4)

46-46: Approve gas limit reduction for ZRC20SetName

Reducing the gas limit to 100,000 for this setter function is reasonable and consistent with other setters in the codebase.


80-80: Approve gas limit reduction for ZRC20SetSymbol

The reduced gas limit of 100,000 for this setter function aligns with the pattern established in this PR.


382-382: Approve hardcoded gas limits for transfer operations

Setting a fixed gas limit of 200,000 for transfer operations is appropriate and consistent with the PR's approach for more complex operations. These transfer functions likely require more gas than simple setters but should be well within the 200,000 limit for typical cases.

Also applies to: 442-442


113-113:

Details

✅ Verification successful

Verify impact of changing gas limit to nil for read-only method

Changing from a hardcoded value to nil for this read-only method seems inconsistent with the PR's objective of avoiding estimate gas calls. This might be intentional for read-only operations, but warrants verification.


🏁 Script executed:

#!/bin/bash
# Check if there are other read-only methods in the codebase using nil gas limits
echo "Searching for patterns of nil gas limits in read-only methods..."
rg -B2 -A10 "CallEVM\(" --type go | grep -B5 -A5 "nil," | grep -A2 "function.*view" || echo "No direct matches found"

# Check if there are any comments or documentation explaining this pattern
echo "Searching for documentation about gas limit patterns..."
rg -A3 "gas limit" --type go | grep -i "read-only\|view\|query" || echo "No explicit documentation found"

Length of output: 2225


Subject: Nil Gas Limit for Read-Only Method Verified

After reviewing the codebase and running the verification scripts, there are no conflicting patterns or documentation that suggest using nil for the gas limit in read-only methods is problematic. In fact, the absence of a hardcoded gas limit aligns with the PR’s objective to avoid unnecessary gas estimation on view methods. Although similar patterns were not found elsewhere in read-only implementations, tests and other references confirm that explicit gas limit queries are generally reserved for transactional (non-read-only) operations.

Recommendations:

  • Maintain the use of nil for the read-only gas limit in this context.
  • Consider adding a concise code comment explaining that nil is used because no gas estimation is required for read-only operations, which will aid future maintainers.
x/fungible/keeper/system_contract.go (2)

377-377: Consistent numeric literal formatting.

The change from big.NewInt(1000_000) to big.NewInt(1_000_000) improves readability by using a consistent thousands separator format throughout the codebase.


800-800: Hardcoded gas limit replaces nil value.

This change aligns with the PR objective of hardcoding gas limits to avoid estimate gas calls. The value of 200,000 is appropriate for a ZRC20 approval operation, which is a moderately complex setter.

x/fungible/keeper/evm.go (4)

43-44: Increased gas limits for deposit and connector calls.

The gas limits for ZEVMGasLimitDepositAndCall and ZEVMGasLimitConnectorCall have been increased from 1,000,000 to 1,500,000. This addresses issue #3592 where certain depositAndCall operations were hitting the previous gas limit.


261-261: Hardcoded gas limit for ZRC20 deposit operations.

Replacing the nil gas limit with a hardcoded value of 200,000 is appropriate for deposit operations, which are more complex than simple setters but less complex than full deposit-and-call operations.


286-286: Hardcoded gas limit for protocol flat fee updates.

The gas limit of 100,000 is suitable for this simple setter operation, aligning with the PR objective of using conservative hardcoded gas limits.


310-310: Hardcoded gas limit for gas limit updates.

Similar to the protocol flat fee update, this simple setter operation receives a conservative hardcoded gas limit of 100,000, which is appropriate for its complexity level.

@skosito skosito added the CONSENSUS_BREAKING_ACK Acknowledge a consensus breaking change label Feb 27, 2025
Copy link
Contributor

@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, minor comments

@skosito skosito requested a review from lumtis February 27, 2025 14:56
@skosito skosito added this pull request to the merge queue Feb 27, 2025
Merged via the queue into develop with commit ed8faa6 Feb 27, 2025
45 checks passed
@skosito skosito deleted the fix-gas-limits branch February 27, 2025 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ADMIN_TESTS Run make start-admin-tests CONSENSUS_BREAKING_ACK Acknowledge a consensus breaking change PERFORMANCE_TESTS Run make start-e2e-performance-test SOLANA_TESTS Run make start-solana-test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cross-chain transaction failed due to 50K gas limit Cross-chain transaction failing due to gas

3 participants