The ComEvProof
struct can perform serialization and deserialization without any errors:
/// `ComEvProof` is a proof for a committed evaluation result that is output by `KZG10::committed_evaluation_prove`.
#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(
Default(bound = ""),
Hash(bound = ""),
Clone(bound = ""),
Copy(bound = ""),
Debug(bound = ""),
PartialEq(bound = ""),
Eq(bound = "")
)]
pub struct ComEvProof<E: PairingEngine> {
///This is a PoK
pub pi_z: PoKProof<E>,
/// This is a commitment to the witness polynomial.
pub com_q: E::G1Affine,
/// This is the Fiat-Shamir challenge
pub rho: E::Fr,
/// This is the first component of the sigma protocol response
pub sigma: E::Fr,
/// This is the second component of the sigma protocol response
pub tau: E::Fr,
}
impl<E: PairingEngine> ToBytes for ComEvProof<E> {
#[inline]
fn write<W: Write>(&self, mut writer: W) -> ark_std::io::Result<()> {
self.pi_z.write(&mut writer)?;
self.com_q.write(&mut writer)?;
self.rho.write(&mut writer)?;
self.sigma.write(&mut writer)?;
self.tau.write(&mut writer)
}
}
However, when implementing the HSNPLinProof
struct, the InvalidData
error always occurs:
///Implements the proof of the HSNP scheme for committed linear functions from [FT22]
#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
pub struct HSNPLinProof<E: PairingEngine> {
/// the group element of the signature
pub lambda: E::G1Affine,
/// the chameleon hash randomness of the signature
pub r: E::Fr,
///the proof of knowledge of the commitment to the result
pub pok_z: hsnp_pc::PoKProof<E>,
}
impl<E: PairingEngine> ToBytes for HSNPLinProof<E> {
#[inline]
fn write<W: Write>(&self, mut writer: W) -> ark_std::io::Result<()> {
self.lambda.write(&mut writer)?;
self.r.write(&mut writer)?;
self.pok_z.write(&mut writer)
}
}
Why is InvalidData
occurring in the second case?Below is the test program.
let mut buffer = Cursor::new(Vec::new());
//proof.sigproof_z is of type HSNPLinProof::<Bls12<Parameters>>
// Invoke the serialize method to serialize the instance of `proof.sigproof_z` into the buffer
let a = proof.sigproof_z.serialize(&mut buffer);
match a {
Ok(_) => {
// At this point, `reproof` is of type `R1csHsnpProof`
eprintln!("Verification process initiated:");
// Here, the variable `ver` would be utilized
},
Err(e) => {
// Handle the error case
eprintln!("An error occurred: {:?}", e);
},
}
buffer.set_position(0);
// Deserialize the data back into the `HSNPLinProof` struct
let deproof_result = hsnp::lhs_ped::HSNPLinProof::<Bls12<Parameters>>::deserialize(&mut buffer);
match deproof_result {
Ok(reproof) => {
// At this point, `reproof` is again of type `R1csHsnpProof`
eprintln!("Verification process completed:");
// Here, the variable `ver` would be utilized again
},
Err(e) => {
// Handle the error case
eprintln!("An error occurred: {:?}", e);
},
}