Skip to content

Commit

Permalink
zcash_primitives: Introduce another intermediate trait Bundles
Browse files Browse the repository at this point in the history
This re-enables the ability to add additional bundle types behind
conditional compilation, which was not possible with the bundle types
being explicit generic parameters.
  • Loading branch information
str4d committed May 13, 2024
1 parent 5596785 commit e3a29b8
Show file tree
Hide file tree
Showing 9 changed files with 232 additions and 195 deletions.
10 changes: 1 addition & 9 deletions zcash_primitives/src/transaction/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use crate::{
components::{
amount::{Amount, BalanceError},
transparent::{self, builder::TransparentBuilder, TxOut},
Orchard, Sapling,
},
fees::FeeRule,
sighash::{signature_hash, SignableInput},
Expand Down Expand Up @@ -757,14 +756,7 @@ impl<'a, P: consensus::Parameters, U: sapling::builder::ProverProgress> Builder<
let txid_parts = unauthed_tx.digest(TxIdDigester);

let transparent_bundle = unauthed_tx.transparent_bundle.clone().map(|b| {
b.apply_signatures::<Sapling<
sapling::builder::InProgress<sapling::builder::Proven, sapling::builder::Unsigned>,
>, Orchard<
orchard::builder::InProgress<
orchard::builder::Unproven,
orchard::builder::Unauthorized,
>,
>>(
b.apply_signatures(
#[cfg(feature = "transparent-inputs")]
&unauthed_tx,
#[cfg(feature = "transparent-inputs")]
Expand Down
31 changes: 31 additions & 0 deletions zcash_primitives/src/transaction/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,40 @@ pub use crate::sapling::bundle::{OutputDescription, SpendDescription};
#[cfg(zcash_unstable = "zfuture")]
pub use self::tze::{TzeIn, TzeOut};

use super::Authorization;

// π_A + π_B + π_C
pub const GROTH_PROOF_SIZE: usize = 48 + 96 + 48;

pub trait Bundles {
type Transparent: TransparentPart;
type Sapling: SaplingPart;
type Orchard: OrchardPart;
}

#[derive(Debug)]
pub struct AllBundles<A: Authorization> {
_auth: PhantomData<A>,
}

impl<A: Authorization> Bundles for AllBundles<A> {
type Transparent = Transparent<A::TransparentAuth>;
type Sapling = Sapling<A::SaplingAuth>;
type Orchard = Orchard<A::OrchardAuth>;
}

pub struct SomeBundles<T: TransparentPart, S: SaplingPart, O: OrchardPart> {
_transparent: PhantomData<T>,
_sapling: PhantomData<S>,
_orchard: PhantomData<O>,
}

impl<T: TransparentPart, S: SaplingPart, O: OrchardPart> Bundles for SomeBundles<T, S, O> {
type Transparent = T;
type Sapling = S;
type Orchard = O;
}

pub trait ShieldedValueBalance {
fn value_balance(&self) -> Amount;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use crate::{
components::{
amount::{Amount, BalanceError, NonNegativeAmount},
transparent::{self, Authorization, Authorized, Bundle, TxIn, TxOut},
OrchardPart,
},
sighash::TransparentAuthorizingContext,
},
Expand Down Expand Up @@ -240,13 +239,12 @@ impl TransparentAuthorizingContext for Unauthorized {
}

impl Bundle<Unauthorized> {
pub fn apply_signatures<S: tx::sighash_v4::SaplingSigDigester, O: OrchardPart>(
pub fn apply_signatures<
S: tx::sighash_v4::SaplingSigDigester,
B: tx::Bundles<Transparent = tx::Transparent<Unauthorized>, Sapling = S>,
>(
self,
#[cfg(feature = "transparent-inputs")] mtx: &TransactionData<
tx::Transparent<Unauthorized>,
S,
O,
>,
#[cfg(feature = "transparent-inputs")] mtx: &TransactionData<B>,
#[cfg(feature = "transparent-inputs")] txid_parts_cache: &TxDigests<Blake2bHash>,
) -> Bundle<Authorized> {
#[cfg(feature = "transparent-inputs")]
Expand Down
Loading

0 comments on commit e3a29b8

Please sign in to comment.