Merge pull request #394 from zcash/note-encryption-avoid-redundant-checks

Remove redundant checks during note encryption
This commit is contained in:
Kris Nuttycombe 2023-05-26 09:13:20 -06:00 committed by GitHub
commit 729def6c60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 19 deletions

View File

@ -17,7 +17,6 @@ use crate::{
OutgoingViewingKey, PreparedEphemeralPublicKey, PreparedIncomingViewingKey, SharedSecret, OutgoingViewingKey, PreparedEphemeralPublicKey, PreparedIncomingViewingKey, SharedSecret,
}, },
note::{ExtractedNoteCommitment, Nullifier, RandomSeed}, note::{ExtractedNoteCommitment, Nullifier, RandomSeed},
spec::diversify_hash,
value::{NoteValue, ValueCommitment}, value::{NoteValue, ValueCommitment},
Address, Note, Address, Note,
}; };
@ -52,10 +51,10 @@ pub(crate) fn prf_ock_orchard(
fn orchard_parse_note_plaintext_without_memo<F>( fn orchard_parse_note_plaintext_without_memo<F>(
domain: &OrchardDomain, domain: &OrchardDomain,
plaintext: &[u8], plaintext: &[u8],
get_validated_pk_d: F, get_pk_d: F,
) -> Option<(Note, Address)> ) -> Option<(Note, Address)>
where where
F: FnOnce(&Diversifier) -> Option<DiversifiedTransmissionKey>, F: FnOnce(&Diversifier) -> DiversifiedTransmissionKey,
{ {
assert!(plaintext.len() >= COMPACT_NOTE_SIZE); assert!(plaintext.len() >= COMPACT_NOTE_SIZE);
@ -72,7 +71,7 @@ where
&domain.rho, &domain.rho,
))?; ))?;
let pk_d = get_validated_pk_d(&diversifier)?; let pk_d = get_pk_d(&diversifier);
let recipient = Address::from_parts(diversifier, pk_d); let recipient = Address::from_parts(diversifier, pk_d);
let note = Option::from(Note::from_parts(recipient, value, domain.rho, rseed))?; let note = Option::from(Note::from_parts(recipient, value, domain.rho, rseed))?;
@ -209,29 +208,18 @@ impl Domain for OrchardDomain {
plaintext: &[u8], plaintext: &[u8],
) -> Option<(Self::Note, Self::Recipient)> { ) -> Option<(Self::Note, Self::Recipient)> {
orchard_parse_note_plaintext_without_memo(self, plaintext, |diversifier| { orchard_parse_note_plaintext_without_memo(self, plaintext, |diversifier| {
Some(DiversifiedTransmissionKey::derive(ivk, diversifier)) DiversifiedTransmissionKey::derive(ivk, diversifier)
}) })
} }
fn parse_note_plaintext_without_memo_ovk( fn parse_note_plaintext_without_memo_ovk(
&self, &self,
pk_d: &Self::DiversifiedTransmissionKey, pk_d: &Self::DiversifiedTransmissionKey,
esk: &Self::EphemeralSecretKey, _esk: &Self::EphemeralSecretKey,
ephemeral_key: &EphemeralKeyBytes, _ephemeral_key: &EphemeralKeyBytes,
plaintext: &NotePlaintextBytes, plaintext: &NotePlaintextBytes,
) -> Option<(Self::Note, Self::Recipient)> { ) -> Option<(Self::Note, Self::Recipient)> {
orchard_parse_note_plaintext_without_memo(self, &plaintext.0, |diversifier| { orchard_parse_note_plaintext_without_memo(self, &plaintext.0, |_| *pk_d)
if esk
.derive_public(diversify_hash(diversifier.as_array()))
.to_bytes()
.0
== ephemeral_key.0
{
Some(*pk_d)
} else {
None
}
})
} }
fn extract_memo(&self, plaintext: &NotePlaintextBytes) -> Self::Memo { fn extract_memo(&self, plaintext: &NotePlaintextBytes) -> Self::Memo {