Skip to main content

zksync_vm2/instruction_handlers/
nop.rs

1use zksync_vm2_interface::{opcodes, Tracer};
2
3use super::common::boilerplate;
4use crate::{
5    addressing_modes::{destination_stack_address, AdvanceStackPointer, Arguments, Source},
6    instruction::ExecutionStatus,
7    Instruction, VirtualMachine, World,
8};
9
10fn nop<T: Tracer, W: World<T>>(
11    vm: &mut VirtualMachine<T, W>,
12    world: &mut W,
13    tracer: &mut T,
14) -> ExecutionStatus {
15    boilerplate::<opcodes::Nop, _, _>(vm, world, tracer, |vm, args| {
16        // nop's addressing modes can move the stack pointer!
17        AdvanceStackPointer::get(args, &mut vm.state);
18        vm.state.current_frame.sp = vm
19            .state
20            .current_frame
21            .sp
22            .wrapping_add(destination_stack_address(args, &mut vm.state));
23    })
24}
25
26impl<T: Tracer, W: World<T>> Instruction<T, W> {
27    /// Creates a [`Nop`](opcodes::Nop) instruction with the provided params.
28    pub fn from_nop(
29        pop: AdvanceStackPointer,
30        push: AdvanceStackPointer,
31        arguments: Arguments,
32    ) -> Self {
33        Self {
34            handler: nop,
35            arguments: arguments.write_source(&pop).write_destination(&push),
36        }
37    }
38}