Skip to main content

zksync_vm2/
mode_requirements.rs

1/// VM execution mode requirements (kernel only, not in static call) that can be placed on instructions.
2#[derive(Debug, Clone, Copy)]
3pub struct ModeRequirements(pub(crate) u8);
4
5impl ModeRequirements {
6    /// Creates new requirements.
7    pub const fn new(kernel_only: bool, cannot_use_in_static: bool) -> Self {
8        Self((kernel_only as u8) | ((cannot_use_in_static as u8) << 1))
9    }
10
11    /// Creates default requirements that always hold.
12    pub const fn none() -> Self {
13        Self::new(false, false)
14    }
15
16    pub(crate) fn met(self, is_kernel: bool, is_static: bool) -> bool {
17        let enabled_modes = u8::from(is_kernel) | (u8::from(!is_static) << 1);
18        enabled_modes & self.0 == self.0
19    }
20}