From 8e1945592b607de19ec79b3e7d1fc1bfab4e614b Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Thu, 28 Nov 2024 17:34:41 +0100 Subject: [PATCH] fix: cap request gas limit in eth estimate (#12970) --- crates/rpc/rpc-eth-api/src/helpers/estimate.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/rpc/rpc-eth-api/src/helpers/estimate.rs b/crates/rpc/rpc-eth-api/src/helpers/estimate.rs index 465c33ada3..f9d62855be 100644 --- a/crates/rpc/rpc-eth-api/src/helpers/estimate.rs +++ b/crates/rpc/rpc-eth-api/src/helpers/estimate.rs @@ -57,7 +57,7 @@ pub trait EstimateCall: Call { request.nonce = None; // Keep a copy of gas related request values - let tx_request_gas_limit = request.gas; + let tx_request_gas_limit = request.gas.map(U256::from); let tx_request_gas_price = request.gas_price; // the gas limit of the corresponding block let block_env_gas_limit = block.gas_limit; @@ -65,7 +65,13 @@ pub trait EstimateCall: Call { // Determine the highest possible gas limit, considering both the request's specified limit // and the block's limit. let mut highest_gas_limit = tx_request_gas_limit - .map(|tx_gas_limit| U256::from(tx_gas_limit).max(block_env_gas_limit)) + .map(|mut tx_gas_limit| { + if block_env_gas_limit < tx_gas_limit { + // requested gas limit is higher than the allowed gas limit, capping + tx_gas_limit = block_env_gas_limit; + } + tx_gas_limit + }) .unwrap_or(block_env_gas_limit); // Configure the evm env