From ab761f417b214689f5c0b3fb21e7a84b642c4aff Mon Sep 17 00:00:00 2001 From: Constance Beguier Date: Tue, 28 Apr 2026 09:00:39 +0200 Subject: [PATCH 1/4] Create type aliases EnCiphertext and CompactEncCiphertext --- src/bundle.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/bundle.rs b/src/bundle.rs index d7ba7e0f..45a7bb72 100644 --- a/src/bundle.rs +++ b/src/bundle.rs @@ -420,6 +420,9 @@ impl DynamicUsage for OutputDescription { } } +type EncCiphertext = NoteBytesData<{ ENC_CIPHERTEXT_SIZE }>; +type CompactEncCiphertext = NoteBytesData<{ COMPACT_NOTE_SIZE }>; + impl ShieldedOutput for OutputDescription { fn ephemeral_key(&self) -> EphemeralKeyBytes { self.ephemeral_key.clone() @@ -433,11 +436,11 @@ impl ShieldedOutput for OutputDescription { self.cmu.to_bytes() } - fn enc_ciphertext(&self) -> Option<&NoteBytesData<{ ENC_CIPHERTEXT_SIZE }>> { + fn enc_ciphertext(&self) -> Option<&EncCiphertext> { Some(&self.enc_ciphertext) } - fn enc_ciphertext_compact(&self) -> NoteBytesData<{ COMPACT_NOTE_SIZE }> { + fn enc_ciphertext_compact(&self) -> CompactEncCiphertext { unimplemented!("This function is not required for sapling") } } From 044e7e8b42c1292527a0a56c2b94d53290f2be25 Mon Sep 17 00:00:00 2001 From: Constance Beguier Date: Tue, 28 Apr 2026 09:11:09 +0200 Subject: [PATCH 2/4] Implement enc_ciphertext_compact for OutputDescription --- src/bundle.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/bundle.rs b/src/bundle.rs index 45a7bb72..d792afb3 100644 --- a/src/bundle.rs +++ b/src/bundle.rs @@ -441,7 +441,9 @@ impl ShieldedOutput for OutputDescription { } fn enc_ciphertext_compact(&self) -> CompactEncCiphertext { - unimplemented!("This function is not required for sapling") + let mut data = [0u8; COMPACT_NOTE_SIZE]; + data.copy_from_slice(&self.enc_ciphertext.as_ref()[..COMPACT_NOTE_SIZE]); + NoteBytesData(data) } } @@ -501,12 +503,12 @@ impl OutputDescriptionV5 { impl From> for CompactOutputDescription { fn from(out: OutputDescription) -> CompactOutputDescription { + let enc_ciphertext = out.enc_ciphertext_compact().0; + CompactOutputDescription { ephemeral_key: out.ephemeral_key, cmu: out.cmu, - enc_ciphertext: out.enc_ciphertext.as_ref()[..COMPACT_NOTE_SIZE] - .try_into() - .unwrap(), + enc_ciphertext, } } } From 2e3b4e816e3acf0bc5904d1ecd994572a1887914 Mon Sep 17 00:00:00 2001 From: Constance Beguier Date: Tue, 28 Apr 2026 09:34:33 +0200 Subject: [PATCH 3/4] Move type aliases --- src/bundle.rs | 5 +---- src/note_encryption.rs | 7 +++++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/bundle.rs b/src/bundle.rs index d792afb3..5f15c9e7 100644 --- a/src/bundle.rs +++ b/src/bundle.rs @@ -13,7 +13,7 @@ use crate::{ constants::GROTH_PROOF_SIZE, note::ExtractedNoteCommitment, note_encryption::{ - CompactOutputDescription, SaplingDomain, COMPACT_NOTE_SIZE, ENC_CIPHERTEXT_SIZE, + CompactOutputDescription, SaplingDomain, COMPACT_NOTE_SIZE, ENC_CIPHERTEXT_SIZE,EncCiphertext, CompactEncCiphertext }, value::ValueCommitment, Nullifier, @@ -420,9 +420,6 @@ impl DynamicUsage for OutputDescription { } } -type EncCiphertext = NoteBytesData<{ ENC_CIPHERTEXT_SIZE }>; -type CompactEncCiphertext = NoteBytesData<{ COMPACT_NOTE_SIZE }>; - impl ShieldedOutput for OutputDescription { fn ephemeral_key(&self) -> EphemeralKeyBytes { self.ephemeral_key.clone() diff --git a/src/note_encryption.rs b/src/note_encryption.rs index 5305b49d..cd18a9f7 100644 --- a/src/note_encryption.rs +++ b/src/note_encryption.rs @@ -140,6 +140,9 @@ impl SaplingDomain { } } +pub(crate) type EncCiphertext = NoteBytesData<{ ENC_CIPHERTEXT_SIZE }>; +pub(crate) type CompactEncCiphertext = NoteBytesData<{ COMPACT_NOTE_SIZE }>; + impl Domain for SaplingDomain { type EphemeralSecretKey = EphemeralSecretKey; // It is acceptable for this to be a point rather than a byte array, because we @@ -160,9 +163,9 @@ impl Domain for SaplingDomain { type Memo = [u8; MEMO_SIZE]; type NotePlaintextBytes = NoteBytesData<{ NOTE_PLAINTEXT_SIZE }>; - type NoteCiphertextBytes = NoteBytesData<{ ENC_CIPHERTEXT_SIZE }>; + type NoteCiphertextBytes = EncCiphertext; type CompactNotePlaintextBytes = NoteBytesData<{ COMPACT_NOTE_SIZE }>; - type CompactNoteCiphertextBytes = NoteBytesData<{ COMPACT_NOTE_SIZE }>; + type CompactNoteCiphertextBytes = CompactEncCiphertext; fn derive_esk(note: &Self::Note) -> Option { note.derive_esk() From 5ec76a1dea5bd471d86ea4eb021a079fda82dd05 Mon Sep 17 00:00:00 2001 From: Constance Beguier Date: Tue, 28 Apr 2026 11:27:42 +0200 Subject: [PATCH 4/4] rustfmt --- src/bundle.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/bundle.rs b/src/bundle.rs index 5f15c9e7..035c32d2 100644 --- a/src/bundle.rs +++ b/src/bundle.rs @@ -13,7 +13,8 @@ use crate::{ constants::GROTH_PROOF_SIZE, note::ExtractedNoteCommitment, note_encryption::{ - CompactOutputDescription, SaplingDomain, COMPACT_NOTE_SIZE, ENC_CIPHERTEXT_SIZE,EncCiphertext, CompactEncCiphertext + CompactEncCiphertext, CompactOutputDescription, EncCiphertext, SaplingDomain, + COMPACT_NOTE_SIZE, ENC_CIPHERTEXT_SIZE, }, value::ValueCommitment, Nullifier,