diff --git a/zcash_primitives/CHANGELOG.md b/zcash_primitives/CHANGELOG.md index 0cc06dc31..f8a26f20e 100644 --- a/zcash_primitives/CHANGELOG.md +++ b/zcash_primitives/CHANGELOG.md @@ -12,6 +12,7 @@ and this library adheres to Rust's notion of - `circuit` module (moved from `zcash_proofs::circuit::sapling`). - `constants` module. - `prover::{SpendProver, OutputProver}` + - `impl Debug for keys::{ExpandedSpendingKey, ProofGenerationKey}` - Test helpers, behind the `test-dependencies` feature flag: - `zcash_primitives::prover::mock::{MockSpendProver, MockOutputProver}` diff --git a/zcash_primitives/src/sapling/circuit.rs b/zcash_primitives/src/sapling/circuit.rs index 78ef9b847..036941f22 100644 --- a/zcash_primitives/src/sapling/circuit.rs +++ b/zcash_primitives/src/sapling/circuit.rs @@ -1,5 +1,7 @@ //! The Sapling circuits. +use core::fmt; + use group::{ff::PrimeField, Curve}; use bellman::{Circuit, ConstraintSystem, SynthesisError}; @@ -46,6 +48,7 @@ impl ValueCommitmentOpening { } /// This is an instance of the `Spend` circuit. +#[derive(Clone)] pub struct Spend { /// The opening of a Pedersen commitment to the value being spent. pub value_commitment_opening: Option, @@ -71,7 +74,16 @@ pub struct Spend { pub anchor: Option, } +impl fmt::Debug for Spend { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Spend") + .field("anchor", &self.anchor) + .finish_non_exhaustive() + } +} + /// This is an output circuit instance. +#[derive(Clone)] pub struct Output { /// The opening of a Pedersen commitment to the value being spent. pub value_commitment_opening: Option, @@ -86,6 +98,12 @@ pub struct Output { pub esk: Option, } +impl fmt::Debug for Output { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Output").finish_non_exhaustive() + } +} + /// Exposes a Pedersen commitment to the value as an /// input to the circuit fn expose_value_commitment( diff --git a/zcash_primitives/src/sapling/keys.rs b/zcash_primitives/src/sapling/keys.rs index 3fd458f49..aa26edd6a 100644 --- a/zcash_primitives/src/sapling/keys.rs +++ b/zcash_primitives/src/sapling/keys.rs @@ -4,6 +4,7 @@ //! //! [section 4.2.2]: https://zips.z.cash/protocol/protocol.pdf#saplingkeycomponents +use std::fmt; use std::io::{self, Read, Write}; use super::{ @@ -46,6 +47,13 @@ pub struct ExpandedSpendingKey { pub ovk: OutgoingViewingKey, } +impl fmt::Debug for ExpandedSpendingKey { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("ExpandedSpendingKey") + .finish_non_exhaustive() + } +} + impl ExpandedSpendingKey { pub fn from_spending_key(sk: &[u8]) -> Self { let ask = jubjub::Fr::from_bytes_wide(prf_expand(sk, &[0x00]).as_array()); @@ -119,6 +127,14 @@ pub struct ProofGenerationKey { pub nsk: jubjub::Fr, } +impl fmt::Debug for ProofGenerationKey { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("ProofGenerationKey") + .field("ak", &self.ak) + .finish_non_exhaustive() + } +} + impl ProofGenerationKey { pub fn to_viewing_key(&self) -> ViewingKey { ViewingKey { @@ -473,16 +489,9 @@ impl SharedSecret { pub mod testing { use proptest::collection::vec; use proptest::prelude::*; - use std::fmt::{self, Debug, Formatter}; use super::{ExpandedSpendingKey, FullViewingKey, SaplingIvk}; - impl Debug for ExpandedSpendingKey { - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - write!(f, "Spending keys cannot be Debug-formatted.") - } - } - prop_compose! { pub fn arb_expanded_spending_key()(v in vec(any::(), 32..252)) -> ExpandedSpendingKey { ExpandedSpendingKey::from_spending_key(&v)