Adopt Orchard ZSA for Zebra (introduce zcash_note_encryption_zsa alias, minor enhancements) (#89)

This Pull Request introduces the `zcash_note_encryption_zsa` alias,
ensuring compatibility with the Zebra project. This alias is used to
prevent conflicts with the original `zcash_note_encryption` crate, which
is also used in Zebra through the original `orchard` crate that is used
in parallel with our `orchard` (Orchard ZSA) crate.
Additionally, this PR includes minor enhancements to ensure
compatibility with the Zebra project.

---------

Co-authored-by: Dmitry Demin <dmitry@qed-it.com>
This commit is contained in:
Dmitry Demin 2023-11-01 10:37:43 +01:00 committed by GitHub
parent a680f410a4
commit 7b943e197e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 22 additions and 26 deletions

View File

@ -41,7 +41,7 @@ reddsa = "0.5"
nonempty = "0.7" nonempty = "0.7"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
subtle = "2.3" subtle = "2.3"
zcash_note_encryption = "0.4" zcash_note_encryption_zsa = { package = "zcash_note_encryption", version = "0.4", git = "https://github.com/QED-it/librustzcash", branch = "zsa1-zebra" }
incrementalmerkletree = "0.5" incrementalmerkletree = "0.5"
# Logging # Logging
@ -57,7 +57,7 @@ criterion = "0.4" # 0.5 depends on clap 4 which has MSRV 1.70
halo2_gadgets = { git = "https://github.com/QED-it/halo2", branch = "zsa1", features = ["test-dependencies"] } halo2_gadgets = { git = "https://github.com/QED-it/halo2", branch = "zsa1", features = ["test-dependencies"] }
hex = "0.4" hex = "0.4"
proptest = "1.0.0" proptest = "1.0.0"
zcash_note_encryption = { version = "0.4", features = ["pre-zip-212"] } zcash_note_encryption_zsa = { package = "zcash_note_encryption", version = "0.4", git = "https://github.com/QED-it/librustzcash", branch = "zsa1-zebra", features = ["pre-zip-212"] }
incrementalmerkletree = { version = "0.5", features = ["test-dependencies"] } incrementalmerkletree = { version = "0.5", features = ["test-dependencies"] }
[target.'cfg(unix)'.dev-dependencies] [target.'cfg(unix)'.dev-dependencies]
@ -91,6 +91,3 @@ debug = true
[profile.bench] [profile.bench]
debug = true debug = true
[patch.crates-io]
zcash_note_encryption = { version = "0.4", git = "https://github.com/QED-it/librustzcash.git", branch = "zsa1-zebra" }

View File

@ -10,7 +10,7 @@ use orchard::{
Anchor, Bundle, Anchor, Bundle,
}; };
use rand::rngs::OsRng; use rand::rngs::OsRng;
use zcash_note_encryption::{batch, try_compact_note_decryption, try_note_decryption}; use zcash_note_encryption_zsa::{batch, try_compact_note_decryption, try_note_decryption};
#[cfg(unix)] #[cfg(unix)]
use pprof::criterion::{Output, PProfProfiler}; use pprof::criterion::{Output, PProfProfiler};

View File

