Merge pull request #308 from zcash/improve-debug-impls

Improve `Debug` impls
This commit is contained in:
str4d 2022-04-06 18:59:33 +01:00 committed by GitHub
commit 2c0aed712a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 4 deletions

View File

@ -30,6 +30,7 @@ fpe = "0.5"
group = "0.11"
halo2_gadgets = "=0.1.0-beta.3"
halo2_proofs = "=0.1.0-beta.4"
hex = "0.4"
lazy_static = "1"
memuse = { version = "0.2", features = ["nonempty"] }
pasta_curves = "0.3"
@ -48,7 +49,6 @@ plotters = { version = "0.3.0", optional = true }
[dev-dependencies]
criterion = "0.3"
halo2_gadgets = { version = "=0.1.0-beta.3", features = ["test-dependencies"] }
hex = "0.4"
proptest = "1.0.0"
zcash_note_encryption = { version = "0.1", features = ["pre-zip-212"] }

View File

@ -237,7 +237,7 @@ pub trait Authorization: fmt::Debug {
}
/// A bundle of actions to be applied to the ledger.
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct Bundle<T: Authorization, V> {
/// The list of actions that make up this bundle.
actions: NonEmpty<Action<T::SpendAuth>>,
@ -253,6 +253,26 @@ pub struct Bundle<T: Authorization, V> {
authorization: T,
}
impl<T: Authorization, V: fmt::Debug> fmt::Debug for Bundle<T, V> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
/// Helper struct for debug-printing actions without exposing `NonEmpty`.
struct Actions<'a, T>(&'a NonEmpty<Action<T>>);
impl<'a, T: fmt::Debug> fmt::Debug for Actions<'a, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_list().entries(self.0.iter()).finish()
}
}
f.debug_struct("Bundle")
.field("actions", &Actions(&self.actions))
.field("flags", &self.flags)
.field("value_balance", &self.value_balance)
.field("anchor", &self.anchor)
.field("authorization", &self.authorization)
.finish()
}
}
impl<T: Authorization, V> Bundle<T, V> {
/// Constructs a `Bundle` from its constituent parts.
pub fn from_parts(

View File

@ -1,5 +1,7 @@
//! The Orchard Action circuit implementation.
use std::fmt;
use group::{Curve, GroupEncoding};
use halo2_proofs::{
circuit::{floor_planner, AssignedCell, Layouter},
@ -818,9 +820,22 @@ impl Instance {
/// A proof of the validity of an Orchard [`Bundle`].
///
/// [`Bundle`]: crate::bundle::Bundle
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct Proof(Vec<u8>);
impl fmt::Debug for Proof {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if f.alternate() {
f.debug_tuple("Proof").field(&self.0).finish()
} else {
// By default, only show the proof length, not its contents.
f.debug_tuple("Proof")
.field(&format_args!("{} bytes", self.0.len()))
.finish()
}
}
}
impl AsRef<[u8]> for Proof {
fn as_ref(&self) -> &[u8] {
&self.0

View File

@ -1,4 +1,6 @@
//! Data structures used for note construction.
use std::fmt;
use group::GroupEncoding;
use pasta_curves::pallas;
use rand::RngCore;
@ -236,7 +238,7 @@ impl Note {
}
/// An encrypted note.
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct TransmittedNoteCiphertext {
/// The serialization of the ephemeral public key
pub epk_bytes: [u8; 32],
@ -247,6 +249,16 @@ pub struct TransmittedNoteCiphertext {
pub out_ciphertext: [u8; 80],
}
impl fmt::Debug for TransmittedNoteCiphertext {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("TransmittedNoteCiphertext")
.field("epk_bytes", &self.epk_bytes)
.field("enc_ciphertext", &hex::encode(self.enc_ciphertext))
.field("out_ciphertext", &hex::encode(self.out_ciphertext))
.finish()
}
}
/// Generators for property testing.
#[cfg(any(test, feature = "test-dependencies"))]
#[cfg_attr(docsrs, doc(cfg(feature = "test-dependencies")))]