Skip to content

Commit f83131f

Browse files
committed
fix(rebase): align EIP-8037 with forks/amsterdam GasCosts refactor
Adapt EIP-8037 to forks/amsterdam's module-level-to-GasCosts refactor: rename GAS_X → GasCosts.X in 8037 files, with remappings: GAS_STORAGE_UPDATE → GasCosts.COLD_STORAGE_WRITE GAS_KECCAK256_PER_WORD → GasCosts.OPCODE_KECCACK256_PER_WORD GAS_SELF_DESTRUCT → GasCosts.OPCODE_SELFDESTRUCT_BASE GAS_CREATE → GasCosts.OPCODE_CREATE_BASE GAS_MEMORY → GasCosts.MEMORY_PER_WORD Tests: 977 pass.
1 parent f2049fb commit f83131f

27 files changed

Lines changed: 216 additions & 309 deletions

File tree

packages/testing/src/execution_testing/forks/forks/eips/amsterdam/eip_8037.py

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def code_deposit_state_gas(cls, *, code_size: int) -> int:
5959
def create_state_gas(cls, *, code_size: int = 0) -> int:
6060
"""Return total state gas for CREATE (EIP-8037)."""
6161
gas_costs = cls.gas_costs()
62-
return gas_costs.GAS_NEW_ACCOUNT + cls.code_deposit_state_gas(
62+
return gas_costs.NEW_ACCOUNT + cls.code_deposit_state_gas(
6363
code_size=code_size
6464
)
6565

@@ -82,17 +82,17 @@ def gas_costs(cls) -> GasCosts:
8282
return replace(
8383
parent,
8484
# EIP-7928: block access list item cost
85-
GAS_BLOCK_ACCESS_LIST_ITEM=2000,
85+
BLOCK_ACCESS_LIST_ITEM=2000,
8686
# EIP-8037: state gas folded into totals
87-
GAS_STORAGE_SET=(
88-
parent.GAS_COLD_STORAGE_WRITE
89-
- parent.GAS_COLD_STORAGE_ACCESS
87+
STORAGE_SET=(
88+
parent.COLD_STORAGE_WRITE
89+
- parent.COLD_STORAGE_ACCESS
9090
+ STATE_BYTES_PER_STORAGE_SET * cpsb
9191
),
92-
GAS_NEW_ACCOUNT=new_acct,
93-
GAS_CREATE=REGULAR_GAS_CREATE + new_acct,
94-
GAS_TX_CREATE=(REGULAR_GAS_CREATE + new_acct),
95-
GAS_AUTH_PER_EMPTY_ACCOUNT=(
92+
NEW_ACCOUNT=new_acct,
93+
OPCODE_CREATE_BASE=REGULAR_GAS_CREATE + new_acct,
94+
TX_CREATE=(REGULAR_GAS_CREATE + new_acct),
95+
AUTH_PER_EMPTY_ACCOUNT=(
9696
PER_AUTH_BASE_COST
9797
+ (STATE_BYTES_PER_NEW_ACCOUNT + STATE_BYTES_PER_AUTH_BASE)
9898
* cpsb
@@ -290,17 +290,14 @@ def _calculate_sstore_gas(
290290
current_value = original_value
291291
new_value = metadata["new_value"]
292292

293-
gas_cost = (
294-
0 if metadata["key_warm"] else gas_costs.GAS_COLD_STORAGE_ACCESS
295-
)
293+
gas_cost = 0 if metadata["key_warm"] else gas_costs.COLD_STORAGE_ACCESS
296294

297295
if original_value == current_value and current_value != new_value:
298296
gas_cost += (
299-
gas_costs.GAS_COLD_STORAGE_WRITE
300-
- gas_costs.GAS_COLD_STORAGE_ACCESS
297+
gas_costs.COLD_STORAGE_WRITE - gas_costs.COLD_STORAGE_ACCESS
301298
)
302299
else:
303-
gas_cost += gas_costs.GAS_WARM_SLOAD
300+
gas_cost += gas_costs.WARM_SLOAD
304301

305302
return gas_cost
306303

@@ -356,9 +353,9 @@ def _calculate_sstore_refund(
356353

357354
if original_value == new_value:
358355
refund += (
359-
gas_costs.GAS_COLD_STORAGE_WRITE
360-
- gas_costs.GAS_COLD_STORAGE_ACCESS
361-
- gas_costs.GAS_WARM_SLOAD
356+
gas_costs.COLD_STORAGE_WRITE
357+
- gas_costs.COLD_STORAGE_ACCESS
358+
- gas_costs.WARM_SLOAD
362359
)
363360

364361
return refund
@@ -404,7 +401,7 @@ def _calculate_return_gas(
404401
code_deposit_size = metadata["code_deposit_size"]
405402
if code_deposit_size > 0:
406403
code_words = (code_deposit_size + 31) // 32
407-
hash_gas = gas_costs.GAS_KECCAK256_PER_WORD * code_words
404+
hash_gas = gas_costs.OPCODE_KECCACK256_PER_WORD * code_words
408405
return hash_gas
409406
return 0
410407

src/ethereum/forks/amsterdam/fork.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,9 @@
9797
from .vm import Message
9898
from .vm.eoa_delegation import is_valid_delegation
9999
from .vm.gas import (
100-
BLOB_SCHEDULE_MAX,
101-
GAS_PER_BLOB,
102100
STATE_BYTES_PER_NEW_ACCOUNT,
103101
STATE_BYTES_PER_STORAGE_SET,
102+
GasCosts,
104103
calculate_blob_gas_price,
105104
calculate_data_fee,
106105
calculate_excess_blob_gas,

src/ethereum/forks/amsterdam/transactions.py

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -27,43 +27,6 @@
2727
)
2828
from .fork_types import Authorization, VersionedHash
2929

30-
GAS_TX_BASE = Uint(21000)
31-
"""
32-
Base cost of a transaction in gas units. This is the minimum amount of gas
33-
required to execute a transaction.
34-
"""
35-
36-
GAS_TX_DATA_TOKEN_FLOOR = Uint(10)
37-
"""
38-
Minimum gas cost per byte of calldata as per [EIP-7623]. Used to calculate
39-
the minimum gas cost for transactions that include calldata.
40-
41-
[EIP-7623]: https://eips.ethereum.org/EIPS/eip-7623
42-
"""
43-
44-
GAS_TX_DATA_TOKEN_STANDARD = Uint(4)
45-
"""
46-
Gas cost per byte of calldata as per [EIP-7623]. Used to calculate the
47-
gas cost for transactions that include calldata.
48-
49-
[EIP-7623]: https://eips.ethereum.org/EIPS/eip-7623
50-
"""
51-
52-
GAS_TX_CREATE = Uint(32000)
53-
"""
54-
Additional gas cost for creating a new contract.
55-
"""
56-
57-
GAS_TX_ACCESS_LIST_ADDRESS = Uint(2400)
58-
"""
59-
Gas cost for including an address in the access list of a transaction.
60-
"""
61-
62-
GAS_TX_ACCESS_LIST_STORAGE_KEY = Uint(1900)
63-
"""
64-
Gas cost for including a storage key in the access list of a transaction.
65-
"""
66-
6730

6831
@dataclass
6932
class IntrinsicGasCost:
@@ -648,6 +611,7 @@ def calculate_intrinsic_cost(
648611
REGULAR_GAS_CREATE,
649612
STATE_BYTES_PER_AUTH_BASE,
650613
STATE_BYTES_PER_NEW_ACCOUNT,
614+
GasCosts,
651615
init_code_cost,
652616
state_gas_per_byte,
653617
)
@@ -668,13 +632,13 @@ def calculate_intrinsic_cost(
668632
tokens_in_access_list = Uint(0)
669633
if has_access_list(tx):
670634
for access in tx.access_list:
671-
access_list_gas += GAS_TX_ACCESS_LIST_ADDRESS
635+
access_list_gas += GasCosts.TX_ACCESS_LIST_ADDRESS
672636
access_list_gas += (
673-
ulen(access.slots) * GAS_TX_ACCESS_LIST_STORAGE_KEY
637+
ulen(access.slots) * GasCosts.TX_ACCESS_LIST_STORAGE_KEY
674638
)
675639

676640
# Data token floor cost for access list bytes.
677-
access_list_gas += tokens_in_access_list * GAS_TX_DATA_TOKEN_FLOOR
641+
access_list_gas += tokens_in_access_list * GasCosts.TX_DATA_TOKEN_FLOOR
678642

679643
auth_regular_gas = Uint(0)
680644
auth_state_gas = Uint(0)
@@ -698,7 +662,7 @@ def calculate_intrinsic_cost(
698662
)
699663

700664
intrinsic_regular_gas = (
701-
GAS_TX_BASE
665+
GasCosts.TX_BASE
702666
+ data_cost
703667
+ create_regular_gas
704668
+ access_list_gas

src/ethereum/forks/amsterdam/vm/eoa_delegation.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@
2222
)
2323
from ..utils.hexadecimal import hex_to_address
2424
from ..vm.gas import (
25-
GAS_COLD_ACCOUNT_ACCESS,
26-
GAS_WARM_ACCESS,
2725
STATE_BYTES_PER_NEW_ACCOUNT,
26+
GasCosts,
2827
state_gas_per_byte,
2928
)
3029
from . import Evm, Message

src/ethereum/forks/amsterdam/vm/gas.py

Lines changed: 18 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -25,56 +25,11 @@
2525
from . import Evm
2626
from .exceptions import OutOfGasError
2727

28-
GAS_JUMPDEST = Uint(1)
29-
GAS_BASE = Uint(2)
30-
GAS_VERY_LOW = Uint(3)
31-
GAS_STORAGE_UPDATE = Uint(5000)
32-
REFUND_STORAGE_CLEAR = 4800
33-
GAS_LOW = Uint(5)
34-
GAS_MID = Uint(8)
35-
GAS_HIGH = Uint(10)
36-
GAS_EXPONENTIATION = Uint(10)
37-
GAS_EXPONENTIATION_PER_BYTE = Uint(50)
38-
GAS_MEMORY = Uint(3)
39-
GAS_KECCAK256 = Uint(30)
40-
GAS_KECCAK256_PER_WORD = Uint(6)
41-
GAS_COPY = Uint(3)
42-
GAS_BLOCK_HASH = Uint(20)
43-
GAS_LOG = Uint(375)
44-
GAS_LOG_DATA_PER_BYTE = Uint(8)
45-
GAS_LOG_TOPIC = Uint(375)
46-
GAS_ZERO = Uint(0)
47-
GAS_CALL_VALUE = Uint(9000)
48-
GAS_CALL_STIPEND = Uint(2300)
49-
GAS_SELF_DESTRUCT = Uint(5000)
50-
GAS_PRECOMPILE_ECRECOVER = Uint(3000)
51-
GAS_PRECOMPILE_P256VERIFY = Uint(6900)
52-
GAS_PRECOMPILE_SHA256_BASE = Uint(60)
53-
GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12)
54-
GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600)
55-
GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120)
56-
GAS_PRECOMPILE_IDENTITY_BASE = Uint(15)
57-
GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3)
58-
GAS_RETURN_DATA_COPY = Uint(3)
59-
GAS_FAST_STEP = Uint(5)
60-
GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1)
61-
GAS_COLD_STORAGE_ACCESS = Uint(2100)
62-
GAS_COLD_ACCOUNT_ACCESS = Uint(2600)
63-
GAS_WARM_ACCESS = Uint(100)
64-
GAS_CODE_INIT_PER_WORD = Uint(2)
65-
GAS_BLOBHASH_OPCODE = Uint(3)
66-
GAS_PRECOMPILE_POINT_EVALUATION = Uint(50000)
67-
68-
# These values may be patched at runtime by a future gas repricing utility
69-
class GasCosts:
70-
"""
71-
Constant gas values for the EVM.
72-
"""
73-
74-
TARGET_STATE_GROWTH_PER_YEAR = Uint(100 * 1024**3) # noqa: F841
75-
BLOCKS_PER_YEAR = Uint(2_628_000) # noqa: F841
76-
COST_PER_STATE_BYTE_SIGNIFICANT_BITS = Uint(5) # noqa: F841
77-
COST_PER_STATE_BYTE_OFFSET = Uint(9578) # noqa: F841
28+
# EIP-8037 state gas accounting constants
29+
TARGET_STATE_GROWTH_PER_YEAR = Uint(100 * 1024**3)
30+
BLOCKS_PER_YEAR = Uint(2_628_000)
31+
COST_PER_STATE_BYTE_SIGNIFICANT_BITS = Uint(5)
32+
COST_PER_STATE_BYTE_OFFSET = Uint(9578)
7833

7934
STATE_BYTES_PER_NEW_ACCOUNT = Uint(112)
8035
STATE_BYTES_PER_STORAGE_SET = Uint(32)
@@ -84,12 +39,19 @@ class GasCosts:
8439

8540
REGULAR_GAS_CREATE = Uint(9000)
8641

87-
GAS_PRECOMPILE_BLS_G1ADD = Uint(375)
88-
GAS_PRECOMPILE_BLS_G1MUL = Uint(12000)
89-
GAS_PRECOMPILE_BLS_G1MAP = Uint(5500)
90-
GAS_PRECOMPILE_BLS_G2ADD = Uint(600)
91-
GAS_PRECOMPILE_BLS_G2MUL = Uint(22500)
92-
GAS_PRECOMPILE_BLS_G2MAP = Uint(23800)
42+
43+
# These values may be patched at runtime by a future gas repricing utility
44+
class GasCosts:
45+
"""
46+
Constant gas values for the EVM.
47+
"""
48+
49+
# Tiers
50+
BASE = Uint(2)
51+
VERY_LOW = Uint(3)
52+
LOW = Uint(5)
53+
MID = Uint(8)
54+
HIGH = Uint(10)
9355

9456
# Access
9557
WARM_ACCESS = Uint(100)

src/ethereum/forks/amsterdam/vm/instructions/storage.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,8 @@
2323
from .. import Evm, credit_state_gas_refund
2424
from ..exceptions import WriteInStaticContext
2525
from ..gas import (
26-
GAS_CALL_STIPEND,
27-
GAS_COLD_STORAGE_ACCESS,
28-
GAS_STORAGE_UPDATE,
29-
GAS_WARM_ACCESS,
30-
REFUND_STORAGE_CLEAR,
3126
STATE_BYTES_PER_STORAGE_SET,
27+
GasCosts,
3228
charge_gas,
3329
charge_state_gas,
3430
check_gas,
@@ -110,7 +106,7 @@ def sstore(evm: Evm) -> None:
110106
needs_state_gas = True
111107
# charge regular cost for the operation, even when we
112108
# already charge state gas for state creation
113-
gas_cost += GAS_STORAGE_UPDATE - GAS_COLD_STORAGE_ACCESS
109+
gas_cost += GasCosts.COLD_STORAGE_WRITE - GasCosts.COLD_STORAGE_ACCESS
114110
else:
115111
gas_cost += GasCosts.WARM_ACCESS
116112

@@ -130,7 +126,9 @@ def sstore(evm: Evm) -> None:
130126
# Slot set then cleared: refund the state gas charge.
131127
credit_state_gas_refund(evm, state_gas_storage_set)
132128
evm.refund_counter += int(
133-
GAS_STORAGE_UPDATE - GAS_COLD_STORAGE_ACCESS - GAS_WARM_ACCESS
129+
GasCosts.COLD_STORAGE_WRITE
130+
- GasCosts.COLD_STORAGE_ACCESS
131+
- GasCosts.WARM_ACCESS
134132
)
135133

136134
# Charge regular gas before state gas so that a regular-gas OOG

src/ethereum/forks/amsterdam/vm/instructions/system.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,9 @@
4444
)
4545
from ..exceptions import OutOfGasError, Revert, WriteInStaticContext
4646
from ..gas import (
47-
GAS_CALL_VALUE,
48-
GAS_COLD_ACCOUNT_ACCESS,
49-
GAS_KECCAK256_PER_WORD,
50-
GAS_SELF_DESTRUCT,
51-
GAS_WARM_ACCESS,
52-
GAS_ZERO,
5347
REGULAR_GAS_CREATE,
5448
STATE_BYTES_PER_NEW_ACCOUNT,
49+
GasCosts,
5550
calculate_gas_extend_memory,
5651
calculate_message_call_gas,
5752
charge_gas,
@@ -253,7 +248,7 @@ def create2(evm: Evm) -> None:
253248
charge_gas(
254249
evm,
255250
REGULAR_GAS_CREATE
256-
+ GAS_KECCAK256_PER_WORD * call_data_words
251+
+ GasCosts.OPCODE_KECCACK256_PER_WORD * call_data_words
257252
+ extend_memory.cost
258253
+ init_code_gas,
259254
)

src/ethereum/forks/amsterdam/vm/interpreter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
from ..vm import Message
4949
from ..vm.eoa_delegation import get_delegated_code_address, set_delegation
5050
from ..vm.gas import (
51-
GAS_KECCAK256_PER_WORD,
51+
GasCosts,
5252
charge_gas,
5353
charge_state_gas,
5454
state_gas_per_byte,
@@ -225,7 +225,7 @@ def process_create_message(message: Message) -> Evm:
225225
raise OutOfGasError
226226
# Hash cost for computing keccak256 of deployed bytecode
227227
code_hash_gas = (
228-
GAS_KECCAK256_PER_WORD
228+
GasCosts.OPCODE_KECCACK256_PER_WORD
229229
* ceil32(Uint(len(contract_code)))
230230
// Uint(32)
231231
)

0 commit comments

Comments
 (0)