@ -337,7 +337,7 @@ impl Builder {
/// Adds a note to be spent in this transaction. /// Adds a note to be spent in this transaction.
/// ///
/// - `note` is a spendable note, obtained by trial-decrypting an [`Action`] using the /// - `note` is a spendable note, obtained by trial-decrypting an [`Action`] using the
/// [`zcash_note_encryption`] crate instantiated with [`OrchardDomain`]. /// [`zcash_note_encryption_zsa`] crate instantiated with [`OrchardDomain`].
/// - `merkle_path` can be obtained using the [`incrementalmerkletree`] crate /// - `merkle_path` can be obtained using the [`incrementalmerkletree`] crate
/// instantiated with [`MerkleHashOrchard`]. /// instantiated with [`MerkleHashOrchard`].
/// ///

View File

@ -11,7 +11,7 @@ use core::fmt;
use blake2b_simd::Hash as Blake2bHash; use blake2b_simd::Hash as Blake2bHash;
use memuse::DynamicUsage; use memuse::DynamicUsage;
use nonempty::NonEmpty; use nonempty::NonEmpty;
use zcash_note_encryption::{try_note_decryption, try_output_recovery_with_ovk}; use zcash_note_encryption_zsa::{try_note_decryption, try_output_recovery_with_ovk};
use crate::note::AssetBase; use crate::note::AssetBase;
use crate::{ use crate::{

View File

@ -26,7 +26,7 @@ use crate::{
use crate::supply_info::{AssetSupply, SupplyInfo}; use crate::supply_info::{AssetSupply, SupplyInfo};
/// A bundle of actions to be applied to the ledger. /// A bundle of actions to be applied to the ledger.
#[derive(Debug, Clone)] #[derive(Debug, Clone, PartialEq, Eq)]
pub struct IssueBundle<T: IssueAuth> { pub struct IssueBundle<T: IssueAuth> {
/// The issuer key for the note being created. /// The issuer key for the note being created.
ik: IssuanceValidatingKey, ik: IssuanceValidatingKey,
@ -39,7 +39,7 @@ pub struct IssueBundle<T: IssueAuth> {
/// An issue action applied to the global ledger. /// An issue action applied to the global ledger.
/// ///
/// Externally, this creates new zsa notes (adding a commitment to the global ledger). /// Externally, this creates new zsa notes (adding a commitment to the global ledger).
#[derive(Debug, Clone)] #[derive(Debug, Clone, PartialEq, Eq)]
pub struct IssueAction { pub struct IssueAction {
/// Asset description for verification. /// Asset description for verification.
asset_desc: String, asset_desc: String,
@ -181,7 +181,7 @@ pub struct Prepared {
} }
/// Marker for an authorized bundle. /// Marker for an authorized bundle.
#[derive(Debug, Clone)] #[derive(Debug, Clone, PartialEq, Eq)]
pub struct Signed { pub struct Signed {
signature: redpallas::Signature<SpendAuth>, signature: redpallas::Signature<SpendAuth>,
} }

View File

@ -14,7 +14,7 @@ use group::{
use pasta_curves::{pallas, pallas::Scalar}; use pasta_curves::{pallas, pallas::Scalar};
use rand::{CryptoRng, RngCore}; use rand::{CryptoRng, RngCore};
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption}; use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};
use zcash_note_encryption::EphemeralKeyBytes; use zcash_note_encryption_zsa::EphemeralKeyBytes;
use crate::{ use crate::{
address::Address, address::Address,

View File

@ -3,7 +3,7 @@
use blake2b_simd::{Hash, Params}; use blake2b_simd::{Hash, Params};
use group::ff::PrimeField; use group::ff::PrimeField;
use std::fmt; use std::fmt;
use zcash_note_encryption::{ use zcash_note_encryption_zsa::{
BatchDomain, Domain, EphemeralKeyBytes, OutPlaintextBytes, OutgoingCipherKey, ShieldedOutput, BatchDomain, Domain, EphemeralKeyBytes, OutPlaintextBytes, OutgoingCipherKey, ShieldedOutput,
AEAD_TAG_SIZE, MEMO_SIZE, OUT_PLAINTEXT_SIZE, AEAD_TAG_SIZE, MEMO_SIZE, OUT_PLAINTEXT_SIZE,
}; };
@ -350,7 +350,7 @@ impl BatchDomain for OrchardDomainV2 {
} }
/// Implementation of in-band secret distribution for Orchard bundles. /// Implementation of in-band secret distribution for Orchard bundles.
pub type OrchardNoteEncryption = zcash_note_encryption::NoteEncryption<OrchardDomainV2>; pub type OrchardNoteEncryption = zcash_note_encryption_zsa::NoteEncryption<OrchardDomainV2>;
impl<T> ShieldedOutput<OrchardDomainV2> for Action<T> { impl<T> ShieldedOutput<OrchardDomainV2> for Action<T> {
fn ephemeral_key(&self) -> EphemeralKeyBytes { fn ephemeral_key(&self) -> EphemeralKeyBytes {
@ -450,7 +450,7 @@ impl CompactAction {
mod tests { mod tests {
use proptest::proptest; use proptest::proptest;
use rand::rngs::OsRng; use rand::rngs::OsRng;
use zcash_note_encryption::{ use zcash_note_encryption_zsa::{
try_compact_note_decryption, try_note_decryption, try_output_recovery_with_ovk, Domain, try_compact_note_decryption, try_note_decryption, try_output_recovery_with_ovk, Domain,
EphemeralKeyBytes, EphemeralKeyBytes,
}; };

View File

@ -3,7 +3,7 @@
use blake2b_simd::{Hash, Params}; use blake2b_simd::{Hash, Params};
use core::fmt; use core::fmt;
use group::ff::PrimeField; use group::ff::PrimeField;
use zcash_note_encryption::{ use zcash_note_encryption_zsa::{
BatchDomain, Domain, EphemeralKeyBytes, OutPlaintextBytes, OutgoingCipherKey, ShieldedOutput, BatchDomain, Domain, EphemeralKeyBytes, OutPlaintextBytes, OutgoingCipherKey, ShieldedOutput,
AEAD_TAG_SIZE, MEMO_SIZE, OUT_PLAINTEXT_SIZE, AEAD_TAG_SIZE, MEMO_SIZE, OUT_PLAINTEXT_SIZE,
}; };
@ -440,9 +440,8 @@ impl BatchDomain for OrchardDomain {
} }
} }
/// Implementation of in-band secret distribution for Orchard bundles. /// Implementation of in-band secret distribution for Orchard bundles.
pub type OrchardNoteEncryption = zcash_note_encryption::NoteEncryption<OrchardDomain>; pub type OrchardNoteEncryption = zcash_note_encryption_zsa::NoteEncryption<OrchardDomain>;
impl<T> ShieldedOutput<OrchardDomain> for Action<T> { impl<T> ShieldedOutput<OrchardDomain> for Action<T> {
fn ephemeral_key(&self) -> EphemeralKeyBytes { fn ephemeral_key(&self) -> EphemeralKeyBytes {
@ -548,7 +547,7 @@ impl CompactAction {
mod tests { mod tests {
use proptest::prelude::*; use proptest::prelude::*;
use rand::rngs::OsRng; use rand::rngs::OsRng;
use zcash_note_encryption::{ use zcash_note_encryption_zsa::{
try_compact_note_decryption, try_note_decryption, try_output_recovery_with_ovk, Domain, try_compact_note_decryption, try_note_decryption, try_output_recovery_with_ovk, Domain,
EphemeralKeyBytes, EphemeralKeyBytes,
}; };
@ -571,7 +570,7 @@ mod tests {
Address, Note, Address, Note,
}; };
use super::{version, orchard_parse_note_plaintext_without_memo}; use super::{orchard_parse_note_plaintext_without_memo, version};
proptest! { proptest! {
#[test] #[test]

View File

@ -3,7 +3,7 @@
use blake2b_simd::{Hash, Params}; use blake2b_simd::{Hash, Params};
use core::fmt; use core::fmt;
use group::ff::PrimeField; use group::ff::PrimeField;
use zcash_note_encryption::{ use zcash_note_encryption_zsa::{
BatchDomain, Domain, EphemeralKeyBytes, OutPlaintextBytes, OutgoingCipherKey, ShieldedOutput, BatchDomain, Domain, EphemeralKeyBytes, OutPlaintextBytes, OutgoingCipherKey, ShieldedOutput,
AEAD_TAG_SIZE, MEMO_SIZE, OUT_PLAINTEXT_SIZE, AEAD_TAG_SIZE, MEMO_SIZE, OUT_PLAINTEXT_SIZE,
}; };
@ -349,7 +349,7 @@ impl BatchDomain for OrchardDomainV3 {
} }
/// Implementation of in-band secret distribution for Orchard bundles. /// Implementation of in-band secret distribution for Orchard bundles.
pub type OrchardNoteEncryption = zcash_note_encryption::NoteEncryption<OrchardDomainV3>; pub type OrchardNoteEncryption = zcash_note_encryption_zsa::NoteEncryption<OrchardDomainV3>;
impl<T> ShieldedOutput<OrchardDomainV3> for Action<T> { impl<T> ShieldedOutput<OrchardDomainV3> for Action<T> {
fn ephemeral_key(&self) -> EphemeralKeyBytes { fn ephemeral_key(&self) -> EphemeralKeyBytes {
@ -449,7 +449,7 @@ impl CompactAction {
mod tests { mod tests {
use proptest::prelude::*; use proptest::prelude::*;
use rand::rngs::OsRng; use rand::rngs::OsRng;
use zcash_note_encryption::{ use zcash_note_encryption_zsa::{
try_compact_note_decryption, try_note_decryption, try_output_recovery_with_ovk, Domain, try_compact_note_decryption, try_note_decryption, try_output_recovery_with_ovk, Domain,
EphemeralKeyBytes, EphemeralKeyBytes,
}; };

View File

@ -154,7 +154,7 @@ impl<T: SigType> VerificationKey<T> {
} }
/// A RedPallas signature. /// A RedPallas signature.
#[derive(Debug, Clone)] #[derive(Debug, Clone, PartialEq, Eq)]
pub struct Signature<T: SigType>(reddsa::Signature<T>); pub struct Signature<T: SigType>(reddsa::Signature<T>);
impl<T: SigType> From<[u8; 64]> for Signature<T> { impl<T: SigType> From<[u8; 64]> for Signature<T> {

View File

@ -12,7 +12,7 @@ use orchard::{
Anchor, Bundle, Note, Anchor, Bundle, Note,
}; };
use rand::rngs::OsRng; use rand::rngs::OsRng;
use zcash_note_encryption::try_note_decryption; use zcash_note_encryption_zsa::try_note_decryption;
pub fn verify_bundle(bundle: &Bundle<Authorized, i64>, vk: &VerifyingKey, verify_proof: bool) { pub fn verify_bundle(bundle: &Bundle<Authorized, i64>, vk: &VerifyingKey, verify_proof: bool) {
if verify_proof { if verify_proof {

View File

@ -22,7 +22,7 @@ use orchard::{
}; };
use rand::rngs::OsRng; use rand::rngs::OsRng;
use std::collections::HashSet; use std::collections::HashSet;
use zcash_note_encryption::try_note_decryption; use zcash_note_encryption_zsa::try_note_decryption;
#[derive(Debug)] #[derive(Debug)]
struct Keychain { struct Keychain {