Skip to content

TransactionBuilder doesn't support varied sighash types in multisig signatures #417

@dthorpe

Description

@dthorpe

Is this a known issue?

If a transaction contains a multisignature script and the hash type used for each signature is not the same across all signatures in the multisig set, TransactionBuilder.fromTransaction(tx).build() will rewrite the hash type bytes of all the signatures to match the hash type of the last signature. This will cause signature verification to fail later for the signatures whose hash type byte was altered.

Example use case:

  1. Alice and Bob enter into a 2 of 2 multisig address. Funds are sent to the multisig address.
  2. Bob constructs a transaction spending from the 2 of 2 multisig address. The tx has a complete set of outputs but is missing other inputs (to be provided and signed by others later). Bob signs this tx with SIGHASH_ALL so that he can tell if the tx was altered in transit when he gets it back later.
  3. Bob sends the partially signed tx to Alice and asks Alice to sign input 0 with SIGHASH_ALL | SIGHASH_ANYONECANPAY using her private key. Alice signs and returns the updated tx to Bob.
  4. Bob receives the tx from Alice and verifies the signatures. Alice's signature passing verification means Alice signed the tx with the correct private key to spend from the 2 of 2 address. Bob's signature passing verification means that Alice (or intermediate parties) did not modify the inputs or outputs of the transaction, other than to sign them.
  5. Later, Bob adds inputs to the tx to spend from Carol's address. Carol signs with SIGHASH_ALL. Bob re-signs the tx with SIGHASH_ALL, since Bob's original signature is invalidated by the changes to the inputs. Alice's original signature is not affected by changes to inputs. The tx is now fully signed and ready for broadcast to the blockchain.

This is not a blocking issue for my use case as I have figured out a workaround.

If this is not a known issue and/or you need more detail I can put together code examples.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions