Skip to content

Commit

Permalink
Fix IetfProof deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
davxy committed Jul 8, 2024
1 parent 56edd4c commit 40c44e3
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/ietf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@ impl<S: IetfSuite> CanonicalSerialize for Proof<S> {
mut writer: W,
_compress_always: ark_serialize::Compress,
) -> Result<(), ark_serialize::SerializationError> {
let buf = utils::encode_scalar::<S>(&self.c);
if buf.len() < S::CHALLENGE_LEN {
let c_buf = utils::encode_scalar::<S>(&self.c);
if c_buf.len() < S::CHALLENGE_LEN {
// Encoded scalar length must be at least S::CHALLENGE_LEN
return Err(ark_serialize::SerializationError::NotEnoughSpace);
}
writer.write_all(&buf[..S::CHALLENGE_LEN])?;
let buf = if S::Codec::BIG_ENDIAN {
&c_buf[c_buf.len() - S::CHALLENGE_LEN..]
} else {
&c_buf[..S::CHALLENGE_LEN]
};
writer.write_all(buf)?;
self.s.serialize_compressed(&mut writer)?;
Ok(())
}
Expand All @@ -47,11 +52,11 @@ impl<S: IetfSuite> CanonicalDeserialize for Proof<S> {
_compress_always: ark_serialize::Compress,
validate: ark_serialize::Validate,
) -> Result<Self, ark_serialize::SerializationError> {
let c = <ScalarField<S> as CanonicalDeserialize>::deserialize_with_mode(
&mut reader,
ark_serialize::Compress::No,
validate,
)?;
let mut c_buf = vec![0; S::CHALLENGE_LEN];
if reader.read_exact(&mut c_buf[..]).is_err() {
return Err(ark_serialize::SerializationError::InvalidData);
}
let c = utils::decode_scalar::<S>(&c_buf);
let s = <ScalarField<S> as CanonicalDeserialize>::deserialize_with_mode(
&mut reader,
ark_serialize::Compress::No,
Expand Down

0 comments on commit 40c44e3

Please sign in to comment.