From 5258e891dcf9fb2ef3d2e303c8b26f59e0e377b4 Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Fri, 28 Aug 2020 00:32:01 -0400 Subject: [PATCH] Rename sapling::note::OutCiphertext to WrappedNoteKey --- zebra-chain/src/sapling/note.rs | 2 +- zebra-chain/src/sapling/note/arbitrary.rs | 4 ++-- zebra-chain/src/sapling/note/ciphertexts.rs | 26 +++++++++++---------- zebra-chain/src/sapling/output.rs | 8 +++---- zebra-chain/src/sapling/tests/arbitrary.rs | 4 ++-- 5 files changed, 23 insertions(+), 21 deletions(-) diff --git a/zebra-chain/src/sapling/note.rs b/zebra-chain/src/sapling/note.rs index 82936dc09..9789daece 100644 --- a/zebra-chain/src/sapling/note.rs +++ b/zebra-chain/src/sapling/note.rs @@ -19,7 +19,7 @@ use super::{ keys::{Diversifier, TransmissionKey}, }; -pub use ciphertexts::{EncryptedCiphertext, OutCiphertext}; +pub use ciphertexts::{EncryptedNote, WrappedNoteKey}; pub use nullifiers::Nullifier; diff --git a/zebra-chain/src/sapling/note/arbitrary.rs b/zebra-chain/src/sapling/note/arbitrary.rs index 61e39ce4f..e6b38f124 100644 --- a/zebra-chain/src/sapling/note/arbitrary.rs +++ b/zebra-chain/src/sapling/note/arbitrary.rs @@ -2,7 +2,7 @@ use proptest::{arbitrary::any, collection::vec, prelude::*}; use super::*; -impl Arbitrary for EncryptedCiphertext { +impl Arbitrary for EncryptedNote { type Parameters = (); fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy { @@ -18,7 +18,7 @@ impl Arbitrary for EncryptedCiphertext { type Strategy = BoxedStrategy; } -impl Arbitrary for OutCiphertext { +impl Arbitrary for WrappedNoteKey { type Parameters = (); fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy { diff --git a/zebra-chain/src/sapling/note/ciphertexts.rs b/zebra-chain/src/sapling/note/ciphertexts.rs index b7289190b..4f5fe24ef 100644 --- a/zebra-chain/src/sapling/note/ciphertexts.rs +++ b/zebra-chain/src/sapling/note/ciphertexts.rs @@ -55,12 +55,14 @@ impl ZcashDeserialize for EncryptedNote { } /// A ciphertext component for encrypted output notes. +/// +/// Corresponds to Sapling's 'outCiphertext' #[derive(Deserialize, Serialize)] -pub struct OutCiphertext(#[serde(with = "serde_helpers::BigArray")] pub [u8; 80]); +pub struct WrappedNoteKey(#[serde(with = "serde_helpers::BigArray")] pub [u8; 80]); -impl fmt::Debug for OutCiphertext { +impl fmt::Debug for WrappedNoteKey { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.debug_tuple("OutCiphertext") + f.debug_tuple("WrappedNoteKey") .field(&hex::encode(&self.0[..])) .finish() } @@ -68,9 +70,9 @@ impl fmt::Debug for OutCiphertext { // These impls all only exist because of array length restrictions. -impl Copy for OutCiphertext {} +impl Copy for WrappedNoteKey {} -impl Clone for OutCiphertext { +impl Clone for WrappedNoteKey { fn clone(&self) -> Self { let mut bytes = [0; 80]; bytes[..].copy_from_slice(&self.0[..]); @@ -78,22 +80,22 @@ impl Clone for OutCiphertext { } } -impl PartialEq for OutCiphertext { +impl PartialEq for WrappedNoteKey { fn eq(&self, other: &Self) -> bool { self.0[..] == other.0[..] } } -impl Eq for OutCiphertext {} +impl Eq for WrappedNoteKey {} -impl ZcashSerialize for OutCiphertext { +impl ZcashSerialize for WrappedNoteKey { fn zcash_serialize(&self, mut writer: W) -> Result<(), io::Error> { writer.write_all(&self.0[..])?; Ok(()) } } -impl ZcashDeserialize for OutCiphertext { +impl ZcashDeserialize for WrappedNoteKey { fn zcash_deserialize(mut reader: R) -> Result { let mut bytes = [0; 80]; reader.read_exact(&mut bytes[..])?; @@ -117,13 +119,13 @@ proptest! { } #[test] - fn out_ciphertext_roundtrip(oc in any::()) { + fn out_ciphertext_roundtrip(oc in any::()) { let mut data = Vec::new(); - oc.zcash_serialize(&mut data).expect("OutCiphertext should serialize"); + oc.zcash_serialize(&mut data).expect("WrappedNoteKey should serialize"); - let oc2 = OutCiphertext::zcash_deserialize(&data[..]).expect("randomized OutCiphertext should deserialize"); + let oc2 = WrappedNoteKey::zcash_deserialize(&data[..]).expect("randomized WrappedNoteKey should deserialize"); prop_assert_eq![oc, oc2]; } diff --git a/zebra-chain/src/sapling/output.rs b/zebra-chain/src/sapling/output.rs index 8e0bb6072..0cbd252d7 100644 --- a/zebra-chain/src/sapling/output.rs +++ b/zebra-chain/src/sapling/output.rs @@ -20,9 +20,9 @@ pub struct Output { /// An encoding of an ephemeral Jubjub public key. pub ephemeral_key: keys::EphemeralPublicKey, /// A ciphertext component for the encrypted output note. - pub enc_ciphertext: note::EncryptedCiphertext, + pub enc_ciphertext: note::EncryptedNote, /// A ciphertext component for the encrypted output note. - pub out_ciphertext: note::OutCiphertext, + pub out_ciphertext: note::WrappedNoteKey, /// The ZK output proof. pub zkproof: Groth16Proof, } @@ -45,8 +45,8 @@ impl ZcashDeserialize for Output { cv: commitment::ValueCommitment::zcash_deserialize(&mut reader)?, cm_u: jubjub::Fq::zcash_deserialize(&mut reader)?, ephemeral_key: keys::EphemeralPublicKey::zcash_deserialize(&mut reader)?, - enc_ciphertext: note::EncryptedCiphertext::zcash_deserialize(&mut reader)?, - out_ciphertext: note::OutCiphertext::zcash_deserialize(&mut reader)?, + enc_ciphertext: note::EncryptedNote::zcash_deserialize(&mut reader)?, + out_ciphertext: note::WrappedNoteKey::zcash_deserialize(&mut reader)?, zkproof: Groth16Proof::zcash_deserialize(&mut reader)?, }) } diff --git a/zebra-chain/src/sapling/tests/arbitrary.rs b/zebra-chain/src/sapling/tests/arbitrary.rs index 09d450431..aae8edbe8 100644 --- a/zebra-chain/src/sapling/tests/arbitrary.rs +++ b/zebra-chain/src/sapling/tests/arbitrary.rs @@ -44,8 +44,8 @@ impl Arbitrary for Output { any::(), any::(), any::(), - any::(), - any::(), + any::(), + any::(), any::(), ) .prop_map(