From f858695076fd2606418c040cd6126444a525fb56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20Stu=CC=88ber?= <15174476+TorstenStueber@users.noreply.github.com> Date: Thu, 4 Dec 2025 07:16:46 -0300 Subject: [PATCH 1/2] Tighten length estimation during dry running --- substrate/frame/revive/src/evm/call.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/substrate/frame/revive/src/evm/call.rs b/substrate/frame/revive/src/evm/call.rs index 28c0df6e1f99d..6bdb294b579b1 100644 --- a/substrate/frame/revive/src/evm/call.rs +++ b/substrate/frame/revive/src/evm/call.rs @@ -104,9 +104,10 @@ impl GenericTransaction { // For dry runs, we need to ensure that the RLP encoding length is at least the // length of the encoding of the actual transaction submitted later let mut maximized_tx = self.clone(); - maximized_tx.gas = Some(U256::MAX); - maximized_tx.gas_price = Some(U256::MAX); - maximized_tx.max_priority_fee_per_gas = Some(U256::MAX); + let maximized_base_fee = base_fee.saturating_mul(256.into()); + maximized_tx.gas = Some(u64::MAX.into()); + maximized_tx.gas_price = Some(maximized_base_fee); + maximized_tx.max_priority_fee_per_gas = Some(maximized_base_fee); let unsigned_tx = maximized_tx.try_into_unsigned().map_err(|_| { log::debug!(target: LOG_TARGET, "Invalid transaction type."); From d346869247bb2438c492fb9b9da000cf1cc2c02d Mon Sep 17 00:00:00 2001 From: "cmd[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 4 Dec 2025 10:33:49 +0000 Subject: [PATCH 2/2] Update from github-actions[bot] running command 'prdoc --audience runtime_dev --bump patch' --- prdoc/pr_10540.prdoc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 prdoc/pr_10540.prdoc diff --git a/prdoc/pr_10540.prdoc b/prdoc/pr_10540.prdoc new file mode 100644 index 0000000000000..ab98da990611c --- /dev/null +++ b/prdoc/pr_10540.prdoc @@ -0,0 +1,20 @@ +title: Tighten length estimation during dry running +doc: +- audience: Runtime Dev + description: |- + The length of the RLP-encoded Ethereum transaction will have an effect on the transaction cost (as pallet-transaction-payment charges a length fee) and therefore the required Ethereum gas. + + During dry running we need to estimate the length of the actual RLP-encoded Ethereum transaction that will submitted later. Some of the parameters that determine the length will usually not be provided at the dry running stage yet: `gas`, `gas_price` and `max_priority_fee_per_gas`. + + If we underestimate the actual lengths of these parameters, then the gas estimate might be too low and transaction execution will run out of gas. If we over estimate, then the pre-dispatch weight will be unreasonably large and we risk that a transaction that might still fit into a block, won't be put into the block anymore, which leads to lower block utilization. + + ## Current Approach + The current approach is to just assume that maximal possible length for these fields, which results when they have the maximum possible value, `U256::MAX`, due to how RLP encoding works. This is a gross over estimation. + + ## New Approach + In practice there won't be gas requirements and gas estimates that are more than `u64::MAX` and therefore we assume this as the maximal value for `gas`. + + For `gas_price` and `max_priority_fee_per_gas` we assume that the caller will use the current base fee and will scale it be some small amount so that the RLP encoding is at most one byte longer than the RLP encoding of the base fee. We achieve that by determining the RLP encoding of the base fee multiplied by 256. +crates: +- name: pallet-revive + bump: patch