Skip to content

Commit 6f7a97b

Browse files
committed
Format redpallas keys as hex when debugging
1 parent ad6dbc3 commit 6f7a97b

File tree

5 files changed

+28
-20
lines changed

5 files changed

+28
-20
lines changed

zebra-chain/src/orchard/arbitrary.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ impl Arbitrary for Signature<SpendAuth> {
7474
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy {
7575
(array::uniform32(any::<u8>()), array::uniform32(any::<u8>()))
7676
.prop_map(|(r_bytes, s_bytes)| Self {
77-
r_bytes,
78-
s_bytes,
77+
r_bytes: r_bytes.into(),
78+
s_bytes: s_bytes.into(),
7979
_marker: PhantomData,
8080
})
8181
.boxed()

zebra-chain/src/primitives/redpallas/batch.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ impl Verifier {
229229

230230
let s = {
231231
// XXX-pallas: should not use CtOption here
232-
let maybe_scalar = pallas::Scalar::from_repr(s_bytes);
232+
let maybe_scalar = pallas::Scalar::from_repr(*s_bytes);
233233
if maybe_scalar.is_some().into() {
234234
maybe_scalar.unwrap()
235235
} else {
@@ -258,10 +258,10 @@ impl Verifier {
258258
//
259259
// This validates the `rk` element, whose type is
260260
// SpendAuthSig^{Orchard}.Public, i.e. ℙ.
261-
VerificationKey::<SpendAuth>::try_from(vk_bytes.bytes)?.point
261+
VerificationKey::<SpendAuth>::try_from(*vk_bytes.bytes)?.point
262262
}
263263
Inner::Binding { vk_bytes, .. } => {
264-
VerificationKey::<Binding>::try_from(vk_bytes.bytes)?.point
264+
VerificationKey::<Binding>::try_from(*vk_bytes.bytes)?.point
265265
}
266266
};
267267

zebra-chain/src/primitives/redpallas/signature.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@ use std::{io, marker::PhantomData};
1212

1313
use super::SigType;
1414

15-
use crate::serialization::{ReadZcashExt, SerializationError, ZcashDeserialize, ZcashSerialize};
15+
use crate::{
16+
fmt::HexDebug,
17+
serialization::{ReadZcashExt, SerializationError, ZcashDeserialize, ZcashSerialize},
18+
};
1619

1720
/// A RedPallas signature.
1821
#[derive(Copy, Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
1922
pub struct Signature<T: SigType> {
20-
pub(crate) r_bytes: [u8; 32],
21-
pub(crate) s_bytes: [u8; 32],
23+
pub(crate) r_bytes: HexDebug<[u8; 32]>,
24+
pub(crate) s_bytes: HexDebug<[u8; 32]>,
2225
pub(crate) _marker: PhantomData<T>,
2326
}
2427

@@ -29,8 +32,8 @@ impl<T: SigType> From<[u8; 64]> for Signature<T> {
2932
let mut s_bytes = [0; 32];
3033
s_bytes.copy_from_slice(&bytes[32..64]);
3134
Signature {
32-
r_bytes,
33-
s_bytes,
35+
r_bytes: r_bytes.into(),
36+
s_bytes: s_bytes.into(),
3437
_marker: PhantomData,
3538
}
3639
}

zebra-chain/src/primitives/redpallas/signing_key.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use std::convert::{TryFrom, TryInto};
1+
//! Redpallas signing keys for Zebra.
2+
23
use std::marker::PhantomData;
34

45
use group::{ff::PrimeField, GroupEncoding};
@@ -117,8 +118,8 @@ impl<T: SigType> SigningKey<T> {
117118
let s_bytes = (nonce + (c * self.sk)).to_repr();
118119

119120
Signature {
120-
r_bytes,
121-
s_bytes,
121+
r_bytes: r_bytes.into(),
122+
s_bytes: s_bytes.into(),
122123
_marker: PhantomData,
123124
}
124125
}

zebra-chain/src/primitives/redpallas/verification_key.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
//! Redpallas verification keys for Zebra.
2+
13
use std::marker::PhantomData;
24

35
use group::{cofactor::CofactorGroup, ff::PrimeField, GroupEncoding};
46
use halo2::pasta::pallas;
57

8+
use crate::fmt::HexDebug;
9+
610
use super::*;
711

812
/// A refinement type for `[u8; 32]` indicating that the bytes represent
@@ -13,22 +17,22 @@ use super::*;
1317
/// used in signature verification.
1418
#[derive(Copy, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
1519
pub struct VerificationKeyBytes<T: SigType> {
16-
pub(crate) bytes: [u8; 32],
20+
pub(crate) bytes: HexDebug<[u8; 32]>,
1721
pub(crate) _marker: PhantomData<T>,
1822
}
1923

2024
impl<T: SigType> From<[u8; 32]> for VerificationKeyBytes<T> {
2125
fn from(bytes: [u8; 32]) -> VerificationKeyBytes<T> {
2226
VerificationKeyBytes {
23-
bytes,
27+
bytes: bytes.into(),
2428
_marker: PhantomData,
2529
}
2630
}
2731
}
2832

2933
impl<T: SigType> From<VerificationKeyBytes<T>> for [u8; 32] {
3034
fn from(refined: VerificationKeyBytes<T>) -> [u8; 32] {
31-
refined.bytes
35+
*refined.bytes
3236
}
3337
}
3438

@@ -65,7 +69,7 @@ impl<T: SigType> From<VerificationKey<T>> for VerificationKeyBytes<T> {
6569

6670
impl<T: SigType> From<VerificationKey<T>> for [u8; 32] {
6771
fn from(pk: VerificationKey<T>) -> [u8; 32] {
68-
pk.bytes.bytes
72+
*pk.bytes.bytes
6973
}
7074
}
7175

@@ -107,7 +111,7 @@ impl VerificationKey<SpendAuth> {
107111
use super::private::Sealed;
108112
let point = self.point + (SpendAuth::basepoint() * randomizer);
109113
let bytes = VerificationKeyBytes {
110-
bytes: point.to_bytes(),
114+
bytes: point.to_bytes().into(),
111115
_marker: PhantomData,
112116
};
113117
VerificationKey { point, bytes }
@@ -118,7 +122,7 @@ impl<T: SigType> VerificationKey<T> {
118122
pub(crate) fn from_scalar(s: &pallas::Scalar) -> VerificationKey<T> {
119123
let point = T::basepoint() * s;
120124
let bytes = VerificationKeyBytes {
121-
bytes: point.to_bytes(),
125+
bytes: point.to_bytes().into(),
122126
_marker: PhantomData,
123127
};
124128
VerificationKey { point, bytes }
@@ -154,7 +158,7 @@ impl<T: SigType> VerificationKey<T> {
154158

155159
let s = {
156160
// XXX-pasta_curves: should not use CtOption here
157-
let maybe_scalar = pallas::Scalar::from_repr(signature.s_bytes);
161+
let maybe_scalar = pallas::Scalar::from_repr(*signature.s_bytes);
158162
if maybe_scalar.is_some().into() {
159163
maybe_scalar.unwrap()
160164
} else {

0 commit comments

Comments
 (0)