Migrate to latest `zcash_note_encryption` API
This commit is contained in:
parent
76f364593a
commit
e148ca84ba
|
@ -20,7 +20,7 @@ codegen-units = 1
|
|||
|
||||
[patch.crates-io]
|
||||
# In development.
|
||||
orchard = { git = "https://github.com/zcash/orchard.git", rev = "8c018eff7e795b16fc68aed22d0fd4eebe2710ec" }
|
||||
orchard = { git = "https://github.com/zcash/orchard.git", rev = "4b0b32275fe941b28cdfe632d2748453e6c32fbb" }
|
||||
incrementalmerkletree = { git = "https://github.com/zcash/incrementalmerkletree.git", rev = "b7bd6246122a6e9ace8edb51553fbf5228906cbb" }
|
||||
zcash_encoding = { path = "components/zcash_encoding" }
|
||||
zcash_note_encryption = { path = "components/zcash_note_encryption" }
|
||||
|
|
|
@ -127,7 +127,7 @@ impl TryFrom<compact_formats::CompactOutput> for CompactOutputDescription {
|
|||
Ok(CompactOutputDescription {
|
||||
cmu: value.cmu()?,
|
||||
ephemeral_key: value.ephemeral_key()?,
|
||||
enc_ciphertext: value.ciphertext,
|
||||
enc_ciphertext: value.ciphertext.try_into().map_err(|_| ())?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ use ff::PrimeField;
|
|||
use std::collections::HashSet;
|
||||
use std::convert::TryFrom;
|
||||
use subtle::{ConditionallySelectable, ConstantTimeEq, CtOption};
|
||||
use zcash_note_encryption::ShieldedOutput;
|
||||
use zcash_note_encryption::{ShieldedOutput, COMPACT_NOTE_SIZE};
|
||||
use zcash_primitives::{
|
||||
consensus::{self, BlockHeight},
|
||||
merkle_tree::{CommitmentTree, IncrementalWitness},
|
||||
|
@ -109,7 +109,10 @@ pub trait ScanningKey {
|
|||
|
||||
/// Attempts to decrypt a Sapling note and payment address
|
||||
/// from the specified ciphertext using this scanning key.
|
||||
fn try_decryption<P: consensus::Parameters, Output: ShieldedOutput<SaplingDomain<P>>>(
|
||||
fn try_decryption<
|
||||
P: consensus::Parameters,
|
||||
Output: ShieldedOutput<SaplingDomain<P>, COMPACT_NOTE_SIZE>,
|
||||
>(
|
||||
&self,
|
||||
params: &P,
|
||||
height: BlockHeight,
|
||||
|
@ -131,7 +134,10 @@ pub trait ScanningKey {
|
|||
impl ScanningKey for ExtendedFullViewingKey {
|
||||
type Nf = Nullifier;
|
||||
|
||||
fn try_decryption<P: consensus::Parameters, Output: ShieldedOutput<SaplingDomain<P>>>(
|
||||
fn try_decryption<
|
||||
P: consensus::Parameters,
|
||||
Output: ShieldedOutput<SaplingDomain<P>, COMPACT_NOTE_SIZE>,
|
||||
>(
|
||||
&self,
|
||||
params: &P,
|
||||
height: BlockHeight,
|
||||
|
@ -152,7 +158,10 @@ impl ScanningKey for ExtendedFullViewingKey {
|
|||
impl ScanningKey for SaplingIvk {
|
||||
type Nf = ();
|
||||
|
||||
fn try_decryption<P: consensus::Parameters, Output: ShieldedOutput<SaplingDomain<P>>>(
|
||||
fn try_decryption<
|
||||
P: consensus::Parameters,
|
||||
Output: ShieldedOutput<SaplingDomain<P>, COMPACT_NOTE_SIZE>,
|
||||
>(
|
||||
&self,
|
||||
params: &P,
|
||||
height: BlockHeight,
|
||||
|
|
|
@ -10,8 +10,8 @@ use std::convert::TryInto;
|
|||
use zcash_note_encryption::{
|
||||
try_compact_note_decryption, try_note_decryption, try_output_recovery_with_ock,
|
||||
try_output_recovery_with_ovk, BatchDomain, Domain, EphemeralKeyBytes, NoteEncryption,
|
||||
NotePlaintextBytes, NoteValidity, OutPlaintextBytes, OutgoingCipherKey, ShieldedOutput,
|
||||
COMPACT_NOTE_SIZE, NOTE_PLAINTEXT_SIZE, OUT_PLAINTEXT_SIZE,
|
||||
NotePlaintextBytes, OutPlaintextBytes, OutgoingCipherKey, ShieldedOutput, COMPACT_NOTE_SIZE,
|
||||
ENC_CIPHERTEXT_SIZE, NOTE_PLAINTEXT_SIZE, OUT_PLAINTEXT_SIZE,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
|
@ -247,18 +247,6 @@ impl<P: consensus::Parameters> Domain for SaplingDomain<P> {
|
|||
jubjub::ExtendedPoint::from_bytes(&ephemeral_key.0).into()
|
||||
}
|
||||
|
||||
fn check_epk_bytes<F: FnOnce(&Self::EphemeralSecretKey) -> NoteValidity>(
|
||||
note: &Note,
|
||||
check: F,
|
||||
) -> NoteValidity {
|
||||
if let Some(derived_esk) = note.derive_esk() {
|
||||
check(&derived_esk)
|
||||
} else {
|
||||
// Before ZIP 212
|
||||
NoteValidity::Valid
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_note_plaintext_without_memo_ivk(
|
||||
&self,
|
||||
ivk: &Self::IncomingViewingKey,
|
||||
|
@ -274,9 +262,9 @@ impl<P: consensus::Parameters> Domain for SaplingDomain<P> {
|
|||
pk_d: &Self::DiversifiedTransmissionKey,
|
||||
esk: &Self::EphemeralSecretKey,
|
||||
ephemeral_key: &EphemeralKeyBytes,
|
||||
plaintext: &[u8],
|
||||
plaintext: &NotePlaintextBytes,
|
||||
) -> Option<(Self::Note, Self::Recipient)> {
|
||||
sapling_parse_note_plaintext_without_memo(&self, plaintext, |diversifier| {
|
||||
sapling_parse_note_plaintext_without_memo(&self, &plaintext.0, |diversifier| {
|
||||
if (diversifier.g_d()? * esk).to_bytes() == ephemeral_key.0 {
|
||||
Some(*pk_d)
|
||||
} else {
|
||||
|
@ -289,29 +277,24 @@ impl<P: consensus::Parameters> Domain for SaplingDomain<P> {
|
|||
note.cmu()
|
||||
}
|
||||
|
||||
fn extract_pk_d(op: &[u8; OUT_PLAINTEXT_SIZE]) -> Option<Self::DiversifiedTransmissionKey> {
|
||||
let pk_d = jubjub::SubgroupPoint::from_bytes(
|
||||
op[0..32].try_into().expect("slice is the correct length"),
|
||||
);
|
||||
|
||||
if pk_d.is_none().into() {
|
||||
None
|
||||
} else {
|
||||
Some(pk_d.unwrap())
|
||||
}
|
||||
fn extract_pk_d(op: &OutPlaintextBytes) -> Option<Self::DiversifiedTransmissionKey> {
|
||||
jubjub::SubgroupPoint::from_bytes(
|
||||
op.0[0..32].try_into().expect("slice is the correct length"),
|
||||
)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn extract_esk(op: &[u8; OUT_PLAINTEXT_SIZE]) -> Option<Self::EphemeralSecretKey> {
|
||||
fn extract_esk(op: &OutPlaintextBytes) -> Option<Self::EphemeralSecretKey> {
|
||||
jubjub::Fr::from_repr(
|
||||
op[32..OUT_PLAINTEXT_SIZE]
|
||||
op.0[32..OUT_PLAINTEXT_SIZE]
|
||||
.try_into()
|
||||
.expect("slice is the correct length"),
|
||||
)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn extract_memo(&self, plaintext: &[u8]) -> Self::Memo {
|
||||
MemoBytes::from_bytes(&plaintext[COMPACT_NOTE_SIZE..NOTE_PLAINTEXT_SIZE]).unwrap()
|
||||
fn extract_memo(&self, plaintext: &NotePlaintextBytes) -> Self::Memo {
|
||||
MemoBytes::from_bytes(&plaintext.0[COMPACT_NOTE_SIZE..NOTE_PLAINTEXT_SIZE]).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -404,7 +387,7 @@ pub fn plaintext_version_is_valid<P: consensus::Parameters>(
|
|||
|
||||
pub fn try_sapling_note_decryption<
|
||||
P: consensus::Parameters,
|
||||
Output: ShieldedOutput<SaplingDomain<P>>,
|
||||
Output: ShieldedOutput<SaplingDomain<P>, ENC_CIPHERTEXT_SIZE>,
|
||||
>(
|
||||
params: &P,
|
||||
height: BlockHeight,
|
||||
|
@ -420,7 +403,7 @@ pub fn try_sapling_note_decryption<
|
|||
|
||||
pub fn try_sapling_compact_note_decryption<
|
||||
P: consensus::Parameters,
|
||||
Output: ShieldedOutput<SaplingDomain<P>>,
|
||||
Output: ShieldedOutput<SaplingDomain<P>, COMPACT_NOTE_SIZE>,
|
||||
>(
|
||||
params: &P,
|
||||
height: BlockHeight,
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
use core::fmt::Debug;
|
||||
use std::convert::TryInto;
|
||||
|
||||
use ff::PrimeField;
|
||||
use group::GroupEncoding;
|
||||
use std::io::{self, Read, Write};
|
||||
|
||||
use zcash_note_encryption::{EphemeralKeyBytes, ShieldedOutput, COMPACT_NOTE_SIZE};
|
||||
use zcash_note_encryption::{
|
||||
EphemeralKeyBytes, ShieldedOutput, COMPACT_NOTE_SIZE, ENC_CIPHERTEXT_SIZE,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
consensus,
|
||||
|
@ -219,7 +223,9 @@ pub struct OutputDescription<Proof> {
|
|||
pub zkproof: Proof,
|
||||
}
|
||||
|
||||
impl<P: consensus::Parameters, A> ShieldedOutput<SaplingDomain<P>> for OutputDescription<A> {
|
||||
impl<P: consensus::Parameters, A> ShieldedOutput<SaplingDomain<P>, ENC_CIPHERTEXT_SIZE>
|
||||
for OutputDescription<A>
|
||||
{
|
||||
fn ephemeral_key(&self) -> EphemeralKeyBytes {
|
||||
self.ephemeral_key.clone()
|
||||
}
|
||||
|
@ -228,7 +234,7 @@ impl<P: consensus::Parameters, A> ShieldedOutput<SaplingDomain<P>> for OutputDes
|
|||
self.cmu.to_repr()
|
||||
}
|
||||
|
||||
fn enc_ciphertext(&self) -> &[u8] {
|
||||
fn enc_ciphertext(&self) -> &[u8; ENC_CIPHERTEXT_SIZE] {
|
||||
&self.enc_ciphertext
|
||||
}
|
||||
}
|
||||
|
@ -347,7 +353,7 @@ impl OutputDescriptionV5 {
|
|||
pub struct CompactOutputDescription {
|
||||
pub ephemeral_key: EphemeralKeyBytes,
|
||||
pub cmu: bls12_381::Scalar,
|
||||
pub enc_ciphertext: Vec<u8>,
|
||||
pub enc_ciphertext: [u8; COMPACT_NOTE_SIZE],
|
||||
}
|
||||
|
||||
impl<A> From<OutputDescription<A>> for CompactOutputDescription {
|
||||
|
@ -355,12 +361,14 @@ impl<A> From<OutputDescription<A>> for CompactOutputDescription {
|
|||
CompactOutputDescription {
|
||||
ephemeral_key: out.ephemeral_key,
|
||||
cmu: out.cmu,
|
||||
enc_ciphertext: out.enc_ciphertext[..COMPACT_NOTE_SIZE].to_vec(),
|
||||
enc_ciphertext: out.enc_ciphertext[..COMPACT_NOTE_SIZE].try_into().unwrap(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<P: consensus::Parameters> ShieldedOutput<SaplingDomain<P>> for CompactOutputDescription {
|
||||
impl<P: consensus::Parameters> ShieldedOutput<SaplingDomain<P>, COMPACT_NOTE_SIZE>
|
||||
for CompactOutputDescription
|
||||
{
|
||||
fn ephemeral_key(&self) -> EphemeralKeyBytes {
|
||||
self.ephemeral_key.clone()
|
||||
}
|
||||
|
@ -369,7 +377,7 @@ impl<P: consensus::Parameters> ShieldedOutput<SaplingDomain<P>> for CompactOutpu
|
|||
self.cmu.to_repr()
|
||||
}
|
||||
|
||||
fn enc_ciphertext(&self) -> &[u8] {
|
||||
fn enc_ciphertext(&self) -> &[u8; COMPACT_NOTE_SIZE] {
|
||||
&self.enc_ciphertext
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue