24
24
EthereumException ,
25
25
InvalidBlock ,
26
26
InvalidSenderError ,
27
+ InsufficientBalanceError ,
28
+ NonceMismatchError
27
29
)
28
30
29
31
from . import vm
30
32
from .blocks import Block , Header , Log , Receipt , Withdrawal , encode_receipt
31
33
from .bloom import logs_bloom
34
+ from .exceptions import (
35
+ TransactionTypeContractCreationError ,
36
+ BlobGasLimitExceededError ,
37
+ InsufficientMaxFeePerBlobGasError ,
38
+ InsufficientMaxFeePerGasError ,
39
+ InvalidBlobVersionedHashError ,
40
+ NoBlobDataError ,
41
+ PriorityFeeGreaterThanMaxFeeError ,
42
+ EmptyAuthorizationListError
43
+ )
32
44
from .fork_types import Account , Address , Authorization , VersionedHash
33
45
from .requests import (
34
46
CONSOLIDATION_REQUEST_TYPE ,
@@ -409,7 +421,7 @@ def check_transaction(
409
421
410
422
tx_blob_gas_used = calculate_total_blob_gas (tx )
411
423
if tx_blob_gas_used > blob_gas_available :
412
- raise InvalidBlock
424
+ raise BlobGasLimitExceededError ( "blob gas limit exceeded" )
413
425
414
426
sender_address = recover_sender (block_env .chain_id , tx )
415
427
sender_account = get_account (block_env .state , sender_address )
@@ -418,9 +430,9 @@ def check_transaction(
418
430
tx , (FeeMarketTransaction , BlobTransaction , SetCodeTransaction )
419
431
):
420
432
if tx .max_fee_per_gas < tx .max_priority_fee_per_gas :
421
- raise InvalidBlock
433
+ raise PriorityFeeGreaterThanMaxFeeError ( "priority fee greater than max fee" )
422
434
if tx .max_fee_per_gas < block_env .base_fee_per_gas :
423
- raise InvalidBlock
435
+ raise InsufficientMaxFeePerGasError ( "insufficient max fee per gas" )
424
436
425
437
priority_fee_per_gas = min (
426
438
tx .max_priority_fee_per_gas ,
@@ -436,14 +448,14 @@ def check_transaction(
436
448
437
449
if isinstance (tx , BlobTransaction ):
438
450
if len (tx .blob_versioned_hashes ) == 0 :
439
- raise InvalidBlock
451
+ raise NoBlobDataError ( "no blob data in transaction" )
440
452
for blob_versioned_hash in tx .blob_versioned_hashes :
441
453
if blob_versioned_hash [0 :1 ] != VERSIONED_HASH_VERSION_KZG :
442
- raise InvalidBlock
454
+ raise InvalidBlobVersionedHashError ( "invalid blob versioned hash" )
443
455
444
456
blob_gas_price = calculate_blob_gas_price (block_env .excess_blob_gas )
445
457
if Uint (tx .max_fee_per_blob_gas ) < blob_gas_price :
446
- raise InvalidBlock
458
+ raise InsufficientMaxFeePerBlobGasError ( "insufficient max fee per blob gas" )
447
459
448
460
max_gas_fee += Uint (calculate_total_blob_gas (tx )) * Uint (
449
461
tx .max_fee_per_blob_gas
@@ -454,16 +466,19 @@ def check_transaction(
454
466
455
467
if isinstance (tx , (BlobTransaction , SetCodeTransaction )):
456
468
if not isinstance (tx .to , Address ):
457
- raise InvalidBlock
469
+ raise TransactionTypeContractCreationError ( tx [ 0 ])
458
470
459
471
if isinstance (tx , SetCodeTransaction ):
460
472
if not any (tx .authorizations ):
461
- raise InvalidBlock
473
+ raise EmptyAuthorizationListError ( "empty authorization list" )
462
474
463
475
if sender_account .nonce != tx .nonce :
464
- raise InvalidBlock
476
+ if sender_account .nonce > tx .nonce :
477
+ raise NonceMismatchError ("nonce too low" )
478
+ else :
479
+ raise NonceMismatchError ("nonce too high" )
465
480
if Uint (sender_account .balance ) < max_gas_fee + Uint (tx .value ):
466
- raise InvalidBlock
481
+ raise InsufficientBalanceError ( "insufficient sender balance" )
467
482
if sender_account .code and not is_valid_delegation (sender_account .code ):
468
483
raise InvalidSenderError ("not EOA" )
469
484
0 commit comments