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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ sapling = { package = "sapling-crypto", version = "0.1.3" }

# - Orchard
nonempty = "0.7"
orchard = { version = "0.8.0", default-features = false }
orchard = { version = "0.8.0", default-features = false }
pasta_curves = "0.5"

# - Transparent
Expand Down
1 change: 1 addition & 0 deletions zcash_client_backend/src/data_api/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,7 @@ where
.orchard_bundle()
.and_then(|bundle| {
bundle
.as_vanilla_bundle()
.decrypt_output_with_key(output_index, &orchard_internal_ivk)
.map(|(note, _, _)| Note::Orchard(note))
})
Expand Down
5 changes: 2 additions & 3 deletions zcash_client_backend/src/decrypt.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::collections::HashMap;

use sapling::note_encryption::{PreparedIncomingViewingKey, SaplingDomain};
use std::collections::HashMap;
use zcash_note_encryption::{try_note_decryption, try_output_recovery_with_ovk};
use zcash_primitives::{
consensus::{self, BlockHeight},
Expand Down Expand Up @@ -159,7 +158,7 @@ pub fn decrypt_transaction<'a, P: consensus::Parameters, AccountId: Copy>(
.collect();

#[cfg(feature = "orchard")]
let orchard_bundle = tx.orchard_bundle();
let orchard_bundle = tx.orchard_bundle().map(|bundle| bundle.as_vanilla_bundle());
#[cfg(feature = "orchard")]
let orchard_outputs = orchard_bundle
.iter()
Expand Down
105 changes: 51 additions & 54 deletions zcash_primitives/src/transaction/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ use crate::{
},
};

use orchard::builder::BundleType;
use orchard::builder::{BundleType, InProgress, Unproven};
use orchard::note::AssetBase;
use orchard::orchard_flavor::OrchardVanilla;
use orchard::orchard_flavor::{OrchardFlavor, OrchardVanilla};
use orchard::Address;

#[cfg(feature = "transparent-inputs")]
Expand All @@ -41,16 +41,7 @@ use crate::transaction::components::transparent::builder::TransparentInputInfo;
#[cfg(not(feature = "transparent-inputs"))]
use std::convert::Infallible;

#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
use orchard::{
issuance,
issuance::{IssueBundle, IssueInfo},
keys::{IssuanceAuthorizingKey, IssuanceValidatingKey},
orchard_flavor::OrchardZSA,
};
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
use rand_core::OsRng;

use crate::transaction::OrchardBundle;
#[cfg(zcash_unstable = "zfuture")]
use crate::{
extensions::transparent::{ExtensionTxBuilder, ToPayload},
Expand All @@ -62,6 +53,16 @@ use crate::{
fees::FutureFeeRule,
},
};
use orchard::bundle::Authorized;
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
use orchard::{
issuance,
issuance::{IssueBundle, IssueInfo},
keys::{IssuanceAuthorizingKey, IssuanceValidatingKey},
orchard_flavor::OrchardZSA,
};
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
use rand_core::OsRng;

/// Since Blossom activation, the default transaction expiry delta should be 40 blocks.
/// <https://zips.z.cash/zip-0203#changes-for-blossom>
Expand Down Expand Up @@ -868,8 +869,6 @@ impl<'a, P: consensus::Parameters, U: sapling::builder::ProverProgress> Builder<
};

let mut unproven_orchard_bundle = None;
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
let mut unproven_orchard_zsa_bundle = None;
let mut orchard_meta = orchard::builder::BundleMetadata::empty();

