Skip to content

Commit

Permalink
Remove OrchardZsaAuth
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeykoren committed Nov 18, 2024
1 parent 1da25a0 commit 1c6529c
Show file tree
Hide file tree
Showing 8 changed files with 344 additions and 383 deletions.
608 changes: 309 additions & 299 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions 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, git = "https://github.com/QED-it/orchard", branch = "spendauth_clone" }
orchard = "0.8.0"
pasta_curves = "0.5"

# - Transparent
Expand Down Expand Up @@ -127,4 +127,4 @@ codegen-units = 1
[patch.crates-io]
zcash_note_encryption = { version = "0.4", git = "https://github.com/QED-it/zcash_note_encryption", branch = "zsa1" }
sapling = { package = "sapling-crypto", version = "0.1.3", git = "https://github.com/QED-it/sapling-crypto", branch = "zsa1" }
orchard = { version = "0.8.0", git = "https://github.com/QED-it/orchard", branch = "zsa1" }
orchard = { version = "0.8.0", default-features = false, git = "https://github.com/QED-it/orchard", branch = "spendauth_clone" }
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "1.70.0"
channel = "1.71.0"
components = [ "clippy", "rustfmt" ]
7 changes: 3 additions & 4 deletions zcash_primitives/src/transaction/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ impl<'a, P: consensus::Parameters, U: sapling::builder::ProverProgress> Builder<
.transpose()
.map_err(Error::SaplingBuild)?;

