snarkvm_algorithms/snark/varuna/data_structures/
certificate.rs

1// Copyright 2024 Aleo Network Foundation
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 crate::polycommit::sonic_pc;
17use snarkvm_curves::PairingEngine;
18use snarkvm_utilities::{
19    FromBytes,
20    ToBytes,
21    error,
22    io::{self, Read, Write},
23    serialize::*,
24};
25
26/// A certificate for the verifying key.
27#[derive(Clone, Debug, PartialEq, Eq, CanonicalSerialize, CanonicalDeserialize)]
28pub struct Certificate<E: PairingEngine> {
29    /// An evaluation proof from the polynomial commitment.
30    pub pc_proof: sonic_pc::BatchLCProof<E>,
31}
32
33impl<E: PairingEngine> Certificate<E> {
34    /// Construct a new certificate.
35    pub fn new(pc_proof: sonic_pc::BatchLCProof<E>) -> Self {
36        Self { pc_proof }
37    }
38}
39
40impl<E: PairingEngine> ToBytes for Certificate<E> {
41    fn write_le<W: Write>(&self, mut w: W) -> io::Result<()> {
42        Self::serialize_compressed(self, &mut w).map_err(|_| error("Failed to serialize certificate"))
43    }
44}
45
46impl<E: PairingEngine> FromBytes for Certificate<E> {
47    fn read_le<R: Read>(mut r: R) -> io::Result<Self> {
48        Self::deserialize_compressed(&mut r).map_err(|_| error("Failed to deserialize certificate"))
49    }
50}