Multisignature Transactions in Bitcoin: An Overview

Multisignature Transactions in Bitcoin: An Overview

Table of contents

No heading

No headings in the article.

Bitcoin no doubt has been praised for its security and transparency. However, like any other financial tool, it can be vulnerable to theft or loss. To address this, Bitcoin introduced a new feature known as multisignature transactions (multisig). Multisig is a method of requiring more than one signature to authorize a transaction on a Bitcoin address, making it a more secure way to hold and spend funds.

A multisig address is created by combining the public keys of multiple users. The number of public keys required to authorize a transaction can be customized, allowing for a flexible balance between security and accessibility. For example, if a user wants to add an extra layer of security to their funds, they can create a 2-of-3 multisig address, which requires two out of three signatures to authorize a transaction. There is a convention in the wider cyptography community that "multisignature" refers to only m-of-m, and the term "threshold multisignature" refers to n-of-m schemes. In bitcoin we call both "multisig".

Multisignature (multisig) was first introduced in Bitcoin through BIP 11 (OP_CHECKMULTISIGVERIFY) in 2012. This BIP(Pay-to-Multisig (P2MS)) proposed a new opcode, OP_CHECKMULTISIGVERIFY, to allow for the efficient implementation of multi-signature transactions. Later, BIP 16 (Pay-to-Script-Hash (P2SH)) specified a standard for using multisig addresses in a more user-friendly and backwards-compatible way. In November 2015, BIP 141 was introduced to improve the efficiency, privacy, and security of transactions in the Bitcoin network. This proposal introduced the concept of a SegWit (Segregated Witness) transaction, which separates the witness data from the transaction data in a block. This allows for more efficient transactions, increased block space, and the ability to use complex transaction types like P2WSH.
Let's take a look at these multisig addresses along with the example code of their corresponding scripts.

P2MS
The Pay-to-Multisig (P2MS) script is a type of script used in the Bitcoin network to define the conditions under which a multisignature (Multisig) transaction can be processed. The P2MS script is typically composed of two parts: the redeem script and the scriptPubKey.

The redeem script is the script that is used to define the conditions for spending the funds in the Multisig transaction. It specifies the number of signatures required from a specified set of public keys, and the order in which the signatures must be provided.

The scriptPubKey is the script that is included in the output of the transaction and specifies how the funds can be spent. It includes a hash of the redeem script, which is used to identify the conditions for spending the funds in the Multisig transaction.
another thing that is worth mentioning is P2MS had a limit of 3 keys because anything more was too much data.

Redeem Script:

OP_2 [Public Key 1] [Public Key 2] [Public Key 3] OP_3 OP_CHECKMULTISIG

ScriptPubKey:

OP_HASH160 [Hash of Redeem Script] OP_EQUAL

P2SH
users to send funds to a hash of a script, rather than to a public key hash. This allows for the creation of complex transactions, including Multisignature (Multisig) transactions, without the need for a long, complicated script to be included in each transaction.

In a P2SH transaction, the recipient provides a script that defines the conditions under which the funds can be spent. The sender then sends the funds to a hash of the script, rather than to a public key hash. This hash is included in the output of the transaction and is used to identify the conditions for spending the funds.

The key advantage of P2SH transactions is that they enable users to send funds to complex scripts without the need for the full script to be included in each transaction. This makes transactions smaller, faster, and more efficient, and also provides greater privacy, as the full script is not visible on the blockchain.

Script:
OP_2 [Public Key 1] [Public Key 2] [Public Key 3] OP_3 OP_CHECKMULTISIG

ScriptPubKey:
OP_HASH160 [Hash of Script] OP_EQUAL

The script specifies the conditions for spending the funds in the Multisig transaction. The scriptPubKey includes a hash of the script ([Hash of Script]) and requires that the hash is equal to the actual script (OP_EQUAL) for the transaction to be processed.

P2WSH
In a P2WSH transaction, the recipient provides a witness script that defines the conditions under which the funds can be spent. The sender then sends the funds to a hash of the witness script, rather than to a public key hash. This hash is included in the output of the transaction and is used to identify the conditions for spending the funds. An advantage of P2WSH transactions is that they enable users to send funds to complex scripts without the need for the full script to be included in each transaction. This makes transactions smaller, faster, and more efficient, and also provides greater privacy, as the full script is not visible on the blockchain.

Witness Script:
OP_2 [Public Key 1] [Public Key 2] [Public Key 3] OP_3 OP_CHECKMULTISIG

