zcash_primitives: Add some more `Clone` and `Debug` impls
This commit is contained in:
parent
4737839662
commit
241a1a3660
|
@ -12,6 +12,7 @@ and this library adheres to Rust's notion of
|
||||||
- `circuit` module (moved from `zcash_proofs::circuit::sapling`).
|
- `circuit` module (moved from `zcash_proofs::circuit::sapling`).
|
||||||
- `constants` module.
|
- `constants` module.
|
||||||
- `prover::{SpendProver, OutputProver}`
|
- `prover::{SpendProver, OutputProver}`
|
||||||
|
- `impl Debug for keys::{ExpandedSpendingKey, ProofGenerationKey}`
|
||||||
- Test helpers, behind the `test-dependencies` feature flag:
|
- Test helpers, behind the `test-dependencies` feature flag:
|
||||||
- `zcash_primitives::prover::mock::{MockSpendProver, MockOutputProver}`
|
- `zcash_primitives::prover::mock::{MockSpendProver, MockOutputProver}`
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
//! The Sapling circuits.
|
//! The Sapling circuits.
|
||||||
|
|
||||||
|
use core::fmt;
|
||||||
|
|
||||||
use group::{ff::PrimeField, Curve};
|
use group::{ff::PrimeField, Curve};
|
||||||
|
|
||||||
use bellman::{Circuit, ConstraintSystem, SynthesisError};
|
use bellman::{Circuit, ConstraintSystem, SynthesisError};
|
||||||
|
@ -46,6 +48,7 @@ impl ValueCommitmentOpening {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This is an instance of the `Spend` circuit.
|
/// This is an instance of the `Spend` circuit.
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct Spend {
|
pub struct Spend {
|
||||||
/// The opening of a Pedersen commitment to the value being spent.
|
/// The opening of a Pedersen commitment to the value being spent.
|
||||||
pub value_commitment_opening: Option<ValueCommitmentOpening>,
|
pub value_commitment_opening: Option<ValueCommitmentOpening>,
|
||||||
|
@ -71,7 +74,16 @@ pub struct Spend {
|
||||||
pub anchor: Option<bls12_381::Scalar>,
|
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.
|
/// This is an output circuit instance.
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct Output {
|
pub struct Output {
|
||||||
/// The opening of a Pedersen commitment to the value being spent.
|
/// The opening of a Pedersen commitment to the value being spent.
|
||||||
pub value_commitment_opening: Option<ValueCommitmentOpening>,
|
pub value_commitment_opening: Option<ValueCommitmentOpening>,
|
||||||
|
@ -86,6 +98,12 @@ pub struct Output {
|
||||||
pub esk: Option<jubjub::Fr>,
|
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
|
/// Exposes a Pedersen commitment to the value as an
|
||||||
/// input to the circuit
|
/// input to the circuit
|
||||||
fn expose_value_commitment<CS>(
|
fn expose_value_commitment<CS>(
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
//!
|
//!
|
||||||
//! [section 4.2.2]: https://zips.z.cash/protocol/protocol.pdf#saplingkeycomponents
|
//! [section 4.2.2]: https://zips.z.cash/protocol/protocol.pdf#saplingkeycomponents
|
||||||
|
|
||||||
|
use std::fmt;
|
||||||
use std::io::{self, Read, Write};
|
use std::io::{self, Read, Write};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
|
@ -46,6 +47,13 @@ pub struct ExpandedSpendingKey {
|
||||||
pub ovk: OutgoingViewingKey,
|
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 {
|
impl ExpandedSpendingKey {
|
||||||
pub fn from_spending_key(sk: &[u8]) -> Self {
|
pub fn from_spending_key(sk: &[u8]) -> Self {
|
||||||
let ask = jubjub::Fr::from_bytes_wide(prf_expand(sk, &[0x00]).as_array());
|
let ask = jubjub::Fr::from_bytes_wide(prf_expand(sk, &[0x00]).as_array());
|
||||||
|
@ -119,6 +127,14 @@ pub struct ProofGenerationKey {
|
||||||
pub nsk: jubjub::Fr,
|
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 {
|
impl ProofGenerationKey {
|
||||||
pub fn to_viewing_key(&self) -> ViewingKey {
|
pub fn to_viewing_key(&self) -> ViewingKey {
|
||||||
ViewingKey {
|
ViewingKey {
|
||||||
|
@ -473,16 +489,9 @@ impl SharedSecret {
|
||||||
pub mod testing {
|
pub mod testing {
|
||||||
use proptest::collection::vec;
|
use proptest::collection::vec;
|
||||||
use proptest::prelude::*;
|
use proptest::prelude::*;
|
||||||
use std::fmt::{self, Debug, Formatter};
|
|
||||||
|
|
||||||
use super::{ExpandedSpendingKey, FullViewingKey, SaplingIvk};
|
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! {
|
prop_compose! {
|
||||||
pub fn arb_expanded_spending_key()(v in vec(any::<u8>(), 32..252)) -> ExpandedSpendingKey {
|
pub fn arb_expanded_spending_key()(v in vec(any::<u8>(), 32..252)) -> ExpandedSpendingKey {
|
||||||
ExpandedSpendingKey::from_spending_key(&v)
|
ExpandedSpendingKey::from_spending_key(&v)
|
||||||
|
|
Loading…
Reference in New Issue