#![allow(non_snake_case)]
use crate::{errors::R1CSError, inner_product_proof::InnerProductProof, ProofError};
use ark_ec::AffineRepr;
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::{io::Cursor, vec::Vec};
#[derive(Clone, Debug, CanonicalSerialize, CanonicalDeserialize)]
#[allow(non_snake_case)]
pub struct R1CSProof<G: AffineRepr> {
pub(super) A_I1: G,
pub(super) A_O1: G,
pub(super) S1: G,
pub(super) A_I2: G,
pub(super) A_O2: G,
pub(super) S2: G,
pub(super) T_1: G,
pub(super) T_3: G,
pub(super) T_4: G,
pub(super) T_5: G,
pub(super) T_6: G,
pub(super) t_x: G::ScalarField,
pub(super) t_x_blinding: G::ScalarField,
pub(super) e_blinding: G::ScalarField,
pub(super) ipp_proof: InnerProductProof<G>,
}
impl<G: AffineRepr> R1CSProof<G> {
pub fn to_bytes(&self) -> Result<Vec<u8>, ProofError> {
let mut cursor = Cursor::new(Vec::new());
self.serialize_compressed(&mut cursor)?;
Ok(cursor.into_inner())
}
pub fn from_bytes(slice: &[u8]) -> Result<R1CSProof<G>, R1CSError> {
let mut cursor = Cursor::new(slice);
let proof = R1CSProof::<G>::deserialize_compressed(&mut cursor);
if proof.is_ok() {
Ok(proof.unwrap())
} else {
Err(R1CSError::FormatError)
}
}
}