snarkvm_algorithms/snark/varuna/data_structures/
certificate.rs

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