Merge pull request #790 from zcash/sapling/zcash_note_encryption-0.3.0

Update zcash_primitives to use zcash_note_encryption 0.3.0
This commit is contained in:
Kris Nuttycombe 2023-03-21 15:39:05 -06:00 committed by GitHub
commit ca349b62fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 12 additions and 37 deletions

View File

@ -20,6 +20,7 @@ codegen-units = 1
[patch.crates-io]
zcash_encoding = { path = "components/zcash_encoding" }
orchard = { git = "https://github.com/zcash/orchard.git", rev = "6cbde279e90974201bedbd9b5ddf155e8f8b1e8e" }
zcash_note_encryption = { path = "components/zcash_note_encryption" }
orchard = { git = "https://github.com/zcash/orchard.git", rev = "dca33119b4d082048a098e9fdc0c87c508ed056e" }
halo2_gadgets = { git = "https://github.com/zcash/halo2.git", rev = "642924d614305d882cc122739c59144109f4bd3f" }
halo2_proofs = { git = "https://github.com/zcash/halo2.git", rev = "642924d614305d882cc122739c59144109f4bd3f" }

View File

@ -171,15 +171,6 @@ pub trait Domain {
fn kdf(secret: Self::SharedSecret, ephemeral_key: &EphemeralKeyBytes) -> Self::SymmetricKey;
/// Encodes the given `Note` and `Memo` as a note plaintext.
///
/// # Future breaking changes
///
/// The `recipient` argument is present as a secondary way to obtain the diversifier;
/// this is due to a historical quirk of how the Sapling `Note` struct was implemented
/// in the `zcash_primitives` crate. `recipient` will be removed from this method in a
/// future crate release, once [`zcash_primitives` has been refactored].
///
/// [`zcash_primitives` has been refactored]: https://github.com/zcash/librustzcash/issues/454
fn note_plaintext_bytes(note: &Self::Note, memo: &Self::Memo) -> NotePlaintextBytes;
/// Derives the [`OutgoingCipherKey`] for an encrypted note, given the note-specific

View File

@ -22,7 +22,7 @@ development = ["zcash_proofs"]
[dependencies]
zcash_address = { version = "0.2", path = "../components/zcash_address" }
zcash_encoding = { version = "0.2", path = "../components/zcash_encoding" }
zcash_note_encryption = "0.2"
zcash_note_encryption = "0.3"
zcash_primitives = { version = "0.10", path = "../zcash_primitives", default-features = false }
# Dependencies exposed in a public API:

View File

@ -470,7 +470,6 @@ mod tests {
let encryptor = sapling_note_encryption::<_, Network>(
Some(dfvk.fvk().ovk),
note.clone(),
to,
MemoBytes::empty(),
&mut rng,
);

View File

@ -50,7 +50,7 @@ proptest = "1.0.0"
rand_core = "0.6"
regex = "1.4"
tempfile = "3"
zcash_note_encryption = "0.2"
zcash_note_encryption = "0.3"
zcash_proofs = { version = "0.10", path = "../zcash_proofs" }
zcash_primitives = { version = "0.10", path = "../zcash_primitives", features = ["test-dependencies"] }
zcash_address = { version = "0.2", path = "../components/zcash_address", features = ["test-dependencies"] }

View File

@ -1114,7 +1114,6 @@ mod tests {
let encryptor = sapling_note_encryption::<_, Network>(
Some(dfvk.fvk().ovk),
note.clone(),
to,
MemoBytes::empty(),
&mut rng,
);
@ -1176,7 +1175,6 @@ mod tests {
let encryptor = sapling_note_encryption::<_, Network>(
Some(dfvk.fvk().ovk),
note.clone(),
to,
MemoBytes::empty(),
&mut rng,
);
@ -1205,7 +1203,6 @@ mod tests {
let encryptor = sapling_note_encryption::<_, Network>(
Some(dfvk.fvk().ovk),
note.clone(),
change_addr,
MemoBytes::empty(),
&mut rng,
);

View File

@ -80,7 +80,7 @@ aes = "0.7"
fpe = "0.5"
[dependencies.zcash_note_encryption]
version = "0.2"
version = "0.3"
features = ["pre-zip-212"]
[dev-dependencies]

View File

@ -183,11 +183,7 @@ impl<P: consensus::Parameters> Domain for SaplingDomain<P> {
dhsecret.kdf_sapling(epk)
}
fn note_plaintext_bytes(
note: &Self::Note,
to: &Self::Recipient,
memo: &Self::Memo,
) -> NotePlaintextBytes {
fn note_plaintext_bytes(note: &Self::Note, memo: &Self::Memo) -> NotePlaintextBytes {
// Note plaintext encoding is defined in section 5.5 of the Zcash Protocol
// Specification.
let mut input = [0; NOTE_PLAINTEXT_SIZE];
@ -195,7 +191,7 @@ impl<P: consensus::Parameters> Domain for SaplingDomain<P> {
Rseed::BeforeZip212(_) => 1,
Rseed::AfterZip212(_) => 2,
};
input[1..12].copy_from_slice(&to.diversifier().0);
input[1..12].copy_from_slice(&note.recipient().diversifier().0);
(&mut input[12..20])
.write_u64::<LittleEndian>(note.value().inner())
.unwrap();
@ -368,19 +364,18 @@ impl<P: consensus::Parameters> BatchDomain for SaplingDomain<P> {
/// let note = to.create_note(value.inner(), rseed);
/// let cmu = note.cmu();
///
/// let mut enc = sapling_note_encryption::<_, TestNetwork>(ovk, note, to, MemoBytes::empty(), &mut rng);
/// let mut enc = sapling_note_encryption::<_, TestNetwork>(ovk, note, MemoBytes::empty(), &mut rng);
/// let encCiphertext = enc.encrypt_note_plaintext();
/// let outCiphertext = enc.encrypt_outgoing_plaintext(&cv, &cmu, &mut rng);
/// ```
pub fn sapling_note_encryption<R: RngCore, P: consensus::Parameters>(
ovk: Option<OutgoingViewingKey>,
note: Note,
to: PaymentAddress,
memo: MemoBytes,
rng: &mut R,
) -> NoteEncryption<SaplingDomain<P>> {
let esk = note.generate_or_derive_esk_internal(rng);
NoteEncryption::new_with_esk(esk, ovk, note, to, memo)
NoteEncryption::new_with_esk(esk, ovk, note, memo)
}
#[allow(clippy::if_same_then_else)]
@ -593,7 +588,6 @@ mod tests {
let ne = sapling_note_encryption::<_, TestNetwork>(
Some(ovk),
note,
pa,
MemoBytes::empty(),
&mut rng,
);
@ -1508,7 +1502,6 @@ mod tests {
esk,
Some(ovk),
note,
to,
MemoBytes::from_bytes(&tv.memo).unwrap(),
);

View File

@ -88,7 +88,6 @@ impl fees::InputView<()> for SpendDescriptionInfo {
struct SaplingOutputInfo {
/// `None` represents the `ovk = ⊥` case.
ovk: Option<OutgoingViewingKey>,
to: PaymentAddress,
note: Note,
memo: MemoBytes,
}
@ -107,12 +106,7 @@ impl SaplingOutputInfo {
let note = Note::from_parts(to, value, rseed);
SaplingOutputInfo {
ovk,
to,
note,
memo,
}
SaplingOutputInfo { ovk, note, memo }
}
fn build<P: consensus::Parameters, Pr: TxProver, R: RngCore>(
@ -122,12 +116,12 @@ impl SaplingOutputInfo {
rng: &mut R,
) -> OutputDescription<GrothProofBytes> {
let encryptor =
sapling_note_encryption::<R, P>(self.ovk, self.note.clone(), self.to, self.memo, rng);
sapling_note_encryption::<R, P>(self.ovk, self.note.clone(), self.memo, rng);
let (zkproof, cv) = prover.output_proof(
ctx,
encryptor.esk().0,
self.to,
self.note.recipient(),
self.note.rcm(),
self.note.value().inner(),
);