ScriptPubKey:
OP_0 [Hash of Witness Script]
The witness script specifies the conditions for spending the funds in the Multisig transaction and the scriptPubKey includes a hash of the witness script ([Hash of Witness Script].

P2TR

Pay-to-Taproot (P2TR) is an upgrade to the Bitcoin scripting language that aims to improve privacy and scalability on the network. It was introduced in BIP 341, is built on top of Taproot, and has a done lot to make multisig more private, cheaper, and easier. P2TR allows for the creation of more efficient and private multisignature (Multisig) transactions. It does this by using Taproot to enable the use of a single public key to represent multiple signers. This makes it possible to create Multisig transactions that look like normal transactions on the blockchain, improving privacy by hiding the fact that multiple signatures are required.

The basics of Multisig transactions

In a Multisig transaction, a set of public keys is used to create a script that will only be valid if a specific number of the corresponding private keys sign the transaction. This number is called the "M-of-N" threshold, where M is the number of signatures required and N is the total number of public keys in the set.

For example, in a 2-of-3 Multisig transaction, three public keys are used to create a script that will only be valid if two of the corresponding private keys sign the transaction. This allows for increased security as funds can only be spent if a majority of the private keys agree to the transaction.

How Multisig transactions work

Multisig transactions work by creating a script that defines the conditions for the transaction to be validated. This script is called a redeem script, and it is a combination of OP codes and data that specify the rules for the transaction. The redeem script is then hashed, and the hash is used as the address for the Multisig transaction. This address is known as a Pay-to-Script-Hash (P2SH) address.

When a Multisig transaction is created, the inputs for the transaction reference the P2SH address, rather than the individual public keys. This allows the transaction to remain confidential, as the public keys are not revealed in the transaction.

The signature process

When a Multisig transaction is broadcast to the network, the signature process begins. The signers must use their private keys to sign the transaction, and the signatures are then added to the transaction as input scripts.

Once the required number of signatures has been collected, the transaction is considered valid, and the redeem script is executed. The redeem script checks the signatures against the public keys, and if the required number of signatures is valid, the transaction is considered confirmed and the funds are transferred.

Multisig addresses in Bitcoin use a specific type of script, known as a "pay-to-witness-script-hash" (P2WSH) script, to enforce the requirement of multiple signatures to authorize a transaction. This script specifies the number of signatures required and the public keys involved in the multisig address.

For example:

OP_0 <20-byte hash of public key 1> <20-byte hash of public key 2> ... <20-byte hash of public key n> OP_m OP_CHECKMULTISIG

In this example, OP_0 represents a version byte, which is used to indicate the type of script being executed. The 20-byte hashes of the public keys involved in the multisig address are then provided as input to the script. The OP_m instruction indicates the number of signatures required, and the OP_CHECKMULTISIG instruction checks that the correct number of signatures has been provided.

It's important to note that P2WSH scripts are a more recent development in Bitcoin, and older multisig addresses may use a different type of script. However, P2WSH scripts are becoming more widely used due to their improved efficiency and compatibility with the SegWit update to the Bitcoin network.

Generating a multisig address
To generate a multisig address in Bitcoin, you will need to follow these steps:

Gather public keys: The first step is to gather the public keys from all parties who will be involved in the multisig address. It is important to ensure that each party generates a new, unique public key for this purpose.

Determine the number of signatures required: Next, you will need to determine the number of signatures required to authorize a transaction. This is known as the "m-of-n" configuration, where "m" is the number of signatures required and "n" is the total number of public keys involved. For example, a 2-of-3 configuration would require two signatures out of three possible signers.

Generate the multisig address: With the public keys and signature requirements in place, you can use a Bitcoin wallet or other cryptocurrency software that supports multisig addresses to generate the multisig address. This will typically involve providing the public keys and signature requirements as input to the wallet.
To generate a multisig address in Bitcoin, you will need to write a script using the Bitcoin Script programming language. Here's an example of what that script might look like:

OP_2 <public key 1> <public key 2> <public key 3> OP_3 OP_CHECKMULTISIG

In this example, the script requires 2 out of 3 possible signatures to authorize a transaction. The OP_2 instruction indicates the number of signatures required, and the OP_3 instruction indicates the number of public keys involved. The public keys are then provided as input to the script, followed by the OP_CHECKMULTISIG instruction, which checks that the correct number of signatures has been provided.

Once the script has been written, it can be hashed to create a multisig address, which can then be used to receive payments just like a regular Bitcoin address. To spend funds from a multisig address, you will need to create a transaction that includes the script and the necessary signatures and broadcast it to the network.

Fund the multisig address: Once the multisig address has been generated, you can fund it just like you would a regular Bitcoin address. This can be done by sending Bitcoin to the multisig address from a regular wallet.

Sign transactions: To spend funds from a multisig address, you will need to create a transaction and sign it using the private keys associated with the public keys involved in the multisig address. The number of signatures required will depend on the "m-of-n" configuration, and once the required signatures have been collected, the transaction can be broadcast to the network.

Advantages of multisig addresses

Increased security: One of the key benefits of multisig is that it adds an extra layer of security to a user's funds. In traditional Bitcoin transactions, a single private key is used to authorize a transaction. However, if a private key is lost or stolen, the funds can be compromised. With multisig, multiple private keys are required to authorize a transaction, reducing the risk of theft or loss. This can be particularly important in situations where large amounts are involved, or where the funds are being held by multiple parties with conflicting interests.

Decentralization: Multisig transactions allow for a decentralized way of managing funds, as no single party holds complete control over the funds.

Flexibility: Multisig transactions can be used for a variety of use cases, including escrow services, joint accounts, and multisig wallets.

Safety of funds: A benefit of utilizing multisignature technology is that by storing different keys on separate devices, all the keys required to sign a transaction are never all in one place. This increases your resilience against malware on one or more devices and provides multiple opportunities to confirm the transaction output addresses and amounts.

Backup plan: Another advantage of multisig addresses is that they can be used as a backup mechanism in case of lost or stolen private keys. By requiring multiple signatures, it becomes possible to recover access to the funds even if one of the private keys is lost or stolen. This can provide added peace of mind for individuals and organizations holding large amounts of funds.

Multisig addresses can also be used to provide an added layer of control in situations where multiple parties need to agree on a transaction. For example, a company might use a 2-of-3 multisig address to ensure that transactions can only be executed if two out of three executives agree on the action. This can provide a level of accountability and prevent unauthorized transactions from occurring.

In conclusion, multisignature addresses in Bitcoin provide a way to increase security and control for transactions. By requiring multiple signatures to authorize a transaction, multisig addresses can help prevent the theft of funds, provide a backup mechanism in case of lost or stolen private keys, and allow multiple parties to control access to a shared wallet. The use of multisig addresses is becoming increasingly common and is a valuable tool for individuals and organizations looking to secure their funds.