programmingbitcoin icon indicating copy to clipboard operation
programmingbitcoin copied to clipboard

Bug when signing segwit transaction with non-segwit inputs

Open justinmoon opened this issue 6 years ago • 1 comments

When signing a segwit transaction with non-segwit inputs, this line fails because tx_in.witness is not defined.

A simple fix is to initialize self.witness = b'' in the TxIn constructor. Then TxIn.witness is always defined, result += int_to_little_endian(len(tx_in.witness), 1) correctly writes b'\x00' representing empty witness for non-segwit inputs, and for item in tx_in.witness: is skipped because it has nothing to iterate over.

justinmoon avatar Jul 12 '19 05:07 justinmoon

empty list also works

scgbckbone avatar Feb 26 '20 12:02 scgbckbone