Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 6 commits into from
Nov 1, 2023
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
7 changes: 2 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ reddsa = "0.5"
nonempty = "0.7"
serde = { version = "1.0", features = ["derive"] }
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"

# Logging
Expand All @@ -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"] }
hex = "0.4"
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"] }

[target.'cfg(unix)'.dev-dependencies]
Expand Down Expand Up @@ -91,6 +91,3 @@ debug = true

[profile.bench]
debug = true

[patch.crates-io]
zcash_note_encryption = { version = "0.4", git = "https://github.com/QED-it/librustzcash.git", branch = "zsa1-zebra" }
2 changes: 1 addition & 1 deletion benches/note_decryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use orchard::{
Anchor, Bundle,
};
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)]
use pprof::criterion::{Output, PProfProfiler};
Expand Down
2 changes: 1 addition & 1 deletion src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@
/// Adds a note to be spent in this transaction.
///
/// - `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
/// instantiated with [`MerkleHashOrchard`].
///
Expand Down Expand Up @@ -452,7 +452,7 @@
.iter()
.map(|recipient| NoteValue::zero() - recipient.value),
)
.fold(Some(ValueSum::zero()), |acc, note_value| acc? + note_value)

Check warning on line 455 in src/builder.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

usage of `Iterator::fold` on a type that implements `Try`

warning: usage of `Iterator::fold` on a type that implements `Try` --> src/builder.rs:455:14 | 455 | .fold(Some(ValueSum::zero()), |acc, note_value| acc? + note_value) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `try_fold` instead: `try_fold(ValueSum::zero(), |acc, note_value| ...)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_try_fold = note: `#[warn(clippy::manual_try_fold)]` on by default

Check warning on line 455 in src/builder.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

usage of `Iterator::fold` on a type that implements `Try`

warning: usage of `Iterator::fold` on a type that implements `Try` --> src/builder.rs:455:14 | 455 | .fold(Some(ValueSum::zero()), |acc, note_value| acc? + note_value) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `try_fold` instead: `try_fold(ValueSum::zero(), |acc, note_value| ...)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_try_fold = note: `#[warn(clippy::manual_try_fold)]` on by default
.ok_or(OverflowError)?;
i64::try_from(value_balance).and_then(|i| V::try_from(i).map_err(|_| value::OverflowError))
}
Expand Down Expand Up @@ -529,9 +529,9 @@
let native_value_balance: V = pre_actions
.iter()
.filter(|action| action.spend.note.asset().is_native().into())
.fold(Some(ValueSum::zero()), |acc, action| {
acc? + action.value_sum()
})

Check warning on line 534 in src/builder.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

usage of `Iterator::fold` on a type that implements `Try`

warning: usage of `Iterator::fold` on a type that implements `Try` --> src/builder.rs:532:14 | 532 | .fold(Some(ValueSum::zero()), |acc, action| { | ______________^ 533 | | acc? + action.value_sum() 534 | | }) | |______________^ help: use `try_fold` instead: `try_fold(ValueSum::zero(), |acc, action| ...)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_try_fold

Check warning on line 534 in src/builder.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

usage of `Iterator::fold` on a type that implements `Try`

warning: usage of `Iterator::fold` on a type that implements `Try` --> src/builder.rs:532:14 | 532 | .fold(Some(ValueSum::zero()), |acc, action| { | ______________^ 533 | | acc? + action.value_sum() 534 | | }) | |______________^ help: use `try_fold` instead: `try_fold(ValueSum::zero(), |acc, action| ...)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_try_fold
.ok_or(OverflowError)?
.into()?;

