-
Notifications
You must be signed in to change notification settings - Fork 107
chore(l1): add default gas limit to eth_call
RPC method
#4755
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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) andMAX_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); |
There was a problem hiding this comment.
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.
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), |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this 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
7178c95
to
3d504d9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
08bb041
to
21fd4aa
Compare
There was a problem hiding this 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| { |
There was a problem hiding this comment.
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
The
eth_call
RPC method lacked a server-side gas limit. This change ensures resource safety and aligns with Ethereum client standards.Description
DEFAULT_ETH_CALL_GAS_LIMIT
andMAX_ETH_CALL_GAS_LIMIT
CallRequest::handle
to apply the default gas limit if none is specified, and cap custom gas limits.Closes #4366