diff --git a/Cargo.toml b/Cargo.toml index 955bb3cc..0d27b4e7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,6 +47,7 @@ plotters = { version = "0.3.0", optional = true } criterion = "0.3" hex = "0.4" proptest = "1.0.0" +zcash_note_encryption = { version = "0.0", features = ["pre-zip-212"] } [target.'cfg(unix)'.dev-dependencies] pprof = { version = "0.5", features = ["criterion", "flamegraph"] } @@ -81,5 +82,5 @@ debug = true debug = true [patch.crates-io] -zcash_note_encryption = { git = "https://github.com/zcash/librustzcash.git", rev = "35e75420657599fdc701cb45704878eb3fa2e59a" } +zcash_note_encryption = { git = "https://github.com/zcash/librustzcash.git", rev = "76f364593a6d5b190dd23d26f8202adcd031b2d3" } incrementalmerkletree = { git = "https://github.com/zcash/incrementalmerkletree.git", rev = "b7bd6246122a6e9ace8edb51553fbf5228906cbb" } diff --git a/src/note_encryption.rs b/src/note_encryption.rs index d6d51063..c0aabfd3 100644 --- a/src/note_encryption.rs +++ b/src/note_encryption.rs @@ -5,8 +5,9 @@ use std::{convert::TryInto, fmt}; use blake2b_simd::{Hash, Params}; use halo2::arithmetic::FieldExt; use zcash_note_encryption::{ - BatchDomain, Domain, EphemeralKeyBytes, NotePlaintextBytes, NoteValidity, OutPlaintextBytes, - OutgoingCipherKey, ShieldedOutput, COMPACT_NOTE_SIZE, NOTE_PLAINTEXT_SIZE, OUT_PLAINTEXT_SIZE, + BatchDomain, Domain, EphemeralKeyBytes, NotePlaintextBytes, OutPlaintextBytes, + OutgoingCipherKey, ShieldedOutput, COMPACT_NOTE_SIZE, ENC_CIPHERTEXT_SIZE, NOTE_PLAINTEXT_SIZE, + OUT_PLAINTEXT_SIZE, }; use crate::{ @@ -182,13 +183,6 @@ impl Domain for OrchardDomain { EphemeralPublicKey::from_bytes(&ephemeral_key.0).into() } - fn check_epk_bytes NoteValidity>( - note: &Self::Note, - check: F, - ) -> NoteValidity { - check(¬e.esk()) - } - fn cmstar(note: &Self::Note) -> Self::ExtractedCommitment { note.commitment().into() } @@ -208,9 +202,9 @@ impl Domain for OrchardDomain { pk_d: &Self::DiversifiedTransmissionKey, esk: &Self::EphemeralSecretKey, ephemeral_key: &EphemeralKeyBytes, - plaintext: &[u8], + plaintext: &NotePlaintextBytes, ) -> Option<(Self::Note, Self::Recipient)> { - orchard_parse_note_plaintext_without_memo(self, plaintext, |diversifier| { + orchard_parse_note_plaintext_without_memo(self, &plaintext.0, |diversifier| { if esk .derive_public(diversify_hash(diversifier.as_array())) .to_bytes() @@ -224,20 +218,18 @@ impl Domain for OrchardDomain { }) } - fn extract_memo(&self, plaintext: &[u8]) -> Self::Memo { - plaintext[COMPACT_NOTE_SIZE..NOTE_PLAINTEXT_SIZE] + fn extract_memo(&self, plaintext: &NotePlaintextBytes) -> Self::Memo { + plaintext.0[COMPACT_NOTE_SIZE..NOTE_PLAINTEXT_SIZE] .try_into() .unwrap() } - fn extract_pk_d( - out_plaintext: &[u8; OUT_PLAINTEXT_SIZE], - ) -> Option { - DiversifiedTransmissionKey::from_bytes(out_plaintext[0..32].try_into().unwrap()).into() + fn extract_pk_d(out_plaintext: &OutPlaintextBytes) -> Option { + DiversifiedTransmissionKey::from_bytes(out_plaintext.0[0..32].try_into().unwrap()).into() } - fn extract_esk(out_plaintext: &[u8; OUT_PLAINTEXT_SIZE]) -> Option { - EphemeralSecretKey::from_bytes(out_plaintext[32..OUT_PLAINTEXT_SIZE].try_into().unwrap()) + fn extract_esk(out_plaintext: &OutPlaintextBytes) -> Option { + EphemeralSecretKey::from_bytes(out_plaintext.0[32..OUT_PLAINTEXT_SIZE].try_into().unwrap()) .into() } } @@ -260,7 +252,7 @@ impl BatchDomain for OrchardDomain { /// Implementation of in-band secret distribution for Orchard bundles. pub type OrchardNoteEncryption = zcash_note_encryption::NoteEncryption; -impl ShieldedOutput for Action { +impl ShieldedOutput for Action { fn ephemeral_key(&self) -> EphemeralKeyBytes { EphemeralKeyBytes(self.encrypted_note().epk_bytes) } @@ -269,7 +261,7 @@ impl ShieldedOutput for Action { self.cmx().to_bytes() } - fn enc_ciphertext(&self) -> &[u8] { + fn enc_ciphertext(&self) -> &[u8; ENC_CIPHERTEXT_SIZE] { &self.encrypted_note().enc_ciphertext } } @@ -299,7 +291,7 @@ impl From<&Action> for CompactAction { } } -impl ShieldedOutput for CompactAction { +impl ShieldedOutput for CompactAction { fn ephemeral_key(&self) -> EphemeralKeyBytes { EphemeralKeyBytes(self.ephemeral_key.0) } @@ -308,7 +300,7 @@ impl ShieldedOutput for CompactAction { self.cmx.to_bytes() } - fn enc_ciphertext(&self) -> &[u8] { + fn enc_ciphertext(&self) -> &[u8; COMPACT_NOTE_SIZE] { &self.enc_ciphertext } }