let orchard_bundle: Option<OrchardBundle<_, _>> = match unauthed_tx.orchard_bundle {
let orchard_bundle: Option<OrchardBundle<_>> = match unauthed_tx.orchard_bundle {
Some(OrchardBundle::OrchardVanilla(b)) => {
Some(OrchardBundle::OrchardVanilla(Box::new(
b.create_proof(
Expand All @@ -967,8 +967,8 @@ impl<'a, P: consensus::Parameters, U: sapling::builder::ProverProgress> Builder<
}

#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
Some(OrchardBundle::OrchardZSA(b)) => Some(OrchardBundle::OrchardZSA(
Box::new(b.create_proof(
Some(OrchardBundle::OrchardZSA(b)) => Some(OrchardBundle::OrchardZSA(Box::new(
b.create_proof(
&orchard::circuit::ProvingKey::build::<OrchardZSA>(),
&mut rng,
)
Expand All @@ -983,7 +983,6 @@ impl<'a, P: consensus::Parameters, U: sapling::builder::ProverProgress> Builder<
))),

None => None,
Some(_) => unreachable!(),
};

#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
Expand Down
15 changes: 7 additions & 8 deletions zcash_primitives/src/transaction/components/orchard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub trait BuildBundle<A: Authorization, D: OrchardDomainCommon> {
burn: Vec<(AssetBase, NoteValue)>,
anchor: Anchor,
authorization: A,
) -> OrchardBundle<A, A>;
) -> OrchardBundle<A>;
}

impl<A: Authorization> BuildBundle<A, OrchardVanilla> for OrchardVanilla {
Expand All @@ -68,7 +68,7 @@ impl<A: Authorization> BuildBundle<A, OrchardVanilla> for OrchardVanilla {
burn: Vec<(AssetBase, NoteValue)>,
anchor: Anchor,
authorization: A,
) -> OrchardBundle<A, A> {
) -> OrchardBundle<A> {
OrchardBundle::OrchardVanilla(Box::new(Bundle::from_parts(
actions,
flags,
Expand All @@ -89,7 +89,7 @@ impl<A: Authorization> BuildBundle<A, OrchardZSA> for OrchardZSA {
burn: Vec<(AssetBase, NoteValue)>,
anchor: Anchor,
authorization: A,
) -> OrchardBundle<A, A> {
) -> OrchardBundle<A> {
OrchardBundle::OrchardZSA(Box::new(orchard::Bundle::from_parts(
actions,
flags,
Expand Down Expand Up @@ -316,15 +316,14 @@ impl<W: Write> WriteBurn<W> for OrchardZSA {

/// Writes an [`orchard::Bundle`] in the appropriate transaction format.
pub fn write_orchard_bundle<W: Write>(
bundle: Option<&OrchardBundle<Authorized, Authorized>>,
bundle: Option<&OrchardBundle<Authorized>>,
mut writer: W,
) -> io::Result<()> {
if let Some(bundle) = &bundle {
match bundle {
OrchardBundle::OrchardVanilla(b) => write_orchard_bundle_contents(b, writer)?,
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
OrchardBundle::OrchardZSA(b) => write_orchard_bundle_contents(b, writer)?,
_ => unreachable!(),
}
} else {
CompactSize::write(&mut writer, 0)?;
Expand Down Expand Up @@ -421,7 +420,7 @@ pub mod testing {
pub fn arb_bundle(n_actions: usize)(
orchard_value_balance in arb_amount(),
bundle in t_orch::BundleArb::arb_bundle(n_actions)
) -> OrchardBundle<Authorized, Authorized> {
) -> OrchardBundle<Authorized> {
// overwrite the value balance, as we can't guarantee that the
// value doesn't exceed the MAX_MONEY bounds.
OrchardBundle::OrchardVanilla(Box::new(bundle.try_map_value_balance::<_, (), _>(|_| Ok(orchard_value_balance)).unwrap()))
Expand All @@ -433,7 +432,7 @@ pub mod testing {
pub fn arb_zsa_bundle(n_actions: usize)(
orchard_value_balance in arb_amount(),
bundle in t_orch::BundleArb::arb_bundle(n_actions)
) -> OrchardBundle<Authorized, Authorized> {
) -> OrchardBundle<Authorized> {
// overwrite the value balance, as we can't guarantee that the
// value doesn't exceed the MAX_MONEY bounds.
let _bundle: Bundle<_, _, OrchardZSA> = bundle.try_map_value_balance::<_, (), _>(|_| Ok(orchard_value_balance)).unwrap();
Expand All @@ -445,7 +444,7 @@ pub mod testing {

pub fn arb_bundle_for_version(
v: TxVersion,
) -> impl Strategy<Value = Option<OrchardBundle<Authorized, Authorized>>> {
) -> impl Strategy<Value = Option<OrchardBundle<Authorized>>> {
if v.has_orchard_zsa() {
Strategy::boxed((1usize..100).prop_flat_map(|n| prop::option::of(arb_zsa_bundle(n))))
} else if v.has_orchard() {
Expand Down
81 changes: 20 additions & 61 deletions zcash_primitives/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@ mod tests;
use blake2b_simd::Hash as Blake2bHash;
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use memuse::DynamicUsage;
use orchard::{
builder::Unproven, orchard_flavor::OrchardVanilla, orchard_flavor::OrchardZSA, Bundle,
};
use orchard::{builder::Unproven, orchard_flavor::OrchardVanilla, Bundle};
use std::convert::TryFrom;
use std::fmt;
use std::fmt::Debug;
use std::io::{self, Read, Write};
use std::marker::PhantomData;
use std::ops::Deref;
use zcash_encoding::{CompactSize, Vector};

Expand All @@ -47,7 +44,7 @@ use self::components::tze::{self, TzeIn, TzeOut};
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
use crate::transaction::components::issuance;
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
use orchard::issuance::IssueBundle;
use orchard::{issuance::IssueBundle, orchard_flavor::OrchardZSA};
use zcash_protocol::value::ZatBalance;

const OVERWINTER_VERSION_GROUP_ID: u32 = 0x03C48270;
Expand Down Expand Up @@ -302,8 +299,6 @@ pub trait Authorization {
type SaplingAuth: sapling::bundle::Authorization;
type OrchardAuth: orchard::bundle::Authorization;

type OrchardZsaAuth: orchard::bundle::Authorization;

#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
type IssueAuth: orchard::issuance::IssueAuth;

Expand All @@ -320,8 +315,6 @@ impl Authorization for Authorized {
type SaplingAuth = sapling::bundle::Authorized;
type OrchardAuth = orchard::bundle::Authorized;

type OrchardZsaAuth = orchard::bundle::Authorized;

#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
type IssueAuth = orchard::issuance::Signed;

Expand All @@ -339,11 +332,7 @@ impl Authorization for Unauthorized {
type TransparentAuth = transparent::builder::Unauthorized;
type SaplingAuth =
sapling_builder::InProgress<sapling_builder::Proven, sapling_builder::Unsigned>;
type OrchardAuth =
orchard::builder::InProgress<Unproven<OrchardVanilla>, orchard::builder::Unauthorized>;

type OrchardZsaAuth =
orchard::builder::InProgress<Unproven<OrchardZSA>, orchard::builder::Unauthorized>;
type OrchardAuth = orchard::builder::InProgress<Unproven, orchard::builder::Unauthorized>;

#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
type IssueAuth = orchard::issuance::Unauthorized;
Expand Down Expand Up @@ -374,12 +363,10 @@ impl PartialEq for Transaction {
}

#[derive(Debug, Clone)]
pub enum OrchardBundle<V: orchard::bundle::Authorization, Z: orchard::bundle::Authorization> {
OrchardVanilla(Box<Bundle<V, Amount, OrchardVanilla>>),
pub enum OrchardBundle<A: orchard::bundle::Authorization> {
OrchardVanilla(Box<Bundle<A, Amount, OrchardVanilla>>),
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
OrchardZSA(Box<Bundle<Z, Amount, OrchardZSA>>),
#[doc(hidden)]
_Phantom(PhantomData<Z>),
OrchardZSA(Box<Bundle<A, Amount, OrchardZSA>>),
}

/// Errors that can occur during transaction construction.
Expand All @@ -388,46 +375,29 @@ pub enum BundleError {
WrongBundleType,
}

impl<V: orchard::bundle::Authorization, Z: orchard::bundle::Authorization> OrchardBundle<V, Z> {
impl<A: orchard::bundle::Authorization> OrchardBundle<A> {
pub fn value_balance(&self) -> &Amount {
match self {
OrchardBundle::OrchardVanilla(b) => b.value_balance(),
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
OrchardBundle::OrchardZSA(b) => b.value_balance(),
_ => unreachable!(),
}
}

pub fn map_authorization<
R,
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )] R2,
NV: orchard::bundle::Authorization,
NZ: orchard::bundle::Authorization,
>(
pub fn map_authorization<R, B: orchard::bundle::Authorization>(
self,
context: &mut R,
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )] context_zsa: &mut R2,
spend_auth: impl FnMut(&mut R, &V, V::SpendAuth) -> NV::SpendAuth,
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )] spend_auth_zsa: impl FnMut(
&mut R2,
&Z,
Z::SpendAuth,
)
-> NZ::SpendAuth,
step: impl FnOnce(&mut R, V) -> NV,
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )] step_zsa: impl FnOnce(&mut R2, Z) -> NZ,
) -> OrchardBundle<NV, NZ> {
spend_auth: impl FnMut(&mut R, &A, A::SpendAuth) -> B::SpendAuth,
step: impl FnOnce(&mut R, A) -> B,
) -> OrchardBundle<B> {
match self {
OrchardBundle::OrchardVanilla(b) => OrchardBundle::OrchardVanilla(Box::new(
b.map_authorization(context, spend_auth, step),
)),
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
OrchardBundle::OrchardZSA(b) => OrchardBundle::OrchardZSA(Box::new(b.map_authorization(
context_zsa,
spend_auth_zsa,
step_zsa,
))),
_ => unreachable!(),
OrchardBundle::OrchardZSA(b) => {
OrchardBundle::OrchardZSA(Box::new(b.map_authorization(context, spend_auth, step)))
}
}
}
}
Expand All @@ -442,7 +412,7 @@ pub struct TransactionData<A: Authorization> {
transparent_bundle: Option<transparent::Bundle<A::TransparentAuth>>,
sprout_bundle: Option<sprout::Bundle>,
sapling_bundle: Option<sapling::Bundle<A::SaplingAuth, Amount>>,
orchard_bundle: Option<OrchardBundle<A::OrchardAuth, A::OrchardZsaAuth>>,
orchard_bundle: Option<OrchardBundle<A::OrchardAuth>>,
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
issue_bundle: Option<IssueBundle<A::IssueAuth>>,
#[cfg(zcash_unstable = "zfuture")]
Expand All @@ -460,7 +430,7 @@ impl<A: Authorization> TransactionData<A> {
transparent_bundle: Option<transparent::Bundle<A::TransparentAuth>>,
sprout_bundle: Option<sprout::Bundle>,
sapling_bundle: Option<sapling::Bundle<A::SaplingAuth, Amount>>,
orchard_bundle: Option<OrchardBundle<A::OrchardAuth, A::OrchardZsaAuth>>,
orchard_bundle: Option<OrchardBundle<A::OrchardAuth>>,
#[rustfmt::skip]
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
issue_bundle: Option<IssueBundle<A::IssueAuth>>,
Expand Down Expand Up @@ -539,7 +509,7 @@ impl<A: Authorization> TransactionData<A> {
self.sapling_bundle.as_ref()
}

pub fn orchard_bundle(&self) -> Option<&OrchardBundle<A::OrchardAuth, A::OrchardZsaAuth>> {
pub fn orchard_bundle(&self) -> Option<&OrchardBundle<A::OrchardAuth>> {
self.orchard_bundle.as_ref()
}

Expand Down Expand Up @@ -618,8 +588,8 @@ impl<A: Authorization> TransactionData<A> {
Option<sapling::Bundle<A::SaplingAuth, Amount>>,
) -> Option<sapling::Bundle<B::SaplingAuth, Amount>>,
f_orchard: impl FnOnce(
Option<OrchardBundle<A::OrchardAuth, A::OrchardZsaAuth>>,
) -> Option<OrchardBundle<B::OrchardAuth, B::OrchardZsaAuth>>,
Option<OrchardBundle<A::OrchardAuth>>,
) -> Option<OrchardBundle<B::OrchardAuth>>,
#[rustfmt::skip]
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
f_issue: impl FnOnce(
Expand Down Expand Up @@ -651,11 +621,6 @@ impl<A: Authorization> TransactionData<A> {
f_transparent: impl transparent::MapAuth<A::TransparentAuth, B::TransparentAuth>,
mut f_sapling: impl sapling_serialization::MapAuth<A::SaplingAuth, B::SaplingAuth>,
mut f_orchard: impl orchard_serialization::MapAuth<A::OrchardAuth, B::OrchardAuth>,
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
mut f_orchard_zsa: impl orchard_serialization::MapAuth<
A::OrchardZsaAuth,
B::OrchardZsaAuth,
>,
#[rustfmt::skip]
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
f_issue: impl issuance::MapIssueAuth<A::IssueAuth, B::IssueAuth>,
Expand All @@ -682,13 +647,7 @@ impl<A: Authorization> TransactionData<A> {
orchard_bundle: self.orchard_bundle.map(|b| {
b.map_authorization(
&mut f_orchard,
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
&mut f_orchard_zsa,
|f, _, s| f.map_spend_auth(s),
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
|f, _, s| f.map_spend_auth(s),
|f, a| f.map_authorization(a),
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
|f, a| f.map_authorization(a),
)
}),
Expand Down Expand Up @@ -1185,7 +1144,7 @@ pub trait TransactionDigest<A: Authorization> {

fn digest_orchard(
&self,
orchard_bundle: Option<&OrchardBundle<A::OrchardAuth, A::OrchardZsaAuth>>,
orchard_bundle: Option<&OrchardBundle<A::OrchardAuth>>,
) -> Self::OrchardDigest;

#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
Expand Down
4 changes: 0 additions & 4 deletions zcash_primitives/src/transaction/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,11 @@ fn check_roundtrip(tx: Transaction) -> Result<(), TestCaseError> {
OrchardVanilla(b) => *b.value_balance(),
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
OrchardZSA(b) => *b.value_balance(),
_ => unreachable!(),
}),
txo.orchard_bundle.as_ref().map(|v| match v {
OrchardVanilla(b) => *b.value_balance(),
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
OrchardZSA(b) => *b.value_balance(),
_ => unreachable!(),
})
);
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
Expand Down Expand Up @@ -228,8 +226,6 @@ impl Authorization for TestUnauthorized {
type SaplingAuth = sapling::bundle::Authorized;
type OrchardAuth = orchard::bundle::Authorized;

type OrchardZsaAuth = orchard::bundle::Authorized;

#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
type IssueAuth = orchard::issuance::Signed;

Expand Down
6 changes: 2 additions & 4 deletions zcash_primitives/src/transaction/txid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,14 +344,13 @@ impl<A: Authorization> TransactionDigest<A> for TxIdDigester {

fn digest_orchard(
&self,
orchard_bundle: Option<&OrchardBundle<A::OrchardAuth, A::OrchardZsaAuth>>,
orchard_bundle: Option<&OrchardBundle<A::OrchardAuth>>,
) -> Self::OrchardDigest {
orchard_bundle.map(|b| {
match b {
OrchardBundle::OrchardVanilla(vanilla_bundle) => vanilla_bundle.commitment().0,
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
OrchardBundle::OrchardZSA(zsa_bundle) => zsa_bundle.commitment().0,
_ => unreachable!(),
}
})
}
Expand Down Expand Up @@ -537,7 +536,7 @@ impl TransactionDigest<Authorized> for BlockTxCommitmentDigester {

fn digest_orchard(
&self,
orchard_bundle: Option<&OrchardBundle<bundle::Authorized, bundle::Authorized>>,
orchard_bundle: Option<&OrchardBundle<bundle::Authorized>>,
) -> Self::OrchardDigest {
orchard_bundle.map_or_else(bundle::commitments::hash_bundle_auth_empty, |b| {
match b {
Expand All @@ -546,7 +545,6 @@ impl TransactionDigest<Authorized> for BlockTxCommitmentDigester {
}
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
OrchardBundle::OrchardZSA(zsa_bundle) => zsa_bundle.authorizing_commitment().0,
_ => unreachable!(),
}
})
}
Expand Down

0 comments on commit 1c6529c

Please sign in to comment.