File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -48,6 +48,8 @@ pub fn run(criterion: &mut Criterion) {
4848 // drop the journal
4949 let _ = evm. finalize ( ) ;
5050
51+ evm. modify_cfg ( |cfg| cfg. disable_nonce_check = false ) ;
52+
5153 criterion. bench_function ( "transfer_finalize" , |b| {
5254 b. iter ( || {
5355 let _ = evm. replay ( ) . unwrap ( ) ;
Original file line number Diff line number Diff line change @@ -330,6 +330,8 @@ pub enum InvalidTransaction {
330330 CreateInitCodeSizeLimit ,
331331 /// Transaction chain id does not match the config chain id.
332332 InvalidChainId ,
333+ /// Missing chain id.
334+ MissingChainId ,
333335 /// Access list is not supported for blocks before the Berlin hardfork.
334336 AccessListNotSupported ,
335337 /// `max_fee_per_blob_gas` is not supported for blocks before the Cancun hardfork.
@@ -445,6 +447,7 @@ impl fmt::Display for InvalidTransaction {
445447 write ! ( f, "create initcode size limit" )
446448 }
447449 Self :: InvalidChainId => write ! ( f, "invalid chain ID" ) ,
450+ Self :: MissingChainId => write ! ( f, "missing chain ID" ) ,
448451 Self :: AccessListNotSupported => write ! ( f, "access list not supported" ) ,
449452 Self :: MaxFeePerBlobGasNotSupported => {
450453 write ! ( f, "max fee per blob gas not supported" )
Original file line number Diff line number Diff line change @@ -20,6 +20,18 @@ pub enum TransactionType {
2020 Custom = 0xFF ,
2121}
2222
23+ impl TransactionType {
24+ /// Returns true if the transaction type is legacy.
25+ pub fn is_legacy ( & self ) -> bool {
26+ matches ! ( self , Self :: Legacy )
27+ }
28+
29+ /// Returns true if the transaction type is custom.
30+ pub fn is_custom ( & self ) -> bool {
31+ matches ! ( self , Self :: Custom )
32+ }
33+ }
34+
2335impl PartialEq < u8 > for TransactionType {
2436 fn eq ( & self , other : & u8 ) -> bool {
2537 ( * self as u8 ) == * other
Original file line number Diff line number Diff line change @@ -42,8 +42,6 @@ pub struct TxEnv {
4242
4343 /// The chain ID of the transaction
4444 ///
45- /// If set to [`None`], no checks are performed.
46- ///
4745 /// Incorporated as part of the Spurious Dragon upgrade via [EIP-155].
4846 ///
4947 /// [EIP-155]: https://eips.ethereum.org/EIPS/eip-155
Original file line number Diff line number Diff line change @@ -96,20 +96,22 @@ pub fn validate_tx_env<CTX: ContextTr, Error>(
9696 Some ( context. block ( ) . basefee ( ) as u128 )
9797 } ;
9898
99- let is_legacy_some = matches ! ( TransactionType :: from( tx_type) , TransactionType :: Legacy )
100- && tx. chain_id ( ) . is_some ( ) ;
99+ let tx_type = TransactionType :: from ( tx_type) ;
101100
102- // Check chain_id only if it is present in the legacy transaction .
101+ // Check chain_id if config is enabled .
103102 // EIP-155: Simple replay attack protection
104- if is_legacy_some && ! context. cfg ( ) . tx_chain_id_check ( ) {
103+ if context. cfg ( ) . tx_chain_id_check ( ) {
105104 if let Some ( chain_id) = tx. chain_id ( ) {
106105 if chain_id != context. cfg ( ) . chain_id ( ) {
107106 return Err ( InvalidTransaction :: InvalidChainId ) ;
108107 }
108+ } else if !tx_type. is_legacy ( ) && !tx_type. is_custom ( ) {
109+ // Legacy transaction are the only one that can omit chain_id.
110+ return Err ( InvalidTransaction :: MissingChainId ) ;
109111 }
110112 }
111113
112- match TransactionType :: from ( tx_type) {
114+ match tx_type {
113115 TransactionType :: Legacy => {
114116 // Gas price must be at least the basefee.
115117 if let Some ( base_fee) = base_fee {
You can’t perform that action at this time.
0 commit comments