Skip to content

Commit c5c776e

Browse files
committed
refactor: drop GAS_ prefix for opcode, precompile, and refund consts
1 parent 8f41464 commit c5c776e

174 files changed

Lines changed: 772 additions & 684 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/testing/src/execution_testing/forks/forks/forks.py

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -151,35 +151,35 @@ def gas_costs(cls) -> GasCosts:
151151
GAS_KECCAK256=30,
152152
GAS_KECCAK256_PER_WORD=6,
153153
GAS_COPY=3,
154-
GAS_PRECOMPILE_ECRECOVER=3_000,
155-
GAS_PRECOMPILE_SHA256_BASE=60,
156-
GAS_PRECOMPILE_SHA256_PER_WORD=12,
157-
GAS_PRECOMPILE_RIPEMD160_BASE=600,
158-
GAS_PRECOMPILE_RIPEMD160_PER_WORD=120,
159-
GAS_PRECOMPILE_IDENTITY_BASE=15,
160-
GAS_PRECOMPILE_IDENTITY_PER_WORD=3,
154+
PRECOMPILE_ECRECOVER=3_000,
155+
PRECOMPILE_SHA256_BASE=60,
156+
PRECOMPILE_SHA256_PER_WORD=12,
157+
PRECOMPILE_RIPEMD160_BASE=600,
158+
PRECOMPILE_RIPEMD160_PER_WORD=120,
159+
PRECOMPILE_IDENTITY_BASE=15,
160+
PRECOMPILE_IDENTITY_PER_WORD=3,
161161
# Zero-initialized: introduced in later forks, set via
162162
# replace() in the fork that activates them.
163163
GAS_TX_DATA_TOKEN_STANDARD=0,
164164
GAS_TX_DATA_TOKEN_FLOOR=0,
165165
GAS_AUTH_PER_EMPTY_ACCOUNT=0,
166166
REFUND_AUTH_PER_EXISTING_ACCOUNT=0,
167-
GAS_PRECOMPILE_ECADD=0,
168-
GAS_PRECOMPILE_ECMUL=0,
169-
GAS_PRECOMPILE_ECPAIRING_BASE=0,
170-
GAS_PRECOMPILE_ECPAIRING_PER_POINT=0,
171-
GAS_PRECOMPILE_BLAKE2F_BASE=0,
172-
GAS_PRECOMPILE_BLAKE2F_PER_ROUND=0,
173-
GAS_PRECOMPILE_POINT_EVALUATION=0,
174-
GAS_PRECOMPILE_BLS_G1ADD=0,
175-
GAS_PRECOMPILE_BLS_G1MUL=0,
176-
GAS_PRECOMPILE_BLS_G1MAP=0,
177-
GAS_PRECOMPILE_BLS_G2ADD=0,
178-
GAS_PRECOMPILE_BLS_G2MUL=0,
179-
GAS_PRECOMPILE_BLS_G2MAP=0,
180-
GAS_PRECOMPILE_BLS_PAIRING_BASE=0,
181-
GAS_PRECOMPILE_BLS_PAIRING_PER_PAIR=0,
182-
GAS_PRECOMPILE_P256VERIFY=0,
167+
PRECOMPILE_ECADD=0,
168+
PRECOMPILE_ECMUL=0,
169+
PRECOMPILE_ECPAIRING_BASE=0,
170+
PRECOMPILE_ECPAIRING_PER_POINT=0,
171+
PRECOMPILE_BLAKE2F_BASE=0,
172+
PRECOMPILE_BLAKE2F_PER_ROUND=0,
173+
PRECOMPILE_POINT_EVALUATION=0,
174+
PRECOMPILE_BLS_G1ADD=0,
175+
PRECOMPILE_BLS_G1MUL=0,
176+
PRECOMPILE_BLS_G1MAP=0,
177+
PRECOMPILE_BLS_G2ADD=0,
178+
PRECOMPILE_BLS_G2MUL=0,
179+
PRECOMPILE_BLS_G2MAP=0,
180+
PRECOMPILE_BLS_PAIRING_BASE=0,
181+
PRECOMPILE_BLS_PAIRING_PER_PAIR=0,
182+
PRECOMPILE_P256VERIFY=0,
183183
GAS_BLOCK_ACCESS_LIST_ITEM=0,
184184
# Opcode specific gas constants for repricing
185185
OPCODE_ADD=GAS_VERY_LOW,
@@ -1529,10 +1529,10 @@ def gas_costs(cls) -> GasCosts:
15291529
"""
15301530
return replace(
15311531
super(Byzantium, cls).gas_costs(),
1532-
GAS_PRECOMPILE_ECADD=500,
1533-
GAS_PRECOMPILE_ECMUL=40_000,
1534-
GAS_PRECOMPILE_ECPAIRING_BASE=100_000,
1535-
GAS_PRECOMPILE_ECPAIRING_PER_POINT=80_000,
1532+
PRECOMPILE_ECADD=500,
1533+
PRECOMPILE_ECMUL=40_000,
1534+
PRECOMPILE_ECPAIRING_BASE=100_000,
1535+
PRECOMPILE_ECPAIRING_PER_POINT=80_000,
15361536
OPCODE_RETURNDATACOPY=GAS_VERY_LOW,
15371537
)
15381538

@@ -1659,11 +1659,11 @@ def gas_costs(cls) -> GasCosts:
16591659
super(Istanbul, cls).gas_costs(),
16601660
GAS_TX_DATA_PER_NON_ZERO=16, # https://eips.ethereum.org/EIPS/eip-2028
16611661
# https://eips.ethereum.org/EIPS/eip-1108
1662-
GAS_PRECOMPILE_ECADD=150,
1663-
GAS_PRECOMPILE_ECMUL=6000,
1664-
GAS_PRECOMPILE_ECPAIRING_BASE=45_000,
1665-
GAS_PRECOMPILE_ECPAIRING_PER_POINT=34_000,
1666-
GAS_PRECOMPILE_BLAKE2F_PER_ROUND=1,
1662+
PRECOMPILE_ECADD=150,
1663+
PRECOMPILE_ECMUL=6000,
1664+
PRECOMPILE_ECPAIRING_BASE=45_000,
1665+
PRECOMPILE_ECPAIRING_PER_POINT=34_000,
1666+
PRECOMPILE_BLAKE2F_PER_ROUND=1,
16671667
)
16681668

16691669

@@ -2270,7 +2270,7 @@ def gas_costs(cls) -> GasCosts:
22702270
"""On Cancun, the point evaluation precompile gas cost is set."""
22712271
return replace(
22722272
super(Cancun, cls).gas_costs(),
2273-
GAS_PRECOMPILE_POINT_EVALUATION=50_000,
2273+
PRECOMPILE_POINT_EVALUATION=50_000,
22742274
OPCODE_BLOBHASH=GAS_VERY_LOW,
22752275
OPCODE_MCOPY=GAS_VERY_LOW,
22762276
)
@@ -2373,14 +2373,14 @@ def gas_costs(cls) -> GasCosts:
23732373
GAS_TX_DATA_TOKEN_FLOOR=10,
23742374
GAS_AUTH_PER_EMPTY_ACCOUNT=25_000,
23752375
REFUND_AUTH_PER_EXISTING_ACCOUNT=12_500,
2376-
GAS_PRECOMPILE_BLS_G1ADD=375,
2377-
GAS_PRECOMPILE_BLS_G1MUL=12_000,
2378-
GAS_PRECOMPILE_BLS_G1MAP=5_500,
2379-
GAS_PRECOMPILE_BLS_G2ADD=600,
2380-
GAS_PRECOMPILE_BLS_G2MUL=22_500,
2381-
GAS_PRECOMPILE_BLS_G2MAP=23_800,
2382-
GAS_PRECOMPILE_BLS_PAIRING_BASE=37_700,
2383-
GAS_PRECOMPILE_BLS_PAIRING_PER_PAIR=32_600,
2376+
PRECOMPILE_BLS_G1ADD=375,
2377+
PRECOMPILE_BLS_G1MUL=12_000,
2378+
PRECOMPILE_BLS_G1MAP=5_500,
2379+
PRECOMPILE_BLS_G2ADD=600,
2380+
PRECOMPILE_BLS_G2MUL=22_500,
2381+
PRECOMPILE_BLS_G2MAP=23_800,
2382+
PRECOMPILE_BLS_PAIRING_BASE=37_700,
2383+
PRECOMPILE_BLS_PAIRING_PER_PAIR=32_600,
23842384
OPCODE_CLZ=GAS_LOW,
23852385
)
23862386

@@ -2712,7 +2712,7 @@ def gas_costs(cls) -> GasCosts:
27122712
"""On Osaka, the P256VERIFY precompile gas cost is set."""
27132713
return replace(
27142714
super(Osaka, cls).gas_costs(),
2715-
GAS_PRECOMPILE_P256VERIFY=6_900,
2715+
PRECOMPILE_P256VERIFY=6_900,
27162716
)
27172717

27182718
@classmethod

packages/testing/src/execution_testing/forks/gas_costs.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -61,34 +61,34 @@ class GasCosts:
6161
GAS_AUTH_PER_EMPTY_ACCOUNT: int
6262

6363
# Precompiled contract gas constants
64-
GAS_PRECOMPILE_ECRECOVER: int
65-
GAS_PRECOMPILE_SHA256_BASE: int
66-
GAS_PRECOMPILE_SHA256_PER_WORD: int
67-
GAS_PRECOMPILE_RIPEMD160_BASE: int
68-
GAS_PRECOMPILE_RIPEMD160_PER_WORD: int
69-
GAS_PRECOMPILE_IDENTITY_BASE: int
70-
GAS_PRECOMPILE_IDENTITY_PER_WORD: int
71-
72-
GAS_PRECOMPILE_ECADD: int
73-
GAS_PRECOMPILE_ECMUL: int
74-
GAS_PRECOMPILE_ECPAIRING_BASE: int
75-
GAS_PRECOMPILE_ECPAIRING_PER_POINT: int
76-
77-
GAS_PRECOMPILE_BLAKE2F_BASE: int
78-
GAS_PRECOMPILE_BLAKE2F_PER_ROUND: int
79-
80-
GAS_PRECOMPILE_POINT_EVALUATION: int
81-
82-
GAS_PRECOMPILE_BLS_G1ADD: int
83-
GAS_PRECOMPILE_BLS_G1MUL: int
84-
GAS_PRECOMPILE_BLS_G1MAP: int
85-
GAS_PRECOMPILE_BLS_G2ADD: int
86-
GAS_PRECOMPILE_BLS_G2MUL: int
87-
GAS_PRECOMPILE_BLS_G2MAP: int
88-
GAS_PRECOMPILE_BLS_PAIRING_BASE: int
89-
GAS_PRECOMPILE_BLS_PAIRING_PER_PAIR: int
90-
91-
GAS_PRECOMPILE_P256VERIFY: int
64+
PRECOMPILE_ECRECOVER: int
65+
PRECOMPILE_SHA256_BASE: int
66+
PRECOMPILE_SHA256_PER_WORD: int
67+
PRECOMPILE_RIPEMD160_BASE: int
68+
PRECOMPILE_RIPEMD160_PER_WORD: int
69+
PRECOMPILE_IDENTITY_BASE: int
70+
PRECOMPILE_IDENTITY_PER_WORD: int
71+
72+
PRECOMPILE_ECADD: int
73+
PRECOMPILE_ECMUL: int
74+
PRECOMPILE_ECPAIRING_BASE: int
75+
PRECOMPILE_ECPAIRING_PER_POINT: int
76+
77+
PRECOMPILE_BLAKE2F_BASE: int
78+
PRECOMPILE_BLAKE2F_PER_ROUND: int
79+
80+
PRECOMPILE_POINT_EVALUATION: int
81+
82+
PRECOMPILE_BLS_G1ADD: int
83+
PRECOMPILE_BLS_G1MUL: int
84+
PRECOMPILE_BLS_G1MAP: int
85+
PRECOMPILE_BLS_G2ADD: int
86+
PRECOMPILE_BLS_G2MUL: int
87+
PRECOMPILE_BLS_G2MAP: int
88+
PRECOMPILE_BLS_PAIRING_BASE: int
89+
PRECOMPILE_BLS_PAIRING_PER_PAIR: int
90+
91+
PRECOMPILE_P256VERIFY: int
9292

9393
# Refund constants
9494
REFUND_STORAGE_CLEAR: int

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

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ class GasCosts:
3333
These values may be patched at runtime by a future gas repricing utility
3434
"""
3535

