Use convenience Reader/Writer methods to only use From/Into for nullifer serialization
And thus remove duplicative Zcash(De)Serialization impls
This commit is contained in:
parent
13b6ff1c65
commit
619afffa16
|
@ -1,12 +1,9 @@
|
|||
#![allow(clippy::unit_arg)]
|
||||
#![allow(dead_code)]
|
||||
|
||||
use std::io;
|
||||
|
||||
use crate::{
|
||||
commitments::sapling::{pedersen_hashes::mixing_pedersen_hash, NoteCommitment},
|
||||
keys::sapling::NullifierDerivingKey,
|
||||
serialization::{ReadZcashExt, SerializationError, ZcashDeserialize, ZcashSerialize},
|
||||
treestate::note_commitment_tree::Position,
|
||||
};
|
||||
|
||||
|
@ -29,7 +26,7 @@ fn prf_nf(nk: [u8; 32], rho: [u8; 32]) -> [u8; 32] {
|
|||
}
|
||||
|
||||
/// A Nullifier for Sapling transactions
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
|
||||
#[cfg_attr(test, derive(proptest_derive::Arbitrary))]
|
||||
pub struct Nullifier([u8; 32]);
|
||||
|
||||
|
@ -47,16 +44,8 @@ impl<'a> From<(NoteCommitment, Position, &'a NullifierDerivingKey)> for Nullifie
|
|||
}
|
||||
}
|
||||
|
||||
impl ZcashDeserialize for Nullifier {
|
||||
fn zcash_deserialize<R: io::Read>(mut reader: R) -> Result<Self, SerializationError> {
|
||||
let bytes = reader.read_32_bytes()?;
|
||||
|
||||
Ok(Self(bytes))
|
||||
}
|
||||
}
|
||||
|
||||
impl ZcashSerialize for Nullifier {
|
||||
fn zcash_serialize<W: io::Write>(&self, mut writer: W) -> Result<(), io::Error> {
|
||||
writer.write_all(&self.0[..])
|
||||
impl From<Nullifier> for [u8; 32] {
|
||||
fn from(n: Nullifier) -> Self {
|
||||
n.0
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,9 @@
|
|||
#![allow(dead_code)]
|
||||
|
||||
use std::io;
|
||||
|
||||
use byteorder::{ByteOrder, LittleEndian};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
keys::sprout::SpendingKey,
|
||||
serialization::{ReadZcashExt, SerializationError, ZcashDeserialize, ZcashSerialize},
|
||||
};
|
||||
use crate::keys::sprout::SpendingKey;
|
||||
|
||||
/// PRF^nf is used to derive a Sprout nullifer from the receiver's
|
||||
/// spending key a_sk and a nullifier seed ρ, instantiated using the
|
||||
|
@ -63,7 +58,7 @@ impl From<NullifierSeed> for [u8; 32] {
|
|||
}
|
||||
|
||||
/// A Nullifier for Sprout transactions
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[cfg_attr(test, derive(proptest_derive::Arbitrary))]
|
||||
pub struct Nullifier(pub(crate) [u8; 32]);
|
||||
|
||||
|
@ -84,17 +79,3 @@ impl From<Nullifier> for [u8; 32] {
|
|||
n.0
|
||||
}
|
||||
}
|
||||
|
||||
impl ZcashDeserialize for Nullifier {
|
||||
fn zcash_deserialize<R: io::Read>(mut reader: R) -> Result<Self, SerializationError> {
|
||||
let bytes = reader.read_32_bytes()?;
|
||||
|
||||
Ok(Self(bytes))
|
||||
}
|
||||
}
|
||||
|
||||
impl ZcashSerialize for Nullifier {
|
||||
fn zcash_serialize<W: io::Write>(&self, mut writer: W) -> Result<(), io::Error> {
|
||||
writer.write_all(&self.0[..])
|
||||
}
|
||||
}
|
||||
|
|
|
@ -242,8 +242,8 @@ impl<P: ZkSnarkProof> ZcashSerialize for JoinSplit<P> {
|
|||
writer.write_u64::<LittleEndian>(self.vpub_old.into())?;
|
||||
writer.write_u64::<LittleEndian>(self.vpub_new.into())?;
|
||||
writer.write_all(&self.anchor[..])?;
|
||||
self.nullifiers[0].zcash_serialize(&mut writer)?;
|
||||
self.nullifiers[1].zcash_serialize(&mut writer)?;
|
||||
writer.write_32_bytes(&self.nullifiers[0].into())?;
|
||||
writer.write_32_bytes(&self.nullifiers[1].into())?;
|
||||
writer.write_all(&self.commitments[0][..])?;
|
||||
writer.write_all(&self.commitments[1][..])?;
|
||||
writer.write_all(&self.ephemeral_key.as_bytes()[..])?;
|
||||
|
@ -264,8 +264,8 @@ impl<P: ZkSnarkProof> ZcashDeserialize for JoinSplit<P> {
|
|||
vpub_new: reader.read_u64::<LittleEndian>()?.try_into()?,
|
||||
anchor: reader.read_32_bytes()?,
|
||||
nullifiers: [
|
||||
notes::sprout::Nullifier::zcash_deserialize(&mut reader)?,
|
||||
notes::sprout::Nullifier::zcash_deserialize(&mut reader)?,
|
||||
notes::sprout::Nullifier::from(reader.read_32_bytes()?),
|
||||
notes::sprout::Nullifier::from(reader.read_32_bytes()?),
|
||||
],
|
||||
commitments: [reader.read_32_bytes()?, reader.read_32_bytes()?],
|
||||
ephemeral_key: x25519_dalek::PublicKey::from(reader.read_32_bytes()?),
|
||||
|
@ -323,7 +323,7 @@ impl ZcashSerialize for Spend {
|
|||
fn zcash_serialize<W: io::Write>(&self, mut writer: W) -> Result<(), io::Error> {
|
||||
self.cv.zcash_serialize(&mut writer)?;
|
||||
writer.write_all(&self.anchor.0[..])?;
|
||||
self.nullifier.zcash_serialize(&mut writer)?;
|
||||
writer.write_32_bytes(&self.nullifier.into())?;
|
||||
writer.write_all(&<[u8; 32]>::from(self.rk)[..])?;
|
||||
self.zkproof.zcash_serialize(&mut writer)?;
|
||||
writer.write_all(&<[u8; 64]>::from(self.spend_auth_sig)[..])?;
|
||||
|
@ -337,7 +337,7 @@ impl ZcashDeserialize for Spend {
|
|||
Ok(Spend {
|
||||
cv: commitments::sapling::ValueCommitment::zcash_deserialize(&mut reader)?,
|
||||
anchor: SaplingNoteTreeRootHash(reader.read_32_bytes()?),
|
||||
nullifier: notes::sapling::Nullifier::zcash_deserialize(&mut reader)?,
|
||||
nullifier: notes::sapling::Nullifier::from(reader.read_32_bytes()?),
|
||||
rk: reader.read_32_bytes()?.into(),
|
||||
zkproof: Groth16Proof::zcash_deserialize(&mut reader)?,
|
||||
spend_auth_sig: reader.read_64_bytes()?.into(),
|
||||
|
|
Loading…
Reference in New Issue