Orchard: some Action (de)serialization fixes
This commit is contained in:
parent
f3cf6966a5
commit
009e1dd37e
|
@ -43,9 +43,9 @@ pub struct Action {
|
|||
impl ZcashSerialize for Action {
|
||||
fn zcash_serialize<W: io::Write>(&self, mut writer: W) -> Result<(), io::Error> {
|
||||
self.cv.zcash_serialize(&mut writer)?;
|
||||
writer.write_32_bytes(self.nullifier.into())?;
|
||||
writer.write_all(&<[u8; 32]>::from(self.nullifier)[..])?;
|
||||
writer.write_all(&<[u8; 32]>::from(self.rk)[..])?;
|
||||
writer.write_all(self.cm_x.to_bytes())?;
|
||||
writer.write_all(&<[u8; 32]>::from(self.cm_x)[..])?;
|
||||
self.ephemeral_key.zcash_serialize(&mut writer)?;
|
||||
self.enc_ciphertext.zcash_serialize(&mut writer)?;
|
||||
self.out_ciphertext.zcash_serialize(&mut writer)?;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
use std::{convert::TryInto, io, sync::Arc};
|
||||
|
||||
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||
use halo2::pasta::pallas;
|
||||
use halo2::{arithmetic::FieldExt, pasta::pallas};
|
||||
|
||||
use crate::{
|
||||
block::MAX_BLOCK_BYTES,
|
||||
|
@ -49,6 +49,20 @@ impl ZcashDeserialize for pallas::Scalar {
|
|||
}
|
||||
}
|
||||
|
||||
impl ZcashDeserialize for pallas::Base {
|
||||
fn zcash_deserialize<R: io::Read>(mut reader: R) -> Result<Self, SerializationError> {
|
||||
let possible_field_element = pallas::Base::from_bytes(&reader.read_32_bytes()?);
|
||||
|
||||
if possible_field_element.is_some().into() {
|
||||
Ok(possible_field_element.unwrap())
|
||||
} else {
|
||||
Err(SerializationError::Parse(
|
||||
"Invalid pallas::Base, input not canonical",
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<P: ZkSnarkProof> ZcashSerialize for JoinSplitData<P> {
|
||||
fn zcash_serialize<W: io::Write>(&self, mut writer: W) -> Result<(), io::Error> {
|
||||
writer.write_compactsize(self.joinsplits().count() as u64)?;
|
||||
|
|
Loading…
Reference in New Issue