36+
# General
3637
GAS_BASE = Uint(2)
3738
GAS_VERY_LOW = Uint(3)
3839
GAS_STORAGE_SET = Uint(20000)
3940
GAS_COLD_STORAGE_WRITE = Uint(5000)
40-
REFUND_STORAGE_CLEAR = 4800
4141
GAS_LOW = Uint(5)
4242
GAS_MID = Uint(8)
4343
GAS_HIGH = Uint(10)
@@ -58,23 +58,35 @@ class GasCosts:
5858
GAS_CALL_STIPEND = Uint(2300)
5959
GAS_SELF_DESTRUCT = Uint(5000)
6060
GAS_SELF_DESTRUCT_NEW_ACCOUNT = Uint(25000)
61-
GAS_PRECOMPILE_ECRECOVER = Uint(3000)
62-
GAS_PRECOMPILE_P256VERIFY = Uint(6900)
63-
GAS_PRECOMPILE_SHA256_BASE = Uint(60)
64-
GAS_PRECOMPILE_SHA256_PER_WORD = Uint(12)
65-
GAS_PRECOMPILE_RIPEMD160_BASE = Uint(600)
66-
GAS_PRECOMPILE_RIPEMD160_PER_WORD = Uint(120)
67-
GAS_PRECOMPILE_IDENTITY_BASE = Uint(15)
68-
GAS_PRECOMPILE_IDENTITY_PER_WORD = Uint(3)
6961
GAS_RETURN_DATA_COPY = Uint(3)
7062
GAS_FAST_STEP = Uint(5)
71-
GAS_PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1)
7263
GAS_COLD_STORAGE_ACCESS = Uint(2100)
7364
GAS_COLD_ACCOUNT_ACCESS = Uint(2600)
7465
GAS_WARM_ACCESS = Uint(100)
7566
GAS_CODE_INIT_PER_WORD = Uint(2)
7667
GAS_POINT_EVALUATION = Uint(50000)
7768

