@@ -219,7 +219,16 @@ pub fn derive_public_key<T: secp256k1::Signing>(secp_ctx: &Secp256k1<T>, per_com
219
219
let mut sha = Sha256 :: engine ( ) ;
220
220
sha. input ( & per_commitment_point. serialize ( ) ) ;
221
221
sha. input ( & base_point. serialize ( ) ) ;
222
- let res = Sha256 :: from_engine ( sha) . into_inner ( ) ;
222
+ let mut res = Sha256 :: from_engine ( sha) . into_inner ( ) ;
223
+
224
+ // In fuzztarget we can get 0-hashes, but they are invalid tweaks, so just increment them.
225
+ #[ cfg( feature = "fuzztarget" ) ]
226
+ {
227
+ if res == [ 0 ; 32 ] {
228
+ res[ 31 ] = 1 ;
229
+ }
230
+ }
231
+ res[ 0 ] = res[ 0 ] ; // Ignore fuzztarget-only mut
223
232
224
233
let hashkey = PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & res) ?) ;
225
234
base_point. combine ( & hashkey)
@@ -273,21 +282,35 @@ pub fn derive_private_revocation_key<T: secp256k1::Signing>(secp_ctx: &Secp256k1
273
282
/// Note that this is infallible iff we trust that at least one of the two input keys are randomly
274
283
/// generated (ie our own).
275
284
pub fn derive_public_revocation_key < T : secp256k1:: Verification > ( secp_ctx : & Secp256k1 < T > , per_commitment_point : & PublicKey , countersignatory_revocation_base_point : & PublicKey ) -> Result < PublicKey , SecpError > {
276
- let rev_append_commit_hash_key = {
285
+ let mut rev_append_commit_hash_key = {
277
286
let mut sha = Sha256 :: engine ( ) ;
278
287
sha. input ( & countersignatory_revocation_base_point. serialize ( ) ) ;
279
288
sha. input ( & per_commitment_point. serialize ( ) ) ;
280
289
281
290
Sha256 :: from_engine ( sha) . into_inner ( )
282
291
} ;
283
- let commit_append_rev_hash_key = {
292
+ let mut commit_append_rev_hash_key = {
284
293
let mut sha = Sha256 :: engine ( ) ;
285
294
sha. input ( & per_commitment_point. serialize ( ) ) ;
286
295
sha. input ( & countersignatory_revocation_base_point. serialize ( ) ) ;
287
296
288
297
Sha256 :: from_engine ( sha) . into_inner ( )
289
298
} ;
290
299
300
+ // In fuzztarget we can get 0-hashes, but they are invalid tweaks, so just increment them.
301
+ #[ cfg( feature = "fuzztarget" ) ]
302
+ {
303
+ if rev_append_commit_hash_key == [ 0 ; 32 ] {
304
+ rev_append_commit_hash_key[ 31 ] = 1 ;
305
+ }
306
+
307
+ if commit_append_rev_hash_key == [ 0 ; 32 ] {
308
+ commit_append_rev_hash_key[ 31 ] = 1 ;
309
+ }
310
+ }
311
+ rev_append_commit_hash_key[ 0 ] = rev_append_commit_hash_key[ 0 ] ; // Ignore fuzztarget-only mut
312
+ commit_append_rev_hash_key[ 0 ] = commit_append_rev_hash_key[ 0 ] ; // Ignore fuzztarget-only mut
313
+
291
314
let mut countersignatory_contrib = countersignatory_revocation_base_point. clone ( ) ;
292
315
countersignatory_contrib. mul_assign ( & secp_ctx, & rev_append_commit_hash_key) ?;
293
316
let mut broadcaster_contrib = per_commitment_point. clone ( ) ;
0 commit comments