From 012d43bc8cae0a13340227a4c3bb0a4a859b9c07 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Sun, 18 Nov 2018 13:13:43 +0000 Subject: [PATCH] derive Debug for various structs --- sapling-crypto/src/jubjub/edwards.rs | 1 + sapling-crypto/src/jubjub/mod.rs | 1 + sapling-crypto/src/redjubjub.rs | 3 +- .../src/transaction/components.rs | 57 +++++++++++++++++++ zcash_primitives/src/transaction/mod.rs | 36 ++++++++++++ 5 files changed, 97 insertions(+), 1 deletion(-) diff --git a/sapling-crypto/src/jubjub/edwards.rs b/sapling-crypto/src/jubjub/edwards.rs index 49018fe..3aa9345 100644 --- a/sapling-crypto/src/jubjub/edwards.rs +++ b/sapling-crypto/src/jubjub/edwards.rs @@ -25,6 +25,7 @@ use std::io::{ // // See "Twisted Edwards Curves Revisited" // Huseyin Hisil, Kenneth Koon-Ho Wong, Gary Carter, and Ed Dawson +#[derive(Debug)] pub struct Point { x: E::Fr, y: E::Fr, diff --git a/sapling-crypto/src/jubjub/mod.rs b/sapling-crypto/src/jubjub/mod.rs index e46fac5..c925877 100644 --- a/sapling-crypto/src/jubjub/mod.rs +++ b/sapling-crypto/src/jubjub/mod.rs @@ -43,6 +43,7 @@ pub mod fs; pub mod tests; /// Point of unknown order. +#[derive(Debug)] pub enum Unknown { } /// Point of prime order. diff --git a/sapling-crypto/src/redjubjub.rs b/sapling-crypto/src/redjubjub.rs index e159179..00e2f8f 100644 --- a/sapling-crypto/src/redjubjub.rs +++ b/sapling-crypto/src/redjubjub.rs @@ -29,7 +29,7 @@ fn h_star(a: &[u8], b: &[u8]) -> E::Fs { hash_to_scalar::(b"Zcash_RedJubjubH", a, b) } -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Debug)] pub struct Signature { rbar: [u8; 32], sbar: [u8; 32], @@ -37,6 +37,7 @@ pub struct Signature { pub struct PrivateKey(pub E::Fs); +#[derive(Debug)] pub struct PublicKey(pub Point); impl Signature { diff --git a/zcash_primitives/src/transaction/components.rs b/zcash_primitives/src/transaction/components.rs index 39b468d..9d5a2a0 100644 --- a/zcash_primitives/src/transaction/components.rs +++ b/zcash_primitives/src/transaction/components.rs @@ -58,6 +58,7 @@ impl Amount { } } +#[derive(Debug)] pub struct Script(pub Vec); impl Script { @@ -71,6 +72,7 @@ impl Script { } } +#[derive(Debug)] pub struct OutPoint { hash: [u8; 32], n: u32, @@ -90,6 +92,7 @@ impl OutPoint { } } +#[derive(Debug)] pub struct TxIn { pub prevout: OutPoint, script_sig: Script, @@ -116,6 +119,7 @@ impl TxIn { } } +#[derive(Debug)] pub struct TxOut { value: Amount, script_pubkey: Script, @@ -147,6 +151,16 @@ pub struct SpendDescription { pub spend_auth_sig: Signature, } +impl std::fmt::Debug for SpendDescription { + fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { + write!( + f, + "SpendDescription(cv = {:?}, anchor = {:?}, nullifier = {:?}, rk = {:?}, spend_auth_sig = {:?})", + self.cv, self.anchor, self.nullifier, self.rk, self.spend_auth_sig + ) + } +} + impl SpendDescription { pub fn read(mut reader: &mut R) -> io::Result { // Consensus rules (§4.4): @@ -211,6 +225,16 @@ pub struct OutputDescription { pub zkproof: [u8; GROTH_PROOF_SIZE], } +impl std::fmt::Debug for OutputDescription { + fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { + write!( + f, + "OutputDescription(cv = {:?}, cmu = {:?}, ephemeral_key = {:?})", + self.cv, self.cmu, self.ephemeral_key + ) + } +} + impl OutputDescription { pub fn read(mut reader: &mut R) -> io::Result { // Consensus rules (§4.5): @@ -268,6 +292,15 @@ enum SproutProof { PHGR([u8; PHGR_PROOF_SIZE]), } +impl std::fmt::Debug for SproutProof { + fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { + match self { + SproutProof::Groth(_) => write!(f, "SproutProof::Groth"), + SproutProof::PHGR(_) => write!(f, "SproutProof::PHGR"), + } + } +} + pub struct JSDescription { vpub_old: Amount, vpub_new: Amount, @@ -281,6 +314,30 @@ pub struct JSDescription { ciphertexts: [[u8; 601]; ZC_NUM_JS_OUTPUTS], } +impl std::fmt::Debug for JSDescription { + fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { + write!( + f, + "JSDescription( + vpub_old = {:?}, vpub_new = {:?}, + anchor = {:?}, + nullifiers = {:?}, + commitments = {:?}, + ephemeral_key = {:?}, + random_seed = {:?}, + macs = {:?})", + self.vpub_old, + self.vpub_new, + self.anchor, + self.nullifiers, + self.commitments, + self.ephemeral_key, + self.random_seed, + self.macs + ) + } +} + impl JSDescription { pub fn read(mut reader: R, use_groth: bool) -> io::Result { // Consensus rule (§4.3): Canonical encoding is enforced here diff --git a/zcash_primitives/src/transaction/mod.rs b/zcash_primitives/src/transaction/mod.rs index 787c01d..70934e1 100644 --- a/zcash_primitives/src/transaction/mod.rs +++ b/zcash_primitives/src/transaction/mod.rs @@ -21,6 +21,7 @@ const SAPLING_VERSION_GROUP_ID: u32 = 0x892F2085; const SAPLING_TX_VERSION: u32 = 4; /// A Zcash transaction. +#[derive(Debug)] pub struct Transaction(TransactionData); impl Deref for Transaction { @@ -48,6 +49,41 @@ pub struct TransactionData { pub binding_sig: Option, } +impl std::fmt::Debug for TransactionData { + fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { + write!( + f, + "TransactionData( + overwintered = {:?}, + version = {:?}, + version_group_id = {:?}, + vin = {:?}, + vout = {:?}, + lock_time = {:?}, + expiry_height = {:?}, + value_balance = {:?}, + shielded_spends = {:?}, + shielded_outputs = {:?}, + joinsplits = {:?}, + joinsplit_pubkey = {:?}, + binding_sig = {:?})", + self.overwintered, + self.version, + self.version_group_id, + self.vin, + self.vout, + self.lock_time, + self.expiry_height, + self.value_balance, + self.shielded_spends, + self.shielded_outputs, + self.joinsplits, + self.joinsplit_pubkey, + self.binding_sig + ) + } +} + impl TransactionData { pub fn new() -> Self { TransactionData {