69+
# Refunds
70+
REFUND_STORAGE_CLEAR = 4800
71+
72+
# Precompiles
73+
PRECOMPILE_ECRECOVER = Uint(3000)
74+
PRECOMPILE_P256VERIFY = Uint(6900)
75+
PRECOMPILE_SHA256_BASE = Uint(60)
76+
PRECOMPILE_SHA256_PER_WORD = Uint(12)
77+
PRECOMPILE_RIPEMD160_BASE = Uint(600)
78+
PRECOMPILE_RIPEMD160_PER_WORD = Uint(120)
79+
PRECOMPILE_IDENTITY_BASE = Uint(15)
80+
PRECOMPILE_IDENTITY_PER_WORD = Uint(3)
81+
PRECOMPILE_BLAKE2F_PER_ROUND = Uint(1)
82+
PRECOMPILE_BLS_G1ADD = Uint(375)
83+
PRECOMPILE_BLS_G1MUL = Uint(12000)
84+
PRECOMPILE_BLS_G1MAP = Uint(5500)
85+
PRECOMPILE_BLS_G2ADD = Uint(600)
86+
PRECOMPILE_BLS_G2MUL = Uint(22500)
87+
PRECOMPILE_BLS_G2MAP = Uint(23800)
88+
89+
# Blobs
7890
GAS_PER_BLOB = U64(2**17)
7991
BLOB_SCHEDULE_TARGET = U64(14)
8092
BLOB_TARGET_GAS_PER_BLOCK = GAS_PER_BLOB * BLOB_SCHEDULE_TARGET
@@ -83,16 +95,10 @@ class GasCosts:
8395
BLOB_MIN_GASPRICE = Uint(1)
8496
BLOB_BASE_FEE_UPDATE_FRACTION = Uint(11684671)
8597

