Skip to content

Commit

Permalink
zcash_note_encryption: Remove Domain::check_epk_bytes
Browse files Browse the repository at this point in the history
`Domain::derive_esk` provides sufficient information to determine
whether or not we need to enforce `EphemeralSecretKey`-specific
decryption checks, as it returns `None` for pre-ZIP 212 notes.
  • Loading branch information
str4d committed Dec 17, 2021
1 parent 7c1687d commit d54e1f0
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions components/zcash_note_encryption/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub struct NotePlaintextBytes(pub [u8; NOTE_PLAINTEXT_SIZE]);
pub struct OutPlaintextBytes(pub [u8; OUT_PLAINTEXT_SIZE]);

#[derive(Copy, Clone, PartialEq, Eq)]
pub enum NoteValidity {
enum NoteValidity {
Valid,
Invalid,
}
Expand Down Expand Up @@ -148,11 +148,6 @@ pub trait Domain {

fn epk(ephemeral_key: &EphemeralKeyBytes) -> Option<Self::EphemeralPublicKey>;

fn check_epk_bytes<F: Fn(&Self::EphemeralSecretKey) -> NoteValidity>(
note: &Self::Note,
check: F,
) -> NoteValidity;

fn cmstar(note: &Self::Note) -> Self::ExtractedCommitment;

fn parse_note_plaintext_without_memo_ivk(
Expand Down Expand Up @@ -464,7 +459,7 @@ fn check_note_validity<D: Domain>(
cmstar_bytes: &D::ExtractedCommitmentBytes,
) -> NoteValidity {
if &D::ExtractedCommitmentBytes::from(&D::cmstar(&note)) == cmstar_bytes {
D::check_epk_bytes(&note, |derived_esk| {
if let Some(derived_esk) = D::derive_esk(note) {
if D::epk_bytes(&D::ka_derive_public(&note, &derived_esk))
.ct_eq(&ephemeral_key)
.into()
Expand All @@ -473,7 +468,10 @@ fn check_note_validity<D: Domain>(
} else {
NoteValidity::Invalid
}
})
} else {
// Before ZIP 212
NoteValidity::Valid
}
} else {
// Published commitment doesn't match calculated commitment
NoteValidity::Invalid
Expand Down

0 comments on commit d54e1f0

Please sign in to comment.