From db8f9cb81ab0e4999732d474a5c59069677ff4a4 Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Sat, 3 Apr 2021 19:14:34 -0400 Subject: [PATCH] orchard: Better Debug impls for some keys --- Cargo.lock | 6 +++--- zebra-chain/src/orchard/keys.rs | 36 ++++++++++++++++++++------------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 19c720403..dce30cd7d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1523,9 +1523,9 @@ source = "git+https://github.com/zcash/halo2.git?branch=main#b079624ea78b4a07d44 dependencies = [ "blake2b_simd", "crossbeam-utils 0.8.0", - "ff 0.9.0", + "ff", "funty", - "group 0.9.0", + "group", "num_cpus", "pasta_curves", "rand 0.8.1", @@ -4448,7 +4448,7 @@ dependencies = [ "fpe", "funty", "futures 0.3.14", - "group 0.9.0", + "group", "halo2", "hex", "itertools 0.10.0", diff --git a/zebra-chain/src/orchard/keys.rs b/zebra-chain/src/orchard/keys.rs index 7ddc28680..cfe0c9472 100644 --- a/zebra-chain/src/orchard/keys.rs +++ b/zebra-chain/src/orchard/keys.rs @@ -862,14 +862,18 @@ pub struct TransmissionKey(pub pallas::Affine); impl fmt::Debug for TransmissionKey { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - // This will panic if the public key is the identity, which is bad news - // bears. - let (x, y) = self.0.get_xy().unwrap(); + let mut d = f.debug_struct("TransmissionKey"); - f.debug_struct("TransmissionKey") - .field("x", &hex::encode(x.to_bytes())) - .field("y", &hex::encode(y.to_bytes())) - .finish() + match self.0.get_xy().into() { + Some((x, y)) => d + .field("x", &hex::encode(x.to_bytes())) + .field("y", &hex::encode(y.to_bytes())) + .finish(), + None => d + .field("x", &hex::encode(pallas::Base::zero().to_bytes())) + .field("y", &hex::encode(pallas::Base::zero().to_bytes())) + .finish(), + } } } @@ -921,14 +925,18 @@ pub struct EphemeralPublicKey(#[serde(with = "serde_helpers::Affine")] pub palla impl fmt::Debug for EphemeralPublicKey { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - // This will panic if the public key is the identity, which is bad news - // bears. - let (x, y) = self.0.get_xy().unwrap(); + let mut d = f.debug_struct("EphemeralPublicKey"); - f.debug_struct("EphemeralPublicKey") - .field("x", &hex::encode(x.to_bytes())) - .field("y", &hex::encode(y.to_bytes())) - .finish() + match self.0.get_xy().into() { + Some((x, y)) => d + .field("x", &hex::encode(x.to_bytes())) + .field("y", &hex::encode(y.to_bytes())) + .finish(), + None => d + .field("x", &hex::encode(pallas::Base::zero().to_bytes())) + .field("y", &hex::encode(pallas::Base::zero().to_bytes())) + .finish(), + } } }