86-
GAS_PRECOMPILE_BLS_G1ADD = Uint(375)
87-
GAS_PRECOMPILE_BLS_G1MUL = Uint(12000)
88-
GAS_PRECOMPILE_BLS_G1MAP = Uint(5500)
89-
GAS_PRECOMPILE_BLS_G2ADD = Uint(600)
90-
GAS_PRECOMPILE_BLS_G2MUL = Uint(22500)
91-
GAS_PRECOMPILE_BLS_G2MAP = Uint(23800)
92-
98+
# Block Access Lists
9399
GAS_BLOCK_ACCESS_LIST_ITEM = Uint(2000)
94100

95-
# Opcode specific vars used for repricing
101+
# Opcodes
96102
OPCODE_ADD = GAS_VERY_LOW
97103
OPCODE_SUB = GAS_VERY_LOW
98104
OPCODE_MUL = GAS_LOW

src/ethereum/forks/amsterdam/vm/precompiled_contracts/blake2f.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def blake2f(evm: Evm) -> None:
3535
blake2b = Blake2b()
3636
rounds, h, m, t_0, t_1, f = blake2b.get_blake2_parameters(data)
3737

38-
charge_gas(evm, GasCosts.GAS_PRECOMPILE_BLAKE2F_PER_ROUND * rounds)
38+
charge_gas(evm, GasCosts.PRECOMPILE_BLAKE2F_PER_ROUND * rounds)
3939
if f not in [0, 1]:
4040
raise InvalidParameter
4141

