Skip to content

Instantly share code, notes, and snippets.

@takuto-h
Last active January 5, 2019 04:14
Show Gist options
  • Save takuto-h/efa6e084c98c7c1a4c1573a151efbea6 to your computer and use it in GitHub Desktop.
Save takuto-h/efa6e084c98c7c1a4c1573a151efbea6 to your computer and use it in GitHub Desktop.
Bitcoin Cash redeem script enforcing fixed output destination powered by OP_CHECKDATASIG

Stack

<sig> <1:nVersion> <2:hashPrevouts> <3:hashSequence> <4:outpoint> <5:scriptCode> <6:value> <7:nSequence>
<8-1:outputValue> <8-2:outputScript> <8-3:changeValue> <8-4:changeScript> <9:nLockTime> <10:sighashType>

Redeem Script

DUP            : ..<10> <10>                                       :
<sighashType>  : ..<10> <10> <sighashType>                         :
EQUALVERIFY    : ..<10>                                            :
OVER           : ..<9> <10> <9>                                    :
SIZE           : ..<9> <10> <9> 4                                  :
4              : ..<9> <10> <9> 4 4                                :
NUMEQUALVERIFY : ..<9> <10> <9>                                    :
DROP           : ..<9> <10>                                        :
CAT            : ..<8-4> <9 ~ 10>                                  :
SWAP           : ..<9 ~ 10> <8-4>                                  :
TOALTSTACK     : ..<8-3> <9 ~ 10>                                  : <8-4>
SWAP           : ..<9 ~ 10> <8-3>                                  : <8-4>
SIZE           : ..<9 ~ 10> <8-3> 8                                : <8-4>
8              : ..<9 ~ 10> <8-3> 8 8                              : <8-4>
NUMEQUALVERIFY : ..<9 ~ 10> <8-3>                                  : <8-4>
TOALTSTACK     : ..<8-2> <9 ~ 10>                                  : <8-4> <8-3>
SWAP           : ..<9 ~ 10> <8-2>                                  : <8-4> <8-3>
DUP            : ..<9 ~ 10> <8-2> <8-2>                            : <8-4> <8-3>
<outputScript> : ..<9 ~ 10> <8-2> <8-2> <outputScript>             : <8-4> <8-3>
EQUALVERIFY    : ..<9 ~ 10> <8-2>                                  : <8-4> <8-3>
TOALTSTACK     : ..<8-1> <9 ~ 10>                                  : <8-4> <8-3> <8-2>
SWAP           : ..<9 ~ 10> <8-1>                                  : <8-4> <8-3> <8-2>
SIZE           : ..<9 ~ 10> <8-1> 8                                : <8-4> <8-3> <8-2>
8              : ..<9 ~ 10> <8-1> 8 8                              : <8-4> <8-3> <8-2>
NUMEQUALVERIFY : ..<9 ~ 10> <8-1>                                  : <8-4> <8-3> <8-2>
FROMALTSTACK   : ..<9 ~ 10> <8-1> <8-2>                            : <8-4> <8-3>
FROMALTSTACK   : ..<9 ~ 10> <8-1> <8-2> <8-3>                      : <8-4>
FROMALTSTACK   : ..<9 ~ 10> <8-1> <8-2> <8-3> <8-4>                :
DUP            : ..<9 ~ 10> <8-1> <8-2> <8-3> <8-4> <8-4>          :
TOALTSTACK     : ..<9 ~ 10> <8-1> <8-2> <8-3> <8-4>                : <8-4>
CAT            : ..<9 ~ 10> <8-1> <8-2> <8-3 ~ 8-4>                : <8-4>
CAT            : ..<9 ~ 10> <8-1> <8-2 ~ 8-4>                      : <8-4>
CAT            : ..<9 ~ 10> <8-1 ~ 8-4>                            : <8-4>
HASH256        : ..<9 ~ 10> <8:hashOutputs>                        : <8-4>
SWAP           : ..<8:hashOutputs> <9 ~ 10>                        : <8-4>
CAT            : ..<7> <8 ~ 10>                                    : <8-4>
OVER           : ..<7> <8 ~ 10> <7>                                : <8-4>
SIZE           : ..<7> <8 ~ 10> <7> 4                              : <8-4>
4              : ..<7> <8 ~ 10> <7> 4 4                            : <8-4>
NUMEQUALVERIFY : ..<7> <8 ~ 10> <7>                                : <8-4>
DROP           : ..<7> <8 ~ 10>                                    : <8-4>
CAT            : ..<6> <7 ~ 10>                                    : <8-4>
OVER           : ..<6> <7 ~ 10> <6>                                : <8-4>
SIZE           : ..<6> <7 ~ 10> <6> 8                              : <8-4>
8              : ..<6> <7 ~ 10> <6> 8 8                            : <8-4>
NUMEQUALVERIFY : ..<6> <7 ~ 10> <6>                                : <8-4>
DROP           : ..<6> <7 ~ 10>                                    : <8-4>
CAT            : ..<5> <6 ~ 10>                                    : <8-4>
OVER           : ..<5> <6 ~ 10> <5>                                : <8-4>
HASH160        : ..<5> <6 ~ 10> <5:scriptHash>                     : <8-4>
0x17a914       : ..<5> <6 ~ 10> <5:scriptHash> 0x17a914            : <8-4>
SWAP           : ..<5> <6 ~ 10> 0x17a914 <5:scriptHash>            : <8-4>
CAT            : ..<5> <6 ~ 10> <0x17a914 5:scriptHash>            : <8-4>
0x87           : ..<5> <6 ~ 10> <0x17a914 5:scriptHash> 0x87       : <8-4>
CAT            : ..<5> <6 ~ 10> <0x17a914 5:scriptHash 0x87>       : <8-4>
FROMALTSTACK   : ..<5> <6 ~ 10> <0x17a914 5:scriptHash 0x87> <8-4> :
EQUALVERIFY    : ..<5> <6 ~ 10>                                    :
CAT            : ..<4> <5 ~ 10>                                    :
OVER           : ..<4> <5 ~ 10> <4>                                :
SIZE           : ..<4> <5 ~ 10> <4> 36                             :
36             : ..<4> <5 ~ 10> <4> 36 36                          :
NUMEQUALVERIFY : ..<4> <5 ~ 10> <4>                                :
DROP           : ..<4> <5 ~ 10>                                    :
CAT            : ..<3> <4 ~ 10>                                    :
OVER           : ..<3> <4 ~ 10> <3>                                :
SIZE           : ..<3> <4 ~ 10> <3> 32                             :
32             : ..<3> <4 ~ 10> <3> 32 32                          :
NUMEQUALVERIFY : ..<3> <4 ~ 10> <3>                                :
DROP           : ..<3> <4 ~ 10>                                    :
CAT            : ..<2> <3 ~ 10>                                    :
OVER           : ..<2> <3 ~ 10> <2>                                :
SIZE           : ..<2> <3 ~ 10> <2> 32                             :
32             : ..<2> <3 ~ 10> <2> 32 32                          :
NUMEQUALVERIFY : ..<2> <3 ~ 10> <2>                                :
DROP           : ..<2> <3 ~ 10>                                    :
CAT            : ..<1> <2 ~ 10>                                    :
OVER           : ..<1> <2 ~ 10> <1>                                :
SIZE           : ..<1> <2 ~ 10> <1> 4                              :
4              : ..<1> <2 ~ 10> <1> 4 4                            :
NUMEQUALVERIFY : ..<1> <2 ~ 10> <1>                                :
DROP           : ..<1> <2 ~ 10>                                    :
CAT            : <sig> <1 ~ 10>                                    :
<pubkey>       : <sig> <1 ~ 10> <pubkey>                           :
3DUP           : <sig> <1 ~ 10> <pubkey> <sig> <1 ~ 10> <pubkey>   :
NIP            : <sig> <1 ~ 10> <pubkey> <sig> <pubkey>            :
CHECKSIGVERIFY : <sig> <1 ~ 10> <pubkey>                           :
CHECKDATASIG   : true                                              :

References

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