Skip to content

Commit

Permalink
Merge pull request foundry-rs#9 from foundry-rs/master
Browse files Browse the repository at this point in the history
fix(anvil): disable basefee if manually set to 0 (foundry-rs#5126)
  • Loading branch information
0xvanbeethoven authored Jun 9, 2023
2 parents a1396e9 + 2ffa619 commit f5bd120
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
16 changes: 15 additions & 1 deletion anvil/src/eth/backend/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,14 @@ impl Backend {
let (outcome, header, block_hash) = {
let current_base_fee = self.base_fee();

let mut env = self.env.read().clone();
let mut env = self.env().read().clone();

if env.block.basefee == revm::primitives::U256::ZERO {
// this is an edge case because the evm fails if `tx.effective_gas_price < base_fee`
// 0 is only possible if it's manually set
env.cfg.disable_base_fee = true;
}

// increase block number for this block
env.block.number = env.block.number.saturating_add(rU256::from(1));
env.block.basefee = current_base_fee.into();
Expand Down Expand Up @@ -1013,6 +1020,13 @@ impl Backend {
nonce: nonce.map(|n| n.as_u64()),
access_list: to_revm_access_list(access_list.unwrap_or_default()),
};

if env.block.basefee == revm::primitives::U256::ZERO {
// this is an edge case because the evm fails if `tx.effective_gas_price < base_fee`
// 0 is only possible if it's manually set
env.cfg.disable_base_fee = true;
}

env
}

Expand Down
1 change: 1 addition & 0 deletions evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ revm = { version = "3", default-features = false, features = [
"memory_limit",
"optional_eip3607",
"optional_block_gas_limit",
"optional_no_base_fee"
] }

# Fuzzer
Expand Down
5 changes: 5 additions & 0 deletions evm/src/executor/fork/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ impl<'de> Deserialize<'de> for BlockchainDbMeta {
// keep default value
obj.insert(key.to_string(), false.into());
}
let key = "disable_base_fee";
if !obj.contains_key(key) {
// keep default value
obj.insert(key.to_string(), false.into());
}
}

let cfg_env: revm::primitives::CfgEnv =
Expand Down

0 comments on commit f5bd120

Please sign in to comment.