Bitcoin Book of BIPs

BIP 67

Abstract

This BIP describes a method to deterministically generate multi-signature pay-to-script-hash transaction scripts. It focuses on defining how the public keys must be encoded and sorted so that the redeem script and corresponding P2SH address are always the same for a given set of keys and number of required signatures.

Motivation

Pay-to-script-hash (BIP-0011BIP-0011) is a transaction type that allows funding of arbitrary scripts, where the recipient carries the cost of fee’s associated with using longer, more complex scripts.

Multi-signature pay-to-script-hash transactions are defined in BIP-0016BIP-0016. The redeem script does not require a particular ordering or encoding for public keys. This means that for a given set of keys and number of required signatures, there are as many as 2(n!) possible standard redeem scripts, each with its separate P2SH address. Adhering to an ordering and key encoding would ensure that a multi-signature “account” (set of public keys and required signature count) has a canonical P2SH address.

By adopting a sorting and encoding standard, compliant wallets will always produce the same P2SH address for the same given set of keys and required signature count, making it easier to recognize transactions involving that multi-signature account. This is particularly attractive for multisignature hierarchical-deterministic wallets, as less state is required to setup multi-signature accounts: only the number of required signatures and master public keys of participants need to be shared, and all wallets will generate the same addresses.

While most web wallets do not presently facilitate the setup of multisignature accounts with users of a different service, conventions which ensure cross-compatibility should make it easier to achieve this.

Many wallet as a service providers use a 2of3 multi-signature schema where the user stores 1 of the keys (offline) as backup while using the other key for daily use and letting the service cosign his transactions. This standard will help in enabling a party other than the service provider to recover the wallet without any help from the service provider.

Specification

For a set of public keys, ensure that they have been received in compressed form:

   022df8750480ad5b26950b25c7ba79d3e37d75f640f8e5d9bcd5b150a0f85014da
   03e3818b65bcc73a7d64064106a859cc1a5a728c4345ff0b641209fba0d90de6e9
   021f2f6e1e50cb6a953935c3601284925decd3fd21bc445712576873fb8c6ebc18

Sort them lexicographically according to their binary representation:

   021f2f6e1e50cb6a953935c3601284925decd3fd21bc445712576873fb8c6ebc18
   022df8750480ad5b26950b25c7ba79d3e37d75f640f8e5d9bcd5b150a0f85014da
   03e3818b65bcc73a7d64064106a859cc1a5a728c4345ff0b641209fba0d90de6e9

..before using the resulting list of keys in a standard multisig redeem script:

   OP_2 021f2f6e1e50cb6a953935c3601284925decd3fd21bc445712576873fb8c6ebc18 022df8750480ad5b26950b25c7ba79d3e37d75f640f8e5d9bcd5b150a0f85014da 03e3818b65bcc73a7d64064106a859cc1a5a728c4345ff0b641209fba0d90de6e9 OP_3 OP_CHECKMULTISIG

Hash the redeem script according to BIP-0016 to get the P2SH address.

   3Q4sF6tv9wsdqu2NtARzNCpQgwifm2rAba

Compatibility

Test vectors

Two signatures are required in each of these test vectors.

Vector 1

Vector 2 (Already sorted, no action required)

Vector 3:

Vector 4: (from bitcore)

Acknowledgements

The authors wish to thank BtcDrak and Luke-Jr for their involvement & contributions in the early discussions of this BIP.

Usage & Implementations

References

This document is placed in the public domain.

  BIP: 69
  Layer: Applications
  Title: Lexicographical Indexing of Transaction Inputs and Outputs
  Authors: Kristov Atlas <kristov@openbitcoinprivacyproject.org>
  Editor: Daniel Cousens <bips@dcousens.com>
  Status: Complete
  Type: Informational
  Assigned: 2015-06-12
  License: PD