Remove Zcash(De)Serialize impls for *Commitments
This commit is contained in:
parent
014afd8e4a
commit
5d13880461
|
|
@ -7,7 +7,7 @@ mod test_vectors;
|
|||
|
||||
pub mod pedersen_hashes;
|
||||
|
||||
use std::{fmt, io};
|
||||
use std::fmt;
|
||||
|
||||
use bitvec::prelude::*;
|
||||
use rand_core::{CryptoRng, RngCore};
|
||||
|
|
@ -15,7 +15,6 @@ use rand_core::{CryptoRng, RngCore};
|
|||
use crate::{
|
||||
keys::sapling::{find_group_hash, Diversifier, TransmissionKey},
|
||||
serde_helpers,
|
||||
serialization::{ReadZcashExt, SerializationError, ZcashDeserialize, ZcashSerialize},
|
||||
types::amount::{Amount, NonNegative},
|
||||
};
|
||||
|
||||
|
|
@ -58,21 +57,6 @@ impl From<NoteCommitment> for [u8; 32] {
|
|||
|
||||
impl Eq for NoteCommitment {}
|
||||
|
||||
impl ZcashSerialize for NoteCommitment {
|
||||
fn zcash_serialize<W: io::Write>(&self, mut writer: W) -> Result<(), io::Error> {
|
||||
writer.write_all(&self.0.to_bytes())?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl ZcashDeserialize for NoteCommitment {
|
||||
fn zcash_deserialize<R: io::Read>(mut reader: R) -> Result<Self, SerializationError> {
|
||||
Ok(Self(
|
||||
jubjub::AffinePoint::from_bytes(reader.read_32_bytes()?).unwrap(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl NoteCommitment {
|
||||
/// Generate a new _NoteCommitment_ and the randomness used to create it.
|
||||
///
|
||||
|
|
@ -132,7 +116,7 @@ impl NoteCommitment {
|
|||
/// Output Descriptions.
|
||||
///
|
||||
/// https://zips.z.cash/protocol/protocol.pdf#concretehomomorphiccommit
|
||||
#[derive(Clone, Deserialize, PartialEq, Serialize)]
|
||||
#[derive(Clone, Copy, Deserialize, PartialEq, Serialize)]
|
||||
pub struct ValueCommitment(#[serde(with = "serde_helpers::AffinePoint")] pub jubjub::AffinePoint);
|
||||
|
||||
impl fmt::Debug for ValueCommitment {
|
||||
|
|
@ -144,6 +128,10 @@ impl fmt::Debug for ValueCommitment {
|
|||
}
|
||||
}
|
||||
|
||||
/// LEBS2OSP256(repr_J(cv))
|
||||
///
|
||||
/// https://zips.z.cash/protocol/protocol.pdf#spendencoding
|
||||
/// https://zips.z.cash/protocol/protocol.pdf#jubjub
|
||||
impl From<[u8; 32]> for ValueCommitment {
|
||||
fn from(bytes: [u8; 32]) -> Self {
|
||||
Self(jubjub::AffinePoint::from_bytes(bytes).unwrap())
|
||||
|
|
@ -158,28 +146,13 @@ impl From<jubjub::ExtendedPoint> for ValueCommitment {
|
|||
|
||||
impl Eq for ValueCommitment {}
|
||||
|
||||
impl From<ValueCommitment> for [u8; 32] {
|
||||
fn from(cm: ValueCommitment) -> [u8; 32] {
|
||||
cm.0.to_bytes()
|
||||
}
|
||||
}
|
||||
|
||||
/// LEBS2OSP256(repr_J(cv))
|
||||
///
|
||||
/// https://zips.z.cash/protocol/protocol.pdf#spendencoding
|
||||
/// https://zips.z.cash/protocol/protocol.pdf#jubjub
|
||||
impl ZcashSerialize for ValueCommitment {
|
||||
fn zcash_serialize<W: io::Write>(&self, mut writer: W) -> Result<(), io::Error> {
|
||||
writer.write_all(&self.0.to_bytes())?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl ZcashDeserialize for ValueCommitment {
|
||||
fn zcash_deserialize<R: io::Read>(mut reader: R) -> Result<Self, SerializationError> {
|
||||
Ok(Self(
|
||||
jubjub::AffinePoint::from_bytes(reader.read_32_bytes()?).unwrap(),
|
||||
))
|
||||
impl From<ValueCommitment> for [u8; 32] {
|
||||
fn from(cm: ValueCommitment) -> [u8; 32] {
|
||||
cm.0.to_bytes()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
#![allow(clippy::unit_arg)]
|
||||
#![allow(dead_code)]
|
||||
|
||||
use std::io;
|
||||
|
|
@ -40,6 +39,7 @@ fn prf_nf(a_sk: [u8; 32], rho: [u8; 32]) -> [u8; 32] {
|
|||
/// Nullifier seed, named rho in the [spec][ps].
|
||||
///
|
||||
/// [ps]: https://zips.z.cash/protocol/protocol.pdf#sproutkeycomponents
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
#[cfg_attr(test, derive(proptest_derive::Arbitrary))]
|
||||
pub struct NullifierSeed(pub(crate) [u8; 32]);
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use std::{
|
|||
};
|
||||
|
||||
use crate::{
|
||||
commitments, notes,
|
||||
notes,
|
||||
proofs::ZkSnarkProof,
|
||||
serialization::{
|
||||
ReadZcashExt, SerializationError, WriteZcashExt, ZcashDeserialize, ZcashSerialize,
|
||||
|
|
@ -321,7 +321,7 @@ impl<P: ZkSnarkProof> ZcashDeserialize for Option<JoinSplitData<P>> {
|
|||
|
||||
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(&<[u8; 32]>::from(self.cv)[..])?;
|
||||
writer.write_all(&self.anchor.0[..])?;
|
||||
self.nullifier.zcash_serialize(&mut writer)?;
|
||||
writer.write_all(&<[u8; 32]>::from(self.rk)[..])?;
|
||||
|
|
@ -335,7 +335,7 @@ impl ZcashDeserialize for Spend {
|
|||
fn zcash_deserialize<R: io::Read>(mut reader: R) -> Result<Self, SerializationError> {
|
||||
use crate::treestate::note_commitment_tree::SaplingNoteTreeRootHash;
|
||||
Ok(Spend {
|
||||
cv: commitments::sapling::ValueCommitment::zcash_deserialize(&mut reader)?,
|
||||
cv: reader.read_32_bytes()?.into(),
|
||||
anchor: SaplingNoteTreeRootHash(reader.read_32_bytes()?),
|
||||
nullifier: notes::sapling::Nullifier::zcash_deserialize(&mut reader)?,
|
||||
rk: reader.read_32_bytes()?.into(),
|
||||
|
|
@ -347,7 +347,7 @@ impl ZcashDeserialize for Spend {
|
|||
|
||||
impl ZcashSerialize for Output {
|
||||
fn zcash_serialize<W: io::Write>(&self, mut writer: W) -> Result<(), io::Error> {
|
||||
self.cv.zcash_serialize(&mut writer)?;
|
||||
writer.write_all(&<[u8; 32]>::from(self.cv)[..])?;
|
||||
writer.write_all(&self.cm_u.to_bytes())?;
|
||||
writer.write_all(&self.ephemeral_key.to_bytes())?;
|
||||
self.enc_ciphertext.zcash_serialize(&mut writer)?;
|
||||
|
|
@ -360,7 +360,7 @@ impl ZcashSerialize for Output {
|
|||
impl ZcashDeserialize for Output {
|
||||
fn zcash_deserialize<R: io::Read>(mut reader: R) -> Result<Self, SerializationError> {
|
||||
Ok(Output {
|
||||
cv: commitments::sapling::ValueCommitment::zcash_deserialize(&mut reader)?,
|
||||
cv: reader.read_32_bytes()?.into(),
|
||||
cm_u: jubjub::Fq::from_bytes(&reader.read_32_bytes()?).unwrap(),
|
||||
ephemeral_key: jubjub::AffinePoint::from_bytes(reader.read_32_bytes()?).unwrap(),
|
||||
enc_ciphertext: notes::sapling::EncryptedCiphertext::zcash_deserialize(&mut reader)?,
|
||||
|
|
|
|||
Loading…
Reference in New Issue