1
- from eth_utils import encode_hex , keccak
2
-
3
- from eth import constants
4
- from eth .abc import ComputationAPI , MessageAPI , StateAPI , TransactionContextAPI
5
- from eth .exceptions import OutOfGas , ReservedBytesInCode
1
+ from eth .exceptions import ReservedBytesInCode
6
2
from eth .vm .forks .berlin .computation import (
7
3
BerlinComputation ,
8
4
)
9
5
10
6
from .opcodes import LONDON_OPCODES
11
7
from ..london .constants import EIP3541_RESERVED_STARTING_BYTE
12
- from ..spurious_dragon .constants import EIP170_CODE_SIZE_LIMIT
13
8
14
9
15
10
class LondonComputation (BerlinComputation ):
@@ -20,60 +15,8 @@ class LondonComputation(BerlinComputation):
20
15
opcodes = LONDON_OPCODES
21
16
22
17
@classmethod
23
- def apply_create_message (
24
- cls ,
25
- state : StateAPI ,
26
- message : MessageAPI ,
27
- transaction_context : TransactionContextAPI
28
- ) -> ComputationAPI :
29
-
30
- snapshot = state .snapshot ()
31
-
32
- # EIP161 nonce incrementation
33
- state .increment_nonce (message .storage_address )
34
-
35
- computation = cls .apply_message (state , message , transaction_context )
36
-
37
- if computation .is_error :
38
- state .revert (snapshot )
39
- return computation
40
- else :
41
- contract_code = computation .output
42
-
43
- if contract_code and len (contract_code ) >= EIP170_CODE_SIZE_LIMIT :
44
- computation .error = OutOfGas (
45
- f"Contract code size exceeds EIP170 limit of { EIP170_CODE_SIZE_LIMIT } ."
46
- f" Got code of size: { len (contract_code )} "
47
- )
48
- state .revert (snapshot )
49
- elif contract_code :
50
- contract_code_gas_cost = len (contract_code ) * constants .GAS_CODEDEPOSIT
51
- try :
52
- computation .consume_gas (
53
- contract_code_gas_cost ,
54
- reason = "Write contract code for CREATE / CREATE2" ,
55
- )
56
- except OutOfGas as err :
57
- computation .error = err
58
- state .revert (snapshot )
59
- else :
60
- if contract_code [:1 ] == EIP3541_RESERVED_STARTING_BYTE :
61
- # As per EIP-3541, gas is still consumed on a revert of this nature
62
- state .revert (snapshot )
63
- raise ReservedBytesInCode (
64
- "Contract code begins with EIP3541 reserved byte '0xEF'."
65
- )
66
- else :
67
- if cls .logger :
68
- cls .logger .debug2 (
69
- "SETTING CODE: %s -> length: %s | hash: %s" ,
70
- encode_hex (message .storage_address ),
71
- len (contract_code ),
72
- encode_hex (keccak (contract_code ))
73
- )
74
-
75
- state .set_code (message .storage_address , contract_code )
76
- state .commit (snapshot )
77
- else :
78
- state .commit (snapshot )
79
- return computation
18
+ def validate_new_contract_code (cls , contract_code : bytes ) -> None :
19
+ if contract_code [:1 ] == EIP3541_RESERVED_STARTING_BYTE :
20
+ raise ReservedBytesInCode (
21
+ "Contract code begins with EIP3541 reserved byte '0xEF'."
22
+ )
0 commit comments