6969/// - `SELFDESTRUCT`
7070/// - `MCOPY`
7171/// - `DIFFICULTY`
72+ /// - `CLZ`
7273pub fn make_scroll_instruction_table < WIRE : InterpreterTypes , HOST : ScrollContextTr > (
7374) -> InstructionTable < WIRE , HOST > {
7475 let mut table = instruction_table :: < WIRE , HOST > ( ) ;
@@ -82,6 +83,7 @@ pub fn make_scroll_instruction_table<WIRE: InterpreterTypes, HOST: ScrollContext
8283 table[ opcode:: SELFDESTRUCT as usize ] = Instruction :: new ( selfdestruct :: < WIRE , HOST > , 0 ) ;
8384 table[ opcode:: MCOPY as usize ] = Instruction :: new ( mcopy :: < WIRE , HOST > , 0 ) ;
8485 table[ opcode:: DIFFICULTY as usize ] = Instruction :: new ( difficulty :: < WIRE , HOST > , 2 ) ;
86+ table[ opcode:: CLZ as usize ] = Instruction :: new ( clz :: < WIRE , HOST > , 5 ) ;
8587
8688 table
8789}
@@ -245,6 +247,23 @@ pub fn difficulty<WIRE: InterpreterTypes, H: Host + ?Sized>(
245247 push ! ( context. interpreter, DIFFICULTY ) ;
246248}
247249
250+ /// Implements the CLZ instruction
251+ ///
252+ /// EIP-7939 count leading zeros.
253+ fn clz < WIRE : InterpreterTypes , H : ScrollContextTr > ( context : InstructionContext < ' _ , H , WIRE > ) {
254+ let host = context. host ;
255+ let interpreter = context. interpreter ;
256+ if !host. cfg ( ) . spec ( ) . is_enabled_in ( ScrollSpecId :: GALILEO ) {
257+ interpreter. halt ( InstructionResult :: NotActivated ) ;
258+ return ;
259+ }
260+
261+ popn_top ! ( [ ] , op1, context. interpreter) ;
262+
263+ let leading_zeros = op1. leading_zeros ( ) ;
264+ * op1 = U256 :: from ( leading_zeros) ;
265+ }
266+
248267// HELPER FUNCTIONS
249268// ================================================================================================
250269
0 commit comments