src/ethereum/forks/amsterdam/vm/precompiled_contracts/bls12_381/bls12_381_g1.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def bls12_g1_add(evm: Evm) -> None:
5858
raise InvalidParameter("Invalid Input Length")
5959

6060
# GAS
61-
charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G1ADD))
61+
charge_gas(evm, Uint(GasCosts.PRECOMPILE_BLS_G1ADD))
6262

6363
# OPERATION
6464
p1 = bytes_to_g1(buffer_read(data, U256(0), U256(128)))
@@ -99,9 +99,7 @@ def bls12_g1_msm(evm: Evm) -> None:
9999
else:
100100
discount = Uint(G1_MAX_DISCOUNT)
101101

102-
gas_cost = (
103-
Uint(k) * GasCosts.GAS_PRECOMPILE_BLS_G1MUL * discount // MULTIPLIER
104-
)
102+
gas_cost = Uint(k) * GasCosts.PRECOMPILE_BLS_G1MUL * discount // MULTIPLIER
105103
charge_gas(evm, gas_cost)
106104

107105
# OPERATION
@@ -140,7 +138,7 @@ def bls12_map_fp_to_g1(evm: Evm) -> None:
140138
raise InvalidParameter("Invalid Input Length")
141139

142140
# GAS
143-
charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G1MAP))
141+
charge_gas(evm, Uint(GasCosts.PRECOMPILE_BLS_G1MAP))
144142

145143
# OPERATION
146144
fp = int.from_bytes(data, "big")

