From 8c018eff7e795b16fc68aed22d0fd4eebe2710ec Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Wed, 17 Nov 2021 12:12:48 +0000 Subject: [PATCH] Migrate to `zcash_note_encryption::BatchDomain` --- Cargo.toml | 2 +- src/note_encryption.rs | 30 ++++++++++++++++-------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f6601004..fd3d9d72 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -84,5 +84,5 @@ debug = true debug = true [patch.crates-io] -zcash_note_encryption = { git = "https://github.com/zcash/librustzcash.git", rev = "13b023387bafdc7b5712c933dc0e16ee94b96a6a" } +zcash_note_encryption = { git = "https://github.com/zcash/librustzcash.git", rev = "35e75420657599fdc701cb45704878eb3fa2e59a" } incrementalmerkletree = { git = "https://github.com/zcash/incrementalmerkletree.git", rev = "b7bd6246122a6e9ace8edb51553fbf5228906cbb" } diff --git a/src/note_encryption.rs b/src/note_encryption.rs index 8053b8bb..d6d51063 100644 --- a/src/note_encryption.rs +++ b/src/note_encryption.rs @@ -5,7 +5,7 @@ use std::{convert::TryInto, fmt}; use blake2b_simd::{Hash, Params}; use halo2::arithmetic::FieldExt; use zcash_note_encryption::{ - Domain, EphemeralKeyBytes, NotePlaintextBytes, NoteValidity, OutPlaintextBytes, + BatchDomain, Domain, EphemeralKeyBytes, NotePlaintextBytes, NoteValidity, OutPlaintextBytes, OutgoingCipherKey, ShieldedOutput, COMPACT_NOTE_SIZE, NOTE_PLAINTEXT_SIZE, OUT_PLAINTEXT_SIZE, }; @@ -141,19 +141,6 @@ impl Domain for OrchardDomain { secret.kdf_orchard(ephemeral_key) } - fn batch_kdf<'a>( - items: impl Iterator, &'a EphemeralKeyBytes)>, - ) -> Vec> { - let (shared_secrets, ephemeral_keys): (Vec<_>, Vec<_>) = items.unzip(); - - SharedSecret::batch_to_affine(shared_secrets) - .zip(ephemeral_keys.into_iter()) - .map(|(secret, ephemeral_key)| { - secret.map(|dhsecret| SharedSecret::kdf_orchard_inner(dhsecret, ephemeral_key)) - }) - .collect() - } - fn note_plaintext_bytes( note: &Self::Note, _: &Self::Recipient, @@ -255,6 +242,21 @@ impl Domain for OrchardDomain { } } +impl BatchDomain for OrchardDomain { + fn batch_kdf<'a>( + items: impl Iterator, &'a EphemeralKeyBytes)>, + ) -> Vec> { + let (shared_secrets, ephemeral_keys): (Vec<_>, Vec<_>) = items.unzip(); + + SharedSecret::batch_to_affine(shared_secrets) + .zip(ephemeral_keys.into_iter()) + .map(|(secret, ephemeral_key)| { + secret.map(|dhsecret| SharedSecret::kdf_orchard_inner(dhsecret, ephemeral_key)) + }) + .collect() + } +} + /// Implementation of in-band secret distribution for Orchard bundles. pub type OrchardNoteEncryption = zcash_note_encryption::NoteEncryption;