if let Some(builder) = self.orchard_builder {
Expand All @@ -879,12 +878,12 @@ impl<'a, P: consensus::Parameters, U: sapling::builder::ProverProgress> Builder<
{
let (bundle, meta) = builder.build(&mut rng).map_err(Error::OrchardBuild)?;

unproven_orchard_zsa_bundle = Some(bundle);
unproven_orchard_bundle = Some(OrchardBundle::OrchardZSA(bundle));
orchard_meta = meta;
}
} else {
let (bundle, meta) = builder.build(&mut rng).map_err(Error::OrchardBuild)?;
unproven_orchard_bundle = Some(bundle);
unproven_orchard_bundle = Some(OrchardBundle::OrchardVanilla(bundle));
orchard_meta = meta;
}
};
Expand All @@ -902,8 +901,6 @@ impl<'a, P: consensus::Parameters, U: sapling::builder::ProverProgress> Builder<
sapling_bundle,
orchard_bundle: unproven_orchard_bundle,
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
orchard_zsa_bundle: unproven_orchard_zsa_bundle,
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
issue_bundle: self.issuance_builder,
#[cfg(zcash_unstable = "zfuture")]
tze_bundle,
Expand Down Expand Up @@ -949,42 +946,28 @@ impl<'a, P: consensus::Parameters, U: sapling::builder::ProverProgress> Builder<
.transpose()
.map_err(Error::SaplingBuild)?;

let orchard_bundle = unauthed_tx
.orchard_bundle
.map(|b| {
b.create_proof(
&orchard::circuit::ProvingKey::build::<OrchardVanilla>(),
let orchard_bundle: Option<OrchardBundle<_>> = match unauthed_tx.orchard_bundle {
Some(OrchardBundle::OrchardVanilla(b)) => {
Some(OrchardBundle::OrchardVanilla(prove_and_sign(
b,
&mut rng,
)
.and_then(|b| {
b.apply_signatures(
&mut rng,
*shielded_sig_commitment.as_ref(),
&self.orchard_saks,
)
})
})
.transpose()
.map_err(Error::OrchardBuild)?;
&orchard::circuit::ProvingKey::build::<OrchardVanilla>(),
shielded_sig_commitment.as_ref(),
&self.orchard_saks,
)?))
}

#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
let orchard_zsa_bundle = unauthed_tx
.orchard_zsa_bundle
.map(|b| {
b.create_proof(
&orchard::circuit::ProvingKey::build::<OrchardZSA>(),
&mut rng,
)
.and_then(|b| {
b.apply_signatures(
&mut rng,
*shielded_sig_commitment.as_ref(),
&self.orchard_saks,
)
})
})
.transpose()
.map_err(Error::OrchardBuild)?;
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
Some(OrchardBundle::OrchardZSA(b)) => Some(OrchardBundle::OrchardZSA(prove_and_sign(
b,
&mut rng,
&orchard::circuit::ProvingKey::build::<OrchardZSA>(),
shielded_sig_commitment.as_ref(),
&self.orchard_saks,
)?)),

None => None,
};

#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
let issue_bundle = unauthed_tx
Expand All @@ -1003,8 +986,6 @@ impl<'a, P: consensus::Parameters, U: sapling::builder::ProverProgress> Builder<
sapling_bundle,
orchard_bundle,
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
orchard_zsa_bundle,
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
issue_bundle,
#[cfg(zcash_unstable = "zfuture")]
tze_bundle,
Expand All @@ -1020,6 +1001,22 @@ impl<'a, P: consensus::Parameters, U: sapling::builder::ProverProgress> Builder<
}
}

fn prove_and_sign<D, V, FE>(
bundle: orchard::Bundle<InProgress<Unproven, orchard::builder::Unauthorized>, V, D>,
mut rng: &mut (impl RngCore + CryptoRng),
proving_key: &orchard::circuit::ProvingKey,
shielded_sig_commitment: &[u8; 32],
orchard_saks: &[orchard::keys::SpendAuthorizingKey],
) -> Result<orchard::Bundle<Authorized, V, D>, Error<FE>>
where
D: OrchardFlavor,
{
bundle
.create_proof(proving_key, &mut rng)
.and_then(|b| b.apply_signatures(&mut rng, *shielded_sig_commitment, orchard_saks))
.map_err(Error::OrchardBuild)
}

#[cfg(zcash_unstable = "zfuture")]
impl<'a, P: consensus::Parameters, U: sapling::builder::ProverProgress> ExtensionTxBuilder<'a>
for Builder<'a, P, U>
Expand Down
Loading