src/ethereum/forks/amsterdam/vm/precompiled_contracts/bls12_381/bls12_381_g2.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def bls12_g2_add(evm: Evm) -> None:
5959
raise InvalidParameter("Invalid Input Length")
6060

6161
# GAS
62-
charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G2ADD))
62+
charge_gas(evm, Uint(GasCosts.PRECOMPILE_BLS_G2ADD))
6363

6464
# OPERATION
6565
p1 = bytes_to_g2(buffer_read(data, U256(0), U256(256)))
@@ -100,9 +100,7 @@ def bls12_g2_msm(evm: Evm) -> None:
100100
else:
101101
discount = Uint(G2_MAX_DISCOUNT)
102102

103-
gas_cost = (
104-
Uint(k) * GasCosts.GAS_PRECOMPILE_BLS_G2MUL * discount // MULTIPLIER
105-
)
103+
gas_cost = Uint(k) * GasCosts.PRECOMPILE_BLS_G2MUL * discount // MULTIPLIER
106104
charge_gas(evm, gas_cost)
107105

108106
# OPERATION
@@ -141,7 +139,7 @@ def bls12_map_fp2_to_g2(evm: Evm) -> None:
141139
raise InvalidParameter("Invalid Input Length")
142140

143141
# GAS
144-
charge_gas(evm, Uint(GasCosts.GAS_PRECOMPILE_BLS_G2MAP))
142+
charge_gas(evm, Uint(GasCosts.PRECOMPILE_BLS_G2MAP))
145143

146144
# OPERATION
147145
field_element = bytes_to_fq2(data)

src/ethereum/forks/amsterdam/vm/precompiled_contracts/ecrecover.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def ecrecover(evm: Evm) -> None:
3737
data = evm.message.data
3838

3939
# GAS
40-
charge_gas(evm, GasCosts.GAS_PRECOMPILE_ECRECOVER)
40+
charge_gas(evm, GasCosts.PRECOMPILE_ECRECOVER)
4141

4242
# OPERATION
4343
message_hash_bytes = buffer_read(data, U256(0), U256(32))

src/ethereum/forks/amsterdam/vm/precompiled_contracts/identity.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ def identity(evm: Evm) -> None:
3838
word_count = ceil32(Uint(len(data))) // Uint(32)
3939
charge_gas(
4040
evm,
41-
GasCosts.GAS_PRECOMPILE_IDENTITY_BASE
42-
+ GasCosts.GAS_PRECOMPILE_IDENTITY_PER_WORD * word_count,
41+
GasCosts.PRECOMPILE_IDENTITY_BASE
42+
+ GasCosts.PRECOMPILE_IDENTITY_PER_WORD * word_count,
4343
)
4444

4545
# OPERATION

src/ethereum/forks/amsterdam/vm/precompiled_contracts/p256verify.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def p256verify(evm: Evm) -> None:
4141
data = evm.message.data
4242

4343
# GAS
44-
charge_gas(evm, GasCosts.GAS_PRECOMPILE_P256VERIFY)
44+
charge_gas(evm, GasCosts.PRECOMPILE_P256VERIFY)
4545

4646
if len(data) != 160:
4747
return

src/ethereum/forks/amsterdam/vm/precompiled_contracts/ripemd160.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ def ripemd160(evm: Evm) -> None:
4141
word_count = ceil32(Uint(len(data))) // Uint(32)
4242
charge_gas(
4343
evm,
44-
GasCosts.GAS_PRECOMPILE_RIPEMD160_BASE
45-
+ GasCosts.GAS_PRECOMPILE_RIPEMD160_PER_WORD * word_count,
44+
GasCosts.PRECOMPILE_RIPEMD160_BASE
45+
+ GasCosts.PRECOMPILE_RIPEMD160_PER_WORD * word_count,
4646
)
4747

4848
# OPERATION

0 commit comments

Comments
 (0)