Skip to content

Commit 715e48b

Browse files
committed
refactor: add missing opcode gas constants and replace usage in functions
1 parent 884b9ff commit 715e48b

144 files changed

Lines changed: 882 additions & 453 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.

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,28 @@ class GasCosts:
147147
OPCODE_CALLDATALOAD = VERY_LOW
148148
OPCODE_BLOCKHASH = Uint(20)
149149
OPCODE_COINBASE = BASE
150+
OPCODE_POP = BASE
151+
OPCODE_MSIZE = BASE
152+
OPCODE_PC = BASE
153+
OPCODE_GAS = BASE
154+
OPCODE_ADDRESS = BASE
155+
OPCODE_ORIGIN = BASE
156+
OPCODE_CALLER = BASE
157+
OPCODE_CALLVALUE = BASE
158+
OPCODE_CALLDATASIZE = BASE
159+
OPCODE_CODESIZE = BASE
160+
OPCODE_GASPRICE = BASE
161+
OPCODE_TIMESTAMP = BASE
162+
OPCODE_NUMBER = BASE
163+
OPCODE_GASLIMIT = BASE
164+
OPCODE_PREVRANDAO = BASE
165+
OPCODE_RETURNDATASIZE = BASE
166+
OPCODE_CHAINID = BASE
167+
OPCODE_BASEFEE = BASE
168+
OPCODE_BLOBBASEFEE = BASE
150169
OPCODE_BLOBHASH = Uint(3)
151170
OPCODE_PUSH = VERY_LOW
171+
OPCODE_PUSH0 = BASE
152172
OPCODE_DUP = VERY_LOW
153173
OPCODE_SWAP = VERY_LOW
154174

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def coinbase(evm: Evm) -> None:
8989
pass
9090

9191
# GAS
92-
charge_gas(evm, GasCosts.BASE)
92+
charge_gas(evm, GasCosts.OPCODE_COINBASE)
9393

9494
# OPERATION
9595
push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase))
@@ -123,7 +123,7 @@ def timestamp(evm: Evm) -> None:
123123
pass
124124

125125
# GAS
126-
charge_gas(evm, GasCosts.BASE)
126+
charge_gas(evm, GasCosts.OPCODE_TIMESTAMP)
127127

128128
# OPERATION
129129
push(evm.stack, evm.message.block_env.time)
@@ -156,7 +156,7 @@ def number(evm: Evm) -> None:
156156
pass
157157

158158
# GAS
159-
charge_gas(evm, GasCosts.BASE)
159+
charge_gas(evm, GasCosts.OPCODE_NUMBER)
160160

161161
# OPERATION
162162
push(evm.stack, U256(evm.message.block_env.number))
@@ -189,7 +189,7 @@ def prev_randao(evm: Evm) -> None:
189189
pass
190190

191191
# GAS
192-
charge_gas(evm, GasCosts.BASE)
192+
charge_gas(evm, GasCosts.OPCODE_PREVRANDAO)
193193

194194
# OPERATION
195195
push(evm.stack, U256.from_be_bytes(evm.message.block_env.prev_randao))
@@ -222,7 +222,7 @@ def gas_limit(evm: Evm) -> None:
222222
pass
223223

224224
# GAS
225-
charge_gas(evm, GasCosts.BASE)
225+
charge_gas(evm, GasCosts.OPCODE_GASLIMIT)
226226

227227
# OPERATION
228228
push(evm.stack, U256(evm.message.block_env.block_gas_limit))
@@ -252,7 +252,7 @@ def chain_id(evm: Evm) -> None:
252252
pass
253253

254254
# GAS
255-
charge_gas(evm, GasCosts.BASE)
255+
charge_gas(evm, GasCosts.OPCODE_CHAINID)
256256

257257
# OPERATION
258258
push(evm.stack, U256(evm.message.block_env.chain_id))

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def pc(evm: Evm) -> None:
116116
pass
117117

118118
# GAS
119-
charge_gas(evm, GasCosts.BASE)
119+
charge_gas(evm, GasCosts.OPCODE_PC)
120120

121121
# OPERATION
122122
push(evm.stack, U256(evm.pc))
@@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None:
140140
pass
141141

142142
# GAS
143-
charge_gas(evm, GasCosts.BASE)
143+
charge_gas(evm, GasCosts.OPCODE_GAS)
144144

145145
# OPERATION
146146
push(evm.stack, U256(evm.gas_left))

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def address(evm: Evm) -> None:
4545
pass
4646

4747
# GAS
48-
charge_gas(evm, GasCosts.BASE)
48+
charge_gas(evm, GasCosts.OPCODE_ADDRESS)
4949

5050
# OPERATION
5151
push(evm.stack, U256.from_be_bytes(evm.message.current_target))
@@ -100,7 +100,7 @@ def origin(evm: Evm) -> None:
100100
pass
101101

102102
# GAS
103-
charge_gas(evm, GasCosts.BASE)
103+
charge_gas(evm, GasCosts.OPCODE_ORIGIN)
104104

105105
# OPERATION
106106
push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin))
@@ -123,7 +123,7 @@ def caller(evm: Evm) -> None:
123123
pass
124124

125125
# GAS
126-
charge_gas(evm, GasCosts.BASE)
126+
charge_gas(evm, GasCosts.OPCODE_CALLER)
127127

128128
# OPERATION
129129
push(evm.stack, U256.from_be_bytes(evm.message.caller))
@@ -146,7 +146,7 @@ def callvalue(evm: Evm) -> None:
146146
pass
147147

148148
# GAS
149-
charge_gas(evm, GasCosts.BASE)
149+
charge_gas(evm, GasCosts.OPCODE_CALLVALUE)
150150

151151
# OPERATION
152152
push(evm.stack, evm.message.value)
@@ -195,7 +195,7 @@ def calldatasize(evm: Evm) -> None:
195195
pass
196196

197197
# GAS
198-
charge_gas(evm, GasCosts.BASE)
198+
charge_gas(evm, GasCosts.OPCODE_CALLDATASIZE)
199199

200200
# OPERATION
201201
push(evm.stack, U256(len(evm.message.data)))
@@ -256,7 +256,7 @@ def codesize(evm: Evm) -> None:
256256
pass
257257

258258
# GAS
259-
charge_gas(evm, GasCosts.BASE)
259+
charge_gas(evm, GasCosts.OPCODE_CODESIZE)
260260

261261
# OPERATION
262262
push(evm.stack, U256(len(evm.code)))
@@ -317,7 +317,7 @@ def gasprice(evm: Evm) -> None:
317317
pass
318318

319319
# GAS
320-
charge_gas(evm, GasCosts.BASE)
320+
charge_gas(evm, GasCosts.OPCODE_GASPRICE)
321321

322322
# OPERATION
323323
push(evm.stack, U256(evm.message.tx_env.gas_price))
@@ -418,7 +418,7 @@ def returndatasize(evm: Evm) -> None:
418418
pass
419419

420420
# GAS
421-
charge_gas(evm, GasCosts.BASE)
421+
charge_gas(evm, GasCosts.OPCODE_RETURNDATASIZE)
422422

423423
# OPERATION
424424
push(evm.stack, U256(len(evm.return_data)))
@@ -546,7 +546,7 @@ def base_fee(evm: Evm) -> None:
546546
pass
547547

548548
# GAS
549-
charge_gas(evm, GasCosts.BASE)
549+
charge_gas(evm, GasCosts.OPCODE_BASEFEE)
550550

551551
# OPERATION
552552
push(evm.stack, U256(evm.message.block_env.base_fee_per_gas))
@@ -596,7 +596,7 @@ def blob_base_fee(evm: Evm) -> None:
596596
pass
597597

598598
# GAS
599-
charge_gas(evm, GasCosts.BASE)
599+
charge_gas(evm, GasCosts.OPCODE_BLOBBASEFEE)
600600

601601
# OPERATION
602602
blob_base_fee = calculate_blob_gas_price(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def msize(evm: Evm) -> None:
133133
pass
134134

135135
# GAS
136-
charge_gas(evm, GasCosts.BASE)
136+
charge_gas(evm, GasCosts.OPCODE_MSIZE)
137137

138138
# OPERATION
139139
push(evm.stack, U256(len(evm.memory)))

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def pop(evm: Evm) -> None:
3838
stack.pop(evm.stack)
3939

4040
# GAS
41-
charge_gas(evm, GasCosts.BASE)
41+
charge_gas(evm, GasCosts.OPCODE_POP)
4242

4343
# OPERATION
4444
pass
@@ -66,7 +66,7 @@ def push_n(evm: Evm, num_bytes: int) -> None:
6666

6767
# GAS
6868
if num_bytes == 0:
69-
charge_gas(evm, GasCosts.BASE)
69+
charge_gas(evm, GasCosts.OPCODE_PUSH0)
7070
else:
7171
charge_gas(evm, GasCosts.OPCODE_PUSH)
7272

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,24 @@ class GasCosts:
119119
OPCODE_CALLDATALOAD = VERY_LOW
120120
OPCODE_BLOCKHASH = Uint(20)
121121
OPCODE_COINBASE = BASE
122+
OPCODE_POP = BASE
123+
OPCODE_MSIZE = BASE
124+
OPCODE_PC = BASE
125+
OPCODE_GAS = BASE
126+
OPCODE_ADDRESS = BASE
127+
OPCODE_ORIGIN = BASE
128+
OPCODE_CALLER = BASE
129+
OPCODE_CALLVALUE = BASE
130+
OPCODE_CALLDATASIZE = BASE
131+
OPCODE_CODESIZE = BASE
132+
OPCODE_GASPRICE = BASE
133+
OPCODE_TIMESTAMP = BASE
134+
OPCODE_NUMBER = BASE
135+
OPCODE_GASLIMIT = BASE
136+
OPCODE_DIFFICULTY = BASE
137+
OPCODE_RETURNDATASIZE = BASE
138+
OPCODE_CHAINID = BASE
139+
OPCODE_BASEFEE = BASE
122140
OPCODE_PUSH = VERY_LOW
123141
OPCODE_DUP = VERY_LOW
124142
OPCODE_SWAP = VERY_LOW

src/ethereum/forks/arrow_glacier/vm/instructions/block.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def coinbase(evm: Evm) -> None:
7575
pass
7676

7777
# GAS
78-
charge_gas(evm, GasCosts.BASE)
78+
charge_gas(evm, GasCosts.OPCODE_COINBASE)
7979

8080
# OPERATION
8181
push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase))
@@ -102,7 +102,7 @@ def timestamp(evm: Evm) -> None:
102102
pass
103103

104104
# GAS
105-
charge_gas(evm, GasCosts.BASE)
105+
charge_gas(evm, GasCosts.OPCODE_TIMESTAMP)
106106

107107
# OPERATION
108108
push(evm.stack, evm.message.block_env.time)
@@ -128,7 +128,7 @@ def number(evm: Evm) -> None:
128128
pass
129129

130130
# GAS
131-
charge_gas(evm, GasCosts.BASE)
131+
charge_gas(evm, GasCosts.OPCODE_NUMBER)
132132

133133
# OPERATION
134134
push(evm.stack, U256(evm.message.block_env.number))
@@ -154,7 +154,7 @@ def difficulty(evm: Evm) -> None:
154154
pass
155155

156156
# GAS
157-
charge_gas(evm, GasCosts.BASE)
157+
charge_gas(evm, GasCosts.OPCODE_DIFFICULTY)
158158

159159
# OPERATION
160160
push(evm.stack, U256(evm.message.block_env.difficulty))
@@ -180,7 +180,7 @@ def gas_limit(evm: Evm) -> None:
180180
pass
181181

182182
# GAS
183-
charge_gas(evm, GasCosts.BASE)
183+
charge_gas(evm, GasCosts.OPCODE_GASLIMIT)
184184

185185
# OPERATION
186186
push(evm.stack, U256(evm.message.block_env.block_gas_limit))
@@ -203,7 +203,7 @@ def chain_id(evm: Evm) -> None:
203203
pass
204204

205205
# GAS
206-
charge_gas(evm, GasCosts.BASE)
206+
charge_gas(evm, GasCosts.OPCODE_CHAINID)
207207

208208
# OPERATION
209209
push(evm.stack, U256(evm.message.block_env.chain_id))

src/ethereum/forks/arrow_glacier/vm/instructions/control_flow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def pc(evm: Evm) -> None:
116116
pass
117117

118118
# GAS
119-
charge_gas(evm, GasCosts.BASE)
119+
charge_gas(evm, GasCosts.OPCODE_PC)
120120

121121
# OPERATION
122122
push(evm.stack, U256(evm.pc))
@@ -140,7 +140,7 @@ def gas_left(evm: Evm) -> None:
140140
pass
141141

142142
# GAS
143-
charge_gas(evm, GasCosts.BASE)
143+
charge_gas(evm, GasCosts.OPCODE_GAS)
144144

145145
# OPERATION
146146
push(evm.stack, U256(evm.gas_left))

src/ethereum/forks/arrow_glacier/vm/instructions/environment.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def address(evm: Evm) -> None:
4343
pass
4444

4545
# GAS
46-
charge_gas(evm, GasCosts.BASE)
46+
charge_gas(evm, GasCosts.OPCODE_ADDRESS)
4747

4848
# OPERATION
4949
push(evm.stack, U256.from_be_bytes(evm.message.current_target))
@@ -97,7 +97,7 @@ def origin(evm: Evm) -> None:
9797
pass
9898

9999
# GAS
100-
charge_gas(evm, GasCosts.BASE)
100+
charge_gas(evm, GasCosts.OPCODE_ORIGIN)
101101

102102
# OPERATION
103103
push(evm.stack, U256.from_be_bytes(evm.message.tx_env.origin))
@@ -120,7 +120,7 @@ def caller(evm: Evm) -> None:
120120
pass
121121

122122
# GAS
123-
charge_gas(evm, GasCosts.BASE)
123+
charge_gas(evm, GasCosts.OPCODE_CALLER)
124124

125125
# OPERATION
126126
push(evm.stack, U256.from_be_bytes(evm.message.caller))
@@ -143,7 +143,7 @@ def callvalue(evm: Evm) -> None:
143143
pass
144144

145145
# GAS
146-
charge_gas(evm, GasCosts.BASE)
146+
charge_gas(evm, GasCosts.OPCODE_CALLVALUE)
147147

148148
# OPERATION
149149
push(evm.stack, evm.message.value)
@@ -192,7 +192,7 @@ def calldatasize(evm: Evm) -> None:
192192
pass
193193

194194
# GAS
195-
charge_gas(evm, GasCosts.BASE)
195+
charge_gas(evm, GasCosts.OPCODE_CALLDATASIZE)
196196

197197
# OPERATION
198198
push(evm.stack, U256(len(evm.message.data)))
@@ -253,7 +253,7 @@ def codesize(evm: Evm) -> None:
253253
pass
254254

255255
# GAS
256-
charge_gas(evm, GasCosts.BASE)
256+
charge_gas(evm, GasCosts.OPCODE_CODESIZE)
257257

258258
# OPERATION
259259
push(evm.stack, U256(len(evm.code)))
@@ -314,7 +314,7 @@ def gasprice(evm: Evm) -> None:
314314
pass
315315

316316
# GAS
317-
charge_gas(evm, GasCosts.BASE)
317+
charge_gas(evm, GasCosts.OPCODE_GASPRICE)
318318

319319
# OPERATION
320320
push(evm.stack, U256(evm.message.tx_env.gas_price))
@@ -413,7 +413,7 @@ def returndatasize(evm: Evm) -> None:
413413
pass
414414

415415
# GAS
416-
charge_gas(evm, GasCosts.BASE)
416+
charge_gas(evm, GasCosts.OPCODE_RETURNDATASIZE)
417417

418418
# OPERATION
419419
push(evm.stack, U256(len(evm.return_data)))
@@ -540,7 +540,7 @@ def base_fee(evm: Evm) -> None:
540540
pass
541541

542542
# GAS
543-
charge_gas(evm, GasCosts.BASE)
543+
charge_gas(evm, GasCosts.OPCODE_BASEFEE)
544544

545545
# OPERATION
546546
push(evm.stack, U256(evm.message.block_env.base_fee_per_gas))

0 commit comments

Comments
 (0)