From 755802a9d6b0be1eca34506162b5feead178f8a8 Mon Sep 17 00:00:00 2001 From: Dmitry Demin Date: Thu, 8 Aug 2024 12:41:13 +0200 Subject: [PATCH 1/9] Update ShieldedOutput/OutputDescription to return reference for enc_ciphertext These changes were discussed and suggested in PR zcash_note_encryption#2 --- Cargo.lock | 1 - Cargo.toml | 4 ++-- src/bundle.rs | 22 ++++++++++++---------- src/note_encryption.rs | 14 +++++++------- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8cdb636c..13914e34 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1795,7 +1795,6 @@ dependencies = [ [[package]] name = "zcash_note_encryption" version = "0.4.0" -source = "git+https://github.com/QED-it/zcash_note_encryption?branch=zsa1#58384553aab76b2ee6d6eb328cf2187fa824ec9a" dependencies = [ "chacha20", "chacha20poly1305", diff --git a/Cargo.toml b/Cargo.toml index 83a8b92e..c206bbda 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,7 +53,7 @@ bitvec = "1" incrementalmerkletree = { version = "0.5", features = ["legacy-api"] } # Note encryption -zcash_note_encryption = { version = "0.4", features = ["pre-zip-212"] } +zcash_note_encryption = { version = "0.4", path = "../zcash_note_encryption", features = ["pre-zip-212"] } # Secret management subtle = "2.2.3" @@ -104,4 +104,4 @@ name = "pedersen_hash" harness = false [patch.crates-io] -zcash_note_encryption = { version = "0.4", git = "https://github.com/QED-it/zcash_note_encryption", branch = "zsa1" } +#zcash_note_encryption = { version = "0.4", git = "https://github.com/QED-it/zcash_note_encryption", branch = "zsa1" } diff --git a/src/bundle.rs b/src/bundle.rs index ea82a060..4c5ea002 100644 --- a/src/bundle.rs +++ b/src/bundle.rs @@ -321,7 +321,7 @@ pub struct OutputDescription { cv: ValueCommitment, cmu: ExtractedNoteCommitment, ephemeral_key: EphemeralKeyBytes, - enc_ciphertext: [u8; ENC_CIPHERTEXT_SIZE], + enc_ciphertext: NoteBytesData<{ ENC_CIPHERTEXT_SIZE }>, out_ciphertext: [u8; OUT_CIPHERTEXT_SIZE], zkproof: Proof, } @@ -342,7 +342,7 @@ impl OutputDescription { } /// Returns the encrypted note ciphertext. - pub fn enc_ciphertext(&self) -> &[u8; ENC_CIPHERTEXT_SIZE] { + pub fn enc_ciphertext(&self) -> &::NoteCiphertextBytes { &self.enc_ciphertext } @@ -369,7 +369,7 @@ impl OutputDescription { cv, cmu, ephemeral_key, - enc_ciphertext, + enc_ciphertext: NoteBytesData(enc_ciphertext), out_ciphertext, zkproof, } @@ -388,7 +388,7 @@ impl OutputDescription { &mut self.ephemeral_key } pub(crate) fn enc_ciphertext_mut(&mut self) -> &mut [u8; ENC_CIPHERTEXT_SIZE] { - &mut self.enc_ciphertext + &mut self.enc_ciphertext.0 } pub(crate) fn out_ciphertext_mut(&mut self) -> &mut [u8; OUT_CIPHERTEXT_SIZE] { &mut self.out_ciphertext @@ -414,8 +414,8 @@ impl ShieldedOutput for OutputDescription { self.cmu.to_bytes() } - fn enc_ciphertext(&self) -> Option<::NoteCiphertextBytes> { - Some(NoteBytesData(self.enc_ciphertext)) + fn enc_ciphertext(&self) -> Option<&::NoteCiphertextBytes> { + Some(&self.enc_ciphertext) } fn enc_ciphertext_compact(&self) -> ::CompactNoteCiphertextBytes { @@ -470,7 +470,7 @@ impl OutputDescriptionV5 { cv: self.cv, cmu: self.cmu, ephemeral_key: self.ephemeral_key, - enc_ciphertext: self.enc_ciphertext, + enc_ciphertext: NoteBytesData(self.enc_ciphertext), out_ciphertext: self.out_ciphertext, zkproof, } @@ -482,7 +482,9 @@ impl From> for CompactOutputDescription { CompactOutputDescription { ephemeral_key: out.ephemeral_key, cmu: out.cmu, - enc_ciphertext: out.enc_ciphertext[..COMPACT_NOTE_SIZE].try_into().unwrap(), + enc_ciphertext: out.enc_ciphertext.as_ref()[..COMPACT_NOTE_SIZE] + .try_into() + .unwrap(), } } } @@ -509,7 +511,7 @@ pub mod testing { }; use super::{ - Authorized, Bundle, GrothProofBytes, OutputDescription, SpendDescription, + Authorized, Bundle, GrothProofBytes, NoteBytesData, OutputDescription, SpendDescription, ENC_CIPHERTEXT_SIZE, OUT_CIPHERTEXT_SIZE, }; @@ -572,7 +574,7 @@ pub mod testing { cv, cmu, ephemeral_key: epk.to_bytes().into(), - enc_ciphertext, + enc_ciphertext: NoteBytesData(enc_ciphertext), out_ciphertext, zkproof, } diff --git a/src/note_encryption.rs b/src/note_encryption.rs index 2276025f..5bf08704 100644 --- a/src/note_encryption.rs +++ b/src/note_encryption.rs @@ -263,7 +263,7 @@ impl Domain for SaplingDomain { pk_d: &Self::DiversifiedTransmissionKey, plaintext: &Self::CompactNotePlaintextBytes, ) -> Option<(Self::Note, Self::Recipient)> { - sapling_parse_note_plaintext_without_memo(self, &plaintext.0, |diversifier| { + sapling_parse_note_plaintext_without_memo(self, plaintext.as_ref(), |diversifier| { diversifier.g_d().map(|_| *pk_d) }) } @@ -351,7 +351,7 @@ impl ShieldedOutput for CompactOutputDescription { self.cmu.to_bytes() } - fn enc_ciphertext(&self) -> Option<::NoteCiphertextBytes> { + fn enc_ciphertext(&self) -> Option<&::NoteCiphertextBytes> { None } @@ -493,8 +493,8 @@ mod tests { use super::{ prf_ock, sapling_note_encryption, try_sapling_compact_note_decryption, try_sapling_note_decryption, try_sapling_output_recovery, - try_sapling_output_recovery_with_ock, CompactOutputDescription, SaplingDomain, - Zip212Enforcement, + try_sapling_output_recovery_with_ock, CompactOutputDescription, NoteBytesData, + SaplingDomain, Zip212Enforcement, }; use crate::{ @@ -620,7 +620,7 @@ mod tests { cv: &ValueCommitment, cmu: &ExtractedNoteCommitment, ephemeral_key: &EphemeralKeyBytes, - enc_ciphertext: &[u8; ENC_CIPHERTEXT_SIZE], + enc_ciphertext: &NoteBytesData<{ ENC_CIPHERTEXT_SIZE }>, out_ciphertext: &[u8; OUT_CIPHERTEXT_SIZE], modify_plaintext: impl Fn(&mut [u8; NOTE_PLAINTEXT_SIZE]), ) -> [u8; ENC_CIPHERTEXT_SIZE] { @@ -646,14 +646,14 @@ mod tests { let key = shared_secret.kdf_sapling(ephemeral_key); let mut plaintext = [0; NOTE_PLAINTEXT_SIZE]; - plaintext.copy_from_slice(&enc_ciphertext[..NOTE_PLAINTEXT_SIZE]); + plaintext.copy_from_slice(&enc_ciphertext.as_ref()[..NOTE_PLAINTEXT_SIZE]); ChaCha20Poly1305::new(key.as_bytes().into()) .decrypt_in_place_detached( [0u8; 12][..].into(), &[], &mut plaintext, - enc_ciphertext[NOTE_PLAINTEXT_SIZE..].into(), + enc_ciphertext.as_ref()[NOTE_PLAINTEXT_SIZE..].into(), ) .unwrap(); From e07f73d96c346ee9ccad3494f15e253fb12b0989 Mon Sep 17 00:00:00 2001 From: Dmitry Demin Date: Thu, 8 Aug 2024 12:45:20 +0200 Subject: [PATCH 2/9] Fix path zcash_note_encryption in Cargo.toml --- Cargo.lock | 1 + Cargo.toml | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 13914e34..701c849c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1795,6 +1795,7 @@ dependencies = [ [[package]] name = "zcash_note_encryption" version = "0.4.0" +source = "git+https://github.com/QED-it/zcash_note_encryption?branch=return-ref-from-enc-ciphertext#3a54c7281bacf59fe8dcffc6d9b82db60ae465f6" dependencies = [ "chacha20", "chacha20poly1305", diff --git a/Cargo.toml b/Cargo.toml index c206bbda..7ef9a733 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,7 +53,7 @@ bitvec = "1" incrementalmerkletree = { version = "0.5", features = ["legacy-api"] } # Note encryption -zcash_note_encryption = { version = "0.4", path = "../zcash_note_encryption", features = ["pre-zip-212"] } +zcash_note_encryption = { version = "0.4", features = ["pre-zip-212"] } # Secret management subtle = "2.2.3" @@ -104,4 +104,4 @@ name = "pedersen_hash" harness = false [patch.crates-io] -#zcash_note_encryption = { version = "0.4", git = "https://github.com/QED-it/zcash_note_encryption", branch = "zsa1" } +zcash_note_encryption = { version = "0.4", git = "https://github.com/QED-it/zcash_note_encryption", branch = "return-ref-from-enc-ciphertext" } From 8a74ebbe2f8ba8ed7cac488624a937394cc86842 Mon Sep 17 00:00:00 2001 From: Dmitry Demin Date: Tue, 13 Aug 2024 14:40:48 +0200 Subject: [PATCH 3/9] Move COMPACT_NOTE_SIZE, NOTE_PLAINTEXT_SIZE, and ENC_CIPHERTEXT_SIZE constant definitions from zcash_note_encryption to here --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/bundle.rs | 7 ++++--- src/note_encryption.rs | 15 +++++++++++++-- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 701c849c..963f9293 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1795,7 +1795,7 @@ dependencies = [ [[package]] name = "zcash_note_encryption" version = "0.4.0" -source = "git+https://github.com/QED-it/zcash_note_encryption?branch=return-ref-from-enc-ciphertext#3a54c7281bacf59fe8dcffc6d9b82db60ae465f6" +source = "git+https://github.com/QED-it/zcash_note_encryption?branch=zsa1#76745f00551d4442dee11ad64a8400b75132d18f" dependencies = [ "chacha20", "chacha20poly1305", diff --git a/Cargo.toml b/Cargo.toml index 7ef9a733..4551efb4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -104,4 +104,4 @@ name = "pedersen_hash" harness = false [patch.crates-io] -zcash_note_encryption = { version = "0.4", git = "https://github.com/QED-it/zcash_note_encryption", branch = "return-ref-from-enc-ciphertext" } +zcash_note_encryption = { version = "0.4", git = "https://github.com/QED-it/zcash_note_encryption", branch = "zsa1" } diff --git a/src/bundle.rs b/src/bundle.rs index 4c5ea002..61207a0a 100644 --- a/src/bundle.rs +++ b/src/bundle.rs @@ -5,14 +5,15 @@ use memuse::DynamicUsage; use redjubjub::{Binding, SpendAuth}; use zcash_note_encryption::{ - note_bytes::NoteBytesData, Domain, EphemeralKeyBytes, ShieldedOutput, COMPACT_NOTE_SIZE, - ENC_CIPHERTEXT_SIZE, OUT_CIPHERTEXT_SIZE, + note_bytes::NoteBytesData, Domain, EphemeralKeyBytes, ShieldedOutput, OUT_CIPHERTEXT_SIZE, }; use crate::{ circuit::GROTH_PROOF_SIZE, note::ExtractedNoteCommitment, - note_encryption::{CompactOutputDescription, SaplingDomain}, + note_encryption::{ + CompactOutputDescription, SaplingDomain, COMPACT_NOTE_SIZE, ENC_CIPHERTEXT_SIZE, + }, value::ValueCommitment, Nullifier, }; diff --git a/src/note_encryption.rs b/src/note_encryption.rs index 5bf08704..bb44d091 100644 --- a/src/note_encryption.rs +++ b/src/note_encryption.rs @@ -12,10 +12,21 @@ use zcash_note_encryption::{ note_bytes::{NoteBytes, NoteBytesData}, try_compact_note_decryption, try_note_decryption, try_output_recovery_with_ock, try_output_recovery_with_ovk, BatchDomain, Domain, EphemeralKeyBytes, NoteEncryption, - OutPlaintextBytes, OutgoingCipherKey, ShieldedOutput, COMPACT_NOTE_SIZE, ENC_CIPHERTEXT_SIZE, - NOTE_PLAINTEXT_SIZE, OUT_PLAINTEXT_SIZE, + OutPlaintextBytes, OutgoingCipherKey, ShieldedOutput, AEAD_TAG_SIZE, OUT_PLAINTEXT_SIZE, }; +/// The size of a compact note. +pub const COMPACT_NOTE_SIZE: usize = 1 + // version + 11 + // diversifier + 8 + // value + 32; // rseed (or rcm prior to ZIP 212) + +/// The size of [`Domain::NotePlaintextBytes`]. +pub const NOTE_PLAINTEXT_SIZE: usize = COMPACT_NOTE_SIZE + 512; + +/// The size of an encrypted note plaintext. +pub const ENC_CIPHERTEXT_SIZE: usize = NOTE_PLAINTEXT_SIZE + AEAD_TAG_SIZE; + use crate::{ bundle::{GrothProofBytes, OutputDescription}, keys::{ From d2cff18283725a386dcbbb144d02a1eca9c414c7 Mon Sep 17 00:00:00 2001 From: Dmitry Demin Date: Tue, 13 Aug 2024 14:49:34 +0200 Subject: [PATCH 4/9] Trigger CI From eb7293f895c12a5df412d4c28c99cca493af877b Mon Sep 17 00:00:00 2001 From: Dmitry Demin Date: Tue, 13 Aug 2024 15:15:27 +0200 Subject: [PATCH 5/9] Fix CI cargo test errors --- src/note_encryption.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/note_encryption.rs b/src/note_encryption.rs index bb44d091..19e1dec9 100644 --- a/src/note_encryption.rs +++ b/src/note_encryption.rs @@ -497,8 +497,8 @@ mod tests { use rand_core::{CryptoRng, RngCore}; use zcash_note_encryption::{ - batch, EphemeralKeyBytes, NoteEncryption, OutgoingCipherKey, ENC_CIPHERTEXT_SIZE, - NOTE_PLAINTEXT_SIZE, OUT_CIPHERTEXT_SIZE, OUT_PLAINTEXT_SIZE, + batch, EphemeralKeyBytes, NoteEncryption, OutgoingCipherKey, OUT_CIPHERTEXT_SIZE, + OUT_PLAINTEXT_SIZE, }; use super::{ @@ -513,7 +513,7 @@ mod tests { circuit::GROTH_PROOF_SIZE, keys::{DiversifiedTransmissionKey, EphemeralSecretKey, OutgoingViewingKey}, note::ExtractedNoteCommitment, - note_encryption::PreparedIncomingViewingKey, + note_encryption::{PreparedIncomingViewingKey, ENC_CIPHERTEXT_SIZE, NOTE_PLAINTEXT_SIZE}, util::generate_random_rseed, value::{NoteValue, ValueCommitTrapdoor, ValueCommitment}, Diversifier, PaymentAddress, Rseed, SaplingIvk, From 9101e2cc984beaf67ded75ca7f62ed7d1a77dcb6 Mon Sep 17 00:00:00 2001 From: Dmitry Demin Date: Tue, 13 Aug 2024 20:23:50 +0200 Subject: [PATCH 6/9] Use NoteBytesData<{...}> instead of ::... --- src/bundle.rs | 8 ++++---- src/note_encryption.rs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/bundle.rs b/src/bundle.rs index 61207a0a..c3158ff0 100644 --- a/src/bundle.rs +++ b/src/bundle.rs @@ -5,7 +5,7 @@ use memuse::DynamicUsage; use redjubjub::{Binding, SpendAuth}; use zcash_note_encryption::{ - note_bytes::NoteBytesData, Domain, EphemeralKeyBytes, ShieldedOutput, OUT_CIPHERTEXT_SIZE, + note_bytes::NoteBytesData, EphemeralKeyBytes, ShieldedOutput, OUT_CIPHERTEXT_SIZE, }; use crate::{ @@ -343,7 +343,7 @@ impl OutputDescription { } /// Returns the encrypted note ciphertext. - pub fn enc_ciphertext(&self) -> &::NoteCiphertextBytes { + pub fn enc_ciphertext(&self) -> &NoteBytesData<{ ENC_CIPHERTEXT_SIZE }> { &self.enc_ciphertext } @@ -415,11 +415,11 @@ impl ShieldedOutput for OutputDescription { self.cmu.to_bytes() } - fn enc_ciphertext(&self) -> Option<&::NoteCiphertextBytes> { + fn enc_ciphertext(&self) -> Option<&NoteBytesData<{ ENC_CIPHERTEXT_SIZE }>> { Some(&self.enc_ciphertext) } - fn enc_ciphertext_compact(&self) -> ::CompactNoteCiphertextBytes { + fn enc_ciphertext_compact(&self) -> NoteBytesData<{ COMPACT_NOTE_SIZE }> { unimplemented!("This function is not required for sapling") } } diff --git a/src/note_encryption.rs b/src/note_encryption.rs index 19e1dec9..102bacc8 100644 --- a/src/note_encryption.rs +++ b/src/note_encryption.rs @@ -362,11 +362,11 @@ impl ShieldedOutput for CompactOutputDescription { self.cmu.to_bytes() } - fn enc_ciphertext(&self) -> Option<&::NoteCiphertextBytes> { + fn enc_ciphertext(&self) -> Option<&NoteBytesData<{ ENC_CIPHERTEXT_SIZE }>> { None } - fn enc_ciphertext_compact(&self) -> ::CompactNoteCiphertextBytes { + fn enc_ciphertext_compact(&self) -> NoteBytesData<{ COMPACT_NOTE_SIZE }> { NoteBytesData::from_slice(self.enc_ciphertext.as_ref()).unwrap() } } From 335bb345156a39c05ffc103c1f80e457c1fcd17e Mon Sep 17 00:00:00 2001 From: Dmitry Demin Date: Tue, 13 Aug 2024 20:49:49 +0200 Subject: [PATCH 7/9] Add MEMO_SIZE constant and use it instead of the hardcoded 512 for the memo array size --- src/builder.rs | 12 ++++++------ src/note_encryption.rs | 21 ++++++++++++--------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/builder.rs b/src/builder.rs index b3e1fa6d..31b7d2cf 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -15,7 +15,7 @@ use crate::{ }, circuit, keys::{OutgoingViewingKey, SpendAuthorizingKey, SpendValidatingKey}, - note_encryption::{sapling_note_encryption, Zip212Enforcement}, + note_encryption::{sapling_note_encryption, Zip212Enforcement, MEMO_SIZE}, prover::{OutputProver, SpendProver}, util::generate_random_rseed_internal, value::{ @@ -281,7 +281,7 @@ pub struct OutputInfo { ovk: Option, to: PaymentAddress, value: NoteValue, - memo: [u8; 512], + memo: [u8; MEMO_SIZE], } impl OutputInfo { @@ -290,14 +290,14 @@ impl OutputInfo { ovk: Option, to: PaymentAddress, value: NoteValue, - memo: Option<[u8; 512]>, + memo: Option<[u8; MEMO_SIZE]>, ) -> Self { Self { ovk, to, value, memo: memo.unwrap_or_else(|| { - let mut memo = [0; 512]; + let mut memo = [0; MEMO_SIZE]; memo[0] = 0xf6; memo }), @@ -353,7 +353,7 @@ struct PreparedOutputInfo { /// `None` represents the `ovk = ⊥` case. ovk: Option, note: Note, - memo: [u8; 512], + memo: [u8; MEMO_SIZE], rcv: ValueCommitTrapdoor, } @@ -523,7 +523,7 @@ impl Builder { ovk: Option, to: PaymentAddress, value: NoteValue, - memo: Option<[u8; 512]>, + memo: Option<[u8; MEMO_SIZE]>, ) -> Result<(), Error> { let output = OutputInfo::new(ovk, to, value, memo); diff --git a/src/note_encryption.rs b/src/note_encryption.rs index 102bacc8..108ea719 100644 --- a/src/note_encryption.rs +++ b/src/note_encryption.rs @@ -15,6 +15,9 @@ use zcash_note_encryption::{ OutPlaintextBytes, OutgoingCipherKey, ShieldedOutput, AEAD_TAG_SIZE, OUT_PLAINTEXT_SIZE, }; +/// The size of the memo. +pub(crate) const MEMO_SIZE: usize = 512; + /// The size of a compact note. pub const COMPACT_NOTE_SIZE: usize = 1 + // version 11 + // diversifier @@ -22,7 +25,7 @@ pub const COMPACT_NOTE_SIZE: usize = 1 + // version 32; // rseed (or rcm prior to ZIP 212) /// The size of [`Domain::NotePlaintextBytes`]. -pub const NOTE_PLAINTEXT_SIZE: usize = COMPACT_NOTE_SIZE + 512; +pub const NOTE_PLAINTEXT_SIZE: usize = COMPACT_NOTE_SIZE + MEMO_SIZE; /// The size of an encrypted note plaintext. pub const ENC_CIPHERTEXT_SIZE: usize = NOTE_PLAINTEXT_SIZE + AEAD_TAG_SIZE; @@ -154,7 +157,7 @@ impl Domain for SaplingDomain { type ValueCommitment = ValueCommitment; type ExtractedCommitment = ExtractedNoteCommitment; type ExtractedCommitmentBytes = [u8; 32]; - type Memo = [u8; 512]; + type Memo = [u8; MEMO_SIZE]; type NotePlaintextBytes = NoteBytesData<{ NOTE_PLAINTEXT_SIZE }>; type NoteCiphertextBytes = NoteBytesData<{ ENC_CIPHERTEXT_SIZE }>; @@ -408,14 +411,14 @@ impl ShieldedOutput for CompactOutputDescription { /// let note = to.create_note(value, rseed); /// let cmu = note.cmu(); /// -/// let mut enc = sapling_note_encryption(ovk, note, [0x37; 512], &mut rng); +/// let mut enc = sapling_note_encryption(ovk, note, [0x37; MEMO_SIZE], &mut rng); /// let encCiphertext = enc.encrypt_note_plaintext(); /// let outCiphertext = enc.encrypt_outgoing_plaintext(&cv, &cmu, &mut rng); /// ``` pub fn sapling_note_encryption( ovk: Option, note: Note, - memo: [u8; 512], + memo: [u8; MEMO_SIZE], rng: &mut R, ) -> NoteEncryption { let esk = note.generate_or_derive_esk_internal(rng); @@ -436,7 +439,7 @@ pub fn try_sapling_note_decryption>( ivk: &PreparedIncomingViewingKey, output: &Output, zip212_enforcement: Zip212Enforcement, -) -> Option<(Note, PaymentAddress, [u8; 512])> { +) -> Option<(Note, PaymentAddress, [u8; MEMO_SIZE])> { let domain = SaplingDomain::new(zip212_enforcement); try_note_decryption(&domain, ivk, output) } @@ -462,7 +465,7 @@ pub fn try_sapling_output_recovery_with_ock( ock: &OutgoingCipherKey, output: &OutputDescription, zip212_enforcement: Zip212Enforcement, -) -> Option<(Note, PaymentAddress, [u8; 512])> { +) -> Option<(Note, PaymentAddress, [u8; MEMO_SIZE])> { let domain = SaplingDomain::new(zip212_enforcement); try_output_recovery_with_ock(&domain, ock, output, output.out_ciphertext()) } @@ -479,7 +482,7 @@ pub fn try_sapling_output_recovery( ovk: &OutgoingViewingKey, output: &OutputDescription, zip212_enforcement: Zip212Enforcement, -) -> Option<(Note, PaymentAddress, [u8; 512])> { +) -> Option<(Note, PaymentAddress, [u8; MEMO_SIZE])> { let domain = SaplingDomain::new(zip212_enforcement); try_output_recovery_with_ovk(&domain, ovk, output, output.cv(), output.out_ciphertext()) } @@ -505,7 +508,7 @@ mod tests { prf_ock, sapling_note_encryption, try_sapling_compact_note_decryption, try_sapling_note_decryption, try_sapling_output_recovery, try_sapling_output_recovery_with_ock, CompactOutputDescription, NoteBytesData, - SaplingDomain, Zip212Enforcement, + SaplingDomain, Zip212Enforcement, MEMO_SIZE, }; use crate::{ @@ -575,7 +578,7 @@ mod tests { let cmu = note.cmu(); let ovk = OutgoingViewingKey([0; 32]); - let ne = sapling_note_encryption(Some(ovk), note, [0x37; 512], &mut rng); + let ne = sapling_note_encryption(Some(ovk), note, [0x37; MEMO_SIZE], &mut rng); let epk = ne.epk(); let ock = prf_ock(&ovk, &cv, &cmu.to_bytes(), &epk.to_bytes()); From 58552e3c1b768f74d59e77630299404c1e18912f Mon Sep 17 00:00:00 2001 From: Dmitry Demin Date: Tue, 13 Aug 2024 20:55:28 +0200 Subject: [PATCH 8/9] Fix code example in comment to use MEMO_SIZE --- src/note_encryption.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/note_encryption.rs b/src/note_encryption.rs index 108ea719..474c6541 100644 --- a/src/note_encryption.rs +++ b/src/note_encryption.rs @@ -388,7 +388,7 @@ impl ShieldedOutput for CompactOutputDescription { /// use rand_core::OsRng; /// use sapling_crypto::{ /// keys::OutgoingViewingKey, -/// note_encryption::{sapling_note_encryption, Zip212Enforcement}, +/// note_encryption::{sapling_note_encryption, Zip212Enforcement, MEMO_SIZE}, /// util::generate_random_rseed, /// value::{NoteValue, ValueCommitTrapdoor, ValueCommitment}, /// Diversifier, PaymentAddress, Rseed, SaplingIvk, From 62fe679045dc4ffa5e0302f46fe39041c79595eb Mon Sep 17 00:00:00 2001 From: Dmitry Demin Date: Tue, 13 Aug 2024 21:19:02 +0200 Subject: [PATCH 9/9] Make MEMO_SIZE const pub to use it in the comment code example --- src/note_encryption.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/note_encryption.rs b/src/note_encryption.rs index 474c6541..ea2c8027 100644 --- a/src/note_encryption.rs +++ b/src/note_encryption.rs @@ -16,7 +16,7 @@ use zcash_note_encryption::{ }; /// The size of the memo. -pub(crate) const MEMO_SIZE: usize = 512; +pub const MEMO_SIZE: usize = 512; /// The size of a compact note. pub const COMPACT_NOTE_SIZE: usize = 1 + // version