diff --git a/zebra-chain/proptest-regressions/orchard/keys/tests.txt b/zebra-chain/proptest-regressions/orchard/keys/tests.txt new file mode 100644 index 00000000..6ae352ec --- /dev/null +++ b/zebra-chain/proptest-regressions/orchard/keys/tests.txt @@ -0,0 +1,7 @@ +# Seeds for failure cases proptest has generated in the past. It is +# automatically read and these particular cases re-run before any +# novel cases are generated. +# +# It is recommended to check this file in to source control so that +# everyone who runs the test benefits from these saved cases. +cc 8ba80e3da74dc90c627f620bed08c47e7a13bb2e7762aad6e8c8f362237aed1b # shrinks to spending_key = SpendingKey { network: Mainnet, bytes: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] } diff --git a/zebra-chain/src/orchard/keys.rs b/zebra-chain/src/orchard/keys.rs index 4a210ae2..6975217d 100644 --- a/zebra-chain/src/orchard/keys.rs +++ b/zebra-chain/src/orchard/keys.rs @@ -11,11 +11,10 @@ use std::{ convert::{From, Into, TryFrom, TryInto}, fmt, io::{self, Write}, - str::FromStr, }; use aes::Aes256; -use bech32::{self, FromBase32, ToBase32, Variant}; +use bech32::{self, ToBase32, Variant}; use bitvec::prelude::*; use fpe::ff1::{BinaryNumeralString, FF1}; use group::{Group, GroupEncoding}; @@ -161,31 +160,6 @@ impl fmt::Display for SpendingKey { } } -impl FromStr for SpendingKey { - type Err = SerializationError; - - fn from_str(s: &str) -> Result { - match bech32::decode(s) { - Ok((hrp, bytes, Variant::Bech32)) => { - let decoded = Vec::::from_base32(&bytes).unwrap(); - - let mut decoded_bytes = [0u8; 32]; - decoded_bytes[..].copy_from_slice(&decoded[0..32]); - - Ok(SpendingKey { - network: match hrp.as_str() { - sk_hrp::MAINNET => Network::Mainnet, - sk_hrp::TESTNET => Network::Testnet, - _ => return Err(SerializationError::Parse("unknown network")), - }, - bytes: decoded_bytes, - }) - } - _ => Err(SerializationError::Parse("bech32 decoding error")), - } - } -} - impl SpendingKey { /// Generate a new `SpendingKey`. /// @@ -493,30 +467,6 @@ impl From for IncomingViewingKey { } } -impl FromStr for IncomingViewingKey { - type Err = SerializationError; - - fn from_str(s: &str) -> Result { - match bech32::decode(s) { - Ok((hrp, bytes, Variant::Bech32)) => { - let decoded = Vec::::from_base32(&bytes).unwrap(); - - let mut scalar_bytes = [0u8; 32]; - scalar_bytes[..].copy_from_slice(&decoded[0..32]); - - Ok(IncomingViewingKey { - network: match hrp.as_str() { - ivk_hrp::MAINNET => Network::Mainnet, - _ => Network::Testnet, - }, - scalar: pallas::Scalar::from_bytes(&scalar_bytes).unwrap(), - }) - } - _ => Err(SerializationError::Parse("bech32 decoding error")), - } - } -} - impl PartialEq<[u8; 32]> for IncomingViewingKey { fn eq(&self, other: &[u8; 32]) -> bool { self.scalar.to_bytes() == *other @@ -588,33 +538,6 @@ impl fmt::Display for FullViewingKey { } } -impl FromStr for FullViewingKey { - type Err = SerializationError; - - fn from_str(s: &str) -> Result { - match bech32::decode(s) { - Ok((hrp, bytes, Variant::Bech32)) => { - let mut decoded_bytes = io::Cursor::new(Vec::::from_base32(&bytes).unwrap()); - - let ak_bytes = decoded_bytes.read_32_bytes()?; - let nk_bytes = decoded_bytes.read_32_bytes()?; - let rivk_bytes = decoded_bytes.read_32_bytes()?; - - Ok(FullViewingKey { - network: match hrp.as_str() { - fvk_hrp::MAINNET => Network::Mainnet, - _ => Network::Testnet, - }, - spend_validating_key: SpendValidatingKey::from(ak_bytes), - nullifier_deriving_key: NullifierDerivingKey::from(nk_bytes), - ivk_commit_randomness: IvkCommitRandomness::try_from(rivk_bytes).unwrap(), - }) - } - _ => Err(SerializationError::Parse("bech32 decoding error")), - } - } -} - impl FullViewingKey { /// [4.2.3]: https://zips.z.cash/protocol/nu5.pdf#orchardkeycomponents #[allow(non_snake_case)] diff --git a/zebra-chain/src/orchard/keys/tests.rs b/zebra-chain/src/orchard/keys/tests.rs index 84ec4abc..93e62047 100644 --- a/zebra-chain/src/orchard/keys/tests.rs +++ b/zebra-chain/src/orchard/keys/tests.rs @@ -30,13 +30,9 @@ impl Arbitrary for TransmissionKey { proptest! { #[test] - fn string_roundtrips(spending_key in any::()) { + fn generate_keys(spending_key in any::()) { zebra_test::init(); - let sk_string = spending_key.to_string(); - let spending_key_2: SpendingKey = sk_string.parse().unwrap(); - prop_assert_eq![spending_key, spending_key_2]; - let spend_authorizing_key = SpendAuthorizingKey::from(spending_key); let spend_validating_key = SpendValidatingKey::from(spend_authorizing_key); @@ -50,17 +46,9 @@ proptest! { ivk_commit_randomness, }; - let fvk_string = full_viewing_key.to_string(); - let full_viewing_key_2: FullViewingKey = fvk_string.parse().unwrap(); - prop_assert_eq![full_viewing_key, full_viewing_key_2]; - let diversifier_key = DiversifierKey::from(full_viewing_key); let incoming_viewing_key = IncomingViewingKey::from(full_viewing_key); - let ivk_string = incoming_viewing_key.to_string(); - let incoming_viewing_key_2: IncomingViewingKey = ivk_string.parse().unwrap(); - prop_assert_eq![incoming_viewing_key, incoming_viewing_key_2]; - let _outgoing_viewing_key = OutgoingViewingKey::from(full_viewing_key); let diversifier = Diversifier::from(diversifier_key);