@@ -301,9 +301,18 @@ def feerate_from_psbt(bitcoind, node, psbt):
301301 return fee / weight * 1000
302302
303303
304+ # I wish we could force libwally to use different entropy and thus force it to
305+ # create 71-byte sigs always!
306+ def did_short_sig (node ):
307+ # This can take a moment to appear in the log!
308+ time .sleep (1 )
309+ return node .daemon .is_in_log ('overgrind: short signature length' )
310+
311+
304312def test_txprepare (node_factory , bitcoind , chainparams ):
305313 amount = 1000000
306- l1 = node_factory .get_node (random_hsm = True )
314+ l1 = node_factory .get_node (random_hsm = True , options = {'dev-warn-on-overgrind' : None },
315+ broken_log = 'overgrind: short signature length' )
307316 addr = chainparams ['example_addr' ]
308317
309318 # Add some funds to withdraw later
@@ -324,7 +333,8 @@ def test_txprepare(node_factory, bitcoind, chainparams):
324333 assert len (decode ['vin' ]) == 4
325334 assert len (decode ['vout' ]) == 2 if not chainparams ['feeoutput' ] else 3
326335 # Feerate should be ~ as we asked for
327- assert normal_feerate_perkw - 1 < feerate_from_psbt (bitcoind , l1 , prep ['psbt' ]) < normal_feerate_perkw + 1
336+ if not did_short_sig (l1 ):
337+ assert normal_feerate_perkw - 1 < feerate_from_psbt (bitcoind , l1 , prep ['psbt' ]) < normal_feerate_perkw + 1
328338
329339 # One output will be correct.
330340 outnum = [i for i , o in enumerate (decode ['vout' ]) if o ['value' ] == Decimal (amount * 3 ) / 10 ** 8 ][0 ]
@@ -353,7 +363,8 @@ def test_txprepare(node_factory, bitcoind, chainparams):
353363 assert decode ['vout' ][0 ]['scriptPubKey' ]['type' ] == 'witness_v0_keyhash'
354364 assert scriptpubkey_addr (decode ['vout' ][0 ]['scriptPubKey' ]) == addr
355365 # Feerate should be ~ as we asked for
356- assert normal_feerate_perkw - 1 < feerate_from_psbt (bitcoind , l1 , prep2 ['psbt' ]) < normal_feerate_perkw + 1
366+ if not did_short_sig (l1 ):
367+ assert normal_feerate_perkw - 1 < feerate_from_psbt (bitcoind , l1 , prep2 ['psbt' ]) < normal_feerate_perkw + 1
357368
358369 # If I cancel the first one, I can get those first 4 outputs.
359370 discard = l1 .rpc .txdiscard (prep ['txid' ])
@@ -373,7 +384,8 @@ def test_txprepare(node_factory, bitcoind, chainparams):
373384 assert decode ['vout' ][0 ]['scriptPubKey' ]['type' ] == 'witness_v0_keyhash'
374385 assert scriptpubkey_addr (decode ['vout' ][0 ]['scriptPubKey' ]) == addr
375386 # Feerate should be ~ as we asked for
376- assert normal_feerate_perkw - 1 < feerate_from_psbt (bitcoind , l1 , prep3 ['psbt' ]) < normal_feerate_perkw + 1
387+ if not did_short_sig (l1 ):
388+ assert normal_feerate_perkw - 1 < feerate_from_psbt (bitcoind , l1 , prep3 ['psbt' ]) < normal_feerate_perkw + 1
377389
378390 # Cannot discard twice.
379391 with pytest .raises (RpcError , match = r'not an unreleased txid' ):
@@ -395,7 +407,8 @@ def test_txprepare(node_factory, bitcoind, chainparams):
395407 assert decode ['vout' ][0 ]['scriptPubKey' ]['type' ] == 'witness_v0_keyhash'
396408 assert scriptpubkey_addr (decode ['vout' ][0 ]['scriptPubKey' ]) == addr
397409 # Feerate should be ~ as we asked for
398- assert normal_feerate_perkw - 1 < feerate_from_psbt (bitcoind , l1 , prep4 ['psbt' ]) < normal_feerate_perkw + 1
410+ if not did_short_sig (l1 ):
411+ assert normal_feerate_perkw - 1 < feerate_from_psbt (bitcoind , l1 , prep4 ['psbt' ]) < normal_feerate_perkw + 1
399412 l1 .rpc .txdiscard (prep4 ['txid' ])
400413
401414 # Try passing in a utxo set
@@ -404,7 +417,8 @@ def test_txprepare(node_factory, bitcoind, chainparams):
404417 prep5 = l1 .rpc .txprepare ([{addr :
405418 Millisatoshi (amount * 3.5 * 1000 )}], utxos = utxos )
406419 # Feerate should be ~ as we asked for
407- assert normal_feerate_perkw - 1 < feerate_from_psbt (bitcoind , l1 , prep3 ['psbt' ]) < normal_feerate_perkw + 1
420+ if not did_short_sig (l1 ):
421+ assert normal_feerate_perkw - 1 < feerate_from_psbt (bitcoind , l1 , prep3 ['psbt' ]) < normal_feerate_perkw + 1
408422
409423 # Try passing unconfirmed utxos
410424 unconfirmed_utxo = l1 .rpc .withdraw (l1 .rpc .newaddr ()["bech32" ], 10 ** 5 )
@@ -445,15 +459,17 @@ def test_txprepare(node_factory, bitcoind, chainparams):
445459 prep5 = l1 .rpc .txprepare ([{addr : Millisatoshi (amount * 3 * 1000 )},
446460 {addr : 'all' }])
447461 # Feerate should be ~ as we asked for
448- assert normal_feerate_perkw - 1 < feerate_from_psbt (bitcoind , l1 , prep5 ['psbt' ]) < normal_feerate_perkw + 1
462+ if not did_short_sig (l1 ):
463+ assert normal_feerate_perkw - 1 < feerate_from_psbt (bitcoind , l1 , prep5 ['psbt' ]) < normal_feerate_perkw + 1
449464 l1 .rpc .txdiscard (prep5 ['txid' ])
450465 with pytest .raises (RpcError , match = r"'all'" ):
451466 prep5 = l1 .rpc .txprepare ([{addr : 'all' }, {addr : 'all' }])
452467
453468 prep5 = l1 .rpc .txprepare ([{addr : Millisatoshi (amount * 3 * 500 + 100000 )},
454469 {addr : Millisatoshi (amount * 3 * 500 - 100000 )}])
455470 # Feerate should be ~ as we asked for
456- assert normal_feerate_perkw - 1 < feerate_from_psbt (bitcoind , l1 , prep5 ['psbt' ]) < normal_feerate_perkw + 1
471+ if not did_short_sig (l1 ):
472+ assert normal_feerate_perkw - 1 < feerate_from_psbt (bitcoind , l1 , prep5 ['psbt' ]) < normal_feerate_perkw + 1
457473 decode = bitcoind .rpc .decoderawtransaction (prep5 ['unsigned_tx' ])
458474 assert decode ['txid' ] == prep5 ['txid' ]
459475 # 4 inputs, 3 outputs(include change).
@@ -485,7 +501,8 @@ def test_txprepare(node_factory, bitcoind, chainparams):
485501
486502def test_txprepare_feerate (node_factory , bitcoind ):
487503 # Make sure it works at different feerates!
488- l1 , l2 = node_factory .get_nodes (2 )
504+ l1 , l2 = node_factory .get_nodes (2 , opts = {'dev-warn-on-overgrind' : None ,
505+ 'broken_log' : 'overgrind: short signature length' })
489506
490507 # Add some funds to withdraw later
491508 for i in range (20 ):
@@ -499,7 +516,8 @@ def test_txprepare_feerate(node_factory, bitcoind):
499516 for addrtype in ('bech32' , 'p2tr' ):
500517 for feerate in range (255 , 10000 , 250 ):
501518 prep = l1 .rpc .txprepare ([{out_addrs [addrtype ]: Millisatoshi (9000 )}], f"{ feerate } perkw" )
502- assert feerate - 1 < feerate_from_psbt (bitcoind , l1 , prep ['psbt' ]) < feerate + 1
519+ if not did_short_sig (l1 ):
520+ assert feerate - 1 < feerate_from_psbt (bitcoind , l1 , prep ['psbt' ]) < feerate + 1
503521 l1 .rpc .txdiscard (prep ['txid' ])
504522
505523
0 commit comments