diff --git a/runtime/common/src/test.rs b/runtime/common/src/test.rs index 31ea6f09f..874106c7a 100644 --- a/runtime/common/src/test.rs +++ b/runtime/common/src/test.rs @@ -609,6 +609,38 @@ macro_rules! impl_weight_tests { let time_o_proof = time_fee.checked_div(proof_fee).unwrap_or_default(); assert!(time_o_proof <= 30, "{} should be at most 30", time_o_proof); } + + #[test] + fn eth_transaction_max_allowed_gas_limit() { + // frontier + use pallet_evm::GasWeightMapping; + + let max_extrinsic_weight = ::BlockWeights::get() + .get(DispatchClass::Normal) + .max_extrinsic + .expect("Failed to get max extrinsic weight"); + + assert!(!::GasWeightMapping::gas_to_weight( + 12_000_000, true + ) + .any_gt(max_extrinsic_weight)); + assert!(!::GasWeightMapping::gas_to_weight( + 14_000_000, true + ) + .any_gt(max_extrinsic_weight)); + assert!(!::GasWeightMapping::gas_to_weight( + 16_000_000, true + ) + .any_gt(max_extrinsic_weight)); + assert!(!::GasWeightMapping::gas_to_weight( + 18_000_000, true + ) + .any_gt(max_extrinsic_weight)); + assert!(::GasWeightMapping::gas_to_weight( + 20_000_000, true + ) + .any_gt(max_extrinsic_weight)); + } } }; } diff --git a/runtime/crab/src/pallets/evm.rs b/runtime/crab/src/pallets/evm.rs index 15d61a13f..fa9ae7b1d 100644 --- a/runtime/crab/src/pallets/evm.rs +++ b/runtime/crab/src/pallets/evm.rs @@ -19,21 +19,24 @@ // darwinia use crate::*; // substrate +use cumulus_primitives_core::relay_chain::MAX_POV_SIZE; use frame_support::dispatch::{DispatchClass, GetDispatchInfo, Pays}; // frontier use pallet_evm::{ExitError, IsPrecompileResult, Precompile}; use pallet_evm_precompile_dispatch::DispatchValidateT; const BLOCK_GAS_LIMIT: u64 = 20_000_000; -const MAX_POV_SIZE: u64 = 5 * 1024 * 1024; frame_support::parameter_types! { pub BlockGasLimit: sp_core::U256 = sp_core::U256::from(BLOCK_GAS_LIMIT); + // Restrict the POV size of the Ethereum transactions in the same way as weight limit. + pub BlockPovSizeLimit: u64 = NORMAL_DISPATCH_RATIO * MAX_POV_SIZE as u64; pub PrecompilesValue: CrabPrecompiles = CrabPrecompiles::<_>::new(); pub WeightPerGas: frame_support::weights::Weight = frame_support::weights::Weight::from_parts( fp_evm::weight_per_gas(BLOCK_GAS_LIMIT, NORMAL_DISPATCH_RATIO, WEIGHT_MILLISECS_PER_BLOCK), 0 ); - pub const GasLimitPovSizeRatio: u64 = BLOCK_GAS_LIMIT.saturating_div(MAX_POV_SIZE); + // TODO: FIX ME. https://github.com/rust-lang/rust/issues/88581 + pub GasLimitPovSizeRatio: u64 = BLOCK_GAS_LIMIT.saturating_div(BlockPovSizeLimit::get()) + 1; } pub struct CrabPrecompiles(sp_std::marker::PhantomData); diff --git a/runtime/darwinia/src/pallets/evm.rs b/runtime/darwinia/src/pallets/evm.rs index 66ba7634f..a2bf4901d 100644 --- a/runtime/darwinia/src/pallets/evm.rs +++ b/runtime/darwinia/src/pallets/evm.rs @@ -19,21 +19,24 @@ // darwinia use crate::*; // substrate +use cumulus_primitives_core::relay_chain::MAX_POV_SIZE; use frame_support::dispatch::{DispatchClass, GetDispatchInfo, Pays}; // frontier use pallet_evm::{ExitError, IsPrecompileResult, Precompile}; use pallet_evm_precompile_dispatch::DispatchValidateT; const BLOCK_GAS_LIMIT: u64 = 20_000_000; -const MAX_POV_SIZE: u64 = 5 * 1024 * 1024; frame_support::parameter_types! { pub BlockGasLimit: sp_core::U256 = sp_core::U256::from(BLOCK_GAS_LIMIT); + // Restrict the POV size of the Ethereum transactions in the same way as weight limit. + pub BlockPovSizeLimit: u64 = NORMAL_DISPATCH_RATIO * MAX_POV_SIZE as u64; pub PrecompilesValue: DarwiniaPrecompiles = DarwiniaPrecompiles::<_>::new(); pub WeightPerGas: frame_support::weights::Weight = frame_support::weights::Weight::from_parts( fp_evm::weight_per_gas(BLOCK_GAS_LIMIT, NORMAL_DISPATCH_RATIO, WEIGHT_MILLISECS_PER_BLOCK), 0 ); - pub const GasLimitPovSizeRatio: u64 = BLOCK_GAS_LIMIT.saturating_div(MAX_POV_SIZE); + // TODO: FIX ME. https://github.com/rust-lang/rust/issues/88581 + pub GasLimitPovSizeRatio: u64 = BLOCK_GAS_LIMIT.saturating_div(BlockPovSizeLimit::get()) + 1; } pub struct DarwiniaPrecompiles(sp_std::marker::PhantomData); impl DarwiniaPrecompiles diff --git a/runtime/pangolin/src/pallets/evm.rs b/runtime/pangolin/src/pallets/evm.rs index 80b776499..d0e2b1e3e 100644 --- a/runtime/pangolin/src/pallets/evm.rs +++ b/runtime/pangolin/src/pallets/evm.rs @@ -19,21 +19,24 @@ // darwinia use crate::*; // substrate +use cumulus_primitives_core::relay_chain::MAX_POV_SIZE; use frame_support::dispatch::{DispatchClass, GetDispatchInfo, Pays}; // frontier use pallet_evm::{ExitError, IsPrecompileResult, Precompile}; use pallet_evm_precompile_dispatch::DispatchValidateT; const BLOCK_GAS_LIMIT: u64 = 20_000_000; -const MAX_POV_SIZE: u64 = 5 * 1024 * 1024; frame_support::parameter_types! { pub BlockGasLimit: sp_core::U256 = sp_core::U256::from(BLOCK_GAS_LIMIT); + // Restrict the POV size of the Ethereum transactions in the same way as weight limit. + pub BlockPovSizeLimit: u64 = NORMAL_DISPATCH_RATIO * MAX_POV_SIZE as u64; pub PrecompilesValue: PangolinPrecompiles = PangolinPrecompiles::<_>::new(); pub WeightPerGas: frame_support::weights::Weight = frame_support::weights::Weight::from_parts( fp_evm::weight_per_gas(BLOCK_GAS_LIMIT, NORMAL_DISPATCH_RATIO, WEIGHT_MILLISECS_PER_BLOCK), 0 ); - pub const GasLimitPovSizeRatio: u64 = BLOCK_GAS_LIMIT.saturating_div(MAX_POV_SIZE); + // TODO: FIX ME. https://github.com/rust-lang/rust/issues/88581 + pub GasLimitPovSizeRatio: u64 = BLOCK_GAS_LIMIT.saturating_div(BlockPovSizeLimit::get()) + 1; } pub struct PangolinPrecompiles(sp_std::marker::PhantomData); diff --git a/runtime/pangoro/src/pallets/evm.rs b/runtime/pangoro/src/pallets/evm.rs index e5f4c5cf8..ad7212d67 100644 --- a/runtime/pangoro/src/pallets/evm.rs +++ b/runtime/pangoro/src/pallets/evm.rs @@ -19,21 +19,24 @@ // darwinia use crate::*; // substrate +use cumulus_primitives_core::relay_chain::MAX_POV_SIZE; use frame_support::dispatch::{DispatchClass, GetDispatchInfo, Pays}; // frontier use pallet_evm::{ExitError, IsPrecompileResult, Precompile}; use pallet_evm_precompile_dispatch::DispatchValidateT; const BLOCK_GAS_LIMIT: u64 = 20_000_000; -const MAX_POV_SIZE: u64 = 5 * 1024 * 1024; frame_support::parameter_types! { pub BlockGasLimit: sp_core::U256 = sp_core::U256::from(BLOCK_GAS_LIMIT); + // Restrict the POV size of the Ethereum transactions in the same way as weight limit. + pub BlockPovSizeLimit: u64 = NORMAL_DISPATCH_RATIO * MAX_POV_SIZE as u64; pub PrecompilesValue: PangoroPrecompiles = PangoroPrecompiles::<_>::new(); pub WeightPerGas: frame_support::weights::Weight = frame_support::weights::Weight::from_parts( fp_evm::weight_per_gas(BLOCK_GAS_LIMIT, NORMAL_DISPATCH_RATIO, WEIGHT_MILLISECS_PER_BLOCK), 0 ); - pub const GasLimitPovSizeRatio: u64 = BLOCK_GAS_LIMIT.saturating_div(MAX_POV_SIZE); + // TODO: FIX ME. https://github.com/rust-lang/rust/issues/88581 + pub GasLimitPovSizeRatio: u64 = BLOCK_GAS_LIMIT.saturating_div(BlockPovSizeLimit::get()) + 1; } pub struct PangoroPrecompiles(sp_std::marker::PhantomData); diff --git a/tests/ethereum/test-bls.ts b/tests/ethereum/test-bls.ts index 2101bfbda..395a7b9ef 100644 --- a/tests/ethereum/test-bls.ts +++ b/tests/ethereum/test-bls.ts @@ -566,7 +566,7 @@ describe("Test Bls precompile", () => { }).timeout(60000); it("Return OutOfGas if insufficient gas", async () => { - bls.options.gas = 300_000; + bls.options.gas = 1000_000; // Less than the normal used gas await bls.methods .fast_aggregate_verify(pub_keys_bytes, hexToBytes(message), hexToBytes(signature)) .call()