@@ -122,6 +122,9 @@ enum NoteValidity {
122122 Invalid ,
123123}
124124
125+ pub type ExtractedCommitment = bls12_381:: Scalar ;
126+ pub type ExtractedCommitmentBytes = [ u8 ; 32 ] ;
127+
125128/// Trait that encapsulates protocol-specific note encryption types and logic.
126129///
127130/// This trait enables most of the note encryption logic to be shared between Sapling and
@@ -138,8 +141,6 @@ pub trait Domain {
138141 type IncomingViewingKey ;
139142 type OutgoingViewingKey ;
140143 type ValueCommitment ;
141- type ExtractedCommitment ;
142- type ExtractedCommitmentBytes : Eq + for < ' a > From < & ' a Self :: ExtractedCommitment > ;
143144 type Memo ;
144145
145146 /// Derives the `EphemeralSecretKey` corresponding to this note.
@@ -209,7 +210,7 @@ pub trait Domain {
209210 fn derive_ock (
210211 ovk : & Self :: OutgoingViewingKey ,
211212 cv : & Self :: ValueCommitment ,
212- cmstar_bytes : & Self :: ExtractedCommitmentBytes ,
213+ cmstar_bytes : & ExtractedCommitmentBytes ,
213214 ephemeral_key : & EphemeralKeyBytes ,
214215 ) -> OutgoingCipherKey ;
215216
@@ -229,7 +230,7 @@ pub trait Domain {
229230 fn epk ( ephemeral_key : & EphemeralKeyBytes ) -> Option < Self :: EphemeralPublicKey > ;
230231
231232 /// Derives the `ExtractedCommitment` for this note.
232- fn cmstar ( note : & Self :: Note ) -> Self :: ExtractedCommitment ;
233+ fn cmstar ( note : & Self :: Note ) -> ExtractedCommitment ;
233234
234235 /// Parses the given note plaintext from the recipient's perspective.
235236 ///
@@ -349,7 +350,7 @@ pub trait ShieldedOutput<D: Domain, const CIPHERTEXT_SIZE: usize> {
349350 fn ephemeral_key ( & self ) -> EphemeralKeyBytes ;
350351
351352 /// Exposes the `cmu_bytes` or `cmx_bytes` field of the output.
352- fn cmstar_bytes ( & self ) -> D :: ExtractedCommitmentBytes ;
353+ fn cmstar_bytes ( & self ) -> ExtractedCommitmentBytes ;
353354
354355 /// Exposes the note ciphertext of the output.
355356 fn enc_ciphertext ( & self ) -> & [ u8 ; CIPHERTEXT_SIZE ] ;
@@ -450,11 +451,11 @@ impl<D: Domain> NoteEncryption<D> {
450451 pub fn encrypt_outgoing_plaintext < R : RngCore > (
451452 & self ,
452453 cv : & D :: ValueCommitment ,
453- cmstar : & D :: ExtractedCommitment ,
454+ cmstar : & ExtractedCommitment ,
454455 rng : & mut R ,
455456 ) -> [ u8 ; OUT_CIPHERTEXT_SIZE ] {
456457 let ( ock, input) = if let Some ( ovk) = & self . ovk {
457- let ock = D :: derive_ock ( ovk, cv, & cmstar. into ( ) , & D :: epk_bytes ( & self . epk ) ) ;
458+ let ock = D :: derive_ock ( ovk, cv, & cmstar. to_bytes_le ( ) , & D :: epk_bytes ( & self . epk ) ) ;
458459 let input = D :: outgoing_plaintext_bytes ( & self . note , & self . esk ) ;
459460
460461 ( ock, input)
@@ -539,7 +540,7 @@ fn parse_note_plaintext_without_memo_ivk<D: Domain>(
539540 domain : & D ,
540541 ivk : & D :: IncomingViewingKey ,
541542 ephemeral_key : & EphemeralKeyBytes ,
542- cmstar_bytes : & D :: ExtractedCommitmentBytes ,
543+ cmstar_bytes : & ExtractedCommitmentBytes ,
543544 plaintext : & [ u8 ] ,
544545) -> Option < ( D :: Note , D :: Recipient ) > {
545546 let ( note, to) = domain. parse_note_plaintext_without_memo_ivk ( ivk, plaintext) ?;
@@ -554,9 +555,9 @@ fn parse_note_plaintext_without_memo_ivk<D: Domain>(
554555fn check_note_validity < D : Domain > (
555556 note : & D :: Note ,
556557 ephemeral_key : & EphemeralKeyBytes ,
557- cmstar_bytes : & D :: ExtractedCommitmentBytes ,
558+ cmstar_bytes : & ExtractedCommitmentBytes ,
558559) -> NoteValidity {
559- if & D :: ExtractedCommitmentBytes :: from ( & D :: cmstar ( note) ) == cmstar_bytes {
560+ if & D :: cmstar ( note) . to_bytes_le ( ) == cmstar_bytes {
560561 if let Some ( derived_esk) = D :: derive_esk ( note) {
561562 if D :: epk_bytes ( & D :: ka_derive_public ( note, & derived_esk) )
562563 . ct_eq ( ephemeral_key)
0 commit comments