halo2_proofs/helpers.rs
1use std::io;
2
3use pasta_curves::arithmetic::CurveAffine;
4
5pub(crate) trait CurveRead: CurveAffine {
6 /// Reads a compressed element from the buffer and attempts to parse it
7 /// using `from_bytes`.
8 fn read<R: io::Read>(reader: &mut R) -> io::Result<Self> {
9 let mut compressed = Self::Repr::default();
10 reader.read_exact(compressed.as_mut())?;
11 Option::from(Self::from_bytes(&compressed))
12 .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "invalid point encoding in proof"))
13 }
14}
15
16impl<C: CurveAffine> CurveRead for C {}