Skip to content

Instantly share code, notes, and snippets.

@RobinLinus
Last active October 16, 2023 00:12
Show Gist options
  • Save RobinLinus/0e7ab6fbd84d0115d2367db1711fc8ca to your computer and use it in GitHub Desktop.
Save RobinLinus/0e7ab6fbd84d0115d2367db1711fc8ca to your computer and use it in GitHub Desktop.

31-bit Commitment

This is a 31-bit commitment in Bitcoin Script.

OP_DUP
OP_TOALTSTACK

OP_DUP
<1073741824>
OP_GREATERTHANOREQUAL
OP_IF
    <1073741824>
    OP_SUB
    OP_SWAP
    OP_HASH256
OP_ELSE
    OP_SWAP
OP_ENDIF
OP_HASH160
OP_SWAP

OP_DUP
<536870912>
OP_GREATERTHANOREQUAL
OP_IF
    <536870912>
    OP_SUB
    OP_SWAP
    OP_HASH256
OP_ELSE
    OP_SWAP
OP_ENDIF
OP_HASH160
OP_SWAP

OP_DUP
<268435456>
OP_GREATERTHANOREQUAL
OP_IF
    <268435456>
    OP_SUB
    OP_SWAP
    OP_HASH256
OP_ELSE
    OP_SWAP
OP_ENDIF
OP_HASH160
OP_SWAP

OP_DUP
<134217728>
OP_GREATERTHANOREQUAL
OP_IF
    <134217728>
    OP_SUB
    OP_SWAP
    OP_HASH256
OP_ELSE
    OP_SWAP
OP_ENDIF
OP_HASH160
OP_SWAP

OP_DUP
<67108864>
OP_GREATERTHANOREQUAL
OP_IF
    <67108864>
    OP_SUB
    OP_SWAP
    OP_HASH256
OP_ELSE
    OP_SWAP
OP_ENDIF
OP_HASH160
OP_SWAP

OP_DUP
<33554432>
OP_GREATERTHANOREQUAL
OP_IF
    <33554432>
    OP_SUB
    OP_SWAP
    OP_HASH256
OP_ELSE
    OP_SWAP
OP_ENDIF
OP_HASH160
OP_SWAP

OP_DUP
<16777216>
OP_GREATERTHANOREQUAL
OP_IF
    <16777216>
    OP_SUB
    OP_SWAP
    OP_HASH256
OP_ELSE
    OP_SWAP
OP_ENDIF
OP_HASH160
OP_SWAP

OP_DUP
<8388608>
OP_GREATERTHANOREQUAL
OP_IF
    <8388608>
    OP_SUB
    OP_SWAP
    OP_HASH256
OP_ELSE
    OP_SWAP
OP_ENDIF
OP_HASH160
OP_SWAP

OP_DUP
<4194304>
OP_GREATERTHANOREQUAL
OP_IF
    <4194304>
    OP_SUB
    OP_SWAP
    OP_HASH256
OP_ELSE
    OP_SWAP
OP_ENDIF
OP_HASH160
OP_SWAP

OP_DUP
<2097152>
OP_GREATERTHANOREQUAL
OP_IF
    <2097152>
    OP_SUB
    OP_SWAP
    OP_HASH256
OP_ELSE
    OP_SWAP
OP_ENDIF
OP_HASH160
OP_SWAP

OP_DUP
<1048576>
OP_GREATERTHANOREQUAL
OP_IF
    <1048576>
    OP_SUB
    OP_SWAP
    OP_HASH256
OP_ELSE
    OP_SWAP
OP_ENDIF
OP_HASH160
OP_SWAP

OP_DUP
<524288>
OP_GREATERTHANOREQUAL
OP_IF
    <524288>
    OP_SUB
    OP_SWAP
    OP_HASH256
OP_ELSE
    OP_SWAP
OP_ENDIF
OP_HASH160
OP_SWAP

OP_DUP
<262144>
OP_GREATERTHANOREQUAL
OP_IF
    <262144>
    OP_SUB
    OP_SWAP
    OP_HASH256
OP_ELSE
    OP_SWAP
OP_ENDIF
OP_HASH160
OP_SWAP

OP_DUP
<131072>
OP_GREATERTHANOREQUAL
OP_IF
    <131072>
    OP_SUB
    OP_SWAP
    OP_HASH256
OP_ELSE
    OP_SWAP
OP_ENDIF
OP_HASH160
OP_SWAP

OP_DUP
<65536>
OP_GREATERTHANOREQUAL
OP_IF
    <65536>
    OP_SUB
    OP_SWAP
    OP_HASH256
OP_ELSE
    OP_SWAP
OP_ENDIF
OP_HASH160
OP_SWAP

OP_DUP
<32768>
OP_GREATERTHANOREQUAL
OP_IF
    <32768>
    OP_SUB
    OP_SWAP
    OP_HASH256
OP_ELSE
    OP_SWAP
OP_ENDIF
OP_HASH160
OP_SWAP

OP_DUP
<16384>
OP_GREATERTHANOREQUAL
OP_IF
    <16384>
    OP_SUB
    OP_SWAP
    OP_HASH256
OP_ELSE
    OP_SWAP
OP_ENDIF
OP_HASH160
OP_SWAP

OP_DUP
<8192>
OP_GREATERTHANOREQUAL
OP_IF
    <8192>
    OP_SUB
    OP_SWAP
    OP_HASH256
OP_ELSE
    OP_SWAP
OP_ENDIF
OP_HASH160
OP_SWAP

OP_DUP
<4096>
OP_GREATERTHANOREQUAL
OP_IF
    <4096>
    OP_SUB
    OP_SWAP
    OP_HASH256
OP_ELSE
    OP_SWAP
OP_ENDIF
OP_HASH160
OP_SWAP

OP_DUP
<2048>
OP_GREATERTHANOREQUAL
OP_IF
    <2048>
    OP_SUB
    OP_SWAP
    OP_HASH256
OP_ELSE
    OP_SWAP
OP_ENDIF
OP_HASH160
OP_SWAP

OP_DUP
<1024>
OP_GREATERTHANOREQUAL
OP_IF
    <1024>
    OP_SUB
    OP_SWAP
    OP_HASH256
OP_ELSE
    OP_SWAP
OP_ENDIF
OP_HASH160
OP_SWAP

OP_DUP
<512>
OP_GREATERTHANOREQUAL
OP_IF
    <512>
    OP_SUB
    OP_SWAP
    OP_HASH256
OP_ELSE
    OP_SWAP
OP_ENDIF
OP_HASH160
OP_SWAP

OP_DUP
<256>
OP_GREATERTHANOREQUAL
OP_IF
    <256>
    OP_SUB
    OP_SWAP
    OP_HASH256
OP_ELSE
    OP_SWAP
OP_ENDIF
OP_HASH160
OP_SWAP

OP_DUP
<128>
OP_GREATERTHANOREQUAL
OP_IF
    <128>
    OP_SUB
    OP_SWAP
    OP_HASH256
OP_ELSE
    OP_SWAP
OP_ENDIF
OP_HASH160
OP_SWAP

OP_DUP
<64>
OP_GREATERTHANOREQUAL
OP_IF
    <64>
    OP_SUB
    OP_SWAP
    OP_HASH256
OP_ELSE
    OP_SWAP
OP_ENDIF
OP_HASH160
OP_SWAP

OP_DUP
<32>
OP_GREATERTHANOREQUAL
OP_IF
    <32>
    OP_SUB
    OP_SWAP
    OP_HASH256
OP_ELSE
    OP_SWAP
OP_ENDIF
OP_HASH160
OP_SWAP

OP_DUP
<16>
OP_GREATERTHANOREQUAL
OP_IF
    <16>
    OP_SUB
    OP_SWAP
    OP_HASH256
OP_ELSE
    OP_SWAP
OP_ENDIF
OP_HASH160
OP_SWAP

OP_DUP
<8>
OP_GREATERTHANOREQUAL
OP_IF
    <8>
    OP_SUB
    OP_SWAP
    OP_HASH256
OP_ELSE
    OP_SWAP
OP_ENDIF
OP_HASH160
OP_SWAP

OP_DUP
<4>
OP_GREATERTHANOREQUAL
OP_IF
    <4>
    OP_SUB
    OP_SWAP
    OP_HASH256
OP_ELSE
    OP_SWAP
OP_ENDIF
OP_HASH160
OP_SWAP

OP_DUP
<2>
OP_GREATERTHANOREQUAL
OP_IF
    <2>
    OP_SUB
    OP_SWAP
    OP_HASH256
OP_ELSE
    OP_SWAP
OP_ENDIF
OP_HASH160
OP_SWAP

OP_DUP
<1>
OP_GREATERTHANOREQUAL
OP_IF
    <1>
    OP_SUB
    OP_SWAP
    OP_HASH256
OP_ELSE
    OP_SWAP
OP_ENDIF
OP_HASH160
OP_SWAP
OP_DROP

<0x8a649c0178523b6dd9de2a15c086067434ee2128>
OP_EQUALVERIFY

OP_FROMALTSTACK

Unlocking Script

<'preimage'>
<1234567890>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment