Skip to content

Conversation

filip-parity
Copy link

TL;DR

This pull request implements the vm.fee cheatcode for polkadot-foundry's PVM mode, following the same pattern as existing cheatcodes like vm.roll and vm.warp.

Changes

  • Added vm.fee handler in revive-strategy to update block.basefee in EVM context
  • Added comprehensive test to verify vm.fee functionality in PVM mode

Closes #318

});
}

fn set_basefee(new_basefee: U256, ecx: Ecx<'_, '_, '_>) {
Copy link

Choose a reason for hiding this comment

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

okay, so i assume it's not possible to modify the value of Weights::seal_base_fee on pallet-revive?

Copy link

Choose a reason for hiding this comment

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

and do we have anyone who's up to date on gas mapping?

Copy link
Author

Choose a reason for hiding this comment

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

Not really

@filip-parity filip-parity requested a review from pkhry September 30, 2025 06:48
import "./Vm.sol";
import {console} from "./console.sol";
contract Fee is DSTest {
Copy link

Choose a reason for hiding this comment

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

try calling block.basefee from a contract that's deployed on pvm side


fn set_basefee(new_basefee: U256, ecx: Ecx<'_, '_, '_>) {
// Set basefee in EVM context.
ecx.block.basefee = new_basefee.try_into().expect("Basefee exceeds u64");
Copy link
Collaborator

@smiasojed smiasojed Sep 30, 2025

Choose a reason for hiding this comment

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

did you check how zksync is handling it?
I think they keep it consistent between vm calls.

  1. Single Source of Truth

// vm.fee() cheatcode sets this:
ccx.ecx.block.basefee =
newBasefee.saturating_to(); // Line 459 in
evm.rs

  1. Shared Through EthEvmContext

When zkVM is called, it receives the same
EthEvmContext that EVM uses:

// In zksync_try_call (strategy/zksync):
foundry_zksync_core::vm::call(call,
factory_deps, ecx, ccx)

  1. zkVM Extracts Basefee from Shared Context

// In runner.rs:303 - zkVM reads basefee from
the shared ecx.block:
block_basefee: min(max_fee_per_gas.to_ru256(),
rU256::from(ecx.block.basefee)),

Why do we use different approach?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Forge test] [Cheatcode support] Implement vm.fee
3 participants