Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
9 changes: 0 additions & 9 deletions components/zcash_note_encryption/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion zcash_client_backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion zcash_client_backend/src/welding_rig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,6 @@ mod tests {
let encryptor = sapling_note_encryption::<_, Network>(
Some(dfvk.fvk().ovk),
note.clone(),
to,
MemoBytes::empty(),
&mut rng,
);
Expand Down
2 changes: 1 addition & 1 deletion zcash_client_sqlite/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
3 changes: 0 additions & 3 deletions zcash_client_sqlite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,6 @@ mod tests {
let encryptor = sapling_note_encryption::<_, Network>(
Some(dfvk.fvk().ovk),
note.clone(),
to,
MemoBytes::empty(),
&mut rng,
);
Expand Down Expand Up @@ -1176,7 +1175,6 @@ mod tests {
let encryptor = sapling_note_encryption::<_, Network>(
Some(dfvk.fvk().ovk),
note.clone(),
to,
MemoBytes::empty(),
&mut rng,
);
Expand Down Expand Up @@ -1205,7 +1203,6 @@ mod tests {
let encryptor = sapling_note_encryption::<_, Network>(
Some(dfvk.fvk().ovk),
note.clone(),
change_addr,
MemoBytes::empty(),
&mut rng,
);
Expand Down
2 changes: 1 addition & 1 deletion zcash_primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
15 changes: 4 additions & 11 deletions zcash_primitives/src/sapling/note_encryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,19 +183,15 @@ 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];
input[0] = match note.rseed() {
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();
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -593,7 +588,6 @@ mod tests {
let ne = sapling_note_encryption::<_, TestNetwork>(
Some(ovk),
note,
pa,
MemoBytes::empty(),
&mut rng,
);
Expand Down Expand Up @@ -1508,7 +1502,6 @@ mod tests {
esk,
Some(ovk),
note,
to,
MemoBytes::from_bytes(&tv.memo).unwrap(),
);

Expand Down
12 changes: 3 additions & 9 deletions zcash_primitives/src/transaction/components/sapling/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -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>(
Expand All @@ -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(),
);
Expand Down