Expand Down
2 changes: 1 addition & 1 deletion src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use core::fmt;
use blake2b_simd::Hash as Blake2bHash;
use memuse::DynamicUsage;
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::{
Expand Down
6 changes: 3 additions & 3 deletions src/issuance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::{
use crate::supply_info::{AssetSupply, SupplyInfo};

/// A bundle of actions to be applied to the ledger.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct IssueBundle<T: IssueAuth> {
/// The issuer key for the note being created.
ik: IssuanceValidatingKey,
Expand All @@ -39,7 +39,7 @@ pub struct IssueBundle<T: IssueAuth> {
/// An issue action applied 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 {
/// Asset description for verification.
asset_desc: String,
Expand Down Expand Up @@ -181,7 +181,7 @@ pub struct Prepared {
}

/// Marker for an authorized bundle.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Signed {
signature: redpallas::Signature<SpendAuth>,
}
Expand Down
2 changes: 1 addition & 1 deletion src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use group::{
use pasta_curves::{pallas, pallas::Scalar};
use rand::{CryptoRng, RngCore};
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};
use zcash_note_encryption::EphemeralKeyBytes;
use zcash_note_encryption_zsa::EphemeralKeyBytes;

use crate::{
address::Address,
Expand Down
6 changes: 3 additions & 3 deletions src/note_encryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use blake2b_simd::{Hash, Params};
use group::ff::PrimeField;
use std::fmt;
use zcash_note_encryption::{
use zcash_note_encryption_zsa::{
BatchDomain, Domain, EphemeralKeyBytes, OutPlaintextBytes, OutgoingCipherKey, ShieldedOutput,
AEAD_TAG_SIZE, MEMO_SIZE, OUT_PLAINTEXT_SIZE,
};
Expand Down Expand Up @@ -350,7 +350,7 @@ impl BatchDomain for OrchardDomainV2 {
}

/// 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> {
fn ephemeral_key(&self) -> EphemeralKeyBytes {
Expand Down Expand Up @@ -450,7 +450,7 @@ impl CompactAction {
mod tests {
use proptest::proptest;
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,
EphemeralKeyBytes,
};
Expand Down
9 changes: 4 additions & 5 deletions src/note_encryption_v2v3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use blake2b_simd::{Hash, Params};
use core::fmt;
use group::ff::PrimeField;
use zcash_note_encryption::{
use zcash_note_encryption_zsa::{
BatchDomain, Domain, EphemeralKeyBytes, OutPlaintextBytes, OutgoingCipherKey, ShieldedOutput,
AEAD_TAG_SIZE, MEMO_SIZE, OUT_PLAINTEXT_SIZE,
};
Expand Down Expand Up @@ -440,9 +440,8 @@ impl BatchDomain for OrchardDomain {
}
}


/// 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> {
fn ephemeral_key(&self) -> EphemeralKeyBytes {
Expand Down Expand Up @@ -548,7 +547,7 @@ impl CompactAction {
mod tests {
use proptest::prelude::*;
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,
EphemeralKeyBytes,
};
Expand All @@ -571,7 +570,7 @@ mod tests {
Address, Note,
};

use super::{version, orchard_parse_note_plaintext_without_memo};
use super::{orchard_parse_note_plaintext_without_memo, version};

proptest! {
#[test]
Expand Down
6 changes: 3 additions & 3 deletions src/note_encryption_v3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use blake2b_simd::{Hash, Params};
use core::fmt;
use group::ff::PrimeField;
use zcash_note_encryption::{
use zcash_note_encryption_zsa::{
BatchDomain, Domain, EphemeralKeyBytes, OutPlaintextBytes, OutgoingCipherKey, ShieldedOutput,
AEAD_TAG_SIZE, MEMO_SIZE, OUT_PLAINTEXT_SIZE,
};
Expand Down Expand Up @@ -340,7 +340,7 @@
let (shared_secrets, ephemeral_keys): (Vec<_>, Vec<_>) = items.unzip();

SharedSecret::batch_to_affine(shared_secrets)
.zip(ephemeral_keys.into_iter())

Check warning on line 343 in src/note_encryption_v3.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

explicit call to `.into_iter()` in function argument accepting `IntoIterator`

warning: explicit call to `.into_iter()` in function argument accepting `IntoIterator` --> src/note_encryption_v3.rs:343:18 | 343 | .zip(ephemeral_keys.into_iter()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `ephemeral_keys` | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` --> /rustc/489647f984b2b3a5ee6b2a0d46a527c8d926ceae/library/core/src/iter/traits/iterator.rs:642:12 = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion = note: `#[warn(clippy::useless_conversion)]` on by default

Check warning on line 343 in src/note_encryption_v3.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

explicit call to `.into_iter()` in function argument accepting `IntoIterator`

warning: explicit call to `.into_iter()` in function argument accepting `IntoIterator` --> src/note_encryption_v3.rs:343:18 | 343 | .zip(ephemeral_keys.into_iter()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `ephemeral_keys` | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` --> /rustc/489647f984b2b3a5ee6b2a0d46a527c8d926ceae/library/core/src/iter/traits/iterator.rs:642:12 = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion = note: `#[warn(clippy::useless_conversion)]` on by default
.map(|(secret, ephemeral_key)| {
secret.map(|dhsecret| SharedSecret::kdf_orchard_inner(dhsecret, ephemeral_key))
})
Expand All @@ -349,7 +349,7 @@
}

/// 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> {
fn ephemeral_key(&self) -> EphemeralKeyBytes {
Expand Down Expand Up @@ -449,7 +449,7 @@
mod tests {
use proptest::prelude::*;
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,
EphemeralKeyBytes,
};
Expand Down
2 changes: 1 addition & 1 deletion src/primitives/redpallas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl<T: SigType> VerificationKey<T> {
}

/// A RedPallas signature.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Signature<T: SigType>(reddsa::Signature<T>);

impl<T: SigType> From<[u8; 64]> for Signature<T> {
Expand Down
2 changes: 1 addition & 1 deletion tests/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use orchard::{
Anchor, Bundle, Note,
};
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) {
if verify_proof {
Expand Down
2 changes: 1 addition & 1 deletion tests/zsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use orchard::{
};
use rand::rngs::OsRng;
use std::collections::HashSet;
use zcash_note_encryption::try_note_decryption;
use zcash_note_encryption_zsa::try_note_decryption;

#[derive(Debug)]
struct Keychain {
Expand Down
Loading