From d94482d5ac670dd56a165d7305a0e30e1868c3ef Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Fri, 28 May 2021 22:57:48 +0100 Subject: [PATCH] zcash_note_encryption: s/TryFrom/From on ExtractedCommitmentBytes bound This was left over from an earlier refactor where we could call a domain API to extract cmstar from a note commitment (which could fail for Orchard). This part of extraction was subsequently refactored into the domain logic (and is rejected earlier for Orchard). The resulting bound is wrong because it's always possible to serialize a scalar. Extracted from: https://github.com/zcash/librustzcash/commit/ee2b96c82d812cc9c36968d876b2f5a923637ac0 --- src/lib.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 95c725b..7855349 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,7 +5,6 @@ use crypto_api_chachapoly::{ChaCha20Ietf, ChachaPolyIetf}; use rand_core::RngCore; -use std::convert::TryFrom; use subtle::{Choice, ConstantTimeEq}; pub const COMPACT_NOTE_SIZE: usize = 1 + // version @@ -75,7 +74,7 @@ pub trait Domain { type OutgoingViewingKey; type ValueCommitment; type ExtractedCommitment; - type ExtractedCommitmentBytes: Eq + TryFrom; + type ExtractedCommitmentBytes: Eq + for<'a> From<&'a Self::ExtractedCommitment>; type Memo; fn derive_esk(note: &Self::Note) -> Option; @@ -384,9 +383,7 @@ fn check_note_validity( epk: &D::EphemeralPublicKey, cmstar_bytes: &D::ExtractedCommitmentBytes, ) -> NoteValidity { - if D::ExtractedCommitmentBytes::try_from(D::cmstar(¬e)) - .map_or(false, |cs| &cs == cmstar_bytes) - { + if &D::ExtractedCommitmentBytes::from(&D::cmstar(¬e)) == cmstar_bytes { let epk_bytes = D::epk_bytes(epk); D::check_epk_bytes(¬e, |derived_esk| { if D::epk_bytes(&D::ka_derive_public(¬e, &derived_esk))