Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions prdoc/pr_10026.prdoc
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion substrate/frame/revive/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()), <Pallet<T>>::evm_block_gas_limit());
}

#[benchmark(pov_mode = Measured)]
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/revive/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2106,7 +2106,7 @@ where
}

fn gas_limit(&self) -> u64 {
<T as frame_system::Config>::BlockWeights::get().max_block.ref_time()
<Contracts<T>>::evm_block_gas_limit().saturated_into()
}

fn chain_id(&self) -> u64 {
Expand Down
7 changes: 5 additions & 2 deletions substrate/frame/revive/src/tests/pvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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()),
<Test as frame_system::Config>::BlockWeights::get().max_block.ref_time()
<Pallet<Test>>::evm_block_gas_limit().saturated_into::<u64>(),
);
});
}
Expand Down
7 changes: 2 additions & 5 deletions substrate/frame/revive/src/tests/sol/block_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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!(
<Test as frame_system::Config>::BlockWeights::get().max_block.ref_time() as u64,
decoded
);
assert_eq!(<Pallet<Test>>::evm_block_gas_limit(), decoded.into());
});
}

Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/revive/src/vm/pvm/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ pub mod env {
#[stable]
fn gas_limit(&mut self, memory: &mut M) -> Result<u64, TrapReason> {
self.charge_gas(RuntimeCosts::GasLimit)?;
Ok(<E::T as frame_system::Config>::BlockWeights::get().max_block.ref_time())
Ok(self.ext.gas_limit())
}

/// Stores the value transferred along with this call/instantiate into the supplied buffer.
Expand Down
Loading