Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
69e2ee2
refactor: rename jumpdest gas cost
LouisTsai-Csie Jan 8, 2026
7168a94
refactor: rename base gas cost
LouisTsai-Csie Jan 8, 2026
96b4b81
refactor: rename very low gas cost
LouisTsai-Csie Jan 8, 2026
322cf6a
refactor: rename memory gas cost
LouisTsai-Csie Jan 8, 2026
b3fc3c4
refactor: rename copy gas cost
LouisTsai-Csie Jan 8, 2026
a384407
refactor: rename low gas cost
LouisTsai-Csie Jan 8, 2026
7fd492e
refactor: rename medium gas cost
LouisTsai-Csie Jan 8, 2026
a2477b2
refactor: rename high gas cost
LouisTsai-Csie Jan 8, 2026
f734ff6
refactor: rename warm access gas cost
LouisTsai-Csie Jan 8, 2026
c3b2411
refactor: rename cold access gas cost
LouisTsai-Csie Jan 8, 2026
e3e1b02
refactor: rename storage reset gas cost
LouisTsai-Csie Jan 8, 2026
c4099bb
refactor: rename storage clear gas cost
LouisTsai-Csie Jan 8, 2026
7852c80
refactor: rename storage set gas cost
LouisTsai-Csie Jan 8, 2026
33a90cf
refactor: rename warm account gas cost
LouisTsai-Csie Jan 8, 2026
99b75fe
refactor: rename cold account gas cost
LouisTsai-Csie Jan 8, 2026
d0fa2a4
refactor: rename initcode word gas cost
LouisTsai-Csie Jan 8, 2026
4b11689
refactor: rename code deposit gas cost
LouisTsai-Csie Jan 8, 2026
60d16b6
refactor: rename create gas cost
LouisTsai-Csie Jan 8, 2026
678c369
refactor: rename call stipen gas cost
LouisTsai-Csie Jan 8, 2026
fa4984e
refactor: rename selfdestruct gas cost
LouisTsai-Csie Jan 8, 2026
a6b13b0
refactor: rename call value gas cost
LouisTsai-Csie Jan 8, 2026
57278e0
refactor: rename new account gas cost
LouisTsai-Csie Jan 8, 2026
0f97654
refactor: rename exp gas cost
LouisTsai-Csie Jan 8, 2026
6e61533
refactor: rename exp per byte gas cost
LouisTsai-Csie Jan 8, 2026
fbf692b
refactor: rename keccak256 gas cost
LouisTsai-Csie Jan 8, 2026
f9e20ca
refactor: rename keccak256 word gas cost
LouisTsai-Csie Jan 8, 2026
67153d2
refactor: rename blockhash gas cost
LouisTsai-Csie Jan 8, 2026
c0867de
refactor: rename log data gas cost
LouisTsai-Csie Jan 8, 2026
84ddb0f
refactor: rename log gas cost
LouisTsai-Csie Jan 8, 2026
c09c1bc
refactor: rename log topic gas cost
LouisTsai-Csie Jan 8, 2026
332beae
refactor: rename tx based gas cost
LouisTsai-Csie Jan 8, 2026
bc3085c
refactor: rename contract creation gas cost
LouisTsai-Csie Jan 8, 2026
add2709
refactor: rename access list addr gas cost
LouisTsai-Csie Jan 8, 2026
d2104af
refactor: rename access list storage gas cost
LouisTsai-Csie Jan 8, 2026
17b4030
refactor: rename floor calldata gas cost
LouisTsai-Csie Jan 8, 2026
23d155c
refactor: rename token standard gas cost
LouisTsai-Csie Jan 8, 2026
df4076e
refactor: rename authorize gas cost
LouisTsai-Csie Jan 8, 2026
e64bc5c
refactor: rename authorize base cost
LouisTsai-Csie Jan 8, 2026
2633970
refactor: rename data zero gas cost
LouisTsai-Csie Jan 8, 2026
a3c5241
refactor: rename non-zero data gas cost
LouisTsai-Csie Jan 8, 2026
526452d
fix: linting issue
LouisTsai-Csie Jan 8, 2026
f184145
refactor: rename blob gas per block gas cost
LouisTsai-Csie Jan 13, 2026
a85871d
refactor: rename blob min price gas cost
LouisTsai-Csie Jan 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/writing_tests/fork_methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_some_feature(fork):

