Skip to content

Commit 4e3f71d

Browse files
committed
fix: correctly set txtype when setting up TxEnv
1 parent 031e060 commit 4e3f71d

File tree

2 files changed

+26
-4
lines changed
  • crates

2 files changed

+26
-4
lines changed

crates/anvil/src/eth/backend/mem/mod.rs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,14 @@ use alloy_consensus::{
4242
Account, BlockHeader, EnvKzgSettings, Header, Receipt, ReceiptWithBloom, Signed,
4343
Transaction as TransactionTrait, TxEnvelope,
4444
};
45-
use alloy_eips::{eip1559::BaseFeeParams, eip4844::MAX_BLOBS_PER_BLOCK};
45+
use alloy_eips::{
46+
eip1559::BaseFeeParams,
47+
eip2718::{
48+
EIP1559_TX_TYPE_ID, EIP2930_TX_TYPE_ID, EIP4844_TX_TYPE_ID, EIP7702_TX_TYPE_ID,
49+
LEGACY_TX_TYPE_ID,
50+
},
51+
eip4844::MAX_BLOBS_PER_BLOCK,
52+
};
4653
use alloy_evm::{eth::EthEvmContext, Database, Evm};
4754
use alloy_network::{
4855
AnyHeader, AnyRpcBlock, AnyRpcHeader, AnyRpcTransaction, AnyTxEnvelope, AnyTxType,
@@ -1410,7 +1417,7 @@ impl Backend {
14101417
authorization_list,
14111418
nonce,
14121419
sidecar: _,
1413-
chain_id: _,
1420+
chain_id,
14141421
transaction_type,
14151422
.. // Rest of the gas fees related fields are taken from `fee_details`
14161423
},
@@ -1424,6 +1431,20 @@ impl Backend {
14241431
max_fee_per_blob_gas,
14251432
} = fee_details;
14261433

1434+
let tx_type = transaction_type.unwrap_or_else(|| {
1435+
if authorization_list.is_some() {
1436+
EIP7702_TX_TYPE_ID
1437+
} else if blob_versioned_hashes.is_some() {
1438+
EIP4844_TX_TYPE_ID
1439+
} else if max_fee_per_gas.is_some() || max_priority_fee_per_gas.is_some() {
1440+
EIP1559_TX_TYPE_ID
1441+
} else if access_list.is_some() {
1442+
EIP2930_TX_TYPE_ID
1443+
} else {
1444+
LEGACY_TX_TYPE_ID
1445+
}
1446+
});
1447+
14271448
let gas_limit = gas.unwrap_or(block_env.gas_limit);
14281449
let mut env = self.env.read().clone();
14291450
env.evm_env.block_env = block_env;
@@ -1463,10 +1484,10 @@ impl Backend {
14631484
Some(addr) => TxKind::Call(*addr),
14641485
None => TxKind::Create,
14651486
},
1466-
tx_type: transaction_type.unwrap_or_default(),
1487+
tx_type,
14671488
value: value.unwrap_or_default(),
14681489
data: input.into_input().unwrap_or_default(),
1469-
chain_id: None,
1490+
chain_id: Some(chain_id.unwrap_or(self.env.read().evm_env.cfg_env.chain_id)),
14701491
access_list: access_list.unwrap_or_default(),
14711492
blob_hashes,
14721493
authorization_list: authorization_list.unwrap_or_default(),

crates/evm/evm/src/executors/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ impl Executor {
438438
) -> eyre::Result<RawCallResult> {
439439
let mut env = self.build_test_env(from, to.into(), calldata, value);
440440
env.tx.authorization_list = authorization_list;
441+
env.tx.tx_type = 4;
441442
self.call_with_env(env)
442443
}
443444

0 commit comments

Comments
 (0)