zebra_chain/primitives/proofs/
halo2.rs

1use serde::{Deserialize, Serialize};
2use std::{fmt, io};
3
4use crate::serialization::{
5    zcash_serialize_bytes, SerializationError, ZcashDeserialize, ZcashSerialize,
6};
7
8/// An encoding of a Halo2 proof, as used in [Zcash][halo2].
9///
10/// Halo2 proofs in Zcash Orchard do not have a fixed size, hence the newtype
11/// around a vector of bytes.
12///
13/// [halo2]: https://zips.z.cash/protocol/nu5.pdf#halo2
14#[derive(Clone, Eq, PartialEq, Serialize, Deserialize)]
15pub struct Halo2Proof(pub Vec<u8>);
16
17impl fmt::Debug for Halo2Proof {
18    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
19        f.debug_tuple("Halo2Proof")
20            .field(&hex::encode(&self.0[..]))
21            .finish()
22    }
23}
24
25impl ZcashSerialize for Halo2Proof {
26    fn zcash_serialize<W: io::Write>(&self, writer: W) -> Result<(), io::Error> {
27        zcash_serialize_bytes(&self.0, writer)
28    }
29}
30
31impl ZcashDeserialize for Halo2Proof {
32    fn zcash_deserialize<R: io::Read>(mut reader: R) -> Result<Self, SerializationError> {
33        let proof = Vec::zcash_deserialize(&mut reader)?;
34
35        Ok(Self(proof))
36    }
37}
38#[cfg(any(test, feature = "proptest-impl"))]
39use proptest::prelude::*;
40
41#[cfg(any(test, feature = "proptest-impl"))]
42impl Arbitrary for Halo2Proof {
43    type Parameters = ();
44
45    fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy {
46        (any::<Vec<u8>>()).prop_map(Self).boxed()
47    }
48
49    type Strategy = BoxedStrategy<Self>;
50}