zcash_primitives: Add some more `Clone` and `Debug` impls

This commit is contained in:
Jack Grigg 2023-10-06 20:45:19 +00:00
parent 4737839662
commit 241a1a3660
3 changed files with 35 additions and 7 deletions

View File

@ -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}`

View File

@ -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<ValueCommitmentOpening>,
@ -71,7 +74,16 @@ pub struct Spend {
pub anchor: Option<bls12_381::Scalar>,
}
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<ValueCommitmentOpening>,
@ -86,6 +98,12 @@ pub struct Output {
pub esk: Option<jubjub::Fr>,
}
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<CS>(

View File

@ -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::<u8>(), 32..252)) -> ExpandedSpendingKey {
ExpandedSpendingKey::from_spending_key(&v)