Skip to content

Instantly share code, notes, and snippets.

@rubensayshi
Last active May 2, 2024 04:00
Show Gist options
  • Select an option

  • Save rubensayshi/fbe39657e90ef416d411 to your computer and use it in GitHub Desktop.

Select an option

Save rubensayshi/fbe39657e90ef416d411 to your computer and use it in GitHub Desktop.
Bitcoin Script Overview

rundown of different scripts and what is what and what goes where.

  • the prevoutScript is the script of the output being spend
  • the redeemScript is the script that is used to solve the P2SH
  • the signatureScript is the script that is taken into the signatureHash for signing
  • the witnessRedeemScript is the script that is used to solve the P2WSH
  • the scriptSig is what goes into the input.scriptSig when serializing the TX
  • the witnessScript is what goes into the input.witness when serializing the TX

for a P2KH

  • prevoutScript = OP_DUP OP_HASH160 <{20byte}pubkeyHash> OP_EQUALVERIFY OP_CHECKSIG
  • signatureScript = OP_DUP OP_HASH160 <{20byte}pubkeyHash> OP_EQUALVERIFY OP_CHECKSIG
  • scriptSig = <sig> <pubkey>

for a P2SH[ 1of1 msig ]

  • prevoutScript = OP_HASH160 <{20byte}scriptHash> OP_EQUAL
  • redeemScript = OP_1 <pubkey1> <pubkey2> OP_2 OP_CHECKMULTISIG
  • signatureScript = OP_1 <pubkey1> <pubkey2> OP_2 OP_CHECKMULTISIG
  • scriptSig = <sigs> <redeemScript>

for a P2WPKH

  • prevoutScript = OP_0 PUSH[<{20byte}pubkeyHash>]
  • signatureScript = OP_DUP OP_HASH160 <{20byte}pubkeyHash> OP_EQUALVERIFY OP_CHECKSIG
  • scriptSig = ''
  • witnessScript = <sig> <pubkey>

for a P2SH[ P2WPKH ]

  • prevoutScript = OP_HASH160 <{20byte}scriptHash> OP_EQUAL
  • redeemScript = OP_0 PUSH[<{20byte}pubkeyHash>]
  • signatureScript = OP_DUP OP_HASH160 <pubkeyHash> OP_EQUALVERIFY OP_CHECKSIG
  • scriptSig = <redeemScript>
  • witnessScript = <sig> <pubkey>

for a P2WSH[ 1of1 msig ]

  • prevoutScript = OP_0 PUSH[<{32byte}pubkeyHash>]
  • redeemScript = OP_1 <pubkey1> <pubkey2> OP_2 OP_CHECKMULTISIG
  • signatureScript = OP_1 <pubkey1> <pubkey2> OP_2 OP_CHECKMULTISIG
  • scriptSig = ''
  • witnessScript = <sigs> <redeemScript>

for a P2SH[ P2WSH[ 1of1 msig ] ]

  • prevoutScript = OP_HASH160 <{20byte}scriptHash> OP_EQUAL
  • redeemScript = OP_0 PUSH[<{32byte}scriptHash>]
  • witnessRedeemScript = OP_1 <pubkey1> <pubkey2> OP_2 OP_CHECKMULTISIG
  • signatureScript = OP_1 <pubkey1> <pubkey2> OP_2 OP_CHECKMULTISIG
  • scriptSig = <redeemScript>
  • witnessScript = <sigs> <witnessRedeemScript>

for a P2SH[ P2WSH[ P2WPKH ] ]

  • prevoutScript = OP_HASH160 <{20byte}scriptHash> OP_EQUAL
  • redeemScript = OP_0 PUSH[<{32byte}scriptHash>]
  • witnessRedeemScript = OP_DUP OP_HASH160 <pubkeyHash> OP_EQUALVERIFY OP_CHECKSIG
  • signatureScript = OP_DUP OP_HASH160 <pubkeyHash> OP_EQUALVERIFY OP_CHECKSIG
  • scriptSig = <redeemScript>
  • witnessScript = <sig> <pubkey> <witnessRedeemScript>
@t4sk

t4sk commented Dec 30, 2016

Copy link
Copy Markdown

Very helpful. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment