File tree Expand file tree Collapse file tree 3 files changed +32
-0
lines changed
src/ethereum/osaka/vm/instructions Expand file tree Collapse file tree 3 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -65,6 +65,7 @@ class Ops(enum.Enum):
65
65
SHL = 0x1B
66
66
SHR = 0x1C
67
67
SAR = 0x1D
68
+ CLZ = 0x1E
68
69
69
70
# Keccak Op
70
71
KECCAK = 0x20
@@ -241,6 +242,7 @@ class Ops(enum.Enum):
241
242
Ops .SHL : bitwise_instructions .bitwise_shl ,
242
243
Ops .SHR : bitwise_instructions .bitwise_shr ,
243
244
Ops .SAR : bitwise_instructions .bitwise_sar ,
245
+ Ops .CLZ : bitwise_instructions .count_leading_zeros ,
244
246
Ops .KECCAK : keccak_instructions .keccak ,
245
247
Ops .SLOAD : storage_instructions .sload ,
246
248
Ops .BLOCKHASH : block_instructions .block_hash ,
Original file line number Diff line number Diff line change @@ -238,3 +238,31 @@ def bitwise_sar(evm: Evm) -> None:
238
238
239
239
# PROGRAM COUNTER
240
240
evm .pc += Uint (1 )
241
+
242
+
243
+ def count_leading_zeros (evm : Evm ) -> None :
244
+ """
245
+ Count the number of leading zero bits in a 256-bit word.
246
+
247
+ Pops one value from the stack and pushes the number of leading zero bits.
248
+ If the input is zero, pushes 256.
249
+
250
+ Parameters
251
+ ----------
252
+ evm :
253
+ The current EVM frame.
254
+ """
255
+ # STACK
256
+ x = pop (evm .stack )
257
+
258
+ # GAS
259
+ charge_gas (evm , GAS_VERY_LOW )
260
+
261
+ # OPERATION
262
+ bit_length = U256 (x .bit_length ())
263
+ result = U256 (256 ) - bit_length
264
+
265
+ push (evm .stack , result )
266
+
267
+ # PROGRAM COUNTER
268
+ evm .pc += Uint (1 )
Original file line number Diff line number Diff line change 475
475
blockchain
476
476
listdir
477
477
precompiles
478
+
479
+ CLZ
You can’t perform that action at this time.
0 commit comments