Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
c49a1ee
Remove stale TODOs
athei Oct 10, 2025
2c69ffd
Rename gas metering to weight metering
TorstenStueber Oct 25, 2025
faa5866
Implement general resource metering
TorstenStueber Oct 30, 2025
43e1bd1
Resolve rebase conflicts
TorstenStueber Oct 30, 2025
ef060f5
Fix conflicts and existing tests
TorstenStueber Nov 1, 2025
6a8afd8
Use max storage deposit for dry runs
TorstenStueber Nov 3, 2025
a96a66f
Use SignedGas instead of StorageDeposit
TorstenStueber Nov 4, 2025
11b57ce
Add doc comments
TorstenStueber Nov 4, 2025
548a143
Use correct gas handling in tracer
TorstenStueber Nov 5, 2025
bdeddd5
Merge master
TorstenStueber Nov 5, 2025
947a492
Add tweaks for dry running
TorstenStueber Nov 5, 2025
7454d91
Merge latest changes from master
TorstenStueber Nov 10, 2025
66cfae5
Add call stipends for *CALL instructions
TorstenStueber Nov 13, 2025
d8b2d89
Merge latest changes from master
TorstenStueber Nov 13, 2025
3115020
Fix errors in other crates
TorstenStueber Nov 13, 2025
695357c
Fix errors in other crates (2)
TorstenStueber Nov 13, 2025
3ee4ed5
Fix errors in other crates (3)
TorstenStueber Nov 13, 2025
9117c8c
Fix errors in other crates (4)
TorstenStueber Nov 13, 2025
cd7cbf2
Fix calculation of max storage deposit
TorstenStueber Nov 14, 2025
2a308bc
Merge branch 'master' into torsten/gas-fixes
pgherveou Nov 17, 2025
e5a3668
Add tests
TorstenStueber Nov 18, 2025
a20f8ed
Fix weight tracing (issue 8362)
TorstenStueber Nov 18, 2025
3fff1a5
Fix max deposit calculation
TorstenStueber Nov 19, 2025
0d2b69f
Merge branch 'torsten/gas-fixes' of github.com:paritytech/polkadot-sd…
TorstenStueber Nov 19, 2025
1c928c9
Add test for max deposits
TorstenStueber Nov 19, 2025
e644aff
Merge branch 'master' into torsten/gas-fixes
TorstenStueber Nov 19, 2025
14947c1
Fix issue with dry running length encoding
TorstenStueber Nov 19, 2025
ed242f0
Merge branch 'master' into torsten/gas-fixes
TorstenStueber Nov 19, 2025
74135f8
Set max block gas to u64::MAX
TorstenStueber Nov 19, 2025
631f6d5
Lower the concurrency of the DT framework
0xOmarA Nov 20, 2025
c7eefbd
Update the concurrency value of the DT framework.
0xOmarA Nov 20, 2025
57b1c13
Merge branch 'master' into torsten/gas-fixes
pgherveou Nov 20, 2025
2f5077e
fix BENCH_INIT_CODE
pgherveou Nov 20, 2025
2f6624a
master merge fix
pgherveou Nov 20, 2025
37e46f9
Add tracing logs
TorstenStueber Nov 21, 2025
7fd98e6
Clean up create call arguments
TorstenStueber Nov 21, 2025
dd3ca1e
Merge branch 'torsten/gas-fixes' of github.com:paritytech/polkadot-sd…
TorstenStueber Nov 21, 2025
c604122
Add optimizations and correct numerical calculations
TorstenStueber Nov 21, 2025
4466f09
Merge branch 'master' into torsten/gas-fixes
TorstenStueber Nov 21, 2025
8bbb05a
Fix code in other crates
TorstenStueber Nov 21, 2025
8f07b75
Add configuration to set Ethereum gas scale
TorstenStueber Nov 22, 2025
5e98c43
Update from github-actions[bot] running command 'prdoc --audience run…
github-actions[bot] Nov 22, 2025
2b823cc
Add GasScale config to other chains
TorstenStueber Nov 22, 2025
b3c9192
Merge branch 'torsten/scale-eth-gas' of github.com:paritytech/polkado…
TorstenStueber Nov 22, 2025
15b8c76
Address clippy complaints
TorstenStueber Nov 22, 2025
cb29390
Increase endowments on dev-node
TorstenStueber Nov 23, 2025
aec7970
Increase the GasScale on the dev node
TorstenStueber Nov 23, 2025
bd87e40
Increase endowments on dev-node again
TorstenStueber Nov 23, 2025
e722626
Set standard differential test concurrency
TorstenStueber Nov 23, 2025
43f54eb
Improve code consistency
TorstenStueber Nov 23, 2025
338f0ee
Clean up code structure
TorstenStueber Nov 24, 2025
7268c14
Merge changes from torsten/gas-fixes
TorstenStueber Nov 24, 2025
e6fcef8
Fix doc comment
TorstenStueber Nov 24, 2025
21e7687
Merge branch 'torsten/gas-fixes' into torsten/scale-eth-gas
TorstenStueber Nov 24, 2025
4f1419a
Lower differential testing concurrency
TorstenStueber Nov 24, 2025
cc32190
Make tests less brittle
TorstenStueber Nov 24, 2025
539a9e9
Update from github-actions[bot] running command 'prdoc --audience run…
github-actions[bot] Nov 24, 2025
f3a9a3e
Update from github-actions[bot] running command 'prdoc --audience run…
github-actions[bot] Nov 24, 2025
8388ab1
Update commit of differential testing CI
TorstenStueber Nov 24, 2025
2a8a6c6
Merge branch 'torsten/scale-eth-gas' of github.com:paritytech/polkado…
TorstenStueber Nov 24, 2025
5a0919b
Update from github-actions[bot] running command 'bench --runtime dev …
github-actions[bot] Nov 24, 2025
0f55b11
Implement PR feedback
TorstenStueber Nov 25, 2025
8e609dc
Merge branch 'torsten/gas-fixes' of github.com:paritytech/polkadot-sd…
TorstenStueber Nov 25, 2025
cab85be
Merge master
TorstenStueber Nov 25, 2025
aacd84f
Merge branch 'torsten/gas-fixes' into torsten/scale-eth-gas
TorstenStueber Nov 25, 2025
116ba4f
Implement review feedback
TorstenStueber Nov 25, 2025
2dba778
Simplify return type of try_upload_code
TorstenStueber Nov 25, 2025
2c1acdf
Make some members crate public
TorstenStueber Nov 26, 2025
aa31d6e
simplify test
pgherveou Nov 26, 2025
7b3ae17
Merge changes from master (PR 10302, PR 10309)
TorstenStueber Nov 26, 2025
c8ced0e
Deprecate gas_meter API
TorstenStueber Nov 27, 2025
c40e273
Simplify deposit refund tests
TorstenStueber Nov 27, 2025
6d7c398
Merge remote-tracking branch 'origin/pg/gas-fix-comment' into torsten…
TorstenStueber Nov 27, 2025
7edd38f
Remove dead code
TorstenStueber Nov 27, 2025
6186657
Merge branch 'master' into torsten/gas-fixes
TorstenStueber Nov 27, 2025
cda93cc
Merge branch 'torsten/gas-fixes' into torsten/scale-eth-gas
TorstenStueber Nov 27, 2025
9a412ae
Format
TorstenStueber Nov 27, 2025
56c8a3c
Merge branch 'torsten/gas-fixes' into torsten/scale-eth-gas
TorstenStueber Nov 27, 2025
93bf186
Fix compiler errors
TorstenStueber Nov 27, 2025
7362fa1
Merge branch 'torsten/gas-fixes' into torsten/scale-eth-gas
TorstenStueber Nov 27, 2025
bc26308
Fix benchmark code
TorstenStueber Nov 27, 2025
aadd6fe
Merge branch 'torsten/gas-fixes' into torsten/scale-eth-gas
TorstenStueber Nov 27, 2025
6c80641
Add doc comment and integrity check
TorstenStueber Nov 27, 2025
ec0b8fb
Fix typo
TorstenStueber Nov 27, 2025
54a9c43
Fix cargo check error
TorstenStueber Nov 27, 2025
94f1a05
Increase gas scale further on dev node
TorstenStueber Nov 27, 2025
8a626e7
Merge branch 'master' into torsten/gas-fixes
TorstenStueber Dec 1, 2025
72fde93
Implement PR feedback
TorstenStueber Dec 1, 2025
ac9155b
Merge branch 'master' into torsten/gas-fixes
TorstenStueber Dec 1, 2025
63862fd
Merge torsten/gas-fixes
TorstenStueber Dec 1, 2025
2d7b95f
Raise endowment of dev node
TorstenStueber Dec 1, 2025
3d8eec1
Lower GasScale of dev node
TorstenStueber Dec 2, 2025
f872bac
Implement code review feedback
TorstenStueber Dec 2, 2025
4a591e0
Address clippy complaints
TorstenStueber Dec 2, 2025
314fe4b
Merge branch 'master' into torsten/gas-fixes
TorstenStueber Dec 3, 2025
c27a97e
Add missing licenses
TorstenStueber Dec 3, 2025
6c42907
Merge branch 'torsten/gas-fixes' into torsten/scale-eth-gas
TorstenStueber Dec 3, 2025
cef5cbb
Merge master
TorstenStueber Dec 3, 2025
922eb7a
Change GasScale to u32
TorstenStueber Dec 3, 2025
70b4010
Merge branch 'master' into torsten/scale-eth-gas
TorstenStueber Dec 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1214,6 +1214,7 @@ impl pallet_revive::Config for Runtime {
type FeeInfo = pallet_revive::evm::fees::Info<Address, Signature, EthExtraImpl>;
type MaxEthExtrinsicWeight = MaxEthExtrinsicWeight;
type DebugEnabled = ConstBool<false>;
type GasScale = ConstU32<1000>;
}

parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions cumulus/parachains/runtimes/testing/penpal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,7 @@ impl pallet_revive::Config for Runtime {
type FeeInfo = pallet_revive::evm::fees::Info<Address, Signature, EthExtraImpl>;
type MaxEthExtrinsicWeight = MaxEthExtrinsicWeight;
type DebugEnabled = ConstBool<false>;
type GasScale = ConstU32<1000>;
}

impl pallet_sudo::Config for Runtime {
Expand Down
39 changes: 39 additions & 0 deletions prdoc/pr_10393.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
title: Add configuration to set Ethereum gas scale
doc:
- audience: Runtime Dev
description: |-
This PR adds a new configuration parameter (`GasScale`) to pallet-revive that allows to change the scale of the Ethereum gas and of the Ethereum gas price.

Before this PR, the Ethereum gas price is simply the next fee multiplier of pallet-transaction-payment multiplied by `NativeToEthRatio`. Thus, on Polkadot this is 100_000_000 when the multiplier has its default value of 1.

The required gas of a transaction is its total cost divided by the gas price, where the total cost is the sum of the transaction fee and the storage deposit.

This leads to a situation where the required gas for a transaction on revive is usually orders of magnitude larger than the required amount of gas on Ethereum. This can lead to issues with tools or systems that interact with revive and hard code expected gas amounts or upper limits of gas amounts.

Setting `GasScale` has two effects:
- revive's Ethereum gas price is scaled up by the factor `GasScale`
- resulting used/estimated gas amounts get scaled down by the factor `GasScale`.

## Technical Details
Internally, revive uses exactly the same gas price and gas units as before. Only at the interface these amounts and prices get scaled by `GasScale`.

## Recommended
This PR sets `GasScale` for the dev-node to 50_000.

This is motivated by the fact that storing a value in a contract storage slot costs `DepositPerChildTrieItem + DepositPerByte * 32`, which is `2_000_000_000 + 10_000_000 * 32` (= `2_320_000_000`) plancks. Before this change the gas price was 1_000_000 wei, so that this
equated to 2_320_000_000 gas units. In EVM this operation requires 22_100 gas only.

Thus, `GasScale` would need to be about 100_000 in order for `SSTORE` to have similar worst case gas requirements.

## Resolved Issues

This PR addresses https://github.com/paritytech/contract-issues/issues/18 but we also need to find an appropriate `GasScale` for a mainnet installment of pallet-revive.
crates:
- name: revive-dev-runtime
bump: patch
- name: pallet-revive
bump: major
- name: asset-hub-westend-runtime
bump: patch
- name: penpal-runtime
bump: patch
1 change: 1 addition & 0 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1539,6 +1539,7 @@ impl pallet_revive::Config for Runtime {
type FeeInfo = pallet_revive::evm::fees::Info<Address, Signature, EthExtraImpl>;
type MaxEthExtrinsicWeight = MaxEthExtrinsicWeight;
type DebugEnabled = ConstBool<false>;
type GasScale = ConstU32<1000>;
}

impl pallet_sudo::Config for Runtime {
Expand Down
3 changes: 2 additions & 1 deletion substrate/frame/revive/dev-node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub mod genesis_config_presets {
use alloc::{vec, vec::Vec};
use serde_json::Value;

pub const ENDOWMENT: Balance = 1_000_000_001 * DOLLARS;
pub const ENDOWMENT: Balance = 10_000_000_000_001 * DOLLARS;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is this necessary? The scale shouldn't change the price apart from rounding.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's just because the evm test suite has one test with a very high hard coded gas limit and the endowment was not sufficient anymore to execute that transaction.

We can also change the hard coded limit in the test suite but I was lazy and just changed it here.


fn well_known_accounts() -> Vec<AccountId> {
Sr25519Keyring::well_known()
Expand Down Expand Up @@ -356,6 +356,7 @@ impl pallet_revive::Config for Runtime {
type Time = Timestamp;
type FeeInfo = FeeInfo<Address, Signature, EthExtraImpl>;
type DebugEnabled = ConstBool<false>;
type GasScale = ConstU32<50000>;
}

pallet_revive::impl_runtime_apis_plus_revive_traits!(
Expand Down
31 changes: 30 additions & 1 deletion substrate/frame/revive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,27 @@ pub mod pallet {
/// Allows debug-mode configuration, such as enabling unlimited contract size.
#[pallet::constant]
type DebugEnabled: Get<bool>;

/// This determines the relative scale of our gas price and gas estimates.
///
/// By default, the gas price (in wei) is `FeeInfo::next_fee_multiplier()` multiplied by
/// `NativeToEthRatio`. `GasScale` allows to scale this value: the actual gas price is the
/// default gas price multiplied by `GasScale`.
///
/// As a consequence, gas cost (gas estimates and actual gas usage during transaction) is
/// scaled down by the same factor. Thus, the total transaction cost is not affected by
/// `GasScale` – apart from rounding differences: the transaction cost is always a multiple
/// of the gas price and is derived by rounded up, so that with higher `GasScales` this can
/// lead to higher gas cost as the rounding difference would be larger.
///
/// The main purpose of changing the `GasScale` is to tune the gas cost so that it is closer
/// to standard EVM gas cost and contracts will not run out of gas when tools or code
/// assume hard coded gas limits.
///
/// Requirement: `GasScale` must not be 0
#[pallet::constant]
#[pallet::no_default_bounds]
type GasScale: Get<u32>;
}

/// Container for different types that implement [`DefaultConfig`]` of this pallet.
Expand Down Expand Up @@ -375,6 +396,7 @@ pub mod pallet {
pub const DepositPerByte: Balance = deposit(0, 1);
pub const CodeHashLockupDepositPercent: Perbill = Perbill::from_percent(0);
pub const MaxEthExtrinsicWeight: FixedU128 = FixedU128::from_rational(9, 10);
pub const GasScale: u32 = 10u32;
}

/// A type providing default configurations for this pallet in testing environment.
Expand Down Expand Up @@ -429,6 +451,7 @@ pub mod pallet {
type FeeInfo = ();
type MaxEthExtrinsicWeight = MaxEthExtrinsicWeight;
type DebugEnabled = ConstBool<false>;
type GasScale = GasScale;
}
}

Expand Down Expand Up @@ -892,6 +915,8 @@ pub mod pallet {
fn integrity_test() {
assert!(T::ChainId::get() > 0, "ChainId must be greater than 0");

assert!(T::GasScale::get() > 0u32.into(), "GasScale must not be 0");

T::FeeInfo::integrity_test();

// The memory available in the block building runtime
Expand Down Expand Up @@ -2114,8 +2139,12 @@ impl<T: Config> Pallet<T> {

/// Get the base gas price.
pub fn evm_base_fee() -> U256 {
let gas_scale = <T as Config>::GasScale::get();
let multiplier = T::FeeInfo::next_fee_multiplier();
multiplier.saturating_mul_int::<u128>(T::NativeToEthRatio::get().into()).into()
multiplier
.saturating_mul_int::<u128>(T::NativeToEthRatio::get().into())
.saturating_mul(gas_scale.saturated_into())
.into()
}

/// Build an EVM tracer from the given tracer type.
Expand Down
11 changes: 8 additions & 3 deletions substrate/frame/revive/src/metering/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// limitations under the License

use crate::{evm::fees::InfoT, BalanceOf, Config, StorageDeposit};
use frame_support::DebugNoBound;
use sp_core::Get;
use sp_runtime::{FixedPointNumber, Saturating};

/// The type for negative and positive gas amounts.
Expand Down Expand Up @@ -52,7 +53,8 @@ impl<T: Config> SignedGas<T> {
/// Transform an Ethereum gas amount coming from outside the metering system and transform into
/// the internally used SignedGas.
pub fn from_ethereum_gas(gas: BalanceOf<T>) -> Self {
Self::Positive(gas)
let gas_scale = <T as Config>::GasScale::get();
Self::Positive(gas.saturating_mul(gas_scale.into()))
}

/// Transform a storage deposit into a gas value. The value will be adjusted by dividing it
Expand Down Expand Up @@ -80,8 +82,11 @@ impl<T: Config> SignedGas<T> {
/// Transform the gas amount to an Ethereum gas amount usable for external purposes
/// Returns None if the gas amount is negative.
pub fn to_ethereum_gas(&self) -> Option<BalanceOf<T>> {
let gas_scale: BalanceOf<T> = <T as Config>::GasScale::get().into();

match self {
Positive(amount) => Some(*amount),
Positive(amount) =>
Some((amount.saturating_add(gas_scale.saturating_sub(1u32.into()))) / gas_scale),
Negative(..) => None,
}
}
Expand Down
Loading
Loading