From a8003c8ff52973dc506a9a0f05d37f39753256b6 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Wed, 8 Mar 2023 03:45:01 +0000 Subject: [PATCH] Temporarily re-expose ability to construct invalid Sapling bundles Until zcash/zcash#6397 is closed, this ability is needed by `zcashd` for crossing the FFI. --- zcash_primitives/CHANGELOG.md | 10 +++ zcash_primitives/Cargo.toml | 3 +- .../src/transaction/components/sapling.rs | 62 ++++++++++++++++++- 3 files changed, 71 insertions(+), 4 deletions(-) diff --git a/zcash_primitives/CHANGELOG.md b/zcash_primitives/CHANGELOG.md index 0dcaa7fbe..b017d7909 100644 --- a/zcash_primitives/CHANGELOG.md +++ b/zcash_primitives/CHANGELOG.md @@ -7,6 +7,16 @@ and this library adheres to Rust's notion of ## [Unreleased] +## [0.10.1] - 2023-03-08 +### Added +- Sapling bundle component constructors, behind the `temporary-zcashd` feature + flag. These temporarily re-expose the ability to construct invalid Sapling + bundles (that was removed in 0.10.0), and will be removed in a future release: + - `zcash_primitives::transaction::components::sapling`: + - `Bundle::temporary_zcashd_from_parts` + - `SpendDescription::temporary_zcashd_from_parts` + - `OutputDescription::temporary_zcashd_from_parts` + ## [0.10.0] - 2023-02-01 ### Added - `zcash_primitives::sapling`: diff --git a/zcash_primitives/Cargo.toml b/zcash_primitives/Cargo.toml index bda15d5fb..d0e7e8e38 100644 --- a/zcash_primitives/Cargo.toml +++ b/zcash_primitives/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "zcash_primitives" description = "Rust implementations of the Zcash primitives" -version = "0.10.0" +version = "0.10.1" authors = [ "Jack Grigg ", "Kris Nuttycombe " @@ -98,6 +98,7 @@ inferno = ">=0.11, <0.11.5" # MSRV 1.59 [features] transparent-inputs = ["hdwallet", "ripemd", "secp256k1"] +temporary-zcashd = [] test-dependencies = ["proptest", "orchard/test-dependencies"] zfuture = [] diff --git a/zcash_primitives/src/transaction/components/sapling.rs b/zcash_primitives/src/transaction/components/sapling.rs index 7730098e4..dc1b66380 100644 --- a/zcash_primitives/src/transaction/components/sapling.rs +++ b/zcash_primitives/src/transaction/components/sapling.rs @@ -105,6 +105,22 @@ pub struct Bundle { } impl Bundle { + /// Constructs a `Bundle` from its constituent parts. + #[cfg(feature = "temporary-zcashd")] + pub fn temporary_zcashd_from_parts( + shielded_spends: Vec>, + shielded_outputs: Vec>, + value_balance: Amount, + authorization: A, + ) -> Self { + Self::from_parts( + shielded_spends, + shielded_outputs, + value_balance, + authorization, + ) + } + /// Constructs a `Bundle` from its constituent parts. pub(crate) fn from_parts( shielded_spends: Vec>, @@ -197,6 +213,25 @@ impl std::fmt::Debug for SpendDescription { } impl SpendDescription { + #[cfg(feature = "temporary-zcashd")] + pub fn temporary_zcashd_from_parts( + cv: ValueCommitment, + anchor: bls12_381::Scalar, + nullifier: Nullifier, + rk: PublicKey, + zkproof: A::SpendProof, + spend_auth_sig: A::AuthSig, + ) -> Self { + Self { + cv, + anchor, + nullifier, + rk, + zkproof, + spend_auth_sig, + } + } + /// Returns the commitment to the value consumed by this spend. pub fn cv(&self) -> &ValueCommitment { &self.cv @@ -410,10 +445,27 @@ impl OutputDescription { pub fn zkproof(&self) -> &Proof { &self.zkproof } -} -#[cfg(test)] -impl OutputDescription { + #[cfg(feature = "temporary-zcashd")] + pub fn temporary_zcashd_from_parts( + cv: ValueCommitment, + cmu: ExtractedNoteCommitment, + ephemeral_key: EphemeralKeyBytes, + enc_ciphertext: [u8; 580], + out_ciphertext: [u8; 80], + zkproof: Proof, + ) -> Self { + Self::from_parts( + cv, + cmu, + ephemeral_key, + enc_ciphertext, + out_ciphertext, + zkproof, + ) + } + + #[cfg(any(test, feature = "temporary-zcashd"))] pub(crate) fn from_parts( cv: ValueCommitment, cmu: ExtractedNoteCommitment, @@ -431,6 +483,10 @@ impl OutputDescription { zkproof, } } +} + +#[cfg(test)] +impl OutputDescription { pub(crate) fn cv_mut(&mut self) -> &mut ValueCommitment { &mut self.cv }