```python
def test_transaction_gas(fork, state_test):
gas_cost = fork.gas_costs(block_number=0, timestamp=0).G_TRANSACTION
gas_cost = fork.gas_costs(block_number=0, timestamp=0).TX_BASE_COST

# Create a transaction with the correct gas parameters for this fork
tx = Transaction(
Expand Down
133 changes: 68 additions & 65 deletions packages/testing/src/execution_testing/forks/forks/forks.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,46 +115,45 @@ def gas_costs(
"""
del block_number, timestamp
return GasCosts(
G_JUMPDEST=1,
G_BASE=2,
G_VERY_LOW=3,
G_LOW=5,
G_MID=8,
G_HIGH=10,
G_WARM_ACCOUNT_ACCESS=100,
G_COLD_ACCOUNT_ACCESS=2_600,
G_ACCESS_LIST_ADDRESS=2_400,
G_ACCESS_LIST_STORAGE=1_900,
G_WARM_SLOAD=100,
G_COLD_SLOAD=2_100,
G_STORAGE_SET=20_000,
G_STORAGE_RESET=2_900,
R_STORAGE_CLEAR=4_800,
G_SELF_DESTRUCT=5_000,
G_CREATE=32_000,
G_CODE_DEPOSIT_BYTE=200,
G_INITCODE_WORD=2,
G_CALL_VALUE=9_000,
G_CALL_STIPEND=2_300,
G_NEW_ACCOUNT=25_000,
G_EXP=10,
G_EXP_BYTE=50,
G_MEMORY=3,
G_TX_DATA_ZERO=4,
G_TX_DATA_NON_ZERO=68,
G_TX_DATA_STANDARD_TOKEN_COST=0,
G_TX_DATA_FLOOR_TOKEN_COST=0,
G_TRANSACTION=21_000,
G_TRANSACTION_CREATE=32_000,
G_LOG=375,
G_LOG_DATA=8,
G_LOG_TOPIC=375,
G_KECCAK_256=30,
G_KECCAK_256_WORD=6,
G_COPY=3,
G_BLOCKHASH=20,
G_AUTHORIZATION=0,
R_AUTHORIZATION_EXISTING_AUTHORITY=0,
GAS_JUMPDEST=1,
GAS_BASE=2,
GAS_VERY_LOW=3,
GAS_LOW=5,
GAS_MID=8,
GAS_HIGH=10,
GAS_WARM_ACCESS=100,
GAS_COLD_ACCOUNT_ACCESS=2_600,
TX_ACCESS_LIST_ADDRESS_COST=2_400,
TX_ACCESS_LIST_STORAGE_KEY_COST=1_900,
GAS_COLD_SLOAD=2_100,
GAS_STORAGE_SET=20_000,
GAS_STORAGE_UPDATE=2_900,
GAS_STORAGE_CLEAR_REFUND=4_800,
GAS_SELF_DESTRUCT=5_000,
GAS_CREATE=32_000,
GAS_CODE_DEPOSIT=200,
GAS_INIT_CODE_WORD_COST=2,
GAS_CALL_VALUE=9_000,
GAS_CALL_STIPEND=2_300,
GAS_NEW_ACCOUNT=25_000,
GAS_EXPONENTIATION=10,
GAS_EXPONENTIATION_PER_BYTE=50,
GAS_MEMORY=3,
TX_DATA_COST_PER_ZERO=4,
TX_DATA_COST_PER_NON_ZERO=68,
STANDARD_CALLDATA_TOKEN_COST=0,
FLOOR_CALLDATA_COST=0,
TX_BASE_COST=21_000,
TX_CREATE_COST=32_000,
GAS_LOG=375,
GAS_LOG_DATA=8,
GAS_LOG_TOPIC=375,
GAS_KECCAK256=30,
GAS_KECCAK256_WORD=6,
GAS_COPY=3,
GAS_BLOCK_HASH=20,
PER_EMPTY_ACCOUNT_COST=0,
PER_AUTH_BASE_COST=0,
)

@classmethod
Expand All @@ -176,7 +175,7 @@ def fn(*, new_bytes: int, previous_bytes: int = 0) -> int:
previous_words = ceiling_division(previous_bytes, 32)

def c(w: int) -> int:
return (gas_costs.G_MEMORY * w) + ((w * w) // 512)
return (gas_costs.GAS_MEMORY * w) + ((w * w) // 512)

return c(new_words) - c(previous_words)

Expand All @@ -200,9 +199,9 @@ def fn(*, data: BytesConvertible, floor: bool = False) -> int:
cost = 0
for b in Bytes(data):
if b == 0:
cost += gas_costs.G_TX_DATA_ZERO
cost += gas_costs.TX_DATA_COST_PER_ZERO
else:
cost += gas_costs.G_TX_DATA_NON_ZERO
cost += gas_costs.TX_DATA_COST_PER_NON_ZERO
return cost

return fn
Expand Down Expand Up @@ -295,11 +294,12 @@ def fn(
f"Authorizations are not supported in {cls.name()}"
)

intrinsic_cost: int = gas_costs.G_TRANSACTION
intrinsic_cost: int = gas_costs.TX_BASE_COST

if contract_creation:
intrinsic_cost += gas_costs.G_INITCODE_WORD * ceiling_division(
len(Bytes(calldata)), 32
intrinsic_cost += (
gas_costs.GAS_INIT_CODE_WORD_COST
* ceiling_division(len(Bytes(calldata)), 32)
)

return intrinsic_cost + calldata_gas_calculator(data=calldata)
Expand Down Expand Up @@ -918,7 +918,7 @@ def fn(
authorization_list_or_count=authorization_list_or_count,
)
if contract_creation:
intrinsic_cost += gas_costs.G_TRANSACTION_CREATE
intrinsic_cost += gas_costs.TX_CREATE_COST
return intrinsic_cost

return fn
Expand Down Expand Up @@ -1103,7 +1103,7 @@ def gas_costs(
super(Istanbul, cls).gas_costs(
block_number=block_number, timestamp=timestamp
),
G_TX_DATA_NON_ZERO=16, # https://eips.ethereum.org/EIPS/eip-2028
TX_DATA_COST_PER_NON_ZERO=16, # https://eips.ethereum.org/EIPS/eip-2028
# https://eips.ethereum.org/EIPS/eip-1108
G_PRECOMPILE_ECADD=150,
G_PRECOMPILE_ECMUL=6000,
Expand Down Expand Up @@ -1172,9 +1172,11 @@ def fn(
)
if access_list is not None:
for access in access_list:
intrinsic_cost += gas_costs.G_ACCESS_LIST_ADDRESS
intrinsic_cost += gas_costs.TX_ACCESS_LIST_ADDRESS_COST
for _ in access.storage_keys:
intrinsic_cost += gas_costs.G_ACCESS_LIST_STORAGE
intrinsic_cost += (
gas_costs.TX_ACCESS_LIST_STORAGE_KEY_COST
)
return intrinsic_cost

return fn
Expand Down Expand Up @@ -1556,7 +1558,7 @@ def excess_blob_gas_calculator(
blob_gas_per_blob = cls.blob_gas_per_blob(
block_number=block_number, timestamp=timestamp
)
target_blob_gas_per_block = target_blobs_per_block * blob_gas_per_blob
blob_target_gas_per_block = target_blobs_per_block * blob_gas_per_blob

def fn(
*,
Expand All @@ -1583,14 +1585,14 @@ def fn(
parent_blob_gas_used = parent_blob_count * blob_gas_per_blob
if (
parent_excess_blob_gas + parent_blob_gas_used
< target_blob_gas_per_block
< blob_target_gas_per_block
):
return 0
else:
return (
parent_excess_blob_gas
+ parent_blob_gas_used
- target_blob_gas_per_block
- blob_target_gas_per_block
)

return fn
Expand Down Expand Up @@ -1818,7 +1820,7 @@ class Prague(Cancun):
"MAX_BLOBS_PER_BLOCK": 9, # but overwrite or add these
"TARGET_BLOBS_PER_BLOCK": 6,
"MAX_BLOB_GAS_PER_BLOCK": 1179648,
"TARGET_BLOB_GAS_PER_BLOCK": 786432,
"BLOB_TARGET_GAS_PER_BLOCK": 786432,
"BLOB_BASE_FEE_UPDATE_FRACTION": 5007716,
}

Expand Down Expand Up @@ -1870,10 +1872,10 @@ def gas_costs(
super(Prague, cls).gas_costs(
block_number=block_number, timestamp=timestamp
),
G_TX_DATA_STANDARD_TOKEN_COST=4, # https://eips.ethereum.org/EIPS/eip-7623
G_TX_DATA_FLOOR_TOKEN_COST=10,
G_AUTHORIZATION=25_000,
R_AUTHORIZATION_EXISTING_AUTHORITY=12_500,
STANDARD_CALLDATA_TOKEN_COST=4, # https://eips.ethereum.org/EIPS/eip-7623
FLOOR_CALLDATA_COST=10,
PER_EMPTY_ACCOUNT_COST=25_000,
PER_AUTH_BASE_COST=12_500,
)

@classmethod
Expand Down Expand Up @@ -1936,8 +1938,8 @@ def fn(*, data: BytesConvertible, floor: bool = False) -> int:
else:
tokens += 4
if floor:
return tokens * gas_costs.G_TX_DATA_FLOOR_TOKEN_COST
return tokens * gas_costs.G_TX_DATA_STANDARD_TOKEN_COST
return tokens * gas_costs.FLOOR_CALLDATA_COST
return tokens * gas_costs.STANDARD_CALLDATA_TOKEN_COST

return fn

Expand All @@ -1959,7 +1961,7 @@ def transaction_data_floor_cost_calculator(
def fn(*, data: BytesConvertible) -> int:
return (
calldata_gas_calculator(data=data, floor=True)
+ gas_costs.G_TRANSACTION
+ gas_costs.TX_BASE_COST
)

return fn
Expand Down Expand Up @@ -2004,7 +2006,8 @@ def fn(
authorization_list_or_count
)
intrinsic_cost += (
authorization_list_or_count * gas_costs.G_AUTHORIZATION
authorization_list_or_count
* gas_costs.PER_EMPTY_ACCOUNT_COST
)

if return_cost_deducted_prior_execution:
Expand Down Expand Up @@ -2257,7 +2260,7 @@ def excess_blob_gas_calculator(
blob_gas_per_blob = cls.blob_gas_per_blob(
block_number=block_number, timestamp=timestamp
)
target_blob_gas_per_block = target_blobs_per_block * blob_gas_per_blob
blob_target_gas_per_block = target_blobs_per_block * blob_gas_per_blob
max_blobs_per_block = cls.max_blobs_per_block(
block_number=block_number, timestamp=timestamp
)
Expand Down Expand Up @@ -2285,7 +2288,7 @@ def fn(
parent_blob_gas_used = parent_blob_count * blob_gas_per_blob
if (
parent_excess_blob_gas + parent_blob_gas_used
< target_blob_gas_per_block
< blob_target_gas_per_block
):
return 0

Expand All @@ -2310,7 +2313,7 @@ def fn(
return (
parent_excess_blob_gas
+ parent_blob_gas_used
- target_blob_gas_per_block
- blob_target_gas_per_block
)

return fn
Expand Down
79 changes: 39 additions & 40 deletions packages/testing/src/execution_testing/forks/gas_costs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,57 +7,56 @@
class GasCosts:
"""Class that contains the gas cost constants for any fork."""

G_JUMPDEST: int
G_BASE: int
G_VERY_LOW: int
G_LOW: int
G_MID: int
G_HIGH: int
G_WARM_ACCOUNT_ACCESS: int
G_COLD_ACCOUNT_ACCESS: int
G_ACCESS_LIST_ADDRESS: int
G_ACCESS_LIST_STORAGE: int
G_WARM_SLOAD: int
G_COLD_SLOAD: int
G_STORAGE_SET: int
G_STORAGE_RESET: int
GAS_JUMPDEST: int
GAS_BASE: int
GAS_VERY_LOW: int
GAS_LOW: int
GAS_MID: int
GAS_HIGH: int
GAS_COLD_ACCOUNT_ACCESS: int
TX_ACCESS_LIST_ADDRESS_COST: int
TX_ACCESS_LIST_STORAGE_KEY_COST: int
GAS_WARM_ACCESS: int
GAS_COLD_SLOAD: int
GAS_STORAGE_SET: int
GAS_STORAGE_UPDATE: int

R_STORAGE_CLEAR: int
GAS_STORAGE_CLEAR_REFUND: int

G_SELF_DESTRUCT: int
G_CREATE: int
GAS_SELF_DESTRUCT: int
GAS_CREATE: int

G_CODE_DEPOSIT_BYTE: int
G_INITCODE_WORD: int
GAS_CODE_DEPOSIT: int
GAS_INIT_CODE_WORD_COST: int

G_CALL_VALUE: int
G_CALL_STIPEND: int
G_NEW_ACCOUNT: int
GAS_CALL_VALUE: int
GAS_CALL_STIPEND: int
GAS_NEW_ACCOUNT: int

G_EXP: int
G_EXP_BYTE: int
GAS_EXPONENTIATION: int
GAS_EXPONENTIATION_PER_BYTE: int

G_MEMORY: int
GAS_MEMORY: int

G_TX_DATA_ZERO: int
G_TX_DATA_NON_ZERO: int
G_TX_DATA_STANDARD_TOKEN_COST: int
G_TX_DATA_FLOOR_TOKEN_COST: int
TX_DATA_COST_PER_ZERO: int
TX_DATA_COST_PER_NON_ZERO: int
STANDARD_CALLDATA_TOKEN_COST: int
FLOOR_CALLDATA_COST: int

G_TRANSACTION: int
G_TRANSACTION_CREATE: int
TX_BASE_COST: int
TX_CREATE_COST: int

G_LOG: int
G_LOG_DATA: int
G_LOG_TOPIC: int
GAS_LOG: int
GAS_LOG_DATA: int
GAS_LOG_TOPIC: int

G_KECCAK_256: int
G_KECCAK_256_WORD: int
GAS_KECCAK256: int
GAS_KECCAK256_WORD: int

G_COPY: int
G_BLOCKHASH: int
GAS_COPY: int
GAS_BLOCK_HASH: int

G_AUTHORIZATION: int
PER_EMPTY_ACCOUNT_COST: int

# Precompiled contract gas constants

Expand All @@ -68,4 +67,4 @@ class GasCosts:

# Refund constants

R_AUTHORIZATION_EXISTING_AUTHORITY: int
PER_AUTH_BASE_COST: int
2 changes: 1 addition & 1 deletion packages/testing/src/execution_testing/specs/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def _generate_blockchain_genesis_environment(self) -> Environment:
# context (block header) where the transaction is executed. In a
# blockchain test, we need to indirectly set the excess blob gas by
# setting the excess blob gas of the genesis block to the expected
# value plus the TARGET_BLOB_GAS_PER_BLOCK, which is the value that
# value plus the BLOB_TARGET_GAS_PER_BLOCK, which is the value that
# will be subtracted from the excess blob gas when the first block
# is mined.
kwargs["excess_blob_gas"] = self.env.excess_blob_gas + (
Expand Down
Loading
Loading