1919from ....base_fork import BaseFork
2020from ....gas_costs import GasCosts
2121
22+ # EIP-8037 state byte sizes (mirrors EELS amsterdam/vm/gas.py).
23+ STATE_BYTES_PER_NEW_ACCOUNT = 120
24+ STATE_BYTES_PER_STORAGE_SET = 64
25+ STATE_BYTES_PER_AUTH_BASE = 23
26+
27+ # EIP-8037 regular gas base costs.
28+ PER_AUTH_BASE_COST = 7_500
29+ REGULAR_GAS_CREATE = 9_000
30+
2231
2332class EIP8037 (BaseFork ):
2433 """EIP-8037 class."""
@@ -28,12 +37,11 @@ def cost_per_state_byte(cls) -> int:
2837 """
2938 Return the fixed cost per state byte for EIP-8037.
3039 """
31- return 1174
40+ return 1530
3241
3342 @classmethod
3443 def sstore_state_gas (cls ) -> int :
3544 """Return state gas for a zero-to-nonzero SSTORE (EIP-8037)."""
36- STATE_BYTES_PER_STORAGE_SET = 32 # noqa: N806
3745 return STATE_BYTES_PER_STORAGE_SET * cls .cost_per_state_byte ()
3846
3947 @classmethod
@@ -57,13 +65,6 @@ def gas_costs(cls) -> GasCosts:
5765 """
5866 cpsb = cls .cost_per_state_byte ()
5967 parent = super (EIP8037 , cls ).gas_costs ()
60- # EIP-8037 state byte sizes (EELS amsterdam/vm/gas.py)
61- STATE_BYTES_PER_STORAGE_SET = 32 # noqa: N806
62- STATE_BYTES_PER_NEW_ACCOUNT = 112 # noqa: N806
63- STATE_BYTES_PER_AUTH_BASE = 23 # noqa: N806
64- # EIP-8037 regular gas base costs
65- PER_AUTH_BASE_COST = 7_500 # noqa: N806
66- REGULAR_GAS_CREATE = 9_000 # noqa: N806
6768 new_acct = STATE_BYTES_PER_NEW_ACCOUNT * cpsb
6869 return replace (
6970 parent ,
@@ -258,8 +259,6 @@ def transaction_intrinsic_state_gas(
258259 - Auth: (NEW_ACCOUNT + AUTH_BASE) * cpsb
259260 """
260261 cpsb = cls .cost_per_state_byte ()
261- STATE_BYTES_PER_NEW_ACCOUNT = 112 # noqa: N806
262- STATE_BYTES_PER_AUTH_BASE = 23 # noqa: N806
263262 state_gas = 0
264263 if contract_creation :
265264 state_gas += STATE_BYTES_PER_NEW_ACCOUNT * cpsb
@@ -278,7 +277,7 @@ def _calculate_sstore_gas(
278277 Calculate updated SSTORE gas cost.
279278
280279 For 0->nonzero: regular (UPDATE - COLD_SLOAD) + state
281- (32 * cpsb).
280+ (STATE_BYTES_PER_STORAGE_SET * cpsb).
282281 For nonzero->different nonzero: regular
283282 (UPDATE - COLD_SLOAD).
284283 Otherwise: WARM_SLOAD.
@@ -324,7 +323,7 @@ def _calculate_sstore_state_gas(
324323 and current_value != new_value
325324 and original_value == 0
326325 ):
327- return 32 * cpsb
326+ return STATE_BYTES_PER_STORAGE_SET * cpsb
328327 return 0
329328
330329 @classmethod
@@ -368,9 +367,9 @@ def _calculate_sstore_state_refund(
368367 """
369368 Calculate SSTORE state gas refund.
370369
371- Return the state-gas portion (`32 * cpsb`) when a slot that
372- was originally empty is restored back to zero within the
373- transaction; otherwise return 0.
370+ Return the state-gas portion (`STATE_BYTES_PER_STORAGE_SET *
371+ cpsb`) when a slot that was originally empty is restored back
372+ to zero within the transaction; otherwise return 0.
374373 """
375374 del gas_costs
376375 metadata = opcode .metadata
@@ -384,7 +383,7 @@ def _calculate_sstore_state_refund(
384383 if current_value != new_value :
385384 if original_value == new_value :
386385 if original_value == 0 :
387- return 32 * cpsb
386+ return STATE_BYTES_PER_STORAGE_SET * cpsb
388387 return 0
389388
390389 @classmethod
@@ -394,8 +393,9 @@ def _calculate_selfdestruct_state_refund(
394393 """
395394 Calculate SELFDESTRUCT state gas refund.
396395
397- Account creation: 112 × cost_per_state_byte
398- Created storage slots: 32 × cost_per_state_byte per non-zero slot
396+ Account creation: STATE_BYTES_PER_NEW_ACCOUNT × cost_per_state_byte
397+ Created storage slots: STATE_BYTES_PER_STORAGE_SET ×
398+ cost_per_state_byte per non-zero slot
399399 Code deposit: len(code) × cost_per_state_byte
400400 """
401401 del gas_costs
@@ -411,9 +411,11 @@ def _calculate_selfdestruct_state_refund(
411411 ]
412412 state_refund = 0
413413 if self_destructed_account :
414- state_refund = 112 * cpsb
414+ state_refund = STATE_BYTES_PER_NEW_ACCOUNT * cpsb
415415 state_refund += (
416- 32 * cpsb * self_destructed_account_storage_slot_count
416+ STATE_BYTES_PER_STORAGE_SET
417+ * cpsb
418+ * self_destructed_account_storage_slot_count
417419 )
418420 state_refund += cpsb * self_destructed_account_code_deposit
419421 return state_refund
0 commit comments