BitCoin Notations
BitCoin Notations
Lecture 4
Dr Sadiqa Arshad
[email protected]
Bitcoin Script
Note: A hash is not ‘encryption’ – it cannot be decrypted back to the original text
Secure Hash Algorithm (SHA)
SHA-256
• SHA-256 (secure hash algorithm, FIPS 182-2) is a cryptographic hash
function with digest length of 256 bits.
The Bitcoin protocol uses SHA-256 to derive transaction IDs (txids), block hashes,
addresses, and Merkle trees. SHA-256 is applied twice, as in the case of txids.
Bitcoin Address Types
In a Pay-to-Script-Hash (P2SH) transaction, the sender, Alice includes a script hash that
refers to the actual spending conditions.
Bob, the recipient, needs to provide both the redeem script and the necessary signatures
when he wants to spend the bitcoins.
Example:
Alice wants to send 1 BTC to Bob in a way that requires:
2 signatures out of 3 possible parties (Bob, Charlie, and Dave) to spend the bitcoin.
This is known as a 2-of-3 multisig condition.
Step1:
Creating the Script:
Alice constructs a redeem script that specifies the spending condition:
• 2 out of 3 signatures are required to spend the bitcoin.
• The public keys of Bob, Charlie, and Dave are included in the script
Pay-to-Script-Hash (P2SH)
OP_2 <Bob's public key> <Charlie's public key> <Dave's public key> OP_3 OP_CHECKMULTISIG
Step2:
Hashing the Script:
•Alice hashes this redeem script using a cryptographic hash function like
SHA-256 and RIPEMD-160. The resulting hash is the script hash.
Pay-to-Script-Hash (P2SH)
Step 4
Broadcasting the Transaction:
•Alice broadcasts the transaction to the Bitcoin network, and Bob now
effectively holds 1 BTC but cannot spend it yet without the redeem script and
the necessary signatures.
Pay-to-Script-Hash (P2SH)
•Bob provides the original redeem script that specifies the 2-of-3 multisig
condition. This script needs to match the script hash in Alice's original
transaction.
Provide Signatures:
•Bob must collect at least 2 valid signatures from the participants listed in the
redeem script (e.g., himself and Charlie).
Pay-to-Script-Hash (P2SH)
Construct the Spending Transaction:
P2SH Address:
Holds the hash of the redeem script.
Redeem Script:
Specifies the actual conditions for spending, such as multisignature.
Signatures:
Needed to satisfy the conditions in the redeem script when spending the
bitcoins.
Pay-to-Public-Key (P2PK)
• Limitations:
• Lacks privacy (exposes public keys).
• Results in larger transaction sizes.
Limitations:
• Lacks the efficiency and security of newer formats (e.g., P2WPKH, P2TR).
Bitcoin Transactions
Bitcoin Change Transactions
•Inputs: These are the previous unspent transaction outputs (UTXOs) the sender is
using to fund the current transaction.
•Outputs: These include the recipient's address (the main output) and the change
address (if necessary).
NOTE: Bitcoin transactions must balance: the total value of the inputs must equal
the total value of the outputs plus the transaction fee.
Bitcoin Change Transactions
Change Addresses:
• Change addresses are new Bitcoin addresses that receive the change.
Modern wallets generate a new change address for every transaction
for privacy reasons.
• If Alice is using a Bitcoin wallet, it will usually handle the creation of
the change output and the change address automatically.
Bitcoin Change Transactions
Example:
Alice's input: 1 BTC
Amount to Bob: 0.7 BTC
Fee: 0.0001 BTC (let’s say)
Change returned to Alice: 1 BTC - 0.7 BTC - 0.0001 BTC = 0.2999 BTC
Bitcoin Change Transactions