Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(forge): blobbasefee cheatcode #7598

Merged
merged 6 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
40 changes: 40 additions & 0 deletions crates/cheatcodes/assets/cheatcodes.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions crates/cheatcodes/spec/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,17 @@ interface Vm {
#[cheatcode(group = Evm, safety = Safe)]
function getBlockTimestamp() external view returns (uint256 timestamp);

/// Sets `block.blobbasefee`
#[cheatcode(group = Evm, safety = Unsafe)]
function blobBaseFee(uint256 newBlobBaseFee) external;

/// Gets the current `block.blobbasefee`.
/// You should use this instead of `block.blobbasefee` if you use `vm.blobBaseFee`, as `block.blobbasefee` is assumed to be constant across a transaction,
/// and as a result will get optimized out by the compiler.
kamuik16 marked this conversation as resolved.
Show resolved Hide resolved
/// See https://github.com/foundry-rs/foundry/issues/6180
#[cheatcode(group = Evm, safety = Safe)]
function getBlobBaseFee() external view returns (uint256 blobBaseFee);

// -------- Account State --------

/// Sets an address' balance.
Expand Down
20 changes: 20 additions & 0 deletions crates/cheatcodes/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,26 @@ impl Cheatcode for getBlockTimestampCall {
}
}

impl Cheatcode for blobBaseFeeCall {
fn apply_full<DB: DatabaseExt>(&self, ccx: &mut CheatsCtxt<DB>) -> Result {
let Self { newBlobBaseFee } = self;
ensure!(
ccx.ecx.spec_id() >= SpecId::CANCUN,
"`blobBaseFee` is not supported before the Cancun hard fork; \
see EIP-4844: https://eips.ethereum.org/EIPS/eip-4844"
);
ccx.ecx.env.block.set_blob_excess_gas_and_price((*newBlobBaseFee).to());
Ok(Default::default())
}
}

impl Cheatcode for getBlobBaseFeeCall {
fn apply_full<DB: DatabaseExt>(&self, ccx: &mut CheatsCtxt<DB>) -> Result {
let Self {} = self;
Ok(ccx.ecx.env.block.get_blob_excess_gas().unwrap_or(0).abi_encode())
}
}

impl Cheatcode for dealCall {
fn apply_full<DB: DatabaseExt>(&self, ccx: &mut CheatsCtxt<DB>) -> Result {
let Self { account: address, newBalance: new_balance } = *self;
Expand Down
2 changes: 2 additions & 0 deletions testdata/cheats/Vm.sol

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions testdata/default/cheats/BlobBaseFee.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity ^0.8.0;

import "ds-test/test.sol";
import "cheats/Vm.sol";

contract BlobBaseFeeTest is DSTest {
Vm constant vm = Vm(HEVM_ADDRESS);

function test_blob_base_fee() public {
vm.blobBaseFee(6969);
assertEq(vm.getBlobBaseFee(), 6969);
}
}
Loading