diff --git a/prdoc/pr_10026.prdoc b/prdoc/pr_10026.prdoc new file mode 100644 index 0000000000000..110e46efca004 --- /dev/null +++ b/prdoc/pr_10026.prdoc @@ -0,0 +1,7 @@ +title: 'pallet_revive: Fix incorrect `block.gaslimit`' +doc: +- audience: Runtime User + description: Fixes https://github.com/paritytech/contract-issues/issues/112 +crates: +- name: pallet-revive + bump: patch diff --git a/substrate/frame/revive/src/benchmarking.rs b/substrate/frame/revive/src/benchmarking.rs index 9732e88bbe6e0..69850e7c030e2 100644 --- a/substrate/frame/revive/src/benchmarking.rs +++ b/substrate/frame/revive/src/benchmarking.rs @@ -985,7 +985,7 @@ mod benchmarks { { result = runtime.bench_gas_limit(&mut memory); } - assert_eq!(result.unwrap(), T::BlockWeights::get().max_block.ref_time()); + assert_eq!(U256::from(result.unwrap()), >::evm_block_gas_limit()); } #[benchmark(pov_mode = Measured)] diff --git a/substrate/frame/revive/src/exec.rs b/substrate/frame/revive/src/exec.rs index 802266210a0fa..743bb84a32a7b 100644 --- a/substrate/frame/revive/src/exec.rs +++ b/substrate/frame/revive/src/exec.rs @@ -2106,7 +2106,7 @@ where } fn gas_limit(&self) -> u64 { - ::BlockWeights::get().max_block.ref_time() + >::evm_block_gas_limit().saturated_into() } fn chain_id(&self) -> u64 { diff --git a/substrate/frame/revive/src/tests/pvm.rs b/substrate/frame/revive/src/tests/pvm.rs index 6b3777eaf41c2..4fa7b0c7167a0 100644 --- a/substrate/frame/revive/src/tests/pvm.rs +++ b/substrate/frame/revive/src/tests/pvm.rs @@ -62,7 +62,10 @@ use pallet_revive_uapi::{ReturnErrorCode as RuntimeReturnCode, ReturnFlags}; use pretty_assertions::{assert_eq, assert_ne}; use sp_core::{Get, U256}; use sp_io::hashing::blake2_256; -use sp_runtime::{testing::H256, traits::Zero, AccountId32, BoundedVec, DispatchError, TokenError}; +use sp_runtime::{ + testing::H256, traits::Zero, AccountId32, BoundedVec, DispatchError, SaturatedConversion, + TokenError, +}; #[test] fn transfer_with_dust_works() { @@ -3950,7 +3953,7 @@ fn gas_limit_api_works() { assert_eq!(received.flags, ReturnFlags::empty()); assert_eq!( u64::from_le_bytes(received.data[..].try_into().unwrap()), - ::BlockWeights::get().max_block.ref_time() + >::evm_block_gas_limit().saturated_into::(), ); }); } diff --git a/substrate/frame/revive/src/tests/sol/block_info.rs b/substrate/frame/revive/src/tests/sol/block_info.rs index 94d5f8f5198b9..258aa61e131c6 100644 --- a/substrate/frame/revive/src/tests/sol/block_info.rs +++ b/substrate/frame/revive/src/tests/sol/block_info.rs @@ -21,7 +21,7 @@ use crate::{ test_utils::{builder::Contract, ALICE}, tests::{builder, Contracts, ExtBuilder, System, Test, Timestamp}, vm::evm::DIFFICULTY, - Code, Config, + Code, Config, Pallet, }; use alloy_core::sol_types::{SolCall, SolInterface}; @@ -127,10 +127,7 @@ fn gaslimit_works(fixture_type: FixtureType) { .data(BlockInfo::BlockInfoCalls::gaslimit(BlockInfo::gaslimitCall {}).abi_encode()) .build_and_unwrap_result(); let decoded = BlockInfo::gaslimitCall::abi_decode_returns(&result.data).unwrap(); - assert_eq!( - ::BlockWeights::get().max_block.ref_time() as u64, - decoded - ); + assert_eq!(>::evm_block_gas_limit(), decoded.into()); }); } diff --git a/substrate/frame/revive/src/vm/pvm/env.rs b/substrate/frame/revive/src/vm/pvm/env.rs index 7c923f7b9fb49..c2427bb158f27 100644 --- a/substrate/frame/revive/src/vm/pvm/env.rs +++ b/substrate/frame/revive/src/vm/pvm/env.rs @@ -627,7 +627,7 @@ pub mod env { #[stable] fn gas_limit(&mut self, memory: &mut M) -> Result { self.charge_gas(RuntimeCosts::GasLimit)?; - Ok(::BlockWeights::get().max_block.ref_time()) + Ok(self.ext.gas_limit()) } /// Stores the value transferred along with this call/instantiate into the supplied buffer.