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
8 changes: 8 additions & 0 deletions prdoc/pr_9945.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
title: pallet-revive update basefee instruction
doc:
- audience: Runtime Dev
description: The base fee instruction now returns the proper base price instead
of a hard coded value.
crates:
- name: pallet-revive
bump: major
4 changes: 2 additions & 2 deletions substrate/frame/revive/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ mod benchmarks {
{
result = runtime.bench_gas_price(memory.as_mut_slice());
}
assert_eq!(U256::from(result.unwrap()), <Pallet<T>>::evm_gas_price());
assert_eq!(U256::from(result.unwrap()), <Pallet<T>>::evm_base_fee());
}

#[benchmark(pov_mode = Measured)]
Expand All @@ -1006,7 +1006,7 @@ mod benchmarks {
result = runtime.bench_base_fee(memory.as_mut_slice(), 0);
}
assert_ok!(result);
assert_eq!(U256::from_little_endian(&memory[..]), U256::zero());
assert_eq!(U256::from_little_endian(&memory[..]), <crate::Pallet<T>>::evm_base_fee());
}

#[benchmark(pov_mode = Measured)]
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/revive/src/evm/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ where
T: Config,
CallOf<T>: SetWeightLimit,
{
let base_fee = <Pallet<T>>::evm_gas_price();
let base_fee = <Pallet<T>>::evm_base_fee();

let Some(gas) = tx.gas else {
log::debug!(target: LOG_TARGET, "No gas provided");
Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/revive/src/evm/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ pub trait EthExtra {
InvalidTransaction::BadProof
})?;
let signer = <Self::Config as Config>::AddressMapper::to_fallback_account_id(&signer_addr);
let base_fee = <Pallet<Self::Config>>::evm_gas_price();
let base_fee = <Pallet<Self::Config>>::evm_base_fee();
let tx = GenericTransaction::from_signed(tx, base_fee, None);
let nonce = tx.nonce.unwrap_or_default().try_into().map_err(|_| {
log::debug!(target: LOG_TARGET, "Failed to convert nonce");
Expand Down Expand Up @@ -406,7 +406,7 @@ mod test {
Self::fund_account(&account);

let dry_run = crate::Pallet::<Test>::dry_run_eth_transact(self.tx.clone());
self.tx.gas_price = Some(<Pallet<Test>>::evm_gas_price());
self.tx.gas_price = Some(<Pallet<Test>>::evm_base_fee());

match dry_run {
Ok(dry_run) => {
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 @@ -2192,7 +2192,7 @@ where
fn effective_gas_price(&self) -> U256 {
self.exec_config
.effective_gas_price
.unwrap_or_else(|| <Contracts<T>>::evm_gas_price())
.unwrap_or_else(|| <Contracts<T>>::evm_base_fee())
}
}

Expand Down
6 changes: 3 additions & 3 deletions substrate/frame/revive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1414,7 +1414,7 @@ impl<T: Config> Pallet<T> {
let origin = T::AddressMapper::to_account_id(&tx.from.unwrap_or_default());
Self::prepare_dry_run(&origin);

let base_fee = Self::evm_gas_price();
let base_fee = Self::evm_base_fee();
let effective_gas_price = tx.effective_gas_price(base_fee).unwrap_or(base_fee);

if effective_gas_price < base_fee {
Expand Down Expand Up @@ -1709,7 +1709,7 @@ impl<T: Config> Pallet<T> {
}

/// Get the base gas price.
pub fn evm_gas_price() -> U256 {
pub fn evm_base_fee() -> U256 {
let multiplier = T::FeeInfo::next_fee_multiplier();
multiplier.saturating_mul_int::<u128>(T::NativeToEthRatio::get().into()).into()
}
Expand Down Expand Up @@ -2269,7 +2269,7 @@ macro_rules! impl_runtime_apis_plus_revive_traits {
}

fn gas_price() -> $crate::U256 {
$crate::Pallet::<Self>::evm_gas_price()
$crate::Pallet::<Self>::evm_base_fee()
}

fn nonce(address: $crate::H160) -> Nonce {
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 @@ -3375,7 +3375,7 @@ fn gas_price_api_works() {
assert_eq!(received.flags, ReturnFlags::empty());
assert_eq!(
u64::from_le_bytes(received.data[..].try_into().unwrap()),
u64::try_from(<Pallet<Test>>::evm_gas_price()).unwrap(),
u64::try_from(<Pallet<Test>>::evm_base_fee()).unwrap(),
);
});
}
Expand All @@ -3394,7 +3394,10 @@ fn base_fee_api_works() {
// Call the contract: It echoes back the value returned by the base fee API.
let received = builder::bare_call(addr).build_and_unwrap_result();
assert_eq!(received.flags, ReturnFlags::empty());
assert_eq!(U256::from_little_endian(received.data[..].try_into().unwrap()), U256::zero());
assert_eq!(
U256::from_little_endian(received.data[..].try_into().unwrap()),
<Pallet<Test>>::evm_base_fee(),
);
});
}

Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/revive/src/tests/sol/block_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ fn gaslimit_works(fixture_type: FixtureType) {
/// Tests that the basefee opcode works as expected.
#[test_case(FixtureType::Solc)]
#[test_case(FixtureType::Resolc)]
fn basefee_works(fixture_type: FixtureType) {
fn base_fee_works(fixture_type: FixtureType) {
let (code, _) = compile_module_with_type("BlockInfo", fixture_type).unwrap();
ExtBuilder::default().build().execute_with(|| {
let _ = <Test as Config>::Currency::set_balance(&ALICE, 100_000_000_000);
Expand All @@ -148,7 +148,7 @@ fn basefee_works(fixture_type: FixtureType) {
.data(BlockInfo::BlockInfoCalls::basefee(BlockInfo::basefeeCall {}).abi_encode())
.build_and_unwrap_result();
let decoded = BlockInfo::basefeeCall::abi_decode_returns(&result.data).unwrap();
assert_eq!(0u64, decoded);
assert_eq!(<crate::Pallet<Test>>::evm_base_fee().as_u64(), decoded);
});
}

Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/revive/src/tests/sol/tx_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn gasprice_works(fixture_type: FixtureType) {
)
.build_and_unwrap_result();
let decoded = TransactionInfo::gaspriceCall::abi_decode_returns(&result.data).unwrap();
assert_eq!(<Pallet<Test>>::evm_gas_price().as_u64(), decoded);
assert_eq!(<Pallet<Test>>::evm_base_fee().as_u64(), decoded);
});
}

Expand Down
6 changes: 0 additions & 6 deletions substrate/frame/revive/src/vm/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use crate::{
vm::{evm::instructions::exec_instruction, BytecodeType, ExecResult, Ext},
weights::WeightInfo,
AccountIdOf, CodeInfo, Config, ContractBlob, DispatchError, Error, Weight, H256, LOG_TARGET,
U256,
};
use alloc::vec::Vec;
use core::{convert::Infallible, ops::ControlFlow};
Expand Down Expand Up @@ -48,11 +47,6 @@ mod util;
/// opcode. The value is aligned with the difficulty hardcoded for PVM contracts.
pub(crate) const DIFFICULTY: u64 = 2500000000000000_u64;

/// The base fee per gas used in the network as defined by EIP-1559.
///
/// For `pallet-revive`, this is hardcoded to 0
pub(crate) const BASE_FEE: U256 = U256::zero();

/// Cost for a single unit of EVM gas.
#[derive(Eq, PartialEq, Debug, Clone, Copy)]
pub struct EVMGas(u64);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

use crate::{
vm::{
evm::{interpreter::Halt, EVMGas, Interpreter, BASE_FEE, DIFFICULTY},
evm::{interpreter::Halt, EVMGas, Interpreter, DIFFICULTY},
Ext,
},
Error, RuntimeCosts,
Expand Down Expand Up @@ -85,7 +85,7 @@ pub fn gaslimit<E: Ext>(interpreter: &mut Interpreter<E>) -> ControlFlow<Halt> {
/// EIP-3198: BASEFEE opcode
pub fn basefee<E: Ext>(interpreter: &mut Interpreter<E>) -> ControlFlow<Halt> {
interpreter.ext.charge_or_halt(RuntimeCosts::BaseFee)?;
interpreter.stack.push(BASE_FEE)?;
interpreter.stack.push(crate::Pallet::<E::T>::evm_base_fee())?;
ControlFlow::Continue(())
}

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 @@ -660,7 +660,7 @@ pub mod env {
Ok(self.write_fixed_sandbox_output(
memory,
out_ptr,
&U256::zero().to_little_endian(),
&Pallet::<E::T>::evm_base_fee().to_little_endian(),
false,
already_charged,
)?)
Expand Down
Loading