Skip to main content

snarkvm_algorithms/snark/varuna/
mode.rs

1// Copyright (c) 2019-2026 Provable Inc.
2// This file is part of the snarkVM library.
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at:
7
8// http://www.apache.org/licenses/LICENSE-2.0
9
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16use core::fmt::Debug;
17use snarkvm_utilities::{FromBytes, ToBytes, io_error};
18use std::io;
19
20/// A trait to specify the SNARK mode.
21pub trait SNARKMode: 'static + Copy + Clone + Debug + PartialEq + Eq + Sync + Send {
22    const ZK: bool;
23}
24
25/// This mode produces a hiding SNARK proof.
26#[derive(Copy, Clone, Debug, PartialEq, Eq)]
27pub struct VarunaHidingMode;
28
29impl SNARKMode for VarunaHidingMode {
30    const ZK: bool = true;
31}
32
33/// This mode produces a non-hiding SNARK proof.
34#[derive(Copy, Clone, Debug, PartialEq, Eq)]
35pub struct VarunaNonHidingMode;
36
37impl SNARKMode for VarunaNonHidingMode {
38    const ZK: bool = false;
39}
40
41/// The different Varuna Versions.
42#[repr(u8)]
43#[derive(Copy, Clone, Debug, PartialEq, Eq)]
44pub enum VarunaVersion {
45    V1 = 1,
46    V2 = 2,
47}
48
49impl ToBytes for VarunaVersion {
50    fn write_le<W: io::Write>(&self, writer: W) -> io::Result<()> {
51        (*self as u8).write_le(writer)
52    }
53}
54
55impl FromBytes for VarunaVersion {
56    fn read_le<R: io::Read>(reader: R) -> io::Result<Self> {
57        match u8::read_le(reader)? {
58            0 => Err(io_error("Zero is not a valid Varuna version")),
59            1 => Ok(Self::V1),
60            2 => Ok(Self::V2),
61            _ => Err(io_error("Invalid Varuna version")),
62        }
63    }
64}