Add Zcash[De]Serialize bound to ZkSnarkProof.
This commit is contained in:
parent
fa1e168fb5
commit
392825c4cb
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|
||||||
|
use crate::serialization::{ZcashDeserialize, ZcashSerialize};
|
||||||
|
|
||||||
mod bctv14;
|
mod bctv14;
|
||||||
mod groth16;
|
mod groth16;
|
||||||
|
|
||||||
|
@ -9,7 +11,10 @@ pub use bctv14::Bctv14Proof;
|
||||||
pub use groth16::Groth16Proof;
|
pub use groth16::Groth16Proof;
|
||||||
|
|
||||||
/// A marker trait used to abstract over BCTV14 or Groth16 proofs.
|
/// A marker trait used to abstract over BCTV14 or Groth16 proofs.
|
||||||
pub trait ZkSnarkProof: Copy + Clone + Debug + PartialEq + Eq + private::Sealed {}
|
pub trait ZkSnarkProof:
|
||||||
|
Copy + Clone + Debug + PartialEq + Eq + ZcashSerialize + ZcashDeserialize + private::Sealed
|
||||||
|
{
|
||||||
|
}
|
||||||
impl ZkSnarkProof for Bctv14Proof {}
|
impl ZkSnarkProof for Bctv14Proof {}
|
||||||
impl ZkSnarkProof for Groth16Proof {}
|
impl ZkSnarkProof for Groth16Proof {}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
use std::fmt;
|
use std::{fmt, io};
|
||||||
|
|
||||||
|
use crate::serialization::{SerializationError, ZcashDeserialize, ZcashSerialize};
|
||||||
|
|
||||||
/// An encoding of a BCTV14 proof, as used in Zcash.
|
/// An encoding of a BCTV14 proof, as used in Zcash.
|
||||||
pub struct Bctv14Proof(pub [u8; 296]);
|
pub struct Bctv14Proof(pub [u8; 296]);
|
||||||
|
@ -30,3 +32,18 @@ impl PartialEq for Bctv14Proof {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Eq for Bctv14Proof {}
|
impl Eq for Bctv14Proof {}
|
||||||
|
|
||||||
|
impl ZcashSerialize for Bctv14Proof {
|
||||||
|
fn zcash_serialize<W: io::Write>(&self, mut writer: W) -> Result<(), SerializationError> {
|
||||||
|
writer.write_all(&self.0[..])?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ZcashDeserialize for Bctv14Proof {
|
||||||
|
fn zcash_deserialize<R: io::Read>(mut reader: R) -> Result<Self, SerializationError> {
|
||||||
|
let mut bytes = [0; 296];
|
||||||
|
reader.read_exact(&mut bytes[..])?;
|
||||||
|
Ok(Self(bytes))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
use std::fmt;
|
use std::{fmt, io};
|
||||||
|
|
||||||
|
use crate::serialization::{SerializationError, ZcashDeserialize, ZcashSerialize};
|
||||||
|
|
||||||
/// An encoding of a Groth16 proof, as used in Zcash.
|
/// An encoding of a Groth16 proof, as used in Zcash.
|
||||||
pub struct Groth16Proof(pub [u8; 192]);
|
pub struct Groth16Proof(pub [u8; 192]);
|
||||||
|
@ -30,3 +32,18 @@ impl PartialEq for Groth16Proof {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Eq for Groth16Proof {}
|
impl Eq for Groth16Proof {}
|
||||||
|
|
||||||
|
impl ZcashSerialize for Groth16Proof {
|
||||||
|
fn zcash_serialize<W: io::Write>(&self, mut writer: W) -> Result<(), SerializationError> {
|
||||||
|
writer.write_all(&self.0[..])?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ZcashDeserialize for Groth16Proof {
|
||||||
|
fn zcash_deserialize<R: io::Read>(mut reader: R) -> Result<Self, SerializationError> {
|
||||||
|
let mut bytes = [0; 192];
|
||||||
|
reader.read_exact(&mut bytes[..])?;
|
||||||
|
Ok(Self(bytes))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue