Skip to content

Conversation

Peponks9
Copy link
Contributor

@Peponks9 Peponks9 commented Oct 3, 2025

The eth_call RPC method lacked a server-side gas limit. This change ensures resource safety and aligns with Ethereum client standards.

Description

  • Added constants DEFAULT_ETH_CALL_GAS_LIMIT and MAX_ETH_CALL_GAS_LIMIT
  • Modified CallRequest::handle to apply the default gas limit if none is specified, and cap custom gas limits.

Closes #4366

@Copilot Copilot AI review requested due to automatic review settings October 3, 2025 04:18
@Peponks9 Peponks9 requested a review from a team as a code owner October 3, 2025 04:18
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds default and maximum gas limits to the eth_call RPC method to improve resource safety and align with Ethereum client standards.

  • Introduced DEFAULT_ETH_CALL_GAS_LIMIT (50M) and MAX_ETH_CALL_GAS_LIMIT (100M) constants
  • Modified CallRequest::handle to apply default gas limit when none is specified and cap custom gas limits
  • Enhanced transaction preparation to ensure proper gas limit enforcement before simulation

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

let mut transaction = self.transaction.clone();
let gas_limit = match transaction.gas {
Some(gas) => {
let gas_u64 = u64::try_from(gas).unwrap_or(u64::MAX);
Copy link
Preview

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

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

Using unwrap_or(u64::MAX) could result in unexpected behavior when the gas value exceeds u64 range. The fallback to u64::MAX bypasses the intended capping logic since std::cmp::min(u64::MAX, MAX_ETH_CALL_GAS_LIMIT) would always return MAX_ETH_CALL_GAS_LIMIT. Consider using unwrap_or(MAX_ETH_CALL_GAS_LIMIT) instead to maintain consistent capping behavior.

Suggested change
let gas_u64 = u64::try_from(gas).unwrap_or(u64::MAX);
let gas_u64 = u64::try_from(gas).unwrap_or(MAX_ETH_CALL_GAS_LIMIT);

Copilot uses AI. Check for mistakes.

// Prepare transaction with gas limit
let mut transaction = self.transaction.clone();
let gas_limit = match transaction.gas {
Some(gas) => u64::try_from(gas).unwrap_or(u64::MAX),
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use DEFAULT_ETH_CALL_GAS_LIMIT as the default value for the unwrap?
You could simplify the match with just the unwrap_or

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Totally agree, changing right away

Copy link
Contributor

@tomip01 tomip01 left a comment

Choose a reason for hiding this comment

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

Looks good! Left a comment.
@Peponks9

@Peponks9 Peponks9 force-pushed the fix-eth-call-gas-limit branch from 7178c95 to 3d504d9 Compare October 4, 2025 22:08
Copy link
Contributor

@tomip01 tomip01 left a comment

Choose a reason for hiding this comment

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

Looks good! Just failing the Lint job. Check out this
cc @Peponks9

@Peponks9 Peponks9 force-pushed the fix-eth-call-gas-limit branch from 08bb041 to 21fd4aa Compare October 6, 2025 15:07
Copy link
Contributor Author

@Peponks9 Peponks9 left a comment

Choose a reason for hiding this comment

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

fixes done, thank you @tomip01

// Prepare transaction with gas limit
let mut transaction = self.transaction.clone();
#[allow(clippy::useless_conversion)]
let gas_limit = transaction.gas.map_or(DEFAULT_ETH_CALL_GAS_LIMIT, |gas| {
Copy link
Collaborator

Choose a reason for hiding this comment

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

let gas_limit = transaction
.gas
.and_then(|gas| u64::try_from(gas).ok())
.unwrap_or(DEFAULT_ETH_CALL_GAS_LIMIT);

is simpler

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 a gas limit to eth_call
3 participants