https://en.bitcoin.it/w/api.php?action=feedcontributions&user=Smtp&feedformat=atom
Bitcoin Wiki - User contributions [en]
2024-03-19T05:45:21Z
User contributions
MediaWiki 1.30.0
https://en.bitcoin.it/w/index.php?title=Running_Bitcoin&diff=35122
Running Bitcoin
2013-01-16T15:18:37Z
<p>Smtp: /* Command-line arguments */</p>
<hr />
<div>There are two variations of the original bitcoin program available; one with a graphical user interface (usually referred to as just “Bitcoin”), and a 'headless' version (called [[bitcoind]]). They are completely compatible with each other, and take the same command-line arguments, read the same configuration file, and read and write the same data files. You can run one copy of either Bitcoin or bitcoind on your system at a time (if you accidently try to launch another, the copy will let you know that Bitcoin or bitcoind is already running and will exit).<br />
<br />
__TOC__<br />
<br />
==Linux Quickstart==<br />
<br />
The simplest way to start from scratch with the command line client, automatically syncing blockchain and creating a wallet, is to just run this command (without arguments) from the directory containing your bitcoind binary:<br />
<br />
./bitcoind<br />
<br />
To run with the standard GUI interface:<br />
<br />
./bitcoin-qt<br />
<br />
==Command-line arguments==<br />
<br />
Give Bitcoin (or bitcoind) the -? or –-help argument and it will print out a list of the most commonly used command-line arguments and then exit:<br />
<br />
Usage:<br />
bitcoind [options] <br />
bitcoind [options] <command> [params] Send command to -server or bitcoind<br />
bitcoind [options] help List commands<br />
bitcoind [options] help <command> Get help for a command<br />
Options:<br />
-conf=<file> Specify configuration file (default: bitcoin.conf)<br />
-pid=<file> Specify pid file (default: bitcoind.pid)<br />
-gen Generate coins<br />
-gen=0 Don't generate coins<br />
-datadir=<dir> Specify data directory<br />
-dbcache=<n> Set database cache size in megabytes (default: 25)<br />
-dblogsize=<n> Set database disk log size in megabytes (default: 100)<br />
-timeout=<n> Specify connection timeout in milliseconds (default: 5000)<br />
-proxy=<ip:port> Connect through socks proxy<br />
-socks=<n> Select the version of socks proxy to use (4-5, default: 5)<br />
-tor=<ip:port> Use proxy to reach tor hidden services (default: same as -proxy)<br />
-dns Allow DNS lookups for -addnode, -seednode and -connect<br />
-port=<port> Listen for connections on <port> (default: 8333 or testnet: 18333)<br />
-maxconnections=<n> Maintain at most <n> connections to peers (default: 125)<br />
-addnode=<ip> Add a node to connect to and attempt to keep the connection open<br />
-connect=<ip> Connect only to the specified node(s)<br />
-seednode=<ip> Connect to a node to retrieve peer addresses, and disconnect<br />
-externalip=<ip> Specify your own public address<br />
-onlynet=<net> Only connect to nodes in network <net> (IPv4, IPv6 or Tor)<br />
-discover Discover own IP address (default: 1 when listening and no -externalip)<br />
-irc Find peers using internet relay chat (default: 0)<br />
-listen Accept connections from outside (default: 1 if no -proxy or -connect)<br />
-bind=<addr> Bind to given address. Use [host]:port notation for IPv6<br />
-dnsseed Find peers using DNS lookup (default: 1 unless -connect)<br />
-banscore=<n> Threshold for disconnecting misbehaving peers (default: 100)<br />
-bantime=<n> Number of seconds to keep misbehaving peers from reconnecting (default: 86400)<br />
-maxreceivebuffer=<n> Maximum per-connection receive buffer, <n>*1000 bytes (default: 5000)<br />
-maxsendbuffer=<n> Maximum per-connection send buffer, <n>*1000 bytes (default: 1000)<br />
-upnp Use UPnP to map the listening port (default: 1 when listening)<br />
-detachdb Detach block and address databases. Increases shutdown time (default: 0)<br />
-paytxfee=<amt> Fee per KB to add to transactions you send<br />
-server Accept command line and JSON-RPC commands<br />
-testnet Use the test network<br />
-debug Output extra debugging information. Implies all other -debug* options<br />
-debugnet Output extra network debugging information<br />
-logtimestamps Prepend debug output with timestamp<br />
-shrinkdebugfile Shrink debug.log file on client startup (default: 1 when no -debug)<br />
-printtoconsole Send trace/debug info to console instead of debug.log file<br />
-rpcuser=<user> Username for JSON-RPC connections<br />
-rpcpassword=<pw> Password for JSON-RPC connections<br />
-rpcport=<port> Listen for JSON-RPC connections on <port> (default: 8332)<br />
-rpcallowip=<ip> Allow JSON-RPC connections from specified IP address<br />
-rpcconnect=<ip> Send commands to node running on <ip> (default: 127.0.0.1)<br />
-blocknotify=<cmd> Execute command when the best block changes (%s in cmd is replaced by block hash)<br />
-upgradewallet Upgrade wallet to latest format<br />
-keypool=<n> Set key pool size to <n> (default: 100)<br />
-rescan Rescan the block chain for missing wallet transactions<br />
-checkblocks=<n> How many blocks to check at startup (default: 2500, 0 = all)<br />
-checklevel=<n> How thorough the block verification is (0-6, default: 1) [https://github.com/bitcoin/bitcoin/pull/972 checklevel interpretation]<br />
-loadblock=<file> Imports blocks from external blk000?.dat file<br />
<br />
Block creation options:<br />
-blockminsize=<n> Set minimum block size in bytes (default: 0)<br />
-blockmaxsize=<n> Set maximum block size in bytes (default: 250000)<br />
-blockprioritysize=<n> Set maximum size of high-priority/low-fee transactions in bytes (default: 27000)<br />
<br />
SSL options: (see the [[Enabling SSL on original client daemon|Bitcoin Wiki for SSL setup instructions]])<br />
-rpcssl Use OpenSSL (https) for JSON-RPC connections<br />
-rpcsslcertificatechainfile=<file.cert> Server certificate file (default: server.cert)<br />
-rpcsslprivatekeyfile=<file.pem> Server private key (default: server.pem)<br />
-rpcsslciphers=<ciphers> Acceptable ciphers (default: TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!AH:!3DES:@STRENGTH)<br />
<br />
Additional (Supported but not listed in -? help):<br />
-min Start minimized<br />
-checkblocks Rescan the whole blockchain (can take very much time)<br />
-nolisten Don't accept connections from outside [Deprecated]<br />
-noupnp Don't attempt to use UPnP to map the listening port [Deprecated]<br />
-nodnsseed Don't bootstrap list of peers using DNS [Deprecated]<br />
-noirc [Deprecated]<br />
-daemon Run in the background as a daemon and accept commands [Deprecated]<br />
<br />
==Bitcoin.conf Configuration File==<br />
All command-line options (except for -datadir and -conf) may be specified in a configuration file, and all configuration file options may also be specified on the command line. Command-line options override values set in the configuration file.<br />
<br />
The configuration file is a list of setting=value pairs, one per line, with optional comments starting with the '#' character.<br />
<br />
The configuration file is not automatically created; you can create it using your favorite plain-text editor. By default, Bitcoin (or bitcoind) will look for a file named 'bitcoin.conf' in the bitcoin [[data directory]], but both the data directory and the configuration file path may be changed using the -datadir and -conf command-line arguments.<br />
{|<br />
! Operating System<br />
! Default bitcoin datadir<br />
! Typical path to configuration file<br />
|-<br />
| Windows<br />
| %APPDATA%\Bitcoin\<br />
| (XP) C:\Documents and Settings\username\Application Data\Bitcoin\bitcoin.conf<br />
(Vista, 7) C:\Users\username\AppData\Roaming\Bitcoin\bitcoin.conf<br />
|-<br />
| Linux<br />
| $HOME/.bitcoin/<br />
| /home/username/.bitcoin/bitcoin.conf<br />
|-<br />
| Mac OSX<br />
| $HOME/Library/Application Support/Bitcoin/<br />
| /Users/username/Library/Application Support/Bitcoin/bitcoin.conf<br />
|}<br />
<br />
Note: if running Bitcoin in testnet mode, the sub-folder "testnet" will be appended to the data directory automatically.<br />
<br />
==Sample Bitcoin.conf==<br />
Here is a sample bitcoin.conf file.<br />
<br />
# bitcoin.conf configuration file. Lines beginning with # are comments.<br />
<br />
<br />
# Network-related settings:<br />
<br />
# Run on the test network instead of the real bitcoin network.<br />
#testnet=0<br />
<br />
# Connect via a socks4 proxy<br />
#proxy=127.0.0.1:9050<br />
<br />
##############################################################<br />
## Quick Primer on addnode vs connect ##<br />
## Let's say for instance you use addnode=4.2.2.4 ##<br />
## addnode will connect you to and tell you about the ##<br />
## nodes connected to 4.2.2.4. In addition it will tell ##<br />
## the other nodes connected to it that you exist so ##<br />
## they can connect to you. ##<br />
## connect will not do the above when you 'connect' to it. ##<br />
## It will *only* connect you to 4.2.2.4 and no one else.##<br />
## ##<br />
## So if you're behind a firewall, or have other problems ##<br />
## finding nodes, add some using 'addnode'. ##<br />
## ##<br />
## If you want to stay private, use 'connect' to only ##<br />
## connect to "trusted" nodes. ##<br />
## ##<br />
## If you run multiple nodes on a LAN, there's no need for ##<br />
## all of them to open lots of connections. Instead ##<br />
## 'connect' them all to one node that is port forwarded ##<br />
## and has lots of connections. ##<br />
## Thanks goes to [Noodle] on Freenode. ##<br />
##############################################################<br />
<br />
# Use as many addnode= settings as you like to connect to specific peers<br />
#addnode=69.164.218.197<br />
#addnode=10.0.0.2:8333<br />
<br />
# ... or use as many connect= settings as you like to connect ONLY<br />
# to specific peers:<br />
#connect=69.164.218.197<br />
#connect=10.0.0.1:8333<br />
<br />
# Do not use Internet Relay Chat (irc.lfnet.org #bitcoin channel) to<br />
# find other peers.<br />
#noirc=0<br />
<br />
# Maximum number of inbound+outbound connections.<br />
#maxconnections=<br />
<br />
<br />
# JSON-RPC options (for controlling a running Bitcoin/bitcoind process)<br />
<br />
# server=1 tells Bitcoin-QT to accept JSON-RPC commands.<br />
#server=0<br />
<br />
# You must set rpcuser and rpcpassword to secure the JSON-RPC api<br />
#rpcuser=Ulysseys<br />
#rpcpassword=YourSuperGreatPasswordNumber_DO_NOT_USE_THIS_OR_YOU_WILL_GET_ROBBED_385593<br />
<br />
# How many seconds bitcoin will wait for a complete RPC HTTP request.<br />
# after the HTTP connection is established. <br />
#rpctimeout=30<br />
<br />
# By default, only RPC connections from localhost are allowed. Specify<br />
# as many rpcallowip= settings as you like to allow connections from<br />
# other hosts (and you may use * as a wildcard character):<br />
#rpcallowip=10.1.1.34<br />
#rpcallowip=192.168.1.*<br />
<br />
# Listen for RPC connections on this TCP port:<br />
#rpcport=8332<br />
<br />
# You can use Bitcoin or bitcoind to send commands to Bitcoin/bitcoind<br />
# running on another host using this option:<br />
#rpcconnect=127.0.0.1<br />
<br />
# Use Secure Sockets Layer (also known as TLS or HTTPS) to communicate<br />
# with Bitcoin -server or bitcoind<br />
#rpcssl=1<br />
<br />
# OpenSSL settings used when rpcssl=1<br />
#rpcsslciphers=TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!AH:!3DES:@STRENGTH<br />
#rpcsslcertificatechainfile=server.cert<br />
#rpcsslprivatekeyfile=server.pem<br />
<br />
<br />
# Miscellaneous options<br />
<br />
# Set gen=1 to attempt to generate bitcoins<br />
#gen=0<br />
<br />
# Use SSE instructions to try to generate bitcoins faster.<br />
#4way=1<br />
<br />
# Pre-generate this many public/private key pairs, so wallet backups will be valid for<br />
# both prior transactions and several dozen future transactions.<br />
#keypool=100<br />
<br />
# Pay an optional transaction fee every time you send bitcoins. Transactions with fees<br />
# are more likely than free transactions to be included in generated blocks, so may<br />
# be validated sooner.<br />
#paytxfee=0.00<br />
<br />
# Allow direct connections for the 'pay via IP address' feature.<br />
#allowreceivebyip=1<br />
<br />
# User interface options<br />
<br />
# Start Bitcoin minimized<br />
#min=1<br />
<br />
# Minimize to the system tray<br />
#minimizetotray=1<br />
<br />
==Platforms==<br />
===Windows===<br />
<br />
====Start automatically====<br />
To configure the Bitcoin client to start automatically:<br />
<br />
You might use the configuration-file, or the GUI-Settings:<br />
<br />
Settings -> Options<br />
<br />
then mark the checkbox titled:<br />
[X] Start Bitcoin on system startup<br />
<br />
[[{{ns:file}}:Client_Settings_Options_windows.png]]<br />
<br />
====Batch automation====<br />
To work with batch, you have to start the daemon (bitcoind.exe). The bitcoin.exe run with option "-server" will respond with GUI-messages you are not able to process its answers.<br />
<br />
===Mac===<br />
[[{{ns:file}}:MacBitcoinStartOnLogin.png]]<br />
<br />
===Linux===<br />
[[{{ns:file}}:Client_Settings_Options.png]]<br />
<br />
[[es:Ejecución de Bitcoin]]<br />
<br />
[[Category:Technical]]<br />
[[Category:Developer]]</div>
Smtp
https://en.bitcoin.it/w/index.php?title=Block_hashing_algorithm&diff=35121
Block hashing algorithm
2013-01-16T15:14:11Z
<p>Smtp: </p>
<hr />
<div>When generating, you constantly hash the block header. The block is also occasionally updated as you are working on it. A block header contains these fields:<br />
{| class="wikitable"<br />
|-<br />
! Field<br />
! Purpose<br />
! Updated when...<br />
! Size (Bytes)<br />
|-<br />
|Version<br />
|Block version number<br />
|You upgrade the software and it specifies a new version<br />
|4<br />
|-<br />
|hashPrevBlock<br />
|256-bit hash of the previous block header<br />
|A new block comes in<br />
|32<br />
|-<br />
|hashMerkleRoot<br />
|256-bit hash based on all of the transactions in the block<br />
|A transaction is accepted<br />
|32<br />
|-<br />
|Time<br />
|Current timestamp as seconds since 1970-01-01T00:00 UTC<br />
|Every few seconds<br />
|4<br />
|-<br />
|Bits<br />
|Current [[target]] in compact format<br />
|The [[difficulty]] is adjusted<br />
|4<br />
|-<br />
|Nonce<br />
|32-bit number (starts at 0)<br />
|A hash is tried (increments)<br />
|4<br />
|}<br />
<br />
The body of the block contains the transactions. These are hashed only indirectly through the Merkle root. Because transactions aren't hashed directly, hashing a block with 1 transaction takes exactly the same amount of effort as hashing a block with 10,000 transactions.<br />
<br />
The compact format of target is a special kind of floating-point encoding using 3 bytes mantissa, the leading byte as exponent (where only the 5 lowest bits are used) and its base is 256.<br />
Most of these fields will be the same for all users. There might be some minor variation in the timestamps. The nonce will usually be different, but it increases in a strictly linear way. "Nonce" starts at 0 and is incremented for each hash. Whenever Nonce overflows (which it does frequently), the extraNonce portion of the generation transaction is incremented, which changes the Merkle root.<br />
<br />
Given just those fields, people would frequently generate the exact same sequence of hashes as each other and the fastest CPU would almost always win. However, it is (nearly) impossible for two people to have the same Merkle root because the first transaction in your block is a generation "sent" to one of ''your'' unique Bitcoin addresses. Since your block is different from everyone else's blocks, you are (nearly) guaranteed to produce different hashes. Every hash you calculate has the same chance of winning as every other hash calculated by the network.<br />
<br />
Bitcoin uses: SHA256(SHA256(Block_Header)) but you have to be careful about byte-order.<br />
<br />
For example, this python code will calculate the hash of the block with the smallest hash as of June 2011, [http://blockexplorer.com/block/00000000000000001e8d6829a8a21adc5d38d0a473b144b6765798e61f98bd1d Block 125552]. The header is built from the six fields described above, concatenated together as little-endian values in hex notation:<br />
<br />
>>> import hashlib<br />
>>> header_hex = ("01000000" +<br />
"81cd02ab7e569e8bcd9317e2fe99f2de44d49ab2b8851ba4a308000000000000" +<br />
"e320b6c2fffc8d750423db8b1eb942ae710e951ed797f7affc8892b0f1fc122b" +<br />
"c7f5d74d" +<br />
"f2b9441a" +<br />
"42a14695")<br />
>>> header_bin = header_hex.decode('hex')<br />
>>> hash = hashlib.sha256(hashlib.sha256(header_bin).digest()).digest()<br />
>>> hash.encode('hex_codec')<br />
'1dbd981fe6985776b644b173a4d0385ddc1aa2a829688d1e0000000000000000'<br />
>>> hash[::-1].encode('hex_codec')<br />
'00000000000000001e8d6829a8a21adc5d38d0a473b144b6765798e61f98bd1d'<br />
<br />
Note that the actual hash, which is a 256-bit number, has lots of leading zero bits. When stored or printed as a big-endian hexadecimal constant, but it has leading zero bytes and if stored or printed as little-endian, these are the trailing zero bytes. E.g. if interpretation as a string -- lowest (or start of) string address keeps lowest significant byte, thus little-endian.<br />
The output of [http://blockexplorer.com blockexplorer] displays the hash values as big-endians numbers as notation for numbers is usual -- leading digits are the most significant digits read from left to right.<br />
<br />
For another example, [http://pastebin.com/n8UEGA86 here] is a version in plain C without any optimization, threading or error checking.<br />
<br />
[[Category:Technical]]</div>
Smtp
https://en.bitcoin.it/w/index.php?title=Block_hashing_algorithm&diff=35120
Block hashing algorithm
2013-01-16T15:11:48Z
<p>Smtp: </p>
<hr />
<div>When generating, you constantly hash the block header. The block is also occasionally updated as you are working on it. A block header contains these fields:<br />
{| class="wikitable"<br />
|-<br />
! Field<br />
! Purpose<br />
! Updated when...<br />
! Size (Bytes)<br />
|-<br />
|Version<br />
|Block version number<br />
|You upgrade the software and it specifies a new version<br />
|4<br />
|-<br />
|hashPrevBlock<br />
|Hash of the previous block header<br />
|A new block comes in<br />
|32<br />
|-<br />
|hashMerkleRoot<br />
|256-bit hash based on all of the transactions in the block<br />
|A transaction is accepted<br />
|32<br />
|-<br />
|Time<br />
|Current timestamp as seconds since 1970-01-01T00:00 UTC<br />
|Every few seconds<br />
|4<br />
|-<br />
|Bits<br />
|Current [[target]] in compact format<br />
|The [[difficulty]] is adjusted<br />
|4<br />
|-<br />
|Nonce<br />
|32-bit number (starts at 0)<br />
|A hash is tried (increments)<br />
|4<br />
|}<br />
<br />
The body of the block contains the transactions. These are hashed only indirectly through the Merkle root. Because transactions aren't hashed directly, hashing a block with 1 transaction takes exactly the same amount of effort as hashing a block with 10,000 transactions.<br />
<br />
The compact format of target is a special kind of floating-point encoding using 3 bytes mantissa, the leading byte as exponent (where only the 5 lowest bits are used) and its base is 256.<br />
Most of these fields will be the same for all users. There might be some minor variation in the timestamps. The nonce will usually be different, but it increases in a strictly linear way. "Nonce" starts at 0 and is incremented for each hash. Whenever Nonce overflows (which it does frequently), the extraNonce portion of the generation transaction is incremented, which changes the Merkle root.<br />
<br />
Given just those fields, people would frequently generate the exact same sequence of hashes as each other and the fastest CPU would almost always win. However, it is (nearly) impossible for two people to have the same Merkle root because the first transaction in your block is a generation "sent" to one of ''your'' unique Bitcoin addresses. Since your block is different from everyone else's blocks, you are (nearly) guaranteed to produce different hashes. Every hash you calculate has the same chance of winning as every other hash calculated by the network.<br />
<br />
Bitcoin uses: SHA256(SHA256(Block_Header)) but you have to be careful about byte-order.<br />
<br />
For example, this python code will calculate the hash of the block with the smallest hash as of June 2011, [http://blockexplorer.com/block/00000000000000001e8d6829a8a21adc5d38d0a473b144b6765798e61f98bd1d Block 125552]. The header is built from the six fields described above, concatenated together as little-endian values in hex notation:<br />
<br />
>>> import hashlib<br />
>>> header_hex = ("01000000" +<br />
"81cd02ab7e569e8bcd9317e2fe99f2de44d49ab2b8851ba4a308000000000000" +<br />
"e320b6c2fffc8d750423db8b1eb942ae710e951ed797f7affc8892b0f1fc122b" +<br />
"c7f5d74d" +<br />
"f2b9441a" +<br />
"42a14695")<br />
>>> header_bin = header_hex.decode('hex')<br />
>>> hash = hashlib.sha256(hashlib.sha256(header_bin).digest()).digest()<br />
>>> hash.encode('hex_codec')<br />
'1dbd981fe6985776b644b173a4d0385ddc1aa2a829688d1e0000000000000000'<br />
>>> hash[::-1].encode('hex_codec')<br />
'00000000000000001e8d6829a8a21adc5d38d0a473b144b6765798e61f98bd1d'<br />
<br />
Note that the actual hash, which is a 256-bit number, has lots of leading zero bits. When stored or printed as a big-endian hexadecimal constant, but it has leading zero bytes and if stored or printed as little-endian, these are the trailing zero bytes. E.g. if interpretation as a string -- lowest (or start of) string address keeps lowest significant byte, thus little-endian.<br />
The output of [http://blockexplorer.com blockexplorer] displays the hash values as big-endians numbers as notation for numbers is usual -- leading digits are the most significant digits read from left to right.<br />
<br />
For another example, [http://pastebin.com/n8UEGA86 here] is a version in plain C without any optimization, threading or error checking.<br />
<br />
[[Category:Technical]]</div>
Smtp
https://en.bitcoin.it/w/index.php?title=Block_hashing_algorithm&diff=35118
Block hashing algorithm
2013-01-16T15:11:12Z
<p>Smtp: </p>
<hr />
<div>When generating, you constantly hash the block header. The block is also occasionally updated as you are working on it. A block header contains these fields:<br />
{| class="wikitable"<br />
|-<br />
! Field<br />
! Purpose<br />
! Updated when...<br />
! Size (Bytes)<br />
|-<br />
|Version<br />
|Block version number<br />
|You upgrade the software and it specifies a new version<br />
|4<br />
|-<br />
|hashPrevBlock<br />
|Hash of the previous block header<br />
|A new block comes in<br />
|32<br />
|-<br />
|hashMerkleRoot<br />
|256-bit hash based on all of the transactions<br />
|A transaction is accepted<br />
|32<br />
|-<br />
|Time<br />
|Current timestamp as seconds since 1970-01-01T00:00 UTC<br />
|Every few seconds<br />
|4<br />
|-<br />
|Bits<br />
|Current [[target]] in compact format<br />
|The [[difficulty]] is adjusted<br />
|4<br />
|-<br />
|Nonce<br />
|32-bit number (starts at 0)<br />
|A hash is tried (increments)<br />
|4<br />
|}<br />
<br />
The body of the block contains the transactions. These are hashed only indirectly through the Merkle root. Because transactions aren't hashed directly, hashing a block with 1 transaction takes exactly the same amount of effort as hashing a block with 10,000 transactions.<br />
<br />
The compact format of target is a special kind of floating-point encoding using 3 bytes mantissa, the leading byte as exponent (where only the 5 lowest bits are used) and its base is 256.<br />
Most of these fields will be the same for all users. There might be some minor variation in the timestamps. The nonce will usually be different, but it increases in a strictly linear way. "Nonce" starts at 0 and is incremented for each hash. Whenever Nonce overflows (which it does frequently), the extraNonce portion of the generation transaction is incremented, which changes the Merkle root.<br />
<br />
Given just those fields, people would frequently generate the exact same sequence of hashes as each other and the fastest CPU would almost always win. However, it is (nearly) impossible for two people to have the same Merkle root because the first transaction in your block is a generation "sent" to one of ''your'' unique Bitcoin addresses. Since your block is different from everyone else's blocks, you are (nearly) guaranteed to produce different hashes. Every hash you calculate has the same chance of winning as every other hash calculated by the network.<br />
<br />
Bitcoin uses: SHA256(SHA256(Block_Header)) but you have to be careful about byte-order.<br />
<br />
For example, this python code will calculate the hash of the block with the smallest hash as of June 2011, [http://blockexplorer.com/block/00000000000000001e8d6829a8a21adc5d38d0a473b144b6765798e61f98bd1d Block 125552]. The header is built from the six fields described above, concatenated together as little-endian values in hex notation:<br />
<br />
>>> import hashlib<br />
>>> header_hex = ("01000000" +<br />
"81cd02ab7e569e8bcd9317e2fe99f2de44d49ab2b8851ba4a308000000000000" +<br />
"e320b6c2fffc8d750423db8b1eb942ae710e951ed797f7affc8892b0f1fc122b" +<br />
"c7f5d74d" +<br />
"f2b9441a" +<br />
"42a14695")<br />
>>> header_bin = header_hex.decode('hex')<br />
>>> hash = hashlib.sha256(hashlib.sha256(header_bin).digest()).digest()<br />
>>> hash.encode('hex_codec')<br />
'1dbd981fe6985776b644b173a4d0385ddc1aa2a829688d1e0000000000000000'<br />
>>> hash[::-1].encode('hex_codec')<br />
'00000000000000001e8d6829a8a21adc5d38d0a473b144b6765798e61f98bd1d'<br />
<br />
Note that the actual hash, which is a 256-bit number, has lots of leading zero bits. When stored or printed as a big-endian hexadecimal constant, but it has leading zero bytes and if stored or printed as little-endian, these are the trailing zero bytes. E.g. if interpretation as a string -- lowest (or start of) string address keeps lowest significant byte, thus little-endian.<br />
The output of [http://blockexplorer.com blockexplorer] displays the hash values as big-endians numbers as notation for numbers is usual -- leading digits are the most significant digits read from left to right.<br />
<br />
For another example, [http://pastebin.com/n8UEGA86 here] is a version in plain C without any optimization, threading or error checking.<br />
<br />
[[Category:Technical]]</div>
Smtp
https://en.bitcoin.it/w/index.php?title=Block_hashing_algorithm&diff=35116
Block hashing algorithm
2013-01-16T15:10:09Z
<p>Smtp: </p>
<hr />
<div>When generating, you constantly hash the block header. The block is also occasionally updated as you are working on it. A block header contains these fields:<br />
{| class="wikitable"<br />
|-<br />
! Field<br />
! Purpose<br />
! Updated when...<br />
! Size (Bytes)<br />
|-<br />
|Version<br />
|Block version number<br />
|You upgrade the software and it specifies a new version<br />
|4<br />
|-<br />
|hashPrevBlock<br />
|Hash of the previous block<br />
|A new block comes in<br />
|32<br />
|-<br />
|hashMerkleRoot<br />
|256-bit hash based on all of the transactions<br />
|A transaction is accepted<br />
|32<br />
|-<br />
|Time<br />
|Current timestamp as seconds since 1970-01-01T00:00 UTC<br />
|Every few seconds<br />
|4<br />
|-<br />
|Bits<br />
|Current [[target]] in compact format<br />
|The [[difficulty]] is adjusted<br />
|4<br />
|-<br />
|Nonce<br />
|32-bit number (starts at 0)<br />
|A hash is tried (increments)<br />
|4<br />
|}<br />
<br />
The body of the block contains the transactions. These are hashed only indirectly through the Merkle root. Because transactions aren't hashed directly, hashing a block with 1 transaction takes exactly the same amount of effort as hashing a block with 10,000 transactions.<br />
<br />
The compact format of target is a special kind of floating-point encoding using 3 bytes mantissa, the leading byte as exponent (where only the 5 lowest bits are used) and its base is 256.<br />
Most of these fields will be the same for all users. There might be some minor variation in the timestamps. The nonce will usually be different, but it increases in a strictly linear way. "Nonce" starts at 0 and is incremented for each hash. Whenever Nonce overflows (which it does frequently), the extraNonce portion of the generation transaction is incremented, which changes the Merkle root.<br />
<br />
Given just those fields, people would frequently generate the exact same sequence of hashes as each other and the fastest CPU would almost always win. However, it is (nearly) impossible for two people to have the same Merkle root because the first transaction in your block is a generation "sent" to one of ''your'' unique Bitcoin addresses. Since your block is different from everyone else's blocks, you are (nearly) guaranteed to produce different hashes. Every hash you calculate has the same chance of winning as every other hash calculated by the network.<br />
<br />
Bitcoin uses: SHA256(SHA256(Block_Header)) but you have to be careful about byte-order.<br />
<br />
For example, this python code will calculate the hash of the block with the smallest hash as of June 2011, [http://blockexplorer.com/block/00000000000000001e8d6829a8a21adc5d38d0a473b144b6765798e61f98bd1d Block 125552]. The header is built from the six fields described above, concatenated together as little-endian values in hex notation:<br />
<br />
>>> import hashlib<br />
>>> header_hex = ("01000000" +<br />
"81cd02ab7e569e8bcd9317e2fe99f2de44d49ab2b8851ba4a308000000000000" +<br />
"e320b6c2fffc8d750423db8b1eb942ae710e951ed797f7affc8892b0f1fc122b" +<br />
"c7f5d74d" +<br />
"f2b9441a" +<br />
"42a14695")<br />
>>> header_bin = header_hex.decode('hex')<br />
>>> hash = hashlib.sha256(hashlib.sha256(header_bin).digest()).digest()<br />
>>> hash.encode('hex_codec')<br />
'1dbd981fe6985776b644b173a4d0385ddc1aa2a829688d1e0000000000000000'<br />
>>> hash[::-1].encode('hex_codec')<br />
'00000000000000001e8d6829a8a21adc5d38d0a473b144b6765798e61f98bd1d'<br />
<br />
Note that the actual hash, which is a 256-bit number, has lots of leading zero bits. When stored or printed as a big-endian hexadecimal constant, but it has leading zero bytes and if stored or printed as little-endian, these are the trailing zero bytes. E.g. if interpretation as a string -- lowest (or start of) string address keeps lowest significant byte, thus little-endian.<br />
The output of [http://blockexplorer.com blockexplorer] displays the hash values as big-endians numbers as notation for numbers is usual -- leading digits are the most significant digits read from left to right.<br />
<br />
For another example, [http://pastebin.com/n8UEGA86 here] is a version in plain C without any optimization, threading or error checking.<br />
<br />
[[Category:Technical]]</div>
Smtp
https://en.bitcoin.it/w/index.php?title=Block_hashing_algorithm&diff=35114
Block hashing algorithm
2013-01-16T15:09:15Z
<p>Smtp: </p>
<hr />
<div>When generating, you constantly hash the block header. The block is also occasionally updated as you are working on it. A block header contains these fields:<br />
{| class="wikitable"<br />
|-<br />
! Field<br />
! Purpose<br />
! Updated when...<br />
! Size (Bytes)<br />
|-<br />
|Version<br />
|Block version number<br />
|You upgrade the software and it specifies a new version<br />
|4<br />
|-<br />
|hashPrevBlock<br />
|Hash of the previous block<br />
|A new block comes in<br />
|32<br />
|-<br />
|hashMerkleRoot<br />
|256-bit hash based on all of the transactions<br />
|A transaction is accepted<br />
|32<br />
|-<br />
|Time<br />
|Current timestamp as UTC (GMT)<br />
|Every few seconds<br />
|4<br />
|-<br />
|Bits<br />
|Current [[target]] in compact format<br />
|The [[difficulty]] is adjusted<br />
|4<br />
|-<br />
|Nonce<br />
|32-bit number (starts at 0)<br />
|A hash is tried (increments)<br />
|4<br />
|}<br />
<br />
The body of the block contains the transactions. These are hashed only indirectly through the Merkle root. Because transactions aren't hashed directly, hashing a block with 1 transaction takes exactly the same amount of effort as hashing a block with 10,000 transactions.<br />
<br />
The compact format of target is a special kind of floating-point encoding using 3 bytes mantissa, the leading byte as exponent (where only the 5 lowest bits are used) and its base is 256.<br />
Most of these fields will be the same for all users. There might be some minor variation in the timestamps. The nonce will usually be different, but it increases in a strictly linear way. "Nonce" starts at 0 and is incremented for each hash. Whenever Nonce overflows (which it does frequently), the extraNonce portion of the generation transaction is incremented, which changes the Merkle root.<br />
<br />
Given just those fields, people would frequently generate the exact same sequence of hashes as each other and the fastest CPU would almost always win. However, it is (nearly) impossible for two people to have the same Merkle root because the first transaction in your block is a generation "sent" to one of ''your'' unique Bitcoin addresses. Since your block is different from everyone else's blocks, you are (nearly) guaranteed to produce different hashes. Every hash you calculate has the same chance of winning as every other hash calculated by the network.<br />
<br />
Bitcoin uses: SHA256(SHA256(Block_Header)) but you have to be careful about byte-order.<br />
<br />
For example, this python code will calculate the hash of the block with the smallest hash as of June 2011, [http://blockexplorer.com/block/00000000000000001e8d6829a8a21adc5d38d0a473b144b6765798e61f98bd1d Block 125552]. The header is built from the six fields described above, concatenated together as little-endian values in hex notation:<br />
<br />
>>> import hashlib<br />
>>> header_hex = ("01000000" +<br />
"81cd02ab7e569e8bcd9317e2fe99f2de44d49ab2b8851ba4a308000000000000" +<br />
"e320b6c2fffc8d750423db8b1eb942ae710e951ed797f7affc8892b0f1fc122b" +<br />
"c7f5d74d" +<br />
"f2b9441a" +<br />
"42a14695")<br />
>>> header_bin = header_hex.decode('hex')<br />
>>> hash = hashlib.sha256(hashlib.sha256(header_bin).digest()).digest()<br />
>>> hash.encode('hex_codec')<br />
'1dbd981fe6985776b644b173a4d0385ddc1aa2a829688d1e0000000000000000'<br />
>>> hash[::-1].encode('hex_codec')<br />
'00000000000000001e8d6829a8a21adc5d38d0a473b144b6765798e61f98bd1d'<br />
<br />
Note that the actual hash, which is a 256-bit number, has lots of leading zero bits. When stored or printed as a big-endian hexadecimal constant, but it has leading zero bytes and if stored or printed as little-endian, these are the trailing zero bytes. E.g. if interpretation as a string -- lowest (or start of) string address keeps lowest significant byte, thus little-endian.<br />
The output of [http://blockexplorer.com blockexplorer] displays the hash values as big-endians numbers as notation for numbers is usual -- leading digits are the most significant digits read from left to right.<br />
<br />
For another example, [http://pastebin.com/n8UEGA86 here] is a version in plain C without any optimization, threading or error checking.<br />
<br />
[[Category:Technical]]</div>
Smtp
https://en.bitcoin.it/w/index.php?title=Block_hashing_algorithm&diff=35113
Block hashing algorithm
2013-01-16T15:08:04Z
<p>Smtp: </p>
<hr />
<div>When generating, you constantly hash the block header. The block is also occasionally updated as you are working on it. A block header contains these fields:<br />
{| class="wikitable"<br />
|-<br />
! Field<br />
! Purpose<br />
! Updated when...<br />
! Size (Bytes)<br />
|-<br />
|Version<br />
|Block version number<br />
|You upgrade the software and it specifies a new version<br />
|4<br />
|-<br />
|hashPrevBlock<br />
|Hash of the previous block<br />
|A new block comes in<br />
|32<br />
|-<br />
|hashMerkleRoot<br />
|256-bit hash based on all of the transactions<br />
|A transaction is accepted<br />
|32<br />
|-<br />
|Time<br />
|Current timestamp<br />
|Every few seconds<br />
|4<br />
|-<br />
|Bits<br />
|Current [[target]] in compact format<br />
|The [[difficulty]] is adjusted<br />
|4<br />
|-<br />
|Nonce<br />
|32-bit number (starts at 0)<br />
|A hash is tried (increments)<br />
|4<br />
|}<br />
<br />
The body of the block contains the transactions. These are hashed only indirectly through the Merkle root. Because transactions aren't hashed directly, hashing a block with 1 transaction takes exactly the same amount of effort as hashing a block with 10,000 transactions.<br />
<br />
The compact format of target is a special kind of floating-point encoding using 3 bytes mantissa, the leading byte as exponent (where only the 5 lowest bits are used) and its base is 256.<br />
Most of these fields will be the same for all users. There might be some minor variation in the timestamps. The nonce will usually be different, but it increases in a strictly linear way. "Nonce" starts at 0 and is incremented for each hash. Whenever Nonce overflows (which it does frequently), the extraNonce portion of the generation transaction is incremented, which changes the Merkle root.<br />
<br />
Given just those fields, people would frequently generate the exact same sequence of hashes as each other and the fastest CPU would almost always win. However, it is (nearly) impossible for two people to have the same Merkle root because the first transaction in your block is a generation "sent" to one of ''your'' unique Bitcoin addresses. Since your block is different from everyone else's blocks, you are (nearly) guaranteed to produce different hashes. Every hash you calculate has the same chance of winning as every other hash calculated by the network.<br />
<br />
Bitcoin uses: SHA256(SHA256(Block_Header)) but you have to be careful about byte-order.<br />
<br />
For example, this python code will calculate the hash of the block with the smallest hash as of June 2011, [http://blockexplorer.com/block/00000000000000001e8d6829a8a21adc5d38d0a473b144b6765798e61f98bd1d Block 125552]. The header is built from the six fields described above, concatenated together as little-endian values in hex notation:<br />
<br />
>>> import hashlib<br />
>>> header_hex = ("01000000" +<br />
"81cd02ab7e569e8bcd9317e2fe99f2de44d49ab2b8851ba4a308000000000000" +<br />
"e320b6c2fffc8d750423db8b1eb942ae710e951ed797f7affc8892b0f1fc122b" +<br />
"c7f5d74d" +<br />
"f2b9441a" +<br />
"42a14695")<br />
>>> header_bin = header_hex.decode('hex')<br />
>>> hash = hashlib.sha256(hashlib.sha256(header_bin).digest()).digest()<br />
>>> hash.encode('hex_codec')<br />
'1dbd981fe6985776b644b173a4d0385ddc1aa2a829688d1e0000000000000000'<br />
>>> hash[::-1].encode('hex_codec')<br />
'00000000000000001e8d6829a8a21adc5d38d0a473b144b6765798e61f98bd1d'<br />
<br />
Note that the actual hash, which is a 256-bit number, has lots of leading zero bits. When stored or printed as a big-endian hexadecimal constant, but it has leading zero bytes and if stored or printed as little-endian, these are the trailing zero bytes. E.g. if interpretation as a string -- lowest (or start of) string address keeps lowest significant byte, thus little-endian.<br />
The output of [http://blockexplorer.com blockexplorer] displays the hash values as big-endians numbers as notation for numbers is usual -- leading digits are the most significant digits read from left to right.<br />
<br />
For another example, [http://pastebin.com/n8UEGA86 here] is a version in plain C without any optimization, threading or error checking.<br />
<br />
[[Category:Technical]]</div>
Smtp
https://en.bitcoin.it/w/index.php?title=Block_hashing_algorithm&diff=35112
Block hashing algorithm
2013-01-16T15:03:34Z
<p>Smtp: </p>
<hr />
<div>When generating, you constantly hash the block header. The block is also occasionally updated as you are working on it. A block header contains these fields:<br />
{| class="wikitable"<br />
|-<br />
! Field<br />
! Purpose<br />
! Updated when...<br />
! Size (Bytes)<br />
|-<br />
|Version<br />
|Block version number<br />
|You upgrade the software and it specifies a new version<br />
|4<br />
|-<br />
|hashPrevBlock<br />
|Hash of the previous block<br />
|A new block comes in<br />
|32<br />
|-<br />
|hashMerkleRoot<br />
|256-bit hash based on all of the transactions<br />
|A transaction is accepted<br />
|32<br />
|-<br />
|Time<br />
|Current timestamp<br />
|Every few seconds<br />
|4<br />
|-<br />
|Bits<br />
|Current [[target]] in compact format<br />
|The [[difficulty]] is adjusted<br />
|4<br />
|-<br />
|Nonce<br />
|32-bit number (starts at 0)<br />
|A hash is tried (increments)<br />
|4<br />
|}<br />
<br />
The body of the block contains the transactions. These are hashed only indirectly through the Merkle root. Because transactions aren't hashed directly, hashing a block with 1 transaction takes exactly the same amount of effort as hashing a block with 10,000 transactions.<br />
<br />
Most of these fields will be the same for all users. There might be some minor variation in the timestamps. The nonce will usually be different, but it increases in a strictly linear way. "Nonce" starts at 0 and is incremented for each hash. Whenever Nonce overflows (which it does frequently), the extraNonce portion of the generation transaction is incremented, which changes the Merkle root.<br />
<br />
Given just those fields, people would frequently generate the exact same sequence of hashes as each other and the fastest CPU would almost always win. However, it is (nearly) impossible for two people to have the same Merkle root because the first transaction in your block is a generation "sent" to one of ''your'' unique Bitcoin addresses. Since your block is different from everyone else's blocks, you are (nearly) guaranteed to produce different hashes. Every hash you calculate has the same chance of winning as every other hash calculated by the network.<br />
<br />
Bitcoin uses: SHA256(SHA256(Block_Header)) but you have to be careful about byte-order.<br />
<br />
For example, this python code will calculate the hash of the block with the smallest hash as of June 2011, [http://blockexplorer.com/block/00000000000000001e8d6829a8a21adc5d38d0a473b144b6765798e61f98bd1d Block 125552]. The header is built from the six fields described above, concatenated together as little-endian values in hex notation:<br />
<br />
>>> import hashlib<br />
>>> header_hex = ("01000000" +<br />
"81cd02ab7e569e8bcd9317e2fe99f2de44d49ab2b8851ba4a308000000000000" +<br />
"e320b6c2fffc8d750423db8b1eb942ae710e951ed797f7affc8892b0f1fc122b" +<br />
"c7f5d74d" +<br />
"f2b9441a" +<br />
"42a14695")<br />
>>> header_bin = header_hex.decode('hex')<br />
>>> hash = hashlib.sha256(hashlib.sha256(header_bin).digest()).digest()<br />
>>> hash.encode('hex_codec')<br />
'1dbd981fe6985776b644b173a4d0385ddc1aa2a829688d1e0000000000000000'<br />
>>> hash[::-1].encode('hex_codec')<br />
'00000000000000001e8d6829a8a21adc5d38d0a473b144b6765798e61f98bd1d'<br />
<br />
Note that the actual hash, which is a 256-bit number, has lots of leading zero bits. When stored or printed as a big-endian hexadecimal constant, but it has leading zero bytes and if stored or printed as little-endian, these are the trailing zero bytes. E.g. if interpretation as a string -- lowest (or start of) string address keeps lowest significant byte, thus little-endian.<br />
The output of [http://blockexplorer.com blockexplorer] displays the hash values as big-endians numbers as notation for numbers is usual -- leading digits are the most significant digits read from left to right.<br />
<br />
For another example, [http://pastebin.com/n8UEGA86 here] is a version in plain C without any optimization, threading or error checking.<br />
<br />
[[Category:Technical]]</div>
Smtp
https://en.bitcoin.it/w/index.php?title=Block_hashing_algorithm&diff=35111
Block hashing algorithm
2013-01-16T15:00:39Z
<p>Smtp: </p>
<hr />
<div>When generating, you constantly hash the block header. The block is also occasionally updated as you are working on it. A block header contains these fields:<br />
{| class="wikitable"<br />
|-<br />
! Field<br />
! Purpose<br />
! Updated when...<br />
! Size (Bytes)<br />
|-<br />
|Version<br />
|Block version number<br />
|You upgrade the software and it specifies a new version<br />
|4<br />
|-<br />
|Previous hash<br />
|Hash of the previous block<br />
|A new block comes in<br />
|32<br />
|-<br />
|Merkle root<br />
|256-bit hash based on all of the transactions<br />
|A transaction is accepted<br />
|32<br />
|-<br />
|Timestamp<br />
|Current timestamp<br />
|Every few seconds<br />
|4<br />
|-<br />
|"Bits"<br />
|Current [[target]] in compact format<br />
|The [[difficulty]] is adjusted<br />
|4<br />
|-<br />
|Nonce<br />
|32-bit number (starts at 0)<br />
|A hash is tried (increments)<br />
|4<br />
|}<br />
<br />
The body of the block contains the transactions. These are hashed only indirectly through the Merkle root. Because transactions aren't hashed directly, hashing a block with 1 transaction takes exactly the same amount of effort as hashing a block with 10,000 transactions.<br />
<br />
Most of these fields will be the same for all users. There might be some minor variation in the timestamps. The nonce will usually be different, but it increases in a strictly linear way. "Nonce" starts at 0 and is incremented for each hash. Whenever Nonce overflows (which it does frequently), the extraNonce portion of the generation transaction is incremented, which changes the Merkle root.<br />
<br />
Given just those fields, people would frequently generate the exact same sequence of hashes as each other and the fastest CPU would almost always win. However, it is (nearly) impossible for two people to have the same Merkle root because the first transaction in your block is a generation "sent" to one of ''your'' unique Bitcoin addresses. Since your block is different from everyone else's blocks, you are (nearly) guaranteed to produce different hashes. Every hash you calculate has the same chance of winning as every other hash calculated by the network.<br />
<br />
Bitcoin uses: SHA256(SHA256(Block_Header)) but you have to be careful about byte-order.<br />
<br />
For example, this python code will calculate the hash of the block with the smallest hash as of June 2011, [http://blockexplorer.com/block/00000000000000001e8d6829a8a21adc5d38d0a473b144b6765798e61f98bd1d Block 125552]. The header is built from the six fields described above, concatenated together as little-endian values in hex notation:<br />
<br />
>>> import hashlib<br />
>>> header_hex = ("01000000" +<br />
"81cd02ab7e569e8bcd9317e2fe99f2de44d49ab2b8851ba4a308000000000000" +<br />
"e320b6c2fffc8d750423db8b1eb942ae710e951ed797f7affc8892b0f1fc122b" +<br />
"c7f5d74d" +<br />
"f2b9441a" +<br />
"42a14695")<br />
>>> header_bin = header_hex.decode('hex')<br />
>>> hash = hashlib.sha256(hashlib.sha256(header_bin).digest()).digest()<br />
>>> hash.encode('hex_codec')<br />
'1dbd981fe6985776b644b173a4d0385ddc1aa2a829688d1e0000000000000000'<br />
>>> hash[::-1].encode('hex_codec')<br />
'00000000000000001e8d6829a8a21adc5d38d0a473b144b6765798e61f98bd1d'<br />
<br />
Note that the actual hash, which is a 256-bit number, has lots of leading zero bits. When stored or printed as a big-endian hexadecimal constant, but it has leading zero bytes and if stored or printed as little-endian, these are the trailing zero bytes. E.g. if interpretation as a string -- lowest (or start of) string address keeps lowest significant byte, thus little-endian.<br />
The output of [http://blockexplorer.com blockexplorer] displays the hash values as big-endians numbers as notation for numbers is usual -- leading digits are the most significant digits read from left to right.<br />
<br />
For another example, [http://pastebin.com/n8UEGA86 here] is a version in plain C without any optimization, threading or error checking.<br />
<br />
[[Category:Technical]]</div>
Smtp
https://en.bitcoin.it/w/index.php?title=Block_hashing_algorithm&diff=35110
Block hashing algorithm
2013-01-16T14:59:11Z
<p>Smtp: a little remember about endianess and typical interpretation (number/string)</p>
<hr />
<div>When generating, you constantly hash the block header. The block is also occasionally updated as you are working on it. A block header contains these fields:<br />
{| class="wikitable"<br />
|-<br />
! Field<br />
! Purpose<br />
! Updated when...<br />
! Size (Bytes)<br />
|-<br />
|Version<br />
|Block version number<br />
|You upgrade the software and it specifies a new version<br />
|4<br />
|-<br />
|Previous hash<br />
|Hash of the previous block<br />
|A new block comes in<br />
|32<br />
|-<br />
|Merkle root<br />
|256-bit hash based on all of the transactions<br />
|A transaction is accepted<br />
|32<br />
|-<br />
|Timestamp<br />
|Current timestamp<br />
|Every few seconds<br />
|4<br />
|-<br />
|"Bits"<br />
|Current [[target]] in compact format<br />
|The [[difficulty]] is adjusted<br />
|4<br />
|-<br />
|Nonce<br />
|32-bit number (starts at 0)<br />
|A hash is tried (increments)<br />
|4<br />
|}<br />
<br />
The body of the block contains the transactions. These are hashed only indirectly through the Merkle root. Because transactions aren't hashed directly, hashing a block with 1 transaction takes exactly the same amount of effort as hashing a block with 10,000 transactions.<br />
<br />
Most of these fields will be the same for all users. There might be some minor variation in the timestamps. The nonce will usually be different, but it increases in a strictly linear way. "Nonce" starts at 0 and is incremented for each hash. Whenever Nonce overflows (which it does frequently), the extraNonce portion of the generation transaction is incremented, which changes the Merkle root.<br />
<br />
Given just those fields, people would frequently generate the exact same sequence of hashes as each other and the fastest CPU would almost always win. However, it is (nearly) impossible for two people to have the same Merkle root because the first transaction in your block is a generation "sent" to one of ''your'' unique Bitcoin addresses. Since your block is different from everyone else's blocks, you are (nearly) guaranteed to produce different hashes. Every hash you calculate has the same chance of winning as every other hash calculated by the network.<br />
<br />
Bitcoin uses: SHA256(SHA256(Block_Header)) but you have to be careful about byte-order.<br />
<br />
For example, this python code will calculate the hash of the block with the smallest hash as of June 2011, [http://blockexplorer.com/block/00000000000000001e8d6829a8a21adc5d38d0a473b144b6765798e61f98bd1d Block 125552]. The header is built from the six fields described above, concatenated together as little-endian values in hex notation:<br />
<br />
>>> import hashlib<br />
>>> header_hex = ("01000000" +<br />
"81cd02ab7e569e8bcd9317e2fe99f2de44d49ab2b8851ba4a308000000000000" +<br />
"e320b6c2fffc8d750423db8b1eb942ae710e951ed797f7affc8892b0f1fc122b" +<br />
"c7f5d74d" +<br />
"f2b9441a" +<br />
"42a14695")<br />
>>> header_bin = header_hex.decode('hex')<br />
>>> hash = hashlib.sha256(hashlib.sha256(header_bin).digest()).digest()<br />
>>> hash.encode('hex_codec')<br />
'1dbd981fe6985776b644b173a4d0385ddc1aa2a829688d1e0000000000000000'<br />
>>> hash[::-1].encode('hex_codec')<br />
'00000000000000001e8d6829a8a21adc5d38d0a473b144b6765798e61f98bd1d'<br />
<br />
Note that the actual hash, which is a 256-bit number, has lots of leading zero bits. When stored or printed as a big-endian hexadecimal constant, but it has leading zero bytes and if stored or printed as little-endian, these are the trailing zero bytes. E.g. if interpretation as a string -- lowest (or start of) string address keeps lowest significant byte, thus little-endian.<br />
The output of [http://blockexplorer.com] displays the hash values as big-endians numbers as notation for numbers is usual -- leading digits are the most significant digits read from left to right.<br />
<br />
For another example, [http://pastebin.com/n8UEGA86 here] is a version in plain C without any optimization, threading or error checking.<br />
<br />
[[Category:Technical]]</div>
Smtp
https://en.bitcoin.it/w/index.php?title=File:Bitcoin_OpCheckSig_InDetail.png&diff=34957
File:Bitcoin OpCheckSig InDetail.png
2013-01-12T20:34:47Z
<p>Smtp: /* Summary */</p>
<hr />
<div>== Summary ==<br />
A full breakdown of the process to verify the Bitcoin ECDSA signature of a pair of transactions.<br />
Sadly, there are '''2 decisive errors''' in the picture: In step 7: "empty string" is "byte 0" and in step 8: the Subscript copied into TxIn script must be lead-in by its length coded as a var-int.<br />
<br />
== Licensing ==<br />
{{self|Cc-zero}}</div>
Smtp
https://en.bitcoin.it/w/index.php?title=File:Bitcoin_OpCheckSig_InDetail.png&diff=34956
File:Bitcoin OpCheckSig InDetail.png
2013-01-12T20:34:15Z
<p>Smtp: /* Summary */</p>
<hr />
<div>== Summary ==<br />
A full breakdown of the process to verify the Bitcoin ECDSA signature of a pair of transactions.<br />
Sadly, there are '''2 decisive errors''' in the picture: In step 7: "empty string" is "byte 0" and in step 8: the Subscript copied into txin-script must be lead-in by its length coded as a var-int.<br />
<br />
== Licensing ==<br />
{{self|Cc-zero}}</div>
Smtp
https://en.bitcoin.it/w/index.php?title=File:Bitcoin_OpCheckSig_InDetail.png&diff=34955
File:Bitcoin OpCheckSig InDetail.png
2013-01-12T20:33:02Z
<p>Smtp: /* Summary */</p>
<hr />
<div>== Summary ==<br />
A full breakdown of the process to verify the Bitcoin ECDSA signature of a pair of transactions.<br />
Sadly, there are '''2 decisive errors''' in the picture: In step 7: "empty string" is "byte 0" and in step 8: the subScript copied into must be lead-in by its length coded as a var-int.<br />
<br />
== Licensing ==<br />
{{self|Cc-zero}}</div>
Smtp
https://en.bitcoin.it/w/index.php?title=OP_CHECKSIG&diff=34950
OP CHECKSIG
2013-01-12T17:24:16Z
<p>Smtp: /* Procedure for Hashtype SIGHASH_SINGLE */</p>
<hr />
<div>OP_CHECKSIG is [[Script|script]] opcode used to verify that the signature for a tx input is valid. OP_CHECKSIG expects two values to be on the stack, these are, in order of stack depth, the public key and the signature of the script. These two values are normally obtained by running the scriptSig script of the transaction input we are attempting to validate. After the scriptSig script is run the script is deleted but the stack is left as is, and then then scriptPubKey script from the previous transaction output that is now being spent is run, generally concluding in an OP_CHECKSIG. <br />
<br />
The standard scriptPubKey checks that the public key (actually a hash of) is a particular value, and that OP_CHECKSIG passes.<br />
<br />
For normal transaction inputs if the creator of the current transaction can successfully create a ScriptSig signature that uses the right public key for the ScriptPubKey of the transaction output they are attempting to spend, that transaction input is considered valid. <br />
<br />
== Parameters ==<br />
<br />
In addition to the script code itself and the stack parameters, to operate OP_CHECKSIG needs to know the current transaction and the index of current transaction input.<br />
<br />
== How it works ==<br />
Firstly always this (the default) procedure is applied:<br />
[[File:Bitcoin_OpCheckSig_InDetail.png|thumb|right|Signature verification process of the default procedure]]<br />
# the public key and the signature are popped from the stack, in that order. If the hash-type value is 0, then it is replaced by the last_byte of the signature. Then the last byte of the signature is always deleted.<br />
# A new subscript is created from the instruction from the most recently parsed OP_CODESEPARATOR (last one in script) to the end of the script. If there is no OP_CODESEPARATOR the entire script becomes the subscript (hereby referred to as subScript)<br />
# The sig is deleted from subScript.<br />
# All OP_CODESEPARATORS are removed from subScript<br />
# The hashtype is removed from the last byte of the sig and stored<br />
# A copy is made of the current transaction (hereby referred to txCopy)<br />
# The scripts for all transaction inputs in txCopy are set to empty scripts (exactly 1 byte 0x00)<br />
# The script for the current transaction input in txCopy is set to subScript (lead in by its length as a var-integer encoded!)<br />
<br />
Now depending on the hashtype various things can happen to txCopy, these will be discussed individually.<br />
<br />
'''Hashtype Values (from script.h):'''<br />
{|class="wikitable"<br />
! Name !! Value<br />
|-<br />
| SIGHASH_ALL || 0x00000001<br />
|-<br />
| SIGHASH_NONE || 0x00000002<br />
|-<br />
| SIGHASH_SINGLE || 0x00000003<br />
|-<br />
| SIGHASH_ANYONECANPAY || 0x00000080<br />
|}<br />
<br />
<ol><br />
<li> If (hashtype&31) = SIGHASH_NONE then apply the SIGHASH_NONE-procedure<br />
<li> If (hashtype&31) = SIGHASH_SINGLE then apply the SIGHASH_SINGLE-procedure<br />
<li> If hashtype & SIGHASH_ANYONECANPAY then apply the SIGHASH_ANYONECANPAY-procedure<br />
</ol><br />
Hence, hashtype SIGHASH_ANYONECANPAY may be applied also after any other hashtype-procedure<ref>[http://sourceforge.net/projects/bitcoin/files/Bitcoin/bitcoin-0.7.1/bitcoin-0.7.1-linux.tar.gz file src/src/script.cpp in bitcoin-0.7.1]</ref>. Besides the four listed hashtypes only a hashtype of value 0 appears a few types in the (main) block chain (and is handled like SIGHASH_ALL).<br />
<br />
=== Hashtype SIGHASH_ALL (default) ===<br />
<br />
No special further handling occurs in the default case. Think of this as "sign '''all''' of the outputs." Which is already done by the default procedure.<br />
<br />
=== Procedure for Hashtype SIGHASH_NONE ===<br />
<br />
# The output of txCopy is set to a vector of zero size.<br />
# All other inputs aside from the current input in txCopy have their nSequence index set to zero<br />
<br />
Think of this as "sign '''none''' of the outputs-- I don't care where the bitcoins go."<br />
<br />
=== Procedure for Hashtype SIGHASH_SINGLE ===<br />
<br />
# The output of txCopy is resized to the size of the current input index+1.<br />
# All other txCopy outputs aside from the output that is the same as the current input index are set to a blank script and a value of (long) -1.<br />
# All other txCopy inputs aside from the current input are set to have an nSequence index of zero.<br />
<br />
Think of this as "sign '''one''' of the outputs-- I don't care where the other outputs go".<br />
<br />
=== Procedure for Hashtype SIGHASH_ANYONECANPAY ===<br />
<br />
# The txCopy input vector is resized to a length of one.<br />
# The subScript (lead in by its length as a var-integer encoded!) is set as the first and only member of this vector.<br />
<br />
Think of this as "Let other people add inputs to this transaction, I don't care where the rest of the bitcoins come from."<br />
<br />
===Final signature check===<br />
<br />
An array of bytes is constructed from the serialized txCopy appended by four bytes for the hash type. This array is sha256 hashed twice, then the public key is used to check the supplied signature against the hash.<br />
The secp256k1 elliptic curve is used for the verification with the given public key.<br />
<br />
== Return values ==<br />
<br />
OP_CHECKSIG will push true to the stack if the check passed, false otherwise.<br />
OP_CHECKSIG_VERIFY leaves nothing on the stack but will cause the script eval to fail immediately if the check does not pass.<br />
<br />
== Code samples and raw dumps ==<br />
<br />
Taking the first transaction in Bitcoin which is in block number 170, we would get after serialising the transaction but before we hash+sign (or verify) it:<br />
<br />
* http://blockexplorer.com/block/00000000d1145790a8694403d4063f323d499e655c83426834d4ce2f8dd4a2ee<br />
* http://blockexplorer.com/tx/f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16<br />
<br />
See also [https://gitorious.org/libbitcoin/libbitcoin libbitcoin] for code samples.<br />
<br />
<pre><br />
01 00 00 00 version<br />
01 number of inputs (var_uint)<br />
<br />
input 0:<br />
c9 97 a5 e5 6e 10 41 02 input address hash<br />
fa 20 9c 6a 85 2d d9 06 <br />
60 a2 0b 2d 9c 35 24 23 <br />
ed ce 25 85 7f cd 37 04<br />
00 00 00 00 input index<br />
<br />
48 size of script (var_uint)<br />
47 push 71 bytes to stack<br />
30 44 02 20 4e 45 e1 69<br />
32 b8 af 51 49 61 a1 d3<br />
a1 a2 5f df 3f 4f 77 32<br />
e9 d6 24 c6 c6 15 48 ab<br />
5f b8 cd 41 02 20 18 15<br />
22 ec 8e ca 07 de 48 60<br />
a4 ac dd 12 90 9d 83 1c<br />
c5 6c bb ac 46 22 08 22<br />
21 a8 76 8d 1d 09 01<br />
ff ff ff ff sequence<br />
<br />
02 number of outputs (var_uint)<br />
<br />
output 0:<br />
00 ca 9a 3b 00 00 00 00 amount = 10.00000000<br />
43 size of script (var_uint)<br />
script for output 0:<br />
41 push 65 bytes to stack<br />
04 ae 1a 62 fe 09 c5 f5 <br />
1b 13 90 5f 07 f0 6b 99 <br />
a2 f7 15 9b 22 25 f3 74 <br />
cd 37 8d 71 30 2f a2 84 <br />
14 e7 aa b3 73 97 f5 54 <br />
a7 df 5f 14 2c 21 c1 b7 <br />
30 3b 8a 06 26 f1 ba de <br />
d5 c7 2a 70 4f 7e 6c d8 <br />
4c <br />
ac OP_CHECKSIG<br />
<br />
output 1:<br />
00 28 6b ee 00 00 00 00 amount = 40.00000000<br />
43 size of script (var_uint)<br />
script for output 1:<br />
41 push 65 bytes to stack<br />
04 11 db 93 e1 dc db 8a <br />
01 6b 49 84 0f 8c 53 bc <br />
1e b6 8a 38 2e 97 b1 48 <br />
2e ca d7 b1 48 a6 90 9a<br />
5c b2 e0 ea dd fb 84 cc <br />
f9 74 44 64 f8 2e 16 0b <br />
fa 9b 8b 64 f9 d4 c0 3f <br />
99 9b 86 43 f6 56 b4 12 <br />
a3 <br />
ac OP_CHECKSIG<br />
<br />
00 00 00 00 locktime<br />
01 00 00 00 hash_code_type (added on)<br />
<br />
result =<br />
01 00 00 00 01 c9 97 a5 e5 6e 10 41 02 fa 20 9c 6a 85 2d d9 06 60 a2 0b 2d 9c 35 <br />
24 23 ed ce 25 85 7f cd 37 04 00 00 00 00 43 41 04 11 db 93 e1 dc db 8a 01 6b 49 <br />
84 0f 8c 53 bc 1e b6 8a 38 2e 97 b1 48 2e ca d7 b1 48 a6 90 9a 5c b2 e0 ea dd fb <br />
84 cc f9 74 44 64 f8 2e 16 0b fa 9b 8b 64 f9 d4 c0 3f 99 9b 86 43 f6 56 b4 12 a3 <br />
ac ff ff ff ff 02 00 ca 9a 3b 00 00 00 00 43 41 04 ae 1a 62 fe 09 c5 f5 1b 13 90 <br />
5f 07 f0 6b 99 a2 f7 15 9b 22 25 f3 74 cd 37 8d 71 30 2f a2 84 14 e7 aa b3 73 97 <br />
f5 54 a7 df 5f 14 2c 21 c1 b7 30 3b 8a 06 26 f1 ba de d5 c7 2a 70 4f 7e 6c d8 4c <br />
ac 00 28 6b ee 00 00 00 00 43 41 04 11 db 93 e1 dc db 8a 01 6b 49 84 0f 8c 53 bc <br />
1e b6 8a 38 2e 97 b1 48 2e ca d7 b1 48 a6 90 9a 5c b2 e0 ea dd fb 84 cc f9 74 44 <br />
64 f8 2e 16 0b fa 9b 8b 64 f9 d4 c0 3f 99 9b 86 43 f6 56 b4 12 a3 ac 00 00 00 00 <br />
01 00 00 00 <br />
</pre><br />
<br />
To understand where that raw dump has come from, it may be useful to examine tests/ec-key.cpp in [https://gitorious.org/libbitcoin/libbitcoin libbitcoin],<br />
<br />
[https://gitorious.org/libbitcoin/libbitcoin libbitcoin] has a unit test under tests/ec-key.cpp (make ec-key && ./bin/tests/ec-key). There is also a working OP_CHECKSIG implementation in src/script.cpp under script::op_checksig(). See also the unit test: tests/script-test.cpp<br />
<br />
<source lang="cpp"><br />
#include <iostream><br />
#include <iomanip><br />
#include <bitcoin/util/serializer.hpp><br />
#include <bitcoin/util/elliptic_curve_key.hpp><br />
#include <bitcoin/util/sha256.hpp><br />
#include <bitcoin/util/assert.hpp><br />
#include <bitcoin/util/logger.hpp><br />
#include <bitcoin/types.hpp><br />
#include <openssl/ecdsa.h><br />
#include <openssl/obj_mac.h><br />
using libbitcoin::elliptic_curve_key;<br />
using libbitcoin::serializer;<br />
using libbitcoin::hash_digest;<br />
using libbitcoin::data_chunk;<br />
using libbitcoin::log_info;<br />
using libbitcoin::log_fatal;<br />
<br />
int main()<br />
{<br />
serializer ss;<br />
// blk number 170, tx 1, input 0<br />
// version = 1<br />
ss.write_4_bytes(1);<br />
// 1 inputs<br />
ss.write_var_uint(1);<br />
<br />
// input 0<br />
// prevout hash<br />
ss.write_hash(hash_digest{0x04, 0x37, 0xcd, 0x7f, 0x85, 0x25, 0xce, 0xed, 0x23, 0x24, 0x35, 0x9c, 0x2d, 0x0b, 0xa2, 0x60, 0x06, 0xd9, 0x2d, 0x85, 0x6a, 0x9c, 0x20, 0xfa, 0x02, 0x41, 0x10, 0x6e, 0xe5, 0xa5, 0x97, 0xc9});<br />
// prevout index <br />
ss.write_4_bytes(0);<br />
<br />
// input script after running OP_CHECKSIG for this tx is a single<br />
// OP_CHECKSIG opcode<br />
data_chunk raw_data;<br />
raw_data = {0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3};<br />
data_chunk raw_script;<br />
raw_script = data_chunk();<br />
raw_script.push_back(raw_data.size());<br />
libbitcoin::extend_data(raw_script, raw_data);<br />
raw_script.push_back(172);<br />
ss.write_var_uint(raw_script.size());<br />
ss.write_data(raw_script);<br />
// sequence<br />
ss.write_4_bytes(0xffffffff);<br />
<br />
// 2 outputs for this tx<br />
ss.write_var_uint(2);<br />
<br />
// output 0<br />
ss.write_8_bytes(1000000000);<br />
// script for output 0<br />
raw_data = {0x04, 0xae, 0x1a, 0x62, 0xfe, 0x09, 0xc5, 0xf5, 0x1b, 0x13, 0x90, 0x5f, 0x07, 0xf0, 0x6b, 0x99, 0xa2, 0xf7, 0x15, 0x9b, 0x22, 0x25, 0xf3, 0x74, 0xcd, 0x37, 0x8d, 0x71, 0x30, 0x2f, 0xa2, 0x84, 0x14, 0xe7, 0xaa, 0xb3, 0x73, 0x97, 0xf5, 0x54, 0xa7, 0xdf, 0x5f, 0x14, 0x2c, 0x21, 0xc1, 0xb7, 0x30, 0x3b, 0x8a, 0x06, 0x26, 0xf1, 0xba, 0xde, 0xd5, 0xc7, 0x2a, 0x70, 0x4f, 0x7e, 0x6c, 0xd8, 0x4c};<br />
// when data < 75, we can just write it's length as a single byte ('special'<br />
// opcodes)<br />
raw_script = data_chunk();<br />
raw_script.push_back(raw_data.size());<br />
libbitcoin::extend_data(raw_script, raw_data);<br />
// OP_CHECKSIG<br />
raw_script.push_back(172);<br />
// now actually write the script<br />
ss.write_var_uint(raw_script.size());<br />
ss.write_data(raw_script);<br />
<br />
// output 0<br />
ss.write_8_bytes(4000000000);<br />
// script for output 0<br />
raw_data = {0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3};<br />
// when data < 75, we can just write it's length as a single byte ('special'<br />
raw_script.push_back(raw_data.size());<br />
libbitcoin::extend_data(raw_script, raw_data);<br />
// OP_CHECKSIG<br />
raw_script.push_back(172);<br />
// now actually write the script<br />
ss.write_var_uint(raw_script.size());<br />
ss.write_data(raw_script);<br />
<br />
// End of 2 outputs<br />
<br />
// locktime<br />
ss.write_4_bytes(0);<br />
<br />
// write hash_type_code<br />
ss.write_4_bytes(1);<br />
<br />
// Dump hex to screen<br />
log_info() << "hashing:";<br />
{<br />
auto log_obj = log_info();<br />
log_obj << std::hex;<br />
for (int val: ss.get_data())<br />
log_obj << std::setfill('0') << std::setw(2) << val << ' ';<br />
}<br />
log_info();<br />
<br />
data_chunk raw_tx = {0x01, 0x00, 0x00, 0x00, 0x01, 0xc9, 0x97, 0xa5, 0xe5, 0x6e, 0x10, 0x41, 0x02, 0xfa, 0x20, 0x9c, 0x6a, 0x85, 0x2d, 0xd9, 0x06, 0x60, 0xa2, 0x0b, 0x2d, 0x9c, 0x35, 0x24, 0x23, 0xed, 0xce, 0x25, 0x85, 0x7f, 0xcd, 0x37, 0x04, 0x00, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3, 0xac, 0xff, 0xff, 0xff, 0xff, 0x02, 0x00, 0xca, 0x9a, 0x3b, 0x00, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, 0xae, 0x1a, 0x62, 0xfe, 0x09, 0xc5, 0xf5, 0x1b, 0x13, 0x90, 0x5f, 0x07, 0xf0, 0x6b, 0x99, 0xa2, 0xf7, 0x15, 0x9b, 0x22, 0x25, 0xf3, 0x74, 0xcd, 0x37, 0x8d, 0x71, 0x30, 0x2f, 0xa2, 0x84, 0x14, 0xe7, 0xaa, 0xb3, 0x73, 0x97, 0xf5, 0x54, 0xa7, 0xdf, 0x5f, 0x14, 0x2c, 0x21, 0xc1, 0xb7, 0x30, 0x3b, 0x8a, 0x06, 0x26, 0xf1, 0xba, 0xde, 0xd5, 0xc7, 0x2a, 0x70, 0x4f, 0x7e, 0x6c, 0xd8, 0x4c, 0xac, 0x00, 0x28, 0x6b, 0xee, 0x00, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3, 0xac, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00};<br />
BITCOIN_ASSERT(raw_tx == ss.get_data());<br />
<br />
hash_digest tx_hash = libbitcoin::generate_sha256_hash(ss.get_data());<br />
<br />
data_chunk pubkey{0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3};<br />
// Leave out last byte since that's the hash_type_code (SIGHASH_ALL in this<br />
// case)<br />
data_chunk signature{0x30, 0x44, 0x02, 0x20, 0x4e, 0x45, 0xe1, 0x69, 0x32, 0xb8, 0xaf, 0x51, 0x49, 0x61, 0xa1, 0xd3, 0xa1, 0xa2, 0x5f, 0xdf, 0x3f, 0x4f, 0x77, 0x32, 0xe9, 0xd6, 0x24, 0xc6, 0xc6, 0x15, 0x48, 0xab, 0x5f, 0xb8, 0xcd, 0x41, 0x02, 0x20, 0x18, 0x15, 0x22, 0xec, 0x8e, 0xca, 0x07, 0xde, 0x48, 0x60, 0xa4, 0xac, 0xdd, 0x12, 0x90, 0x9d, 0x83, 0x1c, 0xc5, 0x6c, 0xbb, 0xac, 0x46, 0x22, 0x08, 0x22, 0x21, 0xa8, 0x76, 0x8d, 0x1d, 0x09};<br />
BITCOIN_ASSERT(signature.size() == 70);<br />
<br />
elliptic_curve_key key;<br />
if (!key.set_public_key(pubkey))<br />
{<br />
log_fatal() << "unable to set EC public key";<br />
return -1;<br />
}<br />
<br />
log_info() << "checksig returns: " << (key.verify(tx_hash, signature) ? "true" : "false");<br />
return 0;<br />
}<br />
<br />
</source><br />
<br />
==References==<br />
<references/><br />
<br />
[[Category:Technical]]<br />
[[Category:Developer]]</div>
Smtp
https://en.bitcoin.it/w/index.php?title=OP_CHECKSIG&diff=34949
OP CHECKSIG
2013-01-12T17:23:19Z
<p>Smtp: /* Procedure for Hashtype SIGHASH_ANYONECANPAY */ This is correct (not the current input!) -- checked</p>
<hr />
<div>OP_CHECKSIG is [[Script|script]] opcode used to verify that the signature for a tx input is valid. OP_CHECKSIG expects two values to be on the stack, these are, in order of stack depth, the public key and the signature of the script. These two values are normally obtained by running the scriptSig script of the transaction input we are attempting to validate. After the scriptSig script is run the script is deleted but the stack is left as is, and then then scriptPubKey script from the previous transaction output that is now being spent is run, generally concluding in an OP_CHECKSIG. <br />
<br />
The standard scriptPubKey checks that the public key (actually a hash of) is a particular value, and that OP_CHECKSIG passes.<br />
<br />
For normal transaction inputs if the creator of the current transaction can successfully create a ScriptSig signature that uses the right public key for the ScriptPubKey of the transaction output they are attempting to spend, that transaction input is considered valid. <br />
<br />
== Parameters ==<br />
<br />
In addition to the script code itself and the stack parameters, to operate OP_CHECKSIG needs to know the current transaction and the index of current transaction input.<br />
<br />
== How it works ==<br />
Firstly always this (the default) procedure is applied:<br />
[[File:Bitcoin_OpCheckSig_InDetail.png|thumb|right|Signature verification process of the default procedure]]<br />
# the public key and the signature are popped from the stack, in that order. If the hash-type value is 0, then it is replaced by the last_byte of the signature. Then the last byte of the signature is always deleted.<br />
# A new subscript is created from the instruction from the most recently parsed OP_CODESEPARATOR (last one in script) to the end of the script. If there is no OP_CODESEPARATOR the entire script becomes the subscript (hereby referred to as subScript)<br />
# The sig is deleted from subScript.<br />
# All OP_CODESEPARATORS are removed from subScript<br />
# The hashtype is removed from the last byte of the sig and stored<br />
# A copy is made of the current transaction (hereby referred to txCopy)<br />
# The scripts for all transaction inputs in txCopy are set to empty scripts (exactly 1 byte 0x00)<br />
# The script for the current transaction input in txCopy is set to subScript (lead in by its length as a var-integer encoded!)<br />
<br />
Now depending on the hashtype various things can happen to txCopy, these will be discussed individually.<br />
<br />
'''Hashtype Values (from script.h):'''<br />
{|class="wikitable"<br />
! Name !! Value<br />
|-<br />
| SIGHASH_ALL || 0x00000001<br />
|-<br />
| SIGHASH_NONE || 0x00000002<br />
|-<br />
| SIGHASH_SINGLE || 0x00000003<br />
|-<br />
| SIGHASH_ANYONECANPAY || 0x00000080<br />
|}<br />
<br />
<ol><br />
<li> If (hashtype&31) = SIGHASH_NONE then apply the SIGHASH_NONE-procedure<br />
<li> If (hashtype&31) = SIGHASH_SINGLE then apply the SIGHASH_SINGLE-procedure<br />
<li> If hashtype & SIGHASH_ANYONECANPAY then apply the SIGHASH_ANYONECANPAY-procedure<br />
</ol><br />
Hence, hashtype SIGHASH_ANYONECANPAY may be applied also after any other hashtype-procedure<ref>[http://sourceforge.net/projects/bitcoin/files/Bitcoin/bitcoin-0.7.1/bitcoin-0.7.1-linux.tar.gz file src/src/script.cpp in bitcoin-0.7.1]</ref>. Besides the four listed hashtypes only a hashtype of value 0 appears a few types in the (main) block chain (and is handled like SIGHASH_ALL).<br />
<br />
=== Hashtype SIGHASH_ALL (default) ===<br />
<br />
No special further handling occurs in the default case. Think of this as "sign '''all''' of the outputs." Which is already done by the default procedure.<br />
<br />
=== Procedure for Hashtype SIGHASH_NONE ===<br />
<br />
# The output of txCopy is set to a vector of zero size.<br />
# All other inputs aside from the current input in txCopy have their nSequence index set to zero<br />
<br />
Think of this as "sign '''none''' of the outputs-- I don't care where the bitcoins go."<br />
<br />
=== Procedure for Hashtype SIGHASH_SINGLE ===<br />
<br />
# The output of txCopy is resized to the size of the current input index+1<br />
# All other txCopy outputs aside from the output that is the same as the current input index are set to a blank script and a value of (long) -1;<br />
# All other txCopy inputs aside from the current input are set to have an nSequence index of zero<br />
<br />
Think of this as "sign '''one''' of the outputs-- I don't care where the other outputs go."<br />
<br />
=== Procedure for Hashtype SIGHASH_ANYONECANPAY ===<br />
<br />
# The txCopy input vector is resized to a length of one.<br />
# The subScript (lead in by its length as a var-integer encoded!) is set as the first and only member of this vector.<br />
<br />
Think of this as "Let other people add inputs to this transaction, I don't care where the rest of the bitcoins come from."<br />
<br />
===Final signature check===<br />
<br />
An array of bytes is constructed from the serialized txCopy appended by four bytes for the hash type. This array is sha256 hashed twice, then the public key is used to check the supplied signature against the hash.<br />
The secp256k1 elliptic curve is used for the verification with the given public key.<br />
<br />
== Return values ==<br />
<br />
OP_CHECKSIG will push true to the stack if the check passed, false otherwise.<br />
OP_CHECKSIG_VERIFY leaves nothing on the stack but will cause the script eval to fail immediately if the check does not pass.<br />
<br />
== Code samples and raw dumps ==<br />
<br />
Taking the first transaction in Bitcoin which is in block number 170, we would get after serialising the transaction but before we hash+sign (or verify) it:<br />
<br />
* http://blockexplorer.com/block/00000000d1145790a8694403d4063f323d499e655c83426834d4ce2f8dd4a2ee<br />
* http://blockexplorer.com/tx/f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16<br />
<br />
See also [https://gitorious.org/libbitcoin/libbitcoin libbitcoin] for code samples.<br />
<br />
<pre><br />
01 00 00 00 version<br />
01 number of inputs (var_uint)<br />
<br />
input 0:<br />
c9 97 a5 e5 6e 10 41 02 input address hash<br />
fa 20 9c 6a 85 2d d9 06 <br />
60 a2 0b 2d 9c 35 24 23 <br />
ed ce 25 85 7f cd 37 04<br />
00 00 00 00 input index<br />
<br />
48 size of script (var_uint)<br />
47 push 71 bytes to stack<br />
30 44 02 20 4e 45 e1 69<br />
32 b8 af 51 49 61 a1 d3<br />
a1 a2 5f df 3f 4f 77 32<br />
e9 d6 24 c6 c6 15 48 ab<br />
5f b8 cd 41 02 20 18 15<br />
22 ec 8e ca 07 de 48 60<br />
a4 ac dd 12 90 9d 83 1c<br />
c5 6c bb ac 46 22 08 22<br />
21 a8 76 8d 1d 09 01<br />
ff ff ff ff sequence<br />
<br />
02 number of outputs (var_uint)<br />
<br />
output 0:<br />
00 ca 9a 3b 00 00 00 00 amount = 10.00000000<br />
43 size of script (var_uint)<br />
script for output 0:<br />
41 push 65 bytes to stack<br />
04 ae 1a 62 fe 09 c5 f5 <br />
1b 13 90 5f 07 f0 6b 99 <br />
a2 f7 15 9b 22 25 f3 74 <br />
cd 37 8d 71 30 2f a2 84 <br />
14 e7 aa b3 73 97 f5 54 <br />
a7 df 5f 14 2c 21 c1 b7 <br />
30 3b 8a 06 26 f1 ba de <br />
d5 c7 2a 70 4f 7e 6c d8 <br />
4c <br />
ac OP_CHECKSIG<br />
<br />
output 1:<br />
00 28 6b ee 00 00 00 00 amount = 40.00000000<br />
43 size of script (var_uint)<br />
script for output 1:<br />
41 push 65 bytes to stack<br />
04 11 db 93 e1 dc db 8a <br />
01 6b 49 84 0f 8c 53 bc <br />
1e b6 8a 38 2e 97 b1 48 <br />
2e ca d7 b1 48 a6 90 9a<br />
5c b2 e0 ea dd fb 84 cc <br />
f9 74 44 64 f8 2e 16 0b <br />
fa 9b 8b 64 f9 d4 c0 3f <br />
99 9b 86 43 f6 56 b4 12 <br />
a3 <br />
ac OP_CHECKSIG<br />
<br />
00 00 00 00 locktime<br />
01 00 00 00 hash_code_type (added on)<br />
<br />
result =<br />
01 00 00 00 01 c9 97 a5 e5 6e 10 41 02 fa 20 9c 6a 85 2d d9 06 60 a2 0b 2d 9c 35 <br />
24 23 ed ce 25 85 7f cd 37 04 00 00 00 00 43 41 04 11 db 93 e1 dc db 8a 01 6b 49 <br />
84 0f 8c 53 bc 1e b6 8a 38 2e 97 b1 48 2e ca d7 b1 48 a6 90 9a 5c b2 e0 ea dd fb <br />
84 cc f9 74 44 64 f8 2e 16 0b fa 9b 8b 64 f9 d4 c0 3f 99 9b 86 43 f6 56 b4 12 a3 <br />
ac ff ff ff ff 02 00 ca 9a 3b 00 00 00 00 43 41 04 ae 1a 62 fe 09 c5 f5 1b 13 90 <br />
5f 07 f0 6b 99 a2 f7 15 9b 22 25 f3 74 cd 37 8d 71 30 2f a2 84 14 e7 aa b3 73 97 <br />
f5 54 a7 df 5f 14 2c 21 c1 b7 30 3b 8a 06 26 f1 ba de d5 c7 2a 70 4f 7e 6c d8 4c <br />
ac 00 28 6b ee 00 00 00 00 43 41 04 11 db 93 e1 dc db 8a 01 6b 49 84 0f 8c 53 bc <br />
1e b6 8a 38 2e 97 b1 48 2e ca d7 b1 48 a6 90 9a 5c b2 e0 ea dd fb 84 cc f9 74 44 <br />
64 f8 2e 16 0b fa 9b 8b 64 f9 d4 c0 3f 99 9b 86 43 f6 56 b4 12 a3 ac 00 00 00 00 <br />
01 00 00 00 <br />
</pre><br />
<br />
To understand where that raw dump has come from, it may be useful to examine tests/ec-key.cpp in [https://gitorious.org/libbitcoin/libbitcoin libbitcoin],<br />
<br />
[https://gitorious.org/libbitcoin/libbitcoin libbitcoin] has a unit test under tests/ec-key.cpp (make ec-key && ./bin/tests/ec-key). There is also a working OP_CHECKSIG implementation in src/script.cpp under script::op_checksig(). See also the unit test: tests/script-test.cpp<br />
<br />
<source lang="cpp"><br />
#include <iostream><br />
#include <iomanip><br />
#include <bitcoin/util/serializer.hpp><br />
#include <bitcoin/util/elliptic_curve_key.hpp><br />
#include <bitcoin/util/sha256.hpp><br />
#include <bitcoin/util/assert.hpp><br />
#include <bitcoin/util/logger.hpp><br />
#include <bitcoin/types.hpp><br />
#include <openssl/ecdsa.h><br />
#include <openssl/obj_mac.h><br />
using libbitcoin::elliptic_curve_key;<br />
using libbitcoin::serializer;<br />
using libbitcoin::hash_digest;<br />
using libbitcoin::data_chunk;<br />
using libbitcoin::log_info;<br />
using libbitcoin::log_fatal;<br />
<br />
int main()<br />
{<br />
serializer ss;<br />
// blk number 170, tx 1, input 0<br />
// version = 1<br />
ss.write_4_bytes(1);<br />
// 1 inputs<br />
ss.write_var_uint(1);<br />
<br />
// input 0<br />
// prevout hash<br />
ss.write_hash(hash_digest{0x04, 0x37, 0xcd, 0x7f, 0x85, 0x25, 0xce, 0xed, 0x23, 0x24, 0x35, 0x9c, 0x2d, 0x0b, 0xa2, 0x60, 0x06, 0xd9, 0x2d, 0x85, 0x6a, 0x9c, 0x20, 0xfa, 0x02, 0x41, 0x10, 0x6e, 0xe5, 0xa5, 0x97, 0xc9});<br />
// prevout index <br />
ss.write_4_bytes(0);<br />
<br />
// input script after running OP_CHECKSIG for this tx is a single<br />
// OP_CHECKSIG opcode<br />
data_chunk raw_data;<br />
raw_data = {0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3};<br />
data_chunk raw_script;<br />
raw_script = data_chunk();<br />
raw_script.push_back(raw_data.size());<br />
libbitcoin::extend_data(raw_script, raw_data);<br />
raw_script.push_back(172);<br />
ss.write_var_uint(raw_script.size());<br />
ss.write_data(raw_script);<br />
// sequence<br />
ss.write_4_bytes(0xffffffff);<br />
<br />
// 2 outputs for this tx<br />
ss.write_var_uint(2);<br />
<br />
// output 0<br />
ss.write_8_bytes(1000000000);<br />
// script for output 0<br />
raw_data = {0x04, 0xae, 0x1a, 0x62, 0xfe, 0x09, 0xc5, 0xf5, 0x1b, 0x13, 0x90, 0x5f, 0x07, 0xf0, 0x6b, 0x99, 0xa2, 0xf7, 0x15, 0x9b, 0x22, 0x25, 0xf3, 0x74, 0xcd, 0x37, 0x8d, 0x71, 0x30, 0x2f, 0xa2, 0x84, 0x14, 0xe7, 0xaa, 0xb3, 0x73, 0x97, 0xf5, 0x54, 0xa7, 0xdf, 0x5f, 0x14, 0x2c, 0x21, 0xc1, 0xb7, 0x30, 0x3b, 0x8a, 0x06, 0x26, 0xf1, 0xba, 0xde, 0xd5, 0xc7, 0x2a, 0x70, 0x4f, 0x7e, 0x6c, 0xd8, 0x4c};<br />
// when data < 75, we can just write it's length as a single byte ('special'<br />
// opcodes)<br />
raw_script = data_chunk();<br />
raw_script.push_back(raw_data.size());<br />
libbitcoin::extend_data(raw_script, raw_data);<br />
// OP_CHECKSIG<br />
raw_script.push_back(172);<br />
// now actually write the script<br />
ss.write_var_uint(raw_script.size());<br />
ss.write_data(raw_script);<br />
<br />
// output 0<br />
ss.write_8_bytes(4000000000);<br />
// script for output 0<br />
raw_data = {0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3};<br />
// when data < 75, we can just write it's length as a single byte ('special'<br />
raw_script.push_back(raw_data.size());<br />
libbitcoin::extend_data(raw_script, raw_data);<br />
// OP_CHECKSIG<br />
raw_script.push_back(172);<br />
// now actually write the script<br />
ss.write_var_uint(raw_script.size());<br />
ss.write_data(raw_script);<br />
<br />
// End of 2 outputs<br />
<br />
// locktime<br />
ss.write_4_bytes(0);<br />
<br />
// write hash_type_code<br />
ss.write_4_bytes(1);<br />
<br />
// Dump hex to screen<br />
log_info() << "hashing:";<br />
{<br />
auto log_obj = log_info();<br />
log_obj << std::hex;<br />
for (int val: ss.get_data())<br />
log_obj << std::setfill('0') << std::setw(2) << val << ' ';<br />
}<br />
log_info();<br />
<br />
data_chunk raw_tx = {0x01, 0x00, 0x00, 0x00, 0x01, 0xc9, 0x97, 0xa5, 0xe5, 0x6e, 0x10, 0x41, 0x02, 0xfa, 0x20, 0x9c, 0x6a, 0x85, 0x2d, 0xd9, 0x06, 0x60, 0xa2, 0x0b, 0x2d, 0x9c, 0x35, 0x24, 0x23, 0xed, 0xce, 0x25, 0x85, 0x7f, 0xcd, 0x37, 0x04, 0x00, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3, 0xac, 0xff, 0xff, 0xff, 0xff, 0x02, 0x00, 0xca, 0x9a, 0x3b, 0x00, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, 0xae, 0x1a, 0x62, 0xfe, 0x09, 0xc5, 0xf5, 0x1b, 0x13, 0x90, 0x5f, 0x07, 0xf0, 0x6b, 0x99, 0xa2, 0xf7, 0x15, 0x9b, 0x22, 0x25, 0xf3, 0x74, 0xcd, 0x37, 0x8d, 0x71, 0x30, 0x2f, 0xa2, 0x84, 0x14, 0xe7, 0xaa, 0xb3, 0x73, 0x97, 0xf5, 0x54, 0xa7, 0xdf, 0x5f, 0x14, 0x2c, 0x21, 0xc1, 0xb7, 0x30, 0x3b, 0x8a, 0x06, 0x26, 0xf1, 0xba, 0xde, 0xd5, 0xc7, 0x2a, 0x70, 0x4f, 0x7e, 0x6c, 0xd8, 0x4c, 0xac, 0x00, 0x28, 0x6b, 0xee, 0x00, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3, 0xac, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00};<br />
BITCOIN_ASSERT(raw_tx == ss.get_data());<br />
<br />
hash_digest tx_hash = libbitcoin::generate_sha256_hash(ss.get_data());<br />
<br />
data_chunk pubkey{0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3};<br />
// Leave out last byte since that's the hash_type_code (SIGHASH_ALL in this<br />
// case)<br />
data_chunk signature{0x30, 0x44, 0x02, 0x20, 0x4e, 0x45, 0xe1, 0x69, 0x32, 0xb8, 0xaf, 0x51, 0x49, 0x61, 0xa1, 0xd3, 0xa1, 0xa2, 0x5f, 0xdf, 0x3f, 0x4f, 0x77, 0x32, 0xe9, 0xd6, 0x24, 0xc6, 0xc6, 0x15, 0x48, 0xab, 0x5f, 0xb8, 0xcd, 0x41, 0x02, 0x20, 0x18, 0x15, 0x22, 0xec, 0x8e, 0xca, 0x07, 0xde, 0x48, 0x60, 0xa4, 0xac, 0xdd, 0x12, 0x90, 0x9d, 0x83, 0x1c, 0xc5, 0x6c, 0xbb, 0xac, 0x46, 0x22, 0x08, 0x22, 0x21, 0xa8, 0x76, 0x8d, 0x1d, 0x09};<br />
BITCOIN_ASSERT(signature.size() == 70);<br />
<br />
elliptic_curve_key key;<br />
if (!key.set_public_key(pubkey))<br />
{<br />
log_fatal() << "unable to set EC public key";<br />
return -1;<br />
}<br />
<br />
log_info() << "checksig returns: " << (key.verify(tx_hash, signature) ? "true" : "false");<br />
return 0;<br />
}<br />
<br />
</source><br />
<br />
==References==<br />
<references/><br />
<br />
[[Category:Technical]]<br />
[[Category:Developer]]</div>
Smtp
https://en.bitcoin.it/w/index.php?title=OP_CHECKSIG&diff=34927
OP CHECKSIG
2013-01-11T22:57:45Z
<p>Smtp: /* Final signature check */</p>
<hr />
<div>OP_CHECKSIG is [[Script|script]] opcode used to verify that the signature for a tx input is valid. OP_CHECKSIG expects two values to be on the stack, these are, in order of stack depth, the public key and the signature of the script. These two values are normally obtained by running the scriptSig script of the transaction input we are attempting to validate. After the scriptSig script is run the script is deleted but the stack is left as is, and then then scriptPubKey script from the previous transaction output that is now being spent is run, generally concluding in an OP_CHECKSIG. <br />
<br />
The standard scriptPubKey checks that the public key (actually a hash of) is a particular value, and that OP_CHECKSIG passes.<br />
<br />
For normal transaction inputs if the creator of the current transaction can successfully create a ScriptSig signature that uses the right public key for the ScriptPubKey of the transaction output they are attempting to spend, that transaction input is considered valid. <br />
<br />
== Parameters ==<br />
<br />
In addition to the script code itself and the stack parameters, to operate OP_CHECKSIG needs to know the current transaction and the index of current transaction input.<br />
<br />
== How it works ==<br />
Firstly always this (the default) procedure is applied:<br />
[[File:Bitcoin_OpCheckSig_InDetail.png|thumb|right|Signature verification process of the default procedure]]<br />
# the public key and the signature are popped from the stack, in that order. If the hash-type value is 0, then it is replaced by the last_byte of the signature. Then the last byte of the signature is always deleted.<br />
# A new subscript is created from the instruction from the most recently parsed OP_CODESEPARATOR (last one in script) to the end of the script. If there is no OP_CODESEPARATOR the entire script becomes the subscript (hereby referred to as subScript)<br />
# The sig is deleted from subScript.<br />
# All OP_CODESEPARATORS are removed from subScript<br />
# The hashtype is removed from the last byte of the sig and stored<br />
# A copy is made of the current transaction (hereby referred to txCopy)<br />
# The scripts for all transaction inputs in txCopy are set to empty scripts (exactly 1 byte 0x00)<br />
# The script for the current transaction input in txCopy is set to subScript (lead in by its length as a var-integer encoded!)<br />
<br />
Now depending on the hashtype various things can happen to txCopy, these will be discussed individually.<br />
<br />
'''Hashtype Values (from script.h):'''<br />
{|class="wikitable"<br />
! Name !! Value<br />
|-<br />
| SIGHASH_ALL || 0x00000001<br />
|-<br />
| SIGHASH_NONE || 0x00000002<br />
|-<br />
| SIGHASH_SINGLE || 0x00000003<br />
|-<br />
| SIGHASH_ANYONECANPAY || 0x00000080<br />
|}<br />
<br />
<ol><br />
<li> If (hashtype&31) = SIGHASH_NONE then apply the SIGHASH_NONE-procedure<br />
<li> If (hashtype&31) = SIGHASH_SINGLE then apply the SIGHASH_SINGLE-procedure<br />
<li> If hashtype & SIGHASH_ANYONECANPAY then apply the SIGHASH_ANYONECANPAY-procedure<br />
</ol><br />
Hence, hashtype SIGHASH_ANYONECANPAY may be applied also after any other hashtype-procedure<ref>[http://sourceforge.net/projects/bitcoin/files/Bitcoin/bitcoin-0.7.1/bitcoin-0.7.1-linux.tar.gz file src/src/script.cpp in bitcoin-0.7.1]</ref>. Besides the four listed hashtypes only a hashtype of value 0 appears a few types in the (main) block chain (and is handled like SIGHASH_ALL).<br />
<br />
=== Hashtype SIGHASH_ALL (default) ===<br />
<br />
No special further handling occurs in the default case. Think of this as "sign '''all''' of the outputs." Which is already done by the default procedure.<br />
<br />
=== Procedure for Hashtype SIGHASH_NONE ===<br />
<br />
# The output of txCopy is set to a vector of zero size.<br />
# All other inputs aside from the current input in txCopy have their nSequence index set to zero<br />
<br />
Think of this as "sign '''none''' of the outputs-- I don't care where the bitcoins go."<br />
<br />
=== Procedure for Hashtype SIGHASH_SINGLE ===<br />
<br />
# The output of txCopy is resized to the size of the current input index+1<br />
# All other txCopy outputs aside from the output that is the same as the current input index are set to a blank script and a value of (long) -1;<br />
# All other txCopy inputs aside from the current input are set to have an nSequence index of zero<br />
<br />
Think of this as "sign '''one''' of the outputs-- I don't care where the other outputs go."<br />
<br />
=== Procedure for Hashtype SIGHASH_ANYONECANPAY ===<br />
<br />
# The txCopy input vector is resized to a length of one<br />
# The current input is set as the first and only member of this vector<br />
<br />
Think of this as "Let other people add inputs to this transaction, I don't care where the rest of the bitcoins come from."<br />
<br />
===Final signature check===<br />
<br />
An array of bytes is constructed from the serialized txCopy appended by four bytes for the hash type. This array is sha256 hashed twice, then the public key is used to check the supplied signature against the hash.<br />
The secp256k1 elliptic curve is used for the verification with the given public key.<br />
<br />
== Return values ==<br />
<br />
OP_CHECKSIG will push true to the stack if the check passed, false otherwise.<br />
OP_CHECKSIG_VERIFY leaves nothing on the stack but will cause the script eval to fail immediately if the check does not pass.<br />
<br />
== Code samples and raw dumps ==<br />
<br />
Taking the first transaction in Bitcoin which is in block number 170, we would get after serialising the transaction but before we hash+sign (or verify) it:<br />
<br />
* http://blockexplorer.com/block/00000000d1145790a8694403d4063f323d499e655c83426834d4ce2f8dd4a2ee<br />
* http://blockexplorer.com/tx/f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16<br />
<br />
See also [https://gitorious.org/libbitcoin/libbitcoin libbitcoin] for code samples.<br />
<br />
<pre><br />
01 00 00 00 version<br />
01 number of inputs (var_uint)<br />
<br />
input 0:<br />
c9 97 a5 e5 6e 10 41 02 input address hash<br />
fa 20 9c 6a 85 2d d9 06 <br />
60 a2 0b 2d 9c 35 24 23 <br />
ed ce 25 85 7f cd 37 04<br />
00 00 00 00 input index<br />
<br />
48 size of script (var_uint)<br />
47 push 71 bytes to stack<br />
30 44 02 20 4e 45 e1 69<br />
32 b8 af 51 49 61 a1 d3<br />
a1 a2 5f df 3f 4f 77 32<br />
e9 d6 24 c6 c6 15 48 ab<br />
5f b8 cd 41 02 20 18 15<br />
22 ec 8e ca 07 de 48 60<br />
a4 ac dd 12 90 9d 83 1c<br />
c5 6c bb ac 46 22 08 22<br />
21 a8 76 8d 1d 09 01<br />
ff ff ff ff sequence<br />
<br />
02 number of outputs (var_uint)<br />
<br />
output 0:<br />
00 ca 9a 3b 00 00 00 00 amount = 10.00000000<br />
43 size of script (var_uint)<br />
script for output 0:<br />
41 push 65 bytes to stack<br />
04 ae 1a 62 fe 09 c5 f5 <br />
1b 13 90 5f 07 f0 6b 99 <br />
a2 f7 15 9b 22 25 f3 74 <br />
cd 37 8d 71 30 2f a2 84 <br />
14 e7 aa b3 73 97 f5 54 <br />
a7 df 5f 14 2c 21 c1 b7 <br />
30 3b 8a 06 26 f1 ba de <br />
d5 c7 2a 70 4f 7e 6c d8 <br />
4c <br />
ac OP_CHECKSIG<br />
<br />
output 1:<br />
00 28 6b ee 00 00 00 00 amount = 40.00000000<br />
43 size of script (var_uint)<br />
script for output 1:<br />
41 push 65 bytes to stack<br />
04 11 db 93 e1 dc db 8a <br />
01 6b 49 84 0f 8c 53 bc <br />
1e b6 8a 38 2e 97 b1 48 <br />
2e ca d7 b1 48 a6 90 9a<br />
5c b2 e0 ea dd fb 84 cc <br />
f9 74 44 64 f8 2e 16 0b <br />
fa 9b 8b 64 f9 d4 c0 3f <br />
99 9b 86 43 f6 56 b4 12 <br />
a3 <br />
ac OP_CHECKSIG<br />
<br />
00 00 00 00 locktime<br />
01 00 00 00 hash_code_type (added on)<br />
<br />
result =<br />
01 00 00 00 01 c9 97 a5 e5 6e 10 41 02 fa 20 9c 6a 85 2d d9 06 60 a2 0b 2d 9c 35 <br />
24 23 ed ce 25 85 7f cd 37 04 00 00 00 00 43 41 04 11 db 93 e1 dc db 8a 01 6b 49 <br />
84 0f 8c 53 bc 1e b6 8a 38 2e 97 b1 48 2e ca d7 b1 48 a6 90 9a 5c b2 e0 ea dd fb <br />
84 cc f9 74 44 64 f8 2e 16 0b fa 9b 8b 64 f9 d4 c0 3f 99 9b 86 43 f6 56 b4 12 a3 <br />
ac ff ff ff ff 02 00 ca 9a 3b 00 00 00 00 43 41 04 ae 1a 62 fe 09 c5 f5 1b 13 90 <br />
5f 07 f0 6b 99 a2 f7 15 9b 22 25 f3 74 cd 37 8d 71 30 2f a2 84 14 e7 aa b3 73 97 <br />
f5 54 a7 df 5f 14 2c 21 c1 b7 30 3b 8a 06 26 f1 ba de d5 c7 2a 70 4f 7e 6c d8 4c <br />
ac 00 28 6b ee 00 00 00 00 43 41 04 11 db 93 e1 dc db 8a 01 6b 49 84 0f 8c 53 bc <br />
1e b6 8a 38 2e 97 b1 48 2e ca d7 b1 48 a6 90 9a 5c b2 e0 ea dd fb 84 cc f9 74 44 <br />
64 f8 2e 16 0b fa 9b 8b 64 f9 d4 c0 3f 99 9b 86 43 f6 56 b4 12 a3 ac 00 00 00 00 <br />
01 00 00 00 <br />
</pre><br />
<br />
To understand where that raw dump has come from, it may be useful to examine tests/ec-key.cpp in [https://gitorious.org/libbitcoin/libbitcoin libbitcoin],<br />
<br />
[https://gitorious.org/libbitcoin/libbitcoin libbitcoin] has a unit test under tests/ec-key.cpp (make ec-key && ./bin/tests/ec-key). There is also a working OP_CHECKSIG implementation in src/script.cpp under script::op_checksig(). See also the unit test: tests/script-test.cpp<br />
<br />
<source lang="cpp"><br />
#include <iostream><br />
#include <iomanip><br />
#include <bitcoin/util/serializer.hpp><br />
#include <bitcoin/util/elliptic_curve_key.hpp><br />
#include <bitcoin/util/sha256.hpp><br />
#include <bitcoin/util/assert.hpp><br />
#include <bitcoin/util/logger.hpp><br />
#include <bitcoin/types.hpp><br />
#include <openssl/ecdsa.h><br />
#include <openssl/obj_mac.h><br />
using libbitcoin::elliptic_curve_key;<br />
using libbitcoin::serializer;<br />
using libbitcoin::hash_digest;<br />
using libbitcoin::data_chunk;<br />
using libbitcoin::log_info;<br />
using libbitcoin::log_fatal;<br />
<br />
int main()<br />
{<br />
serializer ss;<br />
// blk number 170, tx 1, input 0<br />
// version = 1<br />
ss.write_4_bytes(1);<br />
// 1 inputs<br />
ss.write_var_uint(1);<br />
<br />
// input 0<br />
// prevout hash<br />
ss.write_hash(hash_digest{0x04, 0x37, 0xcd, 0x7f, 0x85, 0x25, 0xce, 0xed, 0x23, 0x24, 0x35, 0x9c, 0x2d, 0x0b, 0xa2, 0x60, 0x06, 0xd9, 0x2d, 0x85, 0x6a, 0x9c, 0x20, 0xfa, 0x02, 0x41, 0x10, 0x6e, 0xe5, 0xa5, 0x97, 0xc9});<br />
// prevout index <br />
ss.write_4_bytes(0);<br />
<br />
// input script after running OP_CHECKSIG for this tx is a single<br />
// OP_CHECKSIG opcode<br />
data_chunk raw_data;<br />
raw_data = {0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3};<br />
data_chunk raw_script;<br />
raw_script = data_chunk();<br />
raw_script.push_back(raw_data.size());<br />
libbitcoin::extend_data(raw_script, raw_data);<br />
raw_script.push_back(172);<br />
ss.write_var_uint(raw_script.size());<br />
ss.write_data(raw_script);<br />
// sequence<br />
ss.write_4_bytes(0xffffffff);<br />
<br />
// 2 outputs for this tx<br />
ss.write_var_uint(2);<br />
<br />
// output 0<br />
ss.write_8_bytes(1000000000);<br />
// script for output 0<br />
raw_data = {0x04, 0xae, 0x1a, 0x62, 0xfe, 0x09, 0xc5, 0xf5, 0x1b, 0x13, 0x90, 0x5f, 0x07, 0xf0, 0x6b, 0x99, 0xa2, 0xf7, 0x15, 0x9b, 0x22, 0x25, 0xf3, 0x74, 0xcd, 0x37, 0x8d, 0x71, 0x30, 0x2f, 0xa2, 0x84, 0x14, 0xe7, 0xaa, 0xb3, 0x73, 0x97, 0xf5, 0x54, 0xa7, 0xdf, 0x5f, 0x14, 0x2c, 0x21, 0xc1, 0xb7, 0x30, 0x3b, 0x8a, 0x06, 0x26, 0xf1, 0xba, 0xde, 0xd5, 0xc7, 0x2a, 0x70, 0x4f, 0x7e, 0x6c, 0xd8, 0x4c};<br />
// when data < 75, we can just write it's length as a single byte ('special'<br />
// opcodes)<br />
raw_script = data_chunk();<br />
raw_script.push_back(raw_data.size());<br />
libbitcoin::extend_data(raw_script, raw_data);<br />
// OP_CHECKSIG<br />
raw_script.push_back(172);<br />
// now actually write the script<br />
ss.write_var_uint(raw_script.size());<br />
ss.write_data(raw_script);<br />
<br />
// output 0<br />
ss.write_8_bytes(4000000000);<br />
// script for output 0<br />
raw_data = {0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3};<br />
// when data < 75, we can just write it's length as a single byte ('special'<br />
raw_script.push_back(raw_data.size());<br />
libbitcoin::extend_data(raw_script, raw_data);<br />
// OP_CHECKSIG<br />
raw_script.push_back(172);<br />
// now actually write the script<br />
ss.write_var_uint(raw_script.size());<br />
ss.write_data(raw_script);<br />
<br />
// End of 2 outputs<br />
<br />
// locktime<br />
ss.write_4_bytes(0);<br />
<br />
// write hash_type_code<br />
ss.write_4_bytes(1);<br />
<br />
// Dump hex to screen<br />
log_info() << "hashing:";<br />
{<br />
auto log_obj = log_info();<br />
log_obj << std::hex;<br />
for (int val: ss.get_data())<br />
log_obj << std::setfill('0') << std::setw(2) << val << ' ';<br />
}<br />
log_info();<br />
<br />
data_chunk raw_tx = {0x01, 0x00, 0x00, 0x00, 0x01, 0xc9, 0x97, 0xa5, 0xe5, 0x6e, 0x10, 0x41, 0x02, 0xfa, 0x20, 0x9c, 0x6a, 0x85, 0x2d, 0xd9, 0x06, 0x60, 0xa2, 0x0b, 0x2d, 0x9c, 0x35, 0x24, 0x23, 0xed, 0xce, 0x25, 0x85, 0x7f, 0xcd, 0x37, 0x04, 0x00, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3, 0xac, 0xff, 0xff, 0xff, 0xff, 0x02, 0x00, 0xca, 0x9a, 0x3b, 0x00, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, 0xae, 0x1a, 0x62, 0xfe, 0x09, 0xc5, 0xf5, 0x1b, 0x13, 0x90, 0x5f, 0x07, 0xf0, 0x6b, 0x99, 0xa2, 0xf7, 0x15, 0x9b, 0x22, 0x25, 0xf3, 0x74, 0xcd, 0x37, 0x8d, 0x71, 0x30, 0x2f, 0xa2, 0x84, 0x14, 0xe7, 0xaa, 0xb3, 0x73, 0x97, 0xf5, 0x54, 0xa7, 0xdf, 0x5f, 0x14, 0x2c, 0x21, 0xc1, 0xb7, 0x30, 0x3b, 0x8a, 0x06, 0x26, 0xf1, 0xba, 0xde, 0xd5, 0xc7, 0x2a, 0x70, 0x4f, 0x7e, 0x6c, 0xd8, 0x4c, 0xac, 0x00, 0x28, 0x6b, 0xee, 0x00, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3, 0xac, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00};<br />
BITCOIN_ASSERT(raw_tx == ss.get_data());<br />
<br />
hash_digest tx_hash = libbitcoin::generate_sha256_hash(ss.get_data());<br />
<br />
data_chunk pubkey{0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3};<br />
// Leave out last byte since that's the hash_type_code (SIGHASH_ALL in this<br />
// case)<br />
data_chunk signature{0x30, 0x44, 0x02, 0x20, 0x4e, 0x45, 0xe1, 0x69, 0x32, 0xb8, 0xaf, 0x51, 0x49, 0x61, 0xa1, 0xd3, 0xa1, 0xa2, 0x5f, 0xdf, 0x3f, 0x4f, 0x77, 0x32, 0xe9, 0xd6, 0x24, 0xc6, 0xc6, 0x15, 0x48, 0xab, 0x5f, 0xb8, 0xcd, 0x41, 0x02, 0x20, 0x18, 0x15, 0x22, 0xec, 0x8e, 0xca, 0x07, 0xde, 0x48, 0x60, 0xa4, 0xac, 0xdd, 0x12, 0x90, 0x9d, 0x83, 0x1c, 0xc5, 0x6c, 0xbb, 0xac, 0x46, 0x22, 0x08, 0x22, 0x21, 0xa8, 0x76, 0x8d, 0x1d, 0x09};<br />
BITCOIN_ASSERT(signature.size() == 70);<br />
<br />
elliptic_curve_key key;<br />
if (!key.set_public_key(pubkey))<br />
{<br />
log_fatal() << "unable to set EC public key";<br />
return -1;<br />
}<br />
<br />
log_info() << "checksig returns: " << (key.verify(tx_hash, signature) ? "true" : "false");<br />
return 0;<br />
}<br />
<br />
</source><br />
<br />
==References==<br />
<references/><br />
<br />
[[Category:Technical]]<br />
[[Category:Developer]]</div>
Smtp
https://en.bitcoin.it/w/index.php?title=Script&diff=34921
Script
2013-01-11T17:36:41Z
<p>Smtp: /* Arithmetic */</p>
<hr />
<div>Bitcoin uses a scripting system for [[transactions]]. [[Wikipedia:FORTH|Forth]]-like, Script is simple, stack-based, and processed from left to right. It is purposefully not Turing-complete, with no loops.<br />
<br />
A script is essentially a list of instructions recorded with each transaction that describe how the next person wanting to spend the Bitcoins being transferred can gain access to them.<br />
<br />
Scripts are big-endian and their sequences of bytes is interpreted as a sequence of opcodes with operands. Only opcodes with byte values less than 0x4f have additional operands.<br />
<br />
== Scripts and Bitcoin transactions ==<br />
The script for a typical Bitcoin transfer to destination Bitcoin address D simply encumbers future spending of the bitcoins with two things: the spender must provide<br />
# a public key that, when hashed, yields destination address D embedded in the script, and<br />
# a signature to show evidence of the private key corresponding to the public key just provided.<br />
<br />
Scripting provides the flexibility to change the parameters of what's needed to spend transferred Bitcoins. For example, the scripting system could be used to require two private keys, or a combination of several, or even no keys at all.<br />
<br />
A transaction is valid if nothing in the combined script triggers failure and the top stack item exists and is true (non-zero). The party who originally ''stored'' the Bitcoins now being spent, dictates the script operations that will occur ''last'' in order to release them for use in another transaction. The party wanting to spend them must provide the input(s) to the previously recorded script that results in those operations occurring last leaving behind true (non-zero) on the stack.<br><br />
Only the very first transaction in each bitcoin block has no input script (the entry there is called "coinbase"), because the Bitcoins created with the block are created from hot air and not released by a previous recorded txout-script.<br />
<br />
== Stack ==<br />
<br />
The stacks hold byte vectors (there is the (main) stack and an alternative stack). Byte vectors are interpreted as little-endian variable-length integers with the most significant bit determining the sign of the integer. Thus 0x81 represents -1. 0x80 is another representation of zero (so called negative 0). Byte vectors are interpreted as Booleans where False is represented by any representation of zero, and True is represented by any representation of non-zero.<br />
<br />
== Opcode overview ==<br />
<br />
For each opcode is given: its nemonic without the leading OP_, its hexadecimal byte value, the number of stack items needed (poped) during execution, a semicolon and the number of stack items which has been pushed (after execution). A * after the needed stack items indicates that further bytes from the script following the current opcode are needed. A # indicates that items on the alternative stack are poped/pushed. A @ indicates that further (global) data from the transaction is needed. A / indicates alternatives of a value. <br/><br />
Different colors indicate different semantic execution groups of opcodes:<br />
{| style="background:none; font-size:100%; padding:0; border-collapse:collapse; text-align:center; line-height:2em;" border="0" align="center" <br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | copy a fixed number of bytes but at most 75 onto stack<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | copy bytes onto stack which number is given by a 1, 2 or 4 byte value.<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | copy 1 specific byte onto stack<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | undefined opcode<br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | a pseudo-opcode, unassigned for scripts<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | NOP or opcode is part of a IF-flow-control construction<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00ff00;" | (stack conditionally) invalidation of the script this opcode is part of<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | stack item is moved between main stack and alternate stack<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | stack item(s) is/are moved, copied or deleted<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0;" | byte vectors are appended or divided or their size is determined<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff;" | byte vectors are interpreted bit-position-independently<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | byte vectors are interpreted and processed as signed integers<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | a hash value is computed or a signature checked<br />
|}<br />
<p><br />
===Opcode byte-matrix===<br />
The opcode value 0x00 with nemonic OP_FALSE is also named OP_0 and the opcode value 0x51 with nemonic OP_1 as also named OP_TRUE.<br />
{| style="background:none; font-size:100%; padding:0; border-collapse:collapse; text-align:center; line-height:2em;" border="0" align="center" <br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" |_FALSE<br/> 0x00 <br/> 0 ; 1(0) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x01<br/> 0 *; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x02<br/> 0 *; 1(2)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x03<br/> 0 *; 1(3)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x04<br/> 0 *; 1(4)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x04<br/> 0 *; 1(5)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x06<br/> 0 *; 1(6)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x07<br/> 0 *; 1(7)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x08<br/> 0 *; 1(8)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x09<br/> 0 *; 1(9)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0a<br/> 0 *; 1(10)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0b<br/> 0 *; 1(11)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0c<br/> 0 *; 1(12)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0d<br/> 0 *; 1(13)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0e<br/> 0 *; 1(14)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0f<br/> 0 *; 1(15)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x10 <br/> 0 *; 1(16) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x11 <br/> 0 *; 1(17)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x12 <br/> 0 *; 1(18)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x13 <br/> 0 *; 1(19)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x14 <br/> 0 *; 1(20)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x15 <br/> 0 *; 1(21)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x16 <br/> 0 *; 1(22)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x17 <br/> 0 *; 1(23)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x18 <br/> 0 *; 1(24)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x19 <br/> 0 *; 1(25)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1a <br/> 0 *; 1(26)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1b <br/> 0 *; 1(27)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1c <br/> 0 *; 1(28)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1d <br/> 0 *; 1(29)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1e <br/> 0 *; 1(30)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1f <br/> 0 *; 1(31)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x20 <br/> 0 *; 1(32) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x21 <br/> 0 *; 1(33)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x22 <br/> 0 *; 1(34)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x23 <br/> 0 *; 1(35)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x24 <br/> 0 *; 1(36)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x25 <br/> 0 *; 1(37)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x26 <br/> 0 *; 1(38)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x27 <br/> 0 *; 1(39)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x28 <br/> 0 *; 1(40)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x29 <br/> 0 *; 1(41)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2a <br/> 0 *; 1(42)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2b <br/> 0 *; 1(43)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2c <br/> 0 *; 1(44)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2d <br/> 0 *; 1(45)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2e <br/> 0 *; 1(46)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2f <br/> 0 *; 1(47)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x30 <br/> 0 *; 1(48) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x31 <br/> 0 *; 1(49)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x32 <br/> 0 *; 1(50)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x33 <br/> 0 *; 1(51)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x34 <br/> 0 *; 1(52)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x35 <br/> 0 *; 1(53)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x36 <br/> 0 *; 1(54)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x37 <br/> 0 *; 1(55)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x38 <br/> 0 *; 1(56)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x39 <br/> 0 *; 1(57)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3a <br/> 0 *; 1(58)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3b <br/> 0 *; 1(59)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3c <br/> 0 *; 1(60)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3d <br/> 0 *; 1(61)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3e <br/> 0 *; 1(62)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3f <br/> 0 *; 1(63)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x40 <br/> 0 *; 1(64) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x41 <br/> 0 *; 1(65)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x42 <br/> 0 *; 1(66)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x43 <br/> 0 *; 1(67)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x44 <br/> 0 *; 1(68)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x45 <br/> 0 *; 1(69)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x46 <br/> 0 *; 1(70)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x47 <br/> 0 *; 1(71)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x48 <br/> 0 *; 1(72)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x49 <br/> 0 *; 1(73)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x4a <br/> 0 *; 1(74)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x4b <br/> 0 *; 1(75)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA1 <br/> 0x4c <br/> 0 *; 1(0 - 255)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA2 <br/> 0x4d <br/> 0 *; 1(0 - 2^16-1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA4 <br/> 0x4e <br/> 0 *; 1(0 - 2^32-1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _1NEGATE <br/> 0x4f <br/> 0 ; 1(1)<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED <br/> 0x50 <br/> <br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _1 <br/> 0x51 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _2 <br/> 0x52 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _3 <br/> 0x53 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _4 <br/> 0x54 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _5 <br/> 0x55 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _6 <br/> 0x56 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _7 <br/> 0x57 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _8 <br/> 0x58 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _9 <br/> 0x59 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _10 <br/> 0x5a <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _11 <br/> 0x5b <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _12 <br/> 0x5c <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _13 <br/> 0x5d <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _14 <br/> 0x5e <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _15 <br/> 0x5f <br/> 0 ; 1(1)<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _16 <br/> 0x60 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP <br/> 0x61 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VER <br/> 0x62 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _IF <br/> 0x63 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOTIF <br/> 0x64 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VERIF <br/> 0x65 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VERNOTIF <br/> 0x66 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _ELSE <br/> 0x67 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _ENDIF <br/> 0x68 <br/> 0 ; 0<br />
| style="border:3px solid #808080; background-color:#00ff00;" | _VERIFY <br/> 0x69 <br/> 1 ; 0/1<br />
| style="border:3px solid #808080; background-color:#00ff00;" | _RETURN <br/> 0x6a <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | _TOALTSTACK <br/> 0x6b <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | _FROMALTSTACK <br/> 0x6c <br/> 0 #; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2DROP <br/> 0x6d <br/> 2 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2DUP <br/> 0x6e <br/> 2 ; 4<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _3DUP <br/> 0x6f <br/> 3 ; 6<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2OVER <br/> 0x70 <br/> 4 ; 6<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2ROT <br/> 0x71 <br/> 6 ; 6<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2SWAP <br/> 0x72 <br/> 4 ; 4<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _IFDUP <br/> 0x73 <br/> 1 ; 1/2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DEPTH <br/> 0x74 <br/> 0 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DROP <br/> 0x75 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DUP <br/> 0x76 <br/> 1 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _NIP <br/> 0x77 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _OVER <br/> 0x78 <br/> 2 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _PICK <br/> 0x79 <br/> 1+n+1 ; n+2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _ROLL <br/> 0x7a <br/> 1+n+1 ; n+1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _ROT <br/> 0x7b <br/> 3 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _SWAP <br/> 0x7c <br/> 2 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _TUCK <br/> 0x7d <br/> 2 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _CAT <br/> 0x7e <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _SUBSTR <br/> 0x7f <br/> 3 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _LEFT <br/> 0x80 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _RIGHT <br/> 0x81 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0;" | _SIZE <br/> 0x82 <br/> 1 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _INVERT <br/> 0x83 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _AND <br/> 0x84 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _OR <br/> 0x85 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _XOR <br/> 0x86 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff;" | _EQUAL <br/> 0x87 <br/> 2 ; 1<br />
| style="border:3px solid #808080; background-color:#c080ff;" | _EQUALVERIFY <br/> 0x88 <br/> 2 ; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED1 <br/> 0x89 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED2 <br/> 0x8a <br/><br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _1ADD <br/> 0x8b <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _1SUB <br/> 0x8c <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _2MUL <br/> 0x8d <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _2DIV <br/> 0x8e <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NEGATE <br/> 0x8f <br/> 1 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _ABS <br/> 0x90 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NOT <br/> 0x91 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _0NOTEQUAL <br/> 0x92 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _ADD <br/> 0x93 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _SUB <br/> 0x94 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _MUL <br/> 0x95 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _DIV <br/> 0x96 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _MOD <br/> 0x97 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _LSHIFT <br/> 0x98 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _RSHIFT <br/> 0x99 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _BOOLAND <br/> 0x9a <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _BOOLOR <br/> 0x9b <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NUMEQUAL <br/> 0x9c <br/> 2 ; 1<br />
| style="border:3px solid #808080; background-color:#8080ff;" | _NUMEQUALVERIFY <br/> 0x9d <br/> 2 ; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NUMNOTEQUAL <br/> 0x9e <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _LESSTHAN <br/> 0x9f <br/> 2 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _GREATERTHAN <br/> 0xa0 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _LESSTHANOREQUAL <br/> 0xa1 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _GREATERTHANOREQUAL <br/> 0xa2 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _MIN <br/> 0xa3 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _MAX <br/> 0xa4 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _WITHIN <br/> 0xa5 <br/> 3 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _RIPEMD160 <br/> 0xa6 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _SHA1 <br/> 0xa7 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _SHA256 <br/> 0xa8 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _HASH160 <br/> 0xa9 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _HASH256 <br/> 0xaa <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CODESEPARATOR <br/> 0xab <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CHECKSIG <br/> 0xac <br/> 2 @; 1<br />
| style="border:3px solid #808080; background-color:#a0d0ff;" | _CHECKSIGVERIFY <br/> 0xad <br/> 2 @; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CHECKMULTISIG <br/> 0xae <br/> 2n+2 @; 1<br />
| style="border:3px solid #808080; background-color:#a0d0ff;" | _CHECKMULTISIGVERIFY <br/> 0xaf <br/> 2n+2 @; 0/1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP1 <br/> 0xb0 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP2 <br/> 0xb1 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP3 <br/> 0xb2 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP4 <br/> 0xb3 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP5 <br/> 0xb4 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP6 <br/> 0xb5 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP7 <br/> 0xb6 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP8 <br/> 0xb7 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP9 <br/> 0xb8 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP10 <br/> 0xb9 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xba <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbe <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xca <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xce <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xda <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xde <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xea <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xeb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xec <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xed <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xee <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xef <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xfa <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _SMALLINTEGER <br/> 0xfb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEYS <br/> 0xfc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEYHASH <br/> 0xfd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEY <br/> 0xfe <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _INVALIDOPCODE <br/> 0xff <br/><br />
|}<br><br />
Except later pseudo-opcode changes, the definition of OP_NOP1 - OP_NOP10 and the change of the evaluation of OP_RETURN (did no invalidation previously) which both occured in bitcoin version 0.3.6 in July 2010 were the last changes regarding opcodes <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.2.0/bitcoin-0.2.0-linux.tar.gz file src/srcipt.cpp in bitcoin-0.2.0]</ref> <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.3.3/bitcoin-0.3.3-linux.tar.gz file src/srcipt.cpp in bitcoin-0.3.3]</ref> <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.3.6/bitcoin-0.3.6-linux.tar.gz file src/srcipt.cpp in bitcoin-0.3.6]</ref>.<br />
<br />
== Opcode descriptions ==<br />
It follows for each opcode less than decimal 185 (hexa 0xba) a description for its usage. The columns entitled ''nemonic'', ''decimal'' and ''Hex'' should be evident. The column ''input'' gives the needed items of the stack (and the alternate stack) and the column ''output'' indicates the resulting items on the stack (and the alternate stack). '''Stack-top is always the right most item.''' The naming of the entries in these two columns is chosen to reflect their interpretation. ''x'', ''x0'', ''x1'', ... means arbitrary or no interpretation, ''i0'', ''i1'' and ''i2'' a signed integer value, ''n'',''index'',''size'' and ''depth'' non-negative (unsigned) integer values, ''Boolean'' as either a true or false.<br><br />
<br />
Some of the more complicated opcodes are disabled since version 0.3.10 out of concern that the client might have a bug in the current implementation due to the historically not as 2-complement interpretations of the byte vectors as numerical values (the most significant byte holds the sign of the byte vectors). Furthermore how some of theses opcodes should work precisely is disputable.<br />
<br />
=== Push data from instruction onto stack ===<br />
<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_FALSE, OP_0<br />
|0<br />
|0x00<br />
|Nothing<br />
|Empty string<br />
|A byte vector of length 0 is pushed onto the stack. (Thus, it is not a no-op!)<br />
|-<br />
|(no official nemonics)<br />
|1 - 75<br />
|0x01 - 0x4b<br />
|(operand)<br />
|x<br />
|The next <opcode>-many bytes are to be pushed onto the stack.<br />
|-<br />
|OP_PUSHDATA1<br />
|76<br />
|0x4c<br />
|(operands)<br />
|x<br />
|The next byte contains the number of bytes to be pushed onto the stack which follow this byte.<br />
|-<br />
|OP_PUSHDATA2<br />
|77<br />
|0x4d<br />
|(operands)<br />
|x<br />
|The next two bytes contain the number of bytes to be pushed onto the stack which follow theses 2 bytes.<br />
|-<br />
|OP_PUSHDATA4<br />
|78<br />
|0x4e<br />
|(operands)<br />
|x<br />
|The next four bytes contain the number of bytes to be pushed onto the stack which follow theses 4 bytes.<br />
|-<br />
|OP_1NEGATE<br />
|79<br />
|0x4f<br />
|Nothing<br />
| -1<br />
|The byte with value -1 is pushed onto the stack.<br />
|-<br />
|OP_1, OP_TRUE<br />
|81<br />
|0x51<br />
|Nothing<br />
|1<br />
|The byte with value 1 is pushed onto the stack.<br />
|-<br />
|OP_2 - OP_16<br />
|82 - 96<br />
|0x52 - 0x60<br />
|Nothing<br />
|2-16<br />
|The byte with value <opcode>-80 (thus, one of 2 - 16) is pushed onto the stack.<br />
|}<br />
<br />
=== Flow control ===<br />
<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_NOP<br />
|97<br />
|0x61<br />
|Nothing<br />
|Nothing<br />
|Does nothing.<br />
|-<br />
|OP_IF<br />
|99<br />
|0x63<br />
|Boolean<br />
|Nothing<br />
|If the top stack value is not 0, the statements are executed. The top stack value is removed. Lead in a logcial ''<value> then [statements] [else [statements]] endif'' expression<br />
|-<br />
|OP_NOTIF<br />
|100<br />
|0x64<br />
|Boolean<br />
|Nothing<br />
|If the top stack value is 0, the statements are executed. The top stack value is removed. Lead in a logcial ''<value> then [statements] [else [statements]] endif'' expression <br />
|-<br />
|OP_ELSE<br />
|103<br />
|0x67<br />
|Nothing<br />
|Nothing<br />
|If the preceeding OP_IF or OP_NOTIF or OP_ELSE was not executed then these statements are and if the preceding OP_IF or OP_NOTIF or OP_ELSE was executed then these statements are not. <br />
|-<br />
|OP_ENDIF<br />
|104<br />
|0x68<br />
|Nothing<br />
|Nothing<br />
|Ends a logcial ''If <value> then [statements] [else [statements]] '' expression<br />
|-<br />
|OP_VERIFY<br />
|105<br />
|0x69<br />
|Boolean<br />
|Nothing / False<br />
|If top stack value is not true then marks transaction as '''invalid''' . A value true is removed, but false is not.<br />
|-<br />
|OP_RETURN<br />
|106<br />
|0x6a<br />
|Nothing<br />
|Nothing<br />
|Marks transaction as '''invalid'''. <br />
|}<br />
<br />
===Stack item organization===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_TOALTSTACK<br />
|107<br />
|0x6b<br />
|x1 (alt)<br />
|(alt x1)<br />
|Puts the input onto the top of the alt stack. Removes it from the (main) stack.<br />
|-<br />
|OP_FROMALTSTACK<br />
|108<br />
|0x6c<br />
|(alt x1)<br />
|x1 (alt)<br />
|Puts the input onto the top of the (main) stack. Removes it from the alt stack.<br />
|-<br />
|OP_2DROP<br />
|109<br />
|0x6d<br />
|x2 x1<br />
|Nothing<br />
|Removes the top two stack items.<br />
|-<br />
|OP_2DUP<br />
|110<br />
|0x6e<br />
|x2 x1<br />
|x2 x1 x2 x1<br />
|Duplicates the top two stack items.<br />
|-<br />
|OP_3DUP<br />
|111<br />
|0x6f<br />
|x3 x2 x1<br />
|x3 x2 x1 x3 x2 x1<br />
|Duplicates the top three stack items.<br />
|-<br />
|OP_2OVER<br />
|112<br />
|0x70<br />
|x4 x3 x2 x1<br />
|x4 x3 x2 x1 x4 x3<br />
|Copies the pair of items two spaces back in the stack to the front.<br />
|-<br />
|OP_2ROT<br />
|113<br />
|0x71<br />
|x6 x5 x4 x3 x2 x1<br />
|x4 x3 x2 x1 x6 x5<br />
|The fifth and sixth items back are moved to the top of the stack. Twotimes left rotate.<br />
|-<br />
|OP_2SWAP<br />
|114<br />
|0x72<br />
|x4 x3 x2 x1<br />
|x2 x1 x4 x3<br />
|Swaps the top two pairs of stack items.<br />
|-<br />
|OP_IFDUP<br />
|115<br />
|0x73<br />
|x1<br />
|x1 / x1 x1<br />
|If the top stack value is not 0, duplicate it.<br />
|-<br />
|OP_DEPTH<br />
|116<br />
|0x74<br />
|Nothing<br />
|depth<br />
|Puts the number of stack items onto the stack as one little-endian coded byte-vector<br />
|-<br />
|OP_DROP<br />
|117<br />
|0x75<br />
|x1<br />
|Nothing<br />
|Removes the top stack item.<br />
|-<br />
|OP_DUP<br />
|118<br />
|0x76<br />
|x1<br />
|x1 x1<br />
|Duplicates the top stack item.<br />
|-<br />
|OP_NIP<br />
|119<br />
|0x77<br />
|x2 x1<br />
|x1<br />
|Removes the second-to-top stack item.<br />
|-<br />
|OP_OVER<br />
|120<br />
|0x78<br />
|x2 x1<br />
|x2 x1 x2<br />
|Copies the second-to-top stack item to the top.<br />
|-<br />
|OP_PICK<br />
|121<br />
|0x79<br />
|xn ... x2 x1 x0 <n><br />
|xn ... x2 x1 x0 xn<br />
|<n> is removed and the item ''n'' back in the stack is copied to the top.<br />
|-<br />
|OP_ROLL<br />
|122<br />
|0x7a<br />
|xn ... x2 x1 x0 <n><br />
|... x2 x1 x0 xn<br />
|<n> is removed and the item ''n'' back in the stack is moved to the top.<br />
|-<br />
|OP_ROT<br />
|123<br />
|0x7b<br />
|x3 x2 x1<br />
|x2 x1 x3<br />
|The top three items on the stack are rotated to the left.<br />
|-<br />
|OP_SWAP<br />
|124<br />
|0x7c<br />
|x2 x1<br />
|x1 x2<br />
|The top two items on the stack are swapped resp. rotated.<br />
|-<br />
|OP_TUCK<br />
|125<br />
|0x7d<br />
|x2 x1<br />
|x1 x2 x1<br />
|The item at the top of the stack is copied and inserted before the second-to-top item.<br />
|}<br />
<br />
=== Splice ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_CAT<br />
|126<br />
|0x7e<br />
|x2 x1<br />
|out<br />
|Appends stack-top item at second-to top item. Concatenates two strings resp. byte vectors. ''Currently disabled.''<br />
|-<br />
|OP_SUBSTR<br />
|127<br />
|0x7f<br />
|x3 index size<br />
|out<br />
|Returns the section started at position <index> and of length <size> of a string resp. byte vector. ''Currently disabled.''<br />
|-<br />
|OP_LEFT<br />
|128<br />
|0x80<br />
|x2 index<br />
|out<br />
|Keeps only characters left of the specified point in second-to top item. ''Currently disabled.''<br />
|-<br />
|OP_RIGHT<br />
|129<br />
|0x81<br />
|x2 index<br />
|out<br />
|Keeps only characters right of the specified point in second-to top item. ''Currently disabled.''<br />
|-<br />
|OP_SIZE<br />
|130<br />
|0x82<br />
|x1<br />
|x1 size<br />
|Returns the length of the input string resp. byte vector resp. top-stack item.<br />
|}<br />
<br />
=== Bitwise logic ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_INVERT<br />
|131<br />
|0x83<br />
|x1<br />
|x0<br />
|Flips all of the bits in the input. ''Currently disabled.''<br />
|-<br />
|OP_AND<br />
|132<br />
|0x84<br />
|x2 x1<br />
|x0<br />
|Boolean ''and'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_OR<br />
|133<br />
|0x85<br />
|x2 x1<br />
|x0<br />
|Boolean ''or'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_XOR<br />
|134<br />
|0x86<br />
|x2 x1<br />
|x0<br />
|Boolean ''exclusive or'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_EQUAL<br />
|135<br />
|0x87<br />
|x2 x1<br />
|Boolean<br />
|Returns 1 if the inputs have the same length and are byte-wise equal, 0 otherwise.<br />
|-<br />
|OP_EQUALVERIFY<br />
|136<br />
|0x88<br />
|x2 x1<br />
|Nothing / false<br />
|Same as OP_EQUAL, but runs OP_VERIFY afterward.<br />
|}<br />
<br />
=== Arithmetic ===<br />
<br />
Since version 0.3.10 the implemented arithmetic opcodes are limited to maximal 4 byte vectors (|value| < 2^31), in version 0.3.6 up to 0.3.8 they were limited to 258 byte vectors and prior to 0.3.6 unrestricted <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.3.8/bitcoin-0.3.8-linux.tar.gz file src/srcipt.cpp in bitcoin-0.3.8]</ref><ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.3.10/bitcoin-0.3.10-linux.tar.gz file src/srcipt.cpp in bitcoin-0.3.10]</ref>.<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_1ADD<br />
|139<br />
|0x8b<br />
|i1<br />
|i0<br />
|1 is added to the input.<br />
|-<br />
|OP_1SUB<br />
|140<br />
|0x8c<br />
|i1<br />
|i0<br />
|1 is subtracted from the input.<br />
|-<br />
|OP_2MUL<br />
|141<br />
|0x8d<br />
|i1<br />
|i0<br />
|The input is multiplied by 2. ''Currently disabled.''<br />
|-<br />
|OP_2DIV<br />
|142<br />
|0x8e<br />
|i1<br />
|i0<br />
|The input is divided by 2 (round down). ''Currently disabled.''<br />
|-<br />
|OP_NEGATE<br />
|143<br />
|0x8f<br />
|i1<br />
|i0<br />
|The sign of the input is flipped. Numerically the value is multiplied by -1<br />
|-<br />
|OP_ABS<br />
|144<br />
|0x90<br />
|i1<br />
|i0<br />
|The input is negative, its sign is flipped.<br />
|-<br />
|OP_NOT<br />
|145<br />
|0x91<br />
|i1<br />
|Boolean<br />
|If the input is 0 or 1, it is flipped. Otherwise the output will be 0. Test whether its value equals 0<br />
|-<br />
|OP_0NOTEQUAL<br />
|146<br />
|0x92<br />
|i1<br />
|Boolean<br />
|Returns 0 if the input is 0. 1 otherwise. Test whether its value is unequal 0<br />
|-<br />
|OP_ADD<br />
|147<br />
|0x93<br />
|i2 i1<br />
|i0<br />
|stack-top i1 is added to i2.<br />
|-<br />
|OP_SUB<br />
|148<br />
|0x94<br />
|i2 i1<br />
|i0<br />
|stack-top i1 is subtracted from i2.<br />
|-<br />
|OP_MUL<br />
|149<br />
|0x95<br />
|i2 i1<br />
|i0<br />
|i2 is multiplied with stack-top i1. ''Currently disabled.''<br />
|-<br />
|OP_DIV<br />
|150<br />
|0x96<br />
|i2 i1<br />
|i0<br />
|i2 is divided by stack-top i1 (divisor should be not 0). ''Currently disabled.''<br />
|-<br />
|OP_MOD<br />
|151<br />
|0x97<br />
|i2 i1<br />
|i0<br />
|Returns the remainder after dividing i2 by stack-top i1 (divisor should be not 0). ''Currently disabled.''<br />
|-<br />
|OP_LSHIFT<br />
|152<br />
|0x98<br />
|i2 i1<br />
|i0<br />
|Shifts i2 left by i1 bits, preserving sign of i2 (i1 >= 0). ''Currently disabled.''<br />
|-<br />
|OP_RSHIFT<br />
|153<br />
|0x99<br />
|i2 i1<br />
|i0<br />
|Shifts i2 right by i1 bits, preserving sign of i2 (i1 >= 0). ''Currently disabled.''<br />
|-<br />
|OP_BOOLAND<br />
|154<br />
|0x9a<br />
|i2 i1<br />
|Boolean<br />
|If both i2 and i1 are not 0, the output is 1. Otherwise 0.<br />
|-<br />
|OP_BOOLOR<br />
|155<br />
|0x9b<br />
|i2 i1<br />
|Boolean<br />
|If i2 or i1 is not 0, the output is 1. Otherwise 0.<br />
|-<br />
|OP_NUMEQUAL<br />
|156<br />
|0x9c<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 and i1 are numerically equal, 0 otherwise.<br />
|-<br />
|OP_NUMEQUALVERIFY<br />
|157<br />
|0x9d<br />
|i2 i1<br />
|Nothing / False<br />
|Same as OP_NUMEQUAL, but runs OP_VERIFY afterward.<br />
|-<br />
|OP_NUMNOTEQUAL<br />
|158<br />
|0x9e<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 and i1 are numerically not equal, 0 otherwise.<br />
|-<br />
|OP_LESSTHAN<br />
|159<br />
|0x9f<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is less than stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_GREATERTHAN<br />
|160<br />
|0xa0<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is greater than stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_LESSTHANOREQUAL<br />
|161<br />
|0xa1<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is less than or equal to stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_GREATERTHANOREQUAL<br />
|162<br />
|0xa2<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is greater than or equal to stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_MIN<br />
|163<br />
|0xa3<br />
|i2 i1<br />
|i2 / i1<br />
|Returns the smaller of i2 and i1.<br />
|-<br />
|OP_MAX<br />
|164<br />
|0xa4<br />
|i2 i1<br />
|i2 / i1<br />
|Returns the larger of i2 and i1.<br />
|-<br />
|OP_WITHIN<br />
|165<br />
|0xa5<br />
|i3 i2 i1<br />
|Boolean<br />
|Returns 1 if i3 >= i2 and i3 < i1, 0 otherwise. Thus if i2 > i1 returns always 0.<br />
|}<br />
<br />
=== Crypto ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_RIPEMD160<br />
|166<br />
|0xa6<br />
|x<br />
|hash20<br />
|The input is hashed using RIPEMD-160.<br />
|-<br />
|OP_SHA1<br />
|167<br />
|0xa7<br />
|x<br />
|hash20<br />
|The input is hashed using SHA-1.<br />
|-<br />
|OP_SHA256<br />
|168<br />
|0xa8<br />
|x<br />
|hash32<br />
|The input is hashed using SHA-256.<br />
|-<br />
|OP_HASH160<br />
|169<br />
|0xa9<br />
|x<br />
|hash20<br />
|The input is hashed twice: first with SHA-256 and then with RIPEMD-160.<br />
|-<br />
|OP_HASH256<br />
|170<br />
|0xaa<br />
|x<br />
|hash32<br />
|The input is hashed two times with SHA-256.<br />
|-<br />
|OP_CODESEPARATOR<br />
|171<br />
|0xab<br />
|Nothing<br />
|Nothing<br />
|All of the signature checking opcodes will only match signatures to the data after the most recently-executed OP_CODESEPARATOR.<br />
|-<br />
|[[OP_CHECKSIG]]<br />
|172<br />
|0xac<br />
|sig pubkey<br />
|Boolean<br />
|The entire transaction's outputs, inputs, and script (from the most recently-executed OP_CODESEPARATOR to the end) are hashed. The signature used by OP_CHECKSIG must be a valid signature for a further, extern specified hash and the given public key. If it is, 1 is returned, 0 otherwise.<br />
|-<br />
|OP_CHECKSIGVERIFY<br />
|173<br />
|0xad<br />
|sig pubkey<br />
|Nothing / False<br />
|Same as OP_CHECKSIG, but OP_VERIFY is executed afterward.<br />
|-<br />
|OP_CHECKMULTISIG<br />
|174<br />
|0xae<br />
|sig1 sig2 ... <number of signatures> pub1 pub2 <number of public keys><br />
|Boolean<br />
|For each signature and public key pair, OP_CHECKSIG is executed. If more public keys than signatures are listed, some key/sig pairs can fail. All signatures need to match a public key. If all signatures are valid, 1 is returned, 0 otherwise. Due to a bug, one extra unused value is removed from the stack.<br />
|-<br />
|OP_CHECKMULTISIGVERIFY<br />
|175<br />
|0xaf<br />
|sig1 sig2 ... <number of signatures> pub1 pub2 ... <number of public keys><br />
|Nothing / False<br />
|Same as OP_CHECKMULTISIG, but OP_VERIFY is executed afterward.<br />
|}<br />
<br />
=== Expansion opcodes ===<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_NOP1-OP_NOP10<br />
|176-185<br />
|0xb0-0xb9<br />
|The opcode has no effect.<br />
|}<br />
<br />
=== Version opcodes ===<br />
Version opcodes are disabled since bitcoin 0.2.0 and should not be used (maybe reassigned in the future).<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_VER<br />
|98<br />
|0x62<br />
|Script evalution is triggered invalid (Formerly pushed the bitcoin-serialize version onto stack).<br />
|-<br />
|OP_VERIF<br />
|101<br />
|0x65<br />
|Script evalution is triggered invalid (Formerly top stack item was popped and =< compared to present version)<br />
|-<br />
|OP_VERNOTIF<br />
|102<br />
|0x66<br />
|Script evalution is triggered invalid (Formerly top stack item was popped and > compared to present version)<br />
|}<br />
<br />
=== Reserved opcodes ===<br />
Each opcode not assigned (currently also every opcode value > 185) is also reserved. Using any unassigned opcode triggers the script evaluation to be invalid.<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_RESERVED<br />
|80<br />
|0x50<br />
|Script evalution is triggered invalid-<br />
|-<br />
|OP_RESERVED1<br />
|137<br />
|0x89<br />
|Script evalution is triggered invalid.<br />
|-<br />
|OP_RESERVED2<br />
|138<br />
|0x8a<br />
|Script evalution is triggered invalid.<br />
|}<br />
<br />
===Pseudo-opcodes===<br />
These nemonics are used internally for assisting with transaction matching. They are invalid if used in actual scripts.<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_PUBKEYHASH<br />
|253<br />
|0xfd<br />
|Represents a public key hashed with OP_HASH160.<br />
|-<br />
|OP_PUBKEY<br />
|254<br />
|0xfe<br />
|Represents a public key compatible with OP_CHECKSIG.<br />
|-<br />
|OP_INVALIDOPCODE<br />
|255<br />
|0xff<br />
|Matches any opcode that is not yet assigned.<br />
|}<br />
<br />
==Scripts in bitcoin transactions==<br />
It follows a list of important (most occuring) scripts to see opcodes "at work". Keep in mind that all constants actually use the data-pushing instructions above. At start of a (transaction input) script evaluation, the stack is always empty. Currently less than 0.01 % of all txout-scripts / scriptPubKeys in the main block chain are not of the following two standard scripts.<br />
<br />
===Standard transaction to bitcoin address===<br />
<br />
scriptPubKey: OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG<br />
scriptSig: <sig> <pubKey><br />
<br />
To demonstrate how scripts look on the wire, here is a raw scriptPubKey:<br />
<pre> 76 A9 14<br />
OP_DUP OP_HASH160 Bytes to push<br />
<br />
89 AB CD EF AB BA AB BA AB BA AB BA AB BA AB BA AB BA AB BA 88 AC<br />
Data to push OP_EQUALVERIFY OP_CHECKSIG</pre><br />
<br />
Note: scriptSig is in the input of the spending transaction and scriptPubKey is in the output of the previously storing transaction, i.e. its "available bitcoins".<br />
<br />
Here is how each instruction is processed:<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
| <sig> <pubKey> OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| scriptSig and scriptPubKey are combined.<br />
|-<br />
|<sig> <pubKey><br />
| OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| Constants are added to the stack.<br />
|-<br />
|<sig> <pubKey> <pubKey><br />
| OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| Top stack item is duplicated.<br />
|-<br />
|<sig> <pubKey> <pubHashA><br />
|<pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG<br />
| Top stack item is hashed.<br />
|-<br />
|<sig> <pubKey> <pubHashA> <pubKeyHash><br />
|OP_EQUALVERIFY OP_CHECKSIG<br />
| Constant added.<br />
|-<br />
|<sig> <pubKey><br />
|OP_CHECKSIG<br />
| Equality is checked between the top two stack items.<br />
|-<br />
|true<br />
|Empty.<br />
|Signature is checked for top two stack items.<br />
|}<br />
<br />
===Transaction to IP address (and generation transaction)===<br />
<br />
scriptPubKey: <pubKey> OP_CHECKSIG<br />
scriptSig: <sig><br />
<br />
Checking process:<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
|<sig> <pubKey> OP_CHECKSIG<br />
|scriptSig and scriptPubKey are combined.<br />
|-<br />
|<sig> <pubKey><br />
| OP_CHECKSIG<br />
|Constants are added to the stack.<br />
|-<br />
|true<br />
|Empty.<br />
|Signature is checked for top two stack items.<br />
|}<br />
<br />
In the case of a '''coin generation transaction''' (the first transaction of each block), there is no scriptSig, resp. its code ("coinbase") is completly ignored for the transaction. Only the scriptPubKey is used.<br />
<br />
===Transaction with a message===<br />
<br />
It's possible to add arbitrary data to any transaction by just adding some data along with OP_DROP. <br />
scriptPubKey: <message> OP_DROP <pubKey> OP_CHECKSIG<br />
scriptSig: <sig><br />
<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
|<sig> <message> OP_DROP <pubKey> OP_CHECKSIG<br />
|<br />
|-<br />
|<sig><br />
|<message> OP_DROP <pubKey> OP_CHECKSIG<br />
|scriptSig added to the stack.<br />
|-<br />
|<sig> <message><br />
|OP_DROP <pubKey> OP_CHECKSIG<br />
|The message has been put.<br />
|-<br />
|<sig><br />
|<pubKey> OP_CHECKSIG<br />
|Top stack item has been removed.<br />
|-<br />
|<sig> <pubKey><br />
|OP_CHECKSIG<br />
|Checking signature against the public key.<br />
|-<br />
|true<br />
|Empty.<br />
|Stack holds the value of signature check now.<br />
|}<br />
<br />
===Examples of non standard transaction on Testnet===<br />
<br />
These two links below show a non standard transaction. It just prepends the hex of "bob" and the operation OP_DROP<br />
which just removes it. As you can see they can be spent as normal.<br />
<br />
Input non-std transaction:<br />
http://blockexplorer.com/testnet/t/6ttfeb55B1<br />
<br />
Spent by:<br />
http://blockexplorer.com/testnet/t/AFdRB1CHS3<br />
<br />
==Script validation==<br />
A script evaluation is considered invalid, if any of these conditions meets:<br><br />
<ul><br />
<li>the total size of the script exceeds (currently) 10000 bytes<br />
<li>there are more than (currently) 201 opcodes of opcode value > 0x60 in the script<br />
<li>each instruction is (currently) limited to maximal 520 bytes. This effects only the opcodes OP_PUSHDATA2 and OP_PUSHDATA4<br />
<li>the executed opcode of the script has insufficient input (from stack, from script or from anywhere)<br />
<li>the opcode is not defined (for execution) - indicated by white or light gray background color in the table<br />
<li>the opcode is disabled (currently 15 opcodes) - indicated by white font color in the opcode overview matrix<br />
<li>stack overflow occurs during execution of the opcode (currently the number of items on the stack and on the alternate stack is limited to 1000)<br />
<li>the opcodes OP_VERIF and OP_NOTVERIF invalidate a script which contains this opcode (even if this opcode is not executed!)<br />
<li>the opcodes OP_ELSE or OP_ENDIF has no matching OP_IF<br><br />
<li>the script execution has been finished but there is (at least) an unmatched OP_IF<br><br />
<li>the opcodes OP_VERIFY, OP_EQUALVERIFY, OP_NUMEQUALVERIFY, OP_CHECKSIGVERIFY and OP_CHECKMULTISIGVERIFY invalidate the script if the stack-top item is false<br />
<li>the execution of OP_RETURN<br />
<!--li>alt stack overflow occurs (only possible during execution of OP_TOALTSTACK)--><br />
<li>the numerical value of the top-stack item is negative or greater than the number of items - 2 on the stack if OP_PICK or OP_ROLL shall be executed<br />
<li>When interpreting a stack-item of an arithmetic opcode as a signed integer its value is >= 2^31 or <= -2^31.<br />
<li>an item used as public key or signature for each of the opcodes OP_CHECKSIG, OP_CHECKSIGVERIFY, OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY can be neither a public key or signature (for the given hash)<br />
<li>the number of signature items or the number of public key items on the stack is negative for OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY<br />
<li>there or more signatures items than public key items on the stack for OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY<br />
<li>there are (currently) more than 20 public key items on the stack for OP_CHECKMULTISIG or CHECKMULTISIGVERIFY<br />
<li>the sum of opcodes > 0x60 and the number of public keys in all executed OP_CHECKMULTISIG or CHECKMULTISIGVERIFY exceeds (currently) 201<br />
<li>the script execution has been finished and the stack is empty or the top-stack item is false (numerical value 0)<br />
</ul><br />
else the script evaluation is considered to be valid.<ref>[http://sourceforge.net/projects/bitcoin/files/Bitcoin/bitcoin-0.7.1/bitcoin-0.7.1-linux.tar.gz file src/src/script.cpp in bitcoin-0.7.1]</ref><br />
'''If invalidation of a script is triggered then the script is immediately finished.''' These arbitrary looking limitations of 10000, 201, 520, 1000 and 20 might be increased in the future -- they serve to prevent strong slow down of the evaluation of a script while not restricting its practical usage really.<br />
<br />
==Withdrawn and drafted opcodes==<br />
<br />
<ul><br />
<li> byte value 0x89 OP_NOTEQUAL defined in pre-0.1.0 bitcoin versions. Since 0.1.0 removed because of security concerns. <br />
<li> byte value 0xb1 [[BIP 0012 | OP_EVAL]] withdraw - poll was triggered but insufficient support. <br />
<li> byte value 0xb2 [[BIP 0017 | OP_CHECKHASHVERIFY]] withdraw - poll was triggered but insufficient support.<br />
</ul><br />
<br />
==See Also==<br />
* [[Transactions]]<br />
* [[Contracts]]<br />
<br />
==References==<br />
<references/><br />
<ul><br />
<li>[http://www.zorinaq.com/pub/bitcoin-0.1.0.tgz file src/script.cpp in bitcoin-0.1.0]</li><br />
</ul><br />
[[Category:Technical]]<br />
[[Category:Vocabulary]]</div>
Smtp
https://en.bitcoin.it/w/index.php?title=Script&diff=34920
Script
2013-01-11T17:27:57Z
<p>Smtp: /* Script validation */</p>
<hr />
<div>Bitcoin uses a scripting system for [[transactions]]. [[Wikipedia:FORTH|Forth]]-like, Script is simple, stack-based, and processed from left to right. It is purposefully not Turing-complete, with no loops.<br />
<br />
A script is essentially a list of instructions recorded with each transaction that describe how the next person wanting to spend the Bitcoins being transferred can gain access to them.<br />
<br />
Scripts are big-endian and their sequences of bytes is interpreted as a sequence of opcodes with operands. Only opcodes with byte values less than 0x4f have additional operands.<br />
<br />
== Scripts and Bitcoin transactions ==<br />
The script for a typical Bitcoin transfer to destination Bitcoin address D simply encumbers future spending of the bitcoins with two things: the spender must provide<br />
# a public key that, when hashed, yields destination address D embedded in the script, and<br />
# a signature to show evidence of the private key corresponding to the public key just provided.<br />
<br />
Scripting provides the flexibility to change the parameters of what's needed to spend transferred Bitcoins. For example, the scripting system could be used to require two private keys, or a combination of several, or even no keys at all.<br />
<br />
A transaction is valid if nothing in the combined script triggers failure and the top stack item exists and is true (non-zero). The party who originally ''stored'' the Bitcoins now being spent, dictates the script operations that will occur ''last'' in order to release them for use in another transaction. The party wanting to spend them must provide the input(s) to the previously recorded script that results in those operations occurring last leaving behind true (non-zero) on the stack.<br><br />
Only the very first transaction in each bitcoin block has no input script (the entry there is called "coinbase"), because the Bitcoins created with the block are created from hot air and not released by a previous recorded txout-script.<br />
<br />
== Stack ==<br />
<br />
The stacks hold byte vectors (there is the (main) stack and an alternative stack). Byte vectors are interpreted as little-endian variable-length integers with the most significant bit determining the sign of the integer. Thus 0x81 represents -1. 0x80 is another representation of zero (so called negative 0). Byte vectors are interpreted as Booleans where False is represented by any representation of zero, and True is represented by any representation of non-zero.<br />
<br />
== Opcode overview ==<br />
<br />
For each opcode is given: its nemonic without the leading OP_, its hexadecimal byte value, the number of stack items needed (poped) during execution, a semicolon and the number of stack items which has been pushed (after execution). A * after the needed stack items indicates that further bytes from the script following the current opcode are needed. A # indicates that items on the alternative stack are poped/pushed. A @ indicates that further (global) data from the transaction is needed. A / indicates alternatives of a value. <br/><br />
Different colors indicate different semantic execution groups of opcodes:<br />
{| style="background:none; font-size:100%; padding:0; border-collapse:collapse; text-align:center; line-height:2em;" border="0" align="center" <br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | copy a fixed number of bytes but at most 75 onto stack<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | copy bytes onto stack which number is given by a 1, 2 or 4 byte value.<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | copy 1 specific byte onto stack<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | undefined opcode<br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | a pseudo-opcode, unassigned for scripts<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | NOP or opcode is part of a IF-flow-control construction<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00ff00;" | (stack conditionally) invalidation of the script this opcode is part of<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | stack item is moved between main stack and alternate stack<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | stack item(s) is/are moved, copied or deleted<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0;" | byte vectors are appended or divided or their size is determined<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff;" | byte vectors are interpreted bit-position-independently<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | byte vectors are interpreted and processed as signed integers<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | a hash value is computed or a signature checked<br />
|}<br />
<p><br />
===Opcode byte-matrix===<br />
The opcode value 0x00 with nemonic OP_FALSE is also named OP_0 and the opcode value 0x51 with nemonic OP_1 as also named OP_TRUE.<br />
{| style="background:none; font-size:100%; padding:0; border-collapse:collapse; text-align:center; line-height:2em;" border="0" align="center" <br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" |_FALSE<br/> 0x00 <br/> 0 ; 1(0) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x01<br/> 0 *; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x02<br/> 0 *; 1(2)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x03<br/> 0 *; 1(3)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x04<br/> 0 *; 1(4)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x04<br/> 0 *; 1(5)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x06<br/> 0 *; 1(6)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x07<br/> 0 *; 1(7)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x08<br/> 0 *; 1(8)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x09<br/> 0 *; 1(9)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0a<br/> 0 *; 1(10)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0b<br/> 0 *; 1(11)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0c<br/> 0 *; 1(12)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0d<br/> 0 *; 1(13)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0e<br/> 0 *; 1(14)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0f<br/> 0 *; 1(15)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x10 <br/> 0 *; 1(16) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x11 <br/> 0 *; 1(17)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x12 <br/> 0 *; 1(18)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x13 <br/> 0 *; 1(19)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x14 <br/> 0 *; 1(20)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x15 <br/> 0 *; 1(21)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x16 <br/> 0 *; 1(22)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x17 <br/> 0 *; 1(23)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x18 <br/> 0 *; 1(24)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x19 <br/> 0 *; 1(25)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1a <br/> 0 *; 1(26)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1b <br/> 0 *; 1(27)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1c <br/> 0 *; 1(28)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1d <br/> 0 *; 1(29)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1e <br/> 0 *; 1(30)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1f <br/> 0 *; 1(31)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x20 <br/> 0 *; 1(32) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x21 <br/> 0 *; 1(33)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x22 <br/> 0 *; 1(34)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x23 <br/> 0 *; 1(35)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x24 <br/> 0 *; 1(36)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x25 <br/> 0 *; 1(37)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x26 <br/> 0 *; 1(38)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x27 <br/> 0 *; 1(39)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x28 <br/> 0 *; 1(40)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x29 <br/> 0 *; 1(41)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2a <br/> 0 *; 1(42)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2b <br/> 0 *; 1(43)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2c <br/> 0 *; 1(44)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2d <br/> 0 *; 1(45)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2e <br/> 0 *; 1(46)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2f <br/> 0 *; 1(47)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x30 <br/> 0 *; 1(48) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x31 <br/> 0 *; 1(49)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x32 <br/> 0 *; 1(50)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x33 <br/> 0 *; 1(51)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x34 <br/> 0 *; 1(52)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x35 <br/> 0 *; 1(53)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x36 <br/> 0 *; 1(54)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x37 <br/> 0 *; 1(55)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x38 <br/> 0 *; 1(56)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x39 <br/> 0 *; 1(57)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3a <br/> 0 *; 1(58)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3b <br/> 0 *; 1(59)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3c <br/> 0 *; 1(60)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3d <br/> 0 *; 1(61)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3e <br/> 0 *; 1(62)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3f <br/> 0 *; 1(63)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x40 <br/> 0 *; 1(64) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x41 <br/> 0 *; 1(65)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x42 <br/> 0 *; 1(66)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x43 <br/> 0 *; 1(67)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x44 <br/> 0 *; 1(68)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x45 <br/> 0 *; 1(69)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x46 <br/> 0 *; 1(70)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x47 <br/> 0 *; 1(71)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x48 <br/> 0 *; 1(72)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x49 <br/> 0 *; 1(73)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x4a <br/> 0 *; 1(74)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x4b <br/> 0 *; 1(75)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA1 <br/> 0x4c <br/> 0 *; 1(0 - 255)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA2 <br/> 0x4d <br/> 0 *; 1(0 - 2^16-1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA4 <br/> 0x4e <br/> 0 *; 1(0 - 2^32-1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _1NEGATE <br/> 0x4f <br/> 0 ; 1(1)<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED <br/> 0x50 <br/> <br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _1 <br/> 0x51 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _2 <br/> 0x52 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _3 <br/> 0x53 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _4 <br/> 0x54 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _5 <br/> 0x55 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _6 <br/> 0x56 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _7 <br/> 0x57 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _8 <br/> 0x58 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _9 <br/> 0x59 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _10 <br/> 0x5a <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _11 <br/> 0x5b <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _12 <br/> 0x5c <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _13 <br/> 0x5d <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _14 <br/> 0x5e <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _15 <br/> 0x5f <br/> 0 ; 1(1)<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _16 <br/> 0x60 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP <br/> 0x61 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VER <br/> 0x62 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _IF <br/> 0x63 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOTIF <br/> 0x64 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VERIF <br/> 0x65 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VERNOTIF <br/> 0x66 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _ELSE <br/> 0x67 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _ENDIF <br/> 0x68 <br/> 0 ; 0<br />
| style="border:3px solid #808080; background-color:#00ff00;" | _VERIFY <br/> 0x69 <br/> 1 ; 0/1<br />
| style="border:3px solid #808080; background-color:#00ff00;" | _RETURN <br/> 0x6a <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | _TOALTSTACK <br/> 0x6b <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | _FROMALTSTACK <br/> 0x6c <br/> 0 #; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2DROP <br/> 0x6d <br/> 2 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2DUP <br/> 0x6e <br/> 2 ; 4<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _3DUP <br/> 0x6f <br/> 3 ; 6<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2OVER <br/> 0x70 <br/> 4 ; 6<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2ROT <br/> 0x71 <br/> 6 ; 6<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2SWAP <br/> 0x72 <br/> 4 ; 4<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _IFDUP <br/> 0x73 <br/> 1 ; 1/2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DEPTH <br/> 0x74 <br/> 0 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DROP <br/> 0x75 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DUP <br/> 0x76 <br/> 1 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _NIP <br/> 0x77 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _OVER <br/> 0x78 <br/> 2 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _PICK <br/> 0x79 <br/> 1+n+1 ; n+2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _ROLL <br/> 0x7a <br/> 1+n+1 ; n+1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _ROT <br/> 0x7b <br/> 3 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _SWAP <br/> 0x7c <br/> 2 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _TUCK <br/> 0x7d <br/> 2 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _CAT <br/> 0x7e <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _SUBSTR <br/> 0x7f <br/> 3 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _LEFT <br/> 0x80 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _RIGHT <br/> 0x81 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0;" | _SIZE <br/> 0x82 <br/> 1 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _INVERT <br/> 0x83 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _AND <br/> 0x84 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _OR <br/> 0x85 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _XOR <br/> 0x86 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff;" | _EQUAL <br/> 0x87 <br/> 2 ; 1<br />
| style="border:3px solid #808080; background-color:#c080ff;" | _EQUALVERIFY <br/> 0x88 <br/> 2 ; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED1 <br/> 0x89 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED2 <br/> 0x8a <br/><br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _1ADD <br/> 0x8b <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _1SUB <br/> 0x8c <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _2MUL <br/> 0x8d <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _2DIV <br/> 0x8e <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NEGATE <br/> 0x8f <br/> 1 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _ABS <br/> 0x90 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NOT <br/> 0x91 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _0NOTEQUAL <br/> 0x92 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _ADD <br/> 0x93 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _SUB <br/> 0x94 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _MUL <br/> 0x95 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _DIV <br/> 0x96 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _MOD <br/> 0x97 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _LSHIFT <br/> 0x98 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _RSHIFT <br/> 0x99 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _BOOLAND <br/> 0x9a <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _BOOLOR <br/> 0x9b <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NUMEQUAL <br/> 0x9c <br/> 2 ; 1<br />
| style="border:3px solid #808080; background-color:#8080ff;" | _NUMEQUALVERIFY <br/> 0x9d <br/> 2 ; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NUMNOTEQUAL <br/> 0x9e <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _LESSTHAN <br/> 0x9f <br/> 2 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _GREATERTHAN <br/> 0xa0 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _LESSTHANOREQUAL <br/> 0xa1 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _GREATERTHANOREQUAL <br/> 0xa2 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _MIN <br/> 0xa3 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _MAX <br/> 0xa4 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _WITHIN <br/> 0xa5 <br/> 3 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _RIPEMD160 <br/> 0xa6 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _SHA1 <br/> 0xa7 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _SHA256 <br/> 0xa8 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _HASH160 <br/> 0xa9 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _HASH256 <br/> 0xaa <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CODESEPARATOR <br/> 0xab <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CHECKSIG <br/> 0xac <br/> 2 @; 1<br />
| style="border:3px solid #808080; background-color:#a0d0ff;" | _CHECKSIGVERIFY <br/> 0xad <br/> 2 @; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CHECKMULTISIG <br/> 0xae <br/> 2n+2 @; 1<br />
| style="border:3px solid #808080; background-color:#a0d0ff;" | _CHECKMULTISIGVERIFY <br/> 0xaf <br/> 2n+2 @; 0/1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP1 <br/> 0xb0 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP2 <br/> 0xb1 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP3 <br/> 0xb2 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP4 <br/> 0xb3 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP5 <br/> 0xb4 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP6 <br/> 0xb5 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP7 <br/> 0xb6 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP8 <br/> 0xb7 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP9 <br/> 0xb8 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP10 <br/> 0xb9 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xba <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbe <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xca <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xce <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xda <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xde <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xea <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xeb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xec <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xed <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xee <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xef <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xfa <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _SMALLINTEGER <br/> 0xfb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEYS <br/> 0xfc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEYHASH <br/> 0xfd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEY <br/> 0xfe <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _INVALIDOPCODE <br/> 0xff <br/><br />
|}<br><br />
Except later pseudo-opcode changes, the definition of OP_NOP1 - OP_NOP10 and the change of the evaluation of OP_RETURN (did no invalidation previously) which both occured in bitcoin version 0.3.6 in July 2010 were the last changes regarding opcodes <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.2.0/bitcoin-0.2.0-linux.tar.gz file src/srcipt.cpp in bitcoin-0.2.0]</ref> <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.3.3/bitcoin-0.3.3-linux.tar.gz file src/srcipt.cpp in bitcoin-0.3.3]</ref> <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.3.6/bitcoin-0.3.6-linux.tar.gz file src/srcipt.cpp in bitcoin-0.3.6]</ref>.<br />
<br />
== Opcode descriptions ==<br />
It follows for each opcode less than decimal 185 (hexa 0xba) a description for its usage. The columns entitled ''nemonic'', ''decimal'' and ''Hex'' should be evident. The column ''input'' gives the needed items of the stack (and the alternate stack) and the column ''output'' indicates the resulting items on the stack (and the alternate stack). '''Stack-top is always the right most item.''' The naming of the entries in these two columns is chosen to reflect their interpretation. ''x'', ''x0'', ''x1'', ... means arbitrary or no interpretation, ''i0'', ''i1'' and ''i2'' a signed integer value, ''n'',''index'',''size'' and ''depth'' non-negative (unsigned) integer values, ''Boolean'' as either a true or false.<br><br />
<br />
Some of the more complicated opcodes are disabled since version 0.3.10 out of concern that the client might have a bug in the current implementation due to the historically not as 2-complement interpretations of the byte vectors as numerical values (the most significant byte holds the sign of the byte vectors). Furthermore how some of theses opcodes should work precisely is disputable.<br />
<br />
=== Push data from instruction onto stack ===<br />
<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_FALSE, OP_0<br />
|0<br />
|0x00<br />
|Nothing<br />
|Empty string<br />
|A byte vector of length 0 is pushed onto the stack. (Thus, it is not a no-op!)<br />
|-<br />
|(no official nemonics)<br />
|1 - 75<br />
|0x01 - 0x4b<br />
|(operand)<br />
|x<br />
|The next <opcode>-many bytes are to be pushed onto the stack.<br />
|-<br />
|OP_PUSHDATA1<br />
|76<br />
|0x4c<br />
|(operands)<br />
|x<br />
|The next byte contains the number of bytes to be pushed onto the stack which follow this byte.<br />
|-<br />
|OP_PUSHDATA2<br />
|77<br />
|0x4d<br />
|(operands)<br />
|x<br />
|The next two bytes contain the number of bytes to be pushed onto the stack which follow theses 2 bytes.<br />
|-<br />
|OP_PUSHDATA4<br />
|78<br />
|0x4e<br />
|(operands)<br />
|x<br />
|The next four bytes contain the number of bytes to be pushed onto the stack which follow theses 4 bytes.<br />
|-<br />
|OP_1NEGATE<br />
|79<br />
|0x4f<br />
|Nothing<br />
| -1<br />
|The byte with value -1 is pushed onto the stack.<br />
|-<br />
|OP_1, OP_TRUE<br />
|81<br />
|0x51<br />
|Nothing<br />
|1<br />
|The byte with value 1 is pushed onto the stack.<br />
|-<br />
|OP_2 - OP_16<br />
|82 - 96<br />
|0x52 - 0x60<br />
|Nothing<br />
|2-16<br />
|The byte with value <opcode>-80 (thus, one of 2 - 16) is pushed onto the stack.<br />
|}<br />
<br />
=== Flow control ===<br />
<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_NOP<br />
|97<br />
|0x61<br />
|Nothing<br />
|Nothing<br />
|Does nothing.<br />
|-<br />
|OP_IF<br />
|99<br />
|0x63<br />
|Boolean<br />
|Nothing<br />
|If the top stack value is not 0, the statements are executed. The top stack value is removed. Lead in a logcial ''<value> then [statements] [else [statements]] endif'' expression<br />
|-<br />
|OP_NOTIF<br />
|100<br />
|0x64<br />
|Boolean<br />
|Nothing<br />
|If the top stack value is 0, the statements are executed. The top stack value is removed. Lead in a logcial ''<value> then [statements] [else [statements]] endif'' expression <br />
|-<br />
|OP_ELSE<br />
|103<br />
|0x67<br />
|Nothing<br />
|Nothing<br />
|If the preceeding OP_IF or OP_NOTIF or OP_ELSE was not executed then these statements are and if the preceding OP_IF or OP_NOTIF or OP_ELSE was executed then these statements are not. <br />
|-<br />
|OP_ENDIF<br />
|104<br />
|0x68<br />
|Nothing<br />
|Nothing<br />
|Ends a logcial ''If <value> then [statements] [else [statements]] '' expression<br />
|-<br />
|OP_VERIFY<br />
|105<br />
|0x69<br />
|Boolean<br />
|Nothing / False<br />
|If top stack value is not true then marks transaction as '''invalid''' . A value true is removed, but false is not.<br />
|-<br />
|OP_RETURN<br />
|106<br />
|0x6a<br />
|Nothing<br />
|Nothing<br />
|Marks transaction as '''invalid'''. <br />
|}<br />
<br />
===Stack item organization===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_TOALTSTACK<br />
|107<br />
|0x6b<br />
|x1 (alt)<br />
|(alt x1)<br />
|Puts the input onto the top of the alt stack. Removes it from the (main) stack.<br />
|-<br />
|OP_FROMALTSTACK<br />
|108<br />
|0x6c<br />
|(alt x1)<br />
|x1 (alt)<br />
|Puts the input onto the top of the (main) stack. Removes it from the alt stack.<br />
|-<br />
|OP_2DROP<br />
|109<br />
|0x6d<br />
|x2 x1<br />
|Nothing<br />
|Removes the top two stack items.<br />
|-<br />
|OP_2DUP<br />
|110<br />
|0x6e<br />
|x2 x1<br />
|x2 x1 x2 x1<br />
|Duplicates the top two stack items.<br />
|-<br />
|OP_3DUP<br />
|111<br />
|0x6f<br />
|x3 x2 x1<br />
|x3 x2 x1 x3 x2 x1<br />
|Duplicates the top three stack items.<br />
|-<br />
|OP_2OVER<br />
|112<br />
|0x70<br />
|x4 x3 x2 x1<br />
|x4 x3 x2 x1 x4 x3<br />
|Copies the pair of items two spaces back in the stack to the front.<br />
|-<br />
|OP_2ROT<br />
|113<br />
|0x71<br />
|x6 x5 x4 x3 x2 x1<br />
|x4 x3 x2 x1 x6 x5<br />
|The fifth and sixth items back are moved to the top of the stack. Twotimes left rotate.<br />
|-<br />
|OP_2SWAP<br />
|114<br />
|0x72<br />
|x4 x3 x2 x1<br />
|x2 x1 x4 x3<br />
|Swaps the top two pairs of stack items.<br />
|-<br />
|OP_IFDUP<br />
|115<br />
|0x73<br />
|x1<br />
|x1 / x1 x1<br />
|If the top stack value is not 0, duplicate it.<br />
|-<br />
|OP_DEPTH<br />
|116<br />
|0x74<br />
|Nothing<br />
|depth<br />
|Puts the number of stack items onto the stack as one little-endian coded byte-vector<br />
|-<br />
|OP_DROP<br />
|117<br />
|0x75<br />
|x1<br />
|Nothing<br />
|Removes the top stack item.<br />
|-<br />
|OP_DUP<br />
|118<br />
|0x76<br />
|x1<br />
|x1 x1<br />
|Duplicates the top stack item.<br />
|-<br />
|OP_NIP<br />
|119<br />
|0x77<br />
|x2 x1<br />
|x1<br />
|Removes the second-to-top stack item.<br />
|-<br />
|OP_OVER<br />
|120<br />
|0x78<br />
|x2 x1<br />
|x2 x1 x2<br />
|Copies the second-to-top stack item to the top.<br />
|-<br />
|OP_PICK<br />
|121<br />
|0x79<br />
|xn ... x2 x1 x0 <n><br />
|xn ... x2 x1 x0 xn<br />
|<n> is removed and the item ''n'' back in the stack is copied to the top.<br />
|-<br />
|OP_ROLL<br />
|122<br />
|0x7a<br />
|xn ... x2 x1 x0 <n><br />
|... x2 x1 x0 xn<br />
|<n> is removed and the item ''n'' back in the stack is moved to the top.<br />
|-<br />
|OP_ROT<br />
|123<br />
|0x7b<br />
|x3 x2 x1<br />
|x2 x1 x3<br />
|The top three items on the stack are rotated to the left.<br />
|-<br />
|OP_SWAP<br />
|124<br />
|0x7c<br />
|x2 x1<br />
|x1 x2<br />
|The top two items on the stack are swapped resp. rotated.<br />
|-<br />
|OP_TUCK<br />
|125<br />
|0x7d<br />
|x2 x1<br />
|x1 x2 x1<br />
|The item at the top of the stack is copied and inserted before the second-to-top item.<br />
|}<br />
<br />
=== Splice ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_CAT<br />
|126<br />
|0x7e<br />
|x2 x1<br />
|out<br />
|Appends stack-top item at second-to top item. Concatenates two strings resp. byte vectors. ''Currently disabled.''<br />
|-<br />
|OP_SUBSTR<br />
|127<br />
|0x7f<br />
|x3 index size<br />
|out<br />
|Returns the section started at position <index> and of length <size> of a string resp. byte vector. ''Currently disabled.''<br />
|-<br />
|OP_LEFT<br />
|128<br />
|0x80<br />
|x2 index<br />
|out<br />
|Keeps only characters left of the specified point in second-to top item. ''Currently disabled.''<br />
|-<br />
|OP_RIGHT<br />
|129<br />
|0x81<br />
|x2 index<br />
|out<br />
|Keeps only characters right of the specified point in second-to top item. ''Currently disabled.''<br />
|-<br />
|OP_SIZE<br />
|130<br />
|0x82<br />
|x1<br />
|x1 size<br />
|Returns the length of the input string resp. byte vector resp. top-stack item.<br />
|}<br />
<br />
=== Bitwise logic ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_INVERT<br />
|131<br />
|0x83<br />
|x1<br />
|x0<br />
|Flips all of the bits in the input. ''Currently disabled.''<br />
|-<br />
|OP_AND<br />
|132<br />
|0x84<br />
|x2 x1<br />
|x0<br />
|Boolean ''and'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_OR<br />
|133<br />
|0x85<br />
|x2 x1<br />
|x0<br />
|Boolean ''or'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_XOR<br />
|134<br />
|0x86<br />
|x2 x1<br />
|x0<br />
|Boolean ''exclusive or'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_EQUAL<br />
|135<br />
|0x87<br />
|x2 x1<br />
|Boolean<br />
|Returns 1 if the inputs have the same length and are byte-wise equal, 0 otherwise.<br />
|-<br />
|OP_EQUALVERIFY<br />
|136<br />
|0x88<br />
|x2 x1<br />
|Nothing / false<br />
|Same as OP_EQUAL, but runs OP_VERIFY afterward.<br />
|}<br />
<br />
=== Arithmetic ===<br />
<br />
Since version 0.3.10 the implemented arithmetic opcodes are limited to maximal 4 byte vectors (|value| < 2^31), in version 0.3.6 up to 0.3.8 they were limited to 258 byte vectors and prior to 0.3.6 unrestricted.<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_1ADD<br />
|139<br />
|0x8b<br />
|i1<br />
|i0<br />
|1 is added to the input.<br />
|-<br />
|OP_1SUB<br />
|140<br />
|0x8c<br />
|i1<br />
|i0<br />
|1 is subtracted from the input.<br />
|-<br />
|OP_2MUL<br />
|141<br />
|0x8d<br />
|i1<br />
|i0<br />
|The input is multiplied by 2. ''Currently disabled.''<br />
|-<br />
|OP_2DIV<br />
|142<br />
|0x8e<br />
|i1<br />
|i0<br />
|The input is divided by 2 (round down). ''Currently disabled.''<br />
|-<br />
|OP_NEGATE<br />
|143<br />
|0x8f<br />
|i1<br />
|i0<br />
|The sign of the input is flipped. Numerically the value is multiplied by -1<br />
|-<br />
|OP_ABS<br />
|144<br />
|0x90<br />
|i1<br />
|i0<br />
|The input is negative, its sign is flipped.<br />
|-<br />
|OP_NOT<br />
|145<br />
|0x91<br />
|i1<br />
|Boolean<br />
|If the input is 0 or 1, it is flipped. Otherwise the output will be 0. Test whether its value equals 0<br />
|-<br />
|OP_0NOTEQUAL<br />
|146<br />
|0x92<br />
|i1<br />
|Boolean<br />
|Returns 0 if the input is 0. 1 otherwise. Test whether its value is unequal 0<br />
|-<br />
|OP_ADD<br />
|147<br />
|0x93<br />
|i2 i1<br />
|i0<br />
|stack-top i1 is added to i2.<br />
|-<br />
|OP_SUB<br />
|148<br />
|0x94<br />
|i2 i1<br />
|i0<br />
|stack-top i1 is subtracted from i2.<br />
|-<br />
|OP_MUL<br />
|149<br />
|0x95<br />
|i2 i1<br />
|i0<br />
|i2 is multiplied with stack-top i1. ''Currently disabled.''<br />
|-<br />
|OP_DIV<br />
|150<br />
|0x96<br />
|i2 i1<br />
|i0<br />
|i2 is divided by stack-top i1 (divisor should be not 0). ''Currently disabled.''<br />
|-<br />
|OP_MOD<br />
|151<br />
|0x97<br />
|i2 i1<br />
|i0<br />
|Returns the remainder after dividing i2 by stack-top i1 (divisor should be not 0). ''Currently disabled.''<br />
|-<br />
|OP_LSHIFT<br />
|152<br />
|0x98<br />
|i2 i1<br />
|i0<br />
|Shifts i2 left by i1 bits, preserving sign of i2 (i1 >= 0). ''Currently disabled.''<br />
|-<br />
|OP_RSHIFT<br />
|153<br />
|0x99<br />
|i2 i1<br />
|i0<br />
|Shifts i2 right by i1 bits, preserving sign of i2 (i1 >= 0). ''Currently disabled.''<br />
|-<br />
|OP_BOOLAND<br />
|154<br />
|0x9a<br />
|i2 i1<br />
|Boolean<br />
|If both i2 and i1 are not 0, the output is 1. Otherwise 0.<br />
|-<br />
|OP_BOOLOR<br />
|155<br />
|0x9b<br />
|i2 i1<br />
|Boolean<br />
|If i2 or i1 is not 0, the output is 1. Otherwise 0.<br />
|-<br />
|OP_NUMEQUAL<br />
|156<br />
|0x9c<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 and i1 are numerically equal, 0 otherwise.<br />
|-<br />
|OP_NUMEQUALVERIFY<br />
|157<br />
|0x9d<br />
|i2 i1<br />
|Nothing / False<br />
|Same as OP_NUMEQUAL, but runs OP_VERIFY afterward.<br />
|-<br />
|OP_NUMNOTEQUAL<br />
|158<br />
|0x9e<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 and i1 are numerically not equal, 0 otherwise.<br />
|-<br />
|OP_LESSTHAN<br />
|159<br />
|0x9f<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is less than stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_GREATERTHAN<br />
|160<br />
|0xa0<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is greater than stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_LESSTHANOREQUAL<br />
|161<br />
|0xa1<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is less than or equal to stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_GREATERTHANOREQUAL<br />
|162<br />
|0xa2<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is greater than or equal to stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_MIN<br />
|163<br />
|0xa3<br />
|i2 i1<br />
|i2 / i1<br />
|Returns the smaller of i2 and i1.<br />
|-<br />
|OP_MAX<br />
|164<br />
|0xa4<br />
|i2 i1<br />
|i2 / i1<br />
|Returns the larger of i2 and i1.<br />
|-<br />
|OP_WITHIN<br />
|165<br />
|0xa5<br />
|i3 i2 i1<br />
|Boolean<br />
|Returns 1 if i3 >= i2 and i3 < i1, 0 otherwise. Thus if i2 > i1 returns always 0.<br />
|}<br />
<br />
=== Crypto ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_RIPEMD160<br />
|166<br />
|0xa6<br />
|x<br />
|hash20<br />
|The input is hashed using RIPEMD-160.<br />
|-<br />
|OP_SHA1<br />
|167<br />
|0xa7<br />
|x<br />
|hash20<br />
|The input is hashed using SHA-1.<br />
|-<br />
|OP_SHA256<br />
|168<br />
|0xa8<br />
|x<br />
|hash32<br />
|The input is hashed using SHA-256.<br />
|-<br />
|OP_HASH160<br />
|169<br />
|0xa9<br />
|x<br />
|hash20<br />
|The input is hashed twice: first with SHA-256 and then with RIPEMD-160.<br />
|-<br />
|OP_HASH256<br />
|170<br />
|0xaa<br />
|x<br />
|hash32<br />
|The input is hashed two times with SHA-256.<br />
|-<br />
|OP_CODESEPARATOR<br />
|171<br />
|0xab<br />
|Nothing<br />
|Nothing<br />
|All of the signature checking opcodes will only match signatures to the data after the most recently-executed OP_CODESEPARATOR.<br />
|-<br />
|[[OP_CHECKSIG]]<br />
|172<br />
|0xac<br />
|sig pubkey<br />
|Boolean<br />
|The entire transaction's outputs, inputs, and script (from the most recently-executed OP_CODESEPARATOR to the end) are hashed. The signature used by OP_CHECKSIG must be a valid signature for a further, extern specified hash and the given public key. If it is, 1 is returned, 0 otherwise.<br />
|-<br />
|OP_CHECKSIGVERIFY<br />
|173<br />
|0xad<br />
|sig pubkey<br />
|Nothing / False<br />
|Same as OP_CHECKSIG, but OP_VERIFY is executed afterward.<br />
|-<br />
|OP_CHECKMULTISIG<br />
|174<br />
|0xae<br />
|sig1 sig2 ... <number of signatures> pub1 pub2 <number of public keys><br />
|Boolean<br />
|For each signature and public key pair, OP_CHECKSIG is executed. If more public keys than signatures are listed, some key/sig pairs can fail. All signatures need to match a public key. If all signatures are valid, 1 is returned, 0 otherwise. Due to a bug, one extra unused value is removed from the stack.<br />
|-<br />
|OP_CHECKMULTISIGVERIFY<br />
|175<br />
|0xaf<br />
|sig1 sig2 ... <number of signatures> pub1 pub2 ... <number of public keys><br />
|Nothing / False<br />
|Same as OP_CHECKMULTISIG, but OP_VERIFY is executed afterward.<br />
|}<br />
<br />
=== Expansion opcodes ===<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_NOP1-OP_NOP10<br />
|176-185<br />
|0xb0-0xb9<br />
|The opcode has no effect.<br />
|}<br />
<br />
=== Version opcodes ===<br />
Version opcodes are disabled since bitcoin 0.2.0 and should not be used (maybe reassigned in the future).<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_VER<br />
|98<br />
|0x62<br />
|Script evalution is triggered invalid (Formerly pushed the bitcoin-serialize version onto stack).<br />
|-<br />
|OP_VERIF<br />
|101<br />
|0x65<br />
|Script evalution is triggered invalid (Formerly top stack item was popped and =< compared to present version)<br />
|-<br />
|OP_VERNOTIF<br />
|102<br />
|0x66<br />
|Script evalution is triggered invalid (Formerly top stack item was popped and > compared to present version)<br />
|}<br />
<br />
=== Reserved opcodes ===<br />
Each opcode not assigned (currently also every opcode value > 185) is also reserved. Using any unassigned opcode triggers the script evaluation to be invalid.<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_RESERVED<br />
|80<br />
|0x50<br />
|Script evalution is triggered invalid-<br />
|-<br />
|OP_RESERVED1<br />
|137<br />
|0x89<br />
|Script evalution is triggered invalid.<br />
|-<br />
|OP_RESERVED2<br />
|138<br />
|0x8a<br />
|Script evalution is triggered invalid.<br />
|}<br />
<br />
===Pseudo-opcodes===<br />
These nemonics are used internally for assisting with transaction matching. They are invalid if used in actual scripts.<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_PUBKEYHASH<br />
|253<br />
|0xfd<br />
|Represents a public key hashed with OP_HASH160.<br />
|-<br />
|OP_PUBKEY<br />
|254<br />
|0xfe<br />
|Represents a public key compatible with OP_CHECKSIG.<br />
|-<br />
|OP_INVALIDOPCODE<br />
|255<br />
|0xff<br />
|Matches any opcode that is not yet assigned.<br />
|}<br />
<br />
==Scripts in bitcoin transactions==<br />
It follows a list of important (most occuring) scripts to see opcodes "at work". Keep in mind that all constants actually use the data-pushing instructions above. At start of a (transaction input) script evaluation, the stack is always empty. Currently less than 0.01 % of all txout-scripts / scriptPubKeys in the main block chain are not of the following two standard scripts.<br />
<br />
===Standard transaction to bitcoin address===<br />
<br />
scriptPubKey: OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG<br />
scriptSig: <sig> <pubKey><br />
<br />
To demonstrate how scripts look on the wire, here is a raw scriptPubKey:<br />
<pre> 76 A9 14<br />
OP_DUP OP_HASH160 Bytes to push<br />
<br />
89 AB CD EF AB BA AB BA AB BA AB BA AB BA AB BA AB BA AB BA 88 AC<br />
Data to push OP_EQUALVERIFY OP_CHECKSIG</pre><br />
<br />
Note: scriptSig is in the input of the spending transaction and scriptPubKey is in the output of the previously storing transaction, i.e. its "available bitcoins".<br />
<br />
Here is how each instruction is processed:<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
| <sig> <pubKey> OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| scriptSig and scriptPubKey are combined.<br />
|-<br />
|<sig> <pubKey><br />
| OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| Constants are added to the stack.<br />
|-<br />
|<sig> <pubKey> <pubKey><br />
| OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| Top stack item is duplicated.<br />
|-<br />
|<sig> <pubKey> <pubHashA><br />
|<pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG<br />
| Top stack item is hashed.<br />
|-<br />
|<sig> <pubKey> <pubHashA> <pubKeyHash><br />
|OP_EQUALVERIFY OP_CHECKSIG<br />
| Constant added.<br />
|-<br />
|<sig> <pubKey><br />
|OP_CHECKSIG<br />
| Equality is checked between the top two stack items.<br />
|-<br />
|true<br />
|Empty.<br />
|Signature is checked for top two stack items.<br />
|}<br />
<br />
===Transaction to IP address (and generation transaction)===<br />
<br />
scriptPubKey: <pubKey> OP_CHECKSIG<br />
scriptSig: <sig><br />
<br />
Checking process:<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
|<sig> <pubKey> OP_CHECKSIG<br />
|scriptSig and scriptPubKey are combined.<br />
|-<br />
|<sig> <pubKey><br />
| OP_CHECKSIG<br />
|Constants are added to the stack.<br />
|-<br />
|true<br />
|Empty.<br />
|Signature is checked for top two stack items.<br />
|}<br />
<br />
In the case of a '''coin generation transaction''' (the first transaction of each block), there is no scriptSig, resp. its code ("coinbase") is completly ignored for the transaction. Only the scriptPubKey is used.<br />
<br />
===Transaction with a message===<br />
<br />
It's possible to add arbitrary data to any transaction by just adding some data along with OP_DROP. <br />
scriptPubKey: <message> OP_DROP <pubKey> OP_CHECKSIG<br />
scriptSig: <sig><br />
<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
|<sig> <message> OP_DROP <pubKey> OP_CHECKSIG<br />
|<br />
|-<br />
|<sig><br />
|<message> OP_DROP <pubKey> OP_CHECKSIG<br />
|scriptSig added to the stack.<br />
|-<br />
|<sig> <message><br />
|OP_DROP <pubKey> OP_CHECKSIG<br />
|The message has been put.<br />
|-<br />
|<sig><br />
|<pubKey> OP_CHECKSIG<br />
|Top stack item has been removed.<br />
|-<br />
|<sig> <pubKey><br />
|OP_CHECKSIG<br />
|Checking signature against the public key.<br />
|-<br />
|true<br />
|Empty.<br />
|Stack holds the value of signature check now.<br />
|}<br />
<br />
===Examples of non standard transaction on Testnet===<br />
<br />
These two links below show a non standard transaction. It just prepends the hex of "bob" and the operation OP_DROP<br />
which just removes it. As you can see they can be spent as normal.<br />
<br />
Input non-std transaction:<br />
http://blockexplorer.com/testnet/t/6ttfeb55B1<br />
<br />
Spent by:<br />
http://blockexplorer.com/testnet/t/AFdRB1CHS3<br />
<br />
==Script validation==<br />
A script evaluation is considered invalid, if any of these conditions meets:<br><br />
<ul><br />
<li>the total size of the script exceeds (currently) 10000 bytes<br />
<li>there are more than (currently) 201 opcodes of opcode value > 0x60 in the script<br />
<li>each instruction is (currently) limited to maximal 520 bytes. This effects only the opcodes OP_PUSHDATA2 and OP_PUSHDATA4<br />
<li>the executed opcode of the script has insufficient input (from stack, from script or from anywhere)<br />
<li>the opcode is not defined (for execution) - indicated by white or light gray background color in the table<br />
<li>the opcode is disabled (currently 15 opcodes) - indicated by white font color in the opcode overview matrix<br />
<li>stack overflow occurs during execution of the opcode (currently the number of items on the stack and on the alternate stack is limited to 1000)<br />
<li>the opcodes OP_VERIF and OP_NOTVERIF invalidate a script which contains this opcode (even if this opcode is not executed!)<br />
<li>the opcodes OP_ELSE or OP_ENDIF has no matching OP_IF<br><br />
<li>the script execution has been finished but there is (at least) an unmatched OP_IF<br><br />
<li>the opcodes OP_VERIFY, OP_EQUALVERIFY, OP_NUMEQUALVERIFY, OP_CHECKSIGVERIFY and OP_CHECKMULTISIGVERIFY invalidate the script if the stack-top item is false<br />
<li>the execution of OP_RETURN<br />
<!--li>alt stack overflow occurs (only possible during execution of OP_TOALTSTACK)--><br />
<li>the numerical value of the top-stack item is negative or greater than the number of items - 2 on the stack if OP_PICK or OP_ROLL shall be executed<br />
<li>When interpreting a stack-item of an arithmetic opcode as a signed integer its value is >= 2^31 or <= -2^31.<br />
<li>an item used as public key or signature for each of the opcodes OP_CHECKSIG, OP_CHECKSIGVERIFY, OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY can be neither a public key or signature (for the given hash)<br />
<li>the number of signature items or the number of public key items on the stack is negative for OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY<br />
<li>there or more signatures items than public key items on the stack for OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY<br />
<li>there are (currently) more than 20 public key items on the stack for OP_CHECKMULTISIG or CHECKMULTISIGVERIFY<br />
<li>the sum of opcodes > 0x60 and the number of public keys in all executed OP_CHECKMULTISIG or CHECKMULTISIGVERIFY exceeds (currently) 201<br />
<li>the script execution has been finished and the stack is empty or the top-stack item is false (numerical value 0)<br />
</ul><br />
else the script evaluation is considered to be valid.<ref>[http://sourceforge.net/projects/bitcoin/files/Bitcoin/bitcoin-0.7.1/bitcoin-0.7.1-linux.tar.gz file src/src/script.cpp in bitcoin-0.7.1]</ref><br />
'''If invalidation of a script is triggered then the script is immediately finished.''' These arbitrary looking limitations of 10000, 201, 520, 1000 and 20 might be increased in the future -- they serve to prevent strong slow down of the evaluation of a script while not restricting its practical usage really.<br />
<br />
==Withdrawn and drafted opcodes==<br />
<br />
<ul><br />
<li> byte value 0x89 OP_NOTEQUAL defined in pre-0.1.0 bitcoin versions. Since 0.1.0 removed because of security concerns. <br />
<li> byte value 0xb1 [[BIP 0012 | OP_EVAL]] withdraw - poll was triggered but insufficient support. <br />
<li> byte value 0xb2 [[BIP 0017 | OP_CHECKHASHVERIFY]] withdraw - poll was triggered but insufficient support.<br />
</ul><br />
<br />
==See Also==<br />
* [[Transactions]]<br />
* [[Contracts]]<br />
<br />
==References==<br />
<references/><br />
<ul><br />
<li>[http://www.zorinaq.com/pub/bitcoin-0.1.0.tgz file src/script.cpp in bitcoin-0.1.0]</li><br />
</ul><br />
[[Category:Technical]]<br />
[[Category:Vocabulary]]</div>
Smtp
https://en.bitcoin.it/w/index.php?title=Script&diff=34919
Script
2013-01-11T17:23:31Z
<p>Smtp: /* Arithmetic */</p>
<hr />
<div>Bitcoin uses a scripting system for [[transactions]]. [[Wikipedia:FORTH|Forth]]-like, Script is simple, stack-based, and processed from left to right. It is purposefully not Turing-complete, with no loops.<br />
<br />
A script is essentially a list of instructions recorded with each transaction that describe how the next person wanting to spend the Bitcoins being transferred can gain access to them.<br />
<br />
Scripts are big-endian and their sequences of bytes is interpreted as a sequence of opcodes with operands. Only opcodes with byte values less than 0x4f have additional operands.<br />
<br />
== Scripts and Bitcoin transactions ==<br />
The script for a typical Bitcoin transfer to destination Bitcoin address D simply encumbers future spending of the bitcoins with two things: the spender must provide<br />
# a public key that, when hashed, yields destination address D embedded in the script, and<br />
# a signature to show evidence of the private key corresponding to the public key just provided.<br />
<br />
Scripting provides the flexibility to change the parameters of what's needed to spend transferred Bitcoins. For example, the scripting system could be used to require two private keys, or a combination of several, or even no keys at all.<br />
<br />
A transaction is valid if nothing in the combined script triggers failure and the top stack item exists and is true (non-zero). The party who originally ''stored'' the Bitcoins now being spent, dictates the script operations that will occur ''last'' in order to release them for use in another transaction. The party wanting to spend them must provide the input(s) to the previously recorded script that results in those operations occurring last leaving behind true (non-zero) on the stack.<br><br />
Only the very first transaction in each bitcoin block has no input script (the entry there is called "coinbase"), because the Bitcoins created with the block are created from hot air and not released by a previous recorded txout-script.<br />
<br />
== Stack ==<br />
<br />
The stacks hold byte vectors (there is the (main) stack and an alternative stack). Byte vectors are interpreted as little-endian variable-length integers with the most significant bit determining the sign of the integer. Thus 0x81 represents -1. 0x80 is another representation of zero (so called negative 0). Byte vectors are interpreted as Booleans where False is represented by any representation of zero, and True is represented by any representation of non-zero.<br />
<br />
== Opcode overview ==<br />
<br />
For each opcode is given: its nemonic without the leading OP_, its hexadecimal byte value, the number of stack items needed (poped) during execution, a semicolon and the number of stack items which has been pushed (after execution). A * after the needed stack items indicates that further bytes from the script following the current opcode are needed. A # indicates that items on the alternative stack are poped/pushed. A @ indicates that further (global) data from the transaction is needed. A / indicates alternatives of a value. <br/><br />
Different colors indicate different semantic execution groups of opcodes:<br />
{| style="background:none; font-size:100%; padding:0; border-collapse:collapse; text-align:center; line-height:2em;" border="0" align="center" <br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | copy a fixed number of bytes but at most 75 onto stack<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | copy bytes onto stack which number is given by a 1, 2 or 4 byte value.<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | copy 1 specific byte onto stack<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | undefined opcode<br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | a pseudo-opcode, unassigned for scripts<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | NOP or opcode is part of a IF-flow-control construction<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00ff00;" | (stack conditionally) invalidation of the script this opcode is part of<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | stack item is moved between main stack and alternate stack<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | stack item(s) is/are moved, copied or deleted<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0;" | byte vectors are appended or divided or their size is determined<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff;" | byte vectors are interpreted bit-position-independently<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | byte vectors are interpreted and processed as signed integers<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | a hash value is computed or a signature checked<br />
|}<br />
<p><br />
===Opcode byte-matrix===<br />
The opcode value 0x00 with nemonic OP_FALSE is also named OP_0 and the opcode value 0x51 with nemonic OP_1 as also named OP_TRUE.<br />
{| style="background:none; font-size:100%; padding:0; border-collapse:collapse; text-align:center; line-height:2em;" border="0" align="center" <br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" |_FALSE<br/> 0x00 <br/> 0 ; 1(0) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x01<br/> 0 *; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x02<br/> 0 *; 1(2)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x03<br/> 0 *; 1(3)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x04<br/> 0 *; 1(4)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x04<br/> 0 *; 1(5)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x06<br/> 0 *; 1(6)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x07<br/> 0 *; 1(7)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x08<br/> 0 *; 1(8)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x09<br/> 0 *; 1(9)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0a<br/> 0 *; 1(10)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0b<br/> 0 *; 1(11)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0c<br/> 0 *; 1(12)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0d<br/> 0 *; 1(13)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0e<br/> 0 *; 1(14)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0f<br/> 0 *; 1(15)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x10 <br/> 0 *; 1(16) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x11 <br/> 0 *; 1(17)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x12 <br/> 0 *; 1(18)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x13 <br/> 0 *; 1(19)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x14 <br/> 0 *; 1(20)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x15 <br/> 0 *; 1(21)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x16 <br/> 0 *; 1(22)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x17 <br/> 0 *; 1(23)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x18 <br/> 0 *; 1(24)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x19 <br/> 0 *; 1(25)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1a <br/> 0 *; 1(26)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1b <br/> 0 *; 1(27)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1c <br/> 0 *; 1(28)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1d <br/> 0 *; 1(29)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1e <br/> 0 *; 1(30)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1f <br/> 0 *; 1(31)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x20 <br/> 0 *; 1(32) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x21 <br/> 0 *; 1(33)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x22 <br/> 0 *; 1(34)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x23 <br/> 0 *; 1(35)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x24 <br/> 0 *; 1(36)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x25 <br/> 0 *; 1(37)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x26 <br/> 0 *; 1(38)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x27 <br/> 0 *; 1(39)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x28 <br/> 0 *; 1(40)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x29 <br/> 0 *; 1(41)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2a <br/> 0 *; 1(42)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2b <br/> 0 *; 1(43)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2c <br/> 0 *; 1(44)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2d <br/> 0 *; 1(45)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2e <br/> 0 *; 1(46)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2f <br/> 0 *; 1(47)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x30 <br/> 0 *; 1(48) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x31 <br/> 0 *; 1(49)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x32 <br/> 0 *; 1(50)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x33 <br/> 0 *; 1(51)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x34 <br/> 0 *; 1(52)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x35 <br/> 0 *; 1(53)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x36 <br/> 0 *; 1(54)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x37 <br/> 0 *; 1(55)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x38 <br/> 0 *; 1(56)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x39 <br/> 0 *; 1(57)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3a <br/> 0 *; 1(58)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3b <br/> 0 *; 1(59)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3c <br/> 0 *; 1(60)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3d <br/> 0 *; 1(61)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3e <br/> 0 *; 1(62)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3f <br/> 0 *; 1(63)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x40 <br/> 0 *; 1(64) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x41 <br/> 0 *; 1(65)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x42 <br/> 0 *; 1(66)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x43 <br/> 0 *; 1(67)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x44 <br/> 0 *; 1(68)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x45 <br/> 0 *; 1(69)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x46 <br/> 0 *; 1(70)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x47 <br/> 0 *; 1(71)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x48 <br/> 0 *; 1(72)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x49 <br/> 0 *; 1(73)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x4a <br/> 0 *; 1(74)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x4b <br/> 0 *; 1(75)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA1 <br/> 0x4c <br/> 0 *; 1(0 - 255)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA2 <br/> 0x4d <br/> 0 *; 1(0 - 2^16-1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA4 <br/> 0x4e <br/> 0 *; 1(0 - 2^32-1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _1NEGATE <br/> 0x4f <br/> 0 ; 1(1)<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED <br/> 0x50 <br/> <br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _1 <br/> 0x51 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _2 <br/> 0x52 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _3 <br/> 0x53 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _4 <br/> 0x54 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _5 <br/> 0x55 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _6 <br/> 0x56 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _7 <br/> 0x57 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _8 <br/> 0x58 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _9 <br/> 0x59 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _10 <br/> 0x5a <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _11 <br/> 0x5b <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _12 <br/> 0x5c <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _13 <br/> 0x5d <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _14 <br/> 0x5e <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _15 <br/> 0x5f <br/> 0 ; 1(1)<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _16 <br/> 0x60 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP <br/> 0x61 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VER <br/> 0x62 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _IF <br/> 0x63 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOTIF <br/> 0x64 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VERIF <br/> 0x65 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VERNOTIF <br/> 0x66 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _ELSE <br/> 0x67 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _ENDIF <br/> 0x68 <br/> 0 ; 0<br />
| style="border:3px solid #808080; background-color:#00ff00;" | _VERIFY <br/> 0x69 <br/> 1 ; 0/1<br />
| style="border:3px solid #808080; background-color:#00ff00;" | _RETURN <br/> 0x6a <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | _TOALTSTACK <br/> 0x6b <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | _FROMALTSTACK <br/> 0x6c <br/> 0 #; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2DROP <br/> 0x6d <br/> 2 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2DUP <br/> 0x6e <br/> 2 ; 4<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _3DUP <br/> 0x6f <br/> 3 ; 6<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2OVER <br/> 0x70 <br/> 4 ; 6<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2ROT <br/> 0x71 <br/> 6 ; 6<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2SWAP <br/> 0x72 <br/> 4 ; 4<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _IFDUP <br/> 0x73 <br/> 1 ; 1/2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DEPTH <br/> 0x74 <br/> 0 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DROP <br/> 0x75 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DUP <br/> 0x76 <br/> 1 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _NIP <br/> 0x77 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _OVER <br/> 0x78 <br/> 2 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _PICK <br/> 0x79 <br/> 1+n+1 ; n+2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _ROLL <br/> 0x7a <br/> 1+n+1 ; n+1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _ROT <br/> 0x7b <br/> 3 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _SWAP <br/> 0x7c <br/> 2 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _TUCK <br/> 0x7d <br/> 2 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _CAT <br/> 0x7e <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _SUBSTR <br/> 0x7f <br/> 3 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _LEFT <br/> 0x80 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _RIGHT <br/> 0x81 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0;" | _SIZE <br/> 0x82 <br/> 1 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _INVERT <br/> 0x83 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _AND <br/> 0x84 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _OR <br/> 0x85 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _XOR <br/> 0x86 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff;" | _EQUAL <br/> 0x87 <br/> 2 ; 1<br />
| style="border:3px solid #808080; background-color:#c080ff;" | _EQUALVERIFY <br/> 0x88 <br/> 2 ; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED1 <br/> 0x89 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED2 <br/> 0x8a <br/><br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _1ADD <br/> 0x8b <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _1SUB <br/> 0x8c <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _2MUL <br/> 0x8d <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _2DIV <br/> 0x8e <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NEGATE <br/> 0x8f <br/> 1 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _ABS <br/> 0x90 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NOT <br/> 0x91 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _0NOTEQUAL <br/> 0x92 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _ADD <br/> 0x93 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _SUB <br/> 0x94 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _MUL <br/> 0x95 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _DIV <br/> 0x96 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _MOD <br/> 0x97 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _LSHIFT <br/> 0x98 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _RSHIFT <br/> 0x99 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _BOOLAND <br/> 0x9a <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _BOOLOR <br/> 0x9b <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NUMEQUAL <br/> 0x9c <br/> 2 ; 1<br />
| style="border:3px solid #808080; background-color:#8080ff;" | _NUMEQUALVERIFY <br/> 0x9d <br/> 2 ; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NUMNOTEQUAL <br/> 0x9e <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _LESSTHAN <br/> 0x9f <br/> 2 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _GREATERTHAN <br/> 0xa0 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _LESSTHANOREQUAL <br/> 0xa1 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _GREATERTHANOREQUAL <br/> 0xa2 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _MIN <br/> 0xa3 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _MAX <br/> 0xa4 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _WITHIN <br/> 0xa5 <br/> 3 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _RIPEMD160 <br/> 0xa6 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _SHA1 <br/> 0xa7 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _SHA256 <br/> 0xa8 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _HASH160 <br/> 0xa9 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _HASH256 <br/> 0xaa <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CODESEPARATOR <br/> 0xab <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CHECKSIG <br/> 0xac <br/> 2 @; 1<br />
| style="border:3px solid #808080; background-color:#a0d0ff;" | _CHECKSIGVERIFY <br/> 0xad <br/> 2 @; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CHECKMULTISIG <br/> 0xae <br/> 2n+2 @; 1<br />
| style="border:3px solid #808080; background-color:#a0d0ff;" | _CHECKMULTISIGVERIFY <br/> 0xaf <br/> 2n+2 @; 0/1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP1 <br/> 0xb0 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP2 <br/> 0xb1 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP3 <br/> 0xb2 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP4 <br/> 0xb3 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP5 <br/> 0xb4 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP6 <br/> 0xb5 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP7 <br/> 0xb6 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP8 <br/> 0xb7 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP9 <br/> 0xb8 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP10 <br/> 0xb9 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xba <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbe <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xca <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xce <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xda <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xde <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xea <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xeb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xec <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xed <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xee <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xef <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xfa <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _SMALLINTEGER <br/> 0xfb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEYS <br/> 0xfc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEYHASH <br/> 0xfd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEY <br/> 0xfe <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _INVALIDOPCODE <br/> 0xff <br/><br />
|}<br><br />
Except later pseudo-opcode changes, the definition of OP_NOP1 - OP_NOP10 and the change of the evaluation of OP_RETURN (did no invalidation previously) which both occured in bitcoin version 0.3.6 in July 2010 were the last changes regarding opcodes <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.2.0/bitcoin-0.2.0-linux.tar.gz file src/srcipt.cpp in bitcoin-0.2.0]</ref> <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.3.3/bitcoin-0.3.3-linux.tar.gz file src/srcipt.cpp in bitcoin-0.3.3]</ref> <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.3.6/bitcoin-0.3.6-linux.tar.gz file src/srcipt.cpp in bitcoin-0.3.6]</ref>.<br />
<br />
== Opcode descriptions ==<br />
It follows for each opcode less than decimal 185 (hexa 0xba) a description for its usage. The columns entitled ''nemonic'', ''decimal'' and ''Hex'' should be evident. The column ''input'' gives the needed items of the stack (and the alternate stack) and the column ''output'' indicates the resulting items on the stack (and the alternate stack). '''Stack-top is always the right most item.''' The naming of the entries in these two columns is chosen to reflect their interpretation. ''x'', ''x0'', ''x1'', ... means arbitrary or no interpretation, ''i0'', ''i1'' and ''i2'' a signed integer value, ''n'',''index'',''size'' and ''depth'' non-negative (unsigned) integer values, ''Boolean'' as either a true or false.<br><br />
<br />
Some of the more complicated opcodes are disabled since version 0.3.10 out of concern that the client might have a bug in the current implementation due to the historically not as 2-complement interpretations of the byte vectors as numerical values (the most significant byte holds the sign of the byte vectors). Furthermore how some of theses opcodes should work precisely is disputable.<br />
<br />
=== Push data from instruction onto stack ===<br />
<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_FALSE, OP_0<br />
|0<br />
|0x00<br />
|Nothing<br />
|Empty string<br />
|A byte vector of length 0 is pushed onto the stack. (Thus, it is not a no-op!)<br />
|-<br />
|(no official nemonics)<br />
|1 - 75<br />
|0x01 - 0x4b<br />
|(operand)<br />
|x<br />
|The next <opcode>-many bytes are to be pushed onto the stack.<br />
|-<br />
|OP_PUSHDATA1<br />
|76<br />
|0x4c<br />
|(operands)<br />
|x<br />
|The next byte contains the number of bytes to be pushed onto the stack which follow this byte.<br />
|-<br />
|OP_PUSHDATA2<br />
|77<br />
|0x4d<br />
|(operands)<br />
|x<br />
|The next two bytes contain the number of bytes to be pushed onto the stack which follow theses 2 bytes.<br />
|-<br />
|OP_PUSHDATA4<br />
|78<br />
|0x4e<br />
|(operands)<br />
|x<br />
|The next four bytes contain the number of bytes to be pushed onto the stack which follow theses 4 bytes.<br />
|-<br />
|OP_1NEGATE<br />
|79<br />
|0x4f<br />
|Nothing<br />
| -1<br />
|The byte with value -1 is pushed onto the stack.<br />
|-<br />
|OP_1, OP_TRUE<br />
|81<br />
|0x51<br />
|Nothing<br />
|1<br />
|The byte with value 1 is pushed onto the stack.<br />
|-<br />
|OP_2 - OP_16<br />
|82 - 96<br />
|0x52 - 0x60<br />
|Nothing<br />
|2-16<br />
|The byte with value <opcode>-80 (thus, one of 2 - 16) is pushed onto the stack.<br />
|}<br />
<br />
=== Flow control ===<br />
<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_NOP<br />
|97<br />
|0x61<br />
|Nothing<br />
|Nothing<br />
|Does nothing.<br />
|-<br />
|OP_IF<br />
|99<br />
|0x63<br />
|Boolean<br />
|Nothing<br />
|If the top stack value is not 0, the statements are executed. The top stack value is removed. Lead in a logcial ''<value> then [statements] [else [statements]] endif'' expression<br />
|-<br />
|OP_NOTIF<br />
|100<br />
|0x64<br />
|Boolean<br />
|Nothing<br />
|If the top stack value is 0, the statements are executed. The top stack value is removed. Lead in a logcial ''<value> then [statements] [else [statements]] endif'' expression <br />
|-<br />
|OP_ELSE<br />
|103<br />
|0x67<br />
|Nothing<br />
|Nothing<br />
|If the preceeding OP_IF or OP_NOTIF or OP_ELSE was not executed then these statements are and if the preceding OP_IF or OP_NOTIF or OP_ELSE was executed then these statements are not. <br />
|-<br />
|OP_ENDIF<br />
|104<br />
|0x68<br />
|Nothing<br />
|Nothing<br />
|Ends a logcial ''If <value> then [statements] [else [statements]] '' expression<br />
|-<br />
|OP_VERIFY<br />
|105<br />
|0x69<br />
|Boolean<br />
|Nothing / False<br />
|If top stack value is not true then marks transaction as '''invalid''' . A value true is removed, but false is not.<br />
|-<br />
|OP_RETURN<br />
|106<br />
|0x6a<br />
|Nothing<br />
|Nothing<br />
|Marks transaction as '''invalid'''. <br />
|}<br />
<br />
===Stack item organization===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_TOALTSTACK<br />
|107<br />
|0x6b<br />
|x1 (alt)<br />
|(alt x1)<br />
|Puts the input onto the top of the alt stack. Removes it from the (main) stack.<br />
|-<br />
|OP_FROMALTSTACK<br />
|108<br />
|0x6c<br />
|(alt x1)<br />
|x1 (alt)<br />
|Puts the input onto the top of the (main) stack. Removes it from the alt stack.<br />
|-<br />
|OP_2DROP<br />
|109<br />
|0x6d<br />
|x2 x1<br />
|Nothing<br />
|Removes the top two stack items.<br />
|-<br />
|OP_2DUP<br />
|110<br />
|0x6e<br />
|x2 x1<br />
|x2 x1 x2 x1<br />
|Duplicates the top two stack items.<br />
|-<br />
|OP_3DUP<br />
|111<br />
|0x6f<br />
|x3 x2 x1<br />
|x3 x2 x1 x3 x2 x1<br />
|Duplicates the top three stack items.<br />
|-<br />
|OP_2OVER<br />
|112<br />
|0x70<br />
|x4 x3 x2 x1<br />
|x4 x3 x2 x1 x4 x3<br />
|Copies the pair of items two spaces back in the stack to the front.<br />
|-<br />
|OP_2ROT<br />
|113<br />
|0x71<br />
|x6 x5 x4 x3 x2 x1<br />
|x4 x3 x2 x1 x6 x5<br />
|The fifth and sixth items back are moved to the top of the stack. Twotimes left rotate.<br />
|-<br />
|OP_2SWAP<br />
|114<br />
|0x72<br />
|x4 x3 x2 x1<br />
|x2 x1 x4 x3<br />
|Swaps the top two pairs of stack items.<br />
|-<br />
|OP_IFDUP<br />
|115<br />
|0x73<br />
|x1<br />
|x1 / x1 x1<br />
|If the top stack value is not 0, duplicate it.<br />
|-<br />
|OP_DEPTH<br />
|116<br />
|0x74<br />
|Nothing<br />
|depth<br />
|Puts the number of stack items onto the stack as one little-endian coded byte-vector<br />
|-<br />
|OP_DROP<br />
|117<br />
|0x75<br />
|x1<br />
|Nothing<br />
|Removes the top stack item.<br />
|-<br />
|OP_DUP<br />
|118<br />
|0x76<br />
|x1<br />
|x1 x1<br />
|Duplicates the top stack item.<br />
|-<br />
|OP_NIP<br />
|119<br />
|0x77<br />
|x2 x1<br />
|x1<br />
|Removes the second-to-top stack item.<br />
|-<br />
|OP_OVER<br />
|120<br />
|0x78<br />
|x2 x1<br />
|x2 x1 x2<br />
|Copies the second-to-top stack item to the top.<br />
|-<br />
|OP_PICK<br />
|121<br />
|0x79<br />
|xn ... x2 x1 x0 <n><br />
|xn ... x2 x1 x0 xn<br />
|<n> is removed and the item ''n'' back in the stack is copied to the top.<br />
|-<br />
|OP_ROLL<br />
|122<br />
|0x7a<br />
|xn ... x2 x1 x0 <n><br />
|... x2 x1 x0 xn<br />
|<n> is removed and the item ''n'' back in the stack is moved to the top.<br />
|-<br />
|OP_ROT<br />
|123<br />
|0x7b<br />
|x3 x2 x1<br />
|x2 x1 x3<br />
|The top three items on the stack are rotated to the left.<br />
|-<br />
|OP_SWAP<br />
|124<br />
|0x7c<br />
|x2 x1<br />
|x1 x2<br />
|The top two items on the stack are swapped resp. rotated.<br />
|-<br />
|OP_TUCK<br />
|125<br />
|0x7d<br />
|x2 x1<br />
|x1 x2 x1<br />
|The item at the top of the stack is copied and inserted before the second-to-top item.<br />
|}<br />
<br />
=== Splice ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_CAT<br />
|126<br />
|0x7e<br />
|x2 x1<br />
|out<br />
|Appends stack-top item at second-to top item. Concatenates two strings resp. byte vectors. ''Currently disabled.''<br />
|-<br />
|OP_SUBSTR<br />
|127<br />
|0x7f<br />
|x3 index size<br />
|out<br />
|Returns the section started at position <index> and of length <size> of a string resp. byte vector. ''Currently disabled.''<br />
|-<br />
|OP_LEFT<br />
|128<br />
|0x80<br />
|x2 index<br />
|out<br />
|Keeps only characters left of the specified point in second-to top item. ''Currently disabled.''<br />
|-<br />
|OP_RIGHT<br />
|129<br />
|0x81<br />
|x2 index<br />
|out<br />
|Keeps only characters right of the specified point in second-to top item. ''Currently disabled.''<br />
|-<br />
|OP_SIZE<br />
|130<br />
|0x82<br />
|x1<br />
|x1 size<br />
|Returns the length of the input string resp. byte vector resp. top-stack item.<br />
|}<br />
<br />
=== Bitwise logic ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_INVERT<br />
|131<br />
|0x83<br />
|x1<br />
|x0<br />
|Flips all of the bits in the input. ''Currently disabled.''<br />
|-<br />
|OP_AND<br />
|132<br />
|0x84<br />
|x2 x1<br />
|x0<br />
|Boolean ''and'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_OR<br />
|133<br />
|0x85<br />
|x2 x1<br />
|x0<br />
|Boolean ''or'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_XOR<br />
|134<br />
|0x86<br />
|x2 x1<br />
|x0<br />
|Boolean ''exclusive or'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_EQUAL<br />
|135<br />
|0x87<br />
|x2 x1<br />
|Boolean<br />
|Returns 1 if the inputs have the same length and are byte-wise equal, 0 otherwise.<br />
|-<br />
|OP_EQUALVERIFY<br />
|136<br />
|0x88<br />
|x2 x1<br />
|Nothing / false<br />
|Same as OP_EQUAL, but runs OP_VERIFY afterward.<br />
|}<br />
<br />
=== Arithmetic ===<br />
<br />
Since version 0.3.10 the implemented arithmetic opcodes are limited to maximal 4 byte vectors (|value| < 2^31), in version 0.3.6 up to 0.3.8 they were limited to 258 byte vectors and prior to 0.3.6 unrestricted.<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_1ADD<br />
|139<br />
|0x8b<br />
|i1<br />
|i0<br />
|1 is added to the input.<br />
|-<br />
|OP_1SUB<br />
|140<br />
|0x8c<br />
|i1<br />
|i0<br />
|1 is subtracted from the input.<br />
|-<br />
|OP_2MUL<br />
|141<br />
|0x8d<br />
|i1<br />
|i0<br />
|The input is multiplied by 2. ''Currently disabled.''<br />
|-<br />
|OP_2DIV<br />
|142<br />
|0x8e<br />
|i1<br />
|i0<br />
|The input is divided by 2 (round down). ''Currently disabled.''<br />
|-<br />
|OP_NEGATE<br />
|143<br />
|0x8f<br />
|i1<br />
|i0<br />
|The sign of the input is flipped. Numerically the value is multiplied by -1<br />
|-<br />
|OP_ABS<br />
|144<br />
|0x90<br />
|i1<br />
|i0<br />
|The input is negative, its sign is flipped.<br />
|-<br />
|OP_NOT<br />
|145<br />
|0x91<br />
|i1<br />
|Boolean<br />
|If the input is 0 or 1, it is flipped. Otherwise the output will be 0. Test whether its value equals 0<br />
|-<br />
|OP_0NOTEQUAL<br />
|146<br />
|0x92<br />
|i1<br />
|Boolean<br />
|Returns 0 if the input is 0. 1 otherwise. Test whether its value is unequal 0<br />
|-<br />
|OP_ADD<br />
|147<br />
|0x93<br />
|i2 i1<br />
|i0<br />
|stack-top i1 is added to i2.<br />
|-<br />
|OP_SUB<br />
|148<br />
|0x94<br />
|i2 i1<br />
|i0<br />
|stack-top i1 is subtracted from i2.<br />
|-<br />
|OP_MUL<br />
|149<br />
|0x95<br />
|i2 i1<br />
|i0<br />
|i2 is multiplied with stack-top i1. ''Currently disabled.''<br />
|-<br />
|OP_DIV<br />
|150<br />
|0x96<br />
|i2 i1<br />
|i0<br />
|i2 is divided by stack-top i1 (divisor should be not 0). ''Currently disabled.''<br />
|-<br />
|OP_MOD<br />
|151<br />
|0x97<br />
|i2 i1<br />
|i0<br />
|Returns the remainder after dividing i2 by stack-top i1 (divisor should be not 0). ''Currently disabled.''<br />
|-<br />
|OP_LSHIFT<br />
|152<br />
|0x98<br />
|i2 i1<br />
|i0<br />
|Shifts i2 left by i1 bits, preserving sign of i2 (i1 >= 0). ''Currently disabled.''<br />
|-<br />
|OP_RSHIFT<br />
|153<br />
|0x99<br />
|i2 i1<br />
|i0<br />
|Shifts i2 right by i1 bits, preserving sign of i2 (i1 >= 0). ''Currently disabled.''<br />
|-<br />
|OP_BOOLAND<br />
|154<br />
|0x9a<br />
|i2 i1<br />
|Boolean<br />
|If both i2 and i1 are not 0, the output is 1. Otherwise 0.<br />
|-<br />
|OP_BOOLOR<br />
|155<br />
|0x9b<br />
|i2 i1<br />
|Boolean<br />
|If i2 or i1 is not 0, the output is 1. Otherwise 0.<br />
|-<br />
|OP_NUMEQUAL<br />
|156<br />
|0x9c<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 and i1 are numerically equal, 0 otherwise.<br />
|-<br />
|OP_NUMEQUALVERIFY<br />
|157<br />
|0x9d<br />
|i2 i1<br />
|Nothing / False<br />
|Same as OP_NUMEQUAL, but runs OP_VERIFY afterward.<br />
|-<br />
|OP_NUMNOTEQUAL<br />
|158<br />
|0x9e<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 and i1 are numerically not equal, 0 otherwise.<br />
|-<br />
|OP_LESSTHAN<br />
|159<br />
|0x9f<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is less than stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_GREATERTHAN<br />
|160<br />
|0xa0<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is greater than stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_LESSTHANOREQUAL<br />
|161<br />
|0xa1<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is less than or equal to stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_GREATERTHANOREQUAL<br />
|162<br />
|0xa2<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is greater than or equal to stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_MIN<br />
|163<br />
|0xa3<br />
|i2 i1<br />
|i2 / i1<br />
|Returns the smaller of i2 and i1.<br />
|-<br />
|OP_MAX<br />
|164<br />
|0xa4<br />
|i2 i1<br />
|i2 / i1<br />
|Returns the larger of i2 and i1.<br />
|-<br />
|OP_WITHIN<br />
|165<br />
|0xa5<br />
|i3 i2 i1<br />
|Boolean<br />
|Returns 1 if i3 >= i2 and i3 < i1, 0 otherwise. Thus if i2 > i1 returns always 0.<br />
|}<br />
<br />
=== Crypto ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_RIPEMD160<br />
|166<br />
|0xa6<br />
|x<br />
|hash20<br />
|The input is hashed using RIPEMD-160.<br />
|-<br />
|OP_SHA1<br />
|167<br />
|0xa7<br />
|x<br />
|hash20<br />
|The input is hashed using SHA-1.<br />
|-<br />
|OP_SHA256<br />
|168<br />
|0xa8<br />
|x<br />
|hash32<br />
|The input is hashed using SHA-256.<br />
|-<br />
|OP_HASH160<br />
|169<br />
|0xa9<br />
|x<br />
|hash20<br />
|The input is hashed twice: first with SHA-256 and then with RIPEMD-160.<br />
|-<br />
|OP_HASH256<br />
|170<br />
|0xaa<br />
|x<br />
|hash32<br />
|The input is hashed two times with SHA-256.<br />
|-<br />
|OP_CODESEPARATOR<br />
|171<br />
|0xab<br />
|Nothing<br />
|Nothing<br />
|All of the signature checking opcodes will only match signatures to the data after the most recently-executed OP_CODESEPARATOR.<br />
|-<br />
|[[OP_CHECKSIG]]<br />
|172<br />
|0xac<br />
|sig pubkey<br />
|Boolean<br />
|The entire transaction's outputs, inputs, and script (from the most recently-executed OP_CODESEPARATOR to the end) are hashed. The signature used by OP_CHECKSIG must be a valid signature for a further, extern specified hash and the given public key. If it is, 1 is returned, 0 otherwise.<br />
|-<br />
|OP_CHECKSIGVERIFY<br />
|173<br />
|0xad<br />
|sig pubkey<br />
|Nothing / False<br />
|Same as OP_CHECKSIG, but OP_VERIFY is executed afterward.<br />
|-<br />
|OP_CHECKMULTISIG<br />
|174<br />
|0xae<br />
|sig1 sig2 ... <number of signatures> pub1 pub2 <number of public keys><br />
|Boolean<br />
|For each signature and public key pair, OP_CHECKSIG is executed. If more public keys than signatures are listed, some key/sig pairs can fail. All signatures need to match a public key. If all signatures are valid, 1 is returned, 0 otherwise. Due to a bug, one extra unused value is removed from the stack.<br />
|-<br />
|OP_CHECKMULTISIGVERIFY<br />
|175<br />
|0xaf<br />
|sig1 sig2 ... <number of signatures> pub1 pub2 ... <number of public keys><br />
|Nothing / False<br />
|Same as OP_CHECKMULTISIG, but OP_VERIFY is executed afterward.<br />
|}<br />
<br />
=== Expansion opcodes ===<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_NOP1-OP_NOP10<br />
|176-185<br />
|0xb0-0xb9<br />
|The opcode has no effect.<br />
|}<br />
<br />
=== Version opcodes ===<br />
Version opcodes are disabled since bitcoin 0.2.0 and should not be used (maybe reassigned in the future).<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_VER<br />
|98<br />
|0x62<br />
|Script evalution is triggered invalid (Formerly pushed the bitcoin-serialize version onto stack).<br />
|-<br />
|OP_VERIF<br />
|101<br />
|0x65<br />
|Script evalution is triggered invalid (Formerly top stack item was popped and =< compared to present version)<br />
|-<br />
|OP_VERNOTIF<br />
|102<br />
|0x66<br />
|Script evalution is triggered invalid (Formerly top stack item was popped and > compared to present version)<br />
|}<br />
<br />
=== Reserved opcodes ===<br />
Each opcode not assigned (currently also every opcode value > 185) is also reserved. Using any unassigned opcode triggers the script evaluation to be invalid.<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_RESERVED<br />
|80<br />
|0x50<br />
|Script evalution is triggered invalid-<br />
|-<br />
|OP_RESERVED1<br />
|137<br />
|0x89<br />
|Script evalution is triggered invalid.<br />
|-<br />
|OP_RESERVED2<br />
|138<br />
|0x8a<br />
|Script evalution is triggered invalid.<br />
|}<br />
<br />
===Pseudo-opcodes===<br />
These nemonics are used internally for assisting with transaction matching. They are invalid if used in actual scripts.<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_PUBKEYHASH<br />
|253<br />
|0xfd<br />
|Represents a public key hashed with OP_HASH160.<br />
|-<br />
|OP_PUBKEY<br />
|254<br />
|0xfe<br />
|Represents a public key compatible with OP_CHECKSIG.<br />
|-<br />
|OP_INVALIDOPCODE<br />
|255<br />
|0xff<br />
|Matches any opcode that is not yet assigned.<br />
|}<br />
<br />
==Scripts in bitcoin transactions==<br />
It follows a list of important (most occuring) scripts to see opcodes "at work". Keep in mind that all constants actually use the data-pushing instructions above. At start of a (transaction input) script evaluation, the stack is always empty. Currently less than 0.01 % of all txout-scripts / scriptPubKeys in the main block chain are not of the following two standard scripts.<br />
<br />
===Standard transaction to bitcoin address===<br />
<br />
scriptPubKey: OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG<br />
scriptSig: <sig> <pubKey><br />
<br />
To demonstrate how scripts look on the wire, here is a raw scriptPubKey:<br />
<pre> 76 A9 14<br />
OP_DUP OP_HASH160 Bytes to push<br />
<br />
89 AB CD EF AB BA AB BA AB BA AB BA AB BA AB BA AB BA AB BA 88 AC<br />
Data to push OP_EQUALVERIFY OP_CHECKSIG</pre><br />
<br />
Note: scriptSig is in the input of the spending transaction and scriptPubKey is in the output of the previously storing transaction, i.e. its "available bitcoins".<br />
<br />
Here is how each instruction is processed:<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
| <sig> <pubKey> OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| scriptSig and scriptPubKey are combined.<br />
|-<br />
|<sig> <pubKey><br />
| OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| Constants are added to the stack.<br />
|-<br />
|<sig> <pubKey> <pubKey><br />
| OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| Top stack item is duplicated.<br />
|-<br />
|<sig> <pubKey> <pubHashA><br />
|<pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG<br />
| Top stack item is hashed.<br />
|-<br />
|<sig> <pubKey> <pubHashA> <pubKeyHash><br />
|OP_EQUALVERIFY OP_CHECKSIG<br />
| Constant added.<br />
|-<br />
|<sig> <pubKey><br />
|OP_CHECKSIG<br />
| Equality is checked between the top two stack items.<br />
|-<br />
|true<br />
|Empty.<br />
|Signature is checked for top two stack items.<br />
|}<br />
<br />
===Transaction to IP address (and generation transaction)===<br />
<br />
scriptPubKey: <pubKey> OP_CHECKSIG<br />
scriptSig: <sig><br />
<br />
Checking process:<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
|<sig> <pubKey> OP_CHECKSIG<br />
|scriptSig and scriptPubKey are combined.<br />
|-<br />
|<sig> <pubKey><br />
| OP_CHECKSIG<br />
|Constants are added to the stack.<br />
|-<br />
|true<br />
|Empty.<br />
|Signature is checked for top two stack items.<br />
|}<br />
<br />
In the case of a '''coin generation transaction''' (the first transaction of each block), there is no scriptSig, resp. its code ("coinbase") is completly ignored for the transaction. Only the scriptPubKey is used.<br />
<br />
===Transaction with a message===<br />
<br />
It's possible to add arbitrary data to any transaction by just adding some data along with OP_DROP. <br />
scriptPubKey: <message> OP_DROP <pubKey> OP_CHECKSIG<br />
scriptSig: <sig><br />
<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
|<sig> <message> OP_DROP <pubKey> OP_CHECKSIG<br />
|<br />
|-<br />
|<sig><br />
|<message> OP_DROP <pubKey> OP_CHECKSIG<br />
|scriptSig added to the stack.<br />
|-<br />
|<sig> <message><br />
|OP_DROP <pubKey> OP_CHECKSIG<br />
|The message has been put.<br />
|-<br />
|<sig><br />
|<pubKey> OP_CHECKSIG<br />
|Top stack item has been removed.<br />
|-<br />
|<sig> <pubKey><br />
|OP_CHECKSIG<br />
|Checking signature against the public key.<br />
|-<br />
|true<br />
|Empty.<br />
|Stack holds the value of signature check now.<br />
|}<br />
<br />
===Examples of non standard transaction on Testnet===<br />
<br />
These two links below show a non standard transaction. It just prepends the hex of "bob" and the operation OP_DROP<br />
which just removes it. As you can see they can be spent as normal.<br />
<br />
Input non-std transaction:<br />
http://blockexplorer.com/testnet/t/6ttfeb55B1<br />
<br />
Spent by:<br />
http://blockexplorer.com/testnet/t/AFdRB1CHS3<br />
<br />
==Script validation==<br />
A script evaluation is considered invalid, if any of these conditions meets:<br><br />
<ul><br />
<li>the total size of the script exceeds (currently) 10000 bytes<br />
<li>there are more than (currently) 201 opcodes of opcode value > 0x60 in the script<br />
<li>each instruction is (currently) limited to maximal 520 bytes. This effects only the opcodes OP_PUSHDATA2 and OP_PUSHDATA4<br />
<li>the executed opcode of the script has insufficient input (from stack, from script or from anywhere)<br />
<li>the opcode is not defined (for execution) - indicated by white or light gray background color in the table<br />
<li>the opcode is disabled (currently 15 opcodes) - indicated by white font color in the opcode overview matrix<br />
<li>stack overflow occurs during execution of the opcode (currently the number of items on the stack and on the alternate stack is limited to 1000)<br />
<li>the opcodes OP_VERIF and OP_NOTVERIF invalidate a script which contains this opcode (even if this opcode is not executed!)<br />
<li>the opcodes OP_ELSE or OP_ENDIF has no matching OP_IF<br><br />
<li>the script execution has been finished but there is (at least) an unmatched OP_IF<br><br />
<li>the opcodes OP_VERIFY, OP_EQUALVERIFY, OP_NUMEQUALVERIFY, OP_CHECKSIGVERIFY and OP_CHECKMULTISIGVERIFY invalidate the script if the stack-top item is false<br />
<li>the execution of OP_RETURN<br />
<!--li>alt stack overflow occurs (only possible during execution of OP_TOALTSTACK)--><br />
<li>the numerical value of the top-stack item is negative or greater than the number of items - 2 on the stack if OP_PICK or OP_ROLL shall be executed<br />
<li>an item used as public key or signature for each of the opcodes OP_CHECKSIG, OP_CHECKSIGVERIFY, OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY can be neither a public key or signature (for the given hash)<br />
<li>the number of signature items or the number of public key items on the stack is negative for OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY<br />
<li>there or more signatures items than public key items on the stack for OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY<br />
<li>there are (currently) more than 20 public key items on the stack for OP_CHECKMULTISIG or CHECKMULTISIGVERIFY<br />
<li>the sum of opcodes > 0x60 and the number of public keys in all executed OP_CHECKMULTISIG or CHECKMULTISIGVERIFY exceeds (currently) 201<br />
<li>the script execution has been finished and the stack is empty or the top-stack item is false (numerical value 0)<br />
</ul><br />
else the script evaluation is considered to be valid.<ref>[http://sourceforge.net/projects/bitcoin/files/Bitcoin/bitcoin-0.7.1/bitcoin-0.7.1-linux.tar.gz file src/src/script.cpp in bitcoin-0.7.1]</ref><br />
'''If invalidation of a script is triggered then the script is immediately finished.''' These arbitrary looking limitations of 10000, 201, 520, 1000 and 20 might be increased in the future -- they serve to prevent strong slow down of the evaluation of a script while not restricting its practical usage really.<br />
<br />
==Withdrawn and drafted opcodes==<br />
<br />
<ul><br />
<li> byte value 0x89 OP_NOTEQUAL defined in pre-0.1.0 bitcoin versions. Since 0.1.0 removed because of security concerns. <br />
<li> byte value 0xb1 [[BIP 0012 | OP_EVAL]] withdraw - poll was triggered but insufficient support. <br />
<li> byte value 0xb2 [[BIP 0017 | OP_CHECKHASHVERIFY]] withdraw - poll was triggered but insufficient support.<br />
</ul><br />
<br />
==See Also==<br />
* [[Transactions]]<br />
* [[Contracts]]<br />
<br />
==References==<br />
<references/><br />
<ul><br />
<li>[http://www.zorinaq.com/pub/bitcoin-0.1.0.tgz file src/script.cpp in bitcoin-0.1.0]</li><br />
</ul><br />
[[Category:Technical]]<br />
[[Category:Vocabulary]]</div>
Smtp
https://en.bitcoin.it/w/index.php?title=Script&diff=34918
Script
2013-01-11T17:21:09Z
<p>Smtp: /* Arithmetic */</p>
<hr />
<div>Bitcoin uses a scripting system for [[transactions]]. [[Wikipedia:FORTH|Forth]]-like, Script is simple, stack-based, and processed from left to right. It is purposefully not Turing-complete, with no loops.<br />
<br />
A script is essentially a list of instructions recorded with each transaction that describe how the next person wanting to spend the Bitcoins being transferred can gain access to them.<br />
<br />
Scripts are big-endian and their sequences of bytes is interpreted as a sequence of opcodes with operands. Only opcodes with byte values less than 0x4f have additional operands.<br />
<br />
== Scripts and Bitcoin transactions ==<br />
The script for a typical Bitcoin transfer to destination Bitcoin address D simply encumbers future spending of the bitcoins with two things: the spender must provide<br />
# a public key that, when hashed, yields destination address D embedded in the script, and<br />
# a signature to show evidence of the private key corresponding to the public key just provided.<br />
<br />
Scripting provides the flexibility to change the parameters of what's needed to spend transferred Bitcoins. For example, the scripting system could be used to require two private keys, or a combination of several, or even no keys at all.<br />
<br />
A transaction is valid if nothing in the combined script triggers failure and the top stack item exists and is true (non-zero). The party who originally ''stored'' the Bitcoins now being spent, dictates the script operations that will occur ''last'' in order to release them for use in another transaction. The party wanting to spend them must provide the input(s) to the previously recorded script that results in those operations occurring last leaving behind true (non-zero) on the stack.<br><br />
Only the very first transaction in each bitcoin block has no input script (the entry there is called "coinbase"), because the Bitcoins created with the block are created from hot air and not released by a previous recorded txout-script.<br />
<br />
== Stack ==<br />
<br />
The stacks hold byte vectors (there is the (main) stack and an alternative stack). Byte vectors are interpreted as little-endian variable-length integers with the most significant bit determining the sign of the integer. Thus 0x81 represents -1. 0x80 is another representation of zero (so called negative 0). Byte vectors are interpreted as Booleans where False is represented by any representation of zero, and True is represented by any representation of non-zero.<br />
<br />
== Opcode overview ==<br />
<br />
For each opcode is given: its nemonic without the leading OP_, its hexadecimal byte value, the number of stack items needed (poped) during execution, a semicolon and the number of stack items which has been pushed (after execution). A * after the needed stack items indicates that further bytes from the script following the current opcode are needed. A # indicates that items on the alternative stack are poped/pushed. A @ indicates that further (global) data from the transaction is needed. A / indicates alternatives of a value. <br/><br />
Different colors indicate different semantic execution groups of opcodes:<br />
{| style="background:none; font-size:100%; padding:0; border-collapse:collapse; text-align:center; line-height:2em;" border="0" align="center" <br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | copy a fixed number of bytes but at most 75 onto stack<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | copy bytes onto stack which number is given by a 1, 2 or 4 byte value.<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | copy 1 specific byte onto stack<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | undefined opcode<br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | a pseudo-opcode, unassigned for scripts<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | NOP or opcode is part of a IF-flow-control construction<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00ff00;" | (stack conditionally) invalidation of the script this opcode is part of<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | stack item is moved between main stack and alternate stack<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | stack item(s) is/are moved, copied or deleted<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0;" | byte vectors are appended or divided or their size is determined<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff;" | byte vectors are interpreted bit-position-independently<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | byte vectors are interpreted and processed as signed integers<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | a hash value is computed or a signature checked<br />
|}<br />
<p><br />
===Opcode byte-matrix===<br />
The opcode value 0x00 with nemonic OP_FALSE is also named OP_0 and the opcode value 0x51 with nemonic OP_1 as also named OP_TRUE.<br />
{| style="background:none; font-size:100%; padding:0; border-collapse:collapse; text-align:center; line-height:2em;" border="0" align="center" <br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" |_FALSE<br/> 0x00 <br/> 0 ; 1(0) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x01<br/> 0 *; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x02<br/> 0 *; 1(2)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x03<br/> 0 *; 1(3)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x04<br/> 0 *; 1(4)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x04<br/> 0 *; 1(5)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x06<br/> 0 *; 1(6)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x07<br/> 0 *; 1(7)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x08<br/> 0 *; 1(8)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x09<br/> 0 *; 1(9)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0a<br/> 0 *; 1(10)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0b<br/> 0 *; 1(11)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0c<br/> 0 *; 1(12)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0d<br/> 0 *; 1(13)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0e<br/> 0 *; 1(14)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0f<br/> 0 *; 1(15)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x10 <br/> 0 *; 1(16) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x11 <br/> 0 *; 1(17)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x12 <br/> 0 *; 1(18)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x13 <br/> 0 *; 1(19)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x14 <br/> 0 *; 1(20)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x15 <br/> 0 *; 1(21)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x16 <br/> 0 *; 1(22)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x17 <br/> 0 *; 1(23)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x18 <br/> 0 *; 1(24)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x19 <br/> 0 *; 1(25)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1a <br/> 0 *; 1(26)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1b <br/> 0 *; 1(27)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1c <br/> 0 *; 1(28)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1d <br/> 0 *; 1(29)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1e <br/> 0 *; 1(30)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1f <br/> 0 *; 1(31)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x20 <br/> 0 *; 1(32) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x21 <br/> 0 *; 1(33)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x22 <br/> 0 *; 1(34)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x23 <br/> 0 *; 1(35)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x24 <br/> 0 *; 1(36)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x25 <br/> 0 *; 1(37)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x26 <br/> 0 *; 1(38)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x27 <br/> 0 *; 1(39)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x28 <br/> 0 *; 1(40)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x29 <br/> 0 *; 1(41)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2a <br/> 0 *; 1(42)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2b <br/> 0 *; 1(43)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2c <br/> 0 *; 1(44)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2d <br/> 0 *; 1(45)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2e <br/> 0 *; 1(46)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2f <br/> 0 *; 1(47)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x30 <br/> 0 *; 1(48) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x31 <br/> 0 *; 1(49)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x32 <br/> 0 *; 1(50)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x33 <br/> 0 *; 1(51)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x34 <br/> 0 *; 1(52)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x35 <br/> 0 *; 1(53)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x36 <br/> 0 *; 1(54)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x37 <br/> 0 *; 1(55)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x38 <br/> 0 *; 1(56)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x39 <br/> 0 *; 1(57)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3a <br/> 0 *; 1(58)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3b <br/> 0 *; 1(59)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3c <br/> 0 *; 1(60)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3d <br/> 0 *; 1(61)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3e <br/> 0 *; 1(62)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3f <br/> 0 *; 1(63)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x40 <br/> 0 *; 1(64) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x41 <br/> 0 *; 1(65)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x42 <br/> 0 *; 1(66)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x43 <br/> 0 *; 1(67)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x44 <br/> 0 *; 1(68)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x45 <br/> 0 *; 1(69)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x46 <br/> 0 *; 1(70)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x47 <br/> 0 *; 1(71)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x48 <br/> 0 *; 1(72)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x49 <br/> 0 *; 1(73)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x4a <br/> 0 *; 1(74)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x4b <br/> 0 *; 1(75)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA1 <br/> 0x4c <br/> 0 *; 1(0 - 255)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA2 <br/> 0x4d <br/> 0 *; 1(0 - 2^16-1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA4 <br/> 0x4e <br/> 0 *; 1(0 - 2^32-1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _1NEGATE <br/> 0x4f <br/> 0 ; 1(1)<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED <br/> 0x50 <br/> <br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _1 <br/> 0x51 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _2 <br/> 0x52 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _3 <br/> 0x53 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _4 <br/> 0x54 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _5 <br/> 0x55 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _6 <br/> 0x56 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _7 <br/> 0x57 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _8 <br/> 0x58 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _9 <br/> 0x59 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _10 <br/> 0x5a <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _11 <br/> 0x5b <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _12 <br/> 0x5c <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _13 <br/> 0x5d <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _14 <br/> 0x5e <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _15 <br/> 0x5f <br/> 0 ; 1(1)<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _16 <br/> 0x60 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP <br/> 0x61 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VER <br/> 0x62 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _IF <br/> 0x63 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOTIF <br/> 0x64 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VERIF <br/> 0x65 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VERNOTIF <br/> 0x66 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _ELSE <br/> 0x67 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _ENDIF <br/> 0x68 <br/> 0 ; 0<br />
| style="border:3px solid #808080; background-color:#00ff00;" | _VERIFY <br/> 0x69 <br/> 1 ; 0/1<br />
| style="border:3px solid #808080; background-color:#00ff00;" | _RETURN <br/> 0x6a <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | _TOALTSTACK <br/> 0x6b <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | _FROMALTSTACK <br/> 0x6c <br/> 0 #; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2DROP <br/> 0x6d <br/> 2 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2DUP <br/> 0x6e <br/> 2 ; 4<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _3DUP <br/> 0x6f <br/> 3 ; 6<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2OVER <br/> 0x70 <br/> 4 ; 6<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2ROT <br/> 0x71 <br/> 6 ; 6<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2SWAP <br/> 0x72 <br/> 4 ; 4<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _IFDUP <br/> 0x73 <br/> 1 ; 1/2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DEPTH <br/> 0x74 <br/> 0 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DROP <br/> 0x75 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DUP <br/> 0x76 <br/> 1 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _NIP <br/> 0x77 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _OVER <br/> 0x78 <br/> 2 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _PICK <br/> 0x79 <br/> 1+n+1 ; n+2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _ROLL <br/> 0x7a <br/> 1+n+1 ; n+1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _ROT <br/> 0x7b <br/> 3 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _SWAP <br/> 0x7c <br/> 2 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _TUCK <br/> 0x7d <br/> 2 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _CAT <br/> 0x7e <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _SUBSTR <br/> 0x7f <br/> 3 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _LEFT <br/> 0x80 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _RIGHT <br/> 0x81 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0;" | _SIZE <br/> 0x82 <br/> 1 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _INVERT <br/> 0x83 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _AND <br/> 0x84 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _OR <br/> 0x85 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _XOR <br/> 0x86 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff;" | _EQUAL <br/> 0x87 <br/> 2 ; 1<br />
| style="border:3px solid #808080; background-color:#c080ff;" | _EQUALVERIFY <br/> 0x88 <br/> 2 ; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED1 <br/> 0x89 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED2 <br/> 0x8a <br/><br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _1ADD <br/> 0x8b <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _1SUB <br/> 0x8c <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _2MUL <br/> 0x8d <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _2DIV <br/> 0x8e <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NEGATE <br/> 0x8f <br/> 1 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _ABS <br/> 0x90 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NOT <br/> 0x91 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _0NOTEQUAL <br/> 0x92 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _ADD <br/> 0x93 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _SUB <br/> 0x94 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _MUL <br/> 0x95 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _DIV <br/> 0x96 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _MOD <br/> 0x97 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _LSHIFT <br/> 0x98 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _RSHIFT <br/> 0x99 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _BOOLAND <br/> 0x9a <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _BOOLOR <br/> 0x9b <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NUMEQUAL <br/> 0x9c <br/> 2 ; 1<br />
| style="border:3px solid #808080; background-color:#8080ff;" | _NUMEQUALVERIFY <br/> 0x9d <br/> 2 ; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NUMNOTEQUAL <br/> 0x9e <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _LESSTHAN <br/> 0x9f <br/> 2 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _GREATERTHAN <br/> 0xa0 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _LESSTHANOREQUAL <br/> 0xa1 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _GREATERTHANOREQUAL <br/> 0xa2 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _MIN <br/> 0xa3 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _MAX <br/> 0xa4 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _WITHIN <br/> 0xa5 <br/> 3 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _RIPEMD160 <br/> 0xa6 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _SHA1 <br/> 0xa7 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _SHA256 <br/> 0xa8 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _HASH160 <br/> 0xa9 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _HASH256 <br/> 0xaa <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CODESEPARATOR <br/> 0xab <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CHECKSIG <br/> 0xac <br/> 2 @; 1<br />
| style="border:3px solid #808080; background-color:#a0d0ff;" | _CHECKSIGVERIFY <br/> 0xad <br/> 2 @; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CHECKMULTISIG <br/> 0xae <br/> 2n+2 @; 1<br />
| style="border:3px solid #808080; background-color:#a0d0ff;" | _CHECKMULTISIGVERIFY <br/> 0xaf <br/> 2n+2 @; 0/1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP1 <br/> 0xb0 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP2 <br/> 0xb1 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP3 <br/> 0xb2 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP4 <br/> 0xb3 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP5 <br/> 0xb4 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP6 <br/> 0xb5 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP7 <br/> 0xb6 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP8 <br/> 0xb7 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP9 <br/> 0xb8 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP10 <br/> 0xb9 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xba <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbe <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xca <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xce <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xda <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xde <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xea <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xeb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xec <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xed <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xee <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xef <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xfa <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _SMALLINTEGER <br/> 0xfb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEYS <br/> 0xfc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEYHASH <br/> 0xfd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEY <br/> 0xfe <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _INVALIDOPCODE <br/> 0xff <br/><br />
|}<br><br />
Except later pseudo-opcode changes, the definition of OP_NOP1 - OP_NOP10 and the change of the evaluation of OP_RETURN (did no invalidation previously) which both occured in bitcoin version 0.3.6 in July 2010 were the last changes regarding opcodes <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.2.0/bitcoin-0.2.0-linux.tar.gz file src/srcipt.cpp in bitcoin-0.2.0]</ref> <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.3.3/bitcoin-0.3.3-linux.tar.gz file src/srcipt.cpp in bitcoin-0.3.3]</ref> <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.3.6/bitcoin-0.3.6-linux.tar.gz file src/srcipt.cpp in bitcoin-0.3.6]</ref>.<br />
<br />
== Opcode descriptions ==<br />
It follows for each opcode less than decimal 185 (hexa 0xba) a description for its usage. The columns entitled ''nemonic'', ''decimal'' and ''Hex'' should be evident. The column ''input'' gives the needed items of the stack (and the alternate stack) and the column ''output'' indicates the resulting items on the stack (and the alternate stack). '''Stack-top is always the right most item.''' The naming of the entries in these two columns is chosen to reflect their interpretation. ''x'', ''x0'', ''x1'', ... means arbitrary or no interpretation, ''i0'', ''i1'' and ''i2'' a signed integer value, ''n'',''index'',''size'' and ''depth'' non-negative (unsigned) integer values, ''Boolean'' as either a true or false.<br><br />
<br />
Some of the more complicated opcodes are disabled since version 0.3.10 out of concern that the client might have a bug in the current implementation due to the historically not as 2-complement interpretations of the byte vectors as numerical values (the most significant byte holds the sign of the byte vectors). Furthermore how some of theses opcodes should work precisely is disputable.<br />
<br />
=== Push data from instruction onto stack ===<br />
<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_FALSE, OP_0<br />
|0<br />
|0x00<br />
|Nothing<br />
|Empty string<br />
|A byte vector of length 0 is pushed onto the stack. (Thus, it is not a no-op!)<br />
|-<br />
|(no official nemonics)<br />
|1 - 75<br />
|0x01 - 0x4b<br />
|(operand)<br />
|x<br />
|The next <opcode>-many bytes are to be pushed onto the stack.<br />
|-<br />
|OP_PUSHDATA1<br />
|76<br />
|0x4c<br />
|(operands)<br />
|x<br />
|The next byte contains the number of bytes to be pushed onto the stack which follow this byte.<br />
|-<br />
|OP_PUSHDATA2<br />
|77<br />
|0x4d<br />
|(operands)<br />
|x<br />
|The next two bytes contain the number of bytes to be pushed onto the stack which follow theses 2 bytes.<br />
|-<br />
|OP_PUSHDATA4<br />
|78<br />
|0x4e<br />
|(operands)<br />
|x<br />
|The next four bytes contain the number of bytes to be pushed onto the stack which follow theses 4 bytes.<br />
|-<br />
|OP_1NEGATE<br />
|79<br />
|0x4f<br />
|Nothing<br />
| -1<br />
|The byte with value -1 is pushed onto the stack.<br />
|-<br />
|OP_1, OP_TRUE<br />
|81<br />
|0x51<br />
|Nothing<br />
|1<br />
|The byte with value 1 is pushed onto the stack.<br />
|-<br />
|OP_2 - OP_16<br />
|82 - 96<br />
|0x52 - 0x60<br />
|Nothing<br />
|2-16<br />
|The byte with value <opcode>-80 (thus, one of 2 - 16) is pushed onto the stack.<br />
|}<br />
<br />
=== Flow control ===<br />
<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_NOP<br />
|97<br />
|0x61<br />
|Nothing<br />
|Nothing<br />
|Does nothing.<br />
|-<br />
|OP_IF<br />
|99<br />
|0x63<br />
|Boolean<br />
|Nothing<br />
|If the top stack value is not 0, the statements are executed. The top stack value is removed. Lead in a logcial ''<value> then [statements] [else [statements]] endif'' expression<br />
|-<br />
|OP_NOTIF<br />
|100<br />
|0x64<br />
|Boolean<br />
|Nothing<br />
|If the top stack value is 0, the statements are executed. The top stack value is removed. Lead in a logcial ''<value> then [statements] [else [statements]] endif'' expression <br />
|-<br />
|OP_ELSE<br />
|103<br />
|0x67<br />
|Nothing<br />
|Nothing<br />
|If the preceeding OP_IF or OP_NOTIF or OP_ELSE was not executed then these statements are and if the preceding OP_IF or OP_NOTIF or OP_ELSE was executed then these statements are not. <br />
|-<br />
|OP_ENDIF<br />
|104<br />
|0x68<br />
|Nothing<br />
|Nothing<br />
|Ends a logcial ''If <value> then [statements] [else [statements]] '' expression<br />
|-<br />
|OP_VERIFY<br />
|105<br />
|0x69<br />
|Boolean<br />
|Nothing / False<br />
|If top stack value is not true then marks transaction as '''invalid''' . A value true is removed, but false is not.<br />
|-<br />
|OP_RETURN<br />
|106<br />
|0x6a<br />
|Nothing<br />
|Nothing<br />
|Marks transaction as '''invalid'''. <br />
|}<br />
<br />
===Stack item organization===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_TOALTSTACK<br />
|107<br />
|0x6b<br />
|x1 (alt)<br />
|(alt x1)<br />
|Puts the input onto the top of the alt stack. Removes it from the (main) stack.<br />
|-<br />
|OP_FROMALTSTACK<br />
|108<br />
|0x6c<br />
|(alt x1)<br />
|x1 (alt)<br />
|Puts the input onto the top of the (main) stack. Removes it from the alt stack.<br />
|-<br />
|OP_2DROP<br />
|109<br />
|0x6d<br />
|x2 x1<br />
|Nothing<br />
|Removes the top two stack items.<br />
|-<br />
|OP_2DUP<br />
|110<br />
|0x6e<br />
|x2 x1<br />
|x2 x1 x2 x1<br />
|Duplicates the top two stack items.<br />
|-<br />
|OP_3DUP<br />
|111<br />
|0x6f<br />
|x3 x2 x1<br />
|x3 x2 x1 x3 x2 x1<br />
|Duplicates the top three stack items.<br />
|-<br />
|OP_2OVER<br />
|112<br />
|0x70<br />
|x4 x3 x2 x1<br />
|x4 x3 x2 x1 x4 x3<br />
|Copies the pair of items two spaces back in the stack to the front.<br />
|-<br />
|OP_2ROT<br />
|113<br />
|0x71<br />
|x6 x5 x4 x3 x2 x1<br />
|x4 x3 x2 x1 x6 x5<br />
|The fifth and sixth items back are moved to the top of the stack. Twotimes left rotate.<br />
|-<br />
|OP_2SWAP<br />
|114<br />
|0x72<br />
|x4 x3 x2 x1<br />
|x2 x1 x4 x3<br />
|Swaps the top two pairs of stack items.<br />
|-<br />
|OP_IFDUP<br />
|115<br />
|0x73<br />
|x1<br />
|x1 / x1 x1<br />
|If the top stack value is not 0, duplicate it.<br />
|-<br />
|OP_DEPTH<br />
|116<br />
|0x74<br />
|Nothing<br />
|depth<br />
|Puts the number of stack items onto the stack as one little-endian coded byte-vector<br />
|-<br />
|OP_DROP<br />
|117<br />
|0x75<br />
|x1<br />
|Nothing<br />
|Removes the top stack item.<br />
|-<br />
|OP_DUP<br />
|118<br />
|0x76<br />
|x1<br />
|x1 x1<br />
|Duplicates the top stack item.<br />
|-<br />
|OP_NIP<br />
|119<br />
|0x77<br />
|x2 x1<br />
|x1<br />
|Removes the second-to-top stack item.<br />
|-<br />
|OP_OVER<br />
|120<br />
|0x78<br />
|x2 x1<br />
|x2 x1 x2<br />
|Copies the second-to-top stack item to the top.<br />
|-<br />
|OP_PICK<br />
|121<br />
|0x79<br />
|xn ... x2 x1 x0 <n><br />
|xn ... x2 x1 x0 xn<br />
|<n> is removed and the item ''n'' back in the stack is copied to the top.<br />
|-<br />
|OP_ROLL<br />
|122<br />
|0x7a<br />
|xn ... x2 x1 x0 <n><br />
|... x2 x1 x0 xn<br />
|<n> is removed and the item ''n'' back in the stack is moved to the top.<br />
|-<br />
|OP_ROT<br />
|123<br />
|0x7b<br />
|x3 x2 x1<br />
|x2 x1 x3<br />
|The top three items on the stack are rotated to the left.<br />
|-<br />
|OP_SWAP<br />
|124<br />
|0x7c<br />
|x2 x1<br />
|x1 x2<br />
|The top two items on the stack are swapped resp. rotated.<br />
|-<br />
|OP_TUCK<br />
|125<br />
|0x7d<br />
|x2 x1<br />
|x1 x2 x1<br />
|The item at the top of the stack is copied and inserted before the second-to-top item.<br />
|}<br />
<br />
=== Splice ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_CAT<br />
|126<br />
|0x7e<br />
|x2 x1<br />
|out<br />
|Appends stack-top item at second-to top item. Concatenates two strings resp. byte vectors. ''Currently disabled.''<br />
|-<br />
|OP_SUBSTR<br />
|127<br />
|0x7f<br />
|x3 index size<br />
|out<br />
|Returns the section started at position <index> and of length <size> of a string resp. byte vector. ''Currently disabled.''<br />
|-<br />
|OP_LEFT<br />
|128<br />
|0x80<br />
|x2 index<br />
|out<br />
|Keeps only characters left of the specified point in second-to top item. ''Currently disabled.''<br />
|-<br />
|OP_RIGHT<br />
|129<br />
|0x81<br />
|x2 index<br />
|out<br />
|Keeps only characters right of the specified point in second-to top item. ''Currently disabled.''<br />
|-<br />
|OP_SIZE<br />
|130<br />
|0x82<br />
|x1<br />
|x1 size<br />
|Returns the length of the input string resp. byte vector resp. top-stack item.<br />
|}<br />
<br />
=== Bitwise logic ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_INVERT<br />
|131<br />
|0x83<br />
|x1<br />
|x0<br />
|Flips all of the bits in the input. ''Currently disabled.''<br />
|-<br />
|OP_AND<br />
|132<br />
|0x84<br />
|x2 x1<br />
|x0<br />
|Boolean ''and'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_OR<br />
|133<br />
|0x85<br />
|x2 x1<br />
|x0<br />
|Boolean ''or'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_XOR<br />
|134<br />
|0x86<br />
|x2 x1<br />
|x0<br />
|Boolean ''exclusive or'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_EQUAL<br />
|135<br />
|0x87<br />
|x2 x1<br />
|Boolean<br />
|Returns 1 if the inputs have the same length and are byte-wise equal, 0 otherwise.<br />
|-<br />
|OP_EQUALVERIFY<br />
|136<br />
|0x88<br />
|x2 x1<br />
|Nothing / false<br />
|Same as OP_EQUAL, but runs OP_VERIFY afterward.<br />
|}<br />
<br />
=== Arithmetic ===<br />
<br />
Since version 0.3.10 the implemented arithmetic opcodes are limited to maximal 4 byte vectors, in version 0.3.6 up to 0.3.8 they were limited to 258 byte vectors and prior to 0.3.6 unrestricted.<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_1ADD<br />
|139<br />
|0x8b<br />
|i1<br />
|i0<br />
|1 is added to the input.<br />
|-<br />
|OP_1SUB<br />
|140<br />
|0x8c<br />
|i1<br />
|i0<br />
|1 is subtracted from the input.<br />
|-<br />
|OP_2MUL<br />
|141<br />
|0x8d<br />
|i1<br />
|i0<br />
|The input is multiplied by 2. ''Currently disabled.''<br />
|-<br />
|OP_2DIV<br />
|142<br />
|0x8e<br />
|i1<br />
|i0<br />
|The input is divided by 2 (round down). ''Currently disabled.''<br />
|-<br />
|OP_NEGATE<br />
|143<br />
|0x8f<br />
|i1<br />
|i0<br />
|The sign of the input is flipped. Numerically the value is multiplied by -1<br />
|-<br />
|OP_ABS<br />
|144<br />
|0x90<br />
|i1<br />
|i0<br />
|The input is negative, its sign is flipped.<br />
|-<br />
|OP_NOT<br />
|145<br />
|0x91<br />
|i1<br />
|Boolean<br />
|If the input is 0 or 1, it is flipped. Otherwise the output will be 0. Test whether its value equals 0<br />
|-<br />
|OP_0NOTEQUAL<br />
|146<br />
|0x92<br />
|i1<br />
|Boolean<br />
|Returns 0 if the input is 0. 1 otherwise. Test whether its value is unequal 0<br />
|-<br />
|OP_ADD<br />
|147<br />
|0x93<br />
|i2 i1<br />
|i0<br />
|stack-top i1 is added to i2.<br />
|-<br />
|OP_SUB<br />
|148<br />
|0x94<br />
|i2 i1<br />
|i0<br />
|stack-top i1 is subtracted from i2.<br />
|-<br />
|OP_MUL<br />
|149<br />
|0x95<br />
|i2 i1<br />
|i0<br />
|i2 is multiplied with stack-top i1. ''Currently disabled.''<br />
|-<br />
|OP_DIV<br />
|150<br />
|0x96<br />
|i2 i1<br />
|i0<br />
|i2 is divided by stack-top i1 (divisor should be not 0). ''Currently disabled.''<br />
|-<br />
|OP_MOD<br />
|151<br />
|0x97<br />
|i2 i1<br />
|i0<br />
|Returns the remainder after dividing i2 by stack-top i1 (divisor should be not 0). ''Currently disabled.''<br />
|-<br />
|OP_LSHIFT<br />
|152<br />
|0x98<br />
|i2 i1<br />
|i0<br />
|Shifts i2 left by i1 bits, preserving sign of i2 (i1 >= 0). ''Currently disabled.''<br />
|-<br />
|OP_RSHIFT<br />
|153<br />
|0x99<br />
|i2 i1<br />
|i0<br />
|Shifts i2 right by i1 bits, preserving sign of i2 (i1 >= 0). ''Currently disabled.''<br />
|-<br />
|OP_BOOLAND<br />
|154<br />
|0x9a<br />
|i2 i1<br />
|Boolean<br />
|If both i2 and i1 are not 0, the output is 1. Otherwise 0.<br />
|-<br />
|OP_BOOLOR<br />
|155<br />
|0x9b<br />
|i2 i1<br />
|Boolean<br />
|If i2 or i1 is not 0, the output is 1. Otherwise 0.<br />
|-<br />
|OP_NUMEQUAL<br />
|156<br />
|0x9c<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 and i1 are numerically equal, 0 otherwise.<br />
|-<br />
|OP_NUMEQUALVERIFY<br />
|157<br />
|0x9d<br />
|i2 i1<br />
|Nothing / False<br />
|Same as OP_NUMEQUAL, but runs OP_VERIFY afterward.<br />
|-<br />
|OP_NUMNOTEQUAL<br />
|158<br />
|0x9e<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 and i1 are numerically not equal, 0 otherwise.<br />
|-<br />
|OP_LESSTHAN<br />
|159<br />
|0x9f<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is less than stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_GREATERTHAN<br />
|160<br />
|0xa0<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is greater than stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_LESSTHANOREQUAL<br />
|161<br />
|0xa1<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is less than or equal to stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_GREATERTHANOREQUAL<br />
|162<br />
|0xa2<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is greater than or equal to stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_MIN<br />
|163<br />
|0xa3<br />
|i2 i1<br />
|i2 / i1<br />
|Returns the smaller of i2 and i1.<br />
|-<br />
|OP_MAX<br />
|164<br />
|0xa4<br />
|i2 i1<br />
|i2 / i1<br />
|Returns the larger of i2 and i1.<br />
|-<br />
|OP_WITHIN<br />
|165<br />
|0xa5<br />
|i3 i2 i1<br />
|Boolean<br />
|Returns 1 if i3 >= i2 and i3 < i1, 0 otherwise. Thus if i2 > i1 returns always 0.<br />
|}<br />
<br />
=== Crypto ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_RIPEMD160<br />
|166<br />
|0xa6<br />
|x<br />
|hash20<br />
|The input is hashed using RIPEMD-160.<br />
|-<br />
|OP_SHA1<br />
|167<br />
|0xa7<br />
|x<br />
|hash20<br />
|The input is hashed using SHA-1.<br />
|-<br />
|OP_SHA256<br />
|168<br />
|0xa8<br />
|x<br />
|hash32<br />
|The input is hashed using SHA-256.<br />
|-<br />
|OP_HASH160<br />
|169<br />
|0xa9<br />
|x<br />
|hash20<br />
|The input is hashed twice: first with SHA-256 and then with RIPEMD-160.<br />
|-<br />
|OP_HASH256<br />
|170<br />
|0xaa<br />
|x<br />
|hash32<br />
|The input is hashed two times with SHA-256.<br />
|-<br />
|OP_CODESEPARATOR<br />
|171<br />
|0xab<br />
|Nothing<br />
|Nothing<br />
|All of the signature checking opcodes will only match signatures to the data after the most recently-executed OP_CODESEPARATOR.<br />
|-<br />
|[[OP_CHECKSIG]]<br />
|172<br />
|0xac<br />
|sig pubkey<br />
|Boolean<br />
|The entire transaction's outputs, inputs, and script (from the most recently-executed OP_CODESEPARATOR to the end) are hashed. The signature used by OP_CHECKSIG must be a valid signature for a further, extern specified hash and the given public key. If it is, 1 is returned, 0 otherwise.<br />
|-<br />
|OP_CHECKSIGVERIFY<br />
|173<br />
|0xad<br />
|sig pubkey<br />
|Nothing / False<br />
|Same as OP_CHECKSIG, but OP_VERIFY is executed afterward.<br />
|-<br />
|OP_CHECKMULTISIG<br />
|174<br />
|0xae<br />
|sig1 sig2 ... <number of signatures> pub1 pub2 <number of public keys><br />
|Boolean<br />
|For each signature and public key pair, OP_CHECKSIG is executed. If more public keys than signatures are listed, some key/sig pairs can fail. All signatures need to match a public key. If all signatures are valid, 1 is returned, 0 otherwise. Due to a bug, one extra unused value is removed from the stack.<br />
|-<br />
|OP_CHECKMULTISIGVERIFY<br />
|175<br />
|0xaf<br />
|sig1 sig2 ... <number of signatures> pub1 pub2 ... <number of public keys><br />
|Nothing / False<br />
|Same as OP_CHECKMULTISIG, but OP_VERIFY is executed afterward.<br />
|}<br />
<br />
=== Expansion opcodes ===<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_NOP1-OP_NOP10<br />
|176-185<br />
|0xb0-0xb9<br />
|The opcode has no effect.<br />
|}<br />
<br />
=== Version opcodes ===<br />
Version opcodes are disabled since bitcoin 0.2.0 and should not be used (maybe reassigned in the future).<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_VER<br />
|98<br />
|0x62<br />
|Script evalution is triggered invalid (Formerly pushed the bitcoin-serialize version onto stack).<br />
|-<br />
|OP_VERIF<br />
|101<br />
|0x65<br />
|Script evalution is triggered invalid (Formerly top stack item was popped and =< compared to present version)<br />
|-<br />
|OP_VERNOTIF<br />
|102<br />
|0x66<br />
|Script evalution is triggered invalid (Formerly top stack item was popped and > compared to present version)<br />
|}<br />
<br />
=== Reserved opcodes ===<br />
Each opcode not assigned (currently also every opcode value > 185) is also reserved. Using any unassigned opcode triggers the script evaluation to be invalid.<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_RESERVED<br />
|80<br />
|0x50<br />
|Script evalution is triggered invalid-<br />
|-<br />
|OP_RESERVED1<br />
|137<br />
|0x89<br />
|Script evalution is triggered invalid.<br />
|-<br />
|OP_RESERVED2<br />
|138<br />
|0x8a<br />
|Script evalution is triggered invalid.<br />
|}<br />
<br />
===Pseudo-opcodes===<br />
These nemonics are used internally for assisting with transaction matching. They are invalid if used in actual scripts.<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_PUBKEYHASH<br />
|253<br />
|0xfd<br />
|Represents a public key hashed with OP_HASH160.<br />
|-<br />
|OP_PUBKEY<br />
|254<br />
|0xfe<br />
|Represents a public key compatible with OP_CHECKSIG.<br />
|-<br />
|OP_INVALIDOPCODE<br />
|255<br />
|0xff<br />
|Matches any opcode that is not yet assigned.<br />
|}<br />
<br />
==Scripts in bitcoin transactions==<br />
It follows a list of important (most occuring) scripts to see opcodes "at work". Keep in mind that all constants actually use the data-pushing instructions above. At start of a (transaction input) script evaluation, the stack is always empty. Currently less than 0.01 % of all txout-scripts / scriptPubKeys in the main block chain are not of the following two standard scripts.<br />
<br />
===Standard transaction to bitcoin address===<br />
<br />
scriptPubKey: OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG<br />
scriptSig: <sig> <pubKey><br />
<br />
To demonstrate how scripts look on the wire, here is a raw scriptPubKey:<br />
<pre> 76 A9 14<br />
OP_DUP OP_HASH160 Bytes to push<br />
<br />
89 AB CD EF AB BA AB BA AB BA AB BA AB BA AB BA AB BA AB BA 88 AC<br />
Data to push OP_EQUALVERIFY OP_CHECKSIG</pre><br />
<br />
Note: scriptSig is in the input of the spending transaction and scriptPubKey is in the output of the previously storing transaction, i.e. its "available bitcoins".<br />
<br />
Here is how each instruction is processed:<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
| <sig> <pubKey> OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| scriptSig and scriptPubKey are combined.<br />
|-<br />
|<sig> <pubKey><br />
| OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| Constants are added to the stack.<br />
|-<br />
|<sig> <pubKey> <pubKey><br />
| OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| Top stack item is duplicated.<br />
|-<br />
|<sig> <pubKey> <pubHashA><br />
|<pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG<br />
| Top stack item is hashed.<br />
|-<br />
|<sig> <pubKey> <pubHashA> <pubKeyHash><br />
|OP_EQUALVERIFY OP_CHECKSIG<br />
| Constant added.<br />
|-<br />
|<sig> <pubKey><br />
|OP_CHECKSIG<br />
| Equality is checked between the top two stack items.<br />
|-<br />
|true<br />
|Empty.<br />
|Signature is checked for top two stack items.<br />
|}<br />
<br />
===Transaction to IP address (and generation transaction)===<br />
<br />
scriptPubKey: <pubKey> OP_CHECKSIG<br />
scriptSig: <sig><br />
<br />
Checking process:<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
|<sig> <pubKey> OP_CHECKSIG<br />
|scriptSig and scriptPubKey are combined.<br />
|-<br />
|<sig> <pubKey><br />
| OP_CHECKSIG<br />
|Constants are added to the stack.<br />
|-<br />
|true<br />
|Empty.<br />
|Signature is checked for top two stack items.<br />
|}<br />
<br />
In the case of a '''coin generation transaction''' (the first transaction of each block), there is no scriptSig, resp. its code ("coinbase") is completly ignored for the transaction. Only the scriptPubKey is used.<br />
<br />
===Transaction with a message===<br />
<br />
It's possible to add arbitrary data to any transaction by just adding some data along with OP_DROP. <br />
scriptPubKey: <message> OP_DROP <pubKey> OP_CHECKSIG<br />
scriptSig: <sig><br />
<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
|<sig> <message> OP_DROP <pubKey> OP_CHECKSIG<br />
|<br />
|-<br />
|<sig><br />
|<message> OP_DROP <pubKey> OP_CHECKSIG<br />
|scriptSig added to the stack.<br />
|-<br />
|<sig> <message><br />
|OP_DROP <pubKey> OP_CHECKSIG<br />
|The message has been put.<br />
|-<br />
|<sig><br />
|<pubKey> OP_CHECKSIG<br />
|Top stack item has been removed.<br />
|-<br />
|<sig> <pubKey><br />
|OP_CHECKSIG<br />
|Checking signature against the public key.<br />
|-<br />
|true<br />
|Empty.<br />
|Stack holds the value of signature check now.<br />
|}<br />
<br />
===Examples of non standard transaction on Testnet===<br />
<br />
These two links below show a non standard transaction. It just prepends the hex of "bob" and the operation OP_DROP<br />
which just removes it. As you can see they can be spent as normal.<br />
<br />
Input non-std transaction:<br />
http://blockexplorer.com/testnet/t/6ttfeb55B1<br />
<br />
Spent by:<br />
http://blockexplorer.com/testnet/t/AFdRB1CHS3<br />
<br />
==Script validation==<br />
A script evaluation is considered invalid, if any of these conditions meets:<br><br />
<ul><br />
<li>the total size of the script exceeds (currently) 10000 bytes<br />
<li>there are more than (currently) 201 opcodes of opcode value > 0x60 in the script<br />
<li>each instruction is (currently) limited to maximal 520 bytes. This effects only the opcodes OP_PUSHDATA2 and OP_PUSHDATA4<br />
<li>the executed opcode of the script has insufficient input (from stack, from script or from anywhere)<br />
<li>the opcode is not defined (for execution) - indicated by white or light gray background color in the table<br />
<li>the opcode is disabled (currently 15 opcodes) - indicated by white font color in the opcode overview matrix<br />
<li>stack overflow occurs during execution of the opcode (currently the number of items on the stack and on the alternate stack is limited to 1000)<br />
<li>the opcodes OP_VERIF and OP_NOTVERIF invalidate a script which contains this opcode (even if this opcode is not executed!)<br />
<li>the opcodes OP_ELSE or OP_ENDIF has no matching OP_IF<br><br />
<li>the script execution has been finished but there is (at least) an unmatched OP_IF<br><br />
<li>the opcodes OP_VERIFY, OP_EQUALVERIFY, OP_NUMEQUALVERIFY, OP_CHECKSIGVERIFY and OP_CHECKMULTISIGVERIFY invalidate the script if the stack-top item is false<br />
<li>the execution of OP_RETURN<br />
<!--li>alt stack overflow occurs (only possible during execution of OP_TOALTSTACK)--><br />
<li>the numerical value of the top-stack item is negative or greater than the number of items - 2 on the stack if OP_PICK or OP_ROLL shall be executed<br />
<li>an item used as public key or signature for each of the opcodes OP_CHECKSIG, OP_CHECKSIGVERIFY, OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY can be neither a public key or signature (for the given hash)<br />
<li>the number of signature items or the number of public key items on the stack is negative for OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY<br />
<li>there or more signatures items than public key items on the stack for OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY<br />
<li>there are (currently) more than 20 public key items on the stack for OP_CHECKMULTISIG or CHECKMULTISIGVERIFY<br />
<li>the sum of opcodes > 0x60 and the number of public keys in all executed OP_CHECKMULTISIG or CHECKMULTISIGVERIFY exceeds (currently) 201<br />
<li>the script execution has been finished and the stack is empty or the top-stack item is false (numerical value 0)<br />
</ul><br />
else the script evaluation is considered to be valid.<ref>[http://sourceforge.net/projects/bitcoin/files/Bitcoin/bitcoin-0.7.1/bitcoin-0.7.1-linux.tar.gz file src/src/script.cpp in bitcoin-0.7.1]</ref><br />
'''If invalidation of a script is triggered then the script is immediately finished.''' These arbitrary looking limitations of 10000, 201, 520, 1000 and 20 might be increased in the future -- they serve to prevent strong slow down of the evaluation of a script while not restricting its practical usage really.<br />
<br />
==Withdrawn and drafted opcodes==<br />
<br />
<ul><br />
<li> byte value 0x89 OP_NOTEQUAL defined in pre-0.1.0 bitcoin versions. Since 0.1.0 removed because of security concerns. <br />
<li> byte value 0xb1 [[BIP 0012 | OP_EVAL]] withdraw - poll was triggered but insufficient support. <br />
<li> byte value 0xb2 [[BIP 0017 | OP_CHECKHASHVERIFY]] withdraw - poll was triggered but insufficient support.<br />
</ul><br />
<br />
==See Also==<br />
* [[Transactions]]<br />
* [[Contracts]]<br />
<br />
==References==<br />
<references/><br />
<ul><br />
<li>[http://www.zorinaq.com/pub/bitcoin-0.1.0.tgz file src/script.cpp in bitcoin-0.1.0]</li><br />
</ul><br />
[[Category:Technical]]<br />
[[Category:Vocabulary]]</div>
Smtp
https://en.bitcoin.it/w/index.php?title=Script&diff=34917
Script
2013-01-11T17:14:34Z
<p>Smtp: /* Opcode descriptions */</p>
<hr />
<div>Bitcoin uses a scripting system for [[transactions]]. [[Wikipedia:FORTH|Forth]]-like, Script is simple, stack-based, and processed from left to right. It is purposefully not Turing-complete, with no loops.<br />
<br />
A script is essentially a list of instructions recorded with each transaction that describe how the next person wanting to spend the Bitcoins being transferred can gain access to them.<br />
<br />
Scripts are big-endian and their sequences of bytes is interpreted as a sequence of opcodes with operands. Only opcodes with byte values less than 0x4f have additional operands.<br />
<br />
== Scripts and Bitcoin transactions ==<br />
The script for a typical Bitcoin transfer to destination Bitcoin address D simply encumbers future spending of the bitcoins with two things: the spender must provide<br />
# a public key that, when hashed, yields destination address D embedded in the script, and<br />
# a signature to show evidence of the private key corresponding to the public key just provided.<br />
<br />
Scripting provides the flexibility to change the parameters of what's needed to spend transferred Bitcoins. For example, the scripting system could be used to require two private keys, or a combination of several, or even no keys at all.<br />
<br />
A transaction is valid if nothing in the combined script triggers failure and the top stack item exists and is true (non-zero). The party who originally ''stored'' the Bitcoins now being spent, dictates the script operations that will occur ''last'' in order to release them for use in another transaction. The party wanting to spend them must provide the input(s) to the previously recorded script that results in those operations occurring last leaving behind true (non-zero) on the stack.<br><br />
Only the very first transaction in each bitcoin block has no input script (the entry there is called "coinbase"), because the Bitcoins created with the block are created from hot air and not released by a previous recorded txout-script.<br />
<br />
== Stack ==<br />
<br />
The stacks hold byte vectors (there is the (main) stack and an alternative stack). Byte vectors are interpreted as little-endian variable-length integers with the most significant bit determining the sign of the integer. Thus 0x81 represents -1. 0x80 is another representation of zero (so called negative 0). Byte vectors are interpreted as Booleans where False is represented by any representation of zero, and True is represented by any representation of non-zero.<br />
<br />
== Opcode overview ==<br />
<br />
For each opcode is given: its nemonic without the leading OP_, its hexadecimal byte value, the number of stack items needed (poped) during execution, a semicolon and the number of stack items which has been pushed (after execution). A * after the needed stack items indicates that further bytes from the script following the current opcode are needed. A # indicates that items on the alternative stack are poped/pushed. A @ indicates that further (global) data from the transaction is needed. A / indicates alternatives of a value. <br/><br />
Different colors indicate different semantic execution groups of opcodes:<br />
{| style="background:none; font-size:100%; padding:0; border-collapse:collapse; text-align:center; line-height:2em;" border="0" align="center" <br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | copy a fixed number of bytes but at most 75 onto stack<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | copy bytes onto stack which number is given by a 1, 2 or 4 byte value.<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | copy 1 specific byte onto stack<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | undefined opcode<br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | a pseudo-opcode, unassigned for scripts<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | NOP or opcode is part of a IF-flow-control construction<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00ff00;" | (stack conditionally) invalidation of the script this opcode is part of<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | stack item is moved between main stack and alternate stack<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | stack item(s) is/are moved, copied or deleted<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0;" | byte vectors are appended or divided or their size is determined<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff;" | byte vectors are interpreted bit-position-independently<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | byte vectors are interpreted and processed as signed integers<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | a hash value is computed or a signature checked<br />
|}<br />
<p><br />
===Opcode byte-matrix===<br />
The opcode value 0x00 with nemonic OP_FALSE is also named OP_0 and the opcode value 0x51 with nemonic OP_1 as also named OP_TRUE.<br />
{| style="background:none; font-size:100%; padding:0; border-collapse:collapse; text-align:center; line-height:2em;" border="0" align="center" <br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" |_FALSE<br/> 0x00 <br/> 0 ; 1(0) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x01<br/> 0 *; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x02<br/> 0 *; 1(2)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x03<br/> 0 *; 1(3)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x04<br/> 0 *; 1(4)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x04<br/> 0 *; 1(5)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x06<br/> 0 *; 1(6)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x07<br/> 0 *; 1(7)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x08<br/> 0 *; 1(8)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x09<br/> 0 *; 1(9)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0a<br/> 0 *; 1(10)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0b<br/> 0 *; 1(11)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0c<br/> 0 *; 1(12)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0d<br/> 0 *; 1(13)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0e<br/> 0 *; 1(14)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0f<br/> 0 *; 1(15)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x10 <br/> 0 *; 1(16) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x11 <br/> 0 *; 1(17)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x12 <br/> 0 *; 1(18)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x13 <br/> 0 *; 1(19)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x14 <br/> 0 *; 1(20)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x15 <br/> 0 *; 1(21)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x16 <br/> 0 *; 1(22)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x17 <br/> 0 *; 1(23)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x18 <br/> 0 *; 1(24)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x19 <br/> 0 *; 1(25)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1a <br/> 0 *; 1(26)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1b <br/> 0 *; 1(27)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1c <br/> 0 *; 1(28)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1d <br/> 0 *; 1(29)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1e <br/> 0 *; 1(30)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1f <br/> 0 *; 1(31)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x20 <br/> 0 *; 1(32) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x21 <br/> 0 *; 1(33)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x22 <br/> 0 *; 1(34)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x23 <br/> 0 *; 1(35)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x24 <br/> 0 *; 1(36)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x25 <br/> 0 *; 1(37)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x26 <br/> 0 *; 1(38)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x27 <br/> 0 *; 1(39)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x28 <br/> 0 *; 1(40)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x29 <br/> 0 *; 1(41)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2a <br/> 0 *; 1(42)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2b <br/> 0 *; 1(43)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2c <br/> 0 *; 1(44)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2d <br/> 0 *; 1(45)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2e <br/> 0 *; 1(46)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2f <br/> 0 *; 1(47)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x30 <br/> 0 *; 1(48) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x31 <br/> 0 *; 1(49)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x32 <br/> 0 *; 1(50)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x33 <br/> 0 *; 1(51)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x34 <br/> 0 *; 1(52)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x35 <br/> 0 *; 1(53)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x36 <br/> 0 *; 1(54)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x37 <br/> 0 *; 1(55)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x38 <br/> 0 *; 1(56)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x39 <br/> 0 *; 1(57)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3a <br/> 0 *; 1(58)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3b <br/> 0 *; 1(59)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3c <br/> 0 *; 1(60)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3d <br/> 0 *; 1(61)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3e <br/> 0 *; 1(62)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3f <br/> 0 *; 1(63)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x40 <br/> 0 *; 1(64) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x41 <br/> 0 *; 1(65)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x42 <br/> 0 *; 1(66)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x43 <br/> 0 *; 1(67)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x44 <br/> 0 *; 1(68)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x45 <br/> 0 *; 1(69)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x46 <br/> 0 *; 1(70)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x47 <br/> 0 *; 1(71)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x48 <br/> 0 *; 1(72)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x49 <br/> 0 *; 1(73)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x4a <br/> 0 *; 1(74)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x4b <br/> 0 *; 1(75)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA1 <br/> 0x4c <br/> 0 *; 1(0 - 255)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA2 <br/> 0x4d <br/> 0 *; 1(0 - 2^16-1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA4 <br/> 0x4e <br/> 0 *; 1(0 - 2^32-1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _1NEGATE <br/> 0x4f <br/> 0 ; 1(1)<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED <br/> 0x50 <br/> <br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _1 <br/> 0x51 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _2 <br/> 0x52 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _3 <br/> 0x53 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _4 <br/> 0x54 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _5 <br/> 0x55 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _6 <br/> 0x56 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _7 <br/> 0x57 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _8 <br/> 0x58 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _9 <br/> 0x59 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _10 <br/> 0x5a <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _11 <br/> 0x5b <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _12 <br/> 0x5c <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _13 <br/> 0x5d <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _14 <br/> 0x5e <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _15 <br/> 0x5f <br/> 0 ; 1(1)<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _16 <br/> 0x60 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP <br/> 0x61 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VER <br/> 0x62 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _IF <br/> 0x63 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOTIF <br/> 0x64 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VERIF <br/> 0x65 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VERNOTIF <br/> 0x66 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _ELSE <br/> 0x67 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _ENDIF <br/> 0x68 <br/> 0 ; 0<br />
| style="border:3px solid #808080; background-color:#00ff00;" | _VERIFY <br/> 0x69 <br/> 1 ; 0/1<br />
| style="border:3px solid #808080; background-color:#00ff00;" | _RETURN <br/> 0x6a <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | _TOALTSTACK <br/> 0x6b <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | _FROMALTSTACK <br/> 0x6c <br/> 0 #; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2DROP <br/> 0x6d <br/> 2 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2DUP <br/> 0x6e <br/> 2 ; 4<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _3DUP <br/> 0x6f <br/> 3 ; 6<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2OVER <br/> 0x70 <br/> 4 ; 6<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2ROT <br/> 0x71 <br/> 6 ; 6<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2SWAP <br/> 0x72 <br/> 4 ; 4<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _IFDUP <br/> 0x73 <br/> 1 ; 1/2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DEPTH <br/> 0x74 <br/> 0 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DROP <br/> 0x75 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DUP <br/> 0x76 <br/> 1 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _NIP <br/> 0x77 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _OVER <br/> 0x78 <br/> 2 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _PICK <br/> 0x79 <br/> 1+n+1 ; n+2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _ROLL <br/> 0x7a <br/> 1+n+1 ; n+1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _ROT <br/> 0x7b <br/> 3 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _SWAP <br/> 0x7c <br/> 2 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _TUCK <br/> 0x7d <br/> 2 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _CAT <br/> 0x7e <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _SUBSTR <br/> 0x7f <br/> 3 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _LEFT <br/> 0x80 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _RIGHT <br/> 0x81 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0;" | _SIZE <br/> 0x82 <br/> 1 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _INVERT <br/> 0x83 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _AND <br/> 0x84 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _OR <br/> 0x85 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _XOR <br/> 0x86 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff;" | _EQUAL <br/> 0x87 <br/> 2 ; 1<br />
| style="border:3px solid #808080; background-color:#c080ff;" | _EQUALVERIFY <br/> 0x88 <br/> 2 ; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED1 <br/> 0x89 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED2 <br/> 0x8a <br/><br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _1ADD <br/> 0x8b <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _1SUB <br/> 0x8c <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _2MUL <br/> 0x8d <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _2DIV <br/> 0x8e <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NEGATE <br/> 0x8f <br/> 1 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _ABS <br/> 0x90 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NOT <br/> 0x91 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _0NOTEQUAL <br/> 0x92 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _ADD <br/> 0x93 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _SUB <br/> 0x94 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _MUL <br/> 0x95 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _DIV <br/> 0x96 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _MOD <br/> 0x97 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _LSHIFT <br/> 0x98 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _RSHIFT <br/> 0x99 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _BOOLAND <br/> 0x9a <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _BOOLOR <br/> 0x9b <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NUMEQUAL <br/> 0x9c <br/> 2 ; 1<br />
| style="border:3px solid #808080; background-color:#8080ff;" | _NUMEQUALVERIFY <br/> 0x9d <br/> 2 ; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NUMNOTEQUAL <br/> 0x9e <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _LESSTHAN <br/> 0x9f <br/> 2 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _GREATERTHAN <br/> 0xa0 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _LESSTHANOREQUAL <br/> 0xa1 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _GREATERTHANOREQUAL <br/> 0xa2 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _MIN <br/> 0xa3 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _MAX <br/> 0xa4 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _WITHIN <br/> 0xa5 <br/> 3 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _RIPEMD160 <br/> 0xa6 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _SHA1 <br/> 0xa7 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _SHA256 <br/> 0xa8 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _HASH160 <br/> 0xa9 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _HASH256 <br/> 0xaa <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CODESEPARATOR <br/> 0xab <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CHECKSIG <br/> 0xac <br/> 2 @; 1<br />
| style="border:3px solid #808080; background-color:#a0d0ff;" | _CHECKSIGVERIFY <br/> 0xad <br/> 2 @; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CHECKMULTISIG <br/> 0xae <br/> 2n+2 @; 1<br />
| style="border:3px solid #808080; background-color:#a0d0ff;" | _CHECKMULTISIGVERIFY <br/> 0xaf <br/> 2n+2 @; 0/1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP1 <br/> 0xb0 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP2 <br/> 0xb1 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP3 <br/> 0xb2 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP4 <br/> 0xb3 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP5 <br/> 0xb4 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP6 <br/> 0xb5 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP7 <br/> 0xb6 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP8 <br/> 0xb7 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP9 <br/> 0xb8 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP10 <br/> 0xb9 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xba <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbe <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xca <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xce <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xda <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xde <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xea <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xeb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xec <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xed <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xee <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xef <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xfa <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _SMALLINTEGER <br/> 0xfb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEYS <br/> 0xfc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEYHASH <br/> 0xfd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEY <br/> 0xfe <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _INVALIDOPCODE <br/> 0xff <br/><br />
|}<br><br />
Except later pseudo-opcode changes, the definition of OP_NOP1 - OP_NOP10 and the change of the evaluation of OP_RETURN (did no invalidation previously) which both occured in bitcoin version 0.3.6 in July 2010 were the last changes regarding opcodes <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.2.0/bitcoin-0.2.0-linux.tar.gz file src/srcipt.cpp in bitcoin-0.2.0]</ref> <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.3.3/bitcoin-0.3.3-linux.tar.gz file src/srcipt.cpp in bitcoin-0.3.3]</ref> <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.3.6/bitcoin-0.3.6-linux.tar.gz file src/srcipt.cpp in bitcoin-0.3.6]</ref>.<br />
<br />
== Opcode descriptions ==<br />
It follows for each opcode less than decimal 185 (hexa 0xba) a description for its usage. The columns entitled ''nemonic'', ''decimal'' and ''Hex'' should be evident. The column ''input'' gives the needed items of the stack (and the alternate stack) and the column ''output'' indicates the resulting items on the stack (and the alternate stack). '''Stack-top is always the right most item.''' The naming of the entries in these two columns is chosen to reflect their interpretation. ''x'', ''x0'', ''x1'', ... means arbitrary or no interpretation, ''i0'', ''i1'' and ''i2'' a signed integer value, ''n'',''index'',''size'' and ''depth'' non-negative (unsigned) integer values, ''Boolean'' as either a true or false.<br><br />
<br />
Some of the more complicated opcodes are disabled since version 0.3.10 out of concern that the client might have a bug in the current implementation due to the historically not as 2-complement interpretations of the byte vectors as numerical values (the most significant byte holds the sign of the byte vectors). Furthermore how some of theses opcodes should work precisely is disputable.<br />
<br />
=== Push data from instruction onto stack ===<br />
<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_FALSE, OP_0<br />
|0<br />
|0x00<br />
|Nothing<br />
|Empty string<br />
|A byte vector of length 0 is pushed onto the stack. (Thus, it is not a no-op!)<br />
|-<br />
|(no official nemonics)<br />
|1 - 75<br />
|0x01 - 0x4b<br />
|(operand)<br />
|x<br />
|The next <opcode>-many bytes are to be pushed onto the stack.<br />
|-<br />
|OP_PUSHDATA1<br />
|76<br />
|0x4c<br />
|(operands)<br />
|x<br />
|The next byte contains the number of bytes to be pushed onto the stack which follow this byte.<br />
|-<br />
|OP_PUSHDATA2<br />
|77<br />
|0x4d<br />
|(operands)<br />
|x<br />
|The next two bytes contain the number of bytes to be pushed onto the stack which follow theses 2 bytes.<br />
|-<br />
|OP_PUSHDATA4<br />
|78<br />
|0x4e<br />
|(operands)<br />
|x<br />
|The next four bytes contain the number of bytes to be pushed onto the stack which follow theses 4 bytes.<br />
|-<br />
|OP_1NEGATE<br />
|79<br />
|0x4f<br />
|Nothing<br />
| -1<br />
|The byte with value -1 is pushed onto the stack.<br />
|-<br />
|OP_1, OP_TRUE<br />
|81<br />
|0x51<br />
|Nothing<br />
|1<br />
|The byte with value 1 is pushed onto the stack.<br />
|-<br />
|OP_2 - OP_16<br />
|82 - 96<br />
|0x52 - 0x60<br />
|Nothing<br />
|2-16<br />
|The byte with value <opcode>-80 (thus, one of 2 - 16) is pushed onto the stack.<br />
|}<br />
<br />
=== Flow control ===<br />
<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_NOP<br />
|97<br />
|0x61<br />
|Nothing<br />
|Nothing<br />
|Does nothing.<br />
|-<br />
|OP_IF<br />
|99<br />
|0x63<br />
|Boolean<br />
|Nothing<br />
|If the top stack value is not 0, the statements are executed. The top stack value is removed. Lead in a logcial ''<value> then [statements] [else [statements]] endif'' expression<br />
|-<br />
|OP_NOTIF<br />
|100<br />
|0x64<br />
|Boolean<br />
|Nothing<br />
|If the top stack value is 0, the statements are executed. The top stack value is removed. Lead in a logcial ''<value> then [statements] [else [statements]] endif'' expression <br />
|-<br />
|OP_ELSE<br />
|103<br />
|0x67<br />
|Nothing<br />
|Nothing<br />
|If the preceeding OP_IF or OP_NOTIF or OP_ELSE was not executed then these statements are and if the preceding OP_IF or OP_NOTIF or OP_ELSE was executed then these statements are not. <br />
|-<br />
|OP_ENDIF<br />
|104<br />
|0x68<br />
|Nothing<br />
|Nothing<br />
|Ends a logcial ''If <value> then [statements] [else [statements]] '' expression<br />
|-<br />
|OP_VERIFY<br />
|105<br />
|0x69<br />
|Boolean<br />
|Nothing / False<br />
|If top stack value is not true then marks transaction as '''invalid''' . A value true is removed, but false is not.<br />
|-<br />
|OP_RETURN<br />
|106<br />
|0x6a<br />
|Nothing<br />
|Nothing<br />
|Marks transaction as '''invalid'''. <br />
|}<br />
<br />
===Stack item organization===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_TOALTSTACK<br />
|107<br />
|0x6b<br />
|x1 (alt)<br />
|(alt x1)<br />
|Puts the input onto the top of the alt stack. Removes it from the (main) stack.<br />
|-<br />
|OP_FROMALTSTACK<br />
|108<br />
|0x6c<br />
|(alt x1)<br />
|x1 (alt)<br />
|Puts the input onto the top of the (main) stack. Removes it from the alt stack.<br />
|-<br />
|OP_2DROP<br />
|109<br />
|0x6d<br />
|x2 x1<br />
|Nothing<br />
|Removes the top two stack items.<br />
|-<br />
|OP_2DUP<br />
|110<br />
|0x6e<br />
|x2 x1<br />
|x2 x1 x2 x1<br />
|Duplicates the top two stack items.<br />
|-<br />
|OP_3DUP<br />
|111<br />
|0x6f<br />
|x3 x2 x1<br />
|x3 x2 x1 x3 x2 x1<br />
|Duplicates the top three stack items.<br />
|-<br />
|OP_2OVER<br />
|112<br />
|0x70<br />
|x4 x3 x2 x1<br />
|x4 x3 x2 x1 x4 x3<br />
|Copies the pair of items two spaces back in the stack to the front.<br />
|-<br />
|OP_2ROT<br />
|113<br />
|0x71<br />
|x6 x5 x4 x3 x2 x1<br />
|x4 x3 x2 x1 x6 x5<br />
|The fifth and sixth items back are moved to the top of the stack. Twotimes left rotate.<br />
|-<br />
|OP_2SWAP<br />
|114<br />
|0x72<br />
|x4 x3 x2 x1<br />
|x2 x1 x4 x3<br />
|Swaps the top two pairs of stack items.<br />
|-<br />
|OP_IFDUP<br />
|115<br />
|0x73<br />
|x1<br />
|x1 / x1 x1<br />
|If the top stack value is not 0, duplicate it.<br />
|-<br />
|OP_DEPTH<br />
|116<br />
|0x74<br />
|Nothing<br />
|depth<br />
|Puts the number of stack items onto the stack as one little-endian coded byte-vector<br />
|-<br />
|OP_DROP<br />
|117<br />
|0x75<br />
|x1<br />
|Nothing<br />
|Removes the top stack item.<br />
|-<br />
|OP_DUP<br />
|118<br />
|0x76<br />
|x1<br />
|x1 x1<br />
|Duplicates the top stack item.<br />
|-<br />
|OP_NIP<br />
|119<br />
|0x77<br />
|x2 x1<br />
|x1<br />
|Removes the second-to-top stack item.<br />
|-<br />
|OP_OVER<br />
|120<br />
|0x78<br />
|x2 x1<br />
|x2 x1 x2<br />
|Copies the second-to-top stack item to the top.<br />
|-<br />
|OP_PICK<br />
|121<br />
|0x79<br />
|xn ... x2 x1 x0 <n><br />
|xn ... x2 x1 x0 xn<br />
|<n> is removed and the item ''n'' back in the stack is copied to the top.<br />
|-<br />
|OP_ROLL<br />
|122<br />
|0x7a<br />
|xn ... x2 x1 x0 <n><br />
|... x2 x1 x0 xn<br />
|<n> is removed and the item ''n'' back in the stack is moved to the top.<br />
|-<br />
|OP_ROT<br />
|123<br />
|0x7b<br />
|x3 x2 x1<br />
|x2 x1 x3<br />
|The top three items on the stack are rotated to the left.<br />
|-<br />
|OP_SWAP<br />
|124<br />
|0x7c<br />
|x2 x1<br />
|x1 x2<br />
|The top two items on the stack are swapped resp. rotated.<br />
|-<br />
|OP_TUCK<br />
|125<br />
|0x7d<br />
|x2 x1<br />
|x1 x2 x1<br />
|The item at the top of the stack is copied and inserted before the second-to-top item.<br />
|}<br />
<br />
=== Splice ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_CAT<br />
|126<br />
|0x7e<br />
|x2 x1<br />
|out<br />
|Appends stack-top item at second-to top item. Concatenates two strings resp. byte vectors. ''Currently disabled.''<br />
|-<br />
|OP_SUBSTR<br />
|127<br />
|0x7f<br />
|x3 index size<br />
|out<br />
|Returns the section started at position <index> and of length <size> of a string resp. byte vector. ''Currently disabled.''<br />
|-<br />
|OP_LEFT<br />
|128<br />
|0x80<br />
|x2 index<br />
|out<br />
|Keeps only characters left of the specified point in second-to top item. ''Currently disabled.''<br />
|-<br />
|OP_RIGHT<br />
|129<br />
|0x81<br />
|x2 index<br />
|out<br />
|Keeps only characters right of the specified point in second-to top item. ''Currently disabled.''<br />
|-<br />
|OP_SIZE<br />
|130<br />
|0x82<br />
|x1<br />
|x1 size<br />
|Returns the length of the input string resp. byte vector resp. top-stack item.<br />
|}<br />
<br />
=== Bitwise logic ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_INVERT<br />
|131<br />
|0x83<br />
|x1<br />
|x0<br />
|Flips all of the bits in the input. ''Currently disabled.''<br />
|-<br />
|OP_AND<br />
|132<br />
|0x84<br />
|x2 x1<br />
|x0<br />
|Boolean ''and'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_OR<br />
|133<br />
|0x85<br />
|x2 x1<br />
|x0<br />
|Boolean ''or'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_XOR<br />
|134<br />
|0x86<br />
|x2 x1<br />
|x0<br />
|Boolean ''exclusive or'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_EQUAL<br />
|135<br />
|0x87<br />
|x2 x1<br />
|Boolean<br />
|Returns 1 if the inputs have the same length and are byte-wise equal, 0 otherwise.<br />
|-<br />
|OP_EQUALVERIFY<br />
|136<br />
|0x88<br />
|x2 x1<br />
|Nothing / false<br />
|Same as OP_EQUAL, but runs OP_VERIFY afterward.<br />
|}<br />
<br />
=== Arithmetic ===<br />
<br />
(In versions 0.3.10 up to 0.3.23, the implemented arithmetic opcodes were limited to maximal 4 byte vectors, in version 0.3.6 up to 0.3.8 to 258 byte vectors and prior to 0.3.6 unrestricted)<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_1ADD<br />
|139<br />
|0x8b<br />
|i1<br />
|i0<br />
|1 is added to the input.<br />
|-<br />
|OP_1SUB<br />
|140<br />
|0x8c<br />
|i1<br />
|i0<br />
|1 is subtracted from the input.<br />
|-<br />
|OP_2MUL<br />
|141<br />
|0x8d<br />
|i1<br />
|i0<br />
|The input is multiplied by 2. ''Currently disabled.''<br />
|-<br />
|OP_2DIV<br />
|142<br />
|0x8e<br />
|i1<br />
|i0<br />
|The input is divided by 2 (round down). ''Currently disabled.''<br />
|-<br />
|OP_NEGATE<br />
|143<br />
|0x8f<br />
|i1<br />
|i0<br />
|The sign of the input is flipped. Numerically the value is multiplied by -1<br />
|-<br />
|OP_ABS<br />
|144<br />
|0x90<br />
|i1<br />
|i0<br />
|The input is negative, its sign is flipped.<br />
|-<br />
|OP_NOT<br />
|145<br />
|0x91<br />
|i1<br />
|Boolean<br />
|If the input is 0 or 1, it is flipped. Otherwise the output will be 0. Test whether its value equals 0<br />
|-<br />
|OP_0NOTEQUAL<br />
|146<br />
|0x92<br />
|i1<br />
|Boolean<br />
|Returns 0 if the input is 0. 1 otherwise. Test whether its value is unequal 0<br />
|-<br />
|OP_ADD<br />
|147<br />
|0x93<br />
|i2 i1<br />
|i0<br />
|stack-top i1 is added to i2.<br />
|-<br />
|OP_SUB<br />
|148<br />
|0x94<br />
|i2 i1<br />
|i0<br />
|stack-top i1 is subtracted from i2.<br />
|-<br />
|OP_MUL<br />
|149<br />
|0x95<br />
|i2 i1<br />
|i0<br />
|i2 is multiplied with stack-top i1. ''Currently disabled.''<br />
|-<br />
|OP_DIV<br />
|150<br />
|0x96<br />
|i2 i1<br />
|i0<br />
|i2 is divided by stack-top i1 (divisor should be not 0). ''Currently disabled.''<br />
|-<br />
|OP_MOD<br />
|151<br />
|0x97<br />
|i2 i1<br />
|i0<br />
|Returns the remainder after dividing i2 by stack-top i1 (divisor should be not 0). ''Currently disabled.''<br />
|-<br />
|OP_LSHIFT<br />
|152<br />
|0x98<br />
|i2 i1<br />
|i0<br />
|Shifts i2 left by i1 bits, preserving sign of i2 (i1 >= 0). ''Currently disabled.''<br />
|-<br />
|OP_RSHIFT<br />
|153<br />
|0x99<br />
|i2 i1<br />
|i0<br />
|Shifts i2 right by i1 bits, preserving sign of i2 (i1 >= 0). ''Currently disabled.''<br />
|-<br />
|OP_BOOLAND<br />
|154<br />
|0x9a<br />
|i2 i1<br />
|Boolean<br />
|If both i2 and i1 are not 0, the output is 1. Otherwise 0.<br />
|-<br />
|OP_BOOLOR<br />
|155<br />
|0x9b<br />
|i2 i1<br />
|Boolean<br />
|If i2 or i1 is not 0, the output is 1. Otherwise 0.<br />
|-<br />
|OP_NUMEQUAL<br />
|156<br />
|0x9c<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 and i1 are numerically equal, 0 otherwise.<br />
|-<br />
|OP_NUMEQUALVERIFY<br />
|157<br />
|0x9d<br />
|i2 i1<br />
|Nothing / False<br />
|Same as OP_NUMEQUAL, but runs OP_VERIFY afterward.<br />
|-<br />
|OP_NUMNOTEQUAL<br />
|158<br />
|0x9e<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 and i1 are numerically not equal, 0 otherwise.<br />
|-<br />
|OP_LESSTHAN<br />
|159<br />
|0x9f<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is less than stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_GREATERTHAN<br />
|160<br />
|0xa0<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is greater than stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_LESSTHANOREQUAL<br />
|161<br />
|0xa1<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is less than or equal to stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_GREATERTHANOREQUAL<br />
|162<br />
|0xa2<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is greater than or equal to stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_MIN<br />
|163<br />
|0xa3<br />
|i2 i1<br />
|i2 / i1<br />
|Returns the smaller of i2 and i1.<br />
|-<br />
|OP_MAX<br />
|164<br />
|0xa4<br />
|i2 i1<br />
|i2 / i1<br />
|Returns the larger of i2 and i1.<br />
|-<br />
|OP_WITHIN<br />
|165<br />
|0xa5<br />
|i3 i2 i1<br />
|Boolean<br />
|Returns 1 if i3 >= i2 and i3 < i1, 0 otherwise. Thus if i2 > i1 returns always 0.<br />
|}<br />
<br />
=== Crypto ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_RIPEMD160<br />
|166<br />
|0xa6<br />
|x<br />
|hash20<br />
|The input is hashed using RIPEMD-160.<br />
|-<br />
|OP_SHA1<br />
|167<br />
|0xa7<br />
|x<br />
|hash20<br />
|The input is hashed using SHA-1.<br />
|-<br />
|OP_SHA256<br />
|168<br />
|0xa8<br />
|x<br />
|hash32<br />
|The input is hashed using SHA-256.<br />
|-<br />
|OP_HASH160<br />
|169<br />
|0xa9<br />
|x<br />
|hash20<br />
|The input is hashed twice: first with SHA-256 and then with RIPEMD-160.<br />
|-<br />
|OP_HASH256<br />
|170<br />
|0xaa<br />
|x<br />
|hash32<br />
|The input is hashed two times with SHA-256.<br />
|-<br />
|OP_CODESEPARATOR<br />
|171<br />
|0xab<br />
|Nothing<br />
|Nothing<br />
|All of the signature checking opcodes will only match signatures to the data after the most recently-executed OP_CODESEPARATOR.<br />
|-<br />
|[[OP_CHECKSIG]]<br />
|172<br />
|0xac<br />
|sig pubkey<br />
|Boolean<br />
|The entire transaction's outputs, inputs, and script (from the most recently-executed OP_CODESEPARATOR to the end) are hashed. The signature used by OP_CHECKSIG must be a valid signature for a further, extern specified hash and the given public key. If it is, 1 is returned, 0 otherwise.<br />
|-<br />
|OP_CHECKSIGVERIFY<br />
|173<br />
|0xad<br />
|sig pubkey<br />
|Nothing / False<br />
|Same as OP_CHECKSIG, but OP_VERIFY is executed afterward.<br />
|-<br />
|OP_CHECKMULTISIG<br />
|174<br />
|0xae<br />
|sig1 sig2 ... <number of signatures> pub1 pub2 <number of public keys><br />
|Boolean<br />
|For each signature and public key pair, OP_CHECKSIG is executed. If more public keys than signatures are listed, some key/sig pairs can fail. All signatures need to match a public key. If all signatures are valid, 1 is returned, 0 otherwise. Due to a bug, one extra unused value is removed from the stack.<br />
|-<br />
|OP_CHECKMULTISIGVERIFY<br />
|175<br />
|0xaf<br />
|sig1 sig2 ... <number of signatures> pub1 pub2 ... <number of public keys><br />
|Nothing / False<br />
|Same as OP_CHECKMULTISIG, but OP_VERIFY is executed afterward.<br />
|}<br />
<br />
=== Expansion opcodes ===<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_NOP1-OP_NOP10<br />
|176-185<br />
|0xb0-0xb9<br />
|The opcode has no effect.<br />
|}<br />
<br />
=== Version opcodes ===<br />
Version opcodes are disabled since bitcoin 0.2.0 and should not be used (maybe reassigned in the future).<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_VER<br />
|98<br />
|0x62<br />
|Script evalution is triggered invalid (Formerly pushed the bitcoin-serialize version onto stack).<br />
|-<br />
|OP_VERIF<br />
|101<br />
|0x65<br />
|Script evalution is triggered invalid (Formerly top stack item was popped and =< compared to present version)<br />
|-<br />
|OP_VERNOTIF<br />
|102<br />
|0x66<br />
|Script evalution is triggered invalid (Formerly top stack item was popped and > compared to present version)<br />
|}<br />
<br />
=== Reserved opcodes ===<br />
Each opcode not assigned (currently also every opcode value > 185) is also reserved. Using any unassigned opcode triggers the script evaluation to be invalid.<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_RESERVED<br />
|80<br />
|0x50<br />
|Script evalution is triggered invalid-<br />
|-<br />
|OP_RESERVED1<br />
|137<br />
|0x89<br />
|Script evalution is triggered invalid.<br />
|-<br />
|OP_RESERVED2<br />
|138<br />
|0x8a<br />
|Script evalution is triggered invalid.<br />
|}<br />
<br />
===Pseudo-opcodes===<br />
These nemonics are used internally for assisting with transaction matching. They are invalid if used in actual scripts.<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_PUBKEYHASH<br />
|253<br />
|0xfd<br />
|Represents a public key hashed with OP_HASH160.<br />
|-<br />
|OP_PUBKEY<br />
|254<br />
|0xfe<br />
|Represents a public key compatible with OP_CHECKSIG.<br />
|-<br />
|OP_INVALIDOPCODE<br />
|255<br />
|0xff<br />
|Matches any opcode that is not yet assigned.<br />
|}<br />
<br />
==Scripts in bitcoin transactions==<br />
It follows a list of important (most occuring) scripts to see opcodes "at work". Keep in mind that all constants actually use the data-pushing instructions above. At start of a (transaction input) script evaluation, the stack is always empty. Currently less than 0.01 % of all txout-scripts / scriptPubKeys in the main block chain are not of the following two standard scripts.<br />
<br />
===Standard transaction to bitcoin address===<br />
<br />
scriptPubKey: OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG<br />
scriptSig: <sig> <pubKey><br />
<br />
To demonstrate how scripts look on the wire, here is a raw scriptPubKey:<br />
<pre> 76 A9 14<br />
OP_DUP OP_HASH160 Bytes to push<br />
<br />
89 AB CD EF AB BA AB BA AB BA AB BA AB BA AB BA AB BA AB BA 88 AC<br />
Data to push OP_EQUALVERIFY OP_CHECKSIG</pre><br />
<br />
Note: scriptSig is in the input of the spending transaction and scriptPubKey is in the output of the previously storing transaction, i.e. its "available bitcoins".<br />
<br />
Here is how each instruction is processed:<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
| <sig> <pubKey> OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| scriptSig and scriptPubKey are combined.<br />
|-<br />
|<sig> <pubKey><br />
| OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| Constants are added to the stack.<br />
|-<br />
|<sig> <pubKey> <pubKey><br />
| OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| Top stack item is duplicated.<br />
|-<br />
|<sig> <pubKey> <pubHashA><br />
|<pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG<br />
| Top stack item is hashed.<br />
|-<br />
|<sig> <pubKey> <pubHashA> <pubKeyHash><br />
|OP_EQUALVERIFY OP_CHECKSIG<br />
| Constant added.<br />
|-<br />
|<sig> <pubKey><br />
|OP_CHECKSIG<br />
| Equality is checked between the top two stack items.<br />
|-<br />
|true<br />
|Empty.<br />
|Signature is checked for top two stack items.<br />
|}<br />
<br />
===Transaction to IP address (and generation transaction)===<br />
<br />
scriptPubKey: <pubKey> OP_CHECKSIG<br />
scriptSig: <sig><br />
<br />
Checking process:<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
|<sig> <pubKey> OP_CHECKSIG<br />
|scriptSig and scriptPubKey are combined.<br />
|-<br />
|<sig> <pubKey><br />
| OP_CHECKSIG<br />
|Constants are added to the stack.<br />
|-<br />
|true<br />
|Empty.<br />
|Signature is checked for top two stack items.<br />
|}<br />
<br />
In the case of a '''coin generation transaction''' (the first transaction of each block), there is no scriptSig, resp. its code ("coinbase") is completly ignored for the transaction. Only the scriptPubKey is used.<br />
<br />
===Transaction with a message===<br />
<br />
It's possible to add arbitrary data to any transaction by just adding some data along with OP_DROP. <br />
scriptPubKey: <message> OP_DROP <pubKey> OP_CHECKSIG<br />
scriptSig: <sig><br />
<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
|<sig> <message> OP_DROP <pubKey> OP_CHECKSIG<br />
|<br />
|-<br />
|<sig><br />
|<message> OP_DROP <pubKey> OP_CHECKSIG<br />
|scriptSig added to the stack.<br />
|-<br />
|<sig> <message><br />
|OP_DROP <pubKey> OP_CHECKSIG<br />
|The message has been put.<br />
|-<br />
|<sig><br />
|<pubKey> OP_CHECKSIG<br />
|Top stack item has been removed.<br />
|-<br />
|<sig> <pubKey><br />
|OP_CHECKSIG<br />
|Checking signature against the public key.<br />
|-<br />
|true<br />
|Empty.<br />
|Stack holds the value of signature check now.<br />
|}<br />
<br />
===Examples of non standard transaction on Testnet===<br />
<br />
These two links below show a non standard transaction. It just prepends the hex of "bob" and the operation OP_DROP<br />
which just removes it. As you can see they can be spent as normal.<br />
<br />
Input non-std transaction:<br />
http://blockexplorer.com/testnet/t/6ttfeb55B1<br />
<br />
Spent by:<br />
http://blockexplorer.com/testnet/t/AFdRB1CHS3<br />
<br />
==Script validation==<br />
A script evaluation is considered invalid, if any of these conditions meets:<br><br />
<ul><br />
<li>the total size of the script exceeds (currently) 10000 bytes<br />
<li>there are more than (currently) 201 opcodes of opcode value > 0x60 in the script<br />
<li>each instruction is (currently) limited to maximal 520 bytes. This effects only the opcodes OP_PUSHDATA2 and OP_PUSHDATA4<br />
<li>the executed opcode of the script has insufficient input (from stack, from script or from anywhere)<br />
<li>the opcode is not defined (for execution) - indicated by white or light gray background color in the table<br />
<li>the opcode is disabled (currently 15 opcodes) - indicated by white font color in the opcode overview matrix<br />
<li>stack overflow occurs during execution of the opcode (currently the number of items on the stack and on the alternate stack is limited to 1000)<br />
<li>the opcodes OP_VERIF and OP_NOTVERIF invalidate a script which contains this opcode (even if this opcode is not executed!)<br />
<li>the opcodes OP_ELSE or OP_ENDIF has no matching OP_IF<br><br />
<li>the script execution has been finished but there is (at least) an unmatched OP_IF<br><br />
<li>the opcodes OP_VERIFY, OP_EQUALVERIFY, OP_NUMEQUALVERIFY, OP_CHECKSIGVERIFY and OP_CHECKMULTISIGVERIFY invalidate the script if the stack-top item is false<br />
<li>the execution of OP_RETURN<br />
<!--li>alt stack overflow occurs (only possible during execution of OP_TOALTSTACK)--><br />
<li>the numerical value of the top-stack item is negative or greater than the number of items - 2 on the stack if OP_PICK or OP_ROLL shall be executed<br />
<li>an item used as public key or signature for each of the opcodes OP_CHECKSIG, OP_CHECKSIGVERIFY, OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY can be neither a public key or signature (for the given hash)<br />
<li>the number of signature items or the number of public key items on the stack is negative for OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY<br />
<li>there or more signatures items than public key items on the stack for OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY<br />
<li>there are (currently) more than 20 public key items on the stack for OP_CHECKMULTISIG or CHECKMULTISIGVERIFY<br />
<li>the sum of opcodes > 0x60 and the number of public keys in all executed OP_CHECKMULTISIG or CHECKMULTISIGVERIFY exceeds (currently) 201<br />
<li>the script execution has been finished and the stack is empty or the top-stack item is false (numerical value 0)<br />
</ul><br />
else the script evaluation is considered to be valid.<ref>[http://sourceforge.net/projects/bitcoin/files/Bitcoin/bitcoin-0.7.1/bitcoin-0.7.1-linux.tar.gz file src/src/script.cpp in bitcoin-0.7.1]</ref><br />
'''If invalidation of a script is triggered then the script is immediately finished.''' These arbitrary looking limitations of 10000, 201, 520, 1000 and 20 might be increased in the future -- they serve to prevent strong slow down of the evaluation of a script while not restricting its practical usage really.<br />
<br />
==Withdrawn and drafted opcodes==<br />
<br />
<ul><br />
<li> byte value 0x89 OP_NOTEQUAL defined in pre-0.1.0 bitcoin versions. Since 0.1.0 removed because of security concerns. <br />
<li> byte value 0xb1 [[BIP 0012 | OP_EVAL]] withdraw - poll was triggered but insufficient support. <br />
<li> byte value 0xb2 [[BIP 0017 | OP_CHECKHASHVERIFY]] withdraw - poll was triggered but insufficient support.<br />
</ul><br />
<br />
==See Also==<br />
* [[Transactions]]<br />
* [[Contracts]]<br />
<br />
==References==<br />
<references/><br />
<ul><br />
<li>[http://www.zorinaq.com/pub/bitcoin-0.1.0.tgz file src/script.cpp in bitcoin-0.1.0]</li><br />
</ul><br />
[[Category:Technical]]<br />
[[Category:Vocabulary]]</div>
Smtp
https://en.bitcoin.it/w/index.php?title=Script&diff=34916
Script
2013-01-11T17:06:17Z
<p>Smtp: /* Arithmetic */</p>
<hr />
<div>Bitcoin uses a scripting system for [[transactions]]. [[Wikipedia:FORTH|Forth]]-like, Script is simple, stack-based, and processed from left to right. It is purposefully not Turing-complete, with no loops.<br />
<br />
A script is essentially a list of instructions recorded with each transaction that describe how the next person wanting to spend the Bitcoins being transferred can gain access to them.<br />
<br />
Scripts are big-endian and their sequences of bytes is interpreted as a sequence of opcodes with operands. Only opcodes with byte values less than 0x4f have additional operands.<br />
<br />
== Scripts and Bitcoin transactions ==<br />
The script for a typical Bitcoin transfer to destination Bitcoin address D simply encumbers future spending of the bitcoins with two things: the spender must provide<br />
# a public key that, when hashed, yields destination address D embedded in the script, and<br />
# a signature to show evidence of the private key corresponding to the public key just provided.<br />
<br />
Scripting provides the flexibility to change the parameters of what's needed to spend transferred Bitcoins. For example, the scripting system could be used to require two private keys, or a combination of several, or even no keys at all.<br />
<br />
A transaction is valid if nothing in the combined script triggers failure and the top stack item exists and is true (non-zero). The party who originally ''stored'' the Bitcoins now being spent, dictates the script operations that will occur ''last'' in order to release them for use in another transaction. The party wanting to spend them must provide the input(s) to the previously recorded script that results in those operations occurring last leaving behind true (non-zero) on the stack.<br><br />
Only the very first transaction in each bitcoin block has no input script (the entry there is called "coinbase"), because the Bitcoins created with the block are created from hot air and not released by a previous recorded txout-script.<br />
<br />
== Stack ==<br />
<br />
The stacks hold byte vectors (there is the (main) stack and an alternative stack). Byte vectors are interpreted as little-endian variable-length integers with the most significant bit determining the sign of the integer. Thus 0x81 represents -1. 0x80 is another representation of zero (so called negative 0). Byte vectors are interpreted as Booleans where False is represented by any representation of zero, and True is represented by any representation of non-zero.<br />
<br />
== Opcode overview ==<br />
<br />
For each opcode is given: its nemonic without the leading OP_, its hexadecimal byte value, the number of stack items needed (poped) during execution, a semicolon and the number of stack items which has been pushed (after execution). A * after the needed stack items indicates that further bytes from the script following the current opcode are needed. A # indicates that items on the alternative stack are poped/pushed. A @ indicates that further (global) data from the transaction is needed. A / indicates alternatives of a value. <br/><br />
Different colors indicate different semantic execution groups of opcodes:<br />
{| style="background:none; font-size:100%; padding:0; border-collapse:collapse; text-align:center; line-height:2em;" border="0" align="center" <br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | copy a fixed number of bytes but at most 75 onto stack<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | copy bytes onto stack which number is given by a 1, 2 or 4 byte value.<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | copy 1 specific byte onto stack<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | undefined opcode<br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | a pseudo-opcode, unassigned for scripts<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | NOP or opcode is part of a IF-flow-control construction<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00ff00;" | (stack conditionally) invalidation of the script this opcode is part of<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | stack item is moved between main stack and alternate stack<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | stack item(s) is/are moved, copied or deleted<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0;" | byte vectors are appended or divided or their size is determined<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff;" | byte vectors are interpreted bit-position-independently<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | byte vectors are interpreted and processed as signed integers<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | a hash value is computed or a signature checked<br />
|}<br />
<p><br />
===Opcode byte-matrix===<br />
The opcode value 0x00 with nemonic OP_FALSE is also named OP_0 and the opcode value 0x51 with nemonic OP_1 as also named OP_TRUE.<br />
{| style="background:none; font-size:100%; padding:0; border-collapse:collapse; text-align:center; line-height:2em;" border="0" align="center" <br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" |_FALSE<br/> 0x00 <br/> 0 ; 1(0) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x01<br/> 0 *; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x02<br/> 0 *; 1(2)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x03<br/> 0 *; 1(3)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x04<br/> 0 *; 1(4)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x04<br/> 0 *; 1(5)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x06<br/> 0 *; 1(6)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x07<br/> 0 *; 1(7)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x08<br/> 0 *; 1(8)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x09<br/> 0 *; 1(9)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0a<br/> 0 *; 1(10)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0b<br/> 0 *; 1(11)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0c<br/> 0 *; 1(12)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0d<br/> 0 *; 1(13)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0e<br/> 0 *; 1(14)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0f<br/> 0 *; 1(15)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x10 <br/> 0 *; 1(16) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x11 <br/> 0 *; 1(17)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x12 <br/> 0 *; 1(18)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x13 <br/> 0 *; 1(19)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x14 <br/> 0 *; 1(20)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x15 <br/> 0 *; 1(21)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x16 <br/> 0 *; 1(22)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x17 <br/> 0 *; 1(23)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x18 <br/> 0 *; 1(24)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x19 <br/> 0 *; 1(25)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1a <br/> 0 *; 1(26)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1b <br/> 0 *; 1(27)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1c <br/> 0 *; 1(28)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1d <br/> 0 *; 1(29)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1e <br/> 0 *; 1(30)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1f <br/> 0 *; 1(31)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x20 <br/> 0 *; 1(32) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x21 <br/> 0 *; 1(33)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x22 <br/> 0 *; 1(34)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x23 <br/> 0 *; 1(35)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x24 <br/> 0 *; 1(36)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x25 <br/> 0 *; 1(37)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x26 <br/> 0 *; 1(38)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x27 <br/> 0 *; 1(39)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x28 <br/> 0 *; 1(40)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x29 <br/> 0 *; 1(41)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2a <br/> 0 *; 1(42)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2b <br/> 0 *; 1(43)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2c <br/> 0 *; 1(44)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2d <br/> 0 *; 1(45)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2e <br/> 0 *; 1(46)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2f <br/> 0 *; 1(47)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x30 <br/> 0 *; 1(48) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x31 <br/> 0 *; 1(49)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x32 <br/> 0 *; 1(50)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x33 <br/> 0 *; 1(51)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x34 <br/> 0 *; 1(52)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x35 <br/> 0 *; 1(53)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x36 <br/> 0 *; 1(54)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x37 <br/> 0 *; 1(55)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x38 <br/> 0 *; 1(56)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x39 <br/> 0 *; 1(57)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3a <br/> 0 *; 1(58)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3b <br/> 0 *; 1(59)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3c <br/> 0 *; 1(60)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3d <br/> 0 *; 1(61)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3e <br/> 0 *; 1(62)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3f <br/> 0 *; 1(63)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x40 <br/> 0 *; 1(64) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x41 <br/> 0 *; 1(65)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x42 <br/> 0 *; 1(66)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x43 <br/> 0 *; 1(67)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x44 <br/> 0 *; 1(68)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x45 <br/> 0 *; 1(69)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x46 <br/> 0 *; 1(70)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x47 <br/> 0 *; 1(71)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x48 <br/> 0 *; 1(72)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x49 <br/> 0 *; 1(73)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x4a <br/> 0 *; 1(74)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x4b <br/> 0 *; 1(75)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA1 <br/> 0x4c <br/> 0 *; 1(0 - 255)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA2 <br/> 0x4d <br/> 0 *; 1(0 - 2^16-1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA4 <br/> 0x4e <br/> 0 *; 1(0 - 2^32-1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _1NEGATE <br/> 0x4f <br/> 0 ; 1(1)<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED <br/> 0x50 <br/> <br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _1 <br/> 0x51 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _2 <br/> 0x52 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _3 <br/> 0x53 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _4 <br/> 0x54 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _5 <br/> 0x55 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _6 <br/> 0x56 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _7 <br/> 0x57 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _8 <br/> 0x58 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _9 <br/> 0x59 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _10 <br/> 0x5a <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _11 <br/> 0x5b <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _12 <br/> 0x5c <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _13 <br/> 0x5d <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _14 <br/> 0x5e <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _15 <br/> 0x5f <br/> 0 ; 1(1)<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _16 <br/> 0x60 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP <br/> 0x61 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VER <br/> 0x62 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _IF <br/> 0x63 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOTIF <br/> 0x64 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VERIF <br/> 0x65 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VERNOTIF <br/> 0x66 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _ELSE <br/> 0x67 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _ENDIF <br/> 0x68 <br/> 0 ; 0<br />
| style="border:3px solid #808080; background-color:#00ff00;" | _VERIFY <br/> 0x69 <br/> 1 ; 0/1<br />
| style="border:3px solid #808080; background-color:#00ff00;" | _RETURN <br/> 0x6a <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | _TOALTSTACK <br/> 0x6b <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | _FROMALTSTACK <br/> 0x6c <br/> 0 #; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2DROP <br/> 0x6d <br/> 2 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2DUP <br/> 0x6e <br/> 2 ; 4<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _3DUP <br/> 0x6f <br/> 3 ; 6<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2OVER <br/> 0x70 <br/> 4 ; 6<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2ROT <br/> 0x71 <br/> 6 ; 6<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2SWAP <br/> 0x72 <br/> 4 ; 4<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _IFDUP <br/> 0x73 <br/> 1 ; 1/2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DEPTH <br/> 0x74 <br/> 0 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DROP <br/> 0x75 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DUP <br/> 0x76 <br/> 1 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _NIP <br/> 0x77 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _OVER <br/> 0x78 <br/> 2 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _PICK <br/> 0x79 <br/> 1+n+1 ; n+2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _ROLL <br/> 0x7a <br/> 1+n+1 ; n+1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _ROT <br/> 0x7b <br/> 3 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _SWAP <br/> 0x7c <br/> 2 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _TUCK <br/> 0x7d <br/> 2 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _CAT <br/> 0x7e <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _SUBSTR <br/> 0x7f <br/> 3 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _LEFT <br/> 0x80 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _RIGHT <br/> 0x81 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0;" | _SIZE <br/> 0x82 <br/> 1 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _INVERT <br/> 0x83 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _AND <br/> 0x84 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _OR <br/> 0x85 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _XOR <br/> 0x86 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff;" | _EQUAL <br/> 0x87 <br/> 2 ; 1<br />
| style="border:3px solid #808080; background-color:#c080ff;" | _EQUALVERIFY <br/> 0x88 <br/> 2 ; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED1 <br/> 0x89 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED2 <br/> 0x8a <br/><br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _1ADD <br/> 0x8b <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _1SUB <br/> 0x8c <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _2MUL <br/> 0x8d <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _2DIV <br/> 0x8e <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NEGATE <br/> 0x8f <br/> 1 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _ABS <br/> 0x90 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NOT <br/> 0x91 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _0NOTEQUAL <br/> 0x92 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _ADD <br/> 0x93 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _SUB <br/> 0x94 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _MUL <br/> 0x95 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _DIV <br/> 0x96 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _MOD <br/> 0x97 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _LSHIFT <br/> 0x98 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _RSHIFT <br/> 0x99 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _BOOLAND <br/> 0x9a <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _BOOLOR <br/> 0x9b <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NUMEQUAL <br/> 0x9c <br/> 2 ; 1<br />
| style="border:3px solid #808080; background-color:#8080ff;" | _NUMEQUALVERIFY <br/> 0x9d <br/> 2 ; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NUMNOTEQUAL <br/> 0x9e <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _LESSTHAN <br/> 0x9f <br/> 2 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _GREATERTHAN <br/> 0xa0 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _LESSTHANOREQUAL <br/> 0xa1 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _GREATERTHANOREQUAL <br/> 0xa2 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _MIN <br/> 0xa3 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _MAX <br/> 0xa4 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _WITHIN <br/> 0xa5 <br/> 3 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _RIPEMD160 <br/> 0xa6 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _SHA1 <br/> 0xa7 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _SHA256 <br/> 0xa8 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _HASH160 <br/> 0xa9 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _HASH256 <br/> 0xaa <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CODESEPARATOR <br/> 0xab <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CHECKSIG <br/> 0xac <br/> 2 @; 1<br />
| style="border:3px solid #808080; background-color:#a0d0ff;" | _CHECKSIGVERIFY <br/> 0xad <br/> 2 @; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CHECKMULTISIG <br/> 0xae <br/> 2n+2 @; 1<br />
| style="border:3px solid #808080; background-color:#a0d0ff;" | _CHECKMULTISIGVERIFY <br/> 0xaf <br/> 2n+2 @; 0/1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP1 <br/> 0xb0 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP2 <br/> 0xb1 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP3 <br/> 0xb2 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP4 <br/> 0xb3 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP5 <br/> 0xb4 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP6 <br/> 0xb5 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP7 <br/> 0xb6 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP8 <br/> 0xb7 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP9 <br/> 0xb8 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP10 <br/> 0xb9 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xba <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbe <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xca <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xce <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xda <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xde <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xea <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xeb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xec <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xed <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xee <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xef <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xfa <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _SMALLINTEGER <br/> 0xfb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEYS <br/> 0xfc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEYHASH <br/> 0xfd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEY <br/> 0xfe <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _INVALIDOPCODE <br/> 0xff <br/><br />
|}<br><br />
Except later pseudo-opcode changes, the definition of OP_NOP1 - OP_NOP10 and the change of the evaluation of OP_RETURN (did no invalidation previously) which both occured in bitcoin version 0.3.6 in July 2010 were the last changes regarding opcodes <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.2.0/bitcoin-0.2.0-linux.tar.gz file src/srcipt.cpp in bitcoin-0.2.0]</ref> <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.3.3/bitcoin-0.3.3-linux.tar.gz file src/srcipt.cpp in bitcoin-0.3.3]</ref> <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.3.6/bitcoin-0.3.6-linux.tar.gz file src/srcipt.cpp in bitcoin-0.3.6]</ref>.<br />
<br />
== Opcode descriptions ==<br />
It follows for each opcode less than decimal 185 (hexa 0xba) a description for its usage. The columns entitled ''nemonic'', ''decimal'' and ''Hex'' should be evident. The column ''input'' gives the needed items of the stack (and the alternate stack) and the column ''output'' indicates the resulting items on the stack (and the alternate stack). '''Stack-top is always the right most item.''' The naming of the entries in these two columns is chosen to reflect their interpretation. ''x'', ''x0'', ''x1'', ... means arbitrary or no interpretation, ''i0'', ''i1'' and ''i2'' a signed integer value, ''n'',''index'',''size'' and ''depth'' non-negative (unsigned) integer values, ''Boolean'' as either a true or false.<br><br />
<br />
Some of the more complicated opcodes are disabled out of concern that the client might have (and has) a bug in the current implementation due to the historically not as 2-complement interpretations of the byte vectors as numerical values (the most significant byte holds the sign of the byte vectors).<br />
<br />
=== Push data from instruction onto stack ===<br />
<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_FALSE, OP_0<br />
|0<br />
|0x00<br />
|Nothing<br />
|Empty string<br />
|A byte vector of length 0 is pushed onto the stack. (Thus, it is not a no-op!)<br />
|-<br />
|(no official nemonics)<br />
|1 - 75<br />
|0x01 - 0x4b<br />
|(operand)<br />
|x<br />
|The next <opcode>-many bytes are to be pushed onto the stack.<br />
|-<br />
|OP_PUSHDATA1<br />
|76<br />
|0x4c<br />
|(operands)<br />
|x<br />
|The next byte contains the number of bytes to be pushed onto the stack which follow this byte.<br />
|-<br />
|OP_PUSHDATA2<br />
|77<br />
|0x4d<br />
|(operands)<br />
|x<br />
|The next two bytes contain the number of bytes to be pushed onto the stack which follow theses 2 bytes.<br />
|-<br />
|OP_PUSHDATA4<br />
|78<br />
|0x4e<br />
|(operands)<br />
|x<br />
|The next four bytes contain the number of bytes to be pushed onto the stack which follow theses 4 bytes.<br />
|-<br />
|OP_1NEGATE<br />
|79<br />
|0x4f<br />
|Nothing<br />
| -1<br />
|The byte with value -1 is pushed onto the stack.<br />
|-<br />
|OP_1, OP_TRUE<br />
|81<br />
|0x51<br />
|Nothing<br />
|1<br />
|The byte with value 1 is pushed onto the stack.<br />
|-<br />
|OP_2 - OP_16<br />
|82 - 96<br />
|0x52 - 0x60<br />
|Nothing<br />
|2-16<br />
|The byte with value <opcode>-80 (thus, one of 2 - 16) is pushed onto the stack.<br />
|}<br />
<br />
=== Flow control ===<br />
<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_NOP<br />
|97<br />
|0x61<br />
|Nothing<br />
|Nothing<br />
|Does nothing.<br />
|-<br />
|OP_IF<br />
|99<br />
|0x63<br />
|Boolean<br />
|Nothing<br />
|If the top stack value is not 0, the statements are executed. The top stack value is removed. Lead in a logcial ''<value> then [statements] [else [statements]] endif'' expression<br />
|-<br />
|OP_NOTIF<br />
|100<br />
|0x64<br />
|Boolean<br />
|Nothing<br />
|If the top stack value is 0, the statements are executed. The top stack value is removed. Lead in a logcial ''<value> then [statements] [else [statements]] endif'' expression <br />
|-<br />
|OP_ELSE<br />
|103<br />
|0x67<br />
|Nothing<br />
|Nothing<br />
|If the preceeding OP_IF or OP_NOTIF or OP_ELSE was not executed then these statements are and if the preceding OP_IF or OP_NOTIF or OP_ELSE was executed then these statements are not. <br />
|-<br />
|OP_ENDIF<br />
|104<br />
|0x68<br />
|Nothing<br />
|Nothing<br />
|Ends a logcial ''If <value> then [statements] [else [statements]] '' expression<br />
|-<br />
|OP_VERIFY<br />
|105<br />
|0x69<br />
|Boolean<br />
|Nothing / False<br />
|If top stack value is not true then marks transaction as '''invalid''' . A value true is removed, but false is not.<br />
|-<br />
|OP_RETURN<br />
|106<br />
|0x6a<br />
|Nothing<br />
|Nothing<br />
|Marks transaction as '''invalid'''. <br />
|}<br />
<br />
===Stack item organization===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_TOALTSTACK<br />
|107<br />
|0x6b<br />
|x1 (alt)<br />
|(alt x1)<br />
|Puts the input onto the top of the alt stack. Removes it from the (main) stack.<br />
|-<br />
|OP_FROMALTSTACK<br />
|108<br />
|0x6c<br />
|(alt x1)<br />
|x1 (alt)<br />
|Puts the input onto the top of the (main) stack. Removes it from the alt stack.<br />
|-<br />
|OP_2DROP<br />
|109<br />
|0x6d<br />
|x2 x1<br />
|Nothing<br />
|Removes the top two stack items.<br />
|-<br />
|OP_2DUP<br />
|110<br />
|0x6e<br />
|x2 x1<br />
|x2 x1 x2 x1<br />
|Duplicates the top two stack items.<br />
|-<br />
|OP_3DUP<br />
|111<br />
|0x6f<br />
|x3 x2 x1<br />
|x3 x2 x1 x3 x2 x1<br />
|Duplicates the top three stack items.<br />
|-<br />
|OP_2OVER<br />
|112<br />
|0x70<br />
|x4 x3 x2 x1<br />
|x4 x3 x2 x1 x4 x3<br />
|Copies the pair of items two spaces back in the stack to the front.<br />
|-<br />
|OP_2ROT<br />
|113<br />
|0x71<br />
|x6 x5 x4 x3 x2 x1<br />
|x4 x3 x2 x1 x6 x5<br />
|The fifth and sixth items back are moved to the top of the stack. Twotimes left rotate.<br />
|-<br />
|OP_2SWAP<br />
|114<br />
|0x72<br />
|x4 x3 x2 x1<br />
|x2 x1 x4 x3<br />
|Swaps the top two pairs of stack items.<br />
|-<br />
|OP_IFDUP<br />
|115<br />
|0x73<br />
|x1<br />
|x1 / x1 x1<br />
|If the top stack value is not 0, duplicate it.<br />
|-<br />
|OP_DEPTH<br />
|116<br />
|0x74<br />
|Nothing<br />
|depth<br />
|Puts the number of stack items onto the stack as one little-endian coded byte-vector<br />
|-<br />
|OP_DROP<br />
|117<br />
|0x75<br />
|x1<br />
|Nothing<br />
|Removes the top stack item.<br />
|-<br />
|OP_DUP<br />
|118<br />
|0x76<br />
|x1<br />
|x1 x1<br />
|Duplicates the top stack item.<br />
|-<br />
|OP_NIP<br />
|119<br />
|0x77<br />
|x2 x1<br />
|x1<br />
|Removes the second-to-top stack item.<br />
|-<br />
|OP_OVER<br />
|120<br />
|0x78<br />
|x2 x1<br />
|x2 x1 x2<br />
|Copies the second-to-top stack item to the top.<br />
|-<br />
|OP_PICK<br />
|121<br />
|0x79<br />
|xn ... x2 x1 x0 <n><br />
|xn ... x2 x1 x0 xn<br />
|<n> is removed and the item ''n'' back in the stack is copied to the top.<br />
|-<br />
|OP_ROLL<br />
|122<br />
|0x7a<br />
|xn ... x2 x1 x0 <n><br />
|... x2 x1 x0 xn<br />
|<n> is removed and the item ''n'' back in the stack is moved to the top.<br />
|-<br />
|OP_ROT<br />
|123<br />
|0x7b<br />
|x3 x2 x1<br />
|x2 x1 x3<br />
|The top three items on the stack are rotated to the left.<br />
|-<br />
|OP_SWAP<br />
|124<br />
|0x7c<br />
|x2 x1<br />
|x1 x2<br />
|The top two items on the stack are swapped resp. rotated.<br />
|-<br />
|OP_TUCK<br />
|125<br />
|0x7d<br />
|x2 x1<br />
|x1 x2 x1<br />
|The item at the top of the stack is copied and inserted before the second-to-top item.<br />
|}<br />
<br />
=== Splice ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_CAT<br />
|126<br />
|0x7e<br />
|x2 x1<br />
|out<br />
|Appends stack-top item at second-to top item. Concatenates two strings resp. byte vectors. ''Currently disabled.''<br />
|-<br />
|OP_SUBSTR<br />
|127<br />
|0x7f<br />
|x3 index size<br />
|out<br />
|Returns the section started at position <index> and of length <size> of a string resp. byte vector. ''Currently disabled.''<br />
|-<br />
|OP_LEFT<br />
|128<br />
|0x80<br />
|x2 index<br />
|out<br />
|Keeps only characters left of the specified point in second-to top item. ''Currently disabled.''<br />
|-<br />
|OP_RIGHT<br />
|129<br />
|0x81<br />
|x2 index<br />
|out<br />
|Keeps only characters right of the specified point in second-to top item. ''Currently disabled.''<br />
|-<br />
|OP_SIZE<br />
|130<br />
|0x82<br />
|x1<br />
|x1 size<br />
|Returns the length of the input string resp. byte vector resp. top-stack item.<br />
|}<br />
<br />
=== Bitwise logic ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_INVERT<br />
|131<br />
|0x83<br />
|x1<br />
|x0<br />
|Flips all of the bits in the input. ''Currently disabled.''<br />
|-<br />
|OP_AND<br />
|132<br />
|0x84<br />
|x2 x1<br />
|x0<br />
|Boolean ''and'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_OR<br />
|133<br />
|0x85<br />
|x2 x1<br />
|x0<br />
|Boolean ''or'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_XOR<br />
|134<br />
|0x86<br />
|x2 x1<br />
|x0<br />
|Boolean ''exclusive or'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_EQUAL<br />
|135<br />
|0x87<br />
|x2 x1<br />
|Boolean<br />
|Returns 1 if the inputs have the same length and are byte-wise equal, 0 otherwise.<br />
|-<br />
|OP_EQUALVERIFY<br />
|136<br />
|0x88<br />
|x2 x1<br />
|Nothing / false<br />
|Same as OP_EQUAL, but runs OP_VERIFY afterward.<br />
|}<br />
<br />
=== Arithmetic ===<br />
<br />
(In versions 0.3.10 up to 0.3.23, the implemented arithmetic opcodes were limited to maximal 4 byte vectors, in version 0.3.6 up to 0.3.8 to 258 byte vectors and prior to 0.3.6 unrestricted)<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_1ADD<br />
|139<br />
|0x8b<br />
|i1<br />
|i0<br />
|1 is added to the input.<br />
|-<br />
|OP_1SUB<br />
|140<br />
|0x8c<br />
|i1<br />
|i0<br />
|1 is subtracted from the input.<br />
|-<br />
|OP_2MUL<br />
|141<br />
|0x8d<br />
|i1<br />
|i0<br />
|The input is multiplied by 2. ''Currently disabled.''<br />
|-<br />
|OP_2DIV<br />
|142<br />
|0x8e<br />
|i1<br />
|i0<br />
|The input is divided by 2 (round down). ''Currently disabled.''<br />
|-<br />
|OP_NEGATE<br />
|143<br />
|0x8f<br />
|i1<br />
|i0<br />
|The sign of the input is flipped. Numerically the value is multiplied by -1<br />
|-<br />
|OP_ABS<br />
|144<br />
|0x90<br />
|i1<br />
|i0<br />
|The input is negative, its sign is flipped.<br />
|-<br />
|OP_NOT<br />
|145<br />
|0x91<br />
|i1<br />
|Boolean<br />
|If the input is 0 or 1, it is flipped. Otherwise the output will be 0. Test whether its value equals 0<br />
|-<br />
|OP_0NOTEQUAL<br />
|146<br />
|0x92<br />
|i1<br />
|Boolean<br />
|Returns 0 if the input is 0. 1 otherwise. Test whether its value is unequal 0<br />
|-<br />
|OP_ADD<br />
|147<br />
|0x93<br />
|i2 i1<br />
|i0<br />
|stack-top i1 is added to i2.<br />
|-<br />
|OP_SUB<br />
|148<br />
|0x94<br />
|i2 i1<br />
|i0<br />
|stack-top i1 is subtracted from i2.<br />
|-<br />
|OP_MUL<br />
|149<br />
|0x95<br />
|i2 i1<br />
|i0<br />
|i2 is multiplied with stack-top i1. ''Currently disabled.''<br />
|-<br />
|OP_DIV<br />
|150<br />
|0x96<br />
|i2 i1<br />
|i0<br />
|i2 is divided by stack-top i1 (divisor should be not 0). ''Currently disabled.''<br />
|-<br />
|OP_MOD<br />
|151<br />
|0x97<br />
|i2 i1<br />
|i0<br />
|Returns the remainder after dividing i2 by stack-top i1 (divisor should be not 0). ''Currently disabled.''<br />
|-<br />
|OP_LSHIFT<br />
|152<br />
|0x98<br />
|i2 i1<br />
|i0<br />
|Shifts i2 left by i1 bits, preserving sign of i2 (i1 >= 0). ''Currently disabled.''<br />
|-<br />
|OP_RSHIFT<br />
|153<br />
|0x99<br />
|i2 i1<br />
|i0<br />
|Shifts i2 right by i1 bits, preserving sign of i2 (i1 >= 0). ''Currently disabled.''<br />
|-<br />
|OP_BOOLAND<br />
|154<br />
|0x9a<br />
|i2 i1<br />
|Boolean<br />
|If both i2 and i1 are not 0, the output is 1. Otherwise 0.<br />
|-<br />
|OP_BOOLOR<br />
|155<br />
|0x9b<br />
|i2 i1<br />
|Boolean<br />
|If i2 or i1 is not 0, the output is 1. Otherwise 0.<br />
|-<br />
|OP_NUMEQUAL<br />
|156<br />
|0x9c<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 and i1 are numerically equal, 0 otherwise.<br />
|-<br />
|OP_NUMEQUALVERIFY<br />
|157<br />
|0x9d<br />
|i2 i1<br />
|Nothing / False<br />
|Same as OP_NUMEQUAL, but runs OP_VERIFY afterward.<br />
|-<br />
|OP_NUMNOTEQUAL<br />
|158<br />
|0x9e<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 and i1 are numerically not equal, 0 otherwise.<br />
|-<br />
|OP_LESSTHAN<br />
|159<br />
|0x9f<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is less than stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_GREATERTHAN<br />
|160<br />
|0xa0<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is greater than stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_LESSTHANOREQUAL<br />
|161<br />
|0xa1<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is less than or equal to stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_GREATERTHANOREQUAL<br />
|162<br />
|0xa2<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is greater than or equal to stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_MIN<br />
|163<br />
|0xa3<br />
|i2 i1<br />
|i2 / i1<br />
|Returns the smaller of i2 and i1.<br />
|-<br />
|OP_MAX<br />
|164<br />
|0xa4<br />
|i2 i1<br />
|i2 / i1<br />
|Returns the larger of i2 and i1.<br />
|-<br />
|OP_WITHIN<br />
|165<br />
|0xa5<br />
|i3 i2 i1<br />
|Boolean<br />
|Returns 1 if i3 >= i2 and i3 < i1, 0 otherwise. Thus if i2 > i1 returns always 0.<br />
|}<br />
<br />
=== Crypto ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_RIPEMD160<br />
|166<br />
|0xa6<br />
|x<br />
|hash20<br />
|The input is hashed using RIPEMD-160.<br />
|-<br />
|OP_SHA1<br />
|167<br />
|0xa7<br />
|x<br />
|hash20<br />
|The input is hashed using SHA-1.<br />
|-<br />
|OP_SHA256<br />
|168<br />
|0xa8<br />
|x<br />
|hash32<br />
|The input is hashed using SHA-256.<br />
|-<br />
|OP_HASH160<br />
|169<br />
|0xa9<br />
|x<br />
|hash20<br />
|The input is hashed twice: first with SHA-256 and then with RIPEMD-160.<br />
|-<br />
|OP_HASH256<br />
|170<br />
|0xaa<br />
|x<br />
|hash32<br />
|The input is hashed two times with SHA-256.<br />
|-<br />
|OP_CODESEPARATOR<br />
|171<br />
|0xab<br />
|Nothing<br />
|Nothing<br />
|All of the signature checking opcodes will only match signatures to the data after the most recently-executed OP_CODESEPARATOR.<br />
|-<br />
|[[OP_CHECKSIG]]<br />
|172<br />
|0xac<br />
|sig pubkey<br />
|Boolean<br />
|The entire transaction's outputs, inputs, and script (from the most recently-executed OP_CODESEPARATOR to the end) are hashed. The signature used by OP_CHECKSIG must be a valid signature for a further, extern specified hash and the given public key. If it is, 1 is returned, 0 otherwise.<br />
|-<br />
|OP_CHECKSIGVERIFY<br />
|173<br />
|0xad<br />
|sig pubkey<br />
|Nothing / False<br />
|Same as OP_CHECKSIG, but OP_VERIFY is executed afterward.<br />
|-<br />
|OP_CHECKMULTISIG<br />
|174<br />
|0xae<br />
|sig1 sig2 ... <number of signatures> pub1 pub2 <number of public keys><br />
|Boolean<br />
|For each signature and public key pair, OP_CHECKSIG is executed. If more public keys than signatures are listed, some key/sig pairs can fail. All signatures need to match a public key. If all signatures are valid, 1 is returned, 0 otherwise. Due to a bug, one extra unused value is removed from the stack.<br />
|-<br />
|OP_CHECKMULTISIGVERIFY<br />
|175<br />
|0xaf<br />
|sig1 sig2 ... <number of signatures> pub1 pub2 ... <number of public keys><br />
|Nothing / False<br />
|Same as OP_CHECKMULTISIG, but OP_VERIFY is executed afterward.<br />
|}<br />
<br />
=== Expansion opcodes ===<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_NOP1-OP_NOP10<br />
|176-185<br />
|0xb0-0xb9<br />
|The opcode has no effect.<br />
|}<br />
<br />
=== Version opcodes ===<br />
Version opcodes are disabled since bitcoin 0.2.0 and should not be used (maybe reassigned in the future).<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_VER<br />
|98<br />
|0x62<br />
|Script evalution is triggered invalid (Formerly pushed the bitcoin-serialize version onto stack).<br />
|-<br />
|OP_VERIF<br />
|101<br />
|0x65<br />
|Script evalution is triggered invalid (Formerly top stack item was popped and =< compared to present version)<br />
|-<br />
|OP_VERNOTIF<br />
|102<br />
|0x66<br />
|Script evalution is triggered invalid (Formerly top stack item was popped and > compared to present version)<br />
|}<br />
<br />
=== Reserved opcodes ===<br />
Each opcode not assigned (currently also every opcode value > 185) is also reserved. Using any unassigned opcode triggers the script evaluation to be invalid.<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_RESERVED<br />
|80<br />
|0x50<br />
|Script evalution is triggered invalid-<br />
|-<br />
|OP_RESERVED1<br />
|137<br />
|0x89<br />
|Script evalution is triggered invalid.<br />
|-<br />
|OP_RESERVED2<br />
|138<br />
|0x8a<br />
|Script evalution is triggered invalid.<br />
|}<br />
<br />
===Pseudo-opcodes===<br />
These nemonics are used internally for assisting with transaction matching. They are invalid if used in actual scripts.<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_PUBKEYHASH<br />
|253<br />
|0xfd<br />
|Represents a public key hashed with OP_HASH160.<br />
|-<br />
|OP_PUBKEY<br />
|254<br />
|0xfe<br />
|Represents a public key compatible with OP_CHECKSIG.<br />
|-<br />
|OP_INVALIDOPCODE<br />
|255<br />
|0xff<br />
|Matches any opcode that is not yet assigned.<br />
|}<br />
<br />
==Scripts in bitcoin transactions==<br />
It follows a list of important (most occuring) scripts to see opcodes "at work". Keep in mind that all constants actually use the data-pushing instructions above. At start of a (transaction input) script evaluation, the stack is always empty. Currently less than 0.01 % of all txout-scripts / scriptPubKeys in the main block chain are not of the following two standard scripts.<br />
<br />
===Standard transaction to bitcoin address===<br />
<br />
scriptPubKey: OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG<br />
scriptSig: <sig> <pubKey><br />
<br />
To demonstrate how scripts look on the wire, here is a raw scriptPubKey:<br />
<pre> 76 A9 14<br />
OP_DUP OP_HASH160 Bytes to push<br />
<br />
89 AB CD EF AB BA AB BA AB BA AB BA AB BA AB BA AB BA AB BA 88 AC<br />
Data to push OP_EQUALVERIFY OP_CHECKSIG</pre><br />
<br />
Note: scriptSig is in the input of the spending transaction and scriptPubKey is in the output of the previously storing transaction, i.e. its "available bitcoins".<br />
<br />
Here is how each instruction is processed:<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
| <sig> <pubKey> OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| scriptSig and scriptPubKey are combined.<br />
|-<br />
|<sig> <pubKey><br />
| OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| Constants are added to the stack.<br />
|-<br />
|<sig> <pubKey> <pubKey><br />
| OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| Top stack item is duplicated.<br />
|-<br />
|<sig> <pubKey> <pubHashA><br />
|<pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG<br />
| Top stack item is hashed.<br />
|-<br />
|<sig> <pubKey> <pubHashA> <pubKeyHash><br />
|OP_EQUALVERIFY OP_CHECKSIG<br />
| Constant added.<br />
|-<br />
|<sig> <pubKey><br />
|OP_CHECKSIG<br />
| Equality is checked between the top two stack items.<br />
|-<br />
|true<br />
|Empty.<br />
|Signature is checked for top two stack items.<br />
|}<br />
<br />
===Transaction to IP address (and generation transaction)===<br />
<br />
scriptPubKey: <pubKey> OP_CHECKSIG<br />
scriptSig: <sig><br />
<br />
Checking process:<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
|<sig> <pubKey> OP_CHECKSIG<br />
|scriptSig and scriptPubKey are combined.<br />
|-<br />
|<sig> <pubKey><br />
| OP_CHECKSIG<br />
|Constants are added to the stack.<br />
|-<br />
|true<br />
|Empty.<br />
|Signature is checked for top two stack items.<br />
|}<br />
<br />
In the case of a '''coin generation transaction''' (the first transaction of each block), there is no scriptSig, resp. its code ("coinbase") is completly ignored for the transaction. Only the scriptPubKey is used.<br />
<br />
===Transaction with a message===<br />
<br />
It's possible to add arbitrary data to any transaction by just adding some data along with OP_DROP. <br />
scriptPubKey: <message> OP_DROP <pubKey> OP_CHECKSIG<br />
scriptSig: <sig><br />
<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
|<sig> <message> OP_DROP <pubKey> OP_CHECKSIG<br />
|<br />
|-<br />
|<sig><br />
|<message> OP_DROP <pubKey> OP_CHECKSIG<br />
|scriptSig added to the stack.<br />
|-<br />
|<sig> <message><br />
|OP_DROP <pubKey> OP_CHECKSIG<br />
|The message has been put.<br />
|-<br />
|<sig><br />
|<pubKey> OP_CHECKSIG<br />
|Top stack item has been removed.<br />
|-<br />
|<sig> <pubKey><br />
|OP_CHECKSIG<br />
|Checking signature against the public key.<br />
|-<br />
|true<br />
|Empty.<br />
|Stack holds the value of signature check now.<br />
|}<br />
<br />
===Examples of non standard transaction on Testnet===<br />
<br />
These two links below show a non standard transaction. It just prepends the hex of "bob" and the operation OP_DROP<br />
which just removes it. As you can see they can be spent as normal.<br />
<br />
Input non-std transaction:<br />
http://blockexplorer.com/testnet/t/6ttfeb55B1<br />
<br />
Spent by:<br />
http://blockexplorer.com/testnet/t/AFdRB1CHS3<br />
<br />
==Script validation==<br />
A script evaluation is considered invalid, if any of these conditions meets:<br><br />
<ul><br />
<li>the total size of the script exceeds (currently) 10000 bytes<br />
<li>there are more than (currently) 201 opcodes of opcode value > 0x60 in the script<br />
<li>each instruction is (currently) limited to maximal 520 bytes. This effects only the opcodes OP_PUSHDATA2 and OP_PUSHDATA4<br />
<li>the executed opcode of the script has insufficient input (from stack, from script or from anywhere)<br />
<li>the opcode is not defined (for execution) - indicated by white or light gray background color in the table<br />
<li>the opcode is disabled (currently 15 opcodes) - indicated by white font color in the opcode overview matrix<br />
<li>stack overflow occurs during execution of the opcode (currently the number of items on the stack and on the alternate stack is limited to 1000)<br />
<li>the opcodes OP_VERIF and OP_NOTVERIF invalidate a script which contains this opcode (even if this opcode is not executed!)<br />
<li>the opcodes OP_ELSE or OP_ENDIF has no matching OP_IF<br><br />
<li>the script execution has been finished but there is (at least) an unmatched OP_IF<br><br />
<li>the opcodes OP_VERIFY, OP_EQUALVERIFY, OP_NUMEQUALVERIFY, OP_CHECKSIGVERIFY and OP_CHECKMULTISIGVERIFY invalidate the script if the stack-top item is false<br />
<li>the execution of OP_RETURN<br />
<!--li>alt stack overflow occurs (only possible during execution of OP_TOALTSTACK)--><br />
<li>the numerical value of the top-stack item is negative or greater than the number of items - 2 on the stack if OP_PICK or OP_ROLL shall be executed<br />
<li>an item used as public key or signature for each of the opcodes OP_CHECKSIG, OP_CHECKSIGVERIFY, OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY can be neither a public key or signature (for the given hash)<br />
<li>the number of signature items or the number of public key items on the stack is negative for OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY<br />
<li>there or more signatures items than public key items on the stack for OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY<br />
<li>there are (currently) more than 20 public key items on the stack for OP_CHECKMULTISIG or CHECKMULTISIGVERIFY<br />
<li>the sum of opcodes > 0x60 and the number of public keys in all executed OP_CHECKMULTISIG or CHECKMULTISIGVERIFY exceeds (currently) 201<br />
<li>the script execution has been finished and the stack is empty or the top-stack item is false (numerical value 0)<br />
</ul><br />
else the script evaluation is considered to be valid.<ref>[http://sourceforge.net/projects/bitcoin/files/Bitcoin/bitcoin-0.7.1/bitcoin-0.7.1-linux.tar.gz file src/src/script.cpp in bitcoin-0.7.1]</ref><br />
'''If invalidation of a script is triggered then the script is immediately finished.''' These arbitrary looking limitations of 10000, 201, 520, 1000 and 20 might be increased in the future -- they serve to prevent strong slow down of the evaluation of a script while not restricting its practical usage really.<br />
<br />
==Withdrawn and drafted opcodes==<br />
<br />
<ul><br />
<li> byte value 0x89 OP_NOTEQUAL defined in pre-0.1.0 bitcoin versions. Since 0.1.0 removed because of security concerns. <br />
<li> byte value 0xb1 [[BIP 0012 | OP_EVAL]] withdraw - poll was triggered but insufficient support. <br />
<li> byte value 0xb2 [[BIP 0017 | OP_CHECKHASHVERIFY]] withdraw - poll was triggered but insufficient support.<br />
</ul><br />
<br />
==See Also==<br />
* [[Transactions]]<br />
* [[Contracts]]<br />
<br />
==References==<br />
<references/><br />
<ul><br />
<li>[http://www.zorinaq.com/pub/bitcoin-0.1.0.tgz file src/script.cpp in bitcoin-0.1.0]</li><br />
</ul><br />
[[Category:Technical]]<br />
[[Category:Vocabulary]]</div>
Smtp
https://en.bitcoin.it/w/index.php?title=Script&diff=34914
Script
2013-01-11T16:30:19Z
<p>Smtp: /* Scripts and Bitcoin transactions */</p>
<hr />
<div>Bitcoin uses a scripting system for [[transactions]]. [[Wikipedia:FORTH|Forth]]-like, Script is simple, stack-based, and processed from left to right. It is purposefully not Turing-complete, with no loops.<br />
<br />
A script is essentially a list of instructions recorded with each transaction that describe how the next person wanting to spend the Bitcoins being transferred can gain access to them.<br />
<br />
Scripts are big-endian and their sequences of bytes is interpreted as a sequence of opcodes with operands. Only opcodes with byte values less than 0x4f have additional operands.<br />
<br />
== Scripts and Bitcoin transactions ==<br />
The script for a typical Bitcoin transfer to destination Bitcoin address D simply encumbers future spending of the bitcoins with two things: the spender must provide<br />
# a public key that, when hashed, yields destination address D embedded in the script, and<br />
# a signature to show evidence of the private key corresponding to the public key just provided.<br />
<br />
Scripting provides the flexibility to change the parameters of what's needed to spend transferred Bitcoins. For example, the scripting system could be used to require two private keys, or a combination of several, or even no keys at all.<br />
<br />
A transaction is valid if nothing in the combined script triggers failure and the top stack item exists and is true (non-zero). The party who originally ''stored'' the Bitcoins now being spent, dictates the script operations that will occur ''last'' in order to release them for use in another transaction. The party wanting to spend them must provide the input(s) to the previously recorded script that results in those operations occurring last leaving behind true (non-zero) on the stack.<br><br />
Only the very first transaction in each bitcoin block has no input script (the entry there is called "coinbase"), because the Bitcoins created with the block are created from hot air and not released by a previous recorded txout-script.<br />
<br />
== Stack ==<br />
<br />
The stacks hold byte vectors (there is the (main) stack and an alternative stack). Byte vectors are interpreted as little-endian variable-length integers with the most significant bit determining the sign of the integer. Thus 0x81 represents -1. 0x80 is another representation of zero (so called negative 0). Byte vectors are interpreted as Booleans where False is represented by any representation of zero, and True is represented by any representation of non-zero.<br />
<br />
== Opcode overview ==<br />
<br />
For each opcode is given: its nemonic without the leading OP_, its hexadecimal byte value, the number of stack items needed (poped) during execution, a semicolon and the number of stack items which has been pushed (after execution). A * after the needed stack items indicates that further bytes from the script following the current opcode are needed. A # indicates that items on the alternative stack are poped/pushed. A @ indicates that further (global) data from the transaction is needed. A / indicates alternatives of a value. <br/><br />
Different colors indicate different semantic execution groups of opcodes:<br />
{| style="background:none; font-size:100%; padding:0; border-collapse:collapse; text-align:center; line-height:2em;" border="0" align="center" <br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | copy a fixed number of bytes but at most 75 onto stack<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | copy bytes onto stack which number is given by a 1, 2 or 4 byte value.<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | copy 1 specific byte onto stack<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | undefined opcode<br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | a pseudo-opcode, unassigned for scripts<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | NOP or opcode is part of a IF-flow-control construction<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00ff00;" | (stack conditionally) invalidation of the script this opcode is part of<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | stack item is moved between main stack and alternate stack<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | stack item(s) is/are moved, copied or deleted<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0;" | byte vectors are appended or divided or their size is determined<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff;" | byte vectors are interpreted bit-position-independently<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | byte vectors are interpreted and processed as signed integers<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | a hash value is computed or a signature checked<br />
|}<br />
<p><br />
===Opcode byte-matrix===<br />
The opcode value 0x00 with nemonic OP_FALSE is also named OP_0 and the opcode value 0x51 with nemonic OP_1 as also named OP_TRUE.<br />
{| style="background:none; font-size:100%; padding:0; border-collapse:collapse; text-align:center; line-height:2em;" border="0" align="center" <br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" |_FALSE<br/> 0x00 <br/> 0 ; 1(0) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x01<br/> 0 *; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x02<br/> 0 *; 1(2)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x03<br/> 0 *; 1(3)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x04<br/> 0 *; 1(4)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x04<br/> 0 *; 1(5)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x06<br/> 0 *; 1(6)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x07<br/> 0 *; 1(7)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x08<br/> 0 *; 1(8)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x09<br/> 0 *; 1(9)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0a<br/> 0 *; 1(10)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0b<br/> 0 *; 1(11)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0c<br/> 0 *; 1(12)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0d<br/> 0 *; 1(13)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0e<br/> 0 *; 1(14)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0f<br/> 0 *; 1(15)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x10 <br/> 0 *; 1(16) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x11 <br/> 0 *; 1(17)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x12 <br/> 0 *; 1(18)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x13 <br/> 0 *; 1(19)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x14 <br/> 0 *; 1(20)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x15 <br/> 0 *; 1(21)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x16 <br/> 0 *; 1(22)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x17 <br/> 0 *; 1(23)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x18 <br/> 0 *; 1(24)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x19 <br/> 0 *; 1(25)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1a <br/> 0 *; 1(26)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1b <br/> 0 *; 1(27)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1c <br/> 0 *; 1(28)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1d <br/> 0 *; 1(29)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1e <br/> 0 *; 1(30)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1f <br/> 0 *; 1(31)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x20 <br/> 0 *; 1(32) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x21 <br/> 0 *; 1(33)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x22 <br/> 0 *; 1(34)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x23 <br/> 0 *; 1(35)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x24 <br/> 0 *; 1(36)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x25 <br/> 0 *; 1(37)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x26 <br/> 0 *; 1(38)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x27 <br/> 0 *; 1(39)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x28 <br/> 0 *; 1(40)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x29 <br/> 0 *; 1(41)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2a <br/> 0 *; 1(42)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2b <br/> 0 *; 1(43)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2c <br/> 0 *; 1(44)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2d <br/> 0 *; 1(45)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2e <br/> 0 *; 1(46)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2f <br/> 0 *; 1(47)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x30 <br/> 0 *; 1(48) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x31 <br/> 0 *; 1(49)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x32 <br/> 0 *; 1(50)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x33 <br/> 0 *; 1(51)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x34 <br/> 0 *; 1(52)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x35 <br/> 0 *; 1(53)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x36 <br/> 0 *; 1(54)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x37 <br/> 0 *; 1(55)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x38 <br/> 0 *; 1(56)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x39 <br/> 0 *; 1(57)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3a <br/> 0 *; 1(58)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3b <br/> 0 *; 1(59)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3c <br/> 0 *; 1(60)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3d <br/> 0 *; 1(61)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3e <br/> 0 *; 1(62)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3f <br/> 0 *; 1(63)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x40 <br/> 0 *; 1(64) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x41 <br/> 0 *; 1(65)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x42 <br/> 0 *; 1(66)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x43 <br/> 0 *; 1(67)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x44 <br/> 0 *; 1(68)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x45 <br/> 0 *; 1(69)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x46 <br/> 0 *; 1(70)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x47 <br/> 0 *; 1(71)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x48 <br/> 0 *; 1(72)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x49 <br/> 0 *; 1(73)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x4a <br/> 0 *; 1(74)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x4b <br/> 0 *; 1(75)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA1 <br/> 0x4c <br/> 0 *; 1(0 - 255)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA2 <br/> 0x4d <br/> 0 *; 1(0 - 2^16-1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA4 <br/> 0x4e <br/> 0 *; 1(0 - 2^32-1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _1NEGATE <br/> 0x4f <br/> 0 ; 1(1)<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED <br/> 0x50 <br/> <br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _1 <br/> 0x51 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _2 <br/> 0x52 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _3 <br/> 0x53 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _4 <br/> 0x54 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _5 <br/> 0x55 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _6 <br/> 0x56 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _7 <br/> 0x57 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _8 <br/> 0x58 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _9 <br/> 0x59 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _10 <br/> 0x5a <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _11 <br/> 0x5b <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _12 <br/> 0x5c <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _13 <br/> 0x5d <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _14 <br/> 0x5e <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _15 <br/> 0x5f <br/> 0 ; 1(1)<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _16 <br/> 0x60 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP <br/> 0x61 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VER <br/> 0x62 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _IF <br/> 0x63 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOTIF <br/> 0x64 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VERIF <br/> 0x65 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VERNOTIF <br/> 0x66 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _ELSE <br/> 0x67 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _ENDIF <br/> 0x68 <br/> 0 ; 0<br />
| style="border:3px solid #808080; background-color:#00ff00;" | _VERIFY <br/> 0x69 <br/> 1 ; 0/1<br />
| style="border:3px solid #808080; background-color:#00ff00;" | _RETURN <br/> 0x6a <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | _TOALTSTACK <br/> 0x6b <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | _FROMALTSTACK <br/> 0x6c <br/> 0 #; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2DROP <br/> 0x6d <br/> 2 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2DUP <br/> 0x6e <br/> 2 ; 4<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _3DUP <br/> 0x6f <br/> 3 ; 6<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2OVER <br/> 0x70 <br/> 4 ; 6<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2ROT <br/> 0x71 <br/> 6 ; 6<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2SWAP <br/> 0x72 <br/> 4 ; 4<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _IFDUP <br/> 0x73 <br/> 1 ; 1/2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DEPTH <br/> 0x74 <br/> 0 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DROP <br/> 0x75 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DUP <br/> 0x76 <br/> 1 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _NIP <br/> 0x77 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _OVER <br/> 0x78 <br/> 2 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _PICK <br/> 0x79 <br/> 1+n+1 ; n+2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _ROLL <br/> 0x7a <br/> 1+n+1 ; n+1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _ROT <br/> 0x7b <br/> 3 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _SWAP <br/> 0x7c <br/> 2 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _TUCK <br/> 0x7d <br/> 2 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _CAT <br/> 0x7e <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _SUBSTR <br/> 0x7f <br/> 3 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _LEFT <br/> 0x80 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _RIGHT <br/> 0x81 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0;" | _SIZE <br/> 0x82 <br/> 1 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _INVERT <br/> 0x83 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _AND <br/> 0x84 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _OR <br/> 0x85 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _XOR <br/> 0x86 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff;" | _EQUAL <br/> 0x87 <br/> 2 ; 1<br />
| style="border:3px solid #808080; background-color:#c080ff;" | _EQUALVERIFY <br/> 0x88 <br/> 2 ; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED1 <br/> 0x89 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED2 <br/> 0x8a <br/><br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _1ADD <br/> 0x8b <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _1SUB <br/> 0x8c <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _2MUL <br/> 0x8d <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _2DIV <br/> 0x8e <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NEGATE <br/> 0x8f <br/> 1 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _ABS <br/> 0x90 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NOT <br/> 0x91 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _0NOTEQUAL <br/> 0x92 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _ADD <br/> 0x93 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _SUB <br/> 0x94 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _MUL <br/> 0x95 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _DIV <br/> 0x96 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _MOD <br/> 0x97 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _LSHIFT <br/> 0x98 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _RSHIFT <br/> 0x99 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _BOOLAND <br/> 0x9a <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _BOOLOR <br/> 0x9b <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NUMEQUAL <br/> 0x9c <br/> 2 ; 1<br />
| style="border:3px solid #808080; background-color:#8080ff;" | _NUMEQUALVERIFY <br/> 0x9d <br/> 2 ; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NUMNOTEQUAL <br/> 0x9e <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _LESSTHAN <br/> 0x9f <br/> 2 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _GREATERTHAN <br/> 0xa0 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _LESSTHANOREQUAL <br/> 0xa1 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _GREATERTHANOREQUAL <br/> 0xa2 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _MIN <br/> 0xa3 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _MAX <br/> 0xa4 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _WITHIN <br/> 0xa5 <br/> 3 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _RIPEMD160 <br/> 0xa6 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _SHA1 <br/> 0xa7 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _SHA256 <br/> 0xa8 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _HASH160 <br/> 0xa9 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _HASH256 <br/> 0xaa <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CODESEPARATOR <br/> 0xab <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CHECKSIG <br/> 0xac <br/> 2 @; 1<br />
| style="border:3px solid #808080; background-color:#a0d0ff;" | _CHECKSIGVERIFY <br/> 0xad <br/> 2 @; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CHECKMULTISIG <br/> 0xae <br/> 2n+2 @; 1<br />
| style="border:3px solid #808080; background-color:#a0d0ff;" | _CHECKMULTISIGVERIFY <br/> 0xaf <br/> 2n+2 @; 0/1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP1 <br/> 0xb0 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP2 <br/> 0xb1 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP3 <br/> 0xb2 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP4 <br/> 0xb3 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP5 <br/> 0xb4 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP6 <br/> 0xb5 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP7 <br/> 0xb6 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP8 <br/> 0xb7 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP9 <br/> 0xb8 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP10 <br/> 0xb9 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xba <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbe <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xca <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xce <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xda <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xde <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xea <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xeb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xec <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xed <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xee <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xef <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xfa <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _SMALLINTEGER <br/> 0xfb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEYS <br/> 0xfc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEYHASH <br/> 0xfd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEY <br/> 0xfe <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _INVALIDOPCODE <br/> 0xff <br/><br />
|}<br><br />
Except later pseudo-opcode changes, the definition of OP_NOP1 - OP_NOP10 and the change of the evaluation of OP_RETURN (did no invalidation previously) which both occured in bitcoin version 0.3.6 in July 2010 were the last changes regarding opcodes <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.2.0/bitcoin-0.2.0-linux.tar.gz file src/srcipt.cpp in bitcoin-0.2.0]</ref> <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.3.3/bitcoin-0.3.3-linux.tar.gz file src/srcipt.cpp in bitcoin-0.3.3]</ref> <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.3.6/bitcoin-0.3.6-linux.tar.gz file src/srcipt.cpp in bitcoin-0.3.6]</ref>.<br />
<br />
== Opcode descriptions ==<br />
It follows for each opcode less than decimal 185 (hexa 0xba) a description for its usage. The columns entitled ''nemonic'', ''decimal'' and ''Hex'' should be evident. The column ''input'' gives the needed items of the stack (and the alternate stack) and the column ''output'' indicates the resulting items on the stack (and the alternate stack). '''Stack-top is always the right most item.''' The naming of the entries in these two columns is chosen to reflect their interpretation. ''x'', ''x0'', ''x1'', ... means arbitrary or no interpretation, ''i0'', ''i1'' and ''i2'' a signed integer value, ''n'',''index'',''size'' and ''depth'' non-negative (unsigned) integer values, ''Boolean'' as either a true or false.<br><br />
<br />
Some of the more complicated opcodes are disabled out of concern that the client might have (and has) a bug in the current implementation due to the historically not as 2-complement interpretations of the byte vectors as numerical values (the most significant byte holds the sign of the byte vectors).<br />
<br />
=== Push data from instruction onto stack ===<br />
<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_FALSE, OP_0<br />
|0<br />
|0x00<br />
|Nothing<br />
|Empty string<br />
|A byte vector of length 0 is pushed onto the stack. (Thus, it is not a no-op!)<br />
|-<br />
|(no official nemonics)<br />
|1 - 75<br />
|0x01 - 0x4b<br />
|(operand)<br />
|x<br />
|The next <opcode>-many bytes are to be pushed onto the stack.<br />
|-<br />
|OP_PUSHDATA1<br />
|76<br />
|0x4c<br />
|(operands)<br />
|x<br />
|The next byte contains the number of bytes to be pushed onto the stack which follow this byte.<br />
|-<br />
|OP_PUSHDATA2<br />
|77<br />
|0x4d<br />
|(operands)<br />
|x<br />
|The next two bytes contain the number of bytes to be pushed onto the stack which follow theses 2 bytes.<br />
|-<br />
|OP_PUSHDATA4<br />
|78<br />
|0x4e<br />
|(operands)<br />
|x<br />
|The next four bytes contain the number of bytes to be pushed onto the stack which follow theses 4 bytes.<br />
|-<br />
|OP_1NEGATE<br />
|79<br />
|0x4f<br />
|Nothing<br />
| -1<br />
|The byte with value -1 is pushed onto the stack.<br />
|-<br />
|OP_1, OP_TRUE<br />
|81<br />
|0x51<br />
|Nothing<br />
|1<br />
|The byte with value 1 is pushed onto the stack.<br />
|-<br />
|OP_2 - OP_16<br />
|82 - 96<br />
|0x52 - 0x60<br />
|Nothing<br />
|2-16<br />
|The byte with value <opcode>-80 (thus, one of 2 - 16) is pushed onto the stack.<br />
|}<br />
<br />
=== Flow control ===<br />
<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_NOP<br />
|97<br />
|0x61<br />
|Nothing<br />
|Nothing<br />
|Does nothing.<br />
|-<br />
|OP_IF<br />
|99<br />
|0x63<br />
|Boolean<br />
|Nothing<br />
|If the top stack value is not 0, the statements are executed. The top stack value is removed. Lead in a logcial ''<value> then [statements] [else [statements]] endif'' expression<br />
|-<br />
|OP_NOTIF<br />
|100<br />
|0x64<br />
|Boolean<br />
|Nothing<br />
|If the top stack value is 0, the statements are executed. The top stack value is removed. Lead in a logcial ''<value> then [statements] [else [statements]] endif'' expression <br />
|-<br />
|OP_ELSE<br />
|103<br />
|0x67<br />
|Nothing<br />
|Nothing<br />
|If the preceeding OP_IF or OP_NOTIF or OP_ELSE was not executed then these statements are and if the preceding OP_IF or OP_NOTIF or OP_ELSE was executed then these statements are not. <br />
|-<br />
|OP_ENDIF<br />
|104<br />
|0x68<br />
|Nothing<br />
|Nothing<br />
|Ends a logcial ''If <value> then [statements] [else [statements]] '' expression<br />
|-<br />
|OP_VERIFY<br />
|105<br />
|0x69<br />
|Boolean<br />
|Nothing / False<br />
|If top stack value is not true then marks transaction as '''invalid''' . A value true is removed, but false is not.<br />
|-<br />
|OP_RETURN<br />
|106<br />
|0x6a<br />
|Nothing<br />
|Nothing<br />
|Marks transaction as '''invalid'''. <br />
|}<br />
<br />
===Stack item organization===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_TOALTSTACK<br />
|107<br />
|0x6b<br />
|x1 (alt)<br />
|(alt x1)<br />
|Puts the input onto the top of the alt stack. Removes it from the (main) stack.<br />
|-<br />
|OP_FROMALTSTACK<br />
|108<br />
|0x6c<br />
|(alt x1)<br />
|x1 (alt)<br />
|Puts the input onto the top of the (main) stack. Removes it from the alt stack.<br />
|-<br />
|OP_2DROP<br />
|109<br />
|0x6d<br />
|x2 x1<br />
|Nothing<br />
|Removes the top two stack items.<br />
|-<br />
|OP_2DUP<br />
|110<br />
|0x6e<br />
|x2 x1<br />
|x2 x1 x2 x1<br />
|Duplicates the top two stack items.<br />
|-<br />
|OP_3DUP<br />
|111<br />
|0x6f<br />
|x3 x2 x1<br />
|x3 x2 x1 x3 x2 x1<br />
|Duplicates the top three stack items.<br />
|-<br />
|OP_2OVER<br />
|112<br />
|0x70<br />
|x4 x3 x2 x1<br />
|x4 x3 x2 x1 x4 x3<br />
|Copies the pair of items two spaces back in the stack to the front.<br />
|-<br />
|OP_2ROT<br />
|113<br />
|0x71<br />
|x6 x5 x4 x3 x2 x1<br />
|x4 x3 x2 x1 x6 x5<br />
|The fifth and sixth items back are moved to the top of the stack. Twotimes left rotate.<br />
|-<br />
|OP_2SWAP<br />
|114<br />
|0x72<br />
|x4 x3 x2 x1<br />
|x2 x1 x4 x3<br />
|Swaps the top two pairs of stack items.<br />
|-<br />
|OP_IFDUP<br />
|115<br />
|0x73<br />
|x1<br />
|x1 / x1 x1<br />
|If the top stack value is not 0, duplicate it.<br />
|-<br />
|OP_DEPTH<br />
|116<br />
|0x74<br />
|Nothing<br />
|depth<br />
|Puts the number of stack items onto the stack as one little-endian coded byte-vector<br />
|-<br />
|OP_DROP<br />
|117<br />
|0x75<br />
|x1<br />
|Nothing<br />
|Removes the top stack item.<br />
|-<br />
|OP_DUP<br />
|118<br />
|0x76<br />
|x1<br />
|x1 x1<br />
|Duplicates the top stack item.<br />
|-<br />
|OP_NIP<br />
|119<br />
|0x77<br />
|x2 x1<br />
|x1<br />
|Removes the second-to-top stack item.<br />
|-<br />
|OP_OVER<br />
|120<br />
|0x78<br />
|x2 x1<br />
|x2 x1 x2<br />
|Copies the second-to-top stack item to the top.<br />
|-<br />
|OP_PICK<br />
|121<br />
|0x79<br />
|xn ... x2 x1 x0 <n><br />
|xn ... x2 x1 x0 xn<br />
|<n> is removed and the item ''n'' back in the stack is copied to the top.<br />
|-<br />
|OP_ROLL<br />
|122<br />
|0x7a<br />
|xn ... x2 x1 x0 <n><br />
|... x2 x1 x0 xn<br />
|<n> is removed and the item ''n'' back in the stack is moved to the top.<br />
|-<br />
|OP_ROT<br />
|123<br />
|0x7b<br />
|x3 x2 x1<br />
|x2 x1 x3<br />
|The top three items on the stack are rotated to the left.<br />
|-<br />
|OP_SWAP<br />
|124<br />
|0x7c<br />
|x2 x1<br />
|x1 x2<br />
|The top two items on the stack are swapped resp. rotated.<br />
|-<br />
|OP_TUCK<br />
|125<br />
|0x7d<br />
|x2 x1<br />
|x1 x2 x1<br />
|The item at the top of the stack is copied and inserted before the second-to-top item.<br />
|}<br />
<br />
=== Splice ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_CAT<br />
|126<br />
|0x7e<br />
|x2 x1<br />
|out<br />
|Appends stack-top item at second-to top item. Concatenates two strings resp. byte vectors. ''Currently disabled.''<br />
|-<br />
|OP_SUBSTR<br />
|127<br />
|0x7f<br />
|x3 index size<br />
|out<br />
|Returns the section started at position <index> and of length <size> of a string resp. byte vector. ''Currently disabled.''<br />
|-<br />
|OP_LEFT<br />
|128<br />
|0x80<br />
|x2 index<br />
|out<br />
|Keeps only characters left of the specified point in second-to top item. ''Currently disabled.''<br />
|-<br />
|OP_RIGHT<br />
|129<br />
|0x81<br />
|x2 index<br />
|out<br />
|Keeps only characters right of the specified point in second-to top item. ''Currently disabled.''<br />
|-<br />
|OP_SIZE<br />
|130<br />
|0x82<br />
|x1<br />
|x1 size<br />
|Returns the length of the input string resp. byte vector resp. top-stack item.<br />
|}<br />
<br />
=== Bitwise logic ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_INVERT<br />
|131<br />
|0x83<br />
|x1<br />
|x0<br />
|Flips all of the bits in the input. ''Currently disabled.''<br />
|-<br />
|OP_AND<br />
|132<br />
|0x84<br />
|x2 x1<br />
|x0<br />
|Boolean ''and'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_OR<br />
|133<br />
|0x85<br />
|x2 x1<br />
|x0<br />
|Boolean ''or'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_XOR<br />
|134<br />
|0x86<br />
|x2 x1<br />
|x0<br />
|Boolean ''exclusive or'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_EQUAL<br />
|135<br />
|0x87<br />
|x2 x1<br />
|Boolean<br />
|Returns 1 if the inputs have the same length and are byte-wise equal, 0 otherwise.<br />
|-<br />
|OP_EQUALVERIFY<br />
|136<br />
|0x88<br />
|x2 x1<br />
|Nothing / false<br />
|Same as OP_EQUAL, but runs OP_VERIFY afterward.<br />
|}<br />
<br />
=== Arithmetic ===<br />
<br />
<!--(In very early versions, pre 0.2.0, the implemented arithmetic opcodes were limited to maximal 4 byte vectors.) --><br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_1ADD<br />
|139<br />
|0x8b<br />
|i1<br />
|i0<br />
|1 is added to the input.<br />
|-<br />
|OP_1SUB<br />
|140<br />
|0x8c<br />
|i1<br />
|i0<br />
|1 is subtracted from the input.<br />
|-<br />
|OP_2MUL<br />
|141<br />
|0x8d<br />
|i1<br />
|i0<br />
|The input is multiplied by 2. ''Currently disabled.''<br />
|-<br />
|OP_2DIV<br />
|142<br />
|0x8e<br />
|i1<br />
|i0<br />
|The input is divided by 2 (round down). ''Currently disabled.''<br />
|-<br />
|OP_NEGATE<br />
|143<br />
|0x8f<br />
|i1<br />
|i0<br />
|The sign of the input is flipped. Numerically the value is multiplied by -1<br />
|-<br />
|OP_ABS<br />
|144<br />
|0x90<br />
|i1<br />
|i0<br />
|The input is negative, its sign is flipped.<br />
|-<br />
|OP_NOT<br />
|145<br />
|0x91<br />
|i1<br />
|Boolean<br />
|If the input is 0 or 1, it is flipped. Otherwise the output will be 0. Test whether its value equals 0<br />
|-<br />
|OP_0NOTEQUAL<br />
|146<br />
|0x92<br />
|i1<br />
|Boolean<br />
|Returns 0 if the input is 0. 1 otherwise. Test whether its value is unequal 0<br />
|-<br />
|OP_ADD<br />
|147<br />
|0x93<br />
|i2 i1<br />
|i0<br />
|stack-top i1 is added to i2.<br />
|-<br />
|OP_SUB<br />
|148<br />
|0x94<br />
|i2 i1<br />
|i0<br />
|stack-top i1 is subtracted from i2.<br />
|-<br />
|OP_MUL<br />
|149<br />
|0x95<br />
|i2 i1<br />
|i0<br />
|i2 is multiplied with stack-top i1. ''Currently disabled.''<br />
|-<br />
|OP_DIV<br />
|150<br />
|0x96<br />
|i2 i1<br />
|i0<br />
|i2 is divided by stack-top i1 (divisor should be not 0). ''Currently disabled.''<br />
|-<br />
|OP_MOD<br />
|151<br />
|0x97<br />
|i2 i1<br />
|i0<br />
|Returns the remainder after dividing i2 by stack-top i1 (divisor should be not 0). ''Currently disabled.''<br />
|-<br />
|OP_LSHIFT<br />
|152<br />
|0x98<br />
|i2 i1<br />
|i0<br />
|Shifts i2 left by i1 bits, preserving sign of i2 (i1 >= 0). ''Currently disabled.''<br />
|-<br />
|OP_RSHIFT<br />
|153<br />
|0x99<br />
|i2 i1<br />
|i0<br />
|Shifts i2 right by i1 bits, preserving sign of i2 (i1 >= 0). ''Currently disabled.''<br />
|-<br />
|OP_BOOLAND<br />
|154<br />
|0x9a<br />
|i2 i1<br />
|Boolean<br />
|If both i2 and i1 are not 0, the output is 1. Otherwise 0.<br />
|-<br />
|OP_BOOLOR<br />
|155<br />
|0x9b<br />
|i2 i1<br />
|Boolean<br />
|If i2 or i1 is not 0, the output is 1. Otherwise 0.<br />
|-<br />
|OP_NUMEQUAL<br />
|156<br />
|0x9c<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 and i1 are numerically equal, 0 otherwise.<br />
|-<br />
|OP_NUMEQUALVERIFY<br />
|157<br />
|0x9d<br />
|i2 i1<br />
|Nothing / False<br />
|Same as OP_NUMEQUAL, but runs OP_VERIFY afterward.<br />
|-<br />
|OP_NUMNOTEQUAL<br />
|158<br />
|0x9e<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 and i1 are numerically not equal, 0 otherwise.<br />
|-<br />
|OP_LESSTHAN<br />
|159<br />
|0x9f<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is less than stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_GREATERTHAN<br />
|160<br />
|0xa0<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is greater than stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_LESSTHANOREQUAL<br />
|161<br />
|0xa1<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is less than or equal to stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_GREATERTHANOREQUAL<br />
|162<br />
|0xa2<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is greater than or equal to stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_MIN<br />
|163<br />
|0xa3<br />
|i2 i1<br />
|i2 / i1<br />
|Returns the smaller of i2 and i1.<br />
|-<br />
|OP_MAX<br />
|164<br />
|0xa4<br />
|i2 i1<br />
|i2 / i1<br />
|Returns the larger of i2 and i1.<br />
|-<br />
|OP_WITHIN<br />
|165<br />
|0xa5<br />
|i3 i2 i1<br />
|Boolean<br />
|Returns 1 if i3 >= i2 and i3 < i1, 0 otherwise. Thus if i2 > i1 returns always 0.<br />
|}<br />
<br />
=== Crypto ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_RIPEMD160<br />
|166<br />
|0xa6<br />
|x<br />
|hash20<br />
|The input is hashed using RIPEMD-160.<br />
|-<br />
|OP_SHA1<br />
|167<br />
|0xa7<br />
|x<br />
|hash20<br />
|The input is hashed using SHA-1.<br />
|-<br />
|OP_SHA256<br />
|168<br />
|0xa8<br />
|x<br />
|hash32<br />
|The input is hashed using SHA-256.<br />
|-<br />
|OP_HASH160<br />
|169<br />
|0xa9<br />
|x<br />
|hash20<br />
|The input is hashed twice: first with SHA-256 and then with RIPEMD-160.<br />
|-<br />
|OP_HASH256<br />
|170<br />
|0xaa<br />
|x<br />
|hash32<br />
|The input is hashed two times with SHA-256.<br />
|-<br />
|OP_CODESEPARATOR<br />
|171<br />
|0xab<br />
|Nothing<br />
|Nothing<br />
|All of the signature checking opcodes will only match signatures to the data after the most recently-executed OP_CODESEPARATOR.<br />
|-<br />
|[[OP_CHECKSIG]]<br />
|172<br />
|0xac<br />
|sig pubkey<br />
|Boolean<br />
|The entire transaction's outputs, inputs, and script (from the most recently-executed OP_CODESEPARATOR to the end) are hashed. The signature used by OP_CHECKSIG must be a valid signature for a further, extern specified hash and the given public key. If it is, 1 is returned, 0 otherwise.<br />
|-<br />
|OP_CHECKSIGVERIFY<br />
|173<br />
|0xad<br />
|sig pubkey<br />
|Nothing / False<br />
|Same as OP_CHECKSIG, but OP_VERIFY is executed afterward.<br />
|-<br />
|OP_CHECKMULTISIG<br />
|174<br />
|0xae<br />
|sig1 sig2 ... <number of signatures> pub1 pub2 <number of public keys><br />
|Boolean<br />
|For each signature and public key pair, OP_CHECKSIG is executed. If more public keys than signatures are listed, some key/sig pairs can fail. All signatures need to match a public key. If all signatures are valid, 1 is returned, 0 otherwise. Due to a bug, one extra unused value is removed from the stack.<br />
|-<br />
|OP_CHECKMULTISIGVERIFY<br />
|175<br />
|0xaf<br />
|sig1 sig2 ... <number of signatures> pub1 pub2 ... <number of public keys><br />
|Nothing / False<br />
|Same as OP_CHECKMULTISIG, but OP_VERIFY is executed afterward.<br />
|}<br />
<br />
=== Expansion opcodes ===<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_NOP1-OP_NOP10<br />
|176-185<br />
|0xb0-0xb9<br />
|The opcode has no effect.<br />
|}<br />
<br />
=== Version opcodes ===<br />
Version opcodes are disabled since bitcoin 0.2.0 and should not be used (maybe reassigned in the future).<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_VER<br />
|98<br />
|0x62<br />
|Script evalution is triggered invalid (Formerly pushed the bitcoin-serialize version onto stack).<br />
|-<br />
|OP_VERIF<br />
|101<br />
|0x65<br />
|Script evalution is triggered invalid (Formerly top stack item was popped and =< compared to present version)<br />
|-<br />
|OP_VERNOTIF<br />
|102<br />
|0x66<br />
|Script evalution is triggered invalid (Formerly top stack item was popped and > compared to present version)<br />
|}<br />
<br />
=== Reserved opcodes ===<br />
Each opcode not assigned (currently also every opcode value > 185) is also reserved. Using any unassigned opcode triggers the script evaluation to be invalid.<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_RESERVED<br />
|80<br />
|0x50<br />
|Script evalution is triggered invalid-<br />
|-<br />
|OP_RESERVED1<br />
|137<br />
|0x89<br />
|Script evalution is triggered invalid.<br />
|-<br />
|OP_RESERVED2<br />
|138<br />
|0x8a<br />
|Script evalution is triggered invalid.<br />
|}<br />
<br />
===Pseudo-opcodes===<br />
These nemonics are used internally for assisting with transaction matching. They are invalid if used in actual scripts.<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_PUBKEYHASH<br />
|253<br />
|0xfd<br />
|Represents a public key hashed with OP_HASH160.<br />
|-<br />
|OP_PUBKEY<br />
|254<br />
|0xfe<br />
|Represents a public key compatible with OP_CHECKSIG.<br />
|-<br />
|OP_INVALIDOPCODE<br />
|255<br />
|0xff<br />
|Matches any opcode that is not yet assigned.<br />
|}<br />
<br />
==Scripts in bitcoin transactions==<br />
It follows a list of important (most occuring) scripts to see opcodes "at work". Keep in mind that all constants actually use the data-pushing instructions above. At start of a (transaction input) script evaluation, the stack is always empty. Currently less than 0.01 % of all txout-scripts / scriptPubKeys in the main block chain are not of the following two standard scripts.<br />
<br />
===Standard transaction to bitcoin address===<br />
<br />
scriptPubKey: OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG<br />
scriptSig: <sig> <pubKey><br />
<br />
To demonstrate how scripts look on the wire, here is a raw scriptPubKey:<br />
<pre> 76 A9 14<br />
OP_DUP OP_HASH160 Bytes to push<br />
<br />
89 AB CD EF AB BA AB BA AB BA AB BA AB BA AB BA AB BA AB BA 88 AC<br />
Data to push OP_EQUALVERIFY OP_CHECKSIG</pre><br />
<br />
Note: scriptSig is in the input of the spending transaction and scriptPubKey is in the output of the previously storing transaction, i.e. its "available bitcoins".<br />
<br />
Here is how each instruction is processed:<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
| <sig> <pubKey> OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| scriptSig and scriptPubKey are combined.<br />
|-<br />
|<sig> <pubKey><br />
| OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| Constants are added to the stack.<br />
|-<br />
|<sig> <pubKey> <pubKey><br />
| OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| Top stack item is duplicated.<br />
|-<br />
|<sig> <pubKey> <pubHashA><br />
|<pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG<br />
| Top stack item is hashed.<br />
|-<br />
|<sig> <pubKey> <pubHashA> <pubKeyHash><br />
|OP_EQUALVERIFY OP_CHECKSIG<br />
| Constant added.<br />
|-<br />
|<sig> <pubKey><br />
|OP_CHECKSIG<br />
| Equality is checked between the top two stack items.<br />
|-<br />
|true<br />
|Empty.<br />
|Signature is checked for top two stack items.<br />
|}<br />
<br />
===Transaction to IP address (and generation transaction)===<br />
<br />
scriptPubKey: <pubKey> OP_CHECKSIG<br />
scriptSig: <sig><br />
<br />
Checking process:<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
|<sig> <pubKey> OP_CHECKSIG<br />
|scriptSig and scriptPubKey are combined.<br />
|-<br />
|<sig> <pubKey><br />
| OP_CHECKSIG<br />
|Constants are added to the stack.<br />
|-<br />
|true<br />
|Empty.<br />
|Signature is checked for top two stack items.<br />
|}<br />
<br />
In the case of a '''coin generation transaction''' (the first transaction of each block), there is no scriptSig, resp. its code ("coinbase") is completly ignored for the transaction. Only the scriptPubKey is used.<br />
<br />
===Transaction with a message===<br />
<br />
It's possible to add arbitrary data to any transaction by just adding some data along with OP_DROP. <br />
scriptPubKey: <message> OP_DROP <pubKey> OP_CHECKSIG<br />
scriptSig: <sig><br />
<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
|<sig> <message> OP_DROP <pubKey> OP_CHECKSIG<br />
|<br />
|-<br />
|<sig><br />
|<message> OP_DROP <pubKey> OP_CHECKSIG<br />
|scriptSig added to the stack.<br />
|-<br />
|<sig> <message><br />
|OP_DROP <pubKey> OP_CHECKSIG<br />
|The message has been put.<br />
|-<br />
|<sig><br />
|<pubKey> OP_CHECKSIG<br />
|Top stack item has been removed.<br />
|-<br />
|<sig> <pubKey><br />
|OP_CHECKSIG<br />
|Checking signature against the public key.<br />
|-<br />
|true<br />
|Empty.<br />
|Stack holds the value of signature check now.<br />
|}<br />
<br />
===Examples of non standard transaction on Testnet===<br />
<br />
These two links below show a non standard transaction. It just prepends the hex of "bob" and the operation OP_DROP<br />
which just removes it. As you can see they can be spent as normal.<br />
<br />
Input non-std transaction:<br />
http://blockexplorer.com/testnet/t/6ttfeb55B1<br />
<br />
Spent by:<br />
http://blockexplorer.com/testnet/t/AFdRB1CHS3<br />
<br />
==Script validation==<br />
A script evaluation is considered invalid, if any of these conditions meets:<br><br />
<ul><br />
<li>the total size of the script exceeds (currently) 10000 bytes<br />
<li>there are more than (currently) 201 opcodes of opcode value > 0x60 in the script<br />
<li>each instruction is (currently) limited to maximal 520 bytes. This effects only the opcodes OP_PUSHDATA2 and OP_PUSHDATA4<br />
<li>the executed opcode of the script has insufficient input (from stack, from script or from anywhere)<br />
<li>the opcode is not defined (for execution) - indicated by white or light gray background color in the table<br />
<li>the opcode is disabled (currently 15 opcodes) - indicated by white font color in the opcode overview matrix<br />
<li>stack overflow occurs during execution of the opcode (currently the number of items on the stack and on the alternate stack is limited to 1000)<br />
<li>the opcodes OP_VERIF and OP_NOTVERIF invalidate a script which contains this opcode (even if this opcode is not executed!)<br />
<li>the opcodes OP_ELSE or OP_ENDIF has no matching OP_IF<br><br />
<li>the script execution has been finished but there is (at least) an unmatched OP_IF<br><br />
<li>the opcodes OP_VERIFY, OP_EQUALVERIFY, OP_NUMEQUALVERIFY, OP_CHECKSIGVERIFY and OP_CHECKMULTISIGVERIFY invalidate the script if the stack-top item is false<br />
<li>the execution of OP_RETURN<br />
<!--li>alt stack overflow occurs (only possible during execution of OP_TOALTSTACK)--><br />
<li>the numerical value of the top-stack item is negative or greater than the number of items - 2 on the stack if OP_PICK or OP_ROLL shall be executed<br />
<li>an item used as public key or signature for each of the opcodes OP_CHECKSIG, OP_CHECKSIGVERIFY, OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY can be neither a public key or signature (for the given hash)<br />
<li>the number of signature items or the number of public key items on the stack is negative for OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY<br />
<li>there or more signatures items than public key items on the stack for OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY<br />
<li>there are (currently) more than 20 public key items on the stack for OP_CHECKMULTISIG or CHECKMULTISIGVERIFY<br />
<li>the sum of opcodes > 0x60 and the number of public keys in all executed OP_CHECKMULTISIG or CHECKMULTISIGVERIFY exceeds (currently) 201<br />
<li>the script execution has been finished and the stack is empty or the top-stack item is false (numerical value 0)<br />
</ul><br />
else the script evaluation is considered to be valid.<ref>[http://sourceforge.net/projects/bitcoin/files/Bitcoin/bitcoin-0.7.1/bitcoin-0.7.1-linux.tar.gz file src/src/script.cpp in bitcoin-0.7.1]</ref><br />
'''If invalidation of a script is triggered then the script is immediately finished.''' These arbitrary looking limitations of 10000, 201, 520, 1000 and 20 might be increased in the future -- they serve to prevent strong slow down of the evaluation of a script while not restricting its practical usage really.<br />
<br />
==Withdrawn and drafted opcodes==<br />
<br />
<ul><br />
<li> byte value 0x89 OP_NOTEQUAL defined in pre-0.1.0 bitcoin versions. Since 0.1.0 removed because of security concerns. <br />
<li> byte value 0xb1 [[BIP 0012 | OP_EVAL]] withdraw - poll was triggered but insufficient support. <br />
<li> byte value 0xb2 [[BIP 0017 | OP_CHECKHASHVERIFY]] withdraw - poll was triggered but insufficient support.<br />
</ul><br />
<br />
==See Also==<br />
* [[Transactions]]<br />
* [[Contracts]]<br />
<br />
==References==<br />
<references/><br />
<ul><br />
<li>[http://www.zorinaq.com/pub/bitcoin-0.1.0.tgz file src/script.cpp in bitcoin-0.1.0]</li><br />
</ul><br />
[[Category:Technical]]<br />
[[Category:Vocabulary]]</div>
Smtp
https://en.bitcoin.it/w/index.php?title=Script&diff=34912
Script
2013-01-11T16:27:52Z
<p>Smtp: /* Scripts in bitcoin transactions */</p>
<hr />
<div>Bitcoin uses a scripting system for [[transactions]]. [[Wikipedia:FORTH|Forth]]-like, Script is simple, stack-based, and processed from left to right. It is purposefully not Turing-complete, with no loops.<br />
<br />
A script is essentially a list of instructions recorded with each transaction that describe how the next person wanting to spend the Bitcoins being transferred can gain access to them.<br />
<br />
Scripts are big-endian and their sequences of bytes is interpreted as a sequence of opcodes with operands. Only opcodes with byte values less than 0x4f have additional operands.<br />
<br />
== Scripts and Bitcoin transactions ==<br />
The script for a typical Bitcoin transfer to destination Bitcoin address D simply encumbers future spending of the bitcoins with two things: the spender must provide<br />
# a public key that, when hashed, yields destination address D embedded in the script, and<br />
# a signature to show evidence of the private key corresponding to the public key just provided.<br />
<br />
Scripting provides the flexibility to change the parameters of what's needed to spend transferred Bitcoins. For example, the scripting system could be used to require two private keys, or a combination of several, or even no keys at all.<br />
<br />
A transaction is valid if nothing in the combined script triggers failure and the top stack item exists and is true (non-zero). The party who originally ''stored'' the Bitcoins now being spent, dictates the script operations that will occur ''last'' in order to release them for use in another transaction. The party wanting to spend them must provide the input(s) to the previously recorded script that results in those operations occurring last leaving behind true (non-zero) on the stack.<br><br />
Only the very first transaction in each bitcoin block has no input script (the entry there is called "coinbase"), because the Bitcoins created with the block are created from hot air and not released by a previous recorded script.<br />
<br />
== Stack ==<br />
<br />
The stacks hold byte vectors (there is the (main) stack and an alternative stack). Byte vectors are interpreted as little-endian variable-length integers with the most significant bit determining the sign of the integer. Thus 0x81 represents -1. 0x80 is another representation of zero (so called negative 0). Byte vectors are interpreted as Booleans where False is represented by any representation of zero, and True is represented by any representation of non-zero.<br />
<br />
== Opcode overview ==<br />
<br />
For each opcode is given: its nemonic without the leading OP_, its hexadecimal byte value, the number of stack items needed (poped) during execution, a semicolon and the number of stack items which has been pushed (after execution). A * after the needed stack items indicates that further bytes from the script following the current opcode are needed. A # indicates that items on the alternative stack are poped/pushed. A @ indicates that further (global) data from the transaction is needed. A / indicates alternatives of a value. <br/><br />
Different colors indicate different semantic execution groups of opcodes:<br />
{| style="background:none; font-size:100%; padding:0; border-collapse:collapse; text-align:center; line-height:2em;" border="0" align="center" <br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | copy a fixed number of bytes but at most 75 onto stack<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | copy bytes onto stack which number is given by a 1, 2 or 4 byte value.<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | copy 1 specific byte onto stack<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | undefined opcode<br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | a pseudo-opcode, unassigned for scripts<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | NOP or opcode is part of a IF-flow-control construction<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00ff00;" | (stack conditionally) invalidation of the script this opcode is part of<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | stack item is moved between main stack and alternate stack<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | stack item(s) is/are moved, copied or deleted<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0;" | byte vectors are appended or divided or their size is determined<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff;" | byte vectors are interpreted bit-position-independently<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | byte vectors are interpreted and processed as signed integers<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | a hash value is computed or a signature checked<br />
|}<br />
<p><br />
===Opcode byte-matrix===<br />
The opcode value 0x00 with nemonic OP_FALSE is also named OP_0 and the opcode value 0x51 with nemonic OP_1 as also named OP_TRUE.<br />
{| style="background:none; font-size:100%; padding:0; border-collapse:collapse; text-align:center; line-height:2em;" border="0" align="center" <br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" |_FALSE<br/> 0x00 <br/> 0 ; 1(0) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x01<br/> 0 *; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x02<br/> 0 *; 1(2)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x03<br/> 0 *; 1(3)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x04<br/> 0 *; 1(4)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x04<br/> 0 *; 1(5)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x06<br/> 0 *; 1(6)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x07<br/> 0 *; 1(7)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x08<br/> 0 *; 1(8)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x09<br/> 0 *; 1(9)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0a<br/> 0 *; 1(10)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0b<br/> 0 *; 1(11)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0c<br/> 0 *; 1(12)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0d<br/> 0 *; 1(13)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0e<br/> 0 *; 1(14)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0f<br/> 0 *; 1(15)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x10 <br/> 0 *; 1(16) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x11 <br/> 0 *; 1(17)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x12 <br/> 0 *; 1(18)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x13 <br/> 0 *; 1(19)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x14 <br/> 0 *; 1(20)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x15 <br/> 0 *; 1(21)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x16 <br/> 0 *; 1(22)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x17 <br/> 0 *; 1(23)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x18 <br/> 0 *; 1(24)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x19 <br/> 0 *; 1(25)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1a <br/> 0 *; 1(26)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1b <br/> 0 *; 1(27)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1c <br/> 0 *; 1(28)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1d <br/> 0 *; 1(29)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1e <br/> 0 *; 1(30)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1f <br/> 0 *; 1(31)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x20 <br/> 0 *; 1(32) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x21 <br/> 0 *; 1(33)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x22 <br/> 0 *; 1(34)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x23 <br/> 0 *; 1(35)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x24 <br/> 0 *; 1(36)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x25 <br/> 0 *; 1(37)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x26 <br/> 0 *; 1(38)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x27 <br/> 0 *; 1(39)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x28 <br/> 0 *; 1(40)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x29 <br/> 0 *; 1(41)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2a <br/> 0 *; 1(42)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2b <br/> 0 *; 1(43)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2c <br/> 0 *; 1(44)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2d <br/> 0 *; 1(45)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2e <br/> 0 *; 1(46)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2f <br/> 0 *; 1(47)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x30 <br/> 0 *; 1(48) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x31 <br/> 0 *; 1(49)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x32 <br/> 0 *; 1(50)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x33 <br/> 0 *; 1(51)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x34 <br/> 0 *; 1(52)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x35 <br/> 0 *; 1(53)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x36 <br/> 0 *; 1(54)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x37 <br/> 0 *; 1(55)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x38 <br/> 0 *; 1(56)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x39 <br/> 0 *; 1(57)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3a <br/> 0 *; 1(58)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3b <br/> 0 *; 1(59)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3c <br/> 0 *; 1(60)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3d <br/> 0 *; 1(61)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3e <br/> 0 *; 1(62)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3f <br/> 0 *; 1(63)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x40 <br/> 0 *; 1(64) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x41 <br/> 0 *; 1(65)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x42 <br/> 0 *; 1(66)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x43 <br/> 0 *; 1(67)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x44 <br/> 0 *; 1(68)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x45 <br/> 0 *; 1(69)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x46 <br/> 0 *; 1(70)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x47 <br/> 0 *; 1(71)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x48 <br/> 0 *; 1(72)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x49 <br/> 0 *; 1(73)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x4a <br/> 0 *; 1(74)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x4b <br/> 0 *; 1(75)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA1 <br/> 0x4c <br/> 0 *; 1(0 - 255)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA2 <br/> 0x4d <br/> 0 *; 1(0 - 2^16-1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA4 <br/> 0x4e <br/> 0 *; 1(0 - 2^32-1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _1NEGATE <br/> 0x4f <br/> 0 ; 1(1)<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED <br/> 0x50 <br/> <br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _1 <br/> 0x51 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _2 <br/> 0x52 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _3 <br/> 0x53 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _4 <br/> 0x54 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _5 <br/> 0x55 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _6 <br/> 0x56 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _7 <br/> 0x57 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _8 <br/> 0x58 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _9 <br/> 0x59 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _10 <br/> 0x5a <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _11 <br/> 0x5b <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _12 <br/> 0x5c <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _13 <br/> 0x5d <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _14 <br/> 0x5e <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _15 <br/> 0x5f <br/> 0 ; 1(1)<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _16 <br/> 0x60 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP <br/> 0x61 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VER <br/> 0x62 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _IF <br/> 0x63 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOTIF <br/> 0x64 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VERIF <br/> 0x65 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VERNOTIF <br/> 0x66 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _ELSE <br/> 0x67 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _ENDIF <br/> 0x68 <br/> 0 ; 0<br />
| style="border:3px solid #808080; background-color:#00ff00;" | _VERIFY <br/> 0x69 <br/> 1 ; 0/1<br />
| style="border:3px solid #808080; background-color:#00ff00;" | _RETURN <br/> 0x6a <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | _TOALTSTACK <br/> 0x6b <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | _FROMALTSTACK <br/> 0x6c <br/> 0 #; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2DROP <br/> 0x6d <br/> 2 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2DUP <br/> 0x6e <br/> 2 ; 4<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _3DUP <br/> 0x6f <br/> 3 ; 6<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2OVER <br/> 0x70 <br/> 4 ; 6<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2ROT <br/> 0x71 <br/> 6 ; 6<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2SWAP <br/> 0x72 <br/> 4 ; 4<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _IFDUP <br/> 0x73 <br/> 1 ; 1/2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DEPTH <br/> 0x74 <br/> 0 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DROP <br/> 0x75 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DUP <br/> 0x76 <br/> 1 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _NIP <br/> 0x77 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _OVER <br/> 0x78 <br/> 2 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _PICK <br/> 0x79 <br/> 1+n+1 ; n+2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _ROLL <br/> 0x7a <br/> 1+n+1 ; n+1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _ROT <br/> 0x7b <br/> 3 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _SWAP <br/> 0x7c <br/> 2 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _TUCK <br/> 0x7d <br/> 2 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _CAT <br/> 0x7e <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _SUBSTR <br/> 0x7f <br/> 3 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _LEFT <br/> 0x80 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _RIGHT <br/> 0x81 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0;" | _SIZE <br/> 0x82 <br/> 1 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _INVERT <br/> 0x83 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _AND <br/> 0x84 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _OR <br/> 0x85 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _XOR <br/> 0x86 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff;" | _EQUAL <br/> 0x87 <br/> 2 ; 1<br />
| style="border:3px solid #808080; background-color:#c080ff;" | _EQUALVERIFY <br/> 0x88 <br/> 2 ; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED1 <br/> 0x89 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED2 <br/> 0x8a <br/><br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _1ADD <br/> 0x8b <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _1SUB <br/> 0x8c <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _2MUL <br/> 0x8d <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _2DIV <br/> 0x8e <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NEGATE <br/> 0x8f <br/> 1 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _ABS <br/> 0x90 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NOT <br/> 0x91 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _0NOTEQUAL <br/> 0x92 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _ADD <br/> 0x93 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _SUB <br/> 0x94 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _MUL <br/> 0x95 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _DIV <br/> 0x96 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _MOD <br/> 0x97 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _LSHIFT <br/> 0x98 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _RSHIFT <br/> 0x99 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _BOOLAND <br/> 0x9a <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _BOOLOR <br/> 0x9b <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NUMEQUAL <br/> 0x9c <br/> 2 ; 1<br />
| style="border:3px solid #808080; background-color:#8080ff;" | _NUMEQUALVERIFY <br/> 0x9d <br/> 2 ; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NUMNOTEQUAL <br/> 0x9e <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _LESSTHAN <br/> 0x9f <br/> 2 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _GREATERTHAN <br/> 0xa0 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _LESSTHANOREQUAL <br/> 0xa1 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _GREATERTHANOREQUAL <br/> 0xa2 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _MIN <br/> 0xa3 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _MAX <br/> 0xa4 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _WITHIN <br/> 0xa5 <br/> 3 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _RIPEMD160 <br/> 0xa6 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _SHA1 <br/> 0xa7 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _SHA256 <br/> 0xa8 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _HASH160 <br/> 0xa9 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _HASH256 <br/> 0xaa <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CODESEPARATOR <br/> 0xab <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CHECKSIG <br/> 0xac <br/> 2 @; 1<br />
| style="border:3px solid #808080; background-color:#a0d0ff;" | _CHECKSIGVERIFY <br/> 0xad <br/> 2 @; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CHECKMULTISIG <br/> 0xae <br/> 2n+2 @; 1<br />
| style="border:3px solid #808080; background-color:#a0d0ff;" | _CHECKMULTISIGVERIFY <br/> 0xaf <br/> 2n+2 @; 0/1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP1 <br/> 0xb0 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP2 <br/> 0xb1 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP3 <br/> 0xb2 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP4 <br/> 0xb3 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP5 <br/> 0xb4 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP6 <br/> 0xb5 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP7 <br/> 0xb6 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP8 <br/> 0xb7 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP9 <br/> 0xb8 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP10 <br/> 0xb9 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xba <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbe <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xca <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xce <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xda <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xde <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xea <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xeb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xec <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xed <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xee <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xef <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xfa <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _SMALLINTEGER <br/> 0xfb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEYS <br/> 0xfc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEYHASH <br/> 0xfd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEY <br/> 0xfe <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _INVALIDOPCODE <br/> 0xff <br/><br />
|}<br><br />
Except later pseudo-opcode changes, the definition of OP_NOP1 - OP_NOP10 and the change of the evaluation of OP_RETURN (did no invalidation previously) which both occured in bitcoin version 0.3.6 in July 2010 were the last changes regarding opcodes <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.2.0/bitcoin-0.2.0-linux.tar.gz file src/srcipt.cpp in bitcoin-0.2.0]</ref> <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.3.3/bitcoin-0.3.3-linux.tar.gz file src/srcipt.cpp in bitcoin-0.3.3]</ref> <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.3.6/bitcoin-0.3.6-linux.tar.gz file src/srcipt.cpp in bitcoin-0.3.6]</ref>.<br />
<br />
== Opcode descriptions ==<br />
It follows for each opcode less than decimal 185 (hexa 0xba) a description for its usage. The columns entitled ''nemonic'', ''decimal'' and ''Hex'' should be evident. The column ''input'' gives the needed items of the stack (and the alternate stack) and the column ''output'' indicates the resulting items on the stack (and the alternate stack). '''Stack-top is always the right most item.''' The naming of the entries in these two columns is chosen to reflect their interpretation. ''x'', ''x0'', ''x1'', ... means arbitrary or no interpretation, ''i0'', ''i1'' and ''i2'' a signed integer value, ''n'',''index'',''size'' and ''depth'' non-negative (unsigned) integer values, ''Boolean'' as either a true or false.<br><br />
<br />
Some of the more complicated opcodes are disabled out of concern that the client might have (and has) a bug in the current implementation due to the historically not as 2-complement interpretations of the byte vectors as numerical values (the most significant byte holds the sign of the byte vectors).<br />
<br />
=== Push data from instruction onto stack ===<br />
<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_FALSE, OP_0<br />
|0<br />
|0x00<br />
|Nothing<br />
|Empty string<br />
|A byte vector of length 0 is pushed onto the stack. (Thus, it is not a no-op!)<br />
|-<br />
|(no official nemonics)<br />
|1 - 75<br />
|0x01 - 0x4b<br />
|(operand)<br />
|x<br />
|The next <opcode>-many bytes are to be pushed onto the stack.<br />
|-<br />
|OP_PUSHDATA1<br />
|76<br />
|0x4c<br />
|(operands)<br />
|x<br />
|The next byte contains the number of bytes to be pushed onto the stack which follow this byte.<br />
|-<br />
|OP_PUSHDATA2<br />
|77<br />
|0x4d<br />
|(operands)<br />
|x<br />
|The next two bytes contain the number of bytes to be pushed onto the stack which follow theses 2 bytes.<br />
|-<br />
|OP_PUSHDATA4<br />
|78<br />
|0x4e<br />
|(operands)<br />
|x<br />
|The next four bytes contain the number of bytes to be pushed onto the stack which follow theses 4 bytes.<br />
|-<br />
|OP_1NEGATE<br />
|79<br />
|0x4f<br />
|Nothing<br />
| -1<br />
|The byte with value -1 is pushed onto the stack.<br />
|-<br />
|OP_1, OP_TRUE<br />
|81<br />
|0x51<br />
|Nothing<br />
|1<br />
|The byte with value 1 is pushed onto the stack.<br />
|-<br />
|OP_2 - OP_16<br />
|82 - 96<br />
|0x52 - 0x60<br />
|Nothing<br />
|2-16<br />
|The byte with value <opcode>-80 (thus, one of 2 - 16) is pushed onto the stack.<br />
|}<br />
<br />
=== Flow control ===<br />
<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_NOP<br />
|97<br />
|0x61<br />
|Nothing<br />
|Nothing<br />
|Does nothing.<br />
|-<br />
|OP_IF<br />
|99<br />
|0x63<br />
|Boolean<br />
|Nothing<br />
|If the top stack value is not 0, the statements are executed. The top stack value is removed. Lead in a logcial ''<value> then [statements] [else [statements]] endif'' expression<br />
|-<br />
|OP_NOTIF<br />
|100<br />
|0x64<br />
|Boolean<br />
|Nothing<br />
|If the top stack value is 0, the statements are executed. The top stack value is removed. Lead in a logcial ''<value> then [statements] [else [statements]] endif'' expression <br />
|-<br />
|OP_ELSE<br />
|103<br />
|0x67<br />
|Nothing<br />
|Nothing<br />
|If the preceeding OP_IF or OP_NOTIF or OP_ELSE was not executed then these statements are and if the preceding OP_IF or OP_NOTIF or OP_ELSE was executed then these statements are not. <br />
|-<br />
|OP_ENDIF<br />
|104<br />
|0x68<br />
|Nothing<br />
|Nothing<br />
|Ends a logcial ''If <value> then [statements] [else [statements]] '' expression<br />
|-<br />
|OP_VERIFY<br />
|105<br />
|0x69<br />
|Boolean<br />
|Nothing / False<br />
|If top stack value is not true then marks transaction as '''invalid''' . A value true is removed, but false is not.<br />
|-<br />
|OP_RETURN<br />
|106<br />
|0x6a<br />
|Nothing<br />
|Nothing<br />
|Marks transaction as '''invalid'''. <br />
|}<br />
<br />
===Stack item organization===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_TOALTSTACK<br />
|107<br />
|0x6b<br />
|x1 (alt)<br />
|(alt x1)<br />
|Puts the input onto the top of the alt stack. Removes it from the (main) stack.<br />
|-<br />
|OP_FROMALTSTACK<br />
|108<br />
|0x6c<br />
|(alt x1)<br />
|x1 (alt)<br />
|Puts the input onto the top of the (main) stack. Removes it from the alt stack.<br />
|-<br />
|OP_2DROP<br />
|109<br />
|0x6d<br />
|x2 x1<br />
|Nothing<br />
|Removes the top two stack items.<br />
|-<br />
|OP_2DUP<br />
|110<br />
|0x6e<br />
|x2 x1<br />
|x2 x1 x2 x1<br />
|Duplicates the top two stack items.<br />
|-<br />
|OP_3DUP<br />
|111<br />
|0x6f<br />
|x3 x2 x1<br />
|x3 x2 x1 x3 x2 x1<br />
|Duplicates the top three stack items.<br />
|-<br />
|OP_2OVER<br />
|112<br />
|0x70<br />
|x4 x3 x2 x1<br />
|x4 x3 x2 x1 x4 x3<br />
|Copies the pair of items two spaces back in the stack to the front.<br />
|-<br />
|OP_2ROT<br />
|113<br />
|0x71<br />
|x6 x5 x4 x3 x2 x1<br />
|x4 x3 x2 x1 x6 x5<br />
|The fifth and sixth items back are moved to the top of the stack. Twotimes left rotate.<br />
|-<br />
|OP_2SWAP<br />
|114<br />
|0x72<br />
|x4 x3 x2 x1<br />
|x2 x1 x4 x3<br />
|Swaps the top two pairs of stack items.<br />
|-<br />
|OP_IFDUP<br />
|115<br />
|0x73<br />
|x1<br />
|x1 / x1 x1<br />
|If the top stack value is not 0, duplicate it.<br />
|-<br />
|OP_DEPTH<br />
|116<br />
|0x74<br />
|Nothing<br />
|depth<br />
|Puts the number of stack items onto the stack as one little-endian coded byte-vector<br />
|-<br />
|OP_DROP<br />
|117<br />
|0x75<br />
|x1<br />
|Nothing<br />
|Removes the top stack item.<br />
|-<br />
|OP_DUP<br />
|118<br />
|0x76<br />
|x1<br />
|x1 x1<br />
|Duplicates the top stack item.<br />
|-<br />
|OP_NIP<br />
|119<br />
|0x77<br />
|x2 x1<br />
|x1<br />
|Removes the second-to-top stack item.<br />
|-<br />
|OP_OVER<br />
|120<br />
|0x78<br />
|x2 x1<br />
|x2 x1 x2<br />
|Copies the second-to-top stack item to the top.<br />
|-<br />
|OP_PICK<br />
|121<br />
|0x79<br />
|xn ... x2 x1 x0 <n><br />
|xn ... x2 x1 x0 xn<br />
|<n> is removed and the item ''n'' back in the stack is copied to the top.<br />
|-<br />
|OP_ROLL<br />
|122<br />
|0x7a<br />
|xn ... x2 x1 x0 <n><br />
|... x2 x1 x0 xn<br />
|<n> is removed and the item ''n'' back in the stack is moved to the top.<br />
|-<br />
|OP_ROT<br />
|123<br />
|0x7b<br />
|x3 x2 x1<br />
|x2 x1 x3<br />
|The top three items on the stack are rotated to the left.<br />
|-<br />
|OP_SWAP<br />
|124<br />
|0x7c<br />
|x2 x1<br />
|x1 x2<br />
|The top two items on the stack are swapped resp. rotated.<br />
|-<br />
|OP_TUCK<br />
|125<br />
|0x7d<br />
|x2 x1<br />
|x1 x2 x1<br />
|The item at the top of the stack is copied and inserted before the second-to-top item.<br />
|}<br />
<br />
=== Splice ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_CAT<br />
|126<br />
|0x7e<br />
|x2 x1<br />
|out<br />
|Appends stack-top item at second-to top item. Concatenates two strings resp. byte vectors. ''Currently disabled.''<br />
|-<br />
|OP_SUBSTR<br />
|127<br />
|0x7f<br />
|x3 index size<br />
|out<br />
|Returns the section started at position <index> and of length <size> of a string resp. byte vector. ''Currently disabled.''<br />
|-<br />
|OP_LEFT<br />
|128<br />
|0x80<br />
|x2 index<br />
|out<br />
|Keeps only characters left of the specified point in second-to top item. ''Currently disabled.''<br />
|-<br />
|OP_RIGHT<br />
|129<br />
|0x81<br />
|x2 index<br />
|out<br />
|Keeps only characters right of the specified point in second-to top item. ''Currently disabled.''<br />
|-<br />
|OP_SIZE<br />
|130<br />
|0x82<br />
|x1<br />
|x1 size<br />
|Returns the length of the input string resp. byte vector resp. top-stack item.<br />
|}<br />
<br />
=== Bitwise logic ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_INVERT<br />
|131<br />
|0x83<br />
|x1<br />
|x0<br />
|Flips all of the bits in the input. ''Currently disabled.''<br />
|-<br />
|OP_AND<br />
|132<br />
|0x84<br />
|x2 x1<br />
|x0<br />
|Boolean ''and'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_OR<br />
|133<br />
|0x85<br />
|x2 x1<br />
|x0<br />
|Boolean ''or'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_XOR<br />
|134<br />
|0x86<br />
|x2 x1<br />
|x0<br />
|Boolean ''exclusive or'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_EQUAL<br />
|135<br />
|0x87<br />
|x2 x1<br />
|Boolean<br />
|Returns 1 if the inputs have the same length and are byte-wise equal, 0 otherwise.<br />
|-<br />
|OP_EQUALVERIFY<br />
|136<br />
|0x88<br />
|x2 x1<br />
|Nothing / false<br />
|Same as OP_EQUAL, but runs OP_VERIFY afterward.<br />
|}<br />
<br />
=== Arithmetic ===<br />
<br />
<!--(In very early versions, pre 0.2.0, the implemented arithmetic opcodes were limited to maximal 4 byte vectors.) --><br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_1ADD<br />
|139<br />
|0x8b<br />
|i1<br />
|i0<br />
|1 is added to the input.<br />
|-<br />
|OP_1SUB<br />
|140<br />
|0x8c<br />
|i1<br />
|i0<br />
|1 is subtracted from the input.<br />
|-<br />
|OP_2MUL<br />
|141<br />
|0x8d<br />
|i1<br />
|i0<br />
|The input is multiplied by 2. ''Currently disabled.''<br />
|-<br />
|OP_2DIV<br />
|142<br />
|0x8e<br />
|i1<br />
|i0<br />
|The input is divided by 2 (round down). ''Currently disabled.''<br />
|-<br />
|OP_NEGATE<br />
|143<br />
|0x8f<br />
|i1<br />
|i0<br />
|The sign of the input is flipped. Numerically the value is multiplied by -1<br />
|-<br />
|OP_ABS<br />
|144<br />
|0x90<br />
|i1<br />
|i0<br />
|The input is negative, its sign is flipped.<br />
|-<br />
|OP_NOT<br />
|145<br />
|0x91<br />
|i1<br />
|Boolean<br />
|If the input is 0 or 1, it is flipped. Otherwise the output will be 0. Test whether its value equals 0<br />
|-<br />
|OP_0NOTEQUAL<br />
|146<br />
|0x92<br />
|i1<br />
|Boolean<br />
|Returns 0 if the input is 0. 1 otherwise. Test whether its value is unequal 0<br />
|-<br />
|OP_ADD<br />
|147<br />
|0x93<br />
|i2 i1<br />
|i0<br />
|stack-top i1 is added to i2.<br />
|-<br />
|OP_SUB<br />
|148<br />
|0x94<br />
|i2 i1<br />
|i0<br />
|stack-top i1 is subtracted from i2.<br />
|-<br />
|OP_MUL<br />
|149<br />
|0x95<br />
|i2 i1<br />
|i0<br />
|i2 is multiplied with stack-top i1. ''Currently disabled.''<br />
|-<br />
|OP_DIV<br />
|150<br />
|0x96<br />
|i2 i1<br />
|i0<br />
|i2 is divided by stack-top i1 (divisor should be not 0). ''Currently disabled.''<br />
|-<br />
|OP_MOD<br />
|151<br />
|0x97<br />
|i2 i1<br />
|i0<br />
|Returns the remainder after dividing i2 by stack-top i1 (divisor should be not 0). ''Currently disabled.''<br />
|-<br />
|OP_LSHIFT<br />
|152<br />
|0x98<br />
|i2 i1<br />
|i0<br />
|Shifts i2 left by i1 bits, preserving sign of i2 (i1 >= 0). ''Currently disabled.''<br />
|-<br />
|OP_RSHIFT<br />
|153<br />
|0x99<br />
|i2 i1<br />
|i0<br />
|Shifts i2 right by i1 bits, preserving sign of i2 (i1 >= 0). ''Currently disabled.''<br />
|-<br />
|OP_BOOLAND<br />
|154<br />
|0x9a<br />
|i2 i1<br />
|Boolean<br />
|If both i2 and i1 are not 0, the output is 1. Otherwise 0.<br />
|-<br />
|OP_BOOLOR<br />
|155<br />
|0x9b<br />
|i2 i1<br />
|Boolean<br />
|If i2 or i1 is not 0, the output is 1. Otherwise 0.<br />
|-<br />
|OP_NUMEQUAL<br />
|156<br />
|0x9c<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 and i1 are numerically equal, 0 otherwise.<br />
|-<br />
|OP_NUMEQUALVERIFY<br />
|157<br />
|0x9d<br />
|i2 i1<br />
|Nothing / False<br />
|Same as OP_NUMEQUAL, but runs OP_VERIFY afterward.<br />
|-<br />
|OP_NUMNOTEQUAL<br />
|158<br />
|0x9e<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 and i1 are numerically not equal, 0 otherwise.<br />
|-<br />
|OP_LESSTHAN<br />
|159<br />
|0x9f<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is less than stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_GREATERTHAN<br />
|160<br />
|0xa0<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is greater than stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_LESSTHANOREQUAL<br />
|161<br />
|0xa1<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is less than or equal to stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_GREATERTHANOREQUAL<br />
|162<br />
|0xa2<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is greater than or equal to stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_MIN<br />
|163<br />
|0xa3<br />
|i2 i1<br />
|i2 / i1<br />
|Returns the smaller of i2 and i1.<br />
|-<br />
|OP_MAX<br />
|164<br />
|0xa4<br />
|i2 i1<br />
|i2 / i1<br />
|Returns the larger of i2 and i1.<br />
|-<br />
|OP_WITHIN<br />
|165<br />
|0xa5<br />
|i3 i2 i1<br />
|Boolean<br />
|Returns 1 if i3 >= i2 and i3 < i1, 0 otherwise. Thus if i2 > i1 returns always 0.<br />
|}<br />
<br />
=== Crypto ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_RIPEMD160<br />
|166<br />
|0xa6<br />
|x<br />
|hash20<br />
|The input is hashed using RIPEMD-160.<br />
|-<br />
|OP_SHA1<br />
|167<br />
|0xa7<br />
|x<br />
|hash20<br />
|The input is hashed using SHA-1.<br />
|-<br />
|OP_SHA256<br />
|168<br />
|0xa8<br />
|x<br />
|hash32<br />
|The input is hashed using SHA-256.<br />
|-<br />
|OP_HASH160<br />
|169<br />
|0xa9<br />
|x<br />
|hash20<br />
|The input is hashed twice: first with SHA-256 and then with RIPEMD-160.<br />
|-<br />
|OP_HASH256<br />
|170<br />
|0xaa<br />
|x<br />
|hash32<br />
|The input is hashed two times with SHA-256.<br />
|-<br />
|OP_CODESEPARATOR<br />
|171<br />
|0xab<br />
|Nothing<br />
|Nothing<br />
|All of the signature checking opcodes will only match signatures to the data after the most recently-executed OP_CODESEPARATOR.<br />
|-<br />
|[[OP_CHECKSIG]]<br />
|172<br />
|0xac<br />
|sig pubkey<br />
|Boolean<br />
|The entire transaction's outputs, inputs, and script (from the most recently-executed OP_CODESEPARATOR to the end) are hashed. The signature used by OP_CHECKSIG must be a valid signature for a further, extern specified hash and the given public key. If it is, 1 is returned, 0 otherwise.<br />
|-<br />
|OP_CHECKSIGVERIFY<br />
|173<br />
|0xad<br />
|sig pubkey<br />
|Nothing / False<br />
|Same as OP_CHECKSIG, but OP_VERIFY is executed afterward.<br />
|-<br />
|OP_CHECKMULTISIG<br />
|174<br />
|0xae<br />
|sig1 sig2 ... <number of signatures> pub1 pub2 <number of public keys><br />
|Boolean<br />
|For each signature and public key pair, OP_CHECKSIG is executed. If more public keys than signatures are listed, some key/sig pairs can fail. All signatures need to match a public key. If all signatures are valid, 1 is returned, 0 otherwise. Due to a bug, one extra unused value is removed from the stack.<br />
|-<br />
|OP_CHECKMULTISIGVERIFY<br />
|175<br />
|0xaf<br />
|sig1 sig2 ... <number of signatures> pub1 pub2 ... <number of public keys><br />
|Nothing / False<br />
|Same as OP_CHECKMULTISIG, but OP_VERIFY is executed afterward.<br />
|}<br />
<br />
=== Expansion opcodes ===<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_NOP1-OP_NOP10<br />
|176-185<br />
|0xb0-0xb9<br />
|The opcode has no effect.<br />
|}<br />
<br />
=== Version opcodes ===<br />
Version opcodes are disabled since bitcoin 0.2.0 and should not be used (maybe reassigned in the future).<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_VER<br />
|98<br />
|0x62<br />
|Script evalution is triggered invalid (Formerly pushed the bitcoin-serialize version onto stack).<br />
|-<br />
|OP_VERIF<br />
|101<br />
|0x65<br />
|Script evalution is triggered invalid (Formerly top stack item was popped and =< compared to present version)<br />
|-<br />
|OP_VERNOTIF<br />
|102<br />
|0x66<br />
|Script evalution is triggered invalid (Formerly top stack item was popped and > compared to present version)<br />
|}<br />
<br />
=== Reserved opcodes ===<br />
Each opcode not assigned (currently also every opcode value > 185) is also reserved. Using any unassigned opcode triggers the script evaluation to be invalid.<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_RESERVED<br />
|80<br />
|0x50<br />
|Script evalution is triggered invalid-<br />
|-<br />
|OP_RESERVED1<br />
|137<br />
|0x89<br />
|Script evalution is triggered invalid.<br />
|-<br />
|OP_RESERVED2<br />
|138<br />
|0x8a<br />
|Script evalution is triggered invalid.<br />
|}<br />
<br />
===Pseudo-opcodes===<br />
These nemonics are used internally for assisting with transaction matching. They are invalid if used in actual scripts.<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_PUBKEYHASH<br />
|253<br />
|0xfd<br />
|Represents a public key hashed with OP_HASH160.<br />
|-<br />
|OP_PUBKEY<br />
|254<br />
|0xfe<br />
|Represents a public key compatible with OP_CHECKSIG.<br />
|-<br />
|OP_INVALIDOPCODE<br />
|255<br />
|0xff<br />
|Matches any opcode that is not yet assigned.<br />
|}<br />
<br />
==Scripts in bitcoin transactions==<br />
It follows a list of important (most occuring) scripts to see opcodes "at work". Keep in mind that all constants actually use the data-pushing instructions above. At start of a (transaction input) script evaluation, the stack is always empty. Currently less than 0.01 % of all txout-scripts / scriptPubKeys in the main block chain are not of the following two standard scripts.<br />
<br />
===Standard transaction to bitcoin address===<br />
<br />
scriptPubKey: OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG<br />
scriptSig: <sig> <pubKey><br />
<br />
To demonstrate how scripts look on the wire, here is a raw scriptPubKey:<br />
<pre> 76 A9 14<br />
OP_DUP OP_HASH160 Bytes to push<br />
<br />
89 AB CD EF AB BA AB BA AB BA AB BA AB BA AB BA AB BA AB BA 88 AC<br />
Data to push OP_EQUALVERIFY OP_CHECKSIG</pre><br />
<br />
Note: scriptSig is in the input of the spending transaction and scriptPubKey is in the output of the previously storing transaction, i.e. its "available bitcoins".<br />
<br />
Here is how each instruction is processed:<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
| <sig> <pubKey> OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| scriptSig and scriptPubKey are combined.<br />
|-<br />
|<sig> <pubKey><br />
| OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| Constants are added to the stack.<br />
|-<br />
|<sig> <pubKey> <pubKey><br />
| OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| Top stack item is duplicated.<br />
|-<br />
|<sig> <pubKey> <pubHashA><br />
|<pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG<br />
| Top stack item is hashed.<br />
|-<br />
|<sig> <pubKey> <pubHashA> <pubKeyHash><br />
|OP_EQUALVERIFY OP_CHECKSIG<br />
| Constant added.<br />
|-<br />
|<sig> <pubKey><br />
|OP_CHECKSIG<br />
| Equality is checked between the top two stack items.<br />
|-<br />
|true<br />
|Empty.<br />
|Signature is checked for top two stack items.<br />
|}<br />
<br />
===Transaction to IP address (and generation transaction)===<br />
<br />
scriptPubKey: <pubKey> OP_CHECKSIG<br />
scriptSig: <sig><br />
<br />
Checking process:<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
|<sig> <pubKey> OP_CHECKSIG<br />
|scriptSig and scriptPubKey are combined.<br />
|-<br />
|<sig> <pubKey><br />
| OP_CHECKSIG<br />
|Constants are added to the stack.<br />
|-<br />
|true<br />
|Empty.<br />
|Signature is checked for top two stack items.<br />
|}<br />
<br />
In the case of a '''coin generation transaction''' (the first transaction of each block), there is no scriptSig, resp. its code ("coinbase") is completly ignored for the transaction. Only the scriptPubKey is used.<br />
<br />
===Transaction with a message===<br />
<br />
It's possible to add arbitrary data to any transaction by just adding some data along with OP_DROP. <br />
scriptPubKey: <message> OP_DROP <pubKey> OP_CHECKSIG<br />
scriptSig: <sig><br />
<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
|<sig> <message> OP_DROP <pubKey> OP_CHECKSIG<br />
|<br />
|-<br />
|<sig><br />
|<message> OP_DROP <pubKey> OP_CHECKSIG<br />
|scriptSig added to the stack.<br />
|-<br />
|<sig> <message><br />
|OP_DROP <pubKey> OP_CHECKSIG<br />
|The message has been put.<br />
|-<br />
|<sig><br />
|<pubKey> OP_CHECKSIG<br />
|Top stack item has been removed.<br />
|-<br />
|<sig> <pubKey><br />
|OP_CHECKSIG<br />
|Checking signature against the public key.<br />
|-<br />
|true<br />
|Empty.<br />
|Stack holds the value of signature check now.<br />
|}<br />
<br />
===Examples of non standard transaction on Testnet===<br />
<br />
These two links below show a non standard transaction. It just prepends the hex of "bob" and the operation OP_DROP<br />
which just removes it. As you can see they can be spent as normal.<br />
<br />
Input non-std transaction:<br />
http://blockexplorer.com/testnet/t/6ttfeb55B1<br />
<br />
Spent by:<br />
http://blockexplorer.com/testnet/t/AFdRB1CHS3<br />
<br />
==Script validation==<br />
A script evaluation is considered invalid, if any of these conditions meets:<br><br />
<ul><br />
<li>the total size of the script exceeds (currently) 10000 bytes<br />
<li>there are more than (currently) 201 opcodes of opcode value > 0x60 in the script<br />
<li>each instruction is (currently) limited to maximal 520 bytes. This effects only the opcodes OP_PUSHDATA2 and OP_PUSHDATA4<br />
<li>the executed opcode of the script has insufficient input (from stack, from script or from anywhere)<br />
<li>the opcode is not defined (for execution) - indicated by white or light gray background color in the table<br />
<li>the opcode is disabled (currently 15 opcodes) - indicated by white font color in the opcode overview matrix<br />
<li>stack overflow occurs during execution of the opcode (currently the number of items on the stack and on the alternate stack is limited to 1000)<br />
<li>the opcodes OP_VERIF and OP_NOTVERIF invalidate a script which contains this opcode (even if this opcode is not executed!)<br />
<li>the opcodes OP_ELSE or OP_ENDIF has no matching OP_IF<br><br />
<li>the script execution has been finished but there is (at least) an unmatched OP_IF<br><br />
<li>the opcodes OP_VERIFY, OP_EQUALVERIFY, OP_NUMEQUALVERIFY, OP_CHECKSIGVERIFY and OP_CHECKMULTISIGVERIFY invalidate the script if the stack-top item is false<br />
<li>the execution of OP_RETURN<br />
<!--li>alt stack overflow occurs (only possible during execution of OP_TOALTSTACK)--><br />
<li>the numerical value of the top-stack item is negative or greater than the number of items - 2 on the stack if OP_PICK or OP_ROLL shall be executed<br />
<li>an item used as public key or signature for each of the opcodes OP_CHECKSIG, OP_CHECKSIGVERIFY, OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY can be neither a public key or signature (for the given hash)<br />
<li>the number of signature items or the number of public key items on the stack is negative for OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY<br />
<li>there or more signatures items than public key items on the stack for OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY<br />
<li>there are (currently) more than 20 public key items on the stack for OP_CHECKMULTISIG or CHECKMULTISIGVERIFY<br />
<li>the sum of opcodes > 0x60 and the number of public keys in all executed OP_CHECKMULTISIG or CHECKMULTISIGVERIFY exceeds (currently) 201<br />
<li>the script execution has been finished and the stack is empty or the top-stack item is false (numerical value 0)<br />
</ul><br />
else the script evaluation is considered to be valid.<ref>[http://sourceforge.net/projects/bitcoin/files/Bitcoin/bitcoin-0.7.1/bitcoin-0.7.1-linux.tar.gz file src/src/script.cpp in bitcoin-0.7.1]</ref><br />
'''If invalidation of a script is triggered then the script is immediately finished.''' These arbitrary looking limitations of 10000, 201, 520, 1000 and 20 might be increased in the future -- they serve to prevent strong slow down of the evaluation of a script while not restricting its practical usage really.<br />
<br />
==Withdrawn and drafted opcodes==<br />
<br />
<ul><br />
<li> byte value 0x89 OP_NOTEQUAL defined in pre-0.1.0 bitcoin versions. Since 0.1.0 removed because of security concerns. <br />
<li> byte value 0xb1 [[BIP 0012 | OP_EVAL]] withdraw - poll was triggered but insufficient support. <br />
<li> byte value 0xb2 [[BIP 0017 | OP_CHECKHASHVERIFY]] withdraw - poll was triggered but insufficient support.<br />
</ul><br />
<br />
==See Also==<br />
* [[Transactions]]<br />
* [[Contracts]]<br />
<br />
==References==<br />
<references/><br />
<ul><br />
<li>[http://www.zorinaq.com/pub/bitcoin-0.1.0.tgz file src/script.cpp in bitcoin-0.1.0]</li><br />
</ul><br />
[[Category:Technical]]<br />
[[Category:Vocabulary]]</div>
Smtp
https://en.bitcoin.it/w/index.php?title=Script&diff=34910
Script
2013-01-11T16:20:22Z
<p>Smtp: /* Arithmetic */ which versions? Like to have a reference!</p>
<hr />
<div>Bitcoin uses a scripting system for [[transactions]]. [[Wikipedia:FORTH|Forth]]-like, Script is simple, stack-based, and processed from left to right. It is purposefully not Turing-complete, with no loops.<br />
<br />
A script is essentially a list of instructions recorded with each transaction that describe how the next person wanting to spend the Bitcoins being transferred can gain access to them.<br />
<br />
Scripts are big-endian and their sequences of bytes is interpreted as a sequence of opcodes with operands. Only opcodes with byte values less than 0x4f have additional operands.<br />
<br />
== Scripts and Bitcoin transactions ==<br />
The script for a typical Bitcoin transfer to destination Bitcoin address D simply encumbers future spending of the bitcoins with two things: the spender must provide<br />
# a public key that, when hashed, yields destination address D embedded in the script, and<br />
# a signature to show evidence of the private key corresponding to the public key just provided.<br />
<br />
Scripting provides the flexibility to change the parameters of what's needed to spend transferred Bitcoins. For example, the scripting system could be used to require two private keys, or a combination of several, or even no keys at all.<br />
<br />
A transaction is valid if nothing in the combined script triggers failure and the top stack item exists and is true (non-zero). The party who originally ''stored'' the Bitcoins now being spent, dictates the script operations that will occur ''last'' in order to release them for use in another transaction. The party wanting to spend them must provide the input(s) to the previously recorded script that results in those operations occurring last leaving behind true (non-zero) on the stack.<br><br />
Only the very first transaction in each bitcoin block has no input script (the entry there is called "coinbase"), because the Bitcoins created with the block are created from hot air and not released by a previous recorded script.<br />
<br />
== Stack ==<br />
<br />
The stacks hold byte vectors (there is the (main) stack and an alternative stack). Byte vectors are interpreted as little-endian variable-length integers with the most significant bit determining the sign of the integer. Thus 0x81 represents -1. 0x80 is another representation of zero (so called negative 0). Byte vectors are interpreted as Booleans where False is represented by any representation of zero, and True is represented by any representation of non-zero.<br />
<br />
== Opcode overview ==<br />
<br />
For each opcode is given: its nemonic without the leading OP_, its hexadecimal byte value, the number of stack items needed (poped) during execution, a semicolon and the number of stack items which has been pushed (after execution). A * after the needed stack items indicates that further bytes from the script following the current opcode are needed. A # indicates that items on the alternative stack are poped/pushed. A @ indicates that further (global) data from the transaction is needed. A / indicates alternatives of a value. <br/><br />
Different colors indicate different semantic execution groups of opcodes:<br />
{| style="background:none; font-size:100%; padding:0; border-collapse:collapse; text-align:center; line-height:2em;" border="0" align="center" <br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | copy a fixed number of bytes but at most 75 onto stack<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | copy bytes onto stack which number is given by a 1, 2 or 4 byte value.<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | copy 1 specific byte onto stack<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | undefined opcode<br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | a pseudo-opcode, unassigned for scripts<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | NOP or opcode is part of a IF-flow-control construction<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00ff00;" | (stack conditionally) invalidation of the script this opcode is part of<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | stack item is moved between main stack and alternate stack<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | stack item(s) is/are moved, copied or deleted<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0;" | byte vectors are appended or divided or their size is determined<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff;" | byte vectors are interpreted bit-position-independently<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | byte vectors are interpreted and processed as signed integers<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | a hash value is computed or a signature checked<br />
|}<br />
<p><br />
===Opcode byte-matrix===<br />
The opcode value 0x00 with nemonic OP_FALSE is also named OP_0 and the opcode value 0x51 with nemonic OP_1 as also named OP_TRUE.<br />
{| style="background:none; font-size:100%; padding:0; border-collapse:collapse; text-align:center; line-height:2em;" border="0" align="center" <br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" |_FALSE<br/> 0x00 <br/> 0 ; 1(0) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x01<br/> 0 *; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x02<br/> 0 *; 1(2)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x03<br/> 0 *; 1(3)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x04<br/> 0 *; 1(4)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x04<br/> 0 *; 1(5)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x06<br/> 0 *; 1(6)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x07<br/> 0 *; 1(7)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x08<br/> 0 *; 1(8)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x09<br/> 0 *; 1(9)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0a<br/> 0 *; 1(10)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0b<br/> 0 *; 1(11)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0c<br/> 0 *; 1(12)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0d<br/> 0 *; 1(13)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0e<br/> 0 *; 1(14)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0f<br/> 0 *; 1(15)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x10 <br/> 0 *; 1(16) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x11 <br/> 0 *; 1(17)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x12 <br/> 0 *; 1(18)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x13 <br/> 0 *; 1(19)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x14 <br/> 0 *; 1(20)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x15 <br/> 0 *; 1(21)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x16 <br/> 0 *; 1(22)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x17 <br/> 0 *; 1(23)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x18 <br/> 0 *; 1(24)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x19 <br/> 0 *; 1(25)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1a <br/> 0 *; 1(26)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1b <br/> 0 *; 1(27)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1c <br/> 0 *; 1(28)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1d <br/> 0 *; 1(29)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1e <br/> 0 *; 1(30)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1f <br/> 0 *; 1(31)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x20 <br/> 0 *; 1(32) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x21 <br/> 0 *; 1(33)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x22 <br/> 0 *; 1(34)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x23 <br/> 0 *; 1(35)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x24 <br/> 0 *; 1(36)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x25 <br/> 0 *; 1(37)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x26 <br/> 0 *; 1(38)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x27 <br/> 0 *; 1(39)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x28 <br/> 0 *; 1(40)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x29 <br/> 0 *; 1(41)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2a <br/> 0 *; 1(42)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2b <br/> 0 *; 1(43)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2c <br/> 0 *; 1(44)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2d <br/> 0 *; 1(45)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2e <br/> 0 *; 1(46)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2f <br/> 0 *; 1(47)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x30 <br/> 0 *; 1(48) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x31 <br/> 0 *; 1(49)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x32 <br/> 0 *; 1(50)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x33 <br/> 0 *; 1(51)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x34 <br/> 0 *; 1(52)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x35 <br/> 0 *; 1(53)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x36 <br/> 0 *; 1(54)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x37 <br/> 0 *; 1(55)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x38 <br/> 0 *; 1(56)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x39 <br/> 0 *; 1(57)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3a <br/> 0 *; 1(58)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3b <br/> 0 *; 1(59)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3c <br/> 0 *; 1(60)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3d <br/> 0 *; 1(61)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3e <br/> 0 *; 1(62)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3f <br/> 0 *; 1(63)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x40 <br/> 0 *; 1(64) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x41 <br/> 0 *; 1(65)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x42 <br/> 0 *; 1(66)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x43 <br/> 0 *; 1(67)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x44 <br/> 0 *; 1(68)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x45 <br/> 0 *; 1(69)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x46 <br/> 0 *; 1(70)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x47 <br/> 0 *; 1(71)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x48 <br/> 0 *; 1(72)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x49 <br/> 0 *; 1(73)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x4a <br/> 0 *; 1(74)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x4b <br/> 0 *; 1(75)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA1 <br/> 0x4c <br/> 0 *; 1(0 - 255)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA2 <br/> 0x4d <br/> 0 *; 1(0 - 2^16-1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA4 <br/> 0x4e <br/> 0 *; 1(0 - 2^32-1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _1NEGATE <br/> 0x4f <br/> 0 ; 1(1)<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED <br/> 0x50 <br/> <br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _1 <br/> 0x51 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _2 <br/> 0x52 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _3 <br/> 0x53 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _4 <br/> 0x54 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _5 <br/> 0x55 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _6 <br/> 0x56 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _7 <br/> 0x57 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _8 <br/> 0x58 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _9 <br/> 0x59 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _10 <br/> 0x5a <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _11 <br/> 0x5b <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _12 <br/> 0x5c <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _13 <br/> 0x5d <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _14 <br/> 0x5e <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _15 <br/> 0x5f <br/> 0 ; 1(1)<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _16 <br/> 0x60 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP <br/> 0x61 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VER <br/> 0x62 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _IF <br/> 0x63 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOTIF <br/> 0x64 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VERIF <br/> 0x65 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VERNOTIF <br/> 0x66 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _ELSE <br/> 0x67 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _ENDIF <br/> 0x68 <br/> 0 ; 0<br />
| style="border:3px solid #808080; background-color:#00ff00;" | _VERIFY <br/> 0x69 <br/> 1 ; 0/1<br />
| style="border:3px solid #808080; background-color:#00ff00;" | _RETURN <br/> 0x6a <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | _TOALTSTACK <br/> 0x6b <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | _FROMALTSTACK <br/> 0x6c <br/> 0 #; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2DROP <br/> 0x6d <br/> 2 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2DUP <br/> 0x6e <br/> 2 ; 4<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _3DUP <br/> 0x6f <br/> 3 ; 6<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2OVER <br/> 0x70 <br/> 4 ; 6<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2ROT <br/> 0x71 <br/> 6 ; 6<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2SWAP <br/> 0x72 <br/> 4 ; 4<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _IFDUP <br/> 0x73 <br/> 1 ; 1/2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DEPTH <br/> 0x74 <br/> 0 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DROP <br/> 0x75 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DUP <br/> 0x76 <br/> 1 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _NIP <br/> 0x77 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _OVER <br/> 0x78 <br/> 2 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _PICK <br/> 0x79 <br/> 1+n+1 ; n+2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _ROLL <br/> 0x7a <br/> 1+n+1 ; n+1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _ROT <br/> 0x7b <br/> 3 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _SWAP <br/> 0x7c <br/> 2 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _TUCK <br/> 0x7d <br/> 2 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _CAT <br/> 0x7e <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _SUBSTR <br/> 0x7f <br/> 3 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _LEFT <br/> 0x80 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _RIGHT <br/> 0x81 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0;" | _SIZE <br/> 0x82 <br/> 1 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _INVERT <br/> 0x83 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _AND <br/> 0x84 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _OR <br/> 0x85 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _XOR <br/> 0x86 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff;" | _EQUAL <br/> 0x87 <br/> 2 ; 1<br />
| style="border:3px solid #808080; background-color:#c080ff;" | _EQUALVERIFY <br/> 0x88 <br/> 2 ; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED1 <br/> 0x89 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED2 <br/> 0x8a <br/><br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _1ADD <br/> 0x8b <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _1SUB <br/> 0x8c <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _2MUL <br/> 0x8d <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _2DIV <br/> 0x8e <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NEGATE <br/> 0x8f <br/> 1 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _ABS <br/> 0x90 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NOT <br/> 0x91 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _0NOTEQUAL <br/> 0x92 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _ADD <br/> 0x93 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _SUB <br/> 0x94 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _MUL <br/> 0x95 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _DIV <br/> 0x96 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _MOD <br/> 0x97 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _LSHIFT <br/> 0x98 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _RSHIFT <br/> 0x99 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _BOOLAND <br/> 0x9a <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _BOOLOR <br/> 0x9b <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NUMEQUAL <br/> 0x9c <br/> 2 ; 1<br />
| style="border:3px solid #808080; background-color:#8080ff;" | _NUMEQUALVERIFY <br/> 0x9d <br/> 2 ; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NUMNOTEQUAL <br/> 0x9e <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _LESSTHAN <br/> 0x9f <br/> 2 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _GREATERTHAN <br/> 0xa0 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _LESSTHANOREQUAL <br/> 0xa1 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _GREATERTHANOREQUAL <br/> 0xa2 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _MIN <br/> 0xa3 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _MAX <br/> 0xa4 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _WITHIN <br/> 0xa5 <br/> 3 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _RIPEMD160 <br/> 0xa6 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _SHA1 <br/> 0xa7 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _SHA256 <br/> 0xa8 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _HASH160 <br/> 0xa9 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _HASH256 <br/> 0xaa <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CODESEPARATOR <br/> 0xab <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CHECKSIG <br/> 0xac <br/> 2 @; 1<br />
| style="border:3px solid #808080; background-color:#a0d0ff;" | _CHECKSIGVERIFY <br/> 0xad <br/> 2 @; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CHECKMULTISIG <br/> 0xae <br/> 2n+2 @; 1<br />
| style="border:3px solid #808080; background-color:#a0d0ff;" | _CHECKMULTISIGVERIFY <br/> 0xaf <br/> 2n+2 @; 0/1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP1 <br/> 0xb0 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP2 <br/> 0xb1 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP3 <br/> 0xb2 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP4 <br/> 0xb3 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP5 <br/> 0xb4 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP6 <br/> 0xb5 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP7 <br/> 0xb6 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP8 <br/> 0xb7 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP9 <br/> 0xb8 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP10 <br/> 0xb9 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xba <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbe <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xca <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xce <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xda <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xde <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xea <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xeb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xec <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xed <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xee <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xef <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xfa <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _SMALLINTEGER <br/> 0xfb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEYS <br/> 0xfc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEYHASH <br/> 0xfd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEY <br/> 0xfe <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _INVALIDOPCODE <br/> 0xff <br/><br />
|}<br><br />
Except later pseudo-opcode changes, the definition of OP_NOP1 - OP_NOP10 and the change of the evaluation of OP_RETURN (did no invalidation previously) which both occured in bitcoin version 0.3.6 in July 2010 were the last changes regarding opcodes <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.2.0/bitcoin-0.2.0-linux.tar.gz file src/srcipt.cpp in bitcoin-0.2.0]</ref> <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.3.3/bitcoin-0.3.3-linux.tar.gz file src/srcipt.cpp in bitcoin-0.3.3]</ref> <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.3.6/bitcoin-0.3.6-linux.tar.gz file src/srcipt.cpp in bitcoin-0.3.6]</ref>.<br />
<br />
== Opcode descriptions ==<br />
It follows for each opcode less than decimal 185 (hexa 0xba) a description for its usage. The columns entitled ''nemonic'', ''decimal'' and ''Hex'' should be evident. The column ''input'' gives the needed items of the stack (and the alternate stack) and the column ''output'' indicates the resulting items on the stack (and the alternate stack). '''Stack-top is always the right most item.''' The naming of the entries in these two columns is chosen to reflect their interpretation. ''x'', ''x0'', ''x1'', ... means arbitrary or no interpretation, ''i0'', ''i1'' and ''i2'' a signed integer value, ''n'',''index'',''size'' and ''depth'' non-negative (unsigned) integer values, ''Boolean'' as either a true or false.<br><br />
<br />
Some of the more complicated opcodes are disabled out of concern that the client might have (and has) a bug in the current implementation due to the historically not as 2-complement interpretations of the byte vectors as numerical values (the most significant byte holds the sign of the byte vectors).<br />
<br />
=== Push data from instruction onto stack ===<br />
<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_FALSE, OP_0<br />
|0<br />
|0x00<br />
|Nothing<br />
|Empty string<br />
|A byte vector of length 0 is pushed onto the stack. (Thus, it is not a no-op!)<br />
|-<br />
|(no official nemonics)<br />
|1 - 75<br />
|0x01 - 0x4b<br />
|(operand)<br />
|x<br />
|The next <opcode>-many bytes are to be pushed onto the stack.<br />
|-<br />
|OP_PUSHDATA1<br />
|76<br />
|0x4c<br />
|(operands)<br />
|x<br />
|The next byte contains the number of bytes to be pushed onto the stack which follow this byte.<br />
|-<br />
|OP_PUSHDATA2<br />
|77<br />
|0x4d<br />
|(operands)<br />
|x<br />
|The next two bytes contain the number of bytes to be pushed onto the stack which follow theses 2 bytes.<br />
|-<br />
|OP_PUSHDATA4<br />
|78<br />
|0x4e<br />
|(operands)<br />
|x<br />
|The next four bytes contain the number of bytes to be pushed onto the stack which follow theses 4 bytes.<br />
|-<br />
|OP_1NEGATE<br />
|79<br />
|0x4f<br />
|Nothing<br />
| -1<br />
|The byte with value -1 is pushed onto the stack.<br />
|-<br />
|OP_1, OP_TRUE<br />
|81<br />
|0x51<br />
|Nothing<br />
|1<br />
|The byte with value 1 is pushed onto the stack.<br />
|-<br />
|OP_2 - OP_16<br />
|82 - 96<br />
|0x52 - 0x60<br />
|Nothing<br />
|2-16<br />
|The byte with value <opcode>-80 (thus, one of 2 - 16) is pushed onto the stack.<br />
|}<br />
<br />
=== Flow control ===<br />
<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_NOP<br />
|97<br />
|0x61<br />
|Nothing<br />
|Nothing<br />
|Does nothing.<br />
|-<br />
|OP_IF<br />
|99<br />
|0x63<br />
|Boolean<br />
|Nothing<br />
|If the top stack value is not 0, the statements are executed. The top stack value is removed. Lead in a logcial ''<value> then [statements] [else [statements]] endif'' expression<br />
|-<br />
|OP_NOTIF<br />
|100<br />
|0x64<br />
|Boolean<br />
|Nothing<br />
|If the top stack value is 0, the statements are executed. The top stack value is removed. Lead in a logcial ''<value> then [statements] [else [statements]] endif'' expression <br />
|-<br />
|OP_ELSE<br />
|103<br />
|0x67<br />
|Nothing<br />
|Nothing<br />
|If the preceeding OP_IF or OP_NOTIF or OP_ELSE was not executed then these statements are and if the preceding OP_IF or OP_NOTIF or OP_ELSE was executed then these statements are not. <br />
|-<br />
|OP_ENDIF<br />
|104<br />
|0x68<br />
|Nothing<br />
|Nothing<br />
|Ends a logcial ''If <value> then [statements] [else [statements]] '' expression<br />
|-<br />
|OP_VERIFY<br />
|105<br />
|0x69<br />
|Boolean<br />
|Nothing / False<br />
|If top stack value is not true then marks transaction as '''invalid''' . A value true is removed, but false is not.<br />
|-<br />
|OP_RETURN<br />
|106<br />
|0x6a<br />
|Nothing<br />
|Nothing<br />
|Marks transaction as '''invalid'''. <br />
|}<br />
<br />
===Stack item organization===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_TOALTSTACK<br />
|107<br />
|0x6b<br />
|x1 (alt)<br />
|(alt x1)<br />
|Puts the input onto the top of the alt stack. Removes it from the (main) stack.<br />
|-<br />
|OP_FROMALTSTACK<br />
|108<br />
|0x6c<br />
|(alt x1)<br />
|x1 (alt)<br />
|Puts the input onto the top of the (main) stack. Removes it from the alt stack.<br />
|-<br />
|OP_2DROP<br />
|109<br />
|0x6d<br />
|x2 x1<br />
|Nothing<br />
|Removes the top two stack items.<br />
|-<br />
|OP_2DUP<br />
|110<br />
|0x6e<br />
|x2 x1<br />
|x2 x1 x2 x1<br />
|Duplicates the top two stack items.<br />
|-<br />
|OP_3DUP<br />
|111<br />
|0x6f<br />
|x3 x2 x1<br />
|x3 x2 x1 x3 x2 x1<br />
|Duplicates the top three stack items.<br />
|-<br />
|OP_2OVER<br />
|112<br />
|0x70<br />
|x4 x3 x2 x1<br />
|x4 x3 x2 x1 x4 x3<br />
|Copies the pair of items two spaces back in the stack to the front.<br />
|-<br />
|OP_2ROT<br />
|113<br />
|0x71<br />
|x6 x5 x4 x3 x2 x1<br />
|x4 x3 x2 x1 x6 x5<br />
|The fifth and sixth items back are moved to the top of the stack. Twotimes left rotate.<br />
|-<br />
|OP_2SWAP<br />
|114<br />
|0x72<br />
|x4 x3 x2 x1<br />
|x2 x1 x4 x3<br />
|Swaps the top two pairs of stack items.<br />
|-<br />
|OP_IFDUP<br />
|115<br />
|0x73<br />
|x1<br />
|x1 / x1 x1<br />
|If the top stack value is not 0, duplicate it.<br />
|-<br />
|OP_DEPTH<br />
|116<br />
|0x74<br />
|Nothing<br />
|depth<br />
|Puts the number of stack items onto the stack as one little-endian coded byte-vector<br />
|-<br />
|OP_DROP<br />
|117<br />
|0x75<br />
|x1<br />
|Nothing<br />
|Removes the top stack item.<br />
|-<br />
|OP_DUP<br />
|118<br />
|0x76<br />
|x1<br />
|x1 x1<br />
|Duplicates the top stack item.<br />
|-<br />
|OP_NIP<br />
|119<br />
|0x77<br />
|x2 x1<br />
|x1<br />
|Removes the second-to-top stack item.<br />
|-<br />
|OP_OVER<br />
|120<br />
|0x78<br />
|x2 x1<br />
|x2 x1 x2<br />
|Copies the second-to-top stack item to the top.<br />
|-<br />
|OP_PICK<br />
|121<br />
|0x79<br />
|xn ... x2 x1 x0 <n><br />
|xn ... x2 x1 x0 xn<br />
|<n> is removed and the item ''n'' back in the stack is copied to the top.<br />
|-<br />
|OP_ROLL<br />
|122<br />
|0x7a<br />
|xn ... x2 x1 x0 <n><br />
|... x2 x1 x0 xn<br />
|<n> is removed and the item ''n'' back in the stack is moved to the top.<br />
|-<br />
|OP_ROT<br />
|123<br />
|0x7b<br />
|x3 x2 x1<br />
|x2 x1 x3<br />
|The top three items on the stack are rotated to the left.<br />
|-<br />
|OP_SWAP<br />
|124<br />
|0x7c<br />
|x2 x1<br />
|x1 x2<br />
|The top two items on the stack are swapped resp. rotated.<br />
|-<br />
|OP_TUCK<br />
|125<br />
|0x7d<br />
|x2 x1<br />
|x1 x2 x1<br />
|The item at the top of the stack is copied and inserted before the second-to-top item.<br />
|}<br />
<br />
=== Splice ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_CAT<br />
|126<br />
|0x7e<br />
|x2 x1<br />
|out<br />
|Appends stack-top item at second-to top item. Concatenates two strings resp. byte vectors. ''Currently disabled.''<br />
|-<br />
|OP_SUBSTR<br />
|127<br />
|0x7f<br />
|x3 index size<br />
|out<br />
|Returns the section started at position <index> and of length <size> of a string resp. byte vector. ''Currently disabled.''<br />
|-<br />
|OP_LEFT<br />
|128<br />
|0x80<br />
|x2 index<br />
|out<br />
|Keeps only characters left of the specified point in second-to top item. ''Currently disabled.''<br />
|-<br />
|OP_RIGHT<br />
|129<br />
|0x81<br />
|x2 index<br />
|out<br />
|Keeps only characters right of the specified point in second-to top item. ''Currently disabled.''<br />
|-<br />
|OP_SIZE<br />
|130<br />
|0x82<br />
|x1<br />
|x1 size<br />
|Returns the length of the input string resp. byte vector resp. top-stack item.<br />
|}<br />
<br />
=== Bitwise logic ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_INVERT<br />
|131<br />
|0x83<br />
|x1<br />
|x0<br />
|Flips all of the bits in the input. ''Currently disabled.''<br />
|-<br />
|OP_AND<br />
|132<br />
|0x84<br />
|x2 x1<br />
|x0<br />
|Boolean ''and'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_OR<br />
|133<br />
|0x85<br />
|x2 x1<br />
|x0<br />
|Boolean ''or'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_XOR<br />
|134<br />
|0x86<br />
|x2 x1<br />
|x0<br />
|Boolean ''exclusive or'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_EQUAL<br />
|135<br />
|0x87<br />
|x2 x1<br />
|Boolean<br />
|Returns 1 if the inputs have the same length and are byte-wise equal, 0 otherwise.<br />
|-<br />
|OP_EQUALVERIFY<br />
|136<br />
|0x88<br />
|x2 x1<br />
|Nothing / false<br />
|Same as OP_EQUAL, but runs OP_VERIFY afterward.<br />
|}<br />
<br />
=== Arithmetic ===<br />
<br />
<!--(In very early versions, pre 0.2.0, the implemented arithmetic opcodes were limited to maximal 4 byte vectors.) --><br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_1ADD<br />
|139<br />
|0x8b<br />
|i1<br />
|i0<br />
|1 is added to the input.<br />
|-<br />
|OP_1SUB<br />
|140<br />
|0x8c<br />
|i1<br />
|i0<br />
|1 is subtracted from the input.<br />
|-<br />
|OP_2MUL<br />
|141<br />
|0x8d<br />
|i1<br />
|i0<br />
|The input is multiplied by 2. ''Currently disabled.''<br />
|-<br />
|OP_2DIV<br />
|142<br />
|0x8e<br />
|i1<br />
|i0<br />
|The input is divided by 2 (round down). ''Currently disabled.''<br />
|-<br />
|OP_NEGATE<br />
|143<br />
|0x8f<br />
|i1<br />
|i0<br />
|The sign of the input is flipped. Numerically the value is multiplied by -1<br />
|-<br />
|OP_ABS<br />
|144<br />
|0x90<br />
|i1<br />
|i0<br />
|The input is negative, its sign is flipped.<br />
|-<br />
|OP_NOT<br />
|145<br />
|0x91<br />
|i1<br />
|Boolean<br />
|If the input is 0 or 1, it is flipped. Otherwise the output will be 0. Test whether its value equals 0<br />
|-<br />
|OP_0NOTEQUAL<br />
|146<br />
|0x92<br />
|i1<br />
|Boolean<br />
|Returns 0 if the input is 0. 1 otherwise. Test whether its value is unequal 0<br />
|-<br />
|OP_ADD<br />
|147<br />
|0x93<br />
|i2 i1<br />
|i0<br />
|stack-top i1 is added to i2.<br />
|-<br />
|OP_SUB<br />
|148<br />
|0x94<br />
|i2 i1<br />
|i0<br />
|stack-top i1 is subtracted from i2.<br />
|-<br />
|OP_MUL<br />
|149<br />
|0x95<br />
|i2 i1<br />
|i0<br />
|i2 is multiplied with stack-top i1. ''Currently disabled.''<br />
|-<br />
|OP_DIV<br />
|150<br />
|0x96<br />
|i2 i1<br />
|i0<br />
|i2 is divided by stack-top i1 (divisor should be not 0). ''Currently disabled.''<br />
|-<br />
|OP_MOD<br />
|151<br />
|0x97<br />
|i2 i1<br />
|i0<br />
|Returns the remainder after dividing i2 by stack-top i1 (divisor should be not 0). ''Currently disabled.''<br />
|-<br />
|OP_LSHIFT<br />
|152<br />
|0x98<br />
|i2 i1<br />
|i0<br />
|Shifts i2 left by i1 bits, preserving sign of i2 (i1 >= 0). ''Currently disabled.''<br />
|-<br />
|OP_RSHIFT<br />
|153<br />
|0x99<br />
|i2 i1<br />
|i0<br />
|Shifts i2 right by i1 bits, preserving sign of i2 (i1 >= 0). ''Currently disabled.''<br />
|-<br />
|OP_BOOLAND<br />
|154<br />
|0x9a<br />
|i2 i1<br />
|Boolean<br />
|If both i2 and i1 are not 0, the output is 1. Otherwise 0.<br />
|-<br />
|OP_BOOLOR<br />
|155<br />
|0x9b<br />
|i2 i1<br />
|Boolean<br />
|If i2 or i1 is not 0, the output is 1. Otherwise 0.<br />
|-<br />
|OP_NUMEQUAL<br />
|156<br />
|0x9c<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 and i1 are numerically equal, 0 otherwise.<br />
|-<br />
|OP_NUMEQUALVERIFY<br />
|157<br />
|0x9d<br />
|i2 i1<br />
|Nothing / False<br />
|Same as OP_NUMEQUAL, but runs OP_VERIFY afterward.<br />
|-<br />
|OP_NUMNOTEQUAL<br />
|158<br />
|0x9e<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 and i1 are numerically not equal, 0 otherwise.<br />
|-<br />
|OP_LESSTHAN<br />
|159<br />
|0x9f<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is less than stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_GREATERTHAN<br />
|160<br />
|0xa0<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is greater than stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_LESSTHANOREQUAL<br />
|161<br />
|0xa1<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is less than or equal to stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_GREATERTHANOREQUAL<br />
|162<br />
|0xa2<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is greater than or equal to stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_MIN<br />
|163<br />
|0xa3<br />
|i2 i1<br />
|i2 / i1<br />
|Returns the smaller of i2 and i1.<br />
|-<br />
|OP_MAX<br />
|164<br />
|0xa4<br />
|i2 i1<br />
|i2 / i1<br />
|Returns the larger of i2 and i1.<br />
|-<br />
|OP_WITHIN<br />
|165<br />
|0xa5<br />
|i3 i2 i1<br />
|Boolean<br />
|Returns 1 if i3 >= i2 and i3 < i1, 0 otherwise. Thus if i2 > i1 returns always 0.<br />
|}<br />
<br />
=== Crypto ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_RIPEMD160<br />
|166<br />
|0xa6<br />
|x<br />
|hash20<br />
|The input is hashed using RIPEMD-160.<br />
|-<br />
|OP_SHA1<br />
|167<br />
|0xa7<br />
|x<br />
|hash20<br />
|The input is hashed using SHA-1.<br />
|-<br />
|OP_SHA256<br />
|168<br />
|0xa8<br />
|x<br />
|hash32<br />
|The input is hashed using SHA-256.<br />
|-<br />
|OP_HASH160<br />
|169<br />
|0xa9<br />
|x<br />
|hash20<br />
|The input is hashed twice: first with SHA-256 and then with RIPEMD-160.<br />
|-<br />
|OP_HASH256<br />
|170<br />
|0xaa<br />
|x<br />
|hash32<br />
|The input is hashed two times with SHA-256.<br />
|-<br />
|OP_CODESEPARATOR<br />
|171<br />
|0xab<br />
|Nothing<br />
|Nothing<br />
|All of the signature checking opcodes will only match signatures to the data after the most recently-executed OP_CODESEPARATOR.<br />
|-<br />
|[[OP_CHECKSIG]]<br />
|172<br />
|0xac<br />
|sig pubkey<br />
|Boolean<br />
|The entire transaction's outputs, inputs, and script (from the most recently-executed OP_CODESEPARATOR to the end) are hashed. The signature used by OP_CHECKSIG must be a valid signature for a further, extern specified hash and the given public key. If it is, 1 is returned, 0 otherwise.<br />
|-<br />
|OP_CHECKSIGVERIFY<br />
|173<br />
|0xad<br />
|sig pubkey<br />
|Nothing / False<br />
|Same as OP_CHECKSIG, but OP_VERIFY is executed afterward.<br />
|-<br />
|OP_CHECKMULTISIG<br />
|174<br />
|0xae<br />
|sig1 sig2 ... <number of signatures> pub1 pub2 <number of public keys><br />
|Boolean<br />
|For each signature and public key pair, OP_CHECKSIG is executed. If more public keys than signatures are listed, some key/sig pairs can fail. All signatures need to match a public key. If all signatures are valid, 1 is returned, 0 otherwise. Due to a bug, one extra unused value is removed from the stack.<br />
|-<br />
|OP_CHECKMULTISIGVERIFY<br />
|175<br />
|0xaf<br />
|sig1 sig2 ... <number of signatures> pub1 pub2 ... <number of public keys><br />
|Nothing / False<br />
|Same as OP_CHECKMULTISIG, but OP_VERIFY is executed afterward.<br />
|}<br />
<br />
=== Expansion opcodes ===<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_NOP1-OP_NOP10<br />
|176-185<br />
|0xb0-0xb9<br />
|The opcode has no effect.<br />
|}<br />
<br />
=== Version opcodes ===<br />
Version opcodes are disabled since bitcoin 0.2.0 and should not be used (maybe reassigned in the future).<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_VER<br />
|98<br />
|0x62<br />
|Script evalution is triggered invalid (Formerly pushed the bitcoin-serialize version onto stack).<br />
|-<br />
|OP_VERIF<br />
|101<br />
|0x65<br />
|Script evalution is triggered invalid (Formerly top stack item was popped and =< compared to present version)<br />
|-<br />
|OP_VERNOTIF<br />
|102<br />
|0x66<br />
|Script evalution is triggered invalid (Formerly top stack item was popped and > compared to present version)<br />
|}<br />
<br />
=== Reserved opcodes ===<br />
Each opcode not assigned (currently also every opcode value > 185) is also reserved. Using any unassigned opcode triggers the script evaluation to be invalid.<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_RESERVED<br />
|80<br />
|0x50<br />
|Script evalution is triggered invalid-<br />
|-<br />
|OP_RESERVED1<br />
|137<br />
|0x89<br />
|Script evalution is triggered invalid.<br />
|-<br />
|OP_RESERVED2<br />
|138<br />
|0x8a<br />
|Script evalution is triggered invalid.<br />
|}<br />
<br />
===Pseudo-opcodes===<br />
These nemonics are used internally for assisting with transaction matching. They are invalid if used in actual scripts.<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_PUBKEYHASH<br />
|253<br />
|0xfd<br />
|Represents a public key hashed with OP_HASH160.<br />
|-<br />
|OP_PUBKEY<br />
|254<br />
|0xfe<br />
|Represents a public key compatible with OP_CHECKSIG.<br />
|-<br />
|OP_INVALIDOPCODE<br />
|255<br />
|0xff<br />
|Matches any opcode that is not yet assigned.<br />
|}<br />
<br />
==Scripts in bitcoin transactions==<br />
It follows a list of important (most occuring) scripts to see opcodes "at work". Keep in mind that all constants actually use the data-pushing instructions above. At start of a (transaction input) script evaluation, the stack is always empty. <br />
<br />
===Standard transaction to bitcoin address===<br />
<br />
scriptPubKey: OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG<br />
scriptSig: <sig> <pubKey><br />
<br />
To demonstrate how scripts look on the wire, here is a raw scriptPubKey:<br />
<pre> 76 A9 14<br />
OP_DUP OP_HASH160 Bytes to push<br />
<br />
89 AB CD EF AB BA AB BA AB BA AB BA AB BA AB BA AB BA AB BA 88 AC<br />
Data to push OP_EQUALVERIFY OP_CHECKSIG</pre><br />
<br />
Note: scriptSig is in the input of the spending transaction and scriptPubKey is in the output of the previously storing transaction, i.e. its "available bitcoins".<br />
<br />
Here is how each instruction is processed:<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
| <sig> <pubKey> OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| scriptSig and scriptPubKey are combined.<br />
|-<br />
|<sig> <pubKey><br />
| OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| Constants are added to the stack.<br />
|-<br />
|<sig> <pubKey> <pubKey><br />
| OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| Top stack item is duplicated.<br />
|-<br />
|<sig> <pubKey> <pubHashA><br />
|<pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG<br />
| Top stack item is hashed.<br />
|-<br />
|<sig> <pubKey> <pubHashA> <pubKeyHash><br />
|OP_EQUALVERIFY OP_CHECKSIG<br />
| Constant added.<br />
|-<br />
|<sig> <pubKey><br />
|OP_CHECKSIG<br />
| Equality is checked between the top two stack items.<br />
|-<br />
|true<br />
|Empty.<br />
|Signature is checked for top two stack items.<br />
|}<br />
<br />
===Transaction to IP address (and generation transaction)===<br />
<br />
scriptPubKey: <pubKey> OP_CHECKSIG<br />
scriptSig: <sig><br />
<br />
Checking process:<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
|<sig> <pubKey> OP_CHECKSIG<br />
|scriptSig and scriptPubKey are combined.<br />
|-<br />
|<sig> <pubKey><br />
| OP_CHECKSIG<br />
|Constants are added to the stack.<br />
|-<br />
|true<br />
|Empty.<br />
|Signature is checked for top two stack items.<br />
|}<br />
<br />
In the case of a '''coin generation transaction''' (the first transaction of each block), there is no scriptSig, resp. its code ("coinbase") is completly ignored for the transaction. Only the scriptPubKey is used.<br />
<br />
===Transaction with a message===<br />
<br />
It's possible to add arbitrary data to any transaction by just adding some data along with OP_DROP. <br />
scriptPubKey: <message> OP_DROP <pubKey> OP_CHECKSIG<br />
scriptSig: <sig><br />
<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
|<sig> <message> OP_DROP <pubKey> OP_CHECKSIG<br />
|<br />
|-<br />
|<sig><br />
|<message> OP_DROP <pubKey> OP_CHECKSIG<br />
|scriptSig added to the stack.<br />
|-<br />
|<sig> <message><br />
|OP_DROP <pubKey> OP_CHECKSIG<br />
|The message has been put.<br />
|-<br />
|<sig><br />
|<pubKey> OP_CHECKSIG<br />
|Top stack item has been removed.<br />
|-<br />
|<sig> <pubKey><br />
|OP_CHECKSIG<br />
|Checking signature against the public key.<br />
|-<br />
|true<br />
|Empty.<br />
|Stack holds the value of signature check now.<br />
|}<br />
<br />
===Examples of non standard transaction on Testnet===<br />
<br />
These two links below show a non standard transaction. It just prepends the hex of "bob" and the operation OP_DROP<br />
which just removes it. As you can see they can be spent as normal.<br />
<br />
Input non-std transaction:<br />
http://blockexplorer.com/testnet/t/6ttfeb55B1<br />
<br />
Spent by:<br />
http://blockexplorer.com/testnet/t/AFdRB1CHS3<br />
<br />
==Script validation==<br />
A script evaluation is considered invalid, if any of these conditions meets:<br><br />
<ul><br />
<li>the total size of the script exceeds (currently) 10000 bytes<br />
<li>there are more than (currently) 201 opcodes of opcode value > 0x60 in the script<br />
<li>each instruction is (currently) limited to maximal 520 bytes. This effects only the opcodes OP_PUSHDATA2 and OP_PUSHDATA4<br />
<li>the executed opcode of the script has insufficient input (from stack, from script or from anywhere)<br />
<li>the opcode is not defined (for execution) - indicated by white or light gray background color in the table<br />
<li>the opcode is disabled (currently 15 opcodes) - indicated by white font color in the opcode overview matrix<br />
<li>stack overflow occurs during execution of the opcode (currently the number of items on the stack and on the alternate stack is limited to 1000)<br />
<li>the opcodes OP_VERIF and OP_NOTVERIF invalidate a script which contains this opcode (even if this opcode is not executed!)<br />
<li>the opcodes OP_ELSE or OP_ENDIF has no matching OP_IF<br><br />
<li>the script execution has been finished but there is (at least) an unmatched OP_IF<br><br />
<li>the opcodes OP_VERIFY, OP_EQUALVERIFY, OP_NUMEQUALVERIFY, OP_CHECKSIGVERIFY and OP_CHECKMULTISIGVERIFY invalidate the script if the stack-top item is false<br />
<li>the execution of OP_RETURN<br />
<!--li>alt stack overflow occurs (only possible during execution of OP_TOALTSTACK)--><br />
<li>the numerical value of the top-stack item is negative or greater than the number of items - 2 on the stack if OP_PICK or OP_ROLL shall be executed<br />
<li>an item used as public key or signature for each of the opcodes OP_CHECKSIG, OP_CHECKSIGVERIFY, OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY can be neither a public key or signature (for the given hash)<br />
<li>the number of signature items or the number of public key items on the stack is negative for OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY<br />
<li>there or more signatures items than public key items on the stack for OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY<br />
<li>there are (currently) more than 20 public key items on the stack for OP_CHECKMULTISIG or CHECKMULTISIGVERIFY<br />
<li>the sum of opcodes > 0x60 and the number of public keys in all executed OP_CHECKMULTISIG or CHECKMULTISIGVERIFY exceeds (currently) 201<br />
<li>the script execution has been finished and the stack is empty or the top-stack item is false (numerical value 0)<br />
</ul><br />
else the script evaluation is considered to be valid.<ref>[http://sourceforge.net/projects/bitcoin/files/Bitcoin/bitcoin-0.7.1/bitcoin-0.7.1-linux.tar.gz file src/src/script.cpp in bitcoin-0.7.1]</ref><br />
'''If invalidation of a script is triggered then the script is immediately finished.''' These arbitrary looking limitations of 10000, 201, 520, 1000 and 20 might be increased in the future -- they serve to prevent strong slow down of the evaluation of a script while not restricting its practical usage really.<br />
<br />
==Withdrawn and drafted opcodes==<br />
<br />
<ul><br />
<li> byte value 0x89 OP_NOTEQUAL defined in pre-0.1.0 bitcoin versions. Since 0.1.0 removed because of security concerns. <br />
<li> byte value 0xb1 [[BIP 0012 | OP_EVAL]] withdraw - poll was triggered but insufficient support. <br />
<li> byte value 0xb2 [[BIP 0017 | OP_CHECKHASHVERIFY]] withdraw - poll was triggered but insufficient support.<br />
</ul><br />
<br />
==See Also==<br />
* [[Transactions]]<br />
* [[Contracts]]<br />
<br />
==References==<br />
<references/><br />
<ul><br />
<li>[http://www.zorinaq.com/pub/bitcoin-0.1.0.tgz file src/script.cpp in bitcoin-0.1.0]</li><br />
</ul><br />
[[Category:Technical]]<br />
[[Category:Vocabulary]]</div>
Smtp
https://en.bitcoin.it/w/index.php?title=Script&diff=34909
Script
2013-01-11T16:18:19Z
<p>Smtp: /* Bitwise logic */</p>
<hr />
<div>Bitcoin uses a scripting system for [[transactions]]. [[Wikipedia:FORTH|Forth]]-like, Script is simple, stack-based, and processed from left to right. It is purposefully not Turing-complete, with no loops.<br />
<br />
A script is essentially a list of instructions recorded with each transaction that describe how the next person wanting to spend the Bitcoins being transferred can gain access to them.<br />
<br />
Scripts are big-endian and their sequences of bytes is interpreted as a sequence of opcodes with operands. Only opcodes with byte values less than 0x4f have additional operands.<br />
<br />
== Scripts and Bitcoin transactions ==<br />
The script for a typical Bitcoin transfer to destination Bitcoin address D simply encumbers future spending of the bitcoins with two things: the spender must provide<br />
# a public key that, when hashed, yields destination address D embedded in the script, and<br />
# a signature to show evidence of the private key corresponding to the public key just provided.<br />
<br />
Scripting provides the flexibility to change the parameters of what's needed to spend transferred Bitcoins. For example, the scripting system could be used to require two private keys, or a combination of several, or even no keys at all.<br />
<br />
A transaction is valid if nothing in the combined script triggers failure and the top stack item exists and is true (non-zero). The party who originally ''stored'' the Bitcoins now being spent, dictates the script operations that will occur ''last'' in order to release them for use in another transaction. The party wanting to spend them must provide the input(s) to the previously recorded script that results in those operations occurring last leaving behind true (non-zero) on the stack.<br><br />
Only the very first transaction in each bitcoin block has no input script (the entry there is called "coinbase"), because the Bitcoins created with the block are created from hot air and not released by a previous recorded script.<br />
<br />
== Stack ==<br />
<br />
The stacks hold byte vectors (there is the (main) stack and an alternative stack). Byte vectors are interpreted as little-endian variable-length integers with the most significant bit determining the sign of the integer. Thus 0x81 represents -1. 0x80 is another representation of zero (so called negative 0). Byte vectors are interpreted as Booleans where False is represented by any representation of zero, and True is represented by any representation of non-zero.<br />
<br />
== Opcode overview ==<br />
<br />
For each opcode is given: its nemonic without the leading OP_, its hexadecimal byte value, the number of stack items needed (poped) during execution, a semicolon and the number of stack items which has been pushed (after execution). A * after the needed stack items indicates that further bytes from the script following the current opcode are needed. A # indicates that items on the alternative stack are poped/pushed. A @ indicates that further (global) data from the transaction is needed. A / indicates alternatives of a value. <br/><br />
Different colors indicate different semantic execution groups of opcodes:<br />
{| style="background:none; font-size:100%; padding:0; border-collapse:collapse; text-align:center; line-height:2em;" border="0" align="center" <br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | copy a fixed number of bytes but at most 75 onto stack<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | copy bytes onto stack which number is given by a 1, 2 or 4 byte value.<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | copy 1 specific byte onto stack<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | undefined opcode<br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | a pseudo-opcode, unassigned for scripts<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | NOP or opcode is part of a IF-flow-control construction<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00ff00;" | (stack conditionally) invalidation of the script this opcode is part of<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | stack item is moved between main stack and alternate stack<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | stack item(s) is/are moved, copied or deleted<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0;" | byte vectors are appended or divided or their size is determined<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff;" | byte vectors are interpreted bit-position-independently<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | byte vectors are interpreted and processed as signed integers<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | a hash value is computed or a signature checked<br />
|}<br />
<p><br />
===Opcode byte-matrix===<br />
The opcode value 0x00 with nemonic OP_FALSE is also named OP_0 and the opcode value 0x51 with nemonic OP_1 as also named OP_TRUE.<br />
{| style="background:none; font-size:100%; padding:0; border-collapse:collapse; text-align:center; line-height:2em;" border="0" align="center" <br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" |_FALSE<br/> 0x00 <br/> 0 ; 1(0) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x01<br/> 0 *; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x02<br/> 0 *; 1(2)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x03<br/> 0 *; 1(3)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x04<br/> 0 *; 1(4)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x04<br/> 0 *; 1(5)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x06<br/> 0 *; 1(6)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x07<br/> 0 *; 1(7)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x08<br/> 0 *; 1(8)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x09<br/> 0 *; 1(9)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0a<br/> 0 *; 1(10)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0b<br/> 0 *; 1(11)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0c<br/> 0 *; 1(12)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0d<br/> 0 *; 1(13)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0e<br/> 0 *; 1(14)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0f<br/> 0 *; 1(15)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x10 <br/> 0 *; 1(16) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x11 <br/> 0 *; 1(17)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x12 <br/> 0 *; 1(18)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x13 <br/> 0 *; 1(19)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x14 <br/> 0 *; 1(20)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x15 <br/> 0 *; 1(21)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x16 <br/> 0 *; 1(22)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x17 <br/> 0 *; 1(23)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x18 <br/> 0 *; 1(24)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x19 <br/> 0 *; 1(25)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1a <br/> 0 *; 1(26)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1b <br/> 0 *; 1(27)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1c <br/> 0 *; 1(28)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1d <br/> 0 *; 1(29)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1e <br/> 0 *; 1(30)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1f <br/> 0 *; 1(31)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x20 <br/> 0 *; 1(32) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x21 <br/> 0 *; 1(33)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x22 <br/> 0 *; 1(34)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x23 <br/> 0 *; 1(35)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x24 <br/> 0 *; 1(36)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x25 <br/> 0 *; 1(37)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x26 <br/> 0 *; 1(38)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x27 <br/> 0 *; 1(39)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x28 <br/> 0 *; 1(40)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x29 <br/> 0 *; 1(41)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2a <br/> 0 *; 1(42)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2b <br/> 0 *; 1(43)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2c <br/> 0 *; 1(44)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2d <br/> 0 *; 1(45)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2e <br/> 0 *; 1(46)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2f <br/> 0 *; 1(47)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x30 <br/> 0 *; 1(48) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x31 <br/> 0 *; 1(49)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x32 <br/> 0 *; 1(50)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x33 <br/> 0 *; 1(51)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x34 <br/> 0 *; 1(52)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x35 <br/> 0 *; 1(53)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x36 <br/> 0 *; 1(54)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x37 <br/> 0 *; 1(55)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x38 <br/> 0 *; 1(56)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x39 <br/> 0 *; 1(57)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3a <br/> 0 *; 1(58)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3b <br/> 0 *; 1(59)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3c <br/> 0 *; 1(60)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3d <br/> 0 *; 1(61)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3e <br/> 0 *; 1(62)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3f <br/> 0 *; 1(63)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x40 <br/> 0 *; 1(64) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x41 <br/> 0 *; 1(65)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x42 <br/> 0 *; 1(66)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x43 <br/> 0 *; 1(67)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x44 <br/> 0 *; 1(68)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x45 <br/> 0 *; 1(69)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x46 <br/> 0 *; 1(70)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x47 <br/> 0 *; 1(71)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x48 <br/> 0 *; 1(72)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x49 <br/> 0 *; 1(73)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x4a <br/> 0 *; 1(74)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x4b <br/> 0 *; 1(75)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA1 <br/> 0x4c <br/> 0 *; 1(0 - 255)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA2 <br/> 0x4d <br/> 0 *; 1(0 - 2^16-1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA4 <br/> 0x4e <br/> 0 *; 1(0 - 2^32-1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _1NEGATE <br/> 0x4f <br/> 0 ; 1(1)<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED <br/> 0x50 <br/> <br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _1 <br/> 0x51 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _2 <br/> 0x52 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _3 <br/> 0x53 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _4 <br/> 0x54 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _5 <br/> 0x55 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _6 <br/> 0x56 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _7 <br/> 0x57 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _8 <br/> 0x58 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _9 <br/> 0x59 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _10 <br/> 0x5a <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _11 <br/> 0x5b <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _12 <br/> 0x5c <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _13 <br/> 0x5d <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _14 <br/> 0x5e <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _15 <br/> 0x5f <br/> 0 ; 1(1)<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _16 <br/> 0x60 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP <br/> 0x61 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VER <br/> 0x62 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _IF <br/> 0x63 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOTIF <br/> 0x64 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VERIF <br/> 0x65 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VERNOTIF <br/> 0x66 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _ELSE <br/> 0x67 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _ENDIF <br/> 0x68 <br/> 0 ; 0<br />
| style="border:3px solid #808080; background-color:#00ff00;" | _VERIFY <br/> 0x69 <br/> 1 ; 0/1<br />
| style="border:3px solid #808080; background-color:#00ff00;" | _RETURN <br/> 0x6a <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | _TOALTSTACK <br/> 0x6b <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | _FROMALTSTACK <br/> 0x6c <br/> 0 #; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2DROP <br/> 0x6d <br/> 2 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2DUP <br/> 0x6e <br/> 2 ; 4<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _3DUP <br/> 0x6f <br/> 3 ; 6<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2OVER <br/> 0x70 <br/> 4 ; 6<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2ROT <br/> 0x71 <br/> 6 ; 6<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2SWAP <br/> 0x72 <br/> 4 ; 4<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _IFDUP <br/> 0x73 <br/> 1 ; 1/2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DEPTH <br/> 0x74 <br/> 0 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DROP <br/> 0x75 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DUP <br/> 0x76 <br/> 1 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _NIP <br/> 0x77 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _OVER <br/> 0x78 <br/> 2 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _PICK <br/> 0x79 <br/> 1+n+1 ; n+2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _ROLL <br/> 0x7a <br/> 1+n+1 ; n+1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _ROT <br/> 0x7b <br/> 3 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _SWAP <br/> 0x7c <br/> 2 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _TUCK <br/> 0x7d <br/> 2 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _CAT <br/> 0x7e <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _SUBSTR <br/> 0x7f <br/> 3 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _LEFT <br/> 0x80 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _RIGHT <br/> 0x81 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0;" | _SIZE <br/> 0x82 <br/> 1 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _INVERT <br/> 0x83 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _AND <br/> 0x84 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _OR <br/> 0x85 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _XOR <br/> 0x86 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff;" | _EQUAL <br/> 0x87 <br/> 2 ; 1<br />
| style="border:3px solid #808080; background-color:#c080ff;" | _EQUALVERIFY <br/> 0x88 <br/> 2 ; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED1 <br/> 0x89 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED2 <br/> 0x8a <br/><br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _1ADD <br/> 0x8b <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _1SUB <br/> 0x8c <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _2MUL <br/> 0x8d <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _2DIV <br/> 0x8e <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NEGATE <br/> 0x8f <br/> 1 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _ABS <br/> 0x90 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NOT <br/> 0x91 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _0NOTEQUAL <br/> 0x92 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _ADD <br/> 0x93 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _SUB <br/> 0x94 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _MUL <br/> 0x95 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _DIV <br/> 0x96 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _MOD <br/> 0x97 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _LSHIFT <br/> 0x98 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _RSHIFT <br/> 0x99 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _BOOLAND <br/> 0x9a <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _BOOLOR <br/> 0x9b <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NUMEQUAL <br/> 0x9c <br/> 2 ; 1<br />
| style="border:3px solid #808080; background-color:#8080ff;" | _NUMEQUALVERIFY <br/> 0x9d <br/> 2 ; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NUMNOTEQUAL <br/> 0x9e <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _LESSTHAN <br/> 0x9f <br/> 2 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _GREATERTHAN <br/> 0xa0 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _LESSTHANOREQUAL <br/> 0xa1 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _GREATERTHANOREQUAL <br/> 0xa2 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _MIN <br/> 0xa3 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _MAX <br/> 0xa4 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _WITHIN <br/> 0xa5 <br/> 3 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _RIPEMD160 <br/> 0xa6 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _SHA1 <br/> 0xa7 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _SHA256 <br/> 0xa8 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _HASH160 <br/> 0xa9 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _HASH256 <br/> 0xaa <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CODESEPARATOR <br/> 0xab <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CHECKSIG <br/> 0xac <br/> 2 @; 1<br />
| style="border:3px solid #808080; background-color:#a0d0ff;" | _CHECKSIGVERIFY <br/> 0xad <br/> 2 @; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CHECKMULTISIG <br/> 0xae <br/> 2n+2 @; 1<br />
| style="border:3px solid #808080; background-color:#a0d0ff;" | _CHECKMULTISIGVERIFY <br/> 0xaf <br/> 2n+2 @; 0/1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP1 <br/> 0xb0 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP2 <br/> 0xb1 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP3 <br/> 0xb2 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP4 <br/> 0xb3 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP5 <br/> 0xb4 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP6 <br/> 0xb5 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP7 <br/> 0xb6 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP8 <br/> 0xb7 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP9 <br/> 0xb8 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP10 <br/> 0xb9 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xba <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbe <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xca <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xce <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xda <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xde <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xea <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xeb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xec <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xed <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xee <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xef <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xfa <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _SMALLINTEGER <br/> 0xfb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEYS <br/> 0xfc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEYHASH <br/> 0xfd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEY <br/> 0xfe <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _INVALIDOPCODE <br/> 0xff <br/><br />
|}<br><br />
Except later pseudo-opcode changes, the definition of OP_NOP1 - OP_NOP10 and the change of the evaluation of OP_RETURN (did no invalidation previously) which both occured in bitcoin version 0.3.6 in July 2010 were the last changes regarding opcodes <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.2.0/bitcoin-0.2.0-linux.tar.gz file src/srcipt.cpp in bitcoin-0.2.0]</ref> <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.3.3/bitcoin-0.3.3-linux.tar.gz file src/srcipt.cpp in bitcoin-0.3.3]</ref> <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.3.6/bitcoin-0.3.6-linux.tar.gz file src/srcipt.cpp in bitcoin-0.3.6]</ref>.<br />
<br />
== Opcode descriptions ==<br />
It follows for each opcode less than decimal 185 (hexa 0xba) a description for its usage. The columns entitled ''nemonic'', ''decimal'' and ''Hex'' should be evident. The column ''input'' gives the needed items of the stack (and the alternate stack) and the column ''output'' indicates the resulting items on the stack (and the alternate stack). '''Stack-top is always the right most item.''' The naming of the entries in these two columns is chosen to reflect their interpretation. ''x'', ''x0'', ''x1'', ... means arbitrary or no interpretation, ''i0'', ''i1'' and ''i2'' a signed integer value, ''n'',''index'',''size'' and ''depth'' non-negative (unsigned) integer values, ''Boolean'' as either a true or false.<br><br />
<br />
Some of the more complicated opcodes are disabled out of concern that the client might have (and has) a bug in the current implementation due to the historically not as 2-complement interpretations of the byte vectors as numerical values (the most significant byte holds the sign of the byte vectors).<br />
<br />
=== Push data from instruction onto stack ===<br />
<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_FALSE, OP_0<br />
|0<br />
|0x00<br />
|Nothing<br />
|Empty string<br />
|A byte vector of length 0 is pushed onto the stack. (Thus, it is not a no-op!)<br />
|-<br />
|(no official nemonics)<br />
|1 - 75<br />
|0x01 - 0x4b<br />
|(operand)<br />
|x<br />
|The next <opcode>-many bytes are to be pushed onto the stack.<br />
|-<br />
|OP_PUSHDATA1<br />
|76<br />
|0x4c<br />
|(operands)<br />
|x<br />
|The next byte contains the number of bytes to be pushed onto the stack which follow this byte.<br />
|-<br />
|OP_PUSHDATA2<br />
|77<br />
|0x4d<br />
|(operands)<br />
|x<br />
|The next two bytes contain the number of bytes to be pushed onto the stack which follow theses 2 bytes.<br />
|-<br />
|OP_PUSHDATA4<br />
|78<br />
|0x4e<br />
|(operands)<br />
|x<br />
|The next four bytes contain the number of bytes to be pushed onto the stack which follow theses 4 bytes.<br />
|-<br />
|OP_1NEGATE<br />
|79<br />
|0x4f<br />
|Nothing<br />
| -1<br />
|The byte with value -1 is pushed onto the stack.<br />
|-<br />
|OP_1, OP_TRUE<br />
|81<br />
|0x51<br />
|Nothing<br />
|1<br />
|The byte with value 1 is pushed onto the stack.<br />
|-<br />
|OP_2 - OP_16<br />
|82 - 96<br />
|0x52 - 0x60<br />
|Nothing<br />
|2-16<br />
|The byte with value <opcode>-80 (thus, one of 2 - 16) is pushed onto the stack.<br />
|}<br />
<br />
=== Flow control ===<br />
<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_NOP<br />
|97<br />
|0x61<br />
|Nothing<br />
|Nothing<br />
|Does nothing.<br />
|-<br />
|OP_IF<br />
|99<br />
|0x63<br />
|Boolean<br />
|Nothing<br />
|If the top stack value is not 0, the statements are executed. The top stack value is removed. Lead in a logcial ''<value> then [statements] [else [statements]] endif'' expression<br />
|-<br />
|OP_NOTIF<br />
|100<br />
|0x64<br />
|Boolean<br />
|Nothing<br />
|If the top stack value is 0, the statements are executed. The top stack value is removed. Lead in a logcial ''<value> then [statements] [else [statements]] endif'' expression <br />
|-<br />
|OP_ELSE<br />
|103<br />
|0x67<br />
|Nothing<br />
|Nothing<br />
|If the preceeding OP_IF or OP_NOTIF or OP_ELSE was not executed then these statements are and if the preceding OP_IF or OP_NOTIF or OP_ELSE was executed then these statements are not. <br />
|-<br />
|OP_ENDIF<br />
|104<br />
|0x68<br />
|Nothing<br />
|Nothing<br />
|Ends a logcial ''If <value> then [statements] [else [statements]] '' expression<br />
|-<br />
|OP_VERIFY<br />
|105<br />
|0x69<br />
|Boolean<br />
|Nothing / False<br />
|If top stack value is not true then marks transaction as '''invalid''' . A value true is removed, but false is not.<br />
|-<br />
|OP_RETURN<br />
|106<br />
|0x6a<br />
|Nothing<br />
|Nothing<br />
|Marks transaction as '''invalid'''. <br />
|}<br />
<br />
===Stack item organization===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_TOALTSTACK<br />
|107<br />
|0x6b<br />
|x1 (alt)<br />
|(alt x1)<br />
|Puts the input onto the top of the alt stack. Removes it from the (main) stack.<br />
|-<br />
|OP_FROMALTSTACK<br />
|108<br />
|0x6c<br />
|(alt x1)<br />
|x1 (alt)<br />
|Puts the input onto the top of the (main) stack. Removes it from the alt stack.<br />
|-<br />
|OP_2DROP<br />
|109<br />
|0x6d<br />
|x2 x1<br />
|Nothing<br />
|Removes the top two stack items.<br />
|-<br />
|OP_2DUP<br />
|110<br />
|0x6e<br />
|x2 x1<br />
|x2 x1 x2 x1<br />
|Duplicates the top two stack items.<br />
|-<br />
|OP_3DUP<br />
|111<br />
|0x6f<br />
|x3 x2 x1<br />
|x3 x2 x1 x3 x2 x1<br />
|Duplicates the top three stack items.<br />
|-<br />
|OP_2OVER<br />
|112<br />
|0x70<br />
|x4 x3 x2 x1<br />
|x4 x3 x2 x1 x4 x3<br />
|Copies the pair of items two spaces back in the stack to the front.<br />
|-<br />
|OP_2ROT<br />
|113<br />
|0x71<br />
|x6 x5 x4 x3 x2 x1<br />
|x4 x3 x2 x1 x6 x5<br />
|The fifth and sixth items back are moved to the top of the stack. Twotimes left rotate.<br />
|-<br />
|OP_2SWAP<br />
|114<br />
|0x72<br />
|x4 x3 x2 x1<br />
|x2 x1 x4 x3<br />
|Swaps the top two pairs of stack items.<br />
|-<br />
|OP_IFDUP<br />
|115<br />
|0x73<br />
|x1<br />
|x1 / x1 x1<br />
|If the top stack value is not 0, duplicate it.<br />
|-<br />
|OP_DEPTH<br />
|116<br />
|0x74<br />
|Nothing<br />
|depth<br />
|Puts the number of stack items onto the stack as one little-endian coded byte-vector<br />
|-<br />
|OP_DROP<br />
|117<br />
|0x75<br />
|x1<br />
|Nothing<br />
|Removes the top stack item.<br />
|-<br />
|OP_DUP<br />
|118<br />
|0x76<br />
|x1<br />
|x1 x1<br />
|Duplicates the top stack item.<br />
|-<br />
|OP_NIP<br />
|119<br />
|0x77<br />
|x2 x1<br />
|x1<br />
|Removes the second-to-top stack item.<br />
|-<br />
|OP_OVER<br />
|120<br />
|0x78<br />
|x2 x1<br />
|x2 x1 x2<br />
|Copies the second-to-top stack item to the top.<br />
|-<br />
|OP_PICK<br />
|121<br />
|0x79<br />
|xn ... x2 x1 x0 <n><br />
|xn ... x2 x1 x0 xn<br />
|<n> is removed and the item ''n'' back in the stack is copied to the top.<br />
|-<br />
|OP_ROLL<br />
|122<br />
|0x7a<br />
|xn ... x2 x1 x0 <n><br />
|... x2 x1 x0 xn<br />
|<n> is removed and the item ''n'' back in the stack is moved to the top.<br />
|-<br />
|OP_ROT<br />
|123<br />
|0x7b<br />
|x3 x2 x1<br />
|x2 x1 x3<br />
|The top three items on the stack are rotated to the left.<br />
|-<br />
|OP_SWAP<br />
|124<br />
|0x7c<br />
|x2 x1<br />
|x1 x2<br />
|The top two items on the stack are swapped resp. rotated.<br />
|-<br />
|OP_TUCK<br />
|125<br />
|0x7d<br />
|x2 x1<br />
|x1 x2 x1<br />
|The item at the top of the stack is copied and inserted before the second-to-top item.<br />
|}<br />
<br />
=== Splice ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_CAT<br />
|126<br />
|0x7e<br />
|x2 x1<br />
|out<br />
|Appends stack-top item at second-to top item. Concatenates two strings resp. byte vectors. ''Currently disabled.''<br />
|-<br />
|OP_SUBSTR<br />
|127<br />
|0x7f<br />
|x3 index size<br />
|out<br />
|Returns the section started at position <index> and of length <size> of a string resp. byte vector. ''Currently disabled.''<br />
|-<br />
|OP_LEFT<br />
|128<br />
|0x80<br />
|x2 index<br />
|out<br />
|Keeps only characters left of the specified point in second-to top item. ''Currently disabled.''<br />
|-<br />
|OP_RIGHT<br />
|129<br />
|0x81<br />
|x2 index<br />
|out<br />
|Keeps only characters right of the specified point in second-to top item. ''Currently disabled.''<br />
|-<br />
|OP_SIZE<br />
|130<br />
|0x82<br />
|x1<br />
|x1 size<br />
|Returns the length of the input string resp. byte vector resp. top-stack item.<br />
|}<br />
<br />
=== Bitwise logic ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_INVERT<br />
|131<br />
|0x83<br />
|x1<br />
|x0<br />
|Flips all of the bits in the input. ''Currently disabled.''<br />
|-<br />
|OP_AND<br />
|132<br />
|0x84<br />
|x2 x1<br />
|x0<br />
|Boolean ''and'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_OR<br />
|133<br />
|0x85<br />
|x2 x1<br />
|x0<br />
|Boolean ''or'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_XOR<br />
|134<br />
|0x86<br />
|x2 x1<br />
|x0<br />
|Boolean ''exclusive or'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_EQUAL<br />
|135<br />
|0x87<br />
|x2 x1<br />
|Boolean<br />
|Returns 1 if the inputs have the same length and are byte-wise equal, 0 otherwise.<br />
|-<br />
|OP_EQUALVERIFY<br />
|136<br />
|0x88<br />
|x2 x1<br />
|Nothing / false<br />
|Same as OP_EQUAL, but runs OP_VERIFY afterward.<br />
|}<br />
<br />
=== Arithmetic ===<br />
<br />
(In very early versions, the implemented arithmetic opcodes were limited to maximal 4 byte vectors.)<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_1ADD<br />
|139<br />
|0x8b<br />
|i1<br />
|i0<br />
|1 is added to the input.<br />
|-<br />
|OP_1SUB<br />
|140<br />
|0x8c<br />
|i1<br />
|i0<br />
|1 is subtracted from the input.<br />
|-<br />
|OP_2MUL<br />
|141<br />
|0x8d<br />
|i1<br />
|i0<br />
|The input is multiplied by 2. ''Currently disabled.''<br />
|-<br />
|OP_2DIV<br />
|142<br />
|0x8e<br />
|i1<br />
|i0<br />
|The input is divided by 2 (round down). ''Currently disabled.''<br />
|-<br />
|OP_NEGATE<br />
|143<br />
|0x8f<br />
|i1<br />
|i0<br />
|The sign of the input is flipped. Numerically the value is multiplied by -1<br />
|-<br />
|OP_ABS<br />
|144<br />
|0x90<br />
|i1<br />
|i0<br />
|The input is negative, its sign is flipped.<br />
|-<br />
|OP_NOT<br />
|145<br />
|0x91<br />
|i1<br />
|Boolean<br />
|If the input is 0 or 1, it is flipped. Otherwise the output will be 0. Test whether its value equals 0<br />
|-<br />
|OP_0NOTEQUAL<br />
|146<br />
|0x92<br />
|i1<br />
|Boolean<br />
|Returns 0 if the input is 0. 1 otherwise. Test whether its value is unequal 0<br />
|-<br />
|OP_ADD<br />
|147<br />
|0x93<br />
|i2 i1<br />
|i0<br />
|stack-top i1 is added to i2.<br />
|-<br />
|OP_SUB<br />
|148<br />
|0x94<br />
|i2 i1<br />
|i0<br />
|stack-top i1 is subtracted from i2.<br />
|-<br />
|OP_MUL<br />
|149<br />
|0x95<br />
|i2 i1<br />
|i0<br />
|i2 is multiplied with stack-top i1. ''Currently disabled.''<br />
|-<br />
|OP_DIV<br />
|150<br />
|0x96<br />
|i2 i1<br />
|i0<br />
|i2 is divided by stack-top i1 (divisor should be not 0). ''Currently disabled.''<br />
|-<br />
|OP_MOD<br />
|151<br />
|0x97<br />
|i2 i1<br />
|i0<br />
|Returns the remainder after dividing i2 by stack-top i1 (divisor should be not 0). ''Currently disabled.''<br />
|-<br />
|OP_LSHIFT<br />
|152<br />
|0x98<br />
|i2 i1<br />
|i0<br />
|Shifts i2 left by i1 bits, preserving sign of i2 (i1 >= 0). ''Currently disabled.''<br />
|-<br />
|OP_RSHIFT<br />
|153<br />
|0x99<br />
|i2 i1<br />
|i0<br />
|Shifts i2 right by i1 bits, preserving sign of i2 (i1 >= 0). ''Currently disabled.''<br />
|-<br />
|OP_BOOLAND<br />
|154<br />
|0x9a<br />
|i2 i1<br />
|Boolean<br />
|If both i2 and i1 are not 0, the output is 1. Otherwise 0.<br />
|-<br />
|OP_BOOLOR<br />
|155<br />
|0x9b<br />
|i2 i1<br />
|Boolean<br />
|If i2 or i1 is not 0, the output is 1. Otherwise 0.<br />
|-<br />
|OP_NUMEQUAL<br />
|156<br />
|0x9c<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 and i1 are numerically equal, 0 otherwise.<br />
|-<br />
|OP_NUMEQUALVERIFY<br />
|157<br />
|0x9d<br />
|i2 i1<br />
|Nothing / False<br />
|Same as OP_NUMEQUAL, but runs OP_VERIFY afterward.<br />
|-<br />
|OP_NUMNOTEQUAL<br />
|158<br />
|0x9e<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 and i1 are numerically not equal, 0 otherwise.<br />
|-<br />
|OP_LESSTHAN<br />
|159<br />
|0x9f<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is less than stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_GREATERTHAN<br />
|160<br />
|0xa0<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is greater than stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_LESSTHANOREQUAL<br />
|161<br />
|0xa1<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is less than or equal to stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_GREATERTHANOREQUAL<br />
|162<br />
|0xa2<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is greater than or equal to stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_MIN<br />
|163<br />
|0xa3<br />
|i2 i1<br />
|i2 / i1<br />
|Returns the smaller of i2 and i1.<br />
|-<br />
|OP_MAX<br />
|164<br />
|0xa4<br />
|i2 i1<br />
|i2 / i1<br />
|Returns the larger of i2 and i1.<br />
|-<br />
|OP_WITHIN<br />
|165<br />
|0xa5<br />
|i3 i2 i1<br />
|Boolean<br />
|Returns 1 if i3 >= i2 and i3 < i1, 0 otherwise. Thus if i2 > i1 returns always 0.<br />
|}<br />
<br />
=== Crypto ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_RIPEMD160<br />
|166<br />
|0xa6<br />
|x<br />
|hash20<br />
|The input is hashed using RIPEMD-160.<br />
|-<br />
|OP_SHA1<br />
|167<br />
|0xa7<br />
|x<br />
|hash20<br />
|The input is hashed using SHA-1.<br />
|-<br />
|OP_SHA256<br />
|168<br />
|0xa8<br />
|x<br />
|hash32<br />
|The input is hashed using SHA-256.<br />
|-<br />
|OP_HASH160<br />
|169<br />
|0xa9<br />
|x<br />
|hash20<br />
|The input is hashed twice: first with SHA-256 and then with RIPEMD-160.<br />
|-<br />
|OP_HASH256<br />
|170<br />
|0xaa<br />
|x<br />
|hash32<br />
|The input is hashed two times with SHA-256.<br />
|-<br />
|OP_CODESEPARATOR<br />
|171<br />
|0xab<br />
|Nothing<br />
|Nothing<br />
|All of the signature checking opcodes will only match signatures to the data after the most recently-executed OP_CODESEPARATOR.<br />
|-<br />
|[[OP_CHECKSIG]]<br />
|172<br />
|0xac<br />
|sig pubkey<br />
|Boolean<br />
|The entire transaction's outputs, inputs, and script (from the most recently-executed OP_CODESEPARATOR to the end) are hashed. The signature used by OP_CHECKSIG must be a valid signature for a further, extern specified hash and the given public key. If it is, 1 is returned, 0 otherwise.<br />
|-<br />
|OP_CHECKSIGVERIFY<br />
|173<br />
|0xad<br />
|sig pubkey<br />
|Nothing / False<br />
|Same as OP_CHECKSIG, but OP_VERIFY is executed afterward.<br />
|-<br />
|OP_CHECKMULTISIG<br />
|174<br />
|0xae<br />
|sig1 sig2 ... <number of signatures> pub1 pub2 <number of public keys><br />
|Boolean<br />
|For each signature and public key pair, OP_CHECKSIG is executed. If more public keys than signatures are listed, some key/sig pairs can fail. All signatures need to match a public key. If all signatures are valid, 1 is returned, 0 otherwise. Due to a bug, one extra unused value is removed from the stack.<br />
|-<br />
|OP_CHECKMULTISIGVERIFY<br />
|175<br />
|0xaf<br />
|sig1 sig2 ... <number of signatures> pub1 pub2 ... <number of public keys><br />
|Nothing / False<br />
|Same as OP_CHECKMULTISIG, but OP_VERIFY is executed afterward.<br />
|}<br />
<br />
=== Expansion opcodes ===<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_NOP1-OP_NOP10<br />
|176-185<br />
|0xb0-0xb9<br />
|The opcode has no effect.<br />
|}<br />
<br />
=== Version opcodes ===<br />
Version opcodes are disabled since bitcoin 0.2.0 and should not be used (maybe reassigned in the future).<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_VER<br />
|98<br />
|0x62<br />
|Script evalution is triggered invalid (Formerly pushed the bitcoin-serialize version onto stack).<br />
|-<br />
|OP_VERIF<br />
|101<br />
|0x65<br />
|Script evalution is triggered invalid (Formerly top stack item was popped and =< compared to present version)<br />
|-<br />
|OP_VERNOTIF<br />
|102<br />
|0x66<br />
|Script evalution is triggered invalid (Formerly top stack item was popped and > compared to present version)<br />
|}<br />
<br />
=== Reserved opcodes ===<br />
Each opcode not assigned (currently also every opcode value > 185) is also reserved. Using any unassigned opcode triggers the script evaluation to be invalid.<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_RESERVED<br />
|80<br />
|0x50<br />
|Script evalution is triggered invalid-<br />
|-<br />
|OP_RESERVED1<br />
|137<br />
|0x89<br />
|Script evalution is triggered invalid.<br />
|-<br />
|OP_RESERVED2<br />
|138<br />
|0x8a<br />
|Script evalution is triggered invalid.<br />
|}<br />
<br />
===Pseudo-opcodes===<br />
These nemonics are used internally for assisting with transaction matching. They are invalid if used in actual scripts.<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_PUBKEYHASH<br />
|253<br />
|0xfd<br />
|Represents a public key hashed with OP_HASH160.<br />
|-<br />
|OP_PUBKEY<br />
|254<br />
|0xfe<br />
|Represents a public key compatible with OP_CHECKSIG.<br />
|-<br />
|OP_INVALIDOPCODE<br />
|255<br />
|0xff<br />
|Matches any opcode that is not yet assigned.<br />
|}<br />
<br />
==Scripts in bitcoin transactions==<br />
It follows a list of important (most occuring) scripts to see opcodes "at work". Keep in mind that all constants actually use the data-pushing instructions above. At start of a (transaction input) script evaluation, the stack is always empty. <br />
<br />
===Standard transaction to bitcoin address===<br />
<br />
scriptPubKey: OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG<br />
scriptSig: <sig> <pubKey><br />
<br />
To demonstrate how scripts look on the wire, here is a raw scriptPubKey:<br />
<pre> 76 A9 14<br />
OP_DUP OP_HASH160 Bytes to push<br />
<br />
89 AB CD EF AB BA AB BA AB BA AB BA AB BA AB BA AB BA AB BA 88 AC<br />
Data to push OP_EQUALVERIFY OP_CHECKSIG</pre><br />
<br />
Note: scriptSig is in the input of the spending transaction and scriptPubKey is in the output of the previously storing transaction, i.e. its "available bitcoins".<br />
<br />
Here is how each instruction is processed:<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
| <sig> <pubKey> OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| scriptSig and scriptPubKey are combined.<br />
|-<br />
|<sig> <pubKey><br />
| OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| Constants are added to the stack.<br />
|-<br />
|<sig> <pubKey> <pubKey><br />
| OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| Top stack item is duplicated.<br />
|-<br />
|<sig> <pubKey> <pubHashA><br />
|<pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG<br />
| Top stack item is hashed.<br />
|-<br />
|<sig> <pubKey> <pubHashA> <pubKeyHash><br />
|OP_EQUALVERIFY OP_CHECKSIG<br />
| Constant added.<br />
|-<br />
|<sig> <pubKey><br />
|OP_CHECKSIG<br />
| Equality is checked between the top two stack items.<br />
|-<br />
|true<br />
|Empty.<br />
|Signature is checked for top two stack items.<br />
|}<br />
<br />
===Transaction to IP address (and generation transaction)===<br />
<br />
scriptPubKey: <pubKey> OP_CHECKSIG<br />
scriptSig: <sig><br />
<br />
Checking process:<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
|<sig> <pubKey> OP_CHECKSIG<br />
|scriptSig and scriptPubKey are combined.<br />
|-<br />
|<sig> <pubKey><br />
| OP_CHECKSIG<br />
|Constants are added to the stack.<br />
|-<br />
|true<br />
|Empty.<br />
|Signature is checked for top two stack items.<br />
|}<br />
<br />
In the case of a '''coin generation transaction''' (the first transaction of each block), there is no scriptSig, resp. its code ("coinbase") is completly ignored for the transaction. Only the scriptPubKey is used.<br />
<br />
===Transaction with a message===<br />
<br />
It's possible to add arbitrary data to any transaction by just adding some data along with OP_DROP. <br />
scriptPubKey: <message> OP_DROP <pubKey> OP_CHECKSIG<br />
scriptSig: <sig><br />
<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
|<sig> <message> OP_DROP <pubKey> OP_CHECKSIG<br />
|<br />
|-<br />
|<sig><br />
|<message> OP_DROP <pubKey> OP_CHECKSIG<br />
|scriptSig added to the stack.<br />
|-<br />
|<sig> <message><br />
|OP_DROP <pubKey> OP_CHECKSIG<br />
|The message has been put.<br />
|-<br />
|<sig><br />
|<pubKey> OP_CHECKSIG<br />
|Top stack item has been removed.<br />
|-<br />
|<sig> <pubKey><br />
|OP_CHECKSIG<br />
|Checking signature against the public key.<br />
|-<br />
|true<br />
|Empty.<br />
|Stack holds the value of signature check now.<br />
|}<br />
<br />
===Examples of non standard transaction on Testnet===<br />
<br />
These two links below show a non standard transaction. It just prepends the hex of "bob" and the operation OP_DROP<br />
which just removes it. As you can see they can be spent as normal.<br />
<br />
Input non-std transaction:<br />
http://blockexplorer.com/testnet/t/6ttfeb55B1<br />
<br />
Spent by:<br />
http://blockexplorer.com/testnet/t/AFdRB1CHS3<br />
<br />
==Script validation==<br />
A script evaluation is considered invalid, if any of these conditions meets:<br><br />
<ul><br />
<li>the total size of the script exceeds (currently) 10000 bytes<br />
<li>there are more than (currently) 201 opcodes of opcode value > 0x60 in the script<br />
<li>each instruction is (currently) limited to maximal 520 bytes. This effects only the opcodes OP_PUSHDATA2 and OP_PUSHDATA4<br />
<li>the executed opcode of the script has insufficient input (from stack, from script or from anywhere)<br />
<li>the opcode is not defined (for execution) - indicated by white or light gray background color in the table<br />
<li>the opcode is disabled (currently 15 opcodes) - indicated by white font color in the opcode overview matrix<br />
<li>stack overflow occurs during execution of the opcode (currently the number of items on the stack and on the alternate stack is limited to 1000)<br />
<li>the opcodes OP_VERIF and OP_NOTVERIF invalidate a script which contains this opcode (even if this opcode is not executed!)<br />
<li>the opcodes OP_ELSE or OP_ENDIF has no matching OP_IF<br><br />
<li>the script execution has been finished but there is (at least) an unmatched OP_IF<br><br />
<li>the opcodes OP_VERIFY, OP_EQUALVERIFY, OP_NUMEQUALVERIFY, OP_CHECKSIGVERIFY and OP_CHECKMULTISIGVERIFY invalidate the script if the stack-top item is false<br />
<li>the execution of OP_RETURN<br />
<!--li>alt stack overflow occurs (only possible during execution of OP_TOALTSTACK)--><br />
<li>the numerical value of the top-stack item is negative or greater than the number of items - 2 on the stack if OP_PICK or OP_ROLL shall be executed<br />
<li>an item used as public key or signature for each of the opcodes OP_CHECKSIG, OP_CHECKSIGVERIFY, OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY can be neither a public key or signature (for the given hash)<br />
<li>the number of signature items or the number of public key items on the stack is negative for OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY<br />
<li>there or more signatures items than public key items on the stack for OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY<br />
<li>there are (currently) more than 20 public key items on the stack for OP_CHECKMULTISIG or CHECKMULTISIGVERIFY<br />
<li>the sum of opcodes > 0x60 and the number of public keys in all executed OP_CHECKMULTISIG or CHECKMULTISIGVERIFY exceeds (currently) 201<br />
<li>the script execution has been finished and the stack is empty or the top-stack item is false (numerical value 0)<br />
</ul><br />
else the script evaluation is considered to be valid.<ref>[http://sourceforge.net/projects/bitcoin/files/Bitcoin/bitcoin-0.7.1/bitcoin-0.7.1-linux.tar.gz file src/src/script.cpp in bitcoin-0.7.1]</ref><br />
'''If invalidation of a script is triggered then the script is immediately finished.''' These arbitrary looking limitations of 10000, 201, 520, 1000 and 20 might be increased in the future -- they serve to prevent strong slow down of the evaluation of a script while not restricting its practical usage really.<br />
<br />
==Withdrawn and drafted opcodes==<br />
<br />
<ul><br />
<li> byte value 0x89 OP_NOTEQUAL defined in pre-0.1.0 bitcoin versions. Since 0.1.0 removed because of security concerns. <br />
<li> byte value 0xb1 [[BIP 0012 | OP_EVAL]] withdraw - poll was triggered but insufficient support. <br />
<li> byte value 0xb2 [[BIP 0017 | OP_CHECKHASHVERIFY]] withdraw - poll was triggered but insufficient support.<br />
</ul><br />
<br />
==See Also==<br />
* [[Transactions]]<br />
* [[Contracts]]<br />
<br />
==References==<br />
<references/><br />
<ul><br />
<li>[http://www.zorinaq.com/pub/bitcoin-0.1.0.tgz file src/script.cpp in bitcoin-0.1.0]</li><br />
</ul><br />
[[Category:Technical]]<br />
[[Category:Vocabulary]]</div>
Smtp
https://en.bitcoin.it/w/index.php?title=Script&diff=34907
Script
2013-01-11T16:14:56Z
<p>Smtp: /* Arithmetic */</p>
<hr />
<div>Bitcoin uses a scripting system for [[transactions]]. [[Wikipedia:FORTH|Forth]]-like, Script is simple, stack-based, and processed from left to right. It is purposefully not Turing-complete, with no loops.<br />
<br />
A script is essentially a list of instructions recorded with each transaction that describe how the next person wanting to spend the Bitcoins being transferred can gain access to them.<br />
<br />
Scripts are big-endian and their sequences of bytes is interpreted as a sequence of opcodes with operands. Only opcodes with byte values less than 0x4f have additional operands.<br />
<br />
== Scripts and Bitcoin transactions ==<br />
The script for a typical Bitcoin transfer to destination Bitcoin address D simply encumbers future spending of the bitcoins with two things: the spender must provide<br />
# a public key that, when hashed, yields destination address D embedded in the script, and<br />
# a signature to show evidence of the private key corresponding to the public key just provided.<br />
<br />
Scripting provides the flexibility to change the parameters of what's needed to spend transferred Bitcoins. For example, the scripting system could be used to require two private keys, or a combination of several, or even no keys at all.<br />
<br />
A transaction is valid if nothing in the combined script triggers failure and the top stack item exists and is true (non-zero). The party who originally ''stored'' the Bitcoins now being spent, dictates the script operations that will occur ''last'' in order to release them for use in another transaction. The party wanting to spend them must provide the input(s) to the previously recorded script that results in those operations occurring last leaving behind true (non-zero) on the stack.<br><br />
Only the very first transaction in each bitcoin block has no input script (the entry there is called "coinbase"), because the Bitcoins created with the block are created from hot air and not released by a previous recorded script.<br />
<br />
== Stack ==<br />
<br />
The stacks hold byte vectors (there is the (main) stack and an alternative stack). Byte vectors are interpreted as little-endian variable-length integers with the most significant bit determining the sign of the integer. Thus 0x81 represents -1. 0x80 is another representation of zero (so called negative 0). Byte vectors are interpreted as Booleans where False is represented by any representation of zero, and True is represented by any representation of non-zero.<br />
<br />
== Opcode overview ==<br />
<br />
For each opcode is given: its nemonic without the leading OP_, its hexadecimal byte value, the number of stack items needed (poped) during execution, a semicolon and the number of stack items which has been pushed (after execution). A * after the needed stack items indicates that further bytes from the script following the current opcode are needed. A # indicates that items on the alternative stack are poped/pushed. A @ indicates that further (global) data from the transaction is needed. A / indicates alternatives of a value. <br/><br />
Different colors indicate different semantic execution groups of opcodes:<br />
{| style="background:none; font-size:100%; padding:0; border-collapse:collapse; text-align:center; line-height:2em;" border="0" align="center" <br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | copy a fixed number of bytes but at most 75 onto stack<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | copy bytes onto stack which number is given by a 1, 2 or 4 byte value.<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | copy 1 specific byte onto stack<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | undefined opcode<br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | a pseudo-opcode, unassigned for scripts<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | NOP or opcode is part of a IF-flow-control construction<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00ff00;" | (stack conditionally) invalidation of the script this opcode is part of<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | stack item is moved between main stack and alternate stack<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | stack item(s) is/are moved, copied or deleted<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0;" | byte vectors are appended or divided or their size is determined<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff;" | byte vectors are interpreted bit-position-independently<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | byte vectors are interpreted and processed as signed integers<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | a hash value is computed or a signature checked<br />
|}<br />
<p><br />
===Opcode byte-matrix===<br />
The opcode value 0x00 with nemonic OP_FALSE is also named OP_0 and the opcode value 0x51 with nemonic OP_1 as also named OP_TRUE.<br />
{| style="background:none; font-size:100%; padding:0; border-collapse:collapse; text-align:center; line-height:2em;" border="0" align="center" <br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" |_FALSE<br/> 0x00 <br/> 0 ; 1(0) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x01<br/> 0 *; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x02<br/> 0 *; 1(2)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x03<br/> 0 *; 1(3)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x04<br/> 0 *; 1(4)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x04<br/> 0 *; 1(5)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x06<br/> 0 *; 1(6)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x07<br/> 0 *; 1(7)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x08<br/> 0 *; 1(8)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x09<br/> 0 *; 1(9)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0a<br/> 0 *; 1(10)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0b<br/> 0 *; 1(11)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0c<br/> 0 *; 1(12)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0d<br/> 0 *; 1(13)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0e<br/> 0 *; 1(14)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0f<br/> 0 *; 1(15)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x10 <br/> 0 *; 1(16) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x11 <br/> 0 *; 1(17)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x12 <br/> 0 *; 1(18)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x13 <br/> 0 *; 1(19)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x14 <br/> 0 *; 1(20)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x15 <br/> 0 *; 1(21)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x16 <br/> 0 *; 1(22)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x17 <br/> 0 *; 1(23)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x18 <br/> 0 *; 1(24)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x19 <br/> 0 *; 1(25)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1a <br/> 0 *; 1(26)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1b <br/> 0 *; 1(27)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1c <br/> 0 *; 1(28)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1d <br/> 0 *; 1(29)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1e <br/> 0 *; 1(30)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1f <br/> 0 *; 1(31)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x20 <br/> 0 *; 1(32) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x21 <br/> 0 *; 1(33)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x22 <br/> 0 *; 1(34)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x23 <br/> 0 *; 1(35)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x24 <br/> 0 *; 1(36)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x25 <br/> 0 *; 1(37)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x26 <br/> 0 *; 1(38)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x27 <br/> 0 *; 1(39)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x28 <br/> 0 *; 1(40)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x29 <br/> 0 *; 1(41)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2a <br/> 0 *; 1(42)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2b <br/> 0 *; 1(43)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2c <br/> 0 *; 1(44)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2d <br/> 0 *; 1(45)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2e <br/> 0 *; 1(46)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2f <br/> 0 *; 1(47)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x30 <br/> 0 *; 1(48) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x31 <br/> 0 *; 1(49)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x32 <br/> 0 *; 1(50)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x33 <br/> 0 *; 1(51)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x34 <br/> 0 *; 1(52)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x35 <br/> 0 *; 1(53)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x36 <br/> 0 *; 1(54)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x37 <br/> 0 *; 1(55)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x38 <br/> 0 *; 1(56)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x39 <br/> 0 *; 1(57)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3a <br/> 0 *; 1(58)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3b <br/> 0 *; 1(59)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3c <br/> 0 *; 1(60)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3d <br/> 0 *; 1(61)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3e <br/> 0 *; 1(62)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3f <br/> 0 *; 1(63)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x40 <br/> 0 *; 1(64) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x41 <br/> 0 *; 1(65)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x42 <br/> 0 *; 1(66)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x43 <br/> 0 *; 1(67)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x44 <br/> 0 *; 1(68)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x45 <br/> 0 *; 1(69)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x46 <br/> 0 *; 1(70)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x47 <br/> 0 *; 1(71)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x48 <br/> 0 *; 1(72)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x49 <br/> 0 *; 1(73)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x4a <br/> 0 *; 1(74)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x4b <br/> 0 *; 1(75)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA1 <br/> 0x4c <br/> 0 *; 1(0 - 255)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA2 <br/> 0x4d <br/> 0 *; 1(0 - 2^16-1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA4 <br/> 0x4e <br/> 0 *; 1(0 - 2^32-1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _1NEGATE <br/> 0x4f <br/> 0 ; 1(1)<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED <br/> 0x50 <br/> <br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _1 <br/> 0x51 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _2 <br/> 0x52 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _3 <br/> 0x53 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _4 <br/> 0x54 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _5 <br/> 0x55 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _6 <br/> 0x56 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _7 <br/> 0x57 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _8 <br/> 0x58 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _9 <br/> 0x59 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _10 <br/> 0x5a <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _11 <br/> 0x5b <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _12 <br/> 0x5c <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _13 <br/> 0x5d <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _14 <br/> 0x5e <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _15 <br/> 0x5f <br/> 0 ; 1(1)<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _16 <br/> 0x60 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP <br/> 0x61 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VER <br/> 0x62 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _IF <br/> 0x63 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOTIF <br/> 0x64 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VERIF <br/> 0x65 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VERNOTIF <br/> 0x66 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _ELSE <br/> 0x67 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _ENDIF <br/> 0x68 <br/> 0 ; 0<br />
| style="border:3px solid #808080; background-color:#00ff00;" | _VERIFY <br/> 0x69 <br/> 1 ; 0/1<br />
| style="border:3px solid #808080; background-color:#00ff00;" | _RETURN <br/> 0x6a <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | _TOALTSTACK <br/> 0x6b <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | _FROMALTSTACK <br/> 0x6c <br/> 0 #; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2DROP <br/> 0x6d <br/> 2 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2DUP <br/> 0x6e <br/> 2 ; 4<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _3DUP <br/> 0x6f <br/> 3 ; 6<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2OVER <br/> 0x70 <br/> 4 ; 6<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2ROT <br/> 0x71 <br/> 6 ; 6<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2SWAP <br/> 0x72 <br/> 4 ; 4<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _IFDUP <br/> 0x73 <br/> 1 ; 1/2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DEPTH <br/> 0x74 <br/> 0 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DROP <br/> 0x75 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DUP <br/> 0x76 <br/> 1 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _NIP <br/> 0x77 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _OVER <br/> 0x78 <br/> 2 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _PICK <br/> 0x79 <br/> 1+n+1 ; n+2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _ROLL <br/> 0x7a <br/> 1+n+1 ; n+1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _ROT <br/> 0x7b <br/> 3 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _SWAP <br/> 0x7c <br/> 2 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _TUCK <br/> 0x7d <br/> 2 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _CAT <br/> 0x7e <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _SUBSTR <br/> 0x7f <br/> 3 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _LEFT <br/> 0x80 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _RIGHT <br/> 0x81 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0;" | _SIZE <br/> 0x82 <br/> 1 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _INVERT <br/> 0x83 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _AND <br/> 0x84 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _OR <br/> 0x85 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _XOR <br/> 0x86 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff;" | _EQUAL <br/> 0x87 <br/> 2 ; 1<br />
| style="border:3px solid #808080; background-color:#c080ff;" | _EQUALVERIFY <br/> 0x88 <br/> 2 ; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED1 <br/> 0x89 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED2 <br/> 0x8a <br/><br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _1ADD <br/> 0x8b <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _1SUB <br/> 0x8c <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _2MUL <br/> 0x8d <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _2DIV <br/> 0x8e <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NEGATE <br/> 0x8f <br/> 1 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _ABS <br/> 0x90 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NOT <br/> 0x91 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _0NOTEQUAL <br/> 0x92 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _ADD <br/> 0x93 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _SUB <br/> 0x94 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _MUL <br/> 0x95 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _DIV <br/> 0x96 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _MOD <br/> 0x97 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _LSHIFT <br/> 0x98 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _RSHIFT <br/> 0x99 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _BOOLAND <br/> 0x9a <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _BOOLOR <br/> 0x9b <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NUMEQUAL <br/> 0x9c <br/> 2 ; 1<br />
| style="border:3px solid #808080; background-color:#8080ff;" | _NUMEQUALVERIFY <br/> 0x9d <br/> 2 ; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NUMNOTEQUAL <br/> 0x9e <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _LESSTHAN <br/> 0x9f <br/> 2 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _GREATERTHAN <br/> 0xa0 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _LESSTHANOREQUAL <br/> 0xa1 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _GREATERTHANOREQUAL <br/> 0xa2 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _MIN <br/> 0xa3 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _MAX <br/> 0xa4 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _WITHIN <br/> 0xa5 <br/> 3 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _RIPEMD160 <br/> 0xa6 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _SHA1 <br/> 0xa7 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _SHA256 <br/> 0xa8 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _HASH160 <br/> 0xa9 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _HASH256 <br/> 0xaa <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CODESEPARATOR <br/> 0xab <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CHECKSIG <br/> 0xac <br/> 2 @; 1<br />
| style="border:3px solid #808080; background-color:#a0d0ff;" | _CHECKSIGVERIFY <br/> 0xad <br/> 2 @; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CHECKMULTISIG <br/> 0xae <br/> 2n+2 @; 1<br />
| style="border:3px solid #808080; background-color:#a0d0ff;" | _CHECKMULTISIGVERIFY <br/> 0xaf <br/> 2n+2 @; 0/1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP1 <br/> 0xb0 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP2 <br/> 0xb1 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP3 <br/> 0xb2 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP4 <br/> 0xb3 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP5 <br/> 0xb4 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP6 <br/> 0xb5 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP7 <br/> 0xb6 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP8 <br/> 0xb7 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP9 <br/> 0xb8 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP10 <br/> 0xb9 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xba <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbe <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xca <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xce <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xda <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xde <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xea <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xeb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xec <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xed <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xee <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xef <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xfa <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _SMALLINTEGER <br/> 0xfb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEYS <br/> 0xfc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEYHASH <br/> 0xfd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEY <br/> 0xfe <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _INVALIDOPCODE <br/> 0xff <br/><br />
|}<br><br />
Except later pseudo-opcode changes, the definition of OP_NOP1 - OP_NOP10 and the change of the evaluation of OP_RETURN (did no invalidation previously) which both occured in bitcoin version 0.3.6 in July 2010 were the last changes regarding opcodes <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.2.0/bitcoin-0.2.0-linux.tar.gz file src/srcipt.cpp in bitcoin-0.2.0]</ref> <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.3.3/bitcoin-0.3.3-linux.tar.gz file src/srcipt.cpp in bitcoin-0.3.3]</ref> <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.3.6/bitcoin-0.3.6-linux.tar.gz file src/srcipt.cpp in bitcoin-0.3.6]</ref>.<br />
<br />
== Opcode descriptions ==<br />
It follows for each opcode less than decimal 185 (hexa 0xba) a description for its usage. The columns entitled ''nemonic'', ''decimal'' and ''Hex'' should be evident. The column ''input'' gives the needed items of the stack (and the alternate stack) and the column ''output'' indicates the resulting items on the stack (and the alternate stack). '''Stack-top is always the right most item.''' The naming of the entries in these two columns is chosen to reflect their interpretation. ''x'', ''x0'', ''x1'', ... means arbitrary or no interpretation, ''i0'', ''i1'' and ''i2'' a signed integer value, ''n'',''index'',''size'' and ''depth'' non-negative (unsigned) integer values, ''Boolean'' as either a true or false.<br><br />
<br />
Some of the more complicated opcodes are disabled out of concern that the client might have (and has) a bug in the current implementation due to the historically not as 2-complement interpretations of the byte vectors as numerical values (the most significant byte holds the sign of the byte vectors).<br />
<br />
=== Push data from instruction onto stack ===<br />
<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_FALSE, OP_0<br />
|0<br />
|0x00<br />
|Nothing<br />
|Empty string<br />
|A byte vector of length 0 is pushed onto the stack. (Thus, it is not a no-op!)<br />
|-<br />
|(no official nemonics)<br />
|1 - 75<br />
|0x01 - 0x4b<br />
|(operand)<br />
|x<br />
|The next <opcode>-many bytes are to be pushed onto the stack.<br />
|-<br />
|OP_PUSHDATA1<br />
|76<br />
|0x4c<br />
|(operands)<br />
|x<br />
|The next byte contains the number of bytes to be pushed onto the stack which follow this byte.<br />
|-<br />
|OP_PUSHDATA2<br />
|77<br />
|0x4d<br />
|(operands)<br />
|x<br />
|The next two bytes contain the number of bytes to be pushed onto the stack which follow theses 2 bytes.<br />
|-<br />
|OP_PUSHDATA4<br />
|78<br />
|0x4e<br />
|(operands)<br />
|x<br />
|The next four bytes contain the number of bytes to be pushed onto the stack which follow theses 4 bytes.<br />
|-<br />
|OP_1NEGATE<br />
|79<br />
|0x4f<br />
|Nothing<br />
| -1<br />
|The byte with value -1 is pushed onto the stack.<br />
|-<br />
|OP_1, OP_TRUE<br />
|81<br />
|0x51<br />
|Nothing<br />
|1<br />
|The byte with value 1 is pushed onto the stack.<br />
|-<br />
|OP_2 - OP_16<br />
|82 - 96<br />
|0x52 - 0x60<br />
|Nothing<br />
|2-16<br />
|The byte with value <opcode>-80 (thus, one of 2 - 16) is pushed onto the stack.<br />
|}<br />
<br />
=== Flow control ===<br />
<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_NOP<br />
|97<br />
|0x61<br />
|Nothing<br />
|Nothing<br />
|Does nothing.<br />
|-<br />
|OP_IF<br />
|99<br />
|0x63<br />
|Boolean<br />
|Nothing<br />
|If the top stack value is not 0, the statements are executed. The top stack value is removed. Lead in a logcial ''<value> then [statements] [else [statements]] endif'' expression<br />
|-<br />
|OP_NOTIF<br />
|100<br />
|0x64<br />
|Boolean<br />
|Nothing<br />
|If the top stack value is 0, the statements are executed. The top stack value is removed. Lead in a logcial ''<value> then [statements] [else [statements]] endif'' expression <br />
|-<br />
|OP_ELSE<br />
|103<br />
|0x67<br />
|Nothing<br />
|Nothing<br />
|If the preceeding OP_IF or OP_NOTIF or OP_ELSE was not executed then these statements are and if the preceding OP_IF or OP_NOTIF or OP_ELSE was executed then these statements are not. <br />
|-<br />
|OP_ENDIF<br />
|104<br />
|0x68<br />
|Nothing<br />
|Nothing<br />
|Ends a logcial ''If <value> then [statements] [else [statements]] '' expression<br />
|-<br />
|OP_VERIFY<br />
|105<br />
|0x69<br />
|Boolean<br />
|Nothing / False<br />
|If top stack value is not true then marks transaction as '''invalid''' . A value true is removed, but false is not.<br />
|-<br />
|OP_RETURN<br />
|106<br />
|0x6a<br />
|Nothing<br />
|Nothing<br />
|Marks transaction as '''invalid'''. <br />
|}<br />
<br />
===Stack item organization===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_TOALTSTACK<br />
|107<br />
|0x6b<br />
|x1 (alt)<br />
|(alt x1)<br />
|Puts the input onto the top of the alt stack. Removes it from the (main) stack.<br />
|-<br />
|OP_FROMALTSTACK<br />
|108<br />
|0x6c<br />
|(alt x1)<br />
|x1 (alt)<br />
|Puts the input onto the top of the (main) stack. Removes it from the alt stack.<br />
|-<br />
|OP_2DROP<br />
|109<br />
|0x6d<br />
|x2 x1<br />
|Nothing<br />
|Removes the top two stack items.<br />
|-<br />
|OP_2DUP<br />
|110<br />
|0x6e<br />
|x2 x1<br />
|x2 x1 x2 x1<br />
|Duplicates the top two stack items.<br />
|-<br />
|OP_3DUP<br />
|111<br />
|0x6f<br />
|x3 x2 x1<br />
|x3 x2 x1 x3 x2 x1<br />
|Duplicates the top three stack items.<br />
|-<br />
|OP_2OVER<br />
|112<br />
|0x70<br />
|x4 x3 x2 x1<br />
|x4 x3 x2 x1 x4 x3<br />
|Copies the pair of items two spaces back in the stack to the front.<br />
|-<br />
|OP_2ROT<br />
|113<br />
|0x71<br />
|x6 x5 x4 x3 x2 x1<br />
|x4 x3 x2 x1 x6 x5<br />
|The fifth and sixth items back are moved to the top of the stack. Twotimes left rotate.<br />
|-<br />
|OP_2SWAP<br />
|114<br />
|0x72<br />
|x4 x3 x2 x1<br />
|x2 x1 x4 x3<br />
|Swaps the top two pairs of stack items.<br />
|-<br />
|OP_IFDUP<br />
|115<br />
|0x73<br />
|x1<br />
|x1 / x1 x1<br />
|If the top stack value is not 0, duplicate it.<br />
|-<br />
|OP_DEPTH<br />
|116<br />
|0x74<br />
|Nothing<br />
|depth<br />
|Puts the number of stack items onto the stack as one little-endian coded byte-vector<br />
|-<br />
|OP_DROP<br />
|117<br />
|0x75<br />
|x1<br />
|Nothing<br />
|Removes the top stack item.<br />
|-<br />
|OP_DUP<br />
|118<br />
|0x76<br />
|x1<br />
|x1 x1<br />
|Duplicates the top stack item.<br />
|-<br />
|OP_NIP<br />
|119<br />
|0x77<br />
|x2 x1<br />
|x1<br />
|Removes the second-to-top stack item.<br />
|-<br />
|OP_OVER<br />
|120<br />
|0x78<br />
|x2 x1<br />
|x2 x1 x2<br />
|Copies the second-to-top stack item to the top.<br />
|-<br />
|OP_PICK<br />
|121<br />
|0x79<br />
|xn ... x2 x1 x0 <n><br />
|xn ... x2 x1 x0 xn<br />
|<n> is removed and the item ''n'' back in the stack is copied to the top.<br />
|-<br />
|OP_ROLL<br />
|122<br />
|0x7a<br />
|xn ... x2 x1 x0 <n><br />
|... x2 x1 x0 xn<br />
|<n> is removed and the item ''n'' back in the stack is moved to the top.<br />
|-<br />
|OP_ROT<br />
|123<br />
|0x7b<br />
|x3 x2 x1<br />
|x2 x1 x3<br />
|The top three items on the stack are rotated to the left.<br />
|-<br />
|OP_SWAP<br />
|124<br />
|0x7c<br />
|x2 x1<br />
|x1 x2<br />
|The top two items on the stack are swapped resp. rotated.<br />
|-<br />
|OP_TUCK<br />
|125<br />
|0x7d<br />
|x2 x1<br />
|x1 x2 x1<br />
|The item at the top of the stack is copied and inserted before the second-to-top item.<br />
|}<br />
<br />
=== Splice ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_CAT<br />
|126<br />
|0x7e<br />
|x2 x1<br />
|out<br />
|Appends stack-top item at second-to top item. Concatenates two strings resp. byte vectors. ''Currently disabled.''<br />
|-<br />
|OP_SUBSTR<br />
|127<br />
|0x7f<br />
|x3 index size<br />
|out<br />
|Returns the section started at position <index> and of length <size> of a string resp. byte vector. ''Currently disabled.''<br />
|-<br />
|OP_LEFT<br />
|128<br />
|0x80<br />
|x2 index<br />
|out<br />
|Keeps only characters left of the specified point in second-to top item. ''Currently disabled.''<br />
|-<br />
|OP_RIGHT<br />
|129<br />
|0x81<br />
|x2 index<br />
|out<br />
|Keeps only characters right of the specified point in second-to top item. ''Currently disabled.''<br />
|-<br />
|OP_SIZE<br />
|130<br />
|0x82<br />
|x1<br />
|x1 size<br />
|Returns the length of the input string resp. byte vector resp. top-stack item.<br />
|}<br />
<br />
=== Bitwise logic ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_INVERT<br />
|131<br />
|0x83<br />
|x1<br />
|x0<br />
|Flips all of the bits in the input. ''Currently disabled.''<br />
|-<br />
|OP_AND<br />
|132<br />
|0x84<br />
|x2 x1<br />
|x0<br />
|Boolean ''and'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_OR<br />
|133<br />
|0x85<br />
|x2 x1<br />
|x0<br />
|Boolean ''or'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_XOR<br />
|134<br />
|0x86<br />
|x2 x1<br />
|x0<br />
|Boolean ''exclusive or'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_EQUAL<br />
|135<br />
|0x87<br />
|x2 x1<br />
|Boolean<br />
|Returns 1 if the inputs are byte-wise equal, 0 otherwise.<br />
|-<br />
|OP_EQUALVERIFY<br />
|136<br />
|0x88<br />
|x2 x1<br />
|Nothing / false<br />
|Same as OP_EQUAL, but runs OP_VERIFY afterward.<br />
|}<br />
<br />
=== Arithmetic ===<br />
<br />
(In very early versions, the implemented arithmetic opcodes were limited to maximal 4 byte vectors.)<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_1ADD<br />
|139<br />
|0x8b<br />
|i1<br />
|i0<br />
|1 is added to the input.<br />
|-<br />
|OP_1SUB<br />
|140<br />
|0x8c<br />
|i1<br />
|i0<br />
|1 is subtracted from the input.<br />
|-<br />
|OP_2MUL<br />
|141<br />
|0x8d<br />
|i1<br />
|i0<br />
|The input is multiplied by 2. ''Currently disabled.''<br />
|-<br />
|OP_2DIV<br />
|142<br />
|0x8e<br />
|i1<br />
|i0<br />
|The input is divided by 2 (round down). ''Currently disabled.''<br />
|-<br />
|OP_NEGATE<br />
|143<br />
|0x8f<br />
|i1<br />
|i0<br />
|The sign of the input is flipped. Numerically the value is multiplied by -1<br />
|-<br />
|OP_ABS<br />
|144<br />
|0x90<br />
|i1<br />
|i0<br />
|The input is negative, its sign is flipped.<br />
|-<br />
|OP_NOT<br />
|145<br />
|0x91<br />
|i1<br />
|Boolean<br />
|If the input is 0 or 1, it is flipped. Otherwise the output will be 0. Test whether its value equals 0<br />
|-<br />
|OP_0NOTEQUAL<br />
|146<br />
|0x92<br />
|i1<br />
|Boolean<br />
|Returns 0 if the input is 0. 1 otherwise. Test whether its value is unequal 0<br />
|-<br />
|OP_ADD<br />
|147<br />
|0x93<br />
|i2 i1<br />
|i0<br />
|stack-top i1 is added to i2.<br />
|-<br />
|OP_SUB<br />
|148<br />
|0x94<br />
|i2 i1<br />
|i0<br />
|stack-top i1 is subtracted from i2.<br />
|-<br />
|OP_MUL<br />
|149<br />
|0x95<br />
|i2 i1<br />
|i0<br />
|i2 is multiplied with stack-top i1. ''Currently disabled.''<br />
|-<br />
|OP_DIV<br />
|150<br />
|0x96<br />
|i2 i1<br />
|i0<br />
|i2 is divided by stack-top i1 (divisor should be not 0). ''Currently disabled.''<br />
|-<br />
|OP_MOD<br />
|151<br />
|0x97<br />
|i2 i1<br />
|i0<br />
|Returns the remainder after dividing i2 by stack-top i1 (divisor should be not 0). ''Currently disabled.''<br />
|-<br />
|OP_LSHIFT<br />
|152<br />
|0x98<br />
|i2 i1<br />
|i0<br />
|Shifts i2 left by i1 bits, preserving sign of i2 (i1 >= 0). ''Currently disabled.''<br />
|-<br />
|OP_RSHIFT<br />
|153<br />
|0x99<br />
|i2 i1<br />
|i0<br />
|Shifts i2 right by i1 bits, preserving sign of i2 (i1 >= 0). ''Currently disabled.''<br />
|-<br />
|OP_BOOLAND<br />
|154<br />
|0x9a<br />
|i2 i1<br />
|Boolean<br />
|If both i2 and i1 are not 0, the output is 1. Otherwise 0.<br />
|-<br />
|OP_BOOLOR<br />
|155<br />
|0x9b<br />
|i2 i1<br />
|Boolean<br />
|If i2 or i1 is not 0, the output is 1. Otherwise 0.<br />
|-<br />
|OP_NUMEQUAL<br />
|156<br />
|0x9c<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 and i1 are numerically equal, 0 otherwise.<br />
|-<br />
|OP_NUMEQUALVERIFY<br />
|157<br />
|0x9d<br />
|i2 i1<br />
|Nothing / False<br />
|Same as OP_NUMEQUAL, but runs OP_VERIFY afterward.<br />
|-<br />
|OP_NUMNOTEQUAL<br />
|158<br />
|0x9e<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 and i1 are numerically not equal, 0 otherwise.<br />
|-<br />
|OP_LESSTHAN<br />
|159<br />
|0x9f<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is less than stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_GREATERTHAN<br />
|160<br />
|0xa0<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is greater than stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_LESSTHANOREQUAL<br />
|161<br />
|0xa1<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is less than or equal to stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_GREATERTHANOREQUAL<br />
|162<br />
|0xa2<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is greater than or equal to stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_MIN<br />
|163<br />
|0xa3<br />
|i2 i1<br />
|i2 / i1<br />
|Returns the smaller of i2 and i1.<br />
|-<br />
|OP_MAX<br />
|164<br />
|0xa4<br />
|i2 i1<br />
|i2 / i1<br />
|Returns the larger of i2 and i1.<br />
|-<br />
|OP_WITHIN<br />
|165<br />
|0xa5<br />
|i3 i2 i1<br />
|Boolean<br />
|Returns 1 if i3 >= i2 and i3 < i1, 0 otherwise. Thus if i2 > i1 returns always 0.<br />
|}<br />
<br />
=== Crypto ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_RIPEMD160<br />
|166<br />
|0xa6<br />
|x<br />
|hash20<br />
|The input is hashed using RIPEMD-160.<br />
|-<br />
|OP_SHA1<br />
|167<br />
|0xa7<br />
|x<br />
|hash20<br />
|The input is hashed using SHA-1.<br />
|-<br />
|OP_SHA256<br />
|168<br />
|0xa8<br />
|x<br />
|hash32<br />
|The input is hashed using SHA-256.<br />
|-<br />
|OP_HASH160<br />
|169<br />
|0xa9<br />
|x<br />
|hash20<br />
|The input is hashed twice: first with SHA-256 and then with RIPEMD-160.<br />
|-<br />
|OP_HASH256<br />
|170<br />
|0xaa<br />
|x<br />
|hash32<br />
|The input is hashed two times with SHA-256.<br />
|-<br />
|OP_CODESEPARATOR<br />
|171<br />
|0xab<br />
|Nothing<br />
|Nothing<br />
|All of the signature checking opcodes will only match signatures to the data after the most recently-executed OP_CODESEPARATOR.<br />
|-<br />
|[[OP_CHECKSIG]]<br />
|172<br />
|0xac<br />
|sig pubkey<br />
|Boolean<br />
|The entire transaction's outputs, inputs, and script (from the most recently-executed OP_CODESEPARATOR to the end) are hashed. The signature used by OP_CHECKSIG must be a valid signature for a further, extern specified hash and the given public key. If it is, 1 is returned, 0 otherwise.<br />
|-<br />
|OP_CHECKSIGVERIFY<br />
|173<br />
|0xad<br />
|sig pubkey<br />
|Nothing / False<br />
|Same as OP_CHECKSIG, but OP_VERIFY is executed afterward.<br />
|-<br />
|OP_CHECKMULTISIG<br />
|174<br />
|0xae<br />
|sig1 sig2 ... <number of signatures> pub1 pub2 <number of public keys><br />
|Boolean<br />
|For each signature and public key pair, OP_CHECKSIG is executed. If more public keys than signatures are listed, some key/sig pairs can fail. All signatures need to match a public key. If all signatures are valid, 1 is returned, 0 otherwise. Due to a bug, one extra unused value is removed from the stack.<br />
|-<br />
|OP_CHECKMULTISIGVERIFY<br />
|175<br />
|0xaf<br />
|sig1 sig2 ... <number of signatures> pub1 pub2 ... <number of public keys><br />
|Nothing / False<br />
|Same as OP_CHECKMULTISIG, but OP_VERIFY is executed afterward.<br />
|}<br />
<br />
=== Expansion opcodes ===<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_NOP1-OP_NOP10<br />
|176-185<br />
|0xb0-0xb9<br />
|The opcode has no effect.<br />
|}<br />
<br />
=== Version opcodes ===<br />
Version opcodes are disabled since bitcoin 0.2.0 and should not be used (maybe reassigned in the future).<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_VER<br />
|98<br />
|0x62<br />
|Script evalution is triggered invalid (Formerly pushed the bitcoin-serialize version onto stack).<br />
|-<br />
|OP_VERIF<br />
|101<br />
|0x65<br />
|Script evalution is triggered invalid (Formerly top stack item was popped and =< compared to present version)<br />
|-<br />
|OP_VERNOTIF<br />
|102<br />
|0x66<br />
|Script evalution is triggered invalid (Formerly top stack item was popped and > compared to present version)<br />
|}<br />
<br />
=== Reserved opcodes ===<br />
Each opcode not assigned (currently also every opcode value > 185) is also reserved. Using any unassigned opcode triggers the script evaluation to be invalid.<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_RESERVED<br />
|80<br />
|0x50<br />
|Script evalution is triggered invalid-<br />
|-<br />
|OP_RESERVED1<br />
|137<br />
|0x89<br />
|Script evalution is triggered invalid.<br />
|-<br />
|OP_RESERVED2<br />
|138<br />
|0x8a<br />
|Script evalution is triggered invalid.<br />
|}<br />
<br />
===Pseudo-opcodes===<br />
These nemonics are used internally for assisting with transaction matching. They are invalid if used in actual scripts.<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_PUBKEYHASH<br />
|253<br />
|0xfd<br />
|Represents a public key hashed with OP_HASH160.<br />
|-<br />
|OP_PUBKEY<br />
|254<br />
|0xfe<br />
|Represents a public key compatible with OP_CHECKSIG.<br />
|-<br />
|OP_INVALIDOPCODE<br />
|255<br />
|0xff<br />
|Matches any opcode that is not yet assigned.<br />
|}<br />
<br />
==Scripts in bitcoin transactions==<br />
It follows a list of important (most occuring) scripts to see opcodes "at work". Keep in mind that all constants actually use the data-pushing instructions above. At start of a (transaction input) script evaluation, the stack is always empty. <br />
<br />
===Standard transaction to bitcoin address===<br />
<br />
scriptPubKey: OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG<br />
scriptSig: <sig> <pubKey><br />
<br />
To demonstrate how scripts look on the wire, here is a raw scriptPubKey:<br />
<pre> 76 A9 14<br />
OP_DUP OP_HASH160 Bytes to push<br />
<br />
89 AB CD EF AB BA AB BA AB BA AB BA AB BA AB BA AB BA AB BA 88 AC<br />
Data to push OP_EQUALVERIFY OP_CHECKSIG</pre><br />
<br />
Note: scriptSig is in the input of the spending transaction and scriptPubKey is in the output of the previously storing transaction, i.e. its "available bitcoins".<br />
<br />
Here is how each instruction is processed:<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
| <sig> <pubKey> OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| scriptSig and scriptPubKey are combined.<br />
|-<br />
|<sig> <pubKey><br />
| OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| Constants are added to the stack.<br />
|-<br />
|<sig> <pubKey> <pubKey><br />
| OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| Top stack item is duplicated.<br />
|-<br />
|<sig> <pubKey> <pubHashA><br />
|<pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG<br />
| Top stack item is hashed.<br />
|-<br />
|<sig> <pubKey> <pubHashA> <pubKeyHash><br />
|OP_EQUALVERIFY OP_CHECKSIG<br />
| Constant added.<br />
|-<br />
|<sig> <pubKey><br />
|OP_CHECKSIG<br />
| Equality is checked between the top two stack items.<br />
|-<br />
|true<br />
|Empty.<br />
|Signature is checked for top two stack items.<br />
|}<br />
<br />
===Transaction to IP address (and generation transaction)===<br />
<br />
scriptPubKey: <pubKey> OP_CHECKSIG<br />
scriptSig: <sig><br />
<br />
Checking process:<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
|<sig> <pubKey> OP_CHECKSIG<br />
|scriptSig and scriptPubKey are combined.<br />
|-<br />
|<sig> <pubKey><br />
| OP_CHECKSIG<br />
|Constants are added to the stack.<br />
|-<br />
|true<br />
|Empty.<br />
|Signature is checked for top two stack items.<br />
|}<br />
<br />
In the case of a '''coin generation transaction''' (the first transaction of each block), there is no scriptSig, resp. its code ("coinbase") is completly ignored for the transaction. Only the scriptPubKey is used.<br />
<br />
===Transaction with a message===<br />
<br />
It's possible to add arbitrary data to any transaction by just adding some data along with OP_DROP. <br />
scriptPubKey: <message> OP_DROP <pubKey> OP_CHECKSIG<br />
scriptSig: <sig><br />
<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
|<sig> <message> OP_DROP <pubKey> OP_CHECKSIG<br />
|<br />
|-<br />
|<sig><br />
|<message> OP_DROP <pubKey> OP_CHECKSIG<br />
|scriptSig added to the stack.<br />
|-<br />
|<sig> <message><br />
|OP_DROP <pubKey> OP_CHECKSIG<br />
|The message has been put.<br />
|-<br />
|<sig><br />
|<pubKey> OP_CHECKSIG<br />
|Top stack item has been removed.<br />
|-<br />
|<sig> <pubKey><br />
|OP_CHECKSIG<br />
|Checking signature against the public key.<br />
|-<br />
|true<br />
|Empty.<br />
|Stack holds the value of signature check now.<br />
|}<br />
<br />
===Examples of non standard transaction on Testnet===<br />
<br />
These two links below show a non standard transaction. It just prepends the hex of "bob" and the operation OP_DROP<br />
which just removes it. As you can see they can be spent as normal.<br />
<br />
Input non-std transaction:<br />
http://blockexplorer.com/testnet/t/6ttfeb55B1<br />
<br />
Spent by:<br />
http://blockexplorer.com/testnet/t/AFdRB1CHS3<br />
<br />
==Script validation==<br />
A script evaluation is considered invalid, if any of these conditions meets:<br><br />
<ul><br />
<li>the total size of the script exceeds (currently) 10000 bytes<br />
<li>there are more than (currently) 201 opcodes of opcode value > 0x60 in the script<br />
<li>each instruction is (currently) limited to maximal 520 bytes. This effects only the opcodes OP_PUSHDATA2 and OP_PUSHDATA4<br />
<li>the executed opcode of the script has insufficient input (from stack, from script or from anywhere)<br />
<li>the opcode is not defined (for execution) - indicated by white or light gray background color in the table<br />
<li>the opcode is disabled (currently 15 opcodes) - indicated by white font color in the opcode overview matrix<br />
<li>stack overflow occurs during execution of the opcode (currently the number of items on the stack and on the alternate stack is limited to 1000)<br />
<li>the opcodes OP_VERIF and OP_NOTVERIF invalidate a script which contains this opcode (even if this opcode is not executed!)<br />
<li>the opcodes OP_ELSE or OP_ENDIF has no matching OP_IF<br><br />
<li>the script execution has been finished but there is (at least) an unmatched OP_IF<br><br />
<li>the opcodes OP_VERIFY, OP_EQUALVERIFY, OP_NUMEQUALVERIFY, OP_CHECKSIGVERIFY and OP_CHECKMULTISIGVERIFY invalidate the script if the stack-top item is false<br />
<li>the execution of OP_RETURN<br />
<!--li>alt stack overflow occurs (only possible during execution of OP_TOALTSTACK)--><br />
<li>the numerical value of the top-stack item is negative or greater than the number of items - 2 on the stack if OP_PICK or OP_ROLL shall be executed<br />
<li>an item used as public key or signature for each of the opcodes OP_CHECKSIG, OP_CHECKSIGVERIFY, OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY can be neither a public key or signature (for the given hash)<br />
<li>the number of signature items or the number of public key items on the stack is negative for OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY<br />
<li>there or more signatures items than public key items on the stack for OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY<br />
<li>there are (currently) more than 20 public key items on the stack for OP_CHECKMULTISIG or CHECKMULTISIGVERIFY<br />
<li>the sum of opcodes > 0x60 and the number of public keys in all executed OP_CHECKMULTISIG or CHECKMULTISIGVERIFY exceeds (currently) 201<br />
<li>the script execution has been finished and the stack is empty or the top-stack item is false (numerical value 0)<br />
</ul><br />
else the script evaluation is considered to be valid.<ref>[http://sourceforge.net/projects/bitcoin/files/Bitcoin/bitcoin-0.7.1/bitcoin-0.7.1-linux.tar.gz file src/src/script.cpp in bitcoin-0.7.1]</ref><br />
'''If invalidation of a script is triggered then the script is immediately finished.''' These arbitrary looking limitations of 10000, 201, 520, 1000 and 20 might be increased in the future -- they serve to prevent strong slow down of the evaluation of a script while not restricting its practical usage really.<br />
<br />
==Withdrawn and drafted opcodes==<br />
<br />
<ul><br />
<li> byte value 0x89 OP_NOTEQUAL defined in pre-0.1.0 bitcoin versions. Since 0.1.0 removed because of security concerns. <br />
<li> byte value 0xb1 [[BIP 0012 | OP_EVAL]] withdraw - poll was triggered but insufficient support. <br />
<li> byte value 0xb2 [[BIP 0017 | OP_CHECKHASHVERIFY]] withdraw - poll was triggered but insufficient support.<br />
</ul><br />
<br />
==See Also==<br />
* [[Transactions]]<br />
* [[Contracts]]<br />
<br />
==References==<br />
<references/><br />
<ul><br />
<li>[http://www.zorinaq.com/pub/bitcoin-0.1.0.tgz file src/script.cpp in bitcoin-0.1.0]</li><br />
</ul><br />
[[Category:Technical]]<br />
[[Category:Vocabulary]]</div>
Smtp
https://en.bitcoin.it/w/index.php?title=Script&diff=34906
Script
2013-01-11T16:09:32Z
<p>Smtp: /* Opcode descriptions */</p>
<hr />
<div>Bitcoin uses a scripting system for [[transactions]]. [[Wikipedia:FORTH|Forth]]-like, Script is simple, stack-based, and processed from left to right. It is purposefully not Turing-complete, with no loops.<br />
<br />
A script is essentially a list of instructions recorded with each transaction that describe how the next person wanting to spend the Bitcoins being transferred can gain access to them.<br />
<br />
Scripts are big-endian and their sequences of bytes is interpreted as a sequence of opcodes with operands. Only opcodes with byte values less than 0x4f have additional operands.<br />
<br />
== Scripts and Bitcoin transactions ==<br />
The script for a typical Bitcoin transfer to destination Bitcoin address D simply encumbers future spending of the bitcoins with two things: the spender must provide<br />
# a public key that, when hashed, yields destination address D embedded in the script, and<br />
# a signature to show evidence of the private key corresponding to the public key just provided.<br />
<br />
Scripting provides the flexibility to change the parameters of what's needed to spend transferred Bitcoins. For example, the scripting system could be used to require two private keys, or a combination of several, or even no keys at all.<br />
<br />
A transaction is valid if nothing in the combined script triggers failure and the top stack item exists and is true (non-zero). The party who originally ''stored'' the Bitcoins now being spent, dictates the script operations that will occur ''last'' in order to release them for use in another transaction. The party wanting to spend them must provide the input(s) to the previously recorded script that results in those operations occurring last leaving behind true (non-zero) on the stack.<br><br />
Only the very first transaction in each bitcoin block has no input script (the entry there is called "coinbase"), because the Bitcoins created with the block are created from hot air and not released by a previous recorded script.<br />
<br />
== Stack ==<br />
<br />
The stacks hold byte vectors (there is the (main) stack and an alternative stack). Byte vectors are interpreted as little-endian variable-length integers with the most significant bit determining the sign of the integer. Thus 0x81 represents -1. 0x80 is another representation of zero (so called negative 0). Byte vectors are interpreted as Booleans where False is represented by any representation of zero, and True is represented by any representation of non-zero.<br />
<br />
== Opcode overview ==<br />
<br />
For each opcode is given: its nemonic without the leading OP_, its hexadecimal byte value, the number of stack items needed (poped) during execution, a semicolon and the number of stack items which has been pushed (after execution). A * after the needed stack items indicates that further bytes from the script following the current opcode are needed. A # indicates that items on the alternative stack are poped/pushed. A @ indicates that further (global) data from the transaction is needed. A / indicates alternatives of a value. <br/><br />
Different colors indicate different semantic execution groups of opcodes:<br />
{| style="background:none; font-size:100%; padding:0; border-collapse:collapse; text-align:center; line-height:2em;" border="0" align="center" <br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | copy a fixed number of bytes but at most 75 onto stack<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | copy bytes onto stack which number is given by a 1, 2 or 4 byte value.<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | copy 1 specific byte onto stack<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | undefined opcode<br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | a pseudo-opcode, unassigned for scripts<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | NOP or opcode is part of a IF-flow-control construction<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00ff00;" | (stack conditionally) invalidation of the script this opcode is part of<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | stack item is moved between main stack and alternate stack<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | stack item(s) is/are moved, copied or deleted<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0;" | byte vectors are appended or divided or their size is determined<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff;" | byte vectors are interpreted bit-position-independently<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | byte vectors are interpreted and processed as signed integers<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | a hash value is computed or a signature checked<br />
|}<br />
<p><br />
===Opcode byte-matrix===<br />
The opcode value 0x00 with nemonic OP_FALSE is also named OP_0 and the opcode value 0x51 with nemonic OP_1 as also named OP_TRUE.<br />
{| style="background:none; font-size:100%; padding:0; border-collapse:collapse; text-align:center; line-height:2em;" border="0" align="center" <br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" |_FALSE<br/> 0x00 <br/> 0 ; 1(0) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x01<br/> 0 *; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x02<br/> 0 *; 1(2)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x03<br/> 0 *; 1(3)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x04<br/> 0 *; 1(4)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x04<br/> 0 *; 1(5)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x06<br/> 0 *; 1(6)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x07<br/> 0 *; 1(7)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x08<br/> 0 *; 1(8)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x09<br/> 0 *; 1(9)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0a<br/> 0 *; 1(10)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0b<br/> 0 *; 1(11)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0c<br/> 0 *; 1(12)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0d<br/> 0 *; 1(13)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0e<br/> 0 *; 1(14)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0f<br/> 0 *; 1(15)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x10 <br/> 0 *; 1(16) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x11 <br/> 0 *; 1(17)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x12 <br/> 0 *; 1(18)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x13 <br/> 0 *; 1(19)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x14 <br/> 0 *; 1(20)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x15 <br/> 0 *; 1(21)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x16 <br/> 0 *; 1(22)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x17 <br/> 0 *; 1(23)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x18 <br/> 0 *; 1(24)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x19 <br/> 0 *; 1(25)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1a <br/> 0 *; 1(26)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1b <br/> 0 *; 1(27)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1c <br/> 0 *; 1(28)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1d <br/> 0 *; 1(29)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1e <br/> 0 *; 1(30)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1f <br/> 0 *; 1(31)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x20 <br/> 0 *; 1(32) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x21 <br/> 0 *; 1(33)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x22 <br/> 0 *; 1(34)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x23 <br/> 0 *; 1(35)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x24 <br/> 0 *; 1(36)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x25 <br/> 0 *; 1(37)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x26 <br/> 0 *; 1(38)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x27 <br/> 0 *; 1(39)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x28 <br/> 0 *; 1(40)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x29 <br/> 0 *; 1(41)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2a <br/> 0 *; 1(42)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2b <br/> 0 *; 1(43)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2c <br/> 0 *; 1(44)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2d <br/> 0 *; 1(45)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2e <br/> 0 *; 1(46)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2f <br/> 0 *; 1(47)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x30 <br/> 0 *; 1(48) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x31 <br/> 0 *; 1(49)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x32 <br/> 0 *; 1(50)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x33 <br/> 0 *; 1(51)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x34 <br/> 0 *; 1(52)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x35 <br/> 0 *; 1(53)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x36 <br/> 0 *; 1(54)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x37 <br/> 0 *; 1(55)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x38 <br/> 0 *; 1(56)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x39 <br/> 0 *; 1(57)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3a <br/> 0 *; 1(58)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3b <br/> 0 *; 1(59)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3c <br/> 0 *; 1(60)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3d <br/> 0 *; 1(61)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3e <br/> 0 *; 1(62)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3f <br/> 0 *; 1(63)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x40 <br/> 0 *; 1(64) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x41 <br/> 0 *; 1(65)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x42 <br/> 0 *; 1(66)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x43 <br/> 0 *; 1(67)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x44 <br/> 0 *; 1(68)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x45 <br/> 0 *; 1(69)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x46 <br/> 0 *; 1(70)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x47 <br/> 0 *; 1(71)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x48 <br/> 0 *; 1(72)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x49 <br/> 0 *; 1(73)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x4a <br/> 0 *; 1(74)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x4b <br/> 0 *; 1(75)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA1 <br/> 0x4c <br/> 0 *; 1(0 - 255)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA2 <br/> 0x4d <br/> 0 *; 1(0 - 2^16-1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA4 <br/> 0x4e <br/> 0 *; 1(0 - 2^32-1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _1NEGATE <br/> 0x4f <br/> 0 ; 1(1)<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED <br/> 0x50 <br/> <br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _1 <br/> 0x51 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _2 <br/> 0x52 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _3 <br/> 0x53 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _4 <br/> 0x54 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _5 <br/> 0x55 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _6 <br/> 0x56 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _7 <br/> 0x57 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _8 <br/> 0x58 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _9 <br/> 0x59 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _10 <br/> 0x5a <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _11 <br/> 0x5b <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _12 <br/> 0x5c <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _13 <br/> 0x5d <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _14 <br/> 0x5e <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _15 <br/> 0x5f <br/> 0 ; 1(1)<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _16 <br/> 0x60 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP <br/> 0x61 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VER <br/> 0x62 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _IF <br/> 0x63 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOTIF <br/> 0x64 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VERIF <br/> 0x65 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VERNOTIF <br/> 0x66 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _ELSE <br/> 0x67 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _ENDIF <br/> 0x68 <br/> 0 ; 0<br />
| style="border:3px solid #808080; background-color:#00ff00;" | _VERIFY <br/> 0x69 <br/> 1 ; 0/1<br />
| style="border:3px solid #808080; background-color:#00ff00;" | _RETURN <br/> 0x6a <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | _TOALTSTACK <br/> 0x6b <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | _FROMALTSTACK <br/> 0x6c <br/> 0 #; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2DROP <br/> 0x6d <br/> 2 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2DUP <br/> 0x6e <br/> 2 ; 4<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _3DUP <br/> 0x6f <br/> 3 ; 6<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2OVER <br/> 0x70 <br/> 4 ; 6<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2ROT <br/> 0x71 <br/> 6 ; 6<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2SWAP <br/> 0x72 <br/> 4 ; 4<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _IFDUP <br/> 0x73 <br/> 1 ; 1/2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DEPTH <br/> 0x74 <br/> 0 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DROP <br/> 0x75 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DUP <br/> 0x76 <br/> 1 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _NIP <br/> 0x77 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _OVER <br/> 0x78 <br/> 2 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _PICK <br/> 0x79 <br/> 1+n+1 ; n+2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _ROLL <br/> 0x7a <br/> 1+n+1 ; n+1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _ROT <br/> 0x7b <br/> 3 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _SWAP <br/> 0x7c <br/> 2 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _TUCK <br/> 0x7d <br/> 2 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _CAT <br/> 0x7e <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _SUBSTR <br/> 0x7f <br/> 3 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _LEFT <br/> 0x80 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _RIGHT <br/> 0x81 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0;" | _SIZE <br/> 0x82 <br/> 1 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _INVERT <br/> 0x83 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _AND <br/> 0x84 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _OR <br/> 0x85 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _XOR <br/> 0x86 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff;" | _EQUAL <br/> 0x87 <br/> 2 ; 1<br />
| style="border:3px solid #808080; background-color:#c080ff;" | _EQUALVERIFY <br/> 0x88 <br/> 2 ; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED1 <br/> 0x89 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED2 <br/> 0x8a <br/><br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _1ADD <br/> 0x8b <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _1SUB <br/> 0x8c <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _2MUL <br/> 0x8d <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _2DIV <br/> 0x8e <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NEGATE <br/> 0x8f <br/> 1 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _ABS <br/> 0x90 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NOT <br/> 0x91 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _0NOTEQUAL <br/> 0x92 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _ADD <br/> 0x93 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _SUB <br/> 0x94 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _MUL <br/> 0x95 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _DIV <br/> 0x96 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _MOD <br/> 0x97 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _LSHIFT <br/> 0x98 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _RSHIFT <br/> 0x99 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _BOOLAND <br/> 0x9a <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _BOOLOR <br/> 0x9b <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NUMEQUAL <br/> 0x9c <br/> 2 ; 1<br />
| style="border:3px solid #808080; background-color:#8080ff;" | _NUMEQUALVERIFY <br/> 0x9d <br/> 2 ; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NUMNOTEQUAL <br/> 0x9e <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _LESSTHAN <br/> 0x9f <br/> 2 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _GREATERTHAN <br/> 0xa0 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _LESSTHANOREQUAL <br/> 0xa1 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _GREATERTHANOREQUAL <br/> 0xa2 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _MIN <br/> 0xa3 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _MAX <br/> 0xa4 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _WITHIN <br/> 0xa5 <br/> 3 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _RIPEMD160 <br/> 0xa6 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _SHA1 <br/> 0xa7 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _SHA256 <br/> 0xa8 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _HASH160 <br/> 0xa9 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _HASH256 <br/> 0xaa <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CODESEPARATOR <br/> 0xab <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CHECKSIG <br/> 0xac <br/> 2 @; 1<br />
| style="border:3px solid #808080; background-color:#a0d0ff;" | _CHECKSIGVERIFY <br/> 0xad <br/> 2 @; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CHECKMULTISIG <br/> 0xae <br/> 2n+2 @; 1<br />
| style="border:3px solid #808080; background-color:#a0d0ff;" | _CHECKMULTISIGVERIFY <br/> 0xaf <br/> 2n+2 @; 0/1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP1 <br/> 0xb0 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP2 <br/> 0xb1 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP3 <br/> 0xb2 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP4 <br/> 0xb3 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP5 <br/> 0xb4 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP6 <br/> 0xb5 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP7 <br/> 0xb6 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP8 <br/> 0xb7 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP9 <br/> 0xb8 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP10 <br/> 0xb9 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xba <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbe <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xca <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xce <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xda <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xde <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xea <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xeb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xec <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xed <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xee <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xef <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xfa <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _SMALLINTEGER <br/> 0xfb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEYS <br/> 0xfc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEYHASH <br/> 0xfd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEY <br/> 0xfe <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _INVALIDOPCODE <br/> 0xff <br/><br />
|}<br><br />
Except later pseudo-opcode changes, the definition of OP_NOP1 - OP_NOP10 and the change of the evaluation of OP_RETURN (did no invalidation previously) which both occured in bitcoin version 0.3.6 in July 2010 were the last changes regarding opcodes <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.2.0/bitcoin-0.2.0-linux.tar.gz file src/srcipt.cpp in bitcoin-0.2.0]</ref> <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.3.3/bitcoin-0.3.3-linux.tar.gz file src/srcipt.cpp in bitcoin-0.3.3]</ref> <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.3.6/bitcoin-0.3.6-linux.tar.gz file src/srcipt.cpp in bitcoin-0.3.6]</ref>.<br />
<br />
== Opcode descriptions ==<br />
It follows for each opcode less than decimal 185 (hexa 0xba) a description for its usage. The columns entitled ''nemonic'', ''decimal'' and ''Hex'' should be evident. The column ''input'' gives the needed items of the stack (and the alternate stack) and the column ''output'' indicates the resulting items on the stack (and the alternate stack). '''Stack-top is always the right most item.''' The naming of the entries in these two columns is chosen to reflect their interpretation. ''x'', ''x0'', ''x1'', ... means arbitrary or no interpretation, ''i0'', ''i1'' and ''i2'' a signed integer value, ''n'',''index'',''size'' and ''depth'' non-negative (unsigned) integer values, ''Boolean'' as either a true or false.<br><br />
<br />
Some of the more complicated opcodes are disabled out of concern that the client might have (and has) a bug in the current implementation due to the historically not as 2-complement interpretations of the byte vectors as numerical values (the most significant byte holds the sign of the byte vectors).<br />
<br />
=== Push data from instruction onto stack ===<br />
<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_FALSE, OP_0<br />
|0<br />
|0x00<br />
|Nothing<br />
|Empty string<br />
|A byte vector of length 0 is pushed onto the stack. (Thus, it is not a no-op!)<br />
|-<br />
|(no official nemonics)<br />
|1 - 75<br />
|0x01 - 0x4b<br />
|(operand)<br />
|x<br />
|The next <opcode>-many bytes are to be pushed onto the stack.<br />
|-<br />
|OP_PUSHDATA1<br />
|76<br />
|0x4c<br />
|(operands)<br />
|x<br />
|The next byte contains the number of bytes to be pushed onto the stack which follow this byte.<br />
|-<br />
|OP_PUSHDATA2<br />
|77<br />
|0x4d<br />
|(operands)<br />
|x<br />
|The next two bytes contain the number of bytes to be pushed onto the stack which follow theses 2 bytes.<br />
|-<br />
|OP_PUSHDATA4<br />
|78<br />
|0x4e<br />
|(operands)<br />
|x<br />
|The next four bytes contain the number of bytes to be pushed onto the stack which follow theses 4 bytes.<br />
|-<br />
|OP_1NEGATE<br />
|79<br />
|0x4f<br />
|Nothing<br />
| -1<br />
|The byte with value -1 is pushed onto the stack.<br />
|-<br />
|OP_1, OP_TRUE<br />
|81<br />
|0x51<br />
|Nothing<br />
|1<br />
|The byte with value 1 is pushed onto the stack.<br />
|-<br />
|OP_2 - OP_16<br />
|82 - 96<br />
|0x52 - 0x60<br />
|Nothing<br />
|2-16<br />
|The byte with value <opcode>-80 (thus, one of 2 - 16) is pushed onto the stack.<br />
|}<br />
<br />
=== Flow control ===<br />
<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_NOP<br />
|97<br />
|0x61<br />
|Nothing<br />
|Nothing<br />
|Does nothing.<br />
|-<br />
|OP_IF<br />
|99<br />
|0x63<br />
|Boolean<br />
|Nothing<br />
|If the top stack value is not 0, the statements are executed. The top stack value is removed. Lead in a logcial ''<value> then [statements] [else [statements]] endif'' expression<br />
|-<br />
|OP_NOTIF<br />
|100<br />
|0x64<br />
|Boolean<br />
|Nothing<br />
|If the top stack value is 0, the statements are executed. The top stack value is removed. Lead in a logcial ''<value> then [statements] [else [statements]] endif'' expression <br />
|-<br />
|OP_ELSE<br />
|103<br />
|0x67<br />
|Nothing<br />
|Nothing<br />
|If the preceeding OP_IF or OP_NOTIF or OP_ELSE was not executed then these statements are and if the preceding OP_IF or OP_NOTIF or OP_ELSE was executed then these statements are not. <br />
|-<br />
|OP_ENDIF<br />
|104<br />
|0x68<br />
|Nothing<br />
|Nothing<br />
|Ends a logcial ''If <value> then [statements] [else [statements]] '' expression<br />
|-<br />
|OP_VERIFY<br />
|105<br />
|0x69<br />
|Boolean<br />
|Nothing / False<br />
|If top stack value is not true then marks transaction as '''invalid''' . A value true is removed, but false is not.<br />
|-<br />
|OP_RETURN<br />
|106<br />
|0x6a<br />
|Nothing<br />
|Nothing<br />
|Marks transaction as '''invalid'''. <br />
|}<br />
<br />
===Stack item organization===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_TOALTSTACK<br />
|107<br />
|0x6b<br />
|x1 (alt)<br />
|(alt x1)<br />
|Puts the input onto the top of the alt stack. Removes it from the (main) stack.<br />
|-<br />
|OP_FROMALTSTACK<br />
|108<br />
|0x6c<br />
|(alt x1)<br />
|x1 (alt)<br />
|Puts the input onto the top of the (main) stack. Removes it from the alt stack.<br />
|-<br />
|OP_2DROP<br />
|109<br />
|0x6d<br />
|x2 x1<br />
|Nothing<br />
|Removes the top two stack items.<br />
|-<br />
|OP_2DUP<br />
|110<br />
|0x6e<br />
|x2 x1<br />
|x2 x1 x2 x1<br />
|Duplicates the top two stack items.<br />
|-<br />
|OP_3DUP<br />
|111<br />
|0x6f<br />
|x3 x2 x1<br />
|x3 x2 x1 x3 x2 x1<br />
|Duplicates the top three stack items.<br />
|-<br />
|OP_2OVER<br />
|112<br />
|0x70<br />
|x4 x3 x2 x1<br />
|x4 x3 x2 x1 x4 x3<br />
|Copies the pair of items two spaces back in the stack to the front.<br />
|-<br />
|OP_2ROT<br />
|113<br />
|0x71<br />
|x6 x5 x4 x3 x2 x1<br />
|x4 x3 x2 x1 x6 x5<br />
|The fifth and sixth items back are moved to the top of the stack. Twotimes left rotate.<br />
|-<br />
|OP_2SWAP<br />
|114<br />
|0x72<br />
|x4 x3 x2 x1<br />
|x2 x1 x4 x3<br />
|Swaps the top two pairs of stack items.<br />
|-<br />
|OP_IFDUP<br />
|115<br />
|0x73<br />
|x1<br />
|x1 / x1 x1<br />
|If the top stack value is not 0, duplicate it.<br />
|-<br />
|OP_DEPTH<br />
|116<br />
|0x74<br />
|Nothing<br />
|depth<br />
|Puts the number of stack items onto the stack as one little-endian coded byte-vector<br />
|-<br />
|OP_DROP<br />
|117<br />
|0x75<br />
|x1<br />
|Nothing<br />
|Removes the top stack item.<br />
|-<br />
|OP_DUP<br />
|118<br />
|0x76<br />
|x1<br />
|x1 x1<br />
|Duplicates the top stack item.<br />
|-<br />
|OP_NIP<br />
|119<br />
|0x77<br />
|x2 x1<br />
|x1<br />
|Removes the second-to-top stack item.<br />
|-<br />
|OP_OVER<br />
|120<br />
|0x78<br />
|x2 x1<br />
|x2 x1 x2<br />
|Copies the second-to-top stack item to the top.<br />
|-<br />
|OP_PICK<br />
|121<br />
|0x79<br />
|xn ... x2 x1 x0 <n><br />
|xn ... x2 x1 x0 xn<br />
|<n> is removed and the item ''n'' back in the stack is copied to the top.<br />
|-<br />
|OP_ROLL<br />
|122<br />
|0x7a<br />
|xn ... x2 x1 x0 <n><br />
|... x2 x1 x0 xn<br />
|<n> is removed and the item ''n'' back in the stack is moved to the top.<br />
|-<br />
|OP_ROT<br />
|123<br />
|0x7b<br />
|x3 x2 x1<br />
|x2 x1 x3<br />
|The top three items on the stack are rotated to the left.<br />
|-<br />
|OP_SWAP<br />
|124<br />
|0x7c<br />
|x2 x1<br />
|x1 x2<br />
|The top two items on the stack are swapped resp. rotated.<br />
|-<br />
|OP_TUCK<br />
|125<br />
|0x7d<br />
|x2 x1<br />
|x1 x2 x1<br />
|The item at the top of the stack is copied and inserted before the second-to-top item.<br />
|}<br />
<br />
=== Splice ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_CAT<br />
|126<br />
|0x7e<br />
|x2 x1<br />
|out<br />
|Appends stack-top item at second-to top item. Concatenates two strings resp. byte vectors. ''Currently disabled.''<br />
|-<br />
|OP_SUBSTR<br />
|127<br />
|0x7f<br />
|x3 index size<br />
|out<br />
|Returns the section started at position <index> and of length <size> of a string resp. byte vector. ''Currently disabled.''<br />
|-<br />
|OP_LEFT<br />
|128<br />
|0x80<br />
|x2 index<br />
|out<br />
|Keeps only characters left of the specified point in second-to top item. ''Currently disabled.''<br />
|-<br />
|OP_RIGHT<br />
|129<br />
|0x81<br />
|x2 index<br />
|out<br />
|Keeps only characters right of the specified point in second-to top item. ''Currently disabled.''<br />
|-<br />
|OP_SIZE<br />
|130<br />
|0x82<br />
|x1<br />
|x1 size<br />
|Returns the length of the input string resp. byte vector resp. top-stack item.<br />
|}<br />
<br />
=== Bitwise logic ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_INVERT<br />
|131<br />
|0x83<br />
|x1<br />
|x0<br />
|Flips all of the bits in the input. ''Currently disabled.''<br />
|-<br />
|OP_AND<br />
|132<br />
|0x84<br />
|x2 x1<br />
|x0<br />
|Boolean ''and'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_OR<br />
|133<br />
|0x85<br />
|x2 x1<br />
|x0<br />
|Boolean ''or'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_XOR<br />
|134<br />
|0x86<br />
|x2 x1<br />
|x0<br />
|Boolean ''exclusive or'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_EQUAL<br />
|135<br />
|0x87<br />
|x2 x1<br />
|Boolean<br />
|Returns 1 if the inputs are byte-wise equal, 0 otherwise.<br />
|-<br />
|OP_EQUALVERIFY<br />
|136<br />
|0x88<br />
|x2 x1<br />
|Nothing / false<br />
|Same as OP_EQUAL, but runs OP_VERIFY afterward.<br />
|}<br />
<br />
=== Arithmetic ===<br />
<br />
(In very early versions, the implemented arithmetic opcodes were limited to maximal 4 byte vectors.)<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_1ADD<br />
|139<br />
|0x8b<br />
|i1<br />
|i0<br />
|1 is added to the input.<br />
|-<br />
|OP_1SUB<br />
|140<br />
|0x8c<br />
|i1<br />
|i0<br />
|1 is subtracted from the input.<br />
|-<br />
|OP_2MUL<br />
|141<br />
|0x8d<br />
|i1<br />
|i0<br />
|The input is multiplied by 2. ''Currently disabled.''<br />
|-<br />
|OP_2DIV<br />
|142<br />
|0x8e<br />
|i1<br />
|i0<br />
|The input is divided by 2 (round down). ''Currently disabled.''<br />
|-<br />
|OP_NEGATE<br />
|143<br />
|0x8f<br />
|i1<br />
|i0<br />
|The sign of the input is flipped. Numerically the value is multiplied by -1<br />
|-<br />
|OP_ABS<br />
|144<br />
|0x90<br />
|i1<br />
|i0<br />
|The input is negative, its sign is flipped.<br />
|-<br />
|OP_NOT<br />
|145<br />
|0x91<br />
|i1<br />
|Boolean<br />
|If the input is 0 or 1, it is flipped. Otherwise the output will be 0. Test whether its value equals 0<br />
|-<br />
|OP_0NOTEQUAL<br />
|146<br />
|0x92<br />
|i1<br />
|Boolean<br />
|Returns 0 if the input is 0. 1 otherwise. Test whether its value is unequal 0<br />
|-<br />
|OP_ADD<br />
|147<br />
|0x93<br />
|i2 i1<br />
|i0<br />
|stack-top i1 is added to i2.<br />
|-<br />
|OP_SUB<br />
|148<br />
|0x94<br />
|i2 i1<br />
|i0<br />
|stack-top i1 is subtracted from i2.<br />
|-<br />
|OP_MUL<br />
|149<br />
|0x95<br />
|i2 i1<br />
|i0<br />
|i2 is multiplied with stack-top i1. ''Currently disabled.''<br />
|-<br />
|OP_DIV<br />
|150<br />
|0x96<br />
|i2 i1<br />
|i0<br />
|i2 is divided by stack-top i1 (divisor should be not 0). ''Currently disabled.''<br />
|-<br />
|OP_MOD<br />
|151<br />
|0x97<br />
|i2 i1<br />
|i0<br />
|Returns the remainder after dividing i2 by stack-top i1 (divisor should be not 0). ''Currently disabled.''<br />
|-<br />
|OP_LSHIFT<br />
|152<br />
|0x98<br />
|i2 i1<br />
|i0<br />
|Shifts i2 left by i1 bits, preserving sign of i2 (i1 >= 0). ''Currently disabled.''<br />
|-<br />
|OP_RSHIFT<br />
|153<br />
|0x99<br />
|i2 i1<br />
|i0<br />
|Shifts i2 right by i1 bits, preserving sign of i2 (i1 >= 0). ''Currently disabled.''<br />
|-<br />
|OP_BOOLAND<br />
|154<br />
|0x9a<br />
|i2 i1<br />
|Boolean<br />
|If both i2 and i1 are not 0, the output is 1. Otherwise 0.<br />
|-<br />
|OP_BOOLOR<br />
|155<br />
|0x9b<br />
|i2 i1<br />
|Boolean<br />
|If i2 or i1 is not 0, the output is 1. Otherwise 0.<br />
|-<br />
|OP_NUMEQUAL<br />
|156<br />
|0x9c<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 and i1 are numerically equal, 0 otherwise.<br />
|-<br />
|OP_NUMEQUALVERIFY<br />
|157<br />
|0x9d<br />
|i2 i1<br />
|Nothing / False<br />
|Same as OP_NUMEQUAL, but runs OP_VERIFY afterward.<br />
|-<br />
|OP_NUMNOTEQUAL<br />
|158<br />
|0x9e<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 and i1 are numerically not equal, 0 otherwise.<br />
|-<br />
|OP_LESSTHAN<br />
|159<br />
|0x9f<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is less than stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_GREATERTHAN<br />
|160<br />
|0xa0<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is greater than stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_LESSTHANOREQUAL<br />
|161<br />
|0xa1<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is less than or equal to stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_GREATERTHANOREQUAL<br />
|162<br />
|0xa2<br />
|i2 i1<br />
|Boolean<br />
|Returns 1 if i2 is greater than or equal to stack-top item i1, 0 otherwise.<br />
|-<br />
|OP_MIN<br />
|163<br />
|0xa3<br />
|i2 i1<br />
|i2 / i1<br />
|Returns the smaller of i2 and i1.<br />
|-<br />
|OP_MAX<br />
|164<br />
|0xa4<br />
|i2 i1<br />
|i2 / i1<br />
|Returns the larger of i2 and i1.<br />
|-<br />
|OP_WITHIN<br />
|165<br />
|0xa5<br />
|i3 min max<br />
|Boolean<br />
|Returns 1 if i3 is within the specified range (left-inclusive) , 0 otherwise. min may be greater than the stack-top item max<br />
|}<br />
<br />
=== Crypto ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_RIPEMD160<br />
|166<br />
|0xa6<br />
|x<br />
|hash20<br />
|The input is hashed using RIPEMD-160.<br />
|-<br />
|OP_SHA1<br />
|167<br />
|0xa7<br />
|x<br />
|hash20<br />
|The input is hashed using SHA-1.<br />
|-<br />
|OP_SHA256<br />
|168<br />
|0xa8<br />
|x<br />
|hash32<br />
|The input is hashed using SHA-256.<br />
|-<br />
|OP_HASH160<br />
|169<br />
|0xa9<br />
|x<br />
|hash20<br />
|The input is hashed twice: first with SHA-256 and then with RIPEMD-160.<br />
|-<br />
|OP_HASH256<br />
|170<br />
|0xaa<br />
|x<br />
|hash32<br />
|The input is hashed two times with SHA-256.<br />
|-<br />
|OP_CODESEPARATOR<br />
|171<br />
|0xab<br />
|Nothing<br />
|Nothing<br />
|All of the signature checking opcodes will only match signatures to the data after the most recently-executed OP_CODESEPARATOR.<br />
|-<br />
|[[OP_CHECKSIG]]<br />
|172<br />
|0xac<br />
|sig pubkey<br />
|Boolean<br />
|The entire transaction's outputs, inputs, and script (from the most recently-executed OP_CODESEPARATOR to the end) are hashed. The signature used by OP_CHECKSIG must be a valid signature for a further, extern specified hash and the given public key. If it is, 1 is returned, 0 otherwise.<br />
|-<br />
|OP_CHECKSIGVERIFY<br />
|173<br />
|0xad<br />
|sig pubkey<br />
|Nothing / False<br />
|Same as OP_CHECKSIG, but OP_VERIFY is executed afterward.<br />
|-<br />
|OP_CHECKMULTISIG<br />
|174<br />
|0xae<br />
|sig1 sig2 ... <number of signatures> pub1 pub2 <number of public keys><br />
|Boolean<br />
|For each signature and public key pair, OP_CHECKSIG is executed. If more public keys than signatures are listed, some key/sig pairs can fail. All signatures need to match a public key. If all signatures are valid, 1 is returned, 0 otherwise. Due to a bug, one extra unused value is removed from the stack.<br />
|-<br />
|OP_CHECKMULTISIGVERIFY<br />
|175<br />
|0xaf<br />
|sig1 sig2 ... <number of signatures> pub1 pub2 ... <number of public keys><br />
|Nothing / False<br />
|Same as OP_CHECKMULTISIG, but OP_VERIFY is executed afterward.<br />
|}<br />
<br />
=== Expansion opcodes ===<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_NOP1-OP_NOP10<br />
|176-185<br />
|0xb0-0xb9<br />
|The opcode has no effect.<br />
|}<br />
<br />
=== Version opcodes ===<br />
Version opcodes are disabled since bitcoin 0.2.0 and should not be used (maybe reassigned in the future).<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_VER<br />
|98<br />
|0x62<br />
|Script evalution is triggered invalid (Formerly pushed the bitcoin-serialize version onto stack).<br />
|-<br />
|OP_VERIF<br />
|101<br />
|0x65<br />
|Script evalution is triggered invalid (Formerly top stack item was popped and =< compared to present version)<br />
|-<br />
|OP_VERNOTIF<br />
|102<br />
|0x66<br />
|Script evalution is triggered invalid (Formerly top stack item was popped and > compared to present version)<br />
|}<br />
<br />
=== Reserved opcodes ===<br />
Each opcode not assigned (currently also every opcode value > 185) is also reserved. Using any unassigned opcode triggers the script evaluation to be invalid.<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_RESERVED<br />
|80<br />
|0x50<br />
|Script evalution is triggered invalid-<br />
|-<br />
|OP_RESERVED1<br />
|137<br />
|0x89<br />
|Script evalution is triggered invalid.<br />
|-<br />
|OP_RESERVED2<br />
|138<br />
|0x8a<br />
|Script evalution is triggered invalid.<br />
|}<br />
<br />
===Pseudo-opcodes===<br />
These nemonics are used internally for assisting with transaction matching. They are invalid if used in actual scripts.<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_PUBKEYHASH<br />
|253<br />
|0xfd<br />
|Represents a public key hashed with OP_HASH160.<br />
|-<br />
|OP_PUBKEY<br />
|254<br />
|0xfe<br />
|Represents a public key compatible with OP_CHECKSIG.<br />
|-<br />
|OP_INVALIDOPCODE<br />
|255<br />
|0xff<br />
|Matches any opcode that is not yet assigned.<br />
|}<br />
<br />
==Scripts in bitcoin transactions==<br />
It follows a list of important (most occuring) scripts to see opcodes "at work". Keep in mind that all constants actually use the data-pushing instructions above. At start of a (transaction input) script evaluation, the stack is always empty. <br />
<br />
===Standard transaction to bitcoin address===<br />
<br />
scriptPubKey: OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG<br />
scriptSig: <sig> <pubKey><br />
<br />
To demonstrate how scripts look on the wire, here is a raw scriptPubKey:<br />
<pre> 76 A9 14<br />
OP_DUP OP_HASH160 Bytes to push<br />
<br />
89 AB CD EF AB BA AB BA AB BA AB BA AB BA AB BA AB BA AB BA 88 AC<br />
Data to push OP_EQUALVERIFY OP_CHECKSIG</pre><br />
<br />
Note: scriptSig is in the input of the spending transaction and scriptPubKey is in the output of the previously storing transaction, i.e. its "available bitcoins".<br />
<br />
Here is how each instruction is processed:<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
| <sig> <pubKey> OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| scriptSig and scriptPubKey are combined.<br />
|-<br />
|<sig> <pubKey><br />
| OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| Constants are added to the stack.<br />
|-<br />
|<sig> <pubKey> <pubKey><br />
| OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| Top stack item is duplicated.<br />
|-<br />
|<sig> <pubKey> <pubHashA><br />
|<pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG<br />
| Top stack item is hashed.<br />
|-<br />
|<sig> <pubKey> <pubHashA> <pubKeyHash><br />
|OP_EQUALVERIFY OP_CHECKSIG<br />
| Constant added.<br />
|-<br />
|<sig> <pubKey><br />
|OP_CHECKSIG<br />
| Equality is checked between the top two stack items.<br />
|-<br />
|true<br />
|Empty.<br />
|Signature is checked for top two stack items.<br />
|}<br />
<br />
===Transaction to IP address (and generation transaction)===<br />
<br />
scriptPubKey: <pubKey> OP_CHECKSIG<br />
scriptSig: <sig><br />
<br />
Checking process:<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
|<sig> <pubKey> OP_CHECKSIG<br />
|scriptSig and scriptPubKey are combined.<br />
|-<br />
|<sig> <pubKey><br />
| OP_CHECKSIG<br />
|Constants are added to the stack.<br />
|-<br />
|true<br />
|Empty.<br />
|Signature is checked for top two stack items.<br />
|}<br />
<br />
In the case of a '''coin generation transaction''' (the first transaction of each block), there is no scriptSig, resp. its code ("coinbase") is completly ignored for the transaction. Only the scriptPubKey is used.<br />
<br />
===Transaction with a message===<br />
<br />
It's possible to add arbitrary data to any transaction by just adding some data along with OP_DROP. <br />
scriptPubKey: <message> OP_DROP <pubKey> OP_CHECKSIG<br />
scriptSig: <sig><br />
<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
|<sig> <message> OP_DROP <pubKey> OP_CHECKSIG<br />
|<br />
|-<br />
|<sig><br />
|<message> OP_DROP <pubKey> OP_CHECKSIG<br />
|scriptSig added to the stack.<br />
|-<br />
|<sig> <message><br />
|OP_DROP <pubKey> OP_CHECKSIG<br />
|The message has been put.<br />
|-<br />
|<sig><br />
|<pubKey> OP_CHECKSIG<br />
|Top stack item has been removed.<br />
|-<br />
|<sig> <pubKey><br />
|OP_CHECKSIG<br />
|Checking signature against the public key.<br />
|-<br />
|true<br />
|Empty.<br />
|Stack holds the value of signature check now.<br />
|}<br />
<br />
===Examples of non standard transaction on Testnet===<br />
<br />
These two links below show a non standard transaction. It just prepends the hex of "bob" and the operation OP_DROP<br />
which just removes it. As you can see they can be spent as normal.<br />
<br />
Input non-std transaction:<br />
http://blockexplorer.com/testnet/t/6ttfeb55B1<br />
<br />
Spent by:<br />
http://blockexplorer.com/testnet/t/AFdRB1CHS3<br />
<br />
==Script validation==<br />
A script evaluation is considered invalid, if any of these conditions meets:<br><br />
<ul><br />
<li>the total size of the script exceeds (currently) 10000 bytes<br />
<li>there are more than (currently) 201 opcodes of opcode value > 0x60 in the script<br />
<li>each instruction is (currently) limited to maximal 520 bytes. This effects only the opcodes OP_PUSHDATA2 and OP_PUSHDATA4<br />
<li>the executed opcode of the script has insufficient input (from stack, from script or from anywhere)<br />
<li>the opcode is not defined (for execution) - indicated by white or light gray background color in the table<br />
<li>the opcode is disabled (currently 15 opcodes) - indicated by white font color in the opcode overview matrix<br />
<li>stack overflow occurs during execution of the opcode (currently the number of items on the stack and on the alternate stack is limited to 1000)<br />
<li>the opcodes OP_VERIF and OP_NOTVERIF invalidate a script which contains this opcode (even if this opcode is not executed!)<br />
<li>the opcodes OP_ELSE or OP_ENDIF has no matching OP_IF<br><br />
<li>the script execution has been finished but there is (at least) an unmatched OP_IF<br><br />
<li>the opcodes OP_VERIFY, OP_EQUALVERIFY, OP_NUMEQUALVERIFY, OP_CHECKSIGVERIFY and OP_CHECKMULTISIGVERIFY invalidate the script if the stack-top item is false<br />
<li>the execution of OP_RETURN<br />
<!--li>alt stack overflow occurs (only possible during execution of OP_TOALTSTACK)--><br />
<li>the numerical value of the top-stack item is negative or greater than the number of items - 2 on the stack if OP_PICK or OP_ROLL shall be executed<br />
<li>an item used as public key or signature for each of the opcodes OP_CHECKSIG, OP_CHECKSIGVERIFY, OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY can be neither a public key or signature (for the given hash)<br />
<li>the number of signature items or the number of public key items on the stack is negative for OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY<br />
<li>there or more signatures items than public key items on the stack for OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY<br />
<li>there are (currently) more than 20 public key items on the stack for OP_CHECKMULTISIG or CHECKMULTISIGVERIFY<br />
<li>the sum of opcodes > 0x60 and the number of public keys in all executed OP_CHECKMULTISIG or CHECKMULTISIGVERIFY exceeds (currently) 201<br />
<li>the script execution has been finished and the stack is empty or the top-stack item is false (numerical value 0)<br />
</ul><br />
else the script evaluation is considered to be valid.<ref>[http://sourceforge.net/projects/bitcoin/files/Bitcoin/bitcoin-0.7.1/bitcoin-0.7.1-linux.tar.gz file src/src/script.cpp in bitcoin-0.7.1]</ref><br />
'''If invalidation of a script is triggered then the script is immediately finished.''' These arbitrary looking limitations of 10000, 201, 520, 1000 and 20 might be increased in the future -- they serve to prevent strong slow down of the evaluation of a script while not restricting its practical usage really.<br />
<br />
==Withdrawn and drafted opcodes==<br />
<br />
<ul><br />
<li> byte value 0x89 OP_NOTEQUAL defined in pre-0.1.0 bitcoin versions. Since 0.1.0 removed because of security concerns. <br />
<li> byte value 0xb1 [[BIP 0012 | OP_EVAL]] withdraw - poll was triggered but insufficient support. <br />
<li> byte value 0xb2 [[BIP 0017 | OP_CHECKHASHVERIFY]] withdraw - poll was triggered but insufficient support.<br />
</ul><br />
<br />
==See Also==<br />
* [[Transactions]]<br />
* [[Contracts]]<br />
<br />
==References==<br />
<references/><br />
<ul><br />
<li>[http://www.zorinaq.com/pub/bitcoin-0.1.0.tgz file src/script.cpp in bitcoin-0.1.0]</li><br />
</ul><br />
[[Category:Technical]]<br />
[[Category:Vocabulary]]</div>
Smtp
https://en.bitcoin.it/w/index.php?title=Script&diff=34901
Script
2013-01-11T12:40:36Z
<p>Smtp: /* Bitwise logic */</p>
<hr />
<div>Bitcoin uses a scripting system for [[transactions]]. [[Wikipedia:FORTH|Forth]]-like, Script is simple, stack-based, and processed from left to right. It is purposefully not Turing-complete, with no loops.<br />
<br />
A script is essentially a list of instructions recorded with each transaction that describe how the next person wanting to spend the Bitcoins being transferred can gain access to them.<br />
<br />
Scripts are big-endian and their sequences of bytes is interpreted as a sequence of opcodes with operands. Only opcodes with byte values less than 0x4f have additional operands.<br />
<br />
== Scripts and Bitcoin transactions ==<br />
The script for a typical Bitcoin transfer to destination Bitcoin address D simply encumbers future spending of the bitcoins with two things: the spender must provide<br />
# a public key that, when hashed, yields destination address D embedded in the script, and<br />
# a signature to show evidence of the private key corresponding to the public key just provided.<br />
<br />
Scripting provides the flexibility to change the parameters of what's needed to spend transferred Bitcoins. For example, the scripting system could be used to require two private keys, or a combination of several, or even no keys at all.<br />
<br />
A transaction is valid if nothing in the combined script triggers failure and the top stack item exists and is true (non-zero). The party who originally ''stored'' the Bitcoins now being spent, dictates the script operations that will occur ''last'' in order to release them for use in another transaction. The party wanting to spend them must provide the input(s) to the previously recorded script that results in those operations occurring last leaving behind true (non-zero) on the stack.<br><br />
Only the very first transaction in each bitcoin block has no input script (the entry there is called "coinbase"), because the Bitcoins created with the block are created from hot air and not released by a previous recorded script.<br />
<br />
== Stack ==<br />
<br />
The stacks hold byte vectors (there is the (main) stack and an alternative stack). Byte vectors are interpreted as little-endian variable-length integers with the most significant bit determining the sign of the integer. Thus 0x81 represents -1. 0x80 is another representation of zero (so called negative 0). Byte vectors are interpreted as Booleans where False is represented by any representation of zero, and True is represented by any representation of non-zero.<br />
<br />
== Opcode overview ==<br />
<br />
For each opcode is given: its nemonic without the leading OP_, its hexadecimal byte value, the number of stack items needed (poped) during execution, a semicolon and the number of stack items which has been pushed (after execution). A * after the needed stack items indicates that further bytes from the script following the current opcode are needed. A # indicates that items on the alternative stack are poped/pushed. A @ indicates that further (global) data from the transaction is needed. A / indicates alternatives of a value. <br/><br />
Different colors indicate different semantic execution groups of opcodes:<br />
{| style="background:none; font-size:100%; padding:0; border-collapse:collapse; text-align:center; line-height:2em;" border="0" align="center" <br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | copy a fixed number of bytes but at most 75 onto stack<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | copy bytes onto stack which number is given by a 1, 2 or 4 byte value.<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | copy 1 specific byte onto stack<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | undefined opcode<br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | a pseudo-opcode, unassigned for scripts<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | NOP or opcode is part of a IF-flow-control construction<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00ff00;" | (stack conditionally) invalidation of the script this opcode is part of<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | stack item is moved between main stack and alternate stack<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | stack item(s) is/are moved, copied or deleted<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0;" | byte vectors are appended or divided or their size is determined<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff;" | byte vectors are interpreted bit-position-independently<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | byte vectors are interpreted and processed as signed integers<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | a hash value is computed or a signature checked<br />
|}<br />
<p><br />
===Opcode byte-matrix===<br />
The opcode value 0x00 with nemonic OP_FALSE is also named OP_0 and the opcode value 0x51 with nemonic OP_1 as also named OP_TRUE.<br />
{| style="background:none; font-size:100%; padding:0; border-collapse:collapse; text-align:center; line-height:2em;" border="0" align="center" <br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" |_FALSE<br/> 0x00 <br/> 0 ; 1(0) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x01<br/> 0 *; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x02<br/> 0 *; 1(2)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x03<br/> 0 *; 1(3)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x04<br/> 0 *; 1(4)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x04<br/> 0 *; 1(5)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x06<br/> 0 *; 1(6)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x07<br/> 0 *; 1(7)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x08<br/> 0 *; 1(8)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x09<br/> 0 *; 1(9)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0a<br/> 0 *; 1(10)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0b<br/> 0 *; 1(11)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0c<br/> 0 *; 1(12)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0d<br/> 0 *; 1(13)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0e<br/> 0 *; 1(14)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0f<br/> 0 *; 1(15)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x10 <br/> 0 *; 1(16) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x11 <br/> 0 *; 1(17)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x12 <br/> 0 *; 1(18)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x13 <br/> 0 *; 1(19)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x14 <br/> 0 *; 1(20)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x15 <br/> 0 *; 1(21)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x16 <br/> 0 *; 1(22)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x17 <br/> 0 *; 1(23)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x18 <br/> 0 *; 1(24)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x19 <br/> 0 *; 1(25)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1a <br/> 0 *; 1(26)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1b <br/> 0 *; 1(27)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1c <br/> 0 *; 1(28)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1d <br/> 0 *; 1(29)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1e <br/> 0 *; 1(30)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1f <br/> 0 *; 1(31)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x20 <br/> 0 *; 1(32) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x21 <br/> 0 *; 1(33)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x22 <br/> 0 *; 1(34)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x23 <br/> 0 *; 1(35)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x24 <br/> 0 *; 1(36)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x25 <br/> 0 *; 1(37)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x26 <br/> 0 *; 1(38)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x27 <br/> 0 *; 1(39)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x28 <br/> 0 *; 1(40)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x29 <br/> 0 *; 1(41)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2a <br/> 0 *; 1(42)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2b <br/> 0 *; 1(43)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2c <br/> 0 *; 1(44)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2d <br/> 0 *; 1(45)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2e <br/> 0 *; 1(46)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2f <br/> 0 *; 1(47)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x30 <br/> 0 *; 1(48) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x31 <br/> 0 *; 1(49)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x32 <br/> 0 *; 1(50)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x33 <br/> 0 *; 1(51)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x34 <br/> 0 *; 1(52)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x35 <br/> 0 *; 1(53)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x36 <br/> 0 *; 1(54)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x37 <br/> 0 *; 1(55)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x38 <br/> 0 *; 1(56)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x39 <br/> 0 *; 1(57)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3a <br/> 0 *; 1(58)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3b <br/> 0 *; 1(59)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3c <br/> 0 *; 1(60)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3d <br/> 0 *; 1(61)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3e <br/> 0 *; 1(62)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3f <br/> 0 *; 1(63)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x40 <br/> 0 *; 1(64) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x41 <br/> 0 *; 1(65)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x42 <br/> 0 *; 1(66)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x43 <br/> 0 *; 1(67)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x44 <br/> 0 *; 1(68)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x45 <br/> 0 *; 1(69)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x46 <br/> 0 *; 1(70)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x47 <br/> 0 *; 1(71)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x48 <br/> 0 *; 1(72)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x49 <br/> 0 *; 1(73)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x4a <br/> 0 *; 1(74)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x4b <br/> 0 *; 1(75)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA1 <br/> 0x4c <br/> 0 *; 1(0 - 255)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA2 <br/> 0x4d <br/> 0 *; 1(0 - 2^16-1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA4 <br/> 0x4e <br/> 0 *; 1(0 - 2^32-1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _1NEGATE <br/> 0x4f <br/> 0 ; 1(1)<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED <br/> 0x50 <br/> <br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _1 <br/> 0x51 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _2 <br/> 0x52 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _3 <br/> 0x53 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _4 <br/> 0x54 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _5 <br/> 0x55 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _6 <br/> 0x56 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _7 <br/> 0x57 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _8 <br/> 0x58 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _9 <br/> 0x59 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _10 <br/> 0x5a <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _11 <br/> 0x5b <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _12 <br/> 0x5c <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _13 <br/> 0x5d <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _14 <br/> 0x5e <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _15 <br/> 0x5f <br/> 0 ; 1(1)<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _16 <br/> 0x60 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP <br/> 0x61 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VER <br/> 0x62 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _IF <br/> 0x63 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOTIF <br/> 0x64 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VERIF <br/> 0x65 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VERNOTIF <br/> 0x66 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _ELSE <br/> 0x67 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _ENDIF <br/> 0x68 <br/> 0 ; 0<br />
| style="border:3px solid #808080; background-color:#00ff00;" | _VERIFY <br/> 0x69 <br/> 1 ; 0/1<br />
| style="border:3px solid #808080; background-color:#00ff00;" | _RETURN <br/> 0x6a <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | _TOALTSTACK <br/> 0x6b <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | _FROMALTSTACK <br/> 0x6c <br/> 0 #; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2DROP <br/> 0x6d <br/> 2 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2DUP <br/> 0x6e <br/> 2 ; 4<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _3DUP <br/> 0x6f <br/> 3 ; 6<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2OVER <br/> 0x70 <br/> 4 ; 6<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2ROT <br/> 0x71 <br/> 6 ; 6<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2SWAP <br/> 0x72 <br/> 4 ; 4<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _IFDUP <br/> 0x73 <br/> 1 ; 1/2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DEPTH <br/> 0x74 <br/> 0 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DROP <br/> 0x75 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DUP <br/> 0x76 <br/> 1 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _NIP <br/> 0x77 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _OVER <br/> 0x78 <br/> 2 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _PICK <br/> 0x79 <br/> 1+n+1 ; n+2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _ROLL <br/> 0x7a <br/> 1+n+1 ; n+1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _ROT <br/> 0x7b <br/> 3 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _SWAP <br/> 0x7c <br/> 2 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _TUCK <br/> 0x7d <br/> 2 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _CAT <br/> 0x7e <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _SUBSTR <br/> 0x7f <br/> 3 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _LEFT <br/> 0x80 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _RIGHT <br/> 0x81 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0;" | _SIZE <br/> 0x82 <br/> 1 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _INVERT <br/> 0x83 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _AND <br/> 0x84 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _OR <br/> 0x85 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _XOR <br/> 0x86 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff;" | _EQUAL <br/> 0x87 <br/> 2 ; 1<br />
| style="border:3px solid #808080; background-color:#c080ff;" | _EQUALVERIFY <br/> 0x88 <br/> 2 ; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED1 <br/> 0x89 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED2 <br/> 0x8a <br/><br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _1ADD <br/> 0x8b <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _1SUB <br/> 0x8c <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _2MUL <br/> 0x8d <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _2DIV <br/> 0x8e <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NEGATE <br/> 0x8f <br/> 1 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _ABS <br/> 0x90 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NOT <br/> 0x91 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _0NOTEQUAL <br/> 0x92 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _ADD <br/> 0x93 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _SUB <br/> 0x94 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _MUL <br/> 0x95 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _DIV <br/> 0x96 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _MOD <br/> 0x97 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _LSHIFT <br/> 0x98 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _RSHIFT <br/> 0x99 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _BOOLAND <br/> 0x9a <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _BOOLOR <br/> 0x9b <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NUMEQUAL <br/> 0x9c <br/> 2 ; 1<br />
| style="border:3px solid #808080; background-color:#8080ff;" | _NUMEQUALVERIFY <br/> 0x9d <br/> 2 ; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NUMNOTEQUAL <br/> 0x9e <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _LESSTHAN <br/> 0x9f <br/> 2 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _GREATERTHAN <br/> 0xa0 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _LESSTHANOREQUAL <br/> 0xa1 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _GREATERTHANOREQUAL <br/> 0xa2 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _MIN <br/> 0xa3 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _MAX <br/> 0xa4 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _WITHIN <br/> 0xa5 <br/> 3 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _RIPEMD160 <br/> 0xa6 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _SHA1 <br/> 0xa7 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _SHA256 <br/> 0xa8 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _HASH160 <br/> 0xa9 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _HASH256 <br/> 0xaa <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CODESEPARATOR <br/> 0xab <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CHECKSIG <br/> 0xac <br/> 2 @; 1<br />
| style="border:3px solid #808080; background-color:#a0d0ff;" | _CHECKSIGVERIFY <br/> 0xad <br/> 2 @; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CHECKMULTISIG <br/> 0xae <br/> 2n+2 @; 1<br />
| style="border:3px solid #808080; background-color:#a0d0ff;" | _CHECKMULTISIGVERIFY <br/> 0xaf <br/> 2n+2 @; 0/1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP1 <br/> 0xb0 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP2 <br/> 0xb1 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP3 <br/> 0xb2 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP4 <br/> 0xb3 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP5 <br/> 0xb4 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP6 <br/> 0xb5 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP7 <br/> 0xb6 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP8 <br/> 0xb7 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP9 <br/> 0xb8 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP10 <br/> 0xb9 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xba <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbe <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xca <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xce <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xda <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xde <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xea <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xeb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xec <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xed <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xee <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xef <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xfa <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _SMALLINTEGER <br/> 0xfb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEYS <br/> 0xfc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEYHASH <br/> 0xfd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEY <br/> 0xfe <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _INVALIDOPCODE <br/> 0xff <br/><br />
|}<br><br />
Except later pseudo-opcode changes, the definition of OP_NOP1 - OP_NOP10 and the change of the evaluation of OP_RETURN (did no invalidation previously) which both occured in bitcoin version 0.3.6 in July 2010 were the last changes regarding opcodes <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.2.0/bitcoin-0.2.0-linux.tar.gz file src/srcipt.cpp in bitcoin-0.2.0]</ref> <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.3.3/bitcoin-0.3.3-linux.tar.gz file src/srcipt.cpp in bitcoin-0.3.3]</ref> <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.3.6/bitcoin-0.3.6-linux.tar.gz file src/srcipt.cpp in bitcoin-0.3.6]</ref>.<br />
<br />
== Opcode descriptions ==<br />
It follows for each opcode less than decimal 185 (hexa 0xba) a description for its usage. The columns entitled ''nemonic'', ''decimal'' and ''Hex'' should be evident. The column ''input'' gives the needed items of the stack (and the alternate stack) and the column ''output'' indicates the resulting items on the stack (and the alternate stack). '''Stack-top is always the right most item.''' The naming of the entries in these two columns is chosen to reflect their interpretation. ''x'',''x0'',''x1'',... means arbitrary or no interpretation, ''a'', ''b'' and ''c'' as a signed integer value, ''n'',''index'',''size'' and ''depth'' non-negative integer values, ''Boolean'' as either a true or false.<br><br />
<br />
Some of the more complicated opcodes are disabled out of concern that the client might have (and has) a bug in the current implementation due to the historically not as 2-complement interpretations of the byte vectors as numerical values (the most significant byte holds the sign of the byte vectors).<br />
<br />
=== Push data from instruction onto stack ===<br />
<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_FALSE, OP_0<br />
|0<br />
|0x00<br />
|Nothing<br />
|Empty string<br />
|A byte vector of length 0 is pushed onto the stack. (Thus, it is not a no-op!)<br />
|-<br />
|(no official nemonics)<br />
|1 - 75<br />
|0x01 - 0x4b<br />
|(operand)<br />
|x<br />
|The next <opcode>-many bytes are to be pushed onto the stack.<br />
|-<br />
|OP_PUSHDATA1<br />
|76<br />
|0x4c<br />
|(operands)<br />
|x<br />
|The next byte contains the number of bytes to be pushed onto the stack which follow this byte.<br />
|-<br />
|OP_PUSHDATA2<br />
|77<br />
|0x4d<br />
|(operands)<br />
|x<br />
|The next two bytes contain the number of bytes to be pushed onto the stack which follow theses 2 bytes.<br />
|-<br />
|OP_PUSHDATA4<br />
|78<br />
|0x4e<br />
|(operands)<br />
|x<br />
|The next four bytes contain the number of bytes to be pushed onto the stack which follow theses 4 bytes.<br />
|-<br />
|OP_1NEGATE<br />
|79<br />
|0x4f<br />
|Nothing<br />
| -1<br />
|The byte with value -1 is pushed onto the stack.<br />
|-<br />
|OP_1, OP_TRUE<br />
|81<br />
|0x51<br />
|Nothing<br />
|1<br />
|The byte with value 1 is pushed onto the stack.<br />
|-<br />
|OP_2 - OP_16<br />
|82 - 96<br />
|0x52 - 0x60<br />
|Nothing<br />
|2-16<br />
|The byte with value <opcode>-80 (thus, one of 2 - 16) is pushed onto the stack.<br />
|}<br />
<br />
=== Flow control ===<br />
<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_NOP<br />
|97<br />
|0x61<br />
|Nothing<br />
|Nothing<br />
|Does nothing.<br />
|-<br />
|OP_IF<br />
|99<br />
|0x63<br />
|Boolean<br />
|Nothing<br />
|If the top stack value is not 0, the statements are executed. The top stack value is removed. Lead in a logcial ''<value> then [statements] [else [statements]] endif'' expression<br />
|-<br />
|OP_NOTIF<br />
|100<br />
|0x64<br />
|Boolean<br />
|Nothing<br />
|If the top stack value is 0, the statements are executed. The top stack value is removed. Lead in a logcial ''<value> then [statements] [else [statements]] endif'' expression <br />
|-<br />
|OP_ELSE<br />
|103<br />
|0x67<br />
|Nothing<br />
|Nothing<br />
|If the preceeding OP_IF or OP_NOTIF or OP_ELSE was not executed then these statements are and if the preceding OP_IF or OP_NOTIF or OP_ELSE was executed then these statements are not. <br />
|-<br />
|OP_ENDIF<br />
|104<br />
|0x68<br />
|Nothing<br />
|Nothing<br />
|Ends a logcial ''If <value> then [statements] [else [statements]] '' expression<br />
|-<br />
|OP_VERIFY<br />
|105<br />
|0x69<br />
|Boolean<br />
|Nothing / False<br />
|If top stack value is not true then marks transaction as '''invalid''' . A value true is removed, but false is not.<br />
|-<br />
|OP_RETURN<br />
|106<br />
|0x6a<br />
|Nothing<br />
|Nothing<br />
|Marks transaction as '''invalid'''. <br />
|}<br />
<br />
===Stack item organization===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_TOALTSTACK<br />
|107<br />
|0x6b<br />
|x1 (alt)<br />
|(alt x1)<br />
|Puts the input onto the top of the alt stack. Removes it from the (main) stack.<br />
|-<br />
|OP_FROMALTSTACK<br />
|108<br />
|0x6c<br />
|(alt x1)<br />
|x1 (alt)<br />
|Puts the input onto the top of the (main) stack. Removes it from the alt stack.<br />
|-<br />
|OP_2DROP<br />
|109<br />
|0x6d<br />
|x2 x1<br />
|Nothing<br />
|Removes the top two stack items.<br />
|-<br />
|OP_2DUP<br />
|110<br />
|0x6e<br />
|x2 x1<br />
|x2 x1 x2 x1<br />
|Duplicates the top two stack items.<br />
|-<br />
|OP_3DUP<br />
|111<br />
|0x6f<br />
|x3 x2 x1<br />
|x3 x2 x1 x3 x2 x1<br />
|Duplicates the top three stack items.<br />
|-<br />
|OP_2OVER<br />
|112<br />
|0x70<br />
|x4 x3 x2 x1<br />
|x4 x3 x2 x1 x4 x3<br />
|Copies the pair of items two spaces back in the stack to the front.<br />
|-<br />
|OP_2ROT<br />
|113<br />
|0x71<br />
|x6 x5 x4 x3 x2 x1<br />
|x4 x3 x2 x1 x6 x5<br />
|The fifth and sixth items back are moved to the top of the stack. Twotimes left rotate.<br />
|-<br />
|OP_2SWAP<br />
|114<br />
|0x72<br />
|x4 x3 x2 x1<br />
|x2 x1 x4 x3<br />
|Swaps the top two pairs of stack items.<br />
|-<br />
|OP_IFDUP<br />
|115<br />
|0x73<br />
|x1<br />
|x1 / x1 x1<br />
|If the top stack value is not 0, duplicate it.<br />
|-<br />
|OP_DEPTH<br />
|116<br />
|0x74<br />
|Nothing<br />
|depth<br />
|Puts the number of stack items onto the stack as one little-endian coded byte-vector<br />
|-<br />
|OP_DROP<br />
|117<br />
|0x75<br />
|x1<br />
|Nothing<br />
|Removes the top stack item.<br />
|-<br />
|OP_DUP<br />
|118<br />
|0x76<br />
|x1<br />
|x1 x1<br />
|Duplicates the top stack item.<br />
|-<br />
|OP_NIP<br />
|119<br />
|0x77<br />
|x2 x1<br />
|x1<br />
|Removes the second-to-top stack item.<br />
|-<br />
|OP_OVER<br />
|120<br />
|0x78<br />
|x2 x1<br />
|x2 x1 x2<br />
|Copies the second-to-top stack item to the top.<br />
|-<br />
|OP_PICK<br />
|121<br />
|0x79<br />
|xn ... x2 x1 x0 <n><br />
|xn ... x2 x1 x0 xn<br />
|<n> is removed and the item ''n'' back in the stack is copied to the top.<br />
|-<br />
|OP_ROLL<br />
|122<br />
|0x7a<br />
|xn ... x2 x1 x0 <n><br />
|... x2 x1 x0 xn<br />
|<n> is removed and the item ''n'' back in the stack is moved to the top.<br />
|-<br />
|OP_ROT<br />
|123<br />
|0x7b<br />
|x3 x2 x1<br />
|x2 x1 x3<br />
|The top three items on the stack are rotated to the left.<br />
|-<br />
|OP_SWAP<br />
|124<br />
|0x7c<br />
|x2 x1<br />
|x1 x2<br />
|The top two items on the stack are swapped resp. rotated.<br />
|-<br />
|OP_TUCK<br />
|125<br />
|0x7d<br />
|x2 x1<br />
|x1 x2 x1<br />
|The item at the top of the stack is copied and inserted before the second-to-top item.<br />
|}<br />
<br />
=== Splice ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_CAT<br />
|126<br />
|0x7e<br />
|x2 x1<br />
|out<br />
|Appends stack-top item at second-to top item. Concatenates two strings resp. byte vectors. ''Currently disabled.''<br />
|-<br />
|OP_SUBSTR<br />
|127<br />
|0x7f<br />
|x3 index size<br />
|out<br />
|Returns the section started at position <index> and of length <size> of a string resp. byte vector. ''Currently disabled.''<br />
|-<br />
|OP_LEFT<br />
|128<br />
|0x80<br />
|x2 index<br />
|out<br />
|Keeps only characters left of the specified point in second-to top item. ''Currently disabled.''<br />
|-<br />
|OP_RIGHT<br />
|129<br />
|0x81<br />
|x2 index<br />
|out<br />
|Keeps only characters right of the specified point in second-to top item. ''Currently disabled.''<br />
|-<br />
|OP_SIZE<br />
|130<br />
|0x82<br />
|x1<br />
|x1 size<br />
|Returns the length of the input string resp. byte vector resp. top-stack item.<br />
|}<br />
<br />
=== Bitwise logic ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_INVERT<br />
|131<br />
|0x83<br />
|x1<br />
|x0<br />
|Flips all of the bits in the input. ''Currently disabled.''<br />
|-<br />
|OP_AND<br />
|132<br />
|0x84<br />
|x2 x1<br />
|x0<br />
|Boolean ''and'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_OR<br />
|133<br />
|0x85<br />
|x2 x1<br />
|x0<br />
|Boolean ''or'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_XOR<br />
|134<br />
|0x86<br />
|x2 x1<br />
|x0<br />
|Boolean ''exclusive or'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_EQUAL<br />
|135<br />
|0x87<br />
|x2 x1<br />
|Boolean<br />
|Returns 1 if the inputs are byte-wise equal, 0 otherwise.<br />
|-<br />
|OP_EQUALVERIFY<br />
|136<br />
|0x88<br />
|x2 x1<br />
|Nothing / false<br />
|Same as OP_EQUAL, but runs OP_VERIFY afterward.<br />
|}<br />
<br />
=== Arithmetic ===<br />
<br />
(In very early versions, the implemented arithmetic opcodes were limited to maximal 4 byte vectors.)<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_1ADD<br />
|139<br />
|0x8b<br />
|a<br />
|c<br />
|1 is added to the input.<br />
|-<br />
|OP_1SUB<br />
|140<br />
|0x8c<br />
|a<br />
|c<br />
|1 is subtracted from the input.<br />
|-<br />
|OP_2MUL<br />
|141<br />
|0x8d<br />
|a<br />
|c<br />
|The input is multiplied by 2. ''Currently disabled.''<br />
|-<br />
|OP_2DIV<br />
|142<br />
|0x8e<br />
|a<br />
|c<br />
|The input is divided by 2. ''Currently disabled.''<br />
|-<br />
|OP_NEGATE<br />
|143<br />
|0x8f<br />
|a<br />
|c<br />
|The sign of the input is flipped. Numerically the value is multiplied by -1<br />
|-<br />
|OP_ABS<br />
|144<br />
|0x90<br />
|a<br />
|c<br />
|The input is negative, its sign is flipped.<br />
|-<br />
|OP_NOT<br />
|145<br />
|0x91<br />
|a<br />
|Boolean<br />
|If the input is 0 or 1, it is flipped. Otherwise the output will be 0. Test whether its value equals 0<br />
|-<br />
|OP_0NOTEQUAL<br />
|146<br />
|0x92<br />
|a<br />
|Boolean<br />
|Returns 0 if the input is 0. 1 otherwise. Test whether its value is unequal 0<br />
|-<br />
|OP_ADD<br />
|147<br />
|0x93<br />
|a b<br />
|c<br />
|a is added to b.<br />
|-<br />
|OP_SUB<br />
|148<br />
|0x94<br />
|a b<br />
|c<br />
|b is subtracted from a.<br />
|-<br />
|OP_MUL<br />
|149<br />
|0x95<br />
|a b<br />
|c<br />
|a is multiplied by b. ''Currently disabled.''<br />
|-<br />
|OP_DIV<br />
|150<br />
|0x96<br />
|a b<br />
|c<br />
|a is divided by b (b should be not 0). ''Currently disabled.''<br />
|-<br />
|OP_MOD<br />
|151<br />
|0x97<br />
|a b<br />
|c<br />
|Returns the remainder after dividing a by b (b should be not 0). ''Currently disabled.''<br />
|-<br />
|OP_LSHIFT<br />
|152<br />
|0x98<br />
|a b<br />
|c<br />
|Shifts a left by b bits, preserving sign. ''Currently disabled.''<br />
|-<br />
|OP_RSHIFT<br />
|153<br />
|0x99<br />
|a b<br />
|c<br />
|Shifts a right by b bits, preserving sign. ''Currently disabled.''<br />
|-<br />
|OP_BOOLAND<br />
|154<br />
|0x9a<br />
|a b<br />
|Boolean<br />
|If both a and b are not 0, the output is 1. Otherwise 0.<br />
|-<br />
|OP_BOOLOR<br />
|155<br />
|0x9b<br />
|a b<br />
|Boolean<br />
|If a or b is not 0, the output is 1. Otherwise 0.<br />
|-<br />
|OP_NUMEQUAL<br />
|156<br />
|0x9c<br />
|a b<br />
|Boolean<br />
|Returns 1 if the numbers are equal, 0 otherwise.<br />
|-<br />
|OP_NUMEQUALVERIFY<br />
|157<br />
|0x9d<br />
|a b<br />
|Nothing / False<br />
|Same as OP_NUMEQUAL, but runs OP_VERIFY afterward.<br />
|-<br />
|OP_NUMNOTEQUAL<br />
|158<br />
|0x9e<br />
|a b<br />
|Boolean<br />
|Returns 1 if the numbers are not equal, 0 otherwise.<br />
|-<br />
|OP_LESSTHAN<br />
|159<br />
|0x9f<br />
|a b<br />
|Boolean<br />
|Returns 1 if a is less than b, 0 otherwise.<br />
|-<br />
|OP_GREATERTHAN<br />
|160<br />
|0xa0<br />
|a b<br />
|Boolean<br />
|Returns 1 if a is greater than b, 0 otherwise.<br />
|-<br />
|OP_LESSTHANOREQUAL<br />
|161<br />
|0xa1<br />
|a b<br />
|Boolean<br />
|Returns 1 if a is less than or equal to b, 0 otherwise.<br />
|-<br />
|OP_GREATERTHANOREQUAL<br />
|162<br />
|0xa2<br />
|a b<br />
|Boolean<br />
|Returns 1 if a is greater than or equal to b, 0 otherwise.<br />
|-<br />
|OP_MIN<br />
|163<br />
|0xa3<br />
|a b<br />
|a / b<br />
|Returns the smaller of a and b.<br />
|-<br />
|OP_MAX<br />
|164<br />
|0xa4<br />
|a b<br />
| a / b<br />
|Returns the larger of a and b.<br />
|-<br />
|OP_WITHIN<br />
|165<br />
|0xa5<br />
|x min max<br />
|Boolean<br />
|Returns 1 if x is within the specified range (left-inclusive) , 0 otherwise. min may be greater than max<br />
|}<br />
<br />
=== Crypto ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_RIPEMD160<br />
|166<br />
|0xa6<br />
|x<br />
|hash20<br />
|The input is hashed using RIPEMD-160.<br />
|-<br />
|OP_SHA1<br />
|167<br />
|0xa7<br />
|x<br />
|hash20<br />
|The input is hashed using SHA-1.<br />
|-<br />
|OP_SHA256<br />
|168<br />
|0xa8<br />
|x<br />
|hash32<br />
|The input is hashed using SHA-256.<br />
|-<br />
|OP_HASH160<br />
|169<br />
|0xa9<br />
|x<br />
|hash20<br />
|The input is hashed twice: first with SHA-256 and then with RIPEMD-160.<br />
|-<br />
|OP_HASH256<br />
|170<br />
|0xaa<br />
|x<br />
|hash32<br />
|The input is hashed two times with SHA-256.<br />
|-<br />
|OP_CODESEPARATOR<br />
|171<br />
|0xab<br />
|Nothing<br />
|Nothing<br />
|All of the signature checking opcodes will only match signatures to the data after the most recently-executed OP_CODESEPARATOR.<br />
|-<br />
|[[OP_CHECKSIG]]<br />
|172<br />
|0xac<br />
|sig pubkey<br />
|Boolean<br />
|The entire transaction's outputs, inputs, and script (from the most recently-executed OP_CODESEPARATOR to the end) are hashed. The signature used by OP_CHECKSIG must be a valid signature for a further, extern specified hash and the given public key. If it is, 1 is returned, 0 otherwise.<br />
|-<br />
|OP_CHECKSIGVERIFY<br />
|173<br />
|0xad<br />
|sig pubkey<br />
|Nothing / False<br />
|Same as OP_CHECKSIG, but OP_VERIFY is executed afterward.<br />
|-<br />
|OP_CHECKMULTISIG<br />
|174<br />
|0xae<br />
|sig1 sig2 ... <number of signatures> pub1 pub2 <number of public keys><br />
|Boolean<br />
|For each signature and public key pair, OP_CHECKSIG is executed. If more public keys than signatures are listed, some key/sig pairs can fail. All signatures need to match a public key. If all signatures are valid, 1 is returned, 0 otherwise. Due to a bug, one extra unused value is removed from the stack.<br />
|-<br />
|OP_CHECKMULTISIGVERIFY<br />
|175<br />
|0xaf<br />
|sig1 sig2 ... <number of signatures> pub1 pub2 ... <number of public keys><br />
|Nothing / False<br />
|Same as OP_CHECKMULTISIG, but OP_VERIFY is executed afterward.<br />
|}<br />
<br />
=== Expansion opcodes ===<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_NOP1-OP_NOP10<br />
|176-185<br />
|0xb0-0xb9<br />
|The opcode has no effect.<br />
|}<br />
<br />
=== Version opcodes ===<br />
Version opcodes are disabled since bitcoin 0.2.0 and should not be used (maybe reassigned in the future).<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_VER<br />
|98<br />
|0x62<br />
|Script evalution is triggered invalid (Formerly pushed the bitcoin-serialize version onto stack).<br />
|-<br />
|OP_VERIF<br />
|101<br />
|0x65<br />
|Script evalution is triggered invalid (Formerly top stack item was popped and =< compared to present version)<br />
|-<br />
|OP_VERNOTIF<br />
|102<br />
|0x66<br />
|Script evalution is triggered invalid (Formerly top stack item was popped and > compared to present version)<br />
|}<br />
<br />
=== Reserved opcodes ===<br />
Each opcode not assigned (currently also every opcode value > 185) is also reserved. Using any unassigned opcode triggers the script evaluation to be invalid.<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_RESERVED<br />
|80<br />
|0x50<br />
|Script evalution is triggered invalid-<br />
|-<br />
|OP_RESERVED1<br />
|137<br />
|0x89<br />
|Script evalution is triggered invalid.<br />
|-<br />
|OP_RESERVED2<br />
|138<br />
|0x8a<br />
|Script evalution is triggered invalid.<br />
|}<br />
<br />
===Pseudo-opcodes===<br />
These nemonics are used internally for assisting with transaction matching. They are invalid if used in actual scripts.<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_PUBKEYHASH<br />
|253<br />
|0xfd<br />
|Represents a public key hashed with OP_HASH160.<br />
|-<br />
|OP_PUBKEY<br />
|254<br />
|0xfe<br />
|Represents a public key compatible with OP_CHECKSIG.<br />
|-<br />
|OP_INVALIDOPCODE<br />
|255<br />
|0xff<br />
|Matches any opcode that is not yet assigned.<br />
|}<br />
<br />
==Scripts in bitcoin transactions==<br />
It follows a list of important (most occuring) scripts to see opcodes "at work". Keep in mind that all constants actually use the data-pushing instructions above. At start of a (transaction input) script evaluation, the stack is always empty. <br />
<br />
===Standard transaction to bitcoin address===<br />
<br />
scriptPubKey: OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG<br />
scriptSig: <sig> <pubKey><br />
<br />
To demonstrate how scripts look on the wire, here is a raw scriptPubKey:<br />
<pre> 76 A9 14<br />
OP_DUP OP_HASH160 Bytes to push<br />
<br />
89 AB CD EF AB BA AB BA AB BA AB BA AB BA AB BA AB BA AB BA 88 AC<br />
Data to push OP_EQUALVERIFY OP_CHECKSIG</pre><br />
<br />
Note: scriptSig is in the input of the spending transaction and scriptPubKey is in the output of the previously storing transaction, i.e. its "available bitcoins".<br />
<br />
Here is how each instruction is processed:<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
| <sig> <pubKey> OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| scriptSig and scriptPubKey are combined.<br />
|-<br />
|<sig> <pubKey><br />
| OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| Constants are added to the stack.<br />
|-<br />
|<sig> <pubKey> <pubKey><br />
| OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| Top stack item is duplicated.<br />
|-<br />
|<sig> <pubKey> <pubHashA><br />
|<pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG<br />
| Top stack item is hashed.<br />
|-<br />
|<sig> <pubKey> <pubHashA> <pubKeyHash><br />
|OP_EQUALVERIFY OP_CHECKSIG<br />
| Constant added.<br />
|-<br />
|<sig> <pubKey><br />
|OP_CHECKSIG<br />
| Equality is checked between the top two stack items.<br />
|-<br />
|true<br />
|Empty.<br />
|Signature is checked for top two stack items.<br />
|}<br />
<br />
===Transaction to IP address (and generation transaction)===<br />
<br />
scriptPubKey: <pubKey> OP_CHECKSIG<br />
scriptSig: <sig><br />
<br />
Checking process:<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
|<sig> <pubKey> OP_CHECKSIG<br />
|scriptSig and scriptPubKey are combined.<br />
|-<br />
|<sig> <pubKey><br />
| OP_CHECKSIG<br />
|Constants are added to the stack.<br />
|-<br />
|true<br />
|Empty.<br />
|Signature is checked for top two stack items.<br />
|}<br />
<br />
In the case of a '''coin generation transaction''' (the first transaction of each block), there is no scriptSig, resp. its code ("coinbase") is completly ignored for the transaction. Only the scriptPubKey is used.<br />
<br />
===Transaction with a message===<br />
<br />
It's possible to add arbitrary data to any transaction by just adding some data along with OP_DROP. <br />
scriptPubKey: <message> OP_DROP <pubKey> OP_CHECKSIG<br />
scriptSig: <sig><br />
<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
|<sig> <message> OP_DROP <pubKey> OP_CHECKSIG<br />
|<br />
|-<br />
|<sig><br />
|<message> OP_DROP <pubKey> OP_CHECKSIG<br />
|scriptSig added to the stack.<br />
|-<br />
|<sig> <message><br />
|OP_DROP <pubKey> OP_CHECKSIG<br />
|The message has been put.<br />
|-<br />
|<sig><br />
|<pubKey> OP_CHECKSIG<br />
|Top stack item has been removed.<br />
|-<br />
|<sig> <pubKey><br />
|OP_CHECKSIG<br />
|Checking signature against the public key.<br />
|-<br />
|true<br />
|Empty.<br />
|Stack holds the value of signature check now.<br />
|}<br />
<br />
===Examples of non standard transaction on Testnet===<br />
<br />
These two links below show a non standard transaction. It just prepends the hex of "bob" and the operation OP_DROP<br />
which just removes it. As you can see they can be spent as normal.<br />
<br />
Input non-std transaction:<br />
http://blockexplorer.com/testnet/t/6ttfeb55B1<br />
<br />
Spent by:<br />
http://blockexplorer.com/testnet/t/AFdRB1CHS3<br />
<br />
==Script validation==<br />
A script evaluation is considered invalid, if any of these conditions meets:<br><br />
<ul><br />
<li>the total size of the script exceeds (currently) 10000 bytes<br />
<li>there are more than (currently) 201 opcodes of opcode value > 0x60 in the script<br />
<li>each instruction is (currently) limited to maximal 520 bytes. This effects only the opcodes OP_PUSHDATA2 and OP_PUSHDATA4<br />
<li>the executed opcode of the script has insufficient input (from stack, from script or from anywhere)<br />
<li>the opcode is not defined (for execution) - indicated by white or light gray background color in the table<br />
<li>the opcode is disabled (currently 15 opcodes) - indicated by white font color in the opcode overview matrix<br />
<li>stack overflow occurs during execution of the opcode (currently the number of items on the stack and on the alternate stack is limited to 1000)<br />
<li>the opcodes OP_VERIF and OP_NOTVERIF invalidate a script which contains this opcode (even if this opcode is not executed!)<br />
<li>the opcodes OP_ELSE or OP_ENDIF has no matching OP_IF<br><br />
<li>the script execution has been finished but there is (at least) an unmatched OP_IF<br><br />
<li>the opcodes OP_VERIFY, OP_EQUALVERIFY, OP_NUMEQUALVERIFY, OP_CHECKSIGVERIFY and OP_CHECKMULTISIGVERIFY invalidate the script if the stack-top item is false<br />
<li>the execution of OP_RETURN<br />
<!--li>alt stack overflow occurs (only possible during execution of OP_TOALTSTACK)--><br />
<li>the numerical value of the top-stack item is negative or greater than the number of items - 2 on the stack if OP_PICK or OP_ROLL shall be executed<br />
<li>an item used as public key or signature for each of the opcodes OP_CHECKSIG, OP_CHECKSIGVERIFY, OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY can be neither a public key or signature (for the given hash)<br />
<li>the number of signature items or the number of public key items on the stack is negative for OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY<br />
<li>there or more signatures items than public key items on the stack for OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY<br />
<li>there are (currently) more than 20 public key items on the stack for OP_CHECKMULTISIG or CHECKMULTISIGVERIFY<br />
<li>the sum of opcodes > 0x60 and the number of public keys in all executed OP_CHECKMULTISIG or CHECKMULTISIGVERIFY exceeds (currently) 201<br />
<li>the script execution has been finished and the stack is empty or the top-stack item is false (numerical value 0)<br />
</ul><br />
else the script evaluation is considered to be valid.<ref>[http://sourceforge.net/projects/bitcoin/files/Bitcoin/bitcoin-0.7.1/bitcoin-0.7.1-linux.tar.gz file src/src/script.cpp in bitcoin-0.7.1]</ref><br />
'''If invalidation of a script is triggered then the script is immediately finished.''' These arbitrary looking limitations of 10000, 201, 520, 1000 and 20 might be increased in the future -- they serve to prevent strong slow down of the evaluation of a script while not restricting its practical usage really.<br />
<br />
==Withdrawn and drafted opcodes==<br />
<br />
<ul><br />
<li> byte value 0x89 OP_NOTEQUAL defined in pre-0.1.0 bitcoin versions. Since 0.1.0 removed because of security concerns. <br />
<li> byte value 0xb1 [[BIP 0012 | OP_EVAL]] withdraw - poll was triggered but insufficient support. <br />
<li> byte value 0xb2 [[BIP 0017 | OP_CHECKHASHVERIFY]] withdraw - poll was triggered but insufficient support.<br />
</ul><br />
<br />
==See Also==<br />
* [[Transactions]]<br />
* [[Contracts]]<br />
<br />
==References==<br />
<references/><br />
<ul><br />
<li>[http://www.zorinaq.com/pub/bitcoin-0.1.0.tgz file src/script.cpp in bitcoin-0.1.0]</li><br />
</ul><br />
[[Category:Technical]]<br />
[[Category:Vocabulary]]</div>
Smtp
https://en.bitcoin.it/w/index.php?title=Script&diff=34900
Script
2013-01-11T12:38:53Z
<p>Smtp: /* Splice */</p>
<hr />
<div>Bitcoin uses a scripting system for [[transactions]]. [[Wikipedia:FORTH|Forth]]-like, Script is simple, stack-based, and processed from left to right. It is purposefully not Turing-complete, with no loops.<br />
<br />
A script is essentially a list of instructions recorded with each transaction that describe how the next person wanting to spend the Bitcoins being transferred can gain access to them.<br />
<br />
Scripts are big-endian and their sequences of bytes is interpreted as a sequence of opcodes with operands. Only opcodes with byte values less than 0x4f have additional operands.<br />
<br />
== Scripts and Bitcoin transactions ==<br />
The script for a typical Bitcoin transfer to destination Bitcoin address D simply encumbers future spending of the bitcoins with two things: the spender must provide<br />
# a public key that, when hashed, yields destination address D embedded in the script, and<br />
# a signature to show evidence of the private key corresponding to the public key just provided.<br />
<br />
Scripting provides the flexibility to change the parameters of what's needed to spend transferred Bitcoins. For example, the scripting system could be used to require two private keys, or a combination of several, or even no keys at all.<br />
<br />
A transaction is valid if nothing in the combined script triggers failure and the top stack item exists and is true (non-zero). The party who originally ''stored'' the Bitcoins now being spent, dictates the script operations that will occur ''last'' in order to release them for use in another transaction. The party wanting to spend them must provide the input(s) to the previously recorded script that results in those operations occurring last leaving behind true (non-zero) on the stack.<br><br />
Only the very first transaction in each bitcoin block has no input script (the entry there is called "coinbase"), because the Bitcoins created with the block are created from hot air and not released by a previous recorded script.<br />
<br />
== Stack ==<br />
<br />
The stacks hold byte vectors (there is the (main) stack and an alternative stack). Byte vectors are interpreted as little-endian variable-length integers with the most significant bit determining the sign of the integer. Thus 0x81 represents -1. 0x80 is another representation of zero (so called negative 0). Byte vectors are interpreted as Booleans where False is represented by any representation of zero, and True is represented by any representation of non-zero.<br />
<br />
== Opcode overview ==<br />
<br />
For each opcode is given: its nemonic without the leading OP_, its hexadecimal byte value, the number of stack items needed (poped) during execution, a semicolon and the number of stack items which has been pushed (after execution). A * after the needed stack items indicates that further bytes from the script following the current opcode are needed. A # indicates that items on the alternative stack are poped/pushed. A @ indicates that further (global) data from the transaction is needed. A / indicates alternatives of a value. <br/><br />
Different colors indicate different semantic execution groups of opcodes:<br />
{| style="background:none; font-size:100%; padding:0; border-collapse:collapse; text-align:center; line-height:2em;" border="0" align="center" <br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | copy a fixed number of bytes but at most 75 onto stack<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | copy bytes onto stack which number is given by a 1, 2 or 4 byte value.<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | copy 1 specific byte onto stack<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | undefined opcode<br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | a pseudo-opcode, unassigned for scripts<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | NOP or opcode is part of a IF-flow-control construction<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00ff00;" | (stack conditionally) invalidation of the script this opcode is part of<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | stack item is moved between main stack and alternate stack<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | stack item(s) is/are moved, copied or deleted<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0;" | byte vectors are appended or divided or their size is determined<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff;" | byte vectors are interpreted bit-position-independently<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | byte vectors are interpreted and processed as signed integers<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | a hash value is computed or a signature checked<br />
|}<br />
<p><br />
===Opcode byte-matrix===<br />
The opcode value 0x00 with nemonic OP_FALSE is also named OP_0 and the opcode value 0x51 with nemonic OP_1 as also named OP_TRUE.<br />
{| style="background:none; font-size:100%; padding:0; border-collapse:collapse; text-align:center; line-height:2em;" border="0" align="center" <br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" |_FALSE<br/> 0x00 <br/> 0 ; 1(0) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x01<br/> 0 *; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x02<br/> 0 *; 1(2)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x03<br/> 0 *; 1(3)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x04<br/> 0 *; 1(4)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x04<br/> 0 *; 1(5)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x06<br/> 0 *; 1(6)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x07<br/> 0 *; 1(7)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x08<br/> 0 *; 1(8)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x09<br/> 0 *; 1(9)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0a<br/> 0 *; 1(10)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0b<br/> 0 *; 1(11)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0c<br/> 0 *; 1(12)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0d<br/> 0 *; 1(13)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0e<br/> 0 *; 1(14)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0f<br/> 0 *; 1(15)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x10 <br/> 0 *; 1(16) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x11 <br/> 0 *; 1(17)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x12 <br/> 0 *; 1(18)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x13 <br/> 0 *; 1(19)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x14 <br/> 0 *; 1(20)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x15 <br/> 0 *; 1(21)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x16 <br/> 0 *; 1(22)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x17 <br/> 0 *; 1(23)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x18 <br/> 0 *; 1(24)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x19 <br/> 0 *; 1(25)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1a <br/> 0 *; 1(26)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1b <br/> 0 *; 1(27)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1c <br/> 0 *; 1(28)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1d <br/> 0 *; 1(29)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1e <br/> 0 *; 1(30)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1f <br/> 0 *; 1(31)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x20 <br/> 0 *; 1(32) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x21 <br/> 0 *; 1(33)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x22 <br/> 0 *; 1(34)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x23 <br/> 0 *; 1(35)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x24 <br/> 0 *; 1(36)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x25 <br/> 0 *; 1(37)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x26 <br/> 0 *; 1(38)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x27 <br/> 0 *; 1(39)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x28 <br/> 0 *; 1(40)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x29 <br/> 0 *; 1(41)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2a <br/> 0 *; 1(42)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2b <br/> 0 *; 1(43)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2c <br/> 0 *; 1(44)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2d <br/> 0 *; 1(45)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2e <br/> 0 *; 1(46)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2f <br/> 0 *; 1(47)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x30 <br/> 0 *; 1(48) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x31 <br/> 0 *; 1(49)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x32 <br/> 0 *; 1(50)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x33 <br/> 0 *; 1(51)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x34 <br/> 0 *; 1(52)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x35 <br/> 0 *; 1(53)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x36 <br/> 0 *; 1(54)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x37 <br/> 0 *; 1(55)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x38 <br/> 0 *; 1(56)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x39 <br/> 0 *; 1(57)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3a <br/> 0 *; 1(58)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3b <br/> 0 *; 1(59)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3c <br/> 0 *; 1(60)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3d <br/> 0 *; 1(61)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3e <br/> 0 *; 1(62)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3f <br/> 0 *; 1(63)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x40 <br/> 0 *; 1(64) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x41 <br/> 0 *; 1(65)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x42 <br/> 0 *; 1(66)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x43 <br/> 0 *; 1(67)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x44 <br/> 0 *; 1(68)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x45 <br/> 0 *; 1(69)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x46 <br/> 0 *; 1(70)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x47 <br/> 0 *; 1(71)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x48 <br/> 0 *; 1(72)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x49 <br/> 0 *; 1(73)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x4a <br/> 0 *; 1(74)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x4b <br/> 0 *; 1(75)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA1 <br/> 0x4c <br/> 0 *; 1(0 - 255)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA2 <br/> 0x4d <br/> 0 *; 1(0 - 2^16-1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA4 <br/> 0x4e <br/> 0 *; 1(0 - 2^32-1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _1NEGATE <br/> 0x4f <br/> 0 ; 1(1)<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED <br/> 0x50 <br/> <br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _1 <br/> 0x51 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _2 <br/> 0x52 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _3 <br/> 0x53 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _4 <br/> 0x54 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _5 <br/> 0x55 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _6 <br/> 0x56 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _7 <br/> 0x57 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _8 <br/> 0x58 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _9 <br/> 0x59 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _10 <br/> 0x5a <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _11 <br/> 0x5b <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _12 <br/> 0x5c <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _13 <br/> 0x5d <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _14 <br/> 0x5e <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _15 <br/> 0x5f <br/> 0 ; 1(1)<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _16 <br/> 0x60 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP <br/> 0x61 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VER <br/> 0x62 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _IF <br/> 0x63 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOTIF <br/> 0x64 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VERIF <br/> 0x65 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VERNOTIF <br/> 0x66 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _ELSE <br/> 0x67 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _ENDIF <br/> 0x68 <br/> 0 ; 0<br />
| style="border:3px solid #808080; background-color:#00ff00;" | _VERIFY <br/> 0x69 <br/> 1 ; 0/1<br />
| style="border:3px solid #808080; background-color:#00ff00;" | _RETURN <br/> 0x6a <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | _TOALTSTACK <br/> 0x6b <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | _FROMALTSTACK <br/> 0x6c <br/> 0 #; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2DROP <br/> 0x6d <br/> 2 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2DUP <br/> 0x6e <br/> 2 ; 4<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _3DUP <br/> 0x6f <br/> 3 ; 6<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2OVER <br/> 0x70 <br/> 4 ; 6<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2ROT <br/> 0x71 <br/> 6 ; 6<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2SWAP <br/> 0x72 <br/> 4 ; 4<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _IFDUP <br/> 0x73 <br/> 1 ; 1/2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DEPTH <br/> 0x74 <br/> 0 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DROP <br/> 0x75 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DUP <br/> 0x76 <br/> 1 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _NIP <br/> 0x77 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _OVER <br/> 0x78 <br/> 2 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _PICK <br/> 0x79 <br/> 1+n+1 ; n+2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _ROLL <br/> 0x7a <br/> 1+n+1 ; n+1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _ROT <br/> 0x7b <br/> 3 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _SWAP <br/> 0x7c <br/> 2 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _TUCK <br/> 0x7d <br/> 2 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _CAT <br/> 0x7e <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _SUBSTR <br/> 0x7f <br/> 3 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _LEFT <br/> 0x80 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _RIGHT <br/> 0x81 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0;" | _SIZE <br/> 0x82 <br/> 1 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _INVERT <br/> 0x83 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _AND <br/> 0x84 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _OR <br/> 0x85 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _XOR <br/> 0x86 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff;" | _EQUAL <br/> 0x87 <br/> 2 ; 1<br />
| style="border:3px solid #808080; background-color:#c080ff;" | _EQUALVERIFY <br/> 0x88 <br/> 2 ; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED1 <br/> 0x89 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED2 <br/> 0x8a <br/><br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _1ADD <br/> 0x8b <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _1SUB <br/> 0x8c <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _2MUL <br/> 0x8d <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _2DIV <br/> 0x8e <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NEGATE <br/> 0x8f <br/> 1 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _ABS <br/> 0x90 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NOT <br/> 0x91 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _0NOTEQUAL <br/> 0x92 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _ADD <br/> 0x93 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _SUB <br/> 0x94 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _MUL <br/> 0x95 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _DIV <br/> 0x96 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _MOD <br/> 0x97 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _LSHIFT <br/> 0x98 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _RSHIFT <br/> 0x99 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _BOOLAND <br/> 0x9a <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _BOOLOR <br/> 0x9b <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NUMEQUAL <br/> 0x9c <br/> 2 ; 1<br />
| style="border:3px solid #808080; background-color:#8080ff;" | _NUMEQUALVERIFY <br/> 0x9d <br/> 2 ; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NUMNOTEQUAL <br/> 0x9e <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _LESSTHAN <br/> 0x9f <br/> 2 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _GREATERTHAN <br/> 0xa0 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _LESSTHANOREQUAL <br/> 0xa1 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _GREATERTHANOREQUAL <br/> 0xa2 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _MIN <br/> 0xa3 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _MAX <br/> 0xa4 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _WITHIN <br/> 0xa5 <br/> 3 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _RIPEMD160 <br/> 0xa6 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _SHA1 <br/> 0xa7 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _SHA256 <br/> 0xa8 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _HASH160 <br/> 0xa9 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _HASH256 <br/> 0xaa <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CODESEPARATOR <br/> 0xab <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CHECKSIG <br/> 0xac <br/> 2 @; 1<br />
| style="border:3px solid #808080; background-color:#a0d0ff;" | _CHECKSIGVERIFY <br/> 0xad <br/> 2 @; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CHECKMULTISIG <br/> 0xae <br/> 2n+2 @; 1<br />
| style="border:3px solid #808080; background-color:#a0d0ff;" | _CHECKMULTISIGVERIFY <br/> 0xaf <br/> 2n+2 @; 0/1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP1 <br/> 0xb0 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP2 <br/> 0xb1 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP3 <br/> 0xb2 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP4 <br/> 0xb3 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP5 <br/> 0xb4 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP6 <br/> 0xb5 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP7 <br/> 0xb6 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP8 <br/> 0xb7 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP9 <br/> 0xb8 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP10 <br/> 0xb9 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xba <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbe <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xca <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xce <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xda <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xde <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xea <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xeb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xec <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xed <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xee <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xef <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xfa <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _SMALLINTEGER <br/> 0xfb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEYS <br/> 0xfc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEYHASH <br/> 0xfd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEY <br/> 0xfe <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _INVALIDOPCODE <br/> 0xff <br/><br />
|}<br><br />
Except later pseudo-opcode changes, the definition of OP_NOP1 - OP_NOP10 and the change of the evaluation of OP_RETURN (did no invalidation previously) which both occured in bitcoin version 0.3.6 in July 2010 were the last changes regarding opcodes <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.2.0/bitcoin-0.2.0-linux.tar.gz file src/srcipt.cpp in bitcoin-0.2.0]</ref> <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.3.3/bitcoin-0.3.3-linux.tar.gz file src/srcipt.cpp in bitcoin-0.3.3]</ref> <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.3.6/bitcoin-0.3.6-linux.tar.gz file src/srcipt.cpp in bitcoin-0.3.6]</ref>.<br />
<br />
== Opcode descriptions ==<br />
It follows for each opcode less than decimal 185 (hexa 0xba) a description for its usage. The columns entitled ''nemonic'', ''decimal'' and ''Hex'' should be evident. The column ''input'' gives the needed items of the stack (and the alternate stack) and the column ''output'' indicates the resulting items on the stack (and the alternate stack). '''Stack-top is always the right most item.''' The naming of the entries in these two columns is chosen to reflect their interpretation. ''x'',''x0'',''x1'',... means arbitrary or no interpretation, ''a'', ''b'' and ''c'' as a signed integer value, ''n'',''index'',''size'' and ''depth'' non-negative integer values, ''Boolean'' as either a true or false.<br><br />
<br />
Some of the more complicated opcodes are disabled out of concern that the client might have (and has) a bug in the current implementation due to the historically not as 2-complement interpretations of the byte vectors as numerical values (the most significant byte holds the sign of the byte vectors).<br />
<br />
=== Push data from instruction onto stack ===<br />
<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_FALSE, OP_0<br />
|0<br />
|0x00<br />
|Nothing<br />
|Empty string<br />
|A byte vector of length 0 is pushed onto the stack. (Thus, it is not a no-op!)<br />
|-<br />
|(no official nemonics)<br />
|1 - 75<br />
|0x01 - 0x4b<br />
|(operand)<br />
|x<br />
|The next <opcode>-many bytes are to be pushed onto the stack.<br />
|-<br />
|OP_PUSHDATA1<br />
|76<br />
|0x4c<br />
|(operands)<br />
|x<br />
|The next byte contains the number of bytes to be pushed onto the stack which follow this byte.<br />
|-<br />
|OP_PUSHDATA2<br />
|77<br />
|0x4d<br />
|(operands)<br />
|x<br />
|The next two bytes contain the number of bytes to be pushed onto the stack which follow theses 2 bytes.<br />
|-<br />
|OP_PUSHDATA4<br />
|78<br />
|0x4e<br />
|(operands)<br />
|x<br />
|The next four bytes contain the number of bytes to be pushed onto the stack which follow theses 4 bytes.<br />
|-<br />
|OP_1NEGATE<br />
|79<br />
|0x4f<br />
|Nothing<br />
| -1<br />
|The byte with value -1 is pushed onto the stack.<br />
|-<br />
|OP_1, OP_TRUE<br />
|81<br />
|0x51<br />
|Nothing<br />
|1<br />
|The byte with value 1 is pushed onto the stack.<br />
|-<br />
|OP_2 - OP_16<br />
|82 - 96<br />
|0x52 - 0x60<br />
|Nothing<br />
|2-16<br />
|The byte with value <opcode>-80 (thus, one of 2 - 16) is pushed onto the stack.<br />
|}<br />
<br />
=== Flow control ===<br />
<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_NOP<br />
|97<br />
|0x61<br />
|Nothing<br />
|Nothing<br />
|Does nothing.<br />
|-<br />
|OP_IF<br />
|99<br />
|0x63<br />
|Boolean<br />
|Nothing<br />
|If the top stack value is not 0, the statements are executed. The top stack value is removed. Lead in a logcial ''<value> then [statements] [else [statements]] endif'' expression<br />
|-<br />
|OP_NOTIF<br />
|100<br />
|0x64<br />
|Boolean<br />
|Nothing<br />
|If the top stack value is 0, the statements are executed. The top stack value is removed. Lead in a logcial ''<value> then [statements] [else [statements]] endif'' expression <br />
|-<br />
|OP_ELSE<br />
|103<br />
|0x67<br />
|Nothing<br />
|Nothing<br />
|If the preceeding OP_IF or OP_NOTIF or OP_ELSE was not executed then these statements are and if the preceding OP_IF or OP_NOTIF or OP_ELSE was executed then these statements are not. <br />
|-<br />
|OP_ENDIF<br />
|104<br />
|0x68<br />
|Nothing<br />
|Nothing<br />
|Ends a logcial ''If <value> then [statements] [else [statements]] '' expression<br />
|-<br />
|OP_VERIFY<br />
|105<br />
|0x69<br />
|Boolean<br />
|Nothing / False<br />
|If top stack value is not true then marks transaction as '''invalid''' . A value true is removed, but false is not.<br />
|-<br />
|OP_RETURN<br />
|106<br />
|0x6a<br />
|Nothing<br />
|Nothing<br />
|Marks transaction as '''invalid'''. <br />
|}<br />
<br />
===Stack item organization===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_TOALTSTACK<br />
|107<br />
|0x6b<br />
|x1 (alt)<br />
|(alt x1)<br />
|Puts the input onto the top of the alt stack. Removes it from the (main) stack.<br />
|-<br />
|OP_FROMALTSTACK<br />
|108<br />
|0x6c<br />
|(alt x1)<br />
|x1 (alt)<br />
|Puts the input onto the top of the (main) stack. Removes it from the alt stack.<br />
|-<br />
|OP_2DROP<br />
|109<br />
|0x6d<br />
|x2 x1<br />
|Nothing<br />
|Removes the top two stack items.<br />
|-<br />
|OP_2DUP<br />
|110<br />
|0x6e<br />
|x2 x1<br />
|x2 x1 x2 x1<br />
|Duplicates the top two stack items.<br />
|-<br />
|OP_3DUP<br />
|111<br />
|0x6f<br />
|x3 x2 x1<br />
|x3 x2 x1 x3 x2 x1<br />
|Duplicates the top three stack items.<br />
|-<br />
|OP_2OVER<br />
|112<br />
|0x70<br />
|x4 x3 x2 x1<br />
|x4 x3 x2 x1 x4 x3<br />
|Copies the pair of items two spaces back in the stack to the front.<br />
|-<br />
|OP_2ROT<br />
|113<br />
|0x71<br />
|x6 x5 x4 x3 x2 x1<br />
|x4 x3 x2 x1 x6 x5<br />
|The fifth and sixth items back are moved to the top of the stack. Twotimes left rotate.<br />
|-<br />
|OP_2SWAP<br />
|114<br />
|0x72<br />
|x4 x3 x2 x1<br />
|x2 x1 x4 x3<br />
|Swaps the top two pairs of stack items.<br />
|-<br />
|OP_IFDUP<br />
|115<br />
|0x73<br />
|x1<br />
|x1 / x1 x1<br />
|If the top stack value is not 0, duplicate it.<br />
|-<br />
|OP_DEPTH<br />
|116<br />
|0x74<br />
|Nothing<br />
|depth<br />
|Puts the number of stack items onto the stack as one little-endian coded byte-vector<br />
|-<br />
|OP_DROP<br />
|117<br />
|0x75<br />
|x1<br />
|Nothing<br />
|Removes the top stack item.<br />
|-<br />
|OP_DUP<br />
|118<br />
|0x76<br />
|x1<br />
|x1 x1<br />
|Duplicates the top stack item.<br />
|-<br />
|OP_NIP<br />
|119<br />
|0x77<br />
|x2 x1<br />
|x1<br />
|Removes the second-to-top stack item.<br />
|-<br />
|OP_OVER<br />
|120<br />
|0x78<br />
|x2 x1<br />
|x2 x1 x2<br />
|Copies the second-to-top stack item to the top.<br />
|-<br />
|OP_PICK<br />
|121<br />
|0x79<br />
|xn ... x2 x1 x0 <n><br />
|xn ... x2 x1 x0 xn<br />
|<n> is removed and the item ''n'' back in the stack is copied to the top.<br />
|-<br />
|OP_ROLL<br />
|122<br />
|0x7a<br />
|xn ... x2 x1 x0 <n><br />
|... x2 x1 x0 xn<br />
|<n> is removed and the item ''n'' back in the stack is moved to the top.<br />
|-<br />
|OP_ROT<br />
|123<br />
|0x7b<br />
|x3 x2 x1<br />
|x2 x1 x3<br />
|The top three items on the stack are rotated to the left.<br />
|-<br />
|OP_SWAP<br />
|124<br />
|0x7c<br />
|x2 x1<br />
|x1 x2<br />
|The top two items on the stack are swapped resp. rotated.<br />
|-<br />
|OP_TUCK<br />
|125<br />
|0x7d<br />
|x2 x1<br />
|x1 x2 x1<br />
|The item at the top of the stack is copied and inserted before the second-to-top item.<br />
|}<br />
<br />
=== Splice ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_CAT<br />
|126<br />
|0x7e<br />
|x2 x1<br />
|out<br />
|Appends stack-top item at second-to top item. Concatenates two strings resp. byte vectors. ''Currently disabled.''<br />
|-<br />
|OP_SUBSTR<br />
|127<br />
|0x7f<br />
|x3 index size<br />
|out<br />
|Returns the section started at position <index> and of length <size> of a string resp. byte vector. ''Currently disabled.''<br />
|-<br />
|OP_LEFT<br />
|128<br />
|0x80<br />
|x2 index<br />
|out<br />
|Keeps only characters left of the specified point in second-to top item. ''Currently disabled.''<br />
|-<br />
|OP_RIGHT<br />
|129<br />
|0x81<br />
|x2 index<br />
|out<br />
|Keeps only characters right of the specified point in second-to top item. ''Currently disabled.''<br />
|-<br />
|OP_SIZE<br />
|130<br />
|0x82<br />
|x1<br />
|x1 size<br />
|Returns the length of the input string resp. byte vector resp. top-stack item.<br />
|}<br />
<br />
=== Bitwise logic ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_INVERT<br />
|131<br />
|0x83<br />
|x1<br />
|x0<br />
|Flips all of the bits in the input. ''Currently disabled.''<br />
|-<br />
|OP_AND<br />
|132<br />
|0x84<br />
|x1 x2<br />
|x0<br />
|Boolean ''and'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_OR<br />
|133<br />
|0x85<br />
|x1 x2<br />
|x0<br />
|Boolean ''or'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_XOR<br />
|134<br />
|0x86<br />
|x1 x2<br />
|x0<br />
|Boolean ''exclusive or'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_EQUAL<br />
|135<br />
|0x87<br />
|x1 x2<br />
|Boolean<br />
|Returns 1 if the inputs are byte-wise equal, 0 otherwise.<br />
|-<br />
|OP_EQUALVERIFY<br />
|136<br />
|0x88<br />
|x1 x2<br />
|Nothing / false<br />
|Same as OP_EQUAL, but runs OP_VERIFY afterward.<br />
|}<br />
<br />
=== Arithmetic ===<br />
<br />
(In very early versions, the implemented arithmetic opcodes were limited to maximal 4 byte vectors.)<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_1ADD<br />
|139<br />
|0x8b<br />
|a<br />
|c<br />
|1 is added to the input.<br />
|-<br />
|OP_1SUB<br />
|140<br />
|0x8c<br />
|a<br />
|c<br />
|1 is subtracted from the input.<br />
|-<br />
|OP_2MUL<br />
|141<br />
|0x8d<br />
|a<br />
|c<br />
|The input is multiplied by 2. ''Currently disabled.''<br />
|-<br />
|OP_2DIV<br />
|142<br />
|0x8e<br />
|a<br />
|c<br />
|The input is divided by 2. ''Currently disabled.''<br />
|-<br />
|OP_NEGATE<br />
|143<br />
|0x8f<br />
|a<br />
|c<br />
|The sign of the input is flipped. Numerically the value is multiplied by -1<br />
|-<br />
|OP_ABS<br />
|144<br />
|0x90<br />
|a<br />
|c<br />
|The input is negative, its sign is flipped.<br />
|-<br />
|OP_NOT<br />
|145<br />
|0x91<br />
|a<br />
|Boolean<br />
|If the input is 0 or 1, it is flipped. Otherwise the output will be 0. Test whether its value equals 0<br />
|-<br />
|OP_0NOTEQUAL<br />
|146<br />
|0x92<br />
|a<br />
|Boolean<br />
|Returns 0 if the input is 0. 1 otherwise. Test whether its value is unequal 0<br />
|-<br />
|OP_ADD<br />
|147<br />
|0x93<br />
|a b<br />
|c<br />
|a is added to b.<br />
|-<br />
|OP_SUB<br />
|148<br />
|0x94<br />
|a b<br />
|c<br />
|b is subtracted from a.<br />
|-<br />
|OP_MUL<br />
|149<br />
|0x95<br />
|a b<br />
|c<br />
|a is multiplied by b. ''Currently disabled.''<br />
|-<br />
|OP_DIV<br />
|150<br />
|0x96<br />
|a b<br />
|c<br />
|a is divided by b (b should be not 0). ''Currently disabled.''<br />
|-<br />
|OP_MOD<br />
|151<br />
|0x97<br />
|a b<br />
|c<br />
|Returns the remainder after dividing a by b (b should be not 0). ''Currently disabled.''<br />
|-<br />
|OP_LSHIFT<br />
|152<br />
|0x98<br />
|a b<br />
|c<br />
|Shifts a left by b bits, preserving sign. ''Currently disabled.''<br />
|-<br />
|OP_RSHIFT<br />
|153<br />
|0x99<br />
|a b<br />
|c<br />
|Shifts a right by b bits, preserving sign. ''Currently disabled.''<br />
|-<br />
|OP_BOOLAND<br />
|154<br />
|0x9a<br />
|a b<br />
|Boolean<br />
|If both a and b are not 0, the output is 1. Otherwise 0.<br />
|-<br />
|OP_BOOLOR<br />
|155<br />
|0x9b<br />
|a b<br />
|Boolean<br />
|If a or b is not 0, the output is 1. Otherwise 0.<br />
|-<br />
|OP_NUMEQUAL<br />
|156<br />
|0x9c<br />
|a b<br />
|Boolean<br />
|Returns 1 if the numbers are equal, 0 otherwise.<br />
|-<br />
|OP_NUMEQUALVERIFY<br />
|157<br />
|0x9d<br />
|a b<br />
|Nothing / False<br />
|Same as OP_NUMEQUAL, but runs OP_VERIFY afterward.<br />
|-<br />
|OP_NUMNOTEQUAL<br />
|158<br />
|0x9e<br />
|a b<br />
|Boolean<br />
|Returns 1 if the numbers are not equal, 0 otherwise.<br />
|-<br />
|OP_LESSTHAN<br />
|159<br />
|0x9f<br />
|a b<br />
|Boolean<br />
|Returns 1 if a is less than b, 0 otherwise.<br />
|-<br />
|OP_GREATERTHAN<br />
|160<br />
|0xa0<br />
|a b<br />
|Boolean<br />
|Returns 1 if a is greater than b, 0 otherwise.<br />
|-<br />
|OP_LESSTHANOREQUAL<br />
|161<br />
|0xa1<br />
|a b<br />
|Boolean<br />
|Returns 1 if a is less than or equal to b, 0 otherwise.<br />
|-<br />
|OP_GREATERTHANOREQUAL<br />
|162<br />
|0xa2<br />
|a b<br />
|Boolean<br />
|Returns 1 if a is greater than or equal to b, 0 otherwise.<br />
|-<br />
|OP_MIN<br />
|163<br />
|0xa3<br />
|a b<br />
|a / b<br />
|Returns the smaller of a and b.<br />
|-<br />
|OP_MAX<br />
|164<br />
|0xa4<br />
|a b<br />
| a / b<br />
|Returns the larger of a and b.<br />
|-<br />
|OP_WITHIN<br />
|165<br />
|0xa5<br />
|x min max<br />
|Boolean<br />
|Returns 1 if x is within the specified range (left-inclusive) , 0 otherwise. min may be greater than max<br />
|}<br />
<br />
=== Crypto ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_RIPEMD160<br />
|166<br />
|0xa6<br />
|x<br />
|hash20<br />
|The input is hashed using RIPEMD-160.<br />
|-<br />
|OP_SHA1<br />
|167<br />
|0xa7<br />
|x<br />
|hash20<br />
|The input is hashed using SHA-1.<br />
|-<br />
|OP_SHA256<br />
|168<br />
|0xa8<br />
|x<br />
|hash32<br />
|The input is hashed using SHA-256.<br />
|-<br />
|OP_HASH160<br />
|169<br />
|0xa9<br />
|x<br />
|hash20<br />
|The input is hashed twice: first with SHA-256 and then with RIPEMD-160.<br />
|-<br />
|OP_HASH256<br />
|170<br />
|0xaa<br />
|x<br />
|hash32<br />
|The input is hashed two times with SHA-256.<br />
|-<br />
|OP_CODESEPARATOR<br />
|171<br />
|0xab<br />
|Nothing<br />
|Nothing<br />
|All of the signature checking opcodes will only match signatures to the data after the most recently-executed OP_CODESEPARATOR.<br />
|-<br />
|[[OP_CHECKSIG]]<br />
|172<br />
|0xac<br />
|sig pubkey<br />
|Boolean<br />
|The entire transaction's outputs, inputs, and script (from the most recently-executed OP_CODESEPARATOR to the end) are hashed. The signature used by OP_CHECKSIG must be a valid signature for a further, extern specified hash and the given public key. If it is, 1 is returned, 0 otherwise.<br />
|-<br />
|OP_CHECKSIGVERIFY<br />
|173<br />
|0xad<br />
|sig pubkey<br />
|Nothing / False<br />
|Same as OP_CHECKSIG, but OP_VERIFY is executed afterward.<br />
|-<br />
|OP_CHECKMULTISIG<br />
|174<br />
|0xae<br />
|sig1 sig2 ... <number of signatures> pub1 pub2 <number of public keys><br />
|Boolean<br />
|For each signature and public key pair, OP_CHECKSIG is executed. If more public keys than signatures are listed, some key/sig pairs can fail. All signatures need to match a public key. If all signatures are valid, 1 is returned, 0 otherwise. Due to a bug, one extra unused value is removed from the stack.<br />
|-<br />
|OP_CHECKMULTISIGVERIFY<br />
|175<br />
|0xaf<br />
|sig1 sig2 ... <number of signatures> pub1 pub2 ... <number of public keys><br />
|Nothing / False<br />
|Same as OP_CHECKMULTISIG, but OP_VERIFY is executed afterward.<br />
|}<br />
<br />
=== Expansion opcodes ===<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_NOP1-OP_NOP10<br />
|176-185<br />
|0xb0-0xb9<br />
|The opcode has no effect.<br />
|}<br />
<br />
=== Version opcodes ===<br />
Version opcodes are disabled since bitcoin 0.2.0 and should not be used (maybe reassigned in the future).<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_VER<br />
|98<br />
|0x62<br />
|Script evalution is triggered invalid (Formerly pushed the bitcoin-serialize version onto stack).<br />
|-<br />
|OP_VERIF<br />
|101<br />
|0x65<br />
|Script evalution is triggered invalid (Formerly top stack item was popped and =< compared to present version)<br />
|-<br />
|OP_VERNOTIF<br />
|102<br />
|0x66<br />
|Script evalution is triggered invalid (Formerly top stack item was popped and > compared to present version)<br />
|}<br />
<br />
=== Reserved opcodes ===<br />
Each opcode not assigned (currently also every opcode value > 185) is also reserved. Using any unassigned opcode triggers the script evaluation to be invalid.<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_RESERVED<br />
|80<br />
|0x50<br />
|Script evalution is triggered invalid-<br />
|-<br />
|OP_RESERVED1<br />
|137<br />
|0x89<br />
|Script evalution is triggered invalid.<br />
|-<br />
|OP_RESERVED2<br />
|138<br />
|0x8a<br />
|Script evalution is triggered invalid.<br />
|}<br />
<br />
===Pseudo-opcodes===<br />
These nemonics are used internally for assisting with transaction matching. They are invalid if used in actual scripts.<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_PUBKEYHASH<br />
|253<br />
|0xfd<br />
|Represents a public key hashed with OP_HASH160.<br />
|-<br />
|OP_PUBKEY<br />
|254<br />
|0xfe<br />
|Represents a public key compatible with OP_CHECKSIG.<br />
|-<br />
|OP_INVALIDOPCODE<br />
|255<br />
|0xff<br />
|Matches any opcode that is not yet assigned.<br />
|}<br />
<br />
==Scripts in bitcoin transactions==<br />
It follows a list of important (most occuring) scripts to see opcodes "at work". Keep in mind that all constants actually use the data-pushing instructions above. At start of a (transaction input) script evaluation, the stack is always empty. <br />
<br />
===Standard transaction to bitcoin address===<br />
<br />
scriptPubKey: OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG<br />
scriptSig: <sig> <pubKey><br />
<br />
To demonstrate how scripts look on the wire, here is a raw scriptPubKey:<br />
<pre> 76 A9 14<br />
OP_DUP OP_HASH160 Bytes to push<br />
<br />
89 AB CD EF AB BA AB BA AB BA AB BA AB BA AB BA AB BA AB BA 88 AC<br />
Data to push OP_EQUALVERIFY OP_CHECKSIG</pre><br />
<br />
Note: scriptSig is in the input of the spending transaction and scriptPubKey is in the output of the previously storing transaction, i.e. its "available bitcoins".<br />
<br />
Here is how each instruction is processed:<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
| <sig> <pubKey> OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| scriptSig and scriptPubKey are combined.<br />
|-<br />
|<sig> <pubKey><br />
| OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| Constants are added to the stack.<br />
|-<br />
|<sig> <pubKey> <pubKey><br />
| OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| Top stack item is duplicated.<br />
|-<br />
|<sig> <pubKey> <pubHashA><br />
|<pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG<br />
| Top stack item is hashed.<br />
|-<br />
|<sig> <pubKey> <pubHashA> <pubKeyHash><br />
|OP_EQUALVERIFY OP_CHECKSIG<br />
| Constant added.<br />
|-<br />
|<sig> <pubKey><br />
|OP_CHECKSIG<br />
| Equality is checked between the top two stack items.<br />
|-<br />
|true<br />
|Empty.<br />
|Signature is checked for top two stack items.<br />
|}<br />
<br />
===Transaction to IP address (and generation transaction)===<br />
<br />
scriptPubKey: <pubKey> OP_CHECKSIG<br />
scriptSig: <sig><br />
<br />
Checking process:<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
|<sig> <pubKey> OP_CHECKSIG<br />
|scriptSig and scriptPubKey are combined.<br />
|-<br />
|<sig> <pubKey><br />
| OP_CHECKSIG<br />
|Constants are added to the stack.<br />
|-<br />
|true<br />
|Empty.<br />
|Signature is checked for top two stack items.<br />
|}<br />
<br />
In the case of a '''coin generation transaction''' (the first transaction of each block), there is no scriptSig, resp. its code ("coinbase") is completly ignored for the transaction. Only the scriptPubKey is used.<br />
<br />
===Transaction with a message===<br />
<br />
It's possible to add arbitrary data to any transaction by just adding some data along with OP_DROP. <br />
scriptPubKey: <message> OP_DROP <pubKey> OP_CHECKSIG<br />
scriptSig: <sig><br />
<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
|<sig> <message> OP_DROP <pubKey> OP_CHECKSIG<br />
|<br />
|-<br />
|<sig><br />
|<message> OP_DROP <pubKey> OP_CHECKSIG<br />
|scriptSig added to the stack.<br />
|-<br />
|<sig> <message><br />
|OP_DROP <pubKey> OP_CHECKSIG<br />
|The message has been put.<br />
|-<br />
|<sig><br />
|<pubKey> OP_CHECKSIG<br />
|Top stack item has been removed.<br />
|-<br />
|<sig> <pubKey><br />
|OP_CHECKSIG<br />
|Checking signature against the public key.<br />
|-<br />
|true<br />
|Empty.<br />
|Stack holds the value of signature check now.<br />
|}<br />
<br />
===Examples of non standard transaction on Testnet===<br />
<br />
These two links below show a non standard transaction. It just prepends the hex of "bob" and the operation OP_DROP<br />
which just removes it. As you can see they can be spent as normal.<br />
<br />
Input non-std transaction:<br />
http://blockexplorer.com/testnet/t/6ttfeb55B1<br />
<br />
Spent by:<br />
http://blockexplorer.com/testnet/t/AFdRB1CHS3<br />
<br />
==Script validation==<br />
A script evaluation is considered invalid, if any of these conditions meets:<br><br />
<ul><br />
<li>the total size of the script exceeds (currently) 10000 bytes<br />
<li>there are more than (currently) 201 opcodes of opcode value > 0x60 in the script<br />
<li>each instruction is (currently) limited to maximal 520 bytes. This effects only the opcodes OP_PUSHDATA2 and OP_PUSHDATA4<br />
<li>the executed opcode of the script has insufficient input (from stack, from script or from anywhere)<br />
<li>the opcode is not defined (for execution) - indicated by white or light gray background color in the table<br />
<li>the opcode is disabled (currently 15 opcodes) - indicated by white font color in the opcode overview matrix<br />
<li>stack overflow occurs during execution of the opcode (currently the number of items on the stack and on the alternate stack is limited to 1000)<br />
<li>the opcodes OP_VERIF and OP_NOTVERIF invalidate a script which contains this opcode (even if this opcode is not executed!)<br />
<li>the opcodes OP_ELSE or OP_ENDIF has no matching OP_IF<br><br />
<li>the script execution has been finished but there is (at least) an unmatched OP_IF<br><br />
<li>the opcodes OP_VERIFY, OP_EQUALVERIFY, OP_NUMEQUALVERIFY, OP_CHECKSIGVERIFY and OP_CHECKMULTISIGVERIFY invalidate the script if the stack-top item is false<br />
<li>the execution of OP_RETURN<br />
<!--li>alt stack overflow occurs (only possible during execution of OP_TOALTSTACK)--><br />
<li>the numerical value of the top-stack item is negative or greater than the number of items - 2 on the stack if OP_PICK or OP_ROLL shall be executed<br />
<li>an item used as public key or signature for each of the opcodes OP_CHECKSIG, OP_CHECKSIGVERIFY, OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY can be neither a public key or signature (for the given hash)<br />
<li>the number of signature items or the number of public key items on the stack is negative for OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY<br />
<li>there or more signatures items than public key items on the stack for OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY<br />
<li>there are (currently) more than 20 public key items on the stack for OP_CHECKMULTISIG or CHECKMULTISIGVERIFY<br />
<li>the sum of opcodes > 0x60 and the number of public keys in all executed OP_CHECKMULTISIG or CHECKMULTISIGVERIFY exceeds (currently) 201<br />
<li>the script execution has been finished and the stack is empty or the top-stack item is false (numerical value 0)<br />
</ul><br />
else the script evaluation is considered to be valid.<ref>[http://sourceforge.net/projects/bitcoin/files/Bitcoin/bitcoin-0.7.1/bitcoin-0.7.1-linux.tar.gz file src/src/script.cpp in bitcoin-0.7.1]</ref><br />
'''If invalidation of a script is triggered then the script is immediately finished.''' These arbitrary looking limitations of 10000, 201, 520, 1000 and 20 might be increased in the future -- they serve to prevent strong slow down of the evaluation of a script while not restricting its practical usage really.<br />
<br />
==Withdrawn and drafted opcodes==<br />
<br />
<ul><br />
<li> byte value 0x89 OP_NOTEQUAL defined in pre-0.1.0 bitcoin versions. Since 0.1.0 removed because of security concerns. <br />
<li> byte value 0xb1 [[BIP 0012 | OP_EVAL]] withdraw - poll was triggered but insufficient support. <br />
<li> byte value 0xb2 [[BIP 0017 | OP_CHECKHASHVERIFY]] withdraw - poll was triggered but insufficient support.<br />
</ul><br />
<br />
==See Also==<br />
* [[Transactions]]<br />
* [[Contracts]]<br />
<br />
==References==<br />
<references/><br />
<ul><br />
<li>[http://www.zorinaq.com/pub/bitcoin-0.1.0.tgz file src/script.cpp in bitcoin-0.1.0]</li><br />
</ul><br />
[[Category:Technical]]<br />
[[Category:Vocabulary]]</div>
Smtp
https://en.bitcoin.it/w/index.php?title=Script&diff=34899
Script
2013-01-11T12:29:16Z
<p>Smtp: /* Stack item organization */</p>
<hr />
<div>Bitcoin uses a scripting system for [[transactions]]. [[Wikipedia:FORTH|Forth]]-like, Script is simple, stack-based, and processed from left to right. It is purposefully not Turing-complete, with no loops.<br />
<br />
A script is essentially a list of instructions recorded with each transaction that describe how the next person wanting to spend the Bitcoins being transferred can gain access to them.<br />
<br />
Scripts are big-endian and their sequences of bytes is interpreted as a sequence of opcodes with operands. Only opcodes with byte values less than 0x4f have additional operands.<br />
<br />
== Scripts and Bitcoin transactions ==<br />
The script for a typical Bitcoin transfer to destination Bitcoin address D simply encumbers future spending of the bitcoins with two things: the spender must provide<br />
# a public key that, when hashed, yields destination address D embedded in the script, and<br />
# a signature to show evidence of the private key corresponding to the public key just provided.<br />
<br />
Scripting provides the flexibility to change the parameters of what's needed to spend transferred Bitcoins. For example, the scripting system could be used to require two private keys, or a combination of several, or even no keys at all.<br />
<br />
A transaction is valid if nothing in the combined script triggers failure and the top stack item exists and is true (non-zero). The party who originally ''stored'' the Bitcoins now being spent, dictates the script operations that will occur ''last'' in order to release them for use in another transaction. The party wanting to spend them must provide the input(s) to the previously recorded script that results in those operations occurring last leaving behind true (non-zero) on the stack.<br><br />
Only the very first transaction in each bitcoin block has no input script (the entry there is called "coinbase"), because the Bitcoins created with the block are created from hot air and not released by a previous recorded script.<br />
<br />
== Stack ==<br />
<br />
The stacks hold byte vectors (there is the (main) stack and an alternative stack). Byte vectors are interpreted as little-endian variable-length integers with the most significant bit determining the sign of the integer. Thus 0x81 represents -1. 0x80 is another representation of zero (so called negative 0). Byte vectors are interpreted as Booleans where False is represented by any representation of zero, and True is represented by any representation of non-zero.<br />
<br />
== Opcode overview ==<br />
<br />
For each opcode is given: its nemonic without the leading OP_, its hexadecimal byte value, the number of stack items needed (poped) during execution, a semicolon and the number of stack items which has been pushed (after execution). A * after the needed stack items indicates that further bytes from the script following the current opcode are needed. A # indicates that items on the alternative stack are poped/pushed. A @ indicates that further (global) data from the transaction is needed. A / indicates alternatives of a value. <br/><br />
Different colors indicate different semantic execution groups of opcodes:<br />
{| style="background:none; font-size:100%; padding:0; border-collapse:collapse; text-align:center; line-height:2em;" border="0" align="center" <br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | copy a fixed number of bytes but at most 75 onto stack<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | copy bytes onto stack which number is given by a 1, 2 or 4 byte value.<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | copy 1 specific byte onto stack<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | undefined opcode<br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | a pseudo-opcode, unassigned for scripts<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | NOP or opcode is part of a IF-flow-control construction<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00ff00;" | (stack conditionally) invalidation of the script this opcode is part of<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | stack item is moved between main stack and alternate stack<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | stack item(s) is/are moved, copied or deleted<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0;" | byte vectors are appended or divided or their size is determined<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff;" | byte vectors are interpreted bit-position-independently<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | byte vectors are interpreted and processed as signed integers<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | a hash value is computed or a signature checked<br />
|}<br />
<p><br />
===Opcode byte-matrix===<br />
The opcode value 0x00 with nemonic OP_FALSE is also named OP_0 and the opcode value 0x51 with nemonic OP_1 as also named OP_TRUE.<br />
{| style="background:none; font-size:100%; padding:0; border-collapse:collapse; text-align:center; line-height:2em;" border="0" align="center" <br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" |_FALSE<br/> 0x00 <br/> 0 ; 1(0) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x01<br/> 0 *; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x02<br/> 0 *; 1(2)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x03<br/> 0 *; 1(3)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x04<br/> 0 *; 1(4)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x04<br/> 0 *; 1(5)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x06<br/> 0 *; 1(6)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x07<br/> 0 *; 1(7)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x08<br/> 0 *; 1(8)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x09<br/> 0 *; 1(9)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0a<br/> 0 *; 1(10)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0b<br/> 0 *; 1(11)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0c<br/> 0 *; 1(12)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0d<br/> 0 *; 1(13)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0e<br/> 0 *; 1(14)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0f<br/> 0 *; 1(15)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x10 <br/> 0 *; 1(16) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x11 <br/> 0 *; 1(17)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x12 <br/> 0 *; 1(18)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x13 <br/> 0 *; 1(19)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x14 <br/> 0 *; 1(20)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x15 <br/> 0 *; 1(21)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x16 <br/> 0 *; 1(22)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x17 <br/> 0 *; 1(23)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x18 <br/> 0 *; 1(24)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x19 <br/> 0 *; 1(25)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1a <br/> 0 *; 1(26)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1b <br/> 0 *; 1(27)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1c <br/> 0 *; 1(28)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1d <br/> 0 *; 1(29)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1e <br/> 0 *; 1(30)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1f <br/> 0 *; 1(31)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x20 <br/> 0 *; 1(32) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x21 <br/> 0 *; 1(33)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x22 <br/> 0 *; 1(34)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x23 <br/> 0 *; 1(35)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x24 <br/> 0 *; 1(36)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x25 <br/> 0 *; 1(37)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x26 <br/> 0 *; 1(38)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x27 <br/> 0 *; 1(39)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x28 <br/> 0 *; 1(40)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x29 <br/> 0 *; 1(41)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2a <br/> 0 *; 1(42)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2b <br/> 0 *; 1(43)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2c <br/> 0 *; 1(44)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2d <br/> 0 *; 1(45)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2e <br/> 0 *; 1(46)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2f <br/> 0 *; 1(47)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x30 <br/> 0 *; 1(48) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x31 <br/> 0 *; 1(49)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x32 <br/> 0 *; 1(50)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x33 <br/> 0 *; 1(51)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x34 <br/> 0 *; 1(52)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x35 <br/> 0 *; 1(53)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x36 <br/> 0 *; 1(54)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x37 <br/> 0 *; 1(55)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x38 <br/> 0 *; 1(56)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x39 <br/> 0 *; 1(57)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3a <br/> 0 *; 1(58)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3b <br/> 0 *; 1(59)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3c <br/> 0 *; 1(60)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3d <br/> 0 *; 1(61)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3e <br/> 0 *; 1(62)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3f <br/> 0 *; 1(63)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x40 <br/> 0 *; 1(64) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x41 <br/> 0 *; 1(65)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x42 <br/> 0 *; 1(66)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x43 <br/> 0 *; 1(67)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x44 <br/> 0 *; 1(68)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x45 <br/> 0 *; 1(69)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x46 <br/> 0 *; 1(70)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x47 <br/> 0 *; 1(71)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x48 <br/> 0 *; 1(72)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x49 <br/> 0 *; 1(73)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x4a <br/> 0 *; 1(74)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x4b <br/> 0 *; 1(75)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA1 <br/> 0x4c <br/> 0 *; 1(0 - 255)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA2 <br/> 0x4d <br/> 0 *; 1(0 - 2^16-1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA4 <br/> 0x4e <br/> 0 *; 1(0 - 2^32-1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _1NEGATE <br/> 0x4f <br/> 0 ; 1(1)<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED <br/> 0x50 <br/> <br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _1 <br/> 0x51 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _2 <br/> 0x52 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _3 <br/> 0x53 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _4 <br/> 0x54 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _5 <br/> 0x55 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _6 <br/> 0x56 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _7 <br/> 0x57 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _8 <br/> 0x58 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _9 <br/> 0x59 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _10 <br/> 0x5a <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _11 <br/> 0x5b <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _12 <br/> 0x5c <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _13 <br/> 0x5d <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _14 <br/> 0x5e <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _15 <br/> 0x5f <br/> 0 ; 1(1)<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _16 <br/> 0x60 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP <br/> 0x61 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VER <br/> 0x62 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _IF <br/> 0x63 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOTIF <br/> 0x64 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VERIF <br/> 0x65 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VERNOTIF <br/> 0x66 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _ELSE <br/> 0x67 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _ENDIF <br/> 0x68 <br/> 0 ; 0<br />
| style="border:3px solid #808080; background-color:#00ff00;" | _VERIFY <br/> 0x69 <br/> 1 ; 0/1<br />
| style="border:3px solid #808080; background-color:#00ff00;" | _RETURN <br/> 0x6a <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | _TOALTSTACK <br/> 0x6b <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | _FROMALTSTACK <br/> 0x6c <br/> 0 #; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2DROP <br/> 0x6d <br/> 2 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2DUP <br/> 0x6e <br/> 2 ; 4<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _3DUP <br/> 0x6f <br/> 3 ; 6<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2OVER <br/> 0x70 <br/> 4 ; 6<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2ROT <br/> 0x71 <br/> 6 ; 6<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2SWAP <br/> 0x72 <br/> 4 ; 4<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _IFDUP <br/> 0x73 <br/> 1 ; 1/2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DEPTH <br/> 0x74 <br/> 0 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DROP <br/> 0x75 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DUP <br/> 0x76 <br/> 1 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _NIP <br/> 0x77 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _OVER <br/> 0x78 <br/> 2 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _PICK <br/> 0x79 <br/> 1+n+1 ; n+2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _ROLL <br/> 0x7a <br/> 1+n+1 ; n+1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _ROT <br/> 0x7b <br/> 3 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _SWAP <br/> 0x7c <br/> 2 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _TUCK <br/> 0x7d <br/> 2 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _CAT <br/> 0x7e <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _SUBSTR <br/> 0x7f <br/> 3 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _LEFT <br/> 0x80 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _RIGHT <br/> 0x81 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0;" | _SIZE <br/> 0x82 <br/> 1 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _INVERT <br/> 0x83 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _AND <br/> 0x84 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _OR <br/> 0x85 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _XOR <br/> 0x86 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff;" | _EQUAL <br/> 0x87 <br/> 2 ; 1<br />
| style="border:3px solid #808080; background-color:#c080ff;" | _EQUALVERIFY <br/> 0x88 <br/> 2 ; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED1 <br/> 0x89 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED2 <br/> 0x8a <br/><br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _1ADD <br/> 0x8b <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _1SUB <br/> 0x8c <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _2MUL <br/> 0x8d <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _2DIV <br/> 0x8e <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NEGATE <br/> 0x8f <br/> 1 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _ABS <br/> 0x90 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NOT <br/> 0x91 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _0NOTEQUAL <br/> 0x92 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _ADD <br/> 0x93 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _SUB <br/> 0x94 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _MUL <br/> 0x95 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _DIV <br/> 0x96 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _MOD <br/> 0x97 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _LSHIFT <br/> 0x98 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _RSHIFT <br/> 0x99 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _BOOLAND <br/> 0x9a <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _BOOLOR <br/> 0x9b <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NUMEQUAL <br/> 0x9c <br/> 2 ; 1<br />
| style="border:3px solid #808080; background-color:#8080ff;" | _NUMEQUALVERIFY <br/> 0x9d <br/> 2 ; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NUMNOTEQUAL <br/> 0x9e <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _LESSTHAN <br/> 0x9f <br/> 2 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _GREATERTHAN <br/> 0xa0 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _LESSTHANOREQUAL <br/> 0xa1 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _GREATERTHANOREQUAL <br/> 0xa2 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _MIN <br/> 0xa3 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _MAX <br/> 0xa4 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _WITHIN <br/> 0xa5 <br/> 3 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _RIPEMD160 <br/> 0xa6 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _SHA1 <br/> 0xa7 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _SHA256 <br/> 0xa8 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _HASH160 <br/> 0xa9 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _HASH256 <br/> 0xaa <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CODESEPARATOR <br/> 0xab <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CHECKSIG <br/> 0xac <br/> 2 @; 1<br />
| style="border:3px solid #808080; background-color:#a0d0ff;" | _CHECKSIGVERIFY <br/> 0xad <br/> 2 @; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CHECKMULTISIG <br/> 0xae <br/> 2n+2 @; 1<br />
| style="border:3px solid #808080; background-color:#a0d0ff;" | _CHECKMULTISIGVERIFY <br/> 0xaf <br/> 2n+2 @; 0/1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP1 <br/> 0xb0 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP2 <br/> 0xb1 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP3 <br/> 0xb2 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP4 <br/> 0xb3 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP5 <br/> 0xb4 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP6 <br/> 0xb5 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP7 <br/> 0xb6 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP8 <br/> 0xb7 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP9 <br/> 0xb8 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP10 <br/> 0xb9 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xba <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbe <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xca <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xce <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xda <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xde <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xea <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xeb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xec <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xed <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xee <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xef <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xfa <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _SMALLINTEGER <br/> 0xfb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEYS <br/> 0xfc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEYHASH <br/> 0xfd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEY <br/> 0xfe <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _INVALIDOPCODE <br/> 0xff <br/><br />
|}<br><br />
Except later pseudo-opcode changes, the definition of OP_NOP1 - OP_NOP10 and the change of the evaluation of OP_RETURN (did no invalidation previously) which both occured in bitcoin version 0.3.6 in July 2010 were the last changes regarding opcodes <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.2.0/bitcoin-0.2.0-linux.tar.gz file src/srcipt.cpp in bitcoin-0.2.0]</ref> <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.3.3/bitcoin-0.3.3-linux.tar.gz file src/srcipt.cpp in bitcoin-0.3.3]</ref> <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.3.6/bitcoin-0.3.6-linux.tar.gz file src/srcipt.cpp in bitcoin-0.3.6]</ref>.<br />
<br />
== Opcode descriptions ==<br />
It follows for each opcode less than decimal 185 (hexa 0xba) a description for its usage. The columns entitled ''nemonic'', ''decimal'' and ''Hex'' should be evident. The column ''input'' gives the needed items of the stack (and the alternate stack) and the column ''output'' indicates the resulting items on the stack (and the alternate stack). '''Stack-top is always the right most item.''' The naming of the entries in these two columns is chosen to reflect their interpretation. ''x'',''x0'',''x1'',... means arbitrary or no interpretation, ''a'', ''b'' and ''c'' as a signed integer value, ''n'',''index'',''size'' and ''depth'' non-negative integer values, ''Boolean'' as either a true or false.<br><br />
<br />
Some of the more complicated opcodes are disabled out of concern that the client might have (and has) a bug in the current implementation due to the historically not as 2-complement interpretations of the byte vectors as numerical values (the most significant byte holds the sign of the byte vectors).<br />
<br />
=== Push data from instruction onto stack ===<br />
<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_FALSE, OP_0<br />
|0<br />
|0x00<br />
|Nothing<br />
|Empty string<br />
|A byte vector of length 0 is pushed onto the stack. (Thus, it is not a no-op!)<br />
|-<br />
|(no official nemonics)<br />
|1 - 75<br />
|0x01 - 0x4b<br />
|(operand)<br />
|x<br />
|The next <opcode>-many bytes are to be pushed onto the stack.<br />
|-<br />
|OP_PUSHDATA1<br />
|76<br />
|0x4c<br />
|(operands)<br />
|x<br />
|The next byte contains the number of bytes to be pushed onto the stack which follow this byte.<br />
|-<br />
|OP_PUSHDATA2<br />
|77<br />
|0x4d<br />
|(operands)<br />
|x<br />
|The next two bytes contain the number of bytes to be pushed onto the stack which follow theses 2 bytes.<br />
|-<br />
|OP_PUSHDATA4<br />
|78<br />
|0x4e<br />
|(operands)<br />
|x<br />
|The next four bytes contain the number of bytes to be pushed onto the stack which follow theses 4 bytes.<br />
|-<br />
|OP_1NEGATE<br />
|79<br />
|0x4f<br />
|Nothing<br />
| -1<br />
|The byte with value -1 is pushed onto the stack.<br />
|-<br />
|OP_1, OP_TRUE<br />
|81<br />
|0x51<br />
|Nothing<br />
|1<br />
|The byte with value 1 is pushed onto the stack.<br />
|-<br />
|OP_2 - OP_16<br />
|82 - 96<br />
|0x52 - 0x60<br />
|Nothing<br />
|2-16<br />
|The byte with value <opcode>-80 (thus, one of 2 - 16) is pushed onto the stack.<br />
|}<br />
<br />
=== Flow control ===<br />
<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_NOP<br />
|97<br />
|0x61<br />
|Nothing<br />
|Nothing<br />
|Does nothing.<br />
|-<br />
|OP_IF<br />
|99<br />
|0x63<br />
|Boolean<br />
|Nothing<br />
|If the top stack value is not 0, the statements are executed. The top stack value is removed. Lead in a logcial ''<value> then [statements] [else [statements]] endif'' expression<br />
|-<br />
|OP_NOTIF<br />
|100<br />
|0x64<br />
|Boolean<br />
|Nothing<br />
|If the top stack value is 0, the statements are executed. The top stack value is removed. Lead in a logcial ''<value> then [statements] [else [statements]] endif'' expression <br />
|-<br />
|OP_ELSE<br />
|103<br />
|0x67<br />
|Nothing<br />
|Nothing<br />
|If the preceeding OP_IF or OP_NOTIF or OP_ELSE was not executed then these statements are and if the preceding OP_IF or OP_NOTIF or OP_ELSE was executed then these statements are not. <br />
|-<br />
|OP_ENDIF<br />
|104<br />
|0x68<br />
|Nothing<br />
|Nothing<br />
|Ends a logcial ''If <value> then [statements] [else [statements]] '' expression<br />
|-<br />
|OP_VERIFY<br />
|105<br />
|0x69<br />
|Boolean<br />
|Nothing / False<br />
|If top stack value is not true then marks transaction as '''invalid''' . A value true is removed, but false is not.<br />
|-<br />
|OP_RETURN<br />
|106<br />
|0x6a<br />
|Nothing<br />
|Nothing<br />
|Marks transaction as '''invalid'''. <br />
|}<br />
<br />
===Stack item organization===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_TOALTSTACK<br />
|107<br />
|0x6b<br />
|x1 (alt)<br />
|(alt x1)<br />
|Puts the input onto the top of the alt stack. Removes it from the (main) stack.<br />
|-<br />
|OP_FROMALTSTACK<br />
|108<br />
|0x6c<br />
|(alt x1)<br />
|x1 (alt)<br />
|Puts the input onto the top of the (main) stack. Removes it from the alt stack.<br />
|-<br />
|OP_2DROP<br />
|109<br />
|0x6d<br />
|x2 x1<br />
|Nothing<br />
|Removes the top two stack items.<br />
|-<br />
|OP_2DUP<br />
|110<br />
|0x6e<br />
|x2 x1<br />
|x2 x1 x2 x1<br />
|Duplicates the top two stack items.<br />
|-<br />
|OP_3DUP<br />
|111<br />
|0x6f<br />
|x3 x2 x1<br />
|x3 x2 x1 x3 x2 x1<br />
|Duplicates the top three stack items.<br />
|-<br />
|OP_2OVER<br />
|112<br />
|0x70<br />
|x4 x3 x2 x1<br />
|x4 x3 x2 x1 x4 x3<br />
|Copies the pair of items two spaces back in the stack to the front.<br />
|-<br />
|OP_2ROT<br />
|113<br />
|0x71<br />
|x6 x5 x4 x3 x2 x1<br />
|x4 x3 x2 x1 x6 x5<br />
|The fifth and sixth items back are moved to the top of the stack. Twotimes left rotate.<br />
|-<br />
|OP_2SWAP<br />
|114<br />
|0x72<br />
|x4 x3 x2 x1<br />
|x2 x1 x4 x3<br />
|Swaps the top two pairs of stack items.<br />
|-<br />
|OP_IFDUP<br />
|115<br />
|0x73<br />
|x1<br />
|x1 / x1 x1<br />
|If the top stack value is not 0, duplicate it.<br />
|-<br />
|OP_DEPTH<br />
|116<br />
|0x74<br />
|Nothing<br />
|depth<br />
|Puts the number of stack items onto the stack as one little-endian coded byte-vector<br />
|-<br />
|OP_DROP<br />
|117<br />
|0x75<br />
|x1<br />
|Nothing<br />
|Removes the top stack item.<br />
|-<br />
|OP_DUP<br />
|118<br />
|0x76<br />
|x1<br />
|x1 x1<br />
|Duplicates the top stack item.<br />
|-<br />
|OP_NIP<br />
|119<br />
|0x77<br />
|x2 x1<br />
|x1<br />
|Removes the second-to-top stack item.<br />
|-<br />
|OP_OVER<br />
|120<br />
|0x78<br />
|x2 x1<br />
|x2 x1 x2<br />
|Copies the second-to-top stack item to the top.<br />
|-<br />
|OP_PICK<br />
|121<br />
|0x79<br />
|xn ... x2 x1 x0 <n><br />
|xn ... x2 x1 x0 xn<br />
|<n> is removed and the item ''n'' back in the stack is copied to the top.<br />
|-<br />
|OP_ROLL<br />
|122<br />
|0x7a<br />
|xn ... x2 x1 x0 <n><br />
|... x2 x1 x0 xn<br />
|<n> is removed and the item ''n'' back in the stack is moved to the top.<br />
|-<br />
|OP_ROT<br />
|123<br />
|0x7b<br />
|x3 x2 x1<br />
|x2 x1 x3<br />
|The top three items on the stack are rotated to the left.<br />
|-<br />
|OP_SWAP<br />
|124<br />
|0x7c<br />
|x2 x1<br />
|x1 x2<br />
|The top two items on the stack are swapped resp. rotated.<br />
|-<br />
|OP_TUCK<br />
|125<br />
|0x7d<br />
|x2 x1<br />
|x1 x2 x1<br />
|The item at the top of the stack is copied and inserted before the second-to-top item.<br />
|}<br />
<br />
=== Splice ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_CAT<br />
|126<br />
|0x7e<br />
|x1 x2<br />
|out<br />
|Concatenates two strings resp. byte vectors. ''Currently disabled.''<br />
|-<br />
|OP_SUBSTR<br />
|127<br />
|0x7f<br />
|x index size<br />
|out<br />
|Returns the section started at position <index> and of length <size> of a string resp. byte vector. ''Currently disabled.''<br />
|-<br />
|OP_LEFT<br />
|128<br />
|0x80<br />
|x index<br />
|out<br />
|Keeps only characters left of the specified point in a string. ''Currently disabled.''<br />
|-<br />
|OP_RIGHT<br />
|129<br />
|0x81<br />
|x index<br />
|out<br />
|Keeps only characters right of the specified point in a string. ''Currently disabled.''<br />
|-<br />
|OP_SIZE<br />
|130<br />
|0x82<br />
|x<br />
|x size<br />
|Returns the length of the input string resp. byte vector resp. stack item.<br />
|}<br />
<br />
=== Bitwise logic ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_INVERT<br />
|131<br />
|0x83<br />
|x1<br />
|x0<br />
|Flips all of the bits in the input. ''Currently disabled.''<br />
|-<br />
|OP_AND<br />
|132<br />
|0x84<br />
|x1 x2<br />
|x0<br />
|Boolean ''and'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_OR<br />
|133<br />
|0x85<br />
|x1 x2<br />
|x0<br />
|Boolean ''or'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_XOR<br />
|134<br />
|0x86<br />
|x1 x2<br />
|x0<br />
|Boolean ''exclusive or'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_EQUAL<br />
|135<br />
|0x87<br />
|x1 x2<br />
|Boolean<br />
|Returns 1 if the inputs are byte-wise equal, 0 otherwise.<br />
|-<br />
|OP_EQUALVERIFY<br />
|136<br />
|0x88<br />
|x1 x2<br />
|Nothing / false<br />
|Same as OP_EQUAL, but runs OP_VERIFY afterward.<br />
|}<br />
<br />
=== Arithmetic ===<br />
<br />
(In very early versions, the implemented arithmetic opcodes were limited to maximal 4 byte vectors.)<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_1ADD<br />
|139<br />
|0x8b<br />
|a<br />
|c<br />
|1 is added to the input.<br />
|-<br />
|OP_1SUB<br />
|140<br />
|0x8c<br />
|a<br />
|c<br />
|1 is subtracted from the input.<br />
|-<br />
|OP_2MUL<br />
|141<br />
|0x8d<br />
|a<br />
|c<br />
|The input is multiplied by 2. ''Currently disabled.''<br />
|-<br />
|OP_2DIV<br />
|142<br />
|0x8e<br />
|a<br />
|c<br />
|The input is divided by 2. ''Currently disabled.''<br />
|-<br />
|OP_NEGATE<br />
|143<br />
|0x8f<br />
|a<br />
|c<br />
|The sign of the input is flipped. Numerically the value is multiplied by -1<br />
|-<br />
|OP_ABS<br />
|144<br />
|0x90<br />
|a<br />
|c<br />
|The input is negative, its sign is flipped.<br />
|-<br />
|OP_NOT<br />
|145<br />
|0x91<br />
|a<br />
|Boolean<br />
|If the input is 0 or 1, it is flipped. Otherwise the output will be 0. Test whether its value equals 0<br />
|-<br />
|OP_0NOTEQUAL<br />
|146<br />
|0x92<br />
|a<br />
|Boolean<br />
|Returns 0 if the input is 0. 1 otherwise. Test whether its value is unequal 0<br />
|-<br />
|OP_ADD<br />
|147<br />
|0x93<br />
|a b<br />
|c<br />
|a is added to b.<br />
|-<br />
|OP_SUB<br />
|148<br />
|0x94<br />
|a b<br />
|c<br />
|b is subtracted from a.<br />
|-<br />
|OP_MUL<br />
|149<br />
|0x95<br />
|a b<br />
|c<br />
|a is multiplied by b. ''Currently disabled.''<br />
|-<br />
|OP_DIV<br />
|150<br />
|0x96<br />
|a b<br />
|c<br />
|a is divided by b (b should be not 0). ''Currently disabled.''<br />
|-<br />
|OP_MOD<br />
|151<br />
|0x97<br />
|a b<br />
|c<br />
|Returns the remainder after dividing a by b (b should be not 0). ''Currently disabled.''<br />
|-<br />
|OP_LSHIFT<br />
|152<br />
|0x98<br />
|a b<br />
|c<br />
|Shifts a left by b bits, preserving sign. ''Currently disabled.''<br />
|-<br />
|OP_RSHIFT<br />
|153<br />
|0x99<br />
|a b<br />
|c<br />
|Shifts a right by b bits, preserving sign. ''Currently disabled.''<br />
|-<br />
|OP_BOOLAND<br />
|154<br />
|0x9a<br />
|a b<br />
|Boolean<br />
|If both a and b are not 0, the output is 1. Otherwise 0.<br />
|-<br />
|OP_BOOLOR<br />
|155<br />
|0x9b<br />
|a b<br />
|Boolean<br />
|If a or b is not 0, the output is 1. Otherwise 0.<br />
|-<br />
|OP_NUMEQUAL<br />
|156<br />
|0x9c<br />
|a b<br />
|Boolean<br />
|Returns 1 if the numbers are equal, 0 otherwise.<br />
|-<br />
|OP_NUMEQUALVERIFY<br />
|157<br />
|0x9d<br />
|a b<br />
|Nothing / False<br />
|Same as OP_NUMEQUAL, but runs OP_VERIFY afterward.<br />
|-<br />
|OP_NUMNOTEQUAL<br />
|158<br />
|0x9e<br />
|a b<br />
|Boolean<br />
|Returns 1 if the numbers are not equal, 0 otherwise.<br />
|-<br />
|OP_LESSTHAN<br />
|159<br />
|0x9f<br />
|a b<br />
|Boolean<br />
|Returns 1 if a is less than b, 0 otherwise.<br />
|-<br />
|OP_GREATERTHAN<br />
|160<br />
|0xa0<br />
|a b<br />
|Boolean<br />
|Returns 1 if a is greater than b, 0 otherwise.<br />
|-<br />
|OP_LESSTHANOREQUAL<br />
|161<br />
|0xa1<br />
|a b<br />
|Boolean<br />
|Returns 1 if a is less than or equal to b, 0 otherwise.<br />
|-<br />
|OP_GREATERTHANOREQUAL<br />
|162<br />
|0xa2<br />
|a b<br />
|Boolean<br />
|Returns 1 if a is greater than or equal to b, 0 otherwise.<br />
|-<br />
|OP_MIN<br />
|163<br />
|0xa3<br />
|a b<br />
|a / b<br />
|Returns the smaller of a and b.<br />
|-<br />
|OP_MAX<br />
|164<br />
|0xa4<br />
|a b<br />
| a / b<br />
|Returns the larger of a and b.<br />
|-<br />
|OP_WITHIN<br />
|165<br />
|0xa5<br />
|x min max<br />
|Boolean<br />
|Returns 1 if x is within the specified range (left-inclusive) , 0 otherwise. min may be greater than max<br />
|}<br />
<br />
=== Crypto ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_RIPEMD160<br />
|166<br />
|0xa6<br />
|x<br />
|hash20<br />
|The input is hashed using RIPEMD-160.<br />
|-<br />
|OP_SHA1<br />
|167<br />
|0xa7<br />
|x<br />
|hash20<br />
|The input is hashed using SHA-1.<br />
|-<br />
|OP_SHA256<br />
|168<br />
|0xa8<br />
|x<br />
|hash32<br />
|The input is hashed using SHA-256.<br />
|-<br />
|OP_HASH160<br />
|169<br />
|0xa9<br />
|x<br />
|hash20<br />
|The input is hashed twice: first with SHA-256 and then with RIPEMD-160.<br />
|-<br />
|OP_HASH256<br />
|170<br />
|0xaa<br />
|x<br />
|hash32<br />
|The input is hashed two times with SHA-256.<br />
|-<br />
|OP_CODESEPARATOR<br />
|171<br />
|0xab<br />
|Nothing<br />
|Nothing<br />
|All of the signature checking opcodes will only match signatures to the data after the most recently-executed OP_CODESEPARATOR.<br />
|-<br />
|[[OP_CHECKSIG]]<br />
|172<br />
|0xac<br />
|sig pubkey<br />
|Boolean<br />
|The entire transaction's outputs, inputs, and script (from the most recently-executed OP_CODESEPARATOR to the end) are hashed. The signature used by OP_CHECKSIG must be a valid signature for a further, extern specified hash and the given public key. If it is, 1 is returned, 0 otherwise.<br />
|-<br />
|OP_CHECKSIGVERIFY<br />
|173<br />
|0xad<br />
|sig pubkey<br />
|Nothing / False<br />
|Same as OP_CHECKSIG, but OP_VERIFY is executed afterward.<br />
|-<br />
|OP_CHECKMULTISIG<br />
|174<br />
|0xae<br />
|sig1 sig2 ... <number of signatures> pub1 pub2 <number of public keys><br />
|Boolean<br />
|For each signature and public key pair, OP_CHECKSIG is executed. If more public keys than signatures are listed, some key/sig pairs can fail. All signatures need to match a public key. If all signatures are valid, 1 is returned, 0 otherwise. Due to a bug, one extra unused value is removed from the stack.<br />
|-<br />
|OP_CHECKMULTISIGVERIFY<br />
|175<br />
|0xaf<br />
|sig1 sig2 ... <number of signatures> pub1 pub2 ... <number of public keys><br />
|Nothing / False<br />
|Same as OP_CHECKMULTISIG, but OP_VERIFY is executed afterward.<br />
|}<br />
<br />
=== Expansion opcodes ===<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_NOP1-OP_NOP10<br />
|176-185<br />
|0xb0-0xb9<br />
|The opcode has no effect.<br />
|}<br />
<br />
=== Version opcodes ===<br />
Version opcodes are disabled since bitcoin 0.2.0 and should not be used (maybe reassigned in the future).<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_VER<br />
|98<br />
|0x62<br />
|Script evalution is triggered invalid (Formerly pushed the bitcoin-serialize version onto stack).<br />
|-<br />
|OP_VERIF<br />
|101<br />
|0x65<br />
|Script evalution is triggered invalid (Formerly top stack item was popped and =< compared to present version)<br />
|-<br />
|OP_VERNOTIF<br />
|102<br />
|0x66<br />
|Script evalution is triggered invalid (Formerly top stack item was popped and > compared to present version)<br />
|}<br />
<br />
=== Reserved opcodes ===<br />
Each opcode not assigned (currently also every opcode value > 185) is also reserved. Using any unassigned opcode triggers the script evaluation to be invalid.<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_RESERVED<br />
|80<br />
|0x50<br />
|Script evalution is triggered invalid-<br />
|-<br />
|OP_RESERVED1<br />
|137<br />
|0x89<br />
|Script evalution is triggered invalid.<br />
|-<br />
|OP_RESERVED2<br />
|138<br />
|0x8a<br />
|Script evalution is triggered invalid.<br />
|}<br />
<br />
===Pseudo-opcodes===<br />
These nemonics are used internally for assisting with transaction matching. They are invalid if used in actual scripts.<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_PUBKEYHASH<br />
|253<br />
|0xfd<br />
|Represents a public key hashed with OP_HASH160.<br />
|-<br />
|OP_PUBKEY<br />
|254<br />
|0xfe<br />
|Represents a public key compatible with OP_CHECKSIG.<br />
|-<br />
|OP_INVALIDOPCODE<br />
|255<br />
|0xff<br />
|Matches any opcode that is not yet assigned.<br />
|}<br />
<br />
==Scripts in bitcoin transactions==<br />
It follows a list of important (most occuring) scripts to see opcodes "at work". Keep in mind that all constants actually use the data-pushing instructions above. At start of a (transaction input) script evaluation, the stack is always empty. <br />
<br />
===Standard transaction to bitcoin address===<br />
<br />
scriptPubKey: OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG<br />
scriptSig: <sig> <pubKey><br />
<br />
To demonstrate how scripts look on the wire, here is a raw scriptPubKey:<br />
<pre> 76 A9 14<br />
OP_DUP OP_HASH160 Bytes to push<br />
<br />
89 AB CD EF AB BA AB BA AB BA AB BA AB BA AB BA AB BA AB BA 88 AC<br />
Data to push OP_EQUALVERIFY OP_CHECKSIG</pre><br />
<br />
Note: scriptSig is in the input of the spending transaction and scriptPubKey is in the output of the previously storing transaction, i.e. its "available bitcoins".<br />
<br />
Here is how each instruction is processed:<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
| <sig> <pubKey> OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| scriptSig and scriptPubKey are combined.<br />
|-<br />
|<sig> <pubKey><br />
| OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| Constants are added to the stack.<br />
|-<br />
|<sig> <pubKey> <pubKey><br />
| OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| Top stack item is duplicated.<br />
|-<br />
|<sig> <pubKey> <pubHashA><br />
|<pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG<br />
| Top stack item is hashed.<br />
|-<br />
|<sig> <pubKey> <pubHashA> <pubKeyHash><br />
|OP_EQUALVERIFY OP_CHECKSIG<br />
| Constant added.<br />
|-<br />
|<sig> <pubKey><br />
|OP_CHECKSIG<br />
| Equality is checked between the top two stack items.<br />
|-<br />
|true<br />
|Empty.<br />
|Signature is checked for top two stack items.<br />
|}<br />
<br />
===Transaction to IP address (and generation transaction)===<br />
<br />
scriptPubKey: <pubKey> OP_CHECKSIG<br />
scriptSig: <sig><br />
<br />
Checking process:<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
|<sig> <pubKey> OP_CHECKSIG<br />
|scriptSig and scriptPubKey are combined.<br />
|-<br />
|<sig> <pubKey><br />
| OP_CHECKSIG<br />
|Constants are added to the stack.<br />
|-<br />
|true<br />
|Empty.<br />
|Signature is checked for top two stack items.<br />
|}<br />
<br />
In the case of a '''coin generation transaction''' (the first transaction of each block), there is no scriptSig, resp. its code ("coinbase") is completly ignored for the transaction. Only the scriptPubKey is used.<br />
<br />
===Transaction with a message===<br />
<br />
It's possible to add arbitrary data to any transaction by just adding some data along with OP_DROP. <br />
scriptPubKey: <message> OP_DROP <pubKey> OP_CHECKSIG<br />
scriptSig: <sig><br />
<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
|<sig> <message> OP_DROP <pubKey> OP_CHECKSIG<br />
|<br />
|-<br />
|<sig><br />
|<message> OP_DROP <pubKey> OP_CHECKSIG<br />
|scriptSig added to the stack.<br />
|-<br />
|<sig> <message><br />
|OP_DROP <pubKey> OP_CHECKSIG<br />
|The message has been put.<br />
|-<br />
|<sig><br />
|<pubKey> OP_CHECKSIG<br />
|Top stack item has been removed.<br />
|-<br />
|<sig> <pubKey><br />
|OP_CHECKSIG<br />
|Checking signature against the public key.<br />
|-<br />
|true<br />
|Empty.<br />
|Stack holds the value of signature check now.<br />
|}<br />
<br />
===Examples of non standard transaction on Testnet===<br />
<br />
These two links below show a non standard transaction. It just prepends the hex of "bob" and the operation OP_DROP<br />
which just removes it. As you can see they can be spent as normal.<br />
<br />
Input non-std transaction:<br />
http://blockexplorer.com/testnet/t/6ttfeb55B1<br />
<br />
Spent by:<br />
http://blockexplorer.com/testnet/t/AFdRB1CHS3<br />
<br />
==Script validation==<br />
A script evaluation is considered invalid, if any of these conditions meets:<br><br />
<ul><br />
<li>the total size of the script exceeds (currently) 10000 bytes<br />
<li>there are more than (currently) 201 opcodes of opcode value > 0x60 in the script<br />
<li>each instruction is (currently) limited to maximal 520 bytes. This effects only the opcodes OP_PUSHDATA2 and OP_PUSHDATA4<br />
<li>the executed opcode of the script has insufficient input (from stack, from script or from anywhere)<br />
<li>the opcode is not defined (for execution) - indicated by white or light gray background color in the table<br />
<li>the opcode is disabled (currently 15 opcodes) - indicated by white font color in the opcode overview matrix<br />
<li>stack overflow occurs during execution of the opcode (currently the number of items on the stack and on the alternate stack is limited to 1000)<br />
<li>the opcodes OP_VERIF and OP_NOTVERIF invalidate a script which contains this opcode (even if this opcode is not executed!)<br />
<li>the opcodes OP_ELSE or OP_ENDIF has no matching OP_IF<br><br />
<li>the script execution has been finished but there is (at least) an unmatched OP_IF<br><br />
<li>the opcodes OP_VERIFY, OP_EQUALVERIFY, OP_NUMEQUALVERIFY, OP_CHECKSIGVERIFY and OP_CHECKMULTISIGVERIFY invalidate the script if the stack-top item is false<br />
<li>the execution of OP_RETURN<br />
<!--li>alt stack overflow occurs (only possible during execution of OP_TOALTSTACK)--><br />
<li>the numerical value of the top-stack item is negative or greater than the number of items - 2 on the stack if OP_PICK or OP_ROLL shall be executed<br />
<li>an item used as public key or signature for each of the opcodes OP_CHECKSIG, OP_CHECKSIGVERIFY, OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY can be neither a public key or signature (for the given hash)<br />
<li>the number of signature items or the number of public key items on the stack is negative for OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY<br />
<li>there or more signatures items than public key items on the stack for OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY<br />
<li>there are (currently) more than 20 public key items on the stack for OP_CHECKMULTISIG or CHECKMULTISIGVERIFY<br />
<li>the sum of opcodes > 0x60 and the number of public keys in all executed OP_CHECKMULTISIG or CHECKMULTISIGVERIFY exceeds (currently) 201<br />
<li>the script execution has been finished and the stack is empty or the top-stack item is false (numerical value 0)<br />
</ul><br />
else the script evaluation is considered to be valid.<ref>[http://sourceforge.net/projects/bitcoin/files/Bitcoin/bitcoin-0.7.1/bitcoin-0.7.1-linux.tar.gz file src/src/script.cpp in bitcoin-0.7.1]</ref><br />
'''If invalidation of a script is triggered then the script is immediately finished.''' These arbitrary looking limitations of 10000, 201, 520, 1000 and 20 might be increased in the future -- they serve to prevent strong slow down of the evaluation of a script while not restricting its practical usage really.<br />
<br />
==Withdrawn and drafted opcodes==<br />
<br />
<ul><br />
<li> byte value 0x89 OP_NOTEQUAL defined in pre-0.1.0 bitcoin versions. Since 0.1.0 removed because of security concerns. <br />
<li> byte value 0xb1 [[BIP 0012 | OP_EVAL]] withdraw - poll was triggered but insufficient support. <br />
<li> byte value 0xb2 [[BIP 0017 | OP_CHECKHASHVERIFY]] withdraw - poll was triggered but insufficient support.<br />
</ul><br />
<br />
==See Also==<br />
* [[Transactions]]<br />
* [[Contracts]]<br />
<br />
==References==<br />
<references/><br />
<ul><br />
<li>[http://www.zorinaq.com/pub/bitcoin-0.1.0.tgz file src/script.cpp in bitcoin-0.1.0]</li><br />
</ul><br />
[[Category:Technical]]<br />
[[Category:Vocabulary]]</div>
Smtp
https://en.bitcoin.it/w/index.php?title=Script&diff=34891
Script
2013-01-10T23:31:08Z
<p>Smtp: /* Opcode descriptions */</p>
<hr />
<div>Bitcoin uses a scripting system for [[transactions]]. [[Wikipedia:FORTH|Forth]]-like, Script is simple, stack-based, and processed from left to right. It is purposefully not Turing-complete, with no loops.<br />
<br />
A script is essentially a list of instructions recorded with each transaction that describe how the next person wanting to spend the Bitcoins being transferred can gain access to them.<br />
<br />
Scripts are big-endian and their sequences of bytes is interpreted as a sequence of opcodes with operands. Only opcodes with byte values less than 0x4f have additional operands.<br />
<br />
== Scripts and Bitcoin transactions ==<br />
The script for a typical Bitcoin transfer to destination Bitcoin address D simply encumbers future spending of the bitcoins with two things: the spender must provide<br />
# a public key that, when hashed, yields destination address D embedded in the script, and<br />
# a signature to show evidence of the private key corresponding to the public key just provided.<br />
<br />
Scripting provides the flexibility to change the parameters of what's needed to spend transferred Bitcoins. For example, the scripting system could be used to require two private keys, or a combination of several, or even no keys at all.<br />
<br />
A transaction is valid if nothing in the combined script triggers failure and the top stack item exists and is true (non-zero). The party who originally ''stored'' the Bitcoins now being spent, dictates the script operations that will occur ''last'' in order to release them for use in another transaction. The party wanting to spend them must provide the input(s) to the previously recorded script that results in those operations occurring last leaving behind true (non-zero) on the stack.<br><br />
Only the very first transaction in each bitcoin block has no input script (the entry there is called "coinbase"), because the Bitcoins created with the block are created from hot air and not released by a previous recorded script.<br />
<br />
== Stack ==<br />
<br />
The stacks hold byte vectors (there is the (main) stack and an alternative stack). Byte vectors are interpreted as little-endian variable-length integers with the most significant bit determining the sign of the integer. Thus 0x81 represents -1. 0x80 is another representation of zero (so called negative 0). Byte vectors are interpreted as Booleans where False is represented by any representation of zero, and True is represented by any representation of non-zero.<br />
<br />
== Opcode overview ==<br />
<br />
For each opcode is given: its nemonic without the leading OP_, its hexadecimal byte value, the number of stack items needed (poped) during execution, a semicolon and the number of stack items which has been pushed (after execution). A * after the needed stack items indicates that further bytes from the script following the current opcode are needed. A # indicates that items on the alternative stack are poped/pushed. A @ indicates that further (global) data from the transaction is needed. A / indicates alternatives of a value. <br/><br />
Different colors indicate different semantic execution groups of opcodes:<br />
{| style="background:none; font-size:100%; padding:0; border-collapse:collapse; text-align:center; line-height:2em;" border="0" align="center" <br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | copy a fixed number of bytes but at most 75 onto stack<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | copy bytes onto stack which number is given by a 1, 2 or 4 byte value.<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | copy 1 specific byte onto stack<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | undefined opcode<br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | a pseudo-opcode, unassigned for scripts<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | NOP or opcode is part of a IF-flow-control construction<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00ff00;" | (stack conditionally) invalidation of the script this opcode is part of<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | stack item is moved between main stack and alternate stack<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | stack item(s) is/are moved, copied or deleted<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0;" | byte vectors are appended or divided or their size is determined<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff;" | byte vectors are interpreted bit-position-independently<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | byte vectors are interpreted and processed as signed integers<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | a hash value is computed or a signature checked<br />
|}<br />
<p><br />
===Opcode byte-matrix===<br />
The opcode value 0x00 with nemonic OP_FALSE is also named OP_0 and the opcode value 0x51 with nemonic OP_1 as also named OP_TRUE.<br />
{| style="background:none; font-size:100%; padding:0; border-collapse:collapse; text-align:center; line-height:2em;" border="0" align="center" <br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" |_FALSE<br/> 0x00 <br/> 0 ; 1(0) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x01<br/> 0 *; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x02<br/> 0 *; 1(2)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x03<br/> 0 *; 1(3)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x04<br/> 0 *; 1(4)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x04<br/> 0 *; 1(5)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x06<br/> 0 *; 1(6)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x07<br/> 0 *; 1(7)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x08<br/> 0 *; 1(8)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x09<br/> 0 *; 1(9)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0a<br/> 0 *; 1(10)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0b<br/> 0 *; 1(11)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0c<br/> 0 *; 1(12)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0d<br/> 0 *; 1(13)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0e<br/> 0 *; 1(14)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0f<br/> 0 *; 1(15)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x10 <br/> 0 *; 1(16) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x11 <br/> 0 *; 1(17)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x12 <br/> 0 *; 1(18)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x13 <br/> 0 *; 1(19)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x14 <br/> 0 *; 1(20)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x15 <br/> 0 *; 1(21)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x16 <br/> 0 *; 1(22)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x17 <br/> 0 *; 1(23)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x18 <br/> 0 *; 1(24)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x19 <br/> 0 *; 1(25)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1a <br/> 0 *; 1(26)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1b <br/> 0 *; 1(27)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1c <br/> 0 *; 1(28)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1d <br/> 0 *; 1(29)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1e <br/> 0 *; 1(30)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1f <br/> 0 *; 1(31)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x20 <br/> 0 *; 1(32) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x21 <br/> 0 *; 1(33)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x22 <br/> 0 *; 1(34)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x23 <br/> 0 *; 1(35)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x24 <br/> 0 *; 1(36)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x25 <br/> 0 *; 1(37)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x26 <br/> 0 *; 1(38)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x27 <br/> 0 *; 1(39)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x28 <br/> 0 *; 1(40)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x29 <br/> 0 *; 1(41)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2a <br/> 0 *; 1(42)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2b <br/> 0 *; 1(43)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2c <br/> 0 *; 1(44)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2d <br/> 0 *; 1(45)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2e <br/> 0 *; 1(46)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2f <br/> 0 *; 1(47)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x30 <br/> 0 *; 1(48) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x31 <br/> 0 *; 1(49)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x32 <br/> 0 *; 1(50)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x33 <br/> 0 *; 1(51)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x34 <br/> 0 *; 1(52)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x35 <br/> 0 *; 1(53)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x36 <br/> 0 *; 1(54)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x37 <br/> 0 *; 1(55)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x38 <br/> 0 *; 1(56)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x39 <br/> 0 *; 1(57)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3a <br/> 0 *; 1(58)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3b <br/> 0 *; 1(59)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3c <br/> 0 *; 1(60)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3d <br/> 0 *; 1(61)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3e <br/> 0 *; 1(62)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3f <br/> 0 *; 1(63)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x40 <br/> 0 *; 1(64) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x41 <br/> 0 *; 1(65)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x42 <br/> 0 *; 1(66)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x43 <br/> 0 *; 1(67)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x44 <br/> 0 *; 1(68)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x45 <br/> 0 *; 1(69)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x46 <br/> 0 *; 1(70)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x47 <br/> 0 *; 1(71)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x48 <br/> 0 *; 1(72)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x49 <br/> 0 *; 1(73)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x4a <br/> 0 *; 1(74)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x4b <br/> 0 *; 1(75)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA1 <br/> 0x4c <br/> 0 *; 1(0 - 255)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA2 <br/> 0x4d <br/> 0 *; 1(0 - 2^16-1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA4 <br/> 0x4e <br/> 0 *; 1(0 - 2^32-1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _1NEGATE <br/> 0x4f <br/> 0 ; 1(1)<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED <br/> 0x50 <br/> <br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _1 <br/> 0x51 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _2 <br/> 0x52 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _3 <br/> 0x53 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _4 <br/> 0x54 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _5 <br/> 0x55 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _6 <br/> 0x56 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _7 <br/> 0x57 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _8 <br/> 0x58 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _9 <br/> 0x59 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _10 <br/> 0x5a <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _11 <br/> 0x5b <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _12 <br/> 0x5c <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _13 <br/> 0x5d <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _14 <br/> 0x5e <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _15 <br/> 0x5f <br/> 0 ; 1(1)<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _16 <br/> 0x60 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP <br/> 0x61 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VER <br/> 0x62 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _IF <br/> 0x63 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOTIF <br/> 0x64 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VERIF <br/> 0x65 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VERNOTIF <br/> 0x66 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _ELSE <br/> 0x67 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _ENDIF <br/> 0x68 <br/> 0 ; 0<br />
| style="border:3px solid #808080; background-color:#00ff00;" | _VERIFY <br/> 0x69 <br/> 1 ; 0/1<br />
| style="border:3px solid #808080; background-color:#00ff00;" | _RETURN <br/> 0x6a <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | _TOALTSTACK <br/> 0x6b <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | _FROMALTSTACK <br/> 0x6c <br/> 0 #; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2DROP <br/> 0x6d <br/> 2 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2DUP <br/> 0x6e <br/> 2 ; 4<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _3DUP <br/> 0x6f <br/> 3 ; 6<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2OVER <br/> 0x70 <br/> 4 ; 6<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2ROT <br/> 0x71 <br/> 6 ; 6<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2SWAP <br/> 0x72 <br/> 4 ; 4<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _IFDUP <br/> 0x73 <br/> 1 ; 1/2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DEPTH <br/> 0x74 <br/> 0 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DROP <br/> 0x75 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DUP <br/> 0x76 <br/> 1 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _NIP <br/> 0x77 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _OVER <br/> 0x78 <br/> 2 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _PICK <br/> 0x79 <br/> 1+n+1 ; n+2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _ROLL <br/> 0x7a <br/> 1+n+1 ; n+1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _ROT <br/> 0x7b <br/> 3 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _SWAP <br/> 0x7c <br/> 2 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _TUCK <br/> 0x7d <br/> 2 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _CAT <br/> 0x7e <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _SUBSTR <br/> 0x7f <br/> 3 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _LEFT <br/> 0x80 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _RIGHT <br/> 0x81 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0;" | _SIZE <br/> 0x82 <br/> 1 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _INVERT <br/> 0x83 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _AND <br/> 0x84 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _OR <br/> 0x85 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _XOR <br/> 0x86 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff;" | _EQUAL <br/> 0x87 <br/> 2 ; 1<br />
| style="border:3px solid #808080; background-color:#c080ff;" | _EQUALVERIFY <br/> 0x88 <br/> 2 ; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED1 <br/> 0x89 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED2 <br/> 0x8a <br/><br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _1ADD <br/> 0x8b <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _1SUB <br/> 0x8c <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _2MUL <br/> 0x8d <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _2DIV <br/> 0x8e <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NEGATE <br/> 0x8f <br/> 1 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _ABS <br/> 0x90 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NOT <br/> 0x91 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _0NOTEQUAL <br/> 0x92 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _ADD <br/> 0x93 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _SUB <br/> 0x94 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _MUL <br/> 0x95 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _DIV <br/> 0x96 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _MOD <br/> 0x97 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _LSHIFT <br/> 0x98 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _RSHIFT <br/> 0x99 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _BOOLAND <br/> 0x9a <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _BOOLOR <br/> 0x9b <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NUMEQUAL <br/> 0x9c <br/> 2 ; 1<br />
| style="border:3px solid #808080; background-color:#8080ff;" | _NUMEQUALVERIFY <br/> 0x9d <br/> 2 ; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NUMNOTEQUAL <br/> 0x9e <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _LESSTHAN <br/> 0x9f <br/> 2 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _GREATERTHAN <br/> 0xa0 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _LESSTHANOREQUAL <br/> 0xa1 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _GREATERTHANOREQUAL <br/> 0xa2 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _MIN <br/> 0xa3 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _MAX <br/> 0xa4 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _WITHIN <br/> 0xa5 <br/> 3 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _RIPEMD160 <br/> 0xa6 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _SHA1 <br/> 0xa7 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _SHA256 <br/> 0xa8 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _HASH160 <br/> 0xa9 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _HASH256 <br/> 0xaa <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CODESEPARATOR <br/> 0xab <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CHECKSIG <br/> 0xac <br/> 2 @; 1<br />
| style="border:3px solid #808080; background-color:#a0d0ff;" | _CHECKSIGVERIFY <br/> 0xad <br/> 2 @; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CHECKMULTISIG <br/> 0xae <br/> 2n+2 @; 1<br />
| style="border:3px solid #808080; background-color:#a0d0ff;" | _CHECKMULTISIGVERIFY <br/> 0xaf <br/> 2n+2 @; 0/1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP1 <br/> 0xb0 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP2 <br/> 0xb1 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP3 <br/> 0xb2 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP4 <br/> 0xb3 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP5 <br/> 0xb4 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP6 <br/> 0xb5 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP7 <br/> 0xb6 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP8 <br/> 0xb7 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP9 <br/> 0xb8 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP10 <br/> 0xb9 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xba <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbe <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xca <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xce <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xda <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xde <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xea <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xeb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xec <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xed <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xee <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xef <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xfa <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _SMALLINTEGER <br/> 0xfb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEYS <br/> 0xfc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEYHASH <br/> 0xfd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEY <br/> 0xfe <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _INVALIDOPCODE <br/> 0xff <br/><br />
|}<br><br />
Except later pseudo-opcode changes, the definition of OP_NOP1 - OP_NOP10 and the change of the evaluation of OP_RETURN (did no invalidation previously) which both occured in bitcoin version 0.3.6 in July 2010 were the last changes regarding opcodes <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.2.0/bitcoin-0.2.0-linux.tar.gz file src/srcipt.cpp in bitcoin-0.2.0]</ref> <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.3.3/bitcoin-0.3.3-linux.tar.gz file src/srcipt.cpp in bitcoin-0.3.3]</ref> <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.3.6/bitcoin-0.3.6-linux.tar.gz file src/srcipt.cpp in bitcoin-0.3.6]</ref>.<br />
<br />
== Opcode descriptions ==<br />
It follows for each opcode less than decimal 185 (hexa 0xba) a description for its usage. The columns entitled ''nemonic'', ''decimal'' and ''Hex'' should be evident. The column ''input'' gives the needed items of the stack (and the alternate stack) and the column ''output'' indicates the resulting items on the stack (and the alternate stack). '''Stack-top is always the right most item.''' The naming of the entries in these two columns is chosen to reflect their interpretation. ''x'',''x0'',''x1'',... means arbitrary or no interpretation, ''a'', ''b'' and ''c'' as a signed integer value, ''n'',''index'',''size'' and ''depth'' non-negative integer values, ''Boolean'' as either a true or false.<br><br />
<br />
Some of the more complicated opcodes are disabled out of concern that the client might have (and has) a bug in the current implementation due to the historically not as 2-complement interpretations of the byte vectors as numerical values (the most significant byte holds the sign of the byte vectors).<br />
<br />
=== Push data from instruction onto stack ===<br />
<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_FALSE, OP_0<br />
|0<br />
|0x00<br />
|Nothing<br />
|Empty string<br />
|A byte vector of length 0 is pushed onto the stack. (Thus, it is not a no-op!)<br />
|-<br />
|(no official nemonics)<br />
|1 - 75<br />
|0x01 - 0x4b<br />
|(operand)<br />
|x<br />
|The next <opcode>-many bytes are to be pushed onto the stack.<br />
|-<br />
|OP_PUSHDATA1<br />
|76<br />
|0x4c<br />
|(operands)<br />
|x<br />
|The next byte contains the number of bytes to be pushed onto the stack which follow this byte.<br />
|-<br />
|OP_PUSHDATA2<br />
|77<br />
|0x4d<br />
|(operands)<br />
|x<br />
|The next two bytes contain the number of bytes to be pushed onto the stack which follow theses 2 bytes.<br />
|-<br />
|OP_PUSHDATA4<br />
|78<br />
|0x4e<br />
|(operands)<br />
|x<br />
|The next four bytes contain the number of bytes to be pushed onto the stack which follow theses 4 bytes.<br />
|-<br />
|OP_1NEGATE<br />
|79<br />
|0x4f<br />
|Nothing<br />
| -1<br />
|The byte with value -1 is pushed onto the stack.<br />
|-<br />
|OP_1, OP_TRUE<br />
|81<br />
|0x51<br />
|Nothing<br />
|1<br />
|The byte with value 1 is pushed onto the stack.<br />
|-<br />
|OP_2 - OP_16<br />
|82 - 96<br />
|0x52 - 0x60<br />
|Nothing<br />
|2-16<br />
|The byte with value <opcode>-80 (thus, one of 2 - 16) is pushed onto the stack.<br />
|}<br />
<br />
=== Flow control ===<br />
<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_NOP<br />
|97<br />
|0x61<br />
|Nothing<br />
|Nothing<br />
|Does nothing.<br />
|-<br />
|OP_IF<br />
|99<br />
|0x63<br />
|Boolean<br />
|Nothing<br />
|If the top stack value is not 0, the statements are executed. The top stack value is removed. Lead in a logcial ''<value> then [statements] [else [statements]] endif'' expression<br />
|-<br />
|OP_NOTIF<br />
|100<br />
|0x64<br />
|Boolean<br />
|Nothing<br />
|If the top stack value is 0, the statements are executed. The top stack value is removed. Lead in a logcial ''<value> then [statements] [else [statements]] endif'' expression <br />
|-<br />
|OP_ELSE<br />
|103<br />
|0x67<br />
|Nothing<br />
|Nothing<br />
|If the preceeding OP_IF or OP_NOTIF or OP_ELSE was not executed then these statements are and if the preceding OP_IF or OP_NOTIF or OP_ELSE was executed then these statements are not. <br />
|-<br />
|OP_ENDIF<br />
|104<br />
|0x68<br />
|Nothing<br />
|Nothing<br />
|Ends a logcial ''If <value> then [statements] [else [statements]] '' expression<br />
|-<br />
|OP_VERIFY<br />
|105<br />
|0x69<br />
|Boolean<br />
|Nothing / False<br />
|If top stack value is not true then marks transaction as '''invalid''' . A value true is removed, but false is not.<br />
|-<br />
|OP_RETURN<br />
|106<br />
|0x6a<br />
|Nothing<br />
|Nothing<br />
|Marks transaction as '''invalid'''. <br />
|}<br />
<br />
===Stack item organization===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_TOALTSTACK<br />
|107<br />
|0x6b<br />
|x1 (alt)<br />
|(alt x1)<br />
|Puts the input onto the top of the alt stack. Removes it from the (main) stack.<br />
|-<br />
|OP_FROMALTSTACK<br />
|108<br />
|0x6c<br />
|(alt x1)<br />
|x1 (alt)<br />
|Puts the input onto the top of the (main) stack. Removes it from the alt stack.<br />
|-<br />
|OP_2DROP<br />
|109<br />
|0x6d<br />
|x1 x2<br />
|Nothing<br />
|Removes the top two stack items.<br />
|-<br />
|OP_2DUP<br />
|110<br />
|0x6e<br />
|x1 x2<br />
|x1 x2 x1 x2<br />
|Duplicates the top two stack items.<br />
|-<br />
|OP_3DUP<br />
|111<br />
|0x6f<br />
|x1 x2 x3<br />
|x1 x2 x3 x1 x2 x3<br />
|Duplicates the top three stack items.<br />
|-<br />
|OP_2OVER<br />
|112<br />
|0x70<br />
|x1 x2 x3 x4<br />
|x1 x2 x3 x4 x1 x2<br />
|Copies the pair of items two spaces back in the stack to the front.<br />
|-<br />
|OP_2ROT<br />
|113<br />
|0x71<br />
|x1 x2 x3 x4 x5 x6<br />
|x3 x4 x5 x6 x1 x2<br />
|The fifth and sixth items back are moved to the top of the stack.<br />
|-<br />
|OP_2SWAP<br />
|114<br />
|0x72<br />
|x1 x2 x3 x4<br />
|x3 x4 x1 x2<br />
|Swaps the top two pairs of items.<br />
|-<br />
|OP_IFDUP<br />
|115<br />
|0x73<br />
|x<br />
|x / x x<br />
|If the top stack value is not 0, duplicate it.<br />
|-<br />
|OP_DEPTH<br />
|116<br />
|0x74<br />
|Nothing<br />
|depth<br />
|Puts the number of stack items onto the stack as one little-endian coded byte-vector<br />
|-<br />
|OP_DROP<br />
|117<br />
|0x75<br />
|x<br />
|Nothing<br />
|Removes the top stack item.<br />
|-<br />
|OP_DUP<br />
|118<br />
|0x76<br />
|x<br />
|x x<br />
|Duplicates the top stack item.<br />
|-<br />
|OP_NIP<br />
|119<br />
|0x77<br />
|x1 x2<br />
|x2<br />
|Removes the second-to-top stack item.<br />
|-<br />
|OP_OVER<br />
|120<br />
|0x78<br />
|x1 x2<br />
|x1 x2 x1<br />
|Copies the second-to-top stack item to the top.<br />
|-<br />
|OP_PICK<br />
|121<br />
|0x79<br />
|xn ... x2 x1 x0 <n><br />
|xn ... x2 x1 x0 xn<br />
|The item ''n'' back in the stack is copied to the top.<br />
|-<br />
|OP_ROLL<br />
|122<br />
|0x7a<br />
|xn ... x2 x1 x0 <n><br />
|... x2 x1 x0 xn<br />
|The item ''n'' back in the stack is moved to the top.<br />
|-<br />
|OP_ROT<br />
|123<br />
|0x7b<br />
|x1 x2 x3<br />
|x2 x3 x1<br />
|The top three items on the stack are rotated to the left.<br />
|-<br />
|OP_SWAP<br />
|124<br />
|0x7c<br />
|x1 x2<br />
|x2 x1<br />
|The top two items on the stack are swapped.<br />
|-<br />
|OP_TUCK<br />
|125<br />
|0x7d<br />
|x1 x2<br />
|x2 x1 x2<br />
|The item at the top of the stack is copied and inserted before the second-to-top item.<br />
|}<br />
<br />
=== Splice ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_CAT<br />
|126<br />
|0x7e<br />
|x1 x2<br />
|out<br />
|Concatenates two strings resp. byte vectors. ''Currently disabled.''<br />
|-<br />
|OP_SUBSTR<br />
|127<br />
|0x7f<br />
|x index size<br />
|out<br />
|Returns the section started at position <index> and of length <size> of a string resp. byte vector. ''Currently disabled.''<br />
|-<br />
|OP_LEFT<br />
|128<br />
|0x80<br />
|x index<br />
|out<br />
|Keeps only characters left of the specified point in a string. ''Currently disabled.''<br />
|-<br />
|OP_RIGHT<br />
|129<br />
|0x81<br />
|x index<br />
|out<br />
|Keeps only characters right of the specified point in a string. ''Currently disabled.''<br />
|-<br />
|OP_SIZE<br />
|130<br />
|0x82<br />
|x<br />
|x size<br />
|Returns the length of the input string resp. byte vector resp. stack item.<br />
|}<br />
<br />
=== Bitwise logic ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_INVERT<br />
|131<br />
|0x83<br />
|x1<br />
|x0<br />
|Flips all of the bits in the input. ''Currently disabled.''<br />
|-<br />
|OP_AND<br />
|132<br />
|0x84<br />
|x1 x2<br />
|x0<br />
|Boolean ''and'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_OR<br />
|133<br />
|0x85<br />
|x1 x2<br />
|x0<br />
|Boolean ''or'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_XOR<br />
|134<br />
|0x86<br />
|x1 x2<br />
|x0<br />
|Boolean ''exclusive or'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_EQUAL<br />
|135<br />
|0x87<br />
|x1 x2<br />
|Boolean<br />
|Returns 1 if the inputs are byte-wise equal, 0 otherwise.<br />
|-<br />
|OP_EQUALVERIFY<br />
|136<br />
|0x88<br />
|x1 x2<br />
|Nothing / false<br />
|Same as OP_EQUAL, but runs OP_VERIFY afterward.<br />
|}<br />
<br />
=== Arithmetic ===<br />
<br />
(In very early versions, the implemented arithmetic opcodes were limited to maximal 4 byte vectors.)<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_1ADD<br />
|139<br />
|0x8b<br />
|a<br />
|c<br />
|1 is added to the input.<br />
|-<br />
|OP_1SUB<br />
|140<br />
|0x8c<br />
|a<br />
|c<br />
|1 is subtracted from the input.<br />
|-<br />
|OP_2MUL<br />
|141<br />
|0x8d<br />
|a<br />
|c<br />
|The input is multiplied by 2. ''Currently disabled.''<br />
|-<br />
|OP_2DIV<br />
|142<br />
|0x8e<br />
|a<br />
|c<br />
|The input is divided by 2. ''Currently disabled.''<br />
|-<br />
|OP_NEGATE<br />
|143<br />
|0x8f<br />
|a<br />
|c<br />
|The sign of the input is flipped. Numerically the value is multiplied by -1<br />
|-<br />
|OP_ABS<br />
|144<br />
|0x90<br />
|a<br />
|c<br />
|The input is negative, its sign is flipped.<br />
|-<br />
|OP_NOT<br />
|145<br />
|0x91<br />
|a<br />
|Boolean<br />
|If the input is 0 or 1, it is flipped. Otherwise the output will be 0. Test whether its value equals 0<br />
|-<br />
|OP_0NOTEQUAL<br />
|146<br />
|0x92<br />
|a<br />
|Boolean<br />
|Returns 0 if the input is 0. 1 otherwise. Test whether its value is unequal 0<br />
|-<br />
|OP_ADD<br />
|147<br />
|0x93<br />
|a b<br />
|c<br />
|a is added to b.<br />
|-<br />
|OP_SUB<br />
|148<br />
|0x94<br />
|a b<br />
|c<br />
|b is subtracted from a.<br />
|-<br />
|OP_MUL<br />
|149<br />
|0x95<br />
|a b<br />
|c<br />
|a is multiplied by b. ''Currently disabled.''<br />
|-<br />
|OP_DIV<br />
|150<br />
|0x96<br />
|a b<br />
|c<br />
|a is divided by b (b should be not 0). ''Currently disabled.''<br />
|-<br />
|OP_MOD<br />
|151<br />
|0x97<br />
|a b<br />
|c<br />
|Returns the remainder after dividing a by b (b should be not 0). ''Currently disabled.''<br />
|-<br />
|OP_LSHIFT<br />
|152<br />
|0x98<br />
|a b<br />
|c<br />
|Shifts a left by b bits, preserving sign. ''Currently disabled.''<br />
|-<br />
|OP_RSHIFT<br />
|153<br />
|0x99<br />
|a b<br />
|c<br />
|Shifts a right by b bits, preserving sign. ''Currently disabled.''<br />
|-<br />
|OP_BOOLAND<br />
|154<br />
|0x9a<br />
|a b<br />
|Boolean<br />
|If both a and b are not 0, the output is 1. Otherwise 0.<br />
|-<br />
|OP_BOOLOR<br />
|155<br />
|0x9b<br />
|a b<br />
|Boolean<br />
|If a or b is not 0, the output is 1. Otherwise 0.<br />
|-<br />
|OP_NUMEQUAL<br />
|156<br />
|0x9c<br />
|a b<br />
|Boolean<br />
|Returns 1 if the numbers are equal, 0 otherwise.<br />
|-<br />
|OP_NUMEQUALVERIFY<br />
|157<br />
|0x9d<br />
|a b<br />
|Nothing / False<br />
|Same as OP_NUMEQUAL, but runs OP_VERIFY afterward.<br />
|-<br />
|OP_NUMNOTEQUAL<br />
|158<br />
|0x9e<br />
|a b<br />
|Boolean<br />
|Returns 1 if the numbers are not equal, 0 otherwise.<br />
|-<br />
|OP_LESSTHAN<br />
|159<br />
|0x9f<br />
|a b<br />
|Boolean<br />
|Returns 1 if a is less than b, 0 otherwise.<br />
|-<br />
|OP_GREATERTHAN<br />
|160<br />
|0xa0<br />
|a b<br />
|Boolean<br />
|Returns 1 if a is greater than b, 0 otherwise.<br />
|-<br />
|OP_LESSTHANOREQUAL<br />
|161<br />
|0xa1<br />
|a b<br />
|Boolean<br />
|Returns 1 if a is less than or equal to b, 0 otherwise.<br />
|-<br />
|OP_GREATERTHANOREQUAL<br />
|162<br />
|0xa2<br />
|a b<br />
|Boolean<br />
|Returns 1 if a is greater than or equal to b, 0 otherwise.<br />
|-<br />
|OP_MIN<br />
|163<br />
|0xa3<br />
|a b<br />
|a / b<br />
|Returns the smaller of a and b.<br />
|-<br />
|OP_MAX<br />
|164<br />
|0xa4<br />
|a b<br />
| a / b<br />
|Returns the larger of a and b.<br />
|-<br />
|OP_WITHIN<br />
|165<br />
|0xa5<br />
|x min max<br />
|Boolean<br />
|Returns 1 if x is within the specified range (left-inclusive) , 0 otherwise. min may be greater than max<br />
|}<br />
<br />
=== Crypto ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_RIPEMD160<br />
|166<br />
|0xa6<br />
|x<br />
|hash20<br />
|The input is hashed using RIPEMD-160.<br />
|-<br />
|OP_SHA1<br />
|167<br />
|0xa7<br />
|x<br />
|hash20<br />
|The input is hashed using SHA-1.<br />
|-<br />
|OP_SHA256<br />
|168<br />
|0xa8<br />
|x<br />
|hash32<br />
|The input is hashed using SHA-256.<br />
|-<br />
|OP_HASH160<br />
|169<br />
|0xa9<br />
|x<br />
|hash20<br />
|The input is hashed twice: first with SHA-256 and then with RIPEMD-160.<br />
|-<br />
|OP_HASH256<br />
|170<br />
|0xaa<br />
|x<br />
|hash32<br />
|The input is hashed two times with SHA-256.<br />
|-<br />
|OP_CODESEPARATOR<br />
|171<br />
|0xab<br />
|Nothing<br />
|Nothing<br />
|All of the signature checking opcodes will only match signatures to the data after the most recently-executed OP_CODESEPARATOR.<br />
|-<br />
|[[OP_CHECKSIG]]<br />
|172<br />
|0xac<br />
|sig pubkey<br />
|Boolean<br />
|The entire transaction's outputs, inputs, and script (from the most recently-executed OP_CODESEPARATOR to the end) are hashed. The signature used by OP_CHECKSIG must be a valid signature for a further, extern specified hash and the given public key. If it is, 1 is returned, 0 otherwise.<br />
|-<br />
|OP_CHECKSIGVERIFY<br />
|173<br />
|0xad<br />
|sig pubkey<br />
|Nothing / False<br />
|Same as OP_CHECKSIG, but OP_VERIFY is executed afterward.<br />
|-<br />
|OP_CHECKMULTISIG<br />
|174<br />
|0xae<br />
|sig1 sig2 ... <number of signatures> pub1 pub2 <number of public keys><br />
|Boolean<br />
|For each signature and public key pair, OP_CHECKSIG is executed. If more public keys than signatures are listed, some key/sig pairs can fail. All signatures need to match a public key. If all signatures are valid, 1 is returned, 0 otherwise. Due to a bug, one extra unused value is removed from the stack.<br />
|-<br />
|OP_CHECKMULTISIGVERIFY<br />
|175<br />
|0xaf<br />
|sig1 sig2 ... <number of signatures> pub1 pub2 ... <number of public keys><br />
|Nothing / False<br />
|Same as OP_CHECKMULTISIG, but OP_VERIFY is executed afterward.<br />
|}<br />
<br />
=== Expansion opcodes ===<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_NOP1-OP_NOP10<br />
|176-185<br />
|0xb0-0xb9<br />
|The opcode has no effect.<br />
|}<br />
<br />
=== Version opcodes ===<br />
Version opcodes are disabled since bitcoin 0.2.0 and should not be used (maybe reassigned in the future).<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_VER<br />
|98<br />
|0x62<br />
|Script evalution is triggered invalid (Formerly pushed the bitcoin-serialize version onto stack).<br />
|-<br />
|OP_VERIF<br />
|101<br />
|0x65<br />
|Script evalution is triggered invalid (Formerly top stack item was popped and =< compared to present version)<br />
|-<br />
|OP_VERNOTIF<br />
|102<br />
|0x66<br />
|Script evalution is triggered invalid (Formerly top stack item was popped and > compared to present version)<br />
|}<br />
<br />
=== Reserved opcodes ===<br />
Each opcode not assigned (currently also every opcode value > 185) is also reserved. Using any unassigned opcode triggers the script evaluation to be invalid.<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_RESERVED<br />
|80<br />
|0x50<br />
|Script evalution is triggered invalid-<br />
|-<br />
|OP_RESERVED1<br />
|137<br />
|0x89<br />
|Script evalution is triggered invalid.<br />
|-<br />
|OP_RESERVED2<br />
|138<br />
|0x8a<br />
|Script evalution is triggered invalid.<br />
|}<br />
<br />
===Pseudo-opcodes===<br />
These nemonics are used internally for assisting with transaction matching. They are invalid if used in actual scripts.<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_PUBKEYHASH<br />
|253<br />
|0xfd<br />
|Represents a public key hashed with OP_HASH160.<br />
|-<br />
|OP_PUBKEY<br />
|254<br />
|0xfe<br />
|Represents a public key compatible with OP_CHECKSIG.<br />
|-<br />
|OP_INVALIDOPCODE<br />
|255<br />
|0xff<br />
|Matches any opcode that is not yet assigned.<br />
|}<br />
<br />
==Scripts in bitcoin transactions==<br />
It follows a list of important (most occuring) scripts to see opcodes "at work". Keep in mind that all constants actually use the data-pushing instructions above. At start of a (transaction input) script evaluation, the stack is always empty. <br />
<br />
===Standard transaction to bitcoin address===<br />
<br />
scriptPubKey: OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG<br />
scriptSig: <sig> <pubKey><br />
<br />
To demonstrate how scripts look on the wire, here is a raw scriptPubKey:<br />
<pre> 76 A9 14<br />
OP_DUP OP_HASH160 Bytes to push<br />
<br />
89 AB CD EF AB BA AB BA AB BA AB BA AB BA AB BA AB BA AB BA 88 AC<br />
Data to push OP_EQUALVERIFY OP_CHECKSIG</pre><br />
<br />
Note: scriptSig is in the input of the spending transaction and scriptPubKey is in the output of the previously storing transaction, i.e. its "available bitcoins".<br />
<br />
Here is how each instruction is processed:<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
| <sig> <pubKey> OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| scriptSig and scriptPubKey are combined.<br />
|-<br />
|<sig> <pubKey><br />
| OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| Constants are added to the stack.<br />
|-<br />
|<sig> <pubKey> <pubKey><br />
| OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| Top stack item is duplicated.<br />
|-<br />
|<sig> <pubKey> <pubHashA><br />
|<pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG<br />
| Top stack item is hashed.<br />
|-<br />
|<sig> <pubKey> <pubHashA> <pubKeyHash><br />
|OP_EQUALVERIFY OP_CHECKSIG<br />
| Constant added.<br />
|-<br />
|<sig> <pubKey><br />
|OP_CHECKSIG<br />
| Equality is checked between the top two stack items.<br />
|-<br />
|true<br />
|Empty.<br />
|Signature is checked for top two stack items.<br />
|}<br />
<br />
===Transaction to IP address (and generation transaction)===<br />
<br />
scriptPubKey: <pubKey> OP_CHECKSIG<br />
scriptSig: <sig><br />
<br />
Checking process:<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
|<sig> <pubKey> OP_CHECKSIG<br />
|scriptSig and scriptPubKey are combined.<br />
|-<br />
|<sig> <pubKey><br />
| OP_CHECKSIG<br />
|Constants are added to the stack.<br />
|-<br />
|true<br />
|Empty.<br />
|Signature is checked for top two stack items.<br />
|}<br />
<br />
In the case of a '''coin generation transaction''' (the first transaction of each block), there is no scriptSig, resp. its code ("coinbase") is completly ignored for the transaction. Only the scriptPubKey is used.<br />
<br />
===Transaction with a message===<br />
<br />
It's possible to add arbitrary data to any transaction by just adding some data along with OP_DROP. <br />
scriptPubKey: <message> OP_DROP <pubKey> OP_CHECKSIG<br />
scriptSig: <sig><br />
<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
|<sig> <message> OP_DROP <pubKey> OP_CHECKSIG<br />
|<br />
|-<br />
|<sig><br />
|<message> OP_DROP <pubKey> OP_CHECKSIG<br />
|scriptSig added to the stack.<br />
|-<br />
|<sig> <message><br />
|OP_DROP <pubKey> OP_CHECKSIG<br />
|The message has been put.<br />
|-<br />
|<sig><br />
|<pubKey> OP_CHECKSIG<br />
|Top stack item has been removed.<br />
|-<br />
|<sig> <pubKey><br />
|OP_CHECKSIG<br />
|Checking signature against the public key.<br />
|-<br />
|true<br />
|Empty.<br />
|Stack holds the value of signature check now.<br />
|}<br />
<br />
===Examples of non standard transaction on Testnet===<br />
<br />
These two links below show a non standard transaction. It just prepends the hex of "bob" and the operation OP_DROP<br />
which just removes it. As you can see they can be spent as normal.<br />
<br />
Input non-std transaction:<br />
http://blockexplorer.com/testnet/t/6ttfeb55B1<br />
<br />
Spent by:<br />
http://blockexplorer.com/testnet/t/AFdRB1CHS3<br />
<br />
==Script validation==<br />
A script evaluation is considered invalid, if any of these conditions meets:<br><br />
<ul><br />
<li>the total size of the script exceeds (currently) 10000 bytes<br />
<li>there are more than (currently) 201 opcodes of opcode value > 0x60 in the script<br />
<li>each instruction is (currently) limited to maximal 520 bytes. This effects only the opcodes OP_PUSHDATA2 and OP_PUSHDATA4<br />
<li>the executed opcode of the script has insufficient input (from stack, from script or from anywhere)<br />
<li>the opcode is not defined (for execution) - indicated by white or light gray background color in the table<br />
<li>the opcode is disabled (currently 15 opcodes) - indicated by white font color in the opcode overview matrix<br />
<li>stack overflow occurs during execution of the opcode (currently the number of items on the stack and on the alternate stack is limited to 1000)<br />
<li>the opcodes OP_VERIF and OP_NOTVERIF invalidate a script which contains this opcode (even if this opcode is not executed!)<br />
<li>the opcodes OP_ELSE or OP_ENDIF has no matching OP_IF<br><br />
<li>the script execution has been finished but there is (at least) an unmatched OP_IF<br><br />
<li>the opcodes OP_VERIFY, OP_EQUALVERIFY, OP_NUMEQUALVERIFY, OP_CHECKSIGVERIFY and OP_CHECKMULTISIGVERIFY invalidate the script if the stack-top item is false<br />
<li>the execution of OP_RETURN<br />
<!--li>alt stack overflow occurs (only possible during execution of OP_TOALTSTACK)--><br />
<li>the numerical value of the top-stack item is negative or greater than the number of items - 2 on the stack if OP_PICK or OP_ROLL shall be executed<br />
<li>an item used as public key or signature for each of the opcodes OP_CHECKSIG, OP_CHECKSIGVERIFY, OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY can be neither a public key or signature (for the given hash)<br />
<li>the number of signature items or the number of public key items on the stack is negative for OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY<br />
<li>there or more signatures items than public key items on the stack for OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY<br />
<li>there are (currently) more than 20 public key items on the stack for OP_CHECKMULTISIG or CHECKMULTISIGVERIFY<br />
<li>the sum of opcodes > 0x60 and the number of public keys in all executed OP_CHECKMULTISIG or CHECKMULTISIGVERIFY exceeds (currently) 201<br />
<li>the script execution has been finished and the stack is empty or the top-stack item is false (numerical value 0)<br />
</ul><br />
else the script evaluation is considered to be valid.<ref>[http://sourceforge.net/projects/bitcoin/files/Bitcoin/bitcoin-0.7.1/bitcoin-0.7.1-linux.tar.gz file src/src/script.cpp in bitcoin-0.7.1]</ref><br />
'''If invalidation of a script is triggered then the script is immediately finished.''' These arbitrary looking limitations of 10000, 201, 520, 1000 and 20 might be increased in the future -- they serve to prevent strong slow down of the evaluation of a script while not restricting its practical usage really.<br />
<br />
==Withdrawn and drafted opcodes==<br />
<br />
<ul><br />
<li> byte value 0x89 OP_NOTEQUAL defined in pre-0.1.0 bitcoin versions. Since 0.1.0 removed because of security concerns. <br />
<li> byte value 0xb1 [[BIP 0012 | OP_EVAL]] withdraw - poll was triggered but insufficient support. <br />
<li> byte value 0xb2 [[BIP 0017 | OP_CHECKHASHVERIFY]] withdraw - poll was triggered but insufficient support.<br />
</ul><br />
<br />
==See Also==<br />
* [[Transactions]]<br />
* [[Contracts]]<br />
<br />
==References==<br />
<references/><br />
<ul><br />
<li>[http://www.zorinaq.com/pub/bitcoin-0.1.0.tgz file src/script.cpp in bitcoin-0.1.0]</li><br />
</ul><br />
[[Category:Technical]]<br />
[[Category:Vocabulary]]</div>
Smtp
https://en.bitcoin.it/w/index.php?title=OP_CHECKSIG&diff=34872
OP CHECKSIG
2013-01-09T23:02:38Z
<p>Smtp: /* Final signature check */</p>
<hr />
<div>OP_CHECKSIG is [[Script|script]] opcode used to verify that the signature for a tx input is valid. OP_CHECKSIG expects two values to be on the stack, these are, in order of stack depth, the public key and the signature of the script. These two values are normally obtained by running the scriptSig script of the transaction input we are attempting to validate. After the scriptSig script is run the script is deleted but the stack is left as is, and then then scriptPubKey script from the previous transaction output that is now being spent is run, generally concluding in an OP_CHECKSIG. <br />
<br />
The standard scriptPubKey checks that the public key (actually a hash of) is a particular value, and that OP_CHECKSIG passes.<br />
<br />
For normal transaction inputs if the creator of the current transaction can successfully create a ScriptSig signature that uses the right public key for the ScriptPubKey of the transaction output they are attempting to spend, that transaction input is considered valid. <br />
<br />
== Parameters ==<br />
<br />
In addition to the script code itself and the stack parameters, to operate OP_CHECKSIG needs to know the current transaction and the index of current transaction input.<br />
<br />
== How it works ==<br />
Firstly always this (the default) procedure is applied:<br />
[[File:Bitcoin_OpCheckSig_InDetail.png|thumb|right|Signature verification process of the default procedure]]<br />
# the public key and the signature are popped from the stack, in that order. If the hash-type value is 0, then it is replaced by the last_byte of the signature. Then the last byte of the signature is always deleted.<br />
# A new subscript is created from the instruction from the most recently parsed OP_CODESEPARATOR (last one in script) to the end of the script. If there is no OP_CODESEPARATOR the entire script becomes the subscript (hereby referred to as subScript)<br />
# The sig is deleted from subScript.<br />
# All OP_CODESEPARATORS are removed from subScript<br />
# The hashtype is removed from the last byte of the sig and stored<br />
# A copy is made of the current transaction (hereby referred to txCopy)<br />
# The scripts for all transaction inputs in txCopy are set to empty scripts (exactly 1 byte 0x00)<br />
# The script for the current transaction input in txCopy is set to subScript (lead in by its length as a var-integer encoded!)<br />
<br />
Now depending on the hashtype various things can happen to txCopy, these will be discussed individually.<br />
<br />
'''Hashtype Values (from script.h):'''<br />
{|class="wikitable"<br />
! Name !! Value<br />
|-<br />
| SIGHASH_ALL || 0x00000001<br />
|-<br />
| SIGHASH_NONE || 0x00000002<br />
|-<br />
| SIGHASH_SINGLE || 0x00000003<br />
|-<br />
| SIGHASH_ANYONECANPAY || 0x00000080<br />
|}<br />
<br />
<ol><br />
<li> If (hashtype&31) = SIGHASH_NONE then apply the SIGHASH_NONE-procedure<br />
<li> If (hashtype&31) = SIGHASH_SINGLE then apply the SIGHASH_SINGLE-procedure<br />
<li> If hashtype & SIGHASH_ANYONECANPAY then apply the SIGHASH_ANYONECANPAY-procedure<br />
</ol><br />
Hence, hashtype SIGHASH_ANYONECANPAY may be applied also after any other hashtype-procedure<ref>[http://sourceforge.net/projects/bitcoin/files/Bitcoin/bitcoin-0.7.1/bitcoin-0.7.1-linux.tar.gz file src/src/script.cpp in bitcoin-0.7.1]</ref>. Besides the four listed hashtypes only a hashtype of value 0 appears a few types in the (main) block chain (and is handled like SIGHASH_ALL).<br />
<br />
=== Hashtype SIGHASH_ALL (default) ===<br />
<br />
No special further handling occurs in the default case. Think of this as "sign '''all''' of the outputs." Which is already done by the default procedure.<br />
<br />
=== Procedure for Hashtype SIGHASH_NONE ===<br />
<br />
# The output of txCopy is set to a vector of zero size.<br />
# All other inputs aside from the current input in txCopy have their nSequence index set to zero<br />
<br />
Think of this as "sign '''none''' of the outputs-- I don't care where the bitcoins go."<br />
<br />
=== Procedure for Hashtype SIGHASH_SINGLE ===<br />
<br />
# The output of txCopy is resized to the size of the current input index+1<br />
# All other txCopy outputs aside from the output that is the same as the current input index are set to a blank script and a value of (long) -1;<br />
# All other txCopy inputs aside from the current input are set to have an nSequence index of zero<br />
<br />
Think of this as "sign '''one''' of the outputs-- I don't care where the other outputs go."<br />
<br />
=== Procedure for Hashtype SIGHASH_ANYONECANPAY ===<br />
<br />
# The txCopy input vector is resized to a length of one<br />
# The current input is set as the first and only member of this vector<br />
<br />
Think of this as "Let other people add inputs to this transaction, I don't care where the rest of the bitcoins come from."<br />
<br />
===Final signature check===<br />
<br />
An array of bytes is constructed from the serialized txCopy appended by four bytes for the hash type. This array is sha256 hashed twice, then the public key is used to to check the supplied signature against the hash.<br />
The secp256k1 elliptic curve is used for the verification with the given public key.<br />
<br />
== Return values ==<br />
<br />
OP_CHECKSIG will push true to the stack if the check passed, false otherwise.<br />
OP_CHECKSIG_VERIFY leaves nothing on the stack but will cause the script eval to fail immediately if the check does not pass.<br />
<br />
== Code samples and raw dumps ==<br />
<br />
Taking the first transaction in Bitcoin which is in block number 170, we would get after serialising the transaction but before we hash+sign (or verify) it:<br />
<br />
* http://blockexplorer.com/block/00000000d1145790a8694403d4063f323d499e655c83426834d4ce2f8dd4a2ee<br />
* http://blockexplorer.com/tx/f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16<br />
<br />
See also [https://gitorious.org/libbitcoin/libbitcoin libbitcoin] for code samples.<br />
<br />
<pre><br />
01 00 00 00 version<br />
01 number of inputs (var_uint)<br />
<br />
input 0:<br />
c9 97 a5 e5 6e 10 41 02 input address hash<br />
fa 20 9c 6a 85 2d d9 06 <br />
60 a2 0b 2d 9c 35 24 23 <br />
ed ce 25 85 7f cd 37 04<br />
00 00 00 00 input index<br />
<br />
48 size of script (var_uint)<br />
47 push 71 bytes to stack<br />
30 44 02 20 4e 45 e1 69<br />
32 b8 af 51 49 61 a1 d3<br />
a1 a2 5f df 3f 4f 77 32<br />
e9 d6 24 c6 c6 15 48 ab<br />
5f b8 cd 41 02 20 18 15<br />
22 ec 8e ca 07 de 48 60<br />
a4 ac dd 12 90 9d 83 1c<br />
c5 6c bb ac 46 22 08 22<br />
21 a8 76 8d 1d 09 01<br />
ff ff ff ff sequence<br />
<br />
02 number of outputs (var_uint)<br />
<br />
output 0:<br />
00 ca 9a 3b 00 00 00 00 amount = 10.00000000<br />
43 size of script (var_uint)<br />
script for output 0:<br />
41 push 65 bytes to stack<br />
04 ae 1a 62 fe 09 c5 f5 <br />
1b 13 90 5f 07 f0 6b 99 <br />
a2 f7 15 9b 22 25 f3 74 <br />
cd 37 8d 71 30 2f a2 84 <br />
14 e7 aa b3 73 97 f5 54 <br />
a7 df 5f 14 2c 21 c1 b7 <br />
30 3b 8a 06 26 f1 ba de <br />
d5 c7 2a 70 4f 7e 6c d8 <br />
4c <br />
ac OP_CHECKSIG<br />
<br />
output 1:<br />
00 28 6b ee 00 00 00 00 amount = 40.00000000<br />
43 size of script (var_uint)<br />
script for output 1:<br />
41 push 65 bytes to stack<br />
04 11 db 93 e1 dc db 8a <br />
01 6b 49 84 0f 8c 53 bc <br />
1e b6 8a 38 2e 97 b1 48 <br />
2e ca d7 b1 48 a6 90 9a<br />
5c b2 e0 ea dd fb 84 cc <br />
f9 74 44 64 f8 2e 16 0b <br />
fa 9b 8b 64 f9 d4 c0 3f <br />
99 9b 86 43 f6 56 b4 12 <br />
a3 <br />
ac OP_CHECKSIG<br />
<br />
00 00 00 00 locktime<br />
01 00 00 00 hash_code_type (added on)<br />
<br />
result =<br />
01 00 00 00 01 c9 97 a5 e5 6e 10 41 02 fa 20 9c 6a 85 2d d9 06 60 a2 0b 2d 9c 35 <br />
24 23 ed ce 25 85 7f cd 37 04 00 00 00 00 43 41 04 11 db 93 e1 dc db 8a 01 6b 49 <br />
84 0f 8c 53 bc 1e b6 8a 38 2e 97 b1 48 2e ca d7 b1 48 a6 90 9a 5c b2 e0 ea dd fb <br />
84 cc f9 74 44 64 f8 2e 16 0b fa 9b 8b 64 f9 d4 c0 3f 99 9b 86 43 f6 56 b4 12 a3 <br />
ac ff ff ff ff 02 00 ca 9a 3b 00 00 00 00 43 41 04 ae 1a 62 fe 09 c5 f5 1b 13 90 <br />
5f 07 f0 6b 99 a2 f7 15 9b 22 25 f3 74 cd 37 8d 71 30 2f a2 84 14 e7 aa b3 73 97 <br />
f5 54 a7 df 5f 14 2c 21 c1 b7 30 3b 8a 06 26 f1 ba de d5 c7 2a 70 4f 7e 6c d8 4c <br />
ac 00 28 6b ee 00 00 00 00 43 41 04 11 db 93 e1 dc db 8a 01 6b 49 84 0f 8c 53 bc <br />
1e b6 8a 38 2e 97 b1 48 2e ca d7 b1 48 a6 90 9a 5c b2 e0 ea dd fb 84 cc f9 74 44 <br />
64 f8 2e 16 0b fa 9b 8b 64 f9 d4 c0 3f 99 9b 86 43 f6 56 b4 12 a3 ac 00 00 00 00 <br />
01 00 00 00 <br />
</pre><br />
<br />
To understand where that raw dump has come from, it may be useful to examine tests/ec-key.cpp in [https://gitorious.org/libbitcoin/libbitcoin libbitcoin],<br />
<br />
[https://gitorious.org/libbitcoin/libbitcoin libbitcoin] has a unit test under tests/ec-key.cpp (make ec-key && ./bin/tests/ec-key). There is also a working OP_CHECKSIG implementation in src/script.cpp under script::op_checksig(). See also the unit test: tests/script-test.cpp<br />
<br />
<source lang="cpp"><br />
#include <iostream><br />
#include <iomanip><br />
#include <bitcoin/util/serializer.hpp><br />
#include <bitcoin/util/elliptic_curve_key.hpp><br />
#include <bitcoin/util/sha256.hpp><br />
#include <bitcoin/util/assert.hpp><br />
#include <bitcoin/util/logger.hpp><br />
#include <bitcoin/types.hpp><br />
#include <openssl/ecdsa.h><br />
#include <openssl/obj_mac.h><br />
using libbitcoin::elliptic_curve_key;<br />
using libbitcoin::serializer;<br />
using libbitcoin::hash_digest;<br />
using libbitcoin::data_chunk;<br />
using libbitcoin::log_info;<br />
using libbitcoin::log_fatal;<br />
<br />
int main()<br />
{<br />
serializer ss;<br />
// blk number 170, tx 1, input 0<br />
// version = 1<br />
ss.write_4_bytes(1);<br />
// 1 inputs<br />
ss.write_var_uint(1);<br />
<br />
// input 0<br />
// prevout hash<br />
ss.write_hash(hash_digest{0x04, 0x37, 0xcd, 0x7f, 0x85, 0x25, 0xce, 0xed, 0x23, 0x24, 0x35, 0x9c, 0x2d, 0x0b, 0xa2, 0x60, 0x06, 0xd9, 0x2d, 0x85, 0x6a, 0x9c, 0x20, 0xfa, 0x02, 0x41, 0x10, 0x6e, 0xe5, 0xa5, 0x97, 0xc9});<br />
// prevout index <br />
ss.write_4_bytes(0);<br />
<br />
// input script after running OP_CHECKSIG for this tx is a single<br />
// OP_CHECKSIG opcode<br />
data_chunk raw_data;<br />
raw_data = {0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3};<br />
data_chunk raw_script;<br />
raw_script = data_chunk();<br />
raw_script.push_back(raw_data.size());<br />
libbitcoin::extend_data(raw_script, raw_data);<br />
raw_script.push_back(172);<br />
ss.write_var_uint(raw_script.size());<br />
ss.write_data(raw_script);<br />
// sequence<br />
ss.write_4_bytes(0xffffffff);<br />
<br />
// 2 outputs for this tx<br />
ss.write_var_uint(2);<br />
<br />
// output 0<br />
ss.write_8_bytes(1000000000);<br />
// script for output 0<br />
raw_data = {0x04, 0xae, 0x1a, 0x62, 0xfe, 0x09, 0xc5, 0xf5, 0x1b, 0x13, 0x90, 0x5f, 0x07, 0xf0, 0x6b, 0x99, 0xa2, 0xf7, 0x15, 0x9b, 0x22, 0x25, 0xf3, 0x74, 0xcd, 0x37, 0x8d, 0x71, 0x30, 0x2f, 0xa2, 0x84, 0x14, 0xe7, 0xaa, 0xb3, 0x73, 0x97, 0xf5, 0x54, 0xa7, 0xdf, 0x5f, 0x14, 0x2c, 0x21, 0xc1, 0xb7, 0x30, 0x3b, 0x8a, 0x06, 0x26, 0xf1, 0xba, 0xde, 0xd5, 0xc7, 0x2a, 0x70, 0x4f, 0x7e, 0x6c, 0xd8, 0x4c};<br />
// when data < 75, we can just write it's length as a single byte ('special'<br />
// opcodes)<br />
raw_script = data_chunk();<br />
raw_script.push_back(raw_data.size());<br />
libbitcoin::extend_data(raw_script, raw_data);<br />
// OP_CHECKSIG<br />
raw_script.push_back(172);<br />
// now actually write the script<br />
ss.write_var_uint(raw_script.size());<br />
ss.write_data(raw_script);<br />
<br />
// output 0<br />
ss.write_8_bytes(4000000000);<br />
// script for output 0<br />
raw_data = {0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3};<br />
// when data < 75, we can just write it's length as a single byte ('special'<br />
raw_script.push_back(raw_data.size());<br />
libbitcoin::extend_data(raw_script, raw_data);<br />
// OP_CHECKSIG<br />
raw_script.push_back(172);<br />
// now actually write the script<br />
ss.write_var_uint(raw_script.size());<br />
ss.write_data(raw_script);<br />
<br />
// End of 2 outputs<br />
<br />
// locktime<br />
ss.write_4_bytes(0);<br />
<br />
// write hash_type_code<br />
ss.write_4_bytes(1);<br />
<br />
// Dump hex to screen<br />
log_info() << "hashing:";<br />
{<br />
auto log_obj = log_info();<br />
log_obj << std::hex;<br />
for (int val: ss.get_data())<br />
log_obj << std::setfill('0') << std::setw(2) << val << ' ';<br />
}<br />
log_info();<br />
<br />
data_chunk raw_tx = {0x01, 0x00, 0x00, 0x00, 0x01, 0xc9, 0x97, 0xa5, 0xe5, 0x6e, 0x10, 0x41, 0x02, 0xfa, 0x20, 0x9c, 0x6a, 0x85, 0x2d, 0xd9, 0x06, 0x60, 0xa2, 0x0b, 0x2d, 0x9c, 0x35, 0x24, 0x23, 0xed, 0xce, 0x25, 0x85, 0x7f, 0xcd, 0x37, 0x04, 0x00, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3, 0xac, 0xff, 0xff, 0xff, 0xff, 0x02, 0x00, 0xca, 0x9a, 0x3b, 0x00, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, 0xae, 0x1a, 0x62, 0xfe, 0x09, 0xc5, 0xf5, 0x1b, 0x13, 0x90, 0x5f, 0x07, 0xf0, 0x6b, 0x99, 0xa2, 0xf7, 0x15, 0x9b, 0x22, 0x25, 0xf3, 0x74, 0xcd, 0x37, 0x8d, 0x71, 0x30, 0x2f, 0xa2, 0x84, 0x14, 0xe7, 0xaa, 0xb3, 0x73, 0x97, 0xf5, 0x54, 0xa7, 0xdf, 0x5f, 0x14, 0x2c, 0x21, 0xc1, 0xb7, 0x30, 0x3b, 0x8a, 0x06, 0x26, 0xf1, 0xba, 0xde, 0xd5, 0xc7, 0x2a, 0x70, 0x4f, 0x7e, 0x6c, 0xd8, 0x4c, 0xac, 0x00, 0x28, 0x6b, 0xee, 0x00, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3, 0xac, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00};<br />
BITCOIN_ASSERT(raw_tx == ss.get_data());<br />
<br />
hash_digest tx_hash = libbitcoin::generate_sha256_hash(ss.get_data());<br />
<br />
data_chunk pubkey{0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3};<br />
// Leave out last byte since that's the hash_type_code (SIGHASH_ALL in this<br />
// case)<br />
data_chunk signature{0x30, 0x44, 0x02, 0x20, 0x4e, 0x45, 0xe1, 0x69, 0x32, 0xb8, 0xaf, 0x51, 0x49, 0x61, 0xa1, 0xd3, 0xa1, 0xa2, 0x5f, 0xdf, 0x3f, 0x4f, 0x77, 0x32, 0xe9, 0xd6, 0x24, 0xc6, 0xc6, 0x15, 0x48, 0xab, 0x5f, 0xb8, 0xcd, 0x41, 0x02, 0x20, 0x18, 0x15, 0x22, 0xec, 0x8e, 0xca, 0x07, 0xde, 0x48, 0x60, 0xa4, 0xac, 0xdd, 0x12, 0x90, 0x9d, 0x83, 0x1c, 0xc5, 0x6c, 0xbb, 0xac, 0x46, 0x22, 0x08, 0x22, 0x21, 0xa8, 0x76, 0x8d, 0x1d, 0x09};<br />
BITCOIN_ASSERT(signature.size() == 70);<br />
<br />
elliptic_curve_key key;<br />
if (!key.set_public_key(pubkey))<br />
{<br />
log_fatal() << "unable to set EC public key";<br />
return -1;<br />
}<br />
<br />
log_info() << "checksig returns: " << (key.verify(tx_hash, signature) ? "true" : "false");<br />
return 0;<br />
}<br />
<br />
</source><br />
<br />
==References==<br />
<references/><br />
<br />
[[Category:Technical]]<br />
[[Category:Developer]]</div>
Smtp
https://en.bitcoin.it/w/index.php?title=OP_CHECKSIG&diff=34871
OP CHECKSIG
2013-01-09T23:01:04Z
<p>Smtp: /* Final signature check */</p>
<hr />
<div>OP_CHECKSIG is [[Script|script]] opcode used to verify that the signature for a tx input is valid. OP_CHECKSIG expects two values to be on the stack, these are, in order of stack depth, the public key and the signature of the script. These two values are normally obtained by running the scriptSig script of the transaction input we are attempting to validate. After the scriptSig script is run the script is deleted but the stack is left as is, and then then scriptPubKey script from the previous transaction output that is now being spent is run, generally concluding in an OP_CHECKSIG. <br />
<br />
The standard scriptPubKey checks that the public key (actually a hash of) is a particular value, and that OP_CHECKSIG passes.<br />
<br />
For normal transaction inputs if the creator of the current transaction can successfully create a ScriptSig signature that uses the right public key for the ScriptPubKey of the transaction output they are attempting to spend, that transaction input is considered valid. <br />
<br />
== Parameters ==<br />
<br />
In addition to the script code itself and the stack parameters, to operate OP_CHECKSIG needs to know the current transaction and the index of current transaction input.<br />
<br />
== How it works ==<br />
Firstly always this (the default) procedure is applied:<br />
[[File:Bitcoin_OpCheckSig_InDetail.png|thumb|right|Signature verification process of the default procedure]]<br />
# the public key and the signature are popped from the stack, in that order. If the hash-type value is 0, then it is replaced by the last_byte of the signature. Then the last byte of the signature is always deleted.<br />
# A new subscript is created from the instruction from the most recently parsed OP_CODESEPARATOR (last one in script) to the end of the script. If there is no OP_CODESEPARATOR the entire script becomes the subscript (hereby referred to as subScript)<br />
# The sig is deleted from subScript.<br />
# All OP_CODESEPARATORS are removed from subScript<br />
# The hashtype is removed from the last byte of the sig and stored<br />
# A copy is made of the current transaction (hereby referred to txCopy)<br />
# The scripts for all transaction inputs in txCopy are set to empty scripts (exactly 1 byte 0x00)<br />
# The script for the current transaction input in txCopy is set to subScript (lead in by its length as a var-integer encoded!)<br />
<br />
Now depending on the hashtype various things can happen to txCopy, these will be discussed individually.<br />
<br />
'''Hashtype Values (from script.h):'''<br />
{|class="wikitable"<br />
! Name !! Value<br />
|-<br />
| SIGHASH_ALL || 0x00000001<br />
|-<br />
| SIGHASH_NONE || 0x00000002<br />
|-<br />
| SIGHASH_SINGLE || 0x00000003<br />
|-<br />
| SIGHASH_ANYONECANPAY || 0x00000080<br />
|}<br />
<br />
<ol><br />
<li> If (hashtype&31) = SIGHASH_NONE then apply the SIGHASH_NONE-procedure<br />
<li> If (hashtype&31) = SIGHASH_SINGLE then apply the SIGHASH_SINGLE-procedure<br />
<li> If hashtype & SIGHASH_ANYONECANPAY then apply the SIGHASH_ANYONECANPAY-procedure<br />
</ol><br />
Hence, hashtype SIGHASH_ANYONECANPAY may be applied also after any other hashtype-procedure<ref>[http://sourceforge.net/projects/bitcoin/files/Bitcoin/bitcoin-0.7.1/bitcoin-0.7.1-linux.tar.gz file src/src/script.cpp in bitcoin-0.7.1]</ref>. Besides the four listed hashtypes only a hashtype of value 0 appears a few types in the (main) block chain (and is handled like SIGHASH_ALL).<br />
<br />
=== Hashtype SIGHASH_ALL (default) ===<br />
<br />
No special further handling occurs in the default case. Think of this as "sign '''all''' of the outputs." Which is already done by the default procedure.<br />
<br />
=== Procedure for Hashtype SIGHASH_NONE ===<br />
<br />
# The output of txCopy is set to a vector of zero size.<br />
# All other inputs aside from the current input in txCopy have their nSequence index set to zero<br />
<br />
Think of this as "sign '''none''' of the outputs-- I don't care where the bitcoins go."<br />
<br />
=== Procedure for Hashtype SIGHASH_SINGLE ===<br />
<br />
# The output of txCopy is resized to the size of the current input index+1<br />
# All other txCopy outputs aside from the output that is the same as the current input index are set to a blank script and a value of (long) -1;<br />
# All other txCopy inputs aside from the current input are set to have an nSequence index of zero<br />
<br />
Think of this as "sign '''one''' of the outputs-- I don't care where the other outputs go."<br />
<br />
=== Procedure for Hashtype SIGHASH_ANYONECANPAY ===<br />
<br />
# The txCopy input vector is resized to a length of one<br />
# The current input is set as the first and only member of this vector<br />
<br />
Think of this as "Let other people add inputs to this transaction, I don't care where the rest of the bitcoins come from."<br />
<br />
===Final signature check===<br />
<br />
An array of bytes is constructed from the serialized txCopy + four bytes for the hash type. This array is sha256 hashed twice, then the public key is used to to check the supplied signature against the hash.<br />
The secp256k1 elliptic curve is used for the verification with the given public key.<br />
<br />
== Return values ==<br />
<br />
OP_CHECKSIG will push true to the stack if the check passed, false otherwise.<br />
OP_CHECKSIG_VERIFY leaves nothing on the stack but will cause the script eval to fail immediately if the check does not pass.<br />
<br />
== Code samples and raw dumps ==<br />
<br />
Taking the first transaction in Bitcoin which is in block number 170, we would get after serialising the transaction but before we hash+sign (or verify) it:<br />
<br />
* http://blockexplorer.com/block/00000000d1145790a8694403d4063f323d499e655c83426834d4ce2f8dd4a2ee<br />
* http://blockexplorer.com/tx/f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16<br />
<br />
See also [https://gitorious.org/libbitcoin/libbitcoin libbitcoin] for code samples.<br />
<br />
<pre><br />
01 00 00 00 version<br />
01 number of inputs (var_uint)<br />
<br />
input 0:<br />
c9 97 a5 e5 6e 10 41 02 input address hash<br />
fa 20 9c 6a 85 2d d9 06 <br />
60 a2 0b 2d 9c 35 24 23 <br />
ed ce 25 85 7f cd 37 04<br />
00 00 00 00 input index<br />
<br />
48 size of script (var_uint)<br />
47 push 71 bytes to stack<br />
30 44 02 20 4e 45 e1 69<br />
32 b8 af 51 49 61 a1 d3<br />
a1 a2 5f df 3f 4f 77 32<br />
e9 d6 24 c6 c6 15 48 ab<br />
5f b8 cd 41 02 20 18 15<br />
22 ec 8e ca 07 de 48 60<br />
a4 ac dd 12 90 9d 83 1c<br />
c5 6c bb ac 46 22 08 22<br />
21 a8 76 8d 1d 09 01<br />
ff ff ff ff sequence<br />
<br />
02 number of outputs (var_uint)<br />
<br />
output 0:<br />
00 ca 9a 3b 00 00 00 00 amount = 10.00000000<br />
43 size of script (var_uint)<br />
script for output 0:<br />
41 push 65 bytes to stack<br />
04 ae 1a 62 fe 09 c5 f5 <br />
1b 13 90 5f 07 f0 6b 99 <br />
a2 f7 15 9b 22 25 f3 74 <br />
cd 37 8d 71 30 2f a2 84 <br />
14 e7 aa b3 73 97 f5 54 <br />
a7 df 5f 14 2c 21 c1 b7 <br />
30 3b 8a 06 26 f1 ba de <br />
d5 c7 2a 70 4f 7e 6c d8 <br />
4c <br />
ac OP_CHECKSIG<br />
<br />
output 1:<br />
00 28 6b ee 00 00 00 00 amount = 40.00000000<br />
43 size of script (var_uint)<br />
script for output 1:<br />
41 push 65 bytes to stack<br />
04 11 db 93 e1 dc db 8a <br />
01 6b 49 84 0f 8c 53 bc <br />
1e b6 8a 38 2e 97 b1 48 <br />
2e ca d7 b1 48 a6 90 9a<br />
5c b2 e0 ea dd fb 84 cc <br />
f9 74 44 64 f8 2e 16 0b <br />
fa 9b 8b 64 f9 d4 c0 3f <br />
99 9b 86 43 f6 56 b4 12 <br />
a3 <br />
ac OP_CHECKSIG<br />
<br />
00 00 00 00 locktime<br />
01 00 00 00 hash_code_type (added on)<br />
<br />
result =<br />
01 00 00 00 01 c9 97 a5 e5 6e 10 41 02 fa 20 9c 6a 85 2d d9 06 60 a2 0b 2d 9c 35 <br />
24 23 ed ce 25 85 7f cd 37 04 00 00 00 00 43 41 04 11 db 93 e1 dc db 8a 01 6b 49 <br />
84 0f 8c 53 bc 1e b6 8a 38 2e 97 b1 48 2e ca d7 b1 48 a6 90 9a 5c b2 e0 ea dd fb <br />
84 cc f9 74 44 64 f8 2e 16 0b fa 9b 8b 64 f9 d4 c0 3f 99 9b 86 43 f6 56 b4 12 a3 <br />
ac ff ff ff ff 02 00 ca 9a 3b 00 00 00 00 43 41 04 ae 1a 62 fe 09 c5 f5 1b 13 90 <br />
5f 07 f0 6b 99 a2 f7 15 9b 22 25 f3 74 cd 37 8d 71 30 2f a2 84 14 e7 aa b3 73 97 <br />
f5 54 a7 df 5f 14 2c 21 c1 b7 30 3b 8a 06 26 f1 ba de d5 c7 2a 70 4f 7e 6c d8 4c <br />
ac 00 28 6b ee 00 00 00 00 43 41 04 11 db 93 e1 dc db 8a 01 6b 49 84 0f 8c 53 bc <br />
1e b6 8a 38 2e 97 b1 48 2e ca d7 b1 48 a6 90 9a 5c b2 e0 ea dd fb 84 cc f9 74 44 <br />
64 f8 2e 16 0b fa 9b 8b 64 f9 d4 c0 3f 99 9b 86 43 f6 56 b4 12 a3 ac 00 00 00 00 <br />
01 00 00 00 <br />
</pre><br />
<br />
To understand where that raw dump has come from, it may be useful to examine tests/ec-key.cpp in [https://gitorious.org/libbitcoin/libbitcoin libbitcoin],<br />
<br />
[https://gitorious.org/libbitcoin/libbitcoin libbitcoin] has a unit test under tests/ec-key.cpp (make ec-key && ./bin/tests/ec-key). There is also a working OP_CHECKSIG implementation in src/script.cpp under script::op_checksig(). See also the unit test: tests/script-test.cpp<br />
<br />
<source lang="cpp"><br />
#include <iostream><br />
#include <iomanip><br />
#include <bitcoin/util/serializer.hpp><br />
#include <bitcoin/util/elliptic_curve_key.hpp><br />
#include <bitcoin/util/sha256.hpp><br />
#include <bitcoin/util/assert.hpp><br />
#include <bitcoin/util/logger.hpp><br />
#include <bitcoin/types.hpp><br />
#include <openssl/ecdsa.h><br />
#include <openssl/obj_mac.h><br />
using libbitcoin::elliptic_curve_key;<br />
using libbitcoin::serializer;<br />
using libbitcoin::hash_digest;<br />
using libbitcoin::data_chunk;<br />
using libbitcoin::log_info;<br />
using libbitcoin::log_fatal;<br />
<br />
int main()<br />
{<br />
serializer ss;<br />
// blk number 170, tx 1, input 0<br />
// version = 1<br />
ss.write_4_bytes(1);<br />
// 1 inputs<br />
ss.write_var_uint(1);<br />
<br />
// input 0<br />
// prevout hash<br />
ss.write_hash(hash_digest{0x04, 0x37, 0xcd, 0x7f, 0x85, 0x25, 0xce, 0xed, 0x23, 0x24, 0x35, 0x9c, 0x2d, 0x0b, 0xa2, 0x60, 0x06, 0xd9, 0x2d, 0x85, 0x6a, 0x9c, 0x20, 0xfa, 0x02, 0x41, 0x10, 0x6e, 0xe5, 0xa5, 0x97, 0xc9});<br />
// prevout index <br />
ss.write_4_bytes(0);<br />
<br />
// input script after running OP_CHECKSIG for this tx is a single<br />
// OP_CHECKSIG opcode<br />
data_chunk raw_data;<br />
raw_data = {0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3};<br />
data_chunk raw_script;<br />
raw_script = data_chunk();<br />
raw_script.push_back(raw_data.size());<br />
libbitcoin::extend_data(raw_script, raw_data);<br />
raw_script.push_back(172);<br />
ss.write_var_uint(raw_script.size());<br />
ss.write_data(raw_script);<br />
// sequence<br />
ss.write_4_bytes(0xffffffff);<br />
<br />
// 2 outputs for this tx<br />
ss.write_var_uint(2);<br />
<br />
// output 0<br />
ss.write_8_bytes(1000000000);<br />
// script for output 0<br />
raw_data = {0x04, 0xae, 0x1a, 0x62, 0xfe, 0x09, 0xc5, 0xf5, 0x1b, 0x13, 0x90, 0x5f, 0x07, 0xf0, 0x6b, 0x99, 0xa2, 0xf7, 0x15, 0x9b, 0x22, 0x25, 0xf3, 0x74, 0xcd, 0x37, 0x8d, 0x71, 0x30, 0x2f, 0xa2, 0x84, 0x14, 0xe7, 0xaa, 0xb3, 0x73, 0x97, 0xf5, 0x54, 0xa7, 0xdf, 0x5f, 0x14, 0x2c, 0x21, 0xc1, 0xb7, 0x30, 0x3b, 0x8a, 0x06, 0x26, 0xf1, 0xba, 0xde, 0xd5, 0xc7, 0x2a, 0x70, 0x4f, 0x7e, 0x6c, 0xd8, 0x4c};<br />
// when data < 75, we can just write it's length as a single byte ('special'<br />
// opcodes)<br />
raw_script = data_chunk();<br />
raw_script.push_back(raw_data.size());<br />
libbitcoin::extend_data(raw_script, raw_data);<br />
// OP_CHECKSIG<br />
raw_script.push_back(172);<br />
// now actually write the script<br />
ss.write_var_uint(raw_script.size());<br />
ss.write_data(raw_script);<br />
<br />
// output 0<br />
ss.write_8_bytes(4000000000);<br />
// script for output 0<br />
raw_data = {0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3};<br />
// when data < 75, we can just write it's length as a single byte ('special'<br />
raw_script.push_back(raw_data.size());<br />
libbitcoin::extend_data(raw_script, raw_data);<br />
// OP_CHECKSIG<br />
raw_script.push_back(172);<br />
// now actually write the script<br />
ss.write_var_uint(raw_script.size());<br />
ss.write_data(raw_script);<br />
<br />
// End of 2 outputs<br />
<br />
// locktime<br />
ss.write_4_bytes(0);<br />
<br />
// write hash_type_code<br />
ss.write_4_bytes(1);<br />
<br />
// Dump hex to screen<br />
log_info() << "hashing:";<br />
{<br />
auto log_obj = log_info();<br />
log_obj << std::hex;<br />
for (int val: ss.get_data())<br />
log_obj << std::setfill('0') << std::setw(2) << val << ' ';<br />
}<br />
log_info();<br />
<br />
data_chunk raw_tx = {0x01, 0x00, 0x00, 0x00, 0x01, 0xc9, 0x97, 0xa5, 0xe5, 0x6e, 0x10, 0x41, 0x02, 0xfa, 0x20, 0x9c, 0x6a, 0x85, 0x2d, 0xd9, 0x06, 0x60, 0xa2, 0x0b, 0x2d, 0x9c, 0x35, 0x24, 0x23, 0xed, 0xce, 0x25, 0x85, 0x7f, 0xcd, 0x37, 0x04, 0x00, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3, 0xac, 0xff, 0xff, 0xff, 0xff, 0x02, 0x00, 0xca, 0x9a, 0x3b, 0x00, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, 0xae, 0x1a, 0x62, 0xfe, 0x09, 0xc5, 0xf5, 0x1b, 0x13, 0x90, 0x5f, 0x07, 0xf0, 0x6b, 0x99, 0xa2, 0xf7, 0x15, 0x9b, 0x22, 0x25, 0xf3, 0x74, 0xcd, 0x37, 0x8d, 0x71, 0x30, 0x2f, 0xa2, 0x84, 0x14, 0xe7, 0xaa, 0xb3, 0x73, 0x97, 0xf5, 0x54, 0xa7, 0xdf, 0x5f, 0x14, 0x2c, 0x21, 0xc1, 0xb7, 0x30, 0x3b, 0x8a, 0x06, 0x26, 0xf1, 0xba, 0xde, 0xd5, 0xc7, 0x2a, 0x70, 0x4f, 0x7e, 0x6c, 0xd8, 0x4c, 0xac, 0x00, 0x28, 0x6b, 0xee, 0x00, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3, 0xac, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00};<br />
BITCOIN_ASSERT(raw_tx == ss.get_data());<br />
<br />
hash_digest tx_hash = libbitcoin::generate_sha256_hash(ss.get_data());<br />
<br />
data_chunk pubkey{0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3};<br />
// Leave out last byte since that's the hash_type_code (SIGHASH_ALL in this<br />
// case)<br />
data_chunk signature{0x30, 0x44, 0x02, 0x20, 0x4e, 0x45, 0xe1, 0x69, 0x32, 0xb8, 0xaf, 0x51, 0x49, 0x61, 0xa1, 0xd3, 0xa1, 0xa2, 0x5f, 0xdf, 0x3f, 0x4f, 0x77, 0x32, 0xe9, 0xd6, 0x24, 0xc6, 0xc6, 0x15, 0x48, 0xab, 0x5f, 0xb8, 0xcd, 0x41, 0x02, 0x20, 0x18, 0x15, 0x22, 0xec, 0x8e, 0xca, 0x07, 0xde, 0x48, 0x60, 0xa4, 0xac, 0xdd, 0x12, 0x90, 0x9d, 0x83, 0x1c, 0xc5, 0x6c, 0xbb, 0xac, 0x46, 0x22, 0x08, 0x22, 0x21, 0xa8, 0x76, 0x8d, 0x1d, 0x09};<br />
BITCOIN_ASSERT(signature.size() == 70);<br />
<br />
elliptic_curve_key key;<br />
if (!key.set_public_key(pubkey))<br />
{<br />
log_fatal() << "unable to set EC public key";<br />
return -1;<br />
}<br />
<br />
log_info() << "checksig returns: " << (key.verify(tx_hash, signature) ? "true" : "false");<br />
return 0;<br />
}<br />
<br />
</source><br />
<br />
==References==<br />
<references/><br />
<br />
[[Category:Technical]]<br />
[[Category:Developer]]</div>
Smtp
https://en.bitcoin.it/w/index.php?title=OP_CHECKSIG&diff=34870
OP CHECKSIG
2013-01-09T23:00:11Z
<p>Smtp: /* Final signature */</p>
<hr />
<div>OP_CHECKSIG is [[Script|script]] opcode used to verify that the signature for a tx input is valid. OP_CHECKSIG expects two values to be on the stack, these are, in order of stack depth, the public key and the signature of the script. These two values are normally obtained by running the scriptSig script of the transaction input we are attempting to validate. After the scriptSig script is run the script is deleted but the stack is left as is, and then then scriptPubKey script from the previous transaction output that is now being spent is run, generally concluding in an OP_CHECKSIG. <br />
<br />
The standard scriptPubKey checks that the public key (actually a hash of) is a particular value, and that OP_CHECKSIG passes.<br />
<br />
For normal transaction inputs if the creator of the current transaction can successfully create a ScriptSig signature that uses the right public key for the ScriptPubKey of the transaction output they are attempting to spend, that transaction input is considered valid. <br />
<br />
== Parameters ==<br />
<br />
In addition to the script code itself and the stack parameters, to operate OP_CHECKSIG needs to know the current transaction and the index of current transaction input.<br />
<br />
== How it works ==<br />
Firstly always this (the default) procedure is applied:<br />
[[File:Bitcoin_OpCheckSig_InDetail.png|thumb|right|Signature verification process of the default procedure]]<br />
# the public key and the signature are popped from the stack, in that order. If the hash-type value is 0, then it is replaced by the last_byte of the signature. Then the last byte of the signature is always deleted.<br />
# A new subscript is created from the instruction from the most recently parsed OP_CODESEPARATOR (last one in script) to the end of the script. If there is no OP_CODESEPARATOR the entire script becomes the subscript (hereby referred to as subScript)<br />
# The sig is deleted from subScript.<br />
# All OP_CODESEPARATORS are removed from subScript<br />
# The hashtype is removed from the last byte of the sig and stored<br />
# A copy is made of the current transaction (hereby referred to txCopy)<br />
# The scripts for all transaction inputs in txCopy are set to empty scripts (exactly 1 byte 0x00)<br />
# The script for the current transaction input in txCopy is set to subScript (lead in by its length as a var-integer encoded!)<br />
<br />
Now depending on the hashtype various things can happen to txCopy, these will be discussed individually.<br />
<br />
'''Hashtype Values (from script.h):'''<br />
{|class="wikitable"<br />
! Name !! Value<br />
|-<br />
| SIGHASH_ALL || 0x00000001<br />
|-<br />
| SIGHASH_NONE || 0x00000002<br />
|-<br />
| SIGHASH_SINGLE || 0x00000003<br />
|-<br />
| SIGHASH_ANYONECANPAY || 0x00000080<br />
|}<br />
<br />
<ol><br />
<li> If (hashtype&31) = SIGHASH_NONE then apply the SIGHASH_NONE-procedure<br />
<li> If (hashtype&31) = SIGHASH_SINGLE then apply the SIGHASH_SINGLE-procedure<br />
<li> If hashtype & SIGHASH_ANYONECANPAY then apply the SIGHASH_ANYONECANPAY-procedure<br />
</ol><br />
Hence, hashtype SIGHASH_ANYONECANPAY may be applied also after any other hashtype-procedure<ref>[http://sourceforge.net/projects/bitcoin/files/Bitcoin/bitcoin-0.7.1/bitcoin-0.7.1-linux.tar.gz file src/src/script.cpp in bitcoin-0.7.1]</ref>. Besides the four listed hashtypes only a hashtype of value 0 appears a few types in the (main) block chain (and is handled like SIGHASH_ALL).<br />
<br />
=== Hashtype SIGHASH_ALL (default) ===<br />
<br />
No special further handling occurs in the default case. Think of this as "sign '''all''' of the outputs." Which is already done by the default procedure.<br />
<br />
=== Procedure for Hashtype SIGHASH_NONE ===<br />
<br />
# The output of txCopy is set to a vector of zero size.<br />
# All other inputs aside from the current input in txCopy have their nSequence index set to zero<br />
<br />
Think of this as "sign '''none''' of the outputs-- I don't care where the bitcoins go."<br />
<br />
=== Procedure for Hashtype SIGHASH_SINGLE ===<br />
<br />
# The output of txCopy is resized to the size of the current input index+1<br />
# All other txCopy outputs aside from the output that is the same as the current input index are set to a blank script and a value of (long) -1;<br />
# All other txCopy inputs aside from the current input are set to have an nSequence index of zero<br />
<br />
Think of this as "sign '''one''' of the outputs-- I don't care where the other outputs go."<br />
<br />
=== Procedure for Hashtype SIGHASH_ANYONECANPAY ===<br />
<br />
# The txCopy input vector is resized to a length of one<br />
# The current input is set as the first and only member of this vector<br />
<br />
Think of this as "Let other people add inputs to this transaction, I don't care where the rest of the bitcoins come from."<br />
<br />
==Final signature check==<br />
<br />
An array of bytes is constructed from the serialized txCopy + four bytes for the hash type. This array is sha256 hashed twice, then the public key is used to to check the supplied signature against the hash.<br />
The secp256k1 elliptic curve is used for the verification with the given public key.<br />
<br />
== Return values ==<br />
<br />
OP_CHECKSIG will push true to the stack if the check passed, false otherwise.<br />
OP_CHECKSIG_VERIFY leaves nothing on the stack but will cause the script eval to fail immediately if the check does not pass.<br />
<br />
== Code samples and raw dumps ==<br />
<br />
Taking the first transaction in Bitcoin which is in block number 170, we would get after serialising the transaction but before we hash+sign (or verify) it:<br />
<br />
* http://blockexplorer.com/block/00000000d1145790a8694403d4063f323d499e655c83426834d4ce2f8dd4a2ee<br />
* http://blockexplorer.com/tx/f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16<br />
<br />
See also [https://gitorious.org/libbitcoin/libbitcoin libbitcoin] for code samples.<br />
<br />
<pre><br />
01 00 00 00 version<br />
01 number of inputs (var_uint)<br />
<br />
input 0:<br />
c9 97 a5 e5 6e 10 41 02 input address hash<br />
fa 20 9c 6a 85 2d d9 06 <br />
60 a2 0b 2d 9c 35 24 23 <br />
ed ce 25 85 7f cd 37 04<br />
00 00 00 00 input index<br />
<br />
48 size of script (var_uint)<br />
47 push 71 bytes to stack<br />
30 44 02 20 4e 45 e1 69<br />
32 b8 af 51 49 61 a1 d3<br />
a1 a2 5f df 3f 4f 77 32<br />
e9 d6 24 c6 c6 15 48 ab<br />
5f b8 cd 41 02 20 18 15<br />
22 ec 8e ca 07 de 48 60<br />
a4 ac dd 12 90 9d 83 1c<br />
c5 6c bb ac 46 22 08 22<br />
21 a8 76 8d 1d 09 01<br />
ff ff ff ff sequence<br />
<br />
02 number of outputs (var_uint)<br />
<br />
output 0:<br />
00 ca 9a 3b 00 00 00 00 amount = 10.00000000<br />
43 size of script (var_uint)<br />
script for output 0:<br />
41 push 65 bytes to stack<br />
04 ae 1a 62 fe 09 c5 f5 <br />
1b 13 90 5f 07 f0 6b 99 <br />
a2 f7 15 9b 22 25 f3 74 <br />
cd 37 8d 71 30 2f a2 84 <br />
14 e7 aa b3 73 97 f5 54 <br />
a7 df 5f 14 2c 21 c1 b7 <br />
30 3b 8a 06 26 f1 ba de <br />
d5 c7 2a 70 4f 7e 6c d8 <br />
4c <br />
ac OP_CHECKSIG<br />
<br />
output 1:<br />
00 28 6b ee 00 00 00 00 amount = 40.00000000<br />
43 size of script (var_uint)<br />
script for output 1:<br />
41 push 65 bytes to stack<br />
04 11 db 93 e1 dc db 8a <br />
01 6b 49 84 0f 8c 53 bc <br />
1e b6 8a 38 2e 97 b1 48 <br />
2e ca d7 b1 48 a6 90 9a<br />
5c b2 e0 ea dd fb 84 cc <br />
f9 74 44 64 f8 2e 16 0b <br />
fa 9b 8b 64 f9 d4 c0 3f <br />
99 9b 86 43 f6 56 b4 12 <br />
a3 <br />
ac OP_CHECKSIG<br />
<br />
00 00 00 00 locktime<br />
01 00 00 00 hash_code_type (added on)<br />
<br />
result =<br />
01 00 00 00 01 c9 97 a5 e5 6e 10 41 02 fa 20 9c 6a 85 2d d9 06 60 a2 0b 2d 9c 35 <br />
24 23 ed ce 25 85 7f cd 37 04 00 00 00 00 43 41 04 11 db 93 e1 dc db 8a 01 6b 49 <br />
84 0f 8c 53 bc 1e b6 8a 38 2e 97 b1 48 2e ca d7 b1 48 a6 90 9a 5c b2 e0 ea dd fb <br />
84 cc f9 74 44 64 f8 2e 16 0b fa 9b 8b 64 f9 d4 c0 3f 99 9b 86 43 f6 56 b4 12 a3 <br />
ac ff ff ff ff 02 00 ca 9a 3b 00 00 00 00 43 41 04 ae 1a 62 fe 09 c5 f5 1b 13 90 <br />
5f 07 f0 6b 99 a2 f7 15 9b 22 25 f3 74 cd 37 8d 71 30 2f a2 84 14 e7 aa b3 73 97 <br />
f5 54 a7 df 5f 14 2c 21 c1 b7 30 3b 8a 06 26 f1 ba de d5 c7 2a 70 4f 7e 6c d8 4c <br />
ac 00 28 6b ee 00 00 00 00 43 41 04 11 db 93 e1 dc db 8a 01 6b 49 84 0f 8c 53 bc <br />
1e b6 8a 38 2e 97 b1 48 2e ca d7 b1 48 a6 90 9a 5c b2 e0 ea dd fb 84 cc f9 74 44 <br />
64 f8 2e 16 0b fa 9b 8b 64 f9 d4 c0 3f 99 9b 86 43 f6 56 b4 12 a3 ac 00 00 00 00 <br />
01 00 00 00 <br />
</pre><br />
<br />
To understand where that raw dump has come from, it may be useful to examine tests/ec-key.cpp in [https://gitorious.org/libbitcoin/libbitcoin libbitcoin],<br />
<br />
[https://gitorious.org/libbitcoin/libbitcoin libbitcoin] has a unit test under tests/ec-key.cpp (make ec-key && ./bin/tests/ec-key). There is also a working OP_CHECKSIG implementation in src/script.cpp under script::op_checksig(). See also the unit test: tests/script-test.cpp<br />
<br />
<source lang="cpp"><br />
#include <iostream><br />
#include <iomanip><br />
#include <bitcoin/util/serializer.hpp><br />
#include <bitcoin/util/elliptic_curve_key.hpp><br />
#include <bitcoin/util/sha256.hpp><br />
#include <bitcoin/util/assert.hpp><br />
#include <bitcoin/util/logger.hpp><br />
#include <bitcoin/types.hpp><br />
#include <openssl/ecdsa.h><br />
#include <openssl/obj_mac.h><br />
using libbitcoin::elliptic_curve_key;<br />
using libbitcoin::serializer;<br />
using libbitcoin::hash_digest;<br />
using libbitcoin::data_chunk;<br />
using libbitcoin::log_info;<br />
using libbitcoin::log_fatal;<br />
<br />
int main()<br />
{<br />
serializer ss;<br />
// blk number 170, tx 1, input 0<br />
// version = 1<br />
ss.write_4_bytes(1);<br />
// 1 inputs<br />
ss.write_var_uint(1);<br />
<br />
// input 0<br />
// prevout hash<br />
ss.write_hash(hash_digest{0x04, 0x37, 0xcd, 0x7f, 0x85, 0x25, 0xce, 0xed, 0x23, 0x24, 0x35, 0x9c, 0x2d, 0x0b, 0xa2, 0x60, 0x06, 0xd9, 0x2d, 0x85, 0x6a, 0x9c, 0x20, 0xfa, 0x02, 0x41, 0x10, 0x6e, 0xe5, 0xa5, 0x97, 0xc9});<br />
// prevout index <br />
ss.write_4_bytes(0);<br />
<br />
// input script after running OP_CHECKSIG for this tx is a single<br />
// OP_CHECKSIG opcode<br />
data_chunk raw_data;<br />
raw_data = {0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3};<br />
data_chunk raw_script;<br />
raw_script = data_chunk();<br />
raw_script.push_back(raw_data.size());<br />
libbitcoin::extend_data(raw_script, raw_data);<br />
raw_script.push_back(172);<br />
ss.write_var_uint(raw_script.size());<br />
ss.write_data(raw_script);<br />
// sequence<br />
ss.write_4_bytes(0xffffffff);<br />
<br />
// 2 outputs for this tx<br />
ss.write_var_uint(2);<br />
<br />
// output 0<br />
ss.write_8_bytes(1000000000);<br />
// script for output 0<br />
raw_data = {0x04, 0xae, 0x1a, 0x62, 0xfe, 0x09, 0xc5, 0xf5, 0x1b, 0x13, 0x90, 0x5f, 0x07, 0xf0, 0x6b, 0x99, 0xa2, 0xf7, 0x15, 0x9b, 0x22, 0x25, 0xf3, 0x74, 0xcd, 0x37, 0x8d, 0x71, 0x30, 0x2f, 0xa2, 0x84, 0x14, 0xe7, 0xaa, 0xb3, 0x73, 0x97, 0xf5, 0x54, 0xa7, 0xdf, 0x5f, 0x14, 0x2c, 0x21, 0xc1, 0xb7, 0x30, 0x3b, 0x8a, 0x06, 0x26, 0xf1, 0xba, 0xde, 0xd5, 0xc7, 0x2a, 0x70, 0x4f, 0x7e, 0x6c, 0xd8, 0x4c};<br />
// when data < 75, we can just write it's length as a single byte ('special'<br />
// opcodes)<br />
raw_script = data_chunk();<br />
raw_script.push_back(raw_data.size());<br />
libbitcoin::extend_data(raw_script, raw_data);<br />
// OP_CHECKSIG<br />
raw_script.push_back(172);<br />
// now actually write the script<br />
ss.write_var_uint(raw_script.size());<br />
ss.write_data(raw_script);<br />
<br />
// output 0<br />
ss.write_8_bytes(4000000000);<br />
// script for output 0<br />
raw_data = {0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3};<br />
// when data < 75, we can just write it's length as a single byte ('special'<br />
raw_script.push_back(raw_data.size());<br />
libbitcoin::extend_data(raw_script, raw_data);<br />
// OP_CHECKSIG<br />
raw_script.push_back(172);<br />
// now actually write the script<br />
ss.write_var_uint(raw_script.size());<br />
ss.write_data(raw_script);<br />
<br />
// End of 2 outputs<br />
<br />
// locktime<br />
ss.write_4_bytes(0);<br />
<br />
// write hash_type_code<br />
ss.write_4_bytes(1);<br />
<br />
// Dump hex to screen<br />
log_info() << "hashing:";<br />
{<br />
auto log_obj = log_info();<br />
log_obj << std::hex;<br />
for (int val: ss.get_data())<br />
log_obj << std::setfill('0') << std::setw(2) << val << ' ';<br />
}<br />
log_info();<br />
<br />
data_chunk raw_tx = {0x01, 0x00, 0x00, 0x00, 0x01, 0xc9, 0x97, 0xa5, 0xe5, 0x6e, 0x10, 0x41, 0x02, 0xfa, 0x20, 0x9c, 0x6a, 0x85, 0x2d, 0xd9, 0x06, 0x60, 0xa2, 0x0b, 0x2d, 0x9c, 0x35, 0x24, 0x23, 0xed, 0xce, 0x25, 0x85, 0x7f, 0xcd, 0x37, 0x04, 0x00, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3, 0xac, 0xff, 0xff, 0xff, 0xff, 0x02, 0x00, 0xca, 0x9a, 0x3b, 0x00, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, 0xae, 0x1a, 0x62, 0xfe, 0x09, 0xc5, 0xf5, 0x1b, 0x13, 0x90, 0x5f, 0x07, 0xf0, 0x6b, 0x99, 0xa2, 0xf7, 0x15, 0x9b, 0x22, 0x25, 0xf3, 0x74, 0xcd, 0x37, 0x8d, 0x71, 0x30, 0x2f, 0xa2, 0x84, 0x14, 0xe7, 0xaa, 0xb3, 0x73, 0x97, 0xf5, 0x54, 0xa7, 0xdf, 0x5f, 0x14, 0x2c, 0x21, 0xc1, 0xb7, 0x30, 0x3b, 0x8a, 0x06, 0x26, 0xf1, 0xba, 0xde, 0xd5, 0xc7, 0x2a, 0x70, 0x4f, 0x7e, 0x6c, 0xd8, 0x4c, 0xac, 0x00, 0x28, 0x6b, 0xee, 0x00, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3, 0xac, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00};<br />
BITCOIN_ASSERT(raw_tx == ss.get_data());<br />
<br />
hash_digest tx_hash = libbitcoin::generate_sha256_hash(ss.get_data());<br />
<br />
data_chunk pubkey{0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3};<br />
// Leave out last byte since that's the hash_type_code (SIGHASH_ALL in this<br />
// case)<br />
data_chunk signature{0x30, 0x44, 0x02, 0x20, 0x4e, 0x45, 0xe1, 0x69, 0x32, 0xb8, 0xaf, 0x51, 0x49, 0x61, 0xa1, 0xd3, 0xa1, 0xa2, 0x5f, 0xdf, 0x3f, 0x4f, 0x77, 0x32, 0xe9, 0xd6, 0x24, 0xc6, 0xc6, 0x15, 0x48, 0xab, 0x5f, 0xb8, 0xcd, 0x41, 0x02, 0x20, 0x18, 0x15, 0x22, 0xec, 0x8e, 0xca, 0x07, 0xde, 0x48, 0x60, 0xa4, 0xac, 0xdd, 0x12, 0x90, 0x9d, 0x83, 0x1c, 0xc5, 0x6c, 0xbb, 0xac, 0x46, 0x22, 0x08, 0x22, 0x21, 0xa8, 0x76, 0x8d, 0x1d, 0x09};<br />
BITCOIN_ASSERT(signature.size() == 70);<br />
<br />
elliptic_curve_key key;<br />
if (!key.set_public_key(pubkey))<br />
{<br />
log_fatal() << "unable to set EC public key";<br />
return -1;<br />
}<br />
<br />
log_info() << "checksig returns: " << (key.verify(tx_hash, signature) ? "true" : "false");<br />
return 0;<br />
}<br />
<br />
</source><br />
<br />
==References==<br />
<references/><br />
<br />
[[Category:Technical]]<br />
[[Category:Developer]]</div>
Smtp
https://en.bitcoin.it/w/index.php?title=OP_CHECKSIG&diff=34869
OP CHECKSIG
2013-01-09T22:59:40Z
<p>Smtp: /* Final signature */</p>
<hr />
<div>OP_CHECKSIG is [[Script|script]] opcode used to verify that the signature for a tx input is valid. OP_CHECKSIG expects two values to be on the stack, these are, in order of stack depth, the public key and the signature of the script. These two values are normally obtained by running the scriptSig script of the transaction input we are attempting to validate. After the scriptSig script is run the script is deleted but the stack is left as is, and then then scriptPubKey script from the previous transaction output that is now being spent is run, generally concluding in an OP_CHECKSIG. <br />
<br />
The standard scriptPubKey checks that the public key (actually a hash of) is a particular value, and that OP_CHECKSIG passes.<br />
<br />
For normal transaction inputs if the creator of the current transaction can successfully create a ScriptSig signature that uses the right public key for the ScriptPubKey of the transaction output they are attempting to spend, that transaction input is considered valid. <br />
<br />
== Parameters ==<br />
<br />
In addition to the script code itself and the stack parameters, to operate OP_CHECKSIG needs to know the current transaction and the index of current transaction input.<br />
<br />
== How it works ==<br />
Firstly always this (the default) procedure is applied:<br />
[[File:Bitcoin_OpCheckSig_InDetail.png|thumb|right|Signature verification process of the default procedure]]<br />
# the public key and the signature are popped from the stack, in that order. If the hash-type value is 0, then it is replaced by the last_byte of the signature. Then the last byte of the signature is always deleted.<br />
# A new subscript is created from the instruction from the most recently parsed OP_CODESEPARATOR (last one in script) to the end of the script. If there is no OP_CODESEPARATOR the entire script becomes the subscript (hereby referred to as subScript)<br />
# The sig is deleted from subScript.<br />
# All OP_CODESEPARATORS are removed from subScript<br />
# The hashtype is removed from the last byte of the sig and stored<br />
# A copy is made of the current transaction (hereby referred to txCopy)<br />
# The scripts for all transaction inputs in txCopy are set to empty scripts (exactly 1 byte 0x00)<br />
# The script for the current transaction input in txCopy is set to subScript (lead in by its length as a var-integer encoded!)<br />
<br />
Now depending on the hashtype various things can happen to txCopy, these will be discussed individually.<br />
<br />
'''Hashtype Values (from script.h):'''<br />
{|class="wikitable"<br />
! Name !! Value<br />
|-<br />
| SIGHASH_ALL || 0x00000001<br />
|-<br />
| SIGHASH_NONE || 0x00000002<br />
|-<br />
| SIGHASH_SINGLE || 0x00000003<br />
|-<br />
| SIGHASH_ANYONECANPAY || 0x00000080<br />
|}<br />
<br />
<ol><br />
<li> If (hashtype&31) = SIGHASH_NONE then apply the SIGHASH_NONE-procedure<br />
<li> If (hashtype&31) = SIGHASH_SINGLE then apply the SIGHASH_SINGLE-procedure<br />
<li> If hashtype & SIGHASH_ANYONECANPAY then apply the SIGHASH_ANYONECANPAY-procedure<br />
</ol><br />
Hence, hashtype SIGHASH_ANYONECANPAY may be applied also after any other hashtype-procedure<ref>[http://sourceforge.net/projects/bitcoin/files/Bitcoin/bitcoin-0.7.1/bitcoin-0.7.1-linux.tar.gz file src/src/script.cpp in bitcoin-0.7.1]</ref>. Besides the four listed hashtypes only a hashtype of value 0 appears a few types in the (main) block chain (and is handled like SIGHASH_ALL).<br />
<br />
=== Hashtype SIGHASH_ALL (default) ===<br />
<br />
No special further handling occurs in the default case. Think of this as "sign '''all''' of the outputs." Which is already done by the default procedure.<br />
<br />
=== Procedure for Hashtype SIGHASH_NONE ===<br />
<br />
# The output of txCopy is set to a vector of zero size.<br />
# All other inputs aside from the current input in txCopy have their nSequence index set to zero<br />
<br />
Think of this as "sign '''none''' of the outputs-- I don't care where the bitcoins go."<br />
<br />
=== Procedure for Hashtype SIGHASH_SINGLE ===<br />
<br />
# The output of txCopy is resized to the size of the current input index+1<br />
# All other txCopy outputs aside from the output that is the same as the current input index are set to a blank script and a value of (long) -1;<br />
# All other txCopy inputs aside from the current input are set to have an nSequence index of zero<br />
<br />
Think of this as "sign '''one''' of the outputs-- I don't care where the other outputs go."<br />
<br />
=== Procedure for Hashtype SIGHASH_ANYONECANPAY ===<br />
<br />
# The txCopy input vector is resized to a length of one<br />
# The current input is set as the first and only member of this vector<br />
<br />
Think of this as "Let other people add inputs to this transaction, I don't care where the rest of the bitcoins come from."<br />
<br />
== Final signature ==<br />
<br />
An array of bytes is constructed from the serialized txCopy + four bytes for the hash type. This array is sha256 hashed twice, then the public key is used to to check the supplied signature against the hash.<br />
The secp256k1 elliptic curve is used for the verification with the given public key.<br />
<br />
== Return values ==<br />
<br />
OP_CHECKSIG will push true to the stack if the check passed, false otherwise.<br />
OP_CHECKSIG_VERIFY leaves nothing on the stack but will cause the script eval to fail immediately if the check does not pass.<br />
<br />
== Code samples and raw dumps ==<br />
<br />
Taking the first transaction in Bitcoin which is in block number 170, we would get after serialising the transaction but before we hash+sign (or verify) it:<br />
<br />
* http://blockexplorer.com/block/00000000d1145790a8694403d4063f323d499e655c83426834d4ce2f8dd4a2ee<br />
* http://blockexplorer.com/tx/f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16<br />
<br />
See also [https://gitorious.org/libbitcoin/libbitcoin libbitcoin] for code samples.<br />
<br />
<pre><br />
01 00 00 00 version<br />
01 number of inputs (var_uint)<br />
<br />
input 0:<br />
c9 97 a5 e5 6e 10 41 02 input address hash<br />
fa 20 9c 6a 85 2d d9 06 <br />
60 a2 0b 2d 9c 35 24 23 <br />
ed ce 25 85 7f cd 37 04<br />
00 00 00 00 input index<br />
<br />
48 size of script (var_uint)<br />
47 push 71 bytes to stack<br />
30 44 02 20 4e 45 e1 69<br />
32 b8 af 51 49 61 a1 d3<br />
a1 a2 5f df 3f 4f 77 32<br />
e9 d6 24 c6 c6 15 48 ab<br />
5f b8 cd 41 02 20 18 15<br />
22 ec 8e ca 07 de 48 60<br />
a4 ac dd 12 90 9d 83 1c<br />
c5 6c bb ac 46 22 08 22<br />
21 a8 76 8d 1d 09 01<br />
ff ff ff ff sequence<br />
<br />
02 number of outputs (var_uint)<br />
<br />
output 0:<br />
00 ca 9a 3b 00 00 00 00 amount = 10.00000000<br />
43 size of script (var_uint)<br />
script for output 0:<br />
41 push 65 bytes to stack<br />
04 ae 1a 62 fe 09 c5 f5 <br />
1b 13 90 5f 07 f0 6b 99 <br />
a2 f7 15 9b 22 25 f3 74 <br />
cd 37 8d 71 30 2f a2 84 <br />
14 e7 aa b3 73 97 f5 54 <br />
a7 df 5f 14 2c 21 c1 b7 <br />
30 3b 8a 06 26 f1 ba de <br />
d5 c7 2a 70 4f 7e 6c d8 <br />
4c <br />
ac OP_CHECKSIG<br />
<br />
output 1:<br />
00 28 6b ee 00 00 00 00 amount = 40.00000000<br />
43 size of script (var_uint)<br />
script for output 1:<br />
41 push 65 bytes to stack<br />
04 11 db 93 e1 dc db 8a <br />
01 6b 49 84 0f 8c 53 bc <br />
1e b6 8a 38 2e 97 b1 48 <br />
2e ca d7 b1 48 a6 90 9a<br />
5c b2 e0 ea dd fb 84 cc <br />
f9 74 44 64 f8 2e 16 0b <br />
fa 9b 8b 64 f9 d4 c0 3f <br />
99 9b 86 43 f6 56 b4 12 <br />
a3 <br />
ac OP_CHECKSIG<br />
<br />
00 00 00 00 locktime<br />
01 00 00 00 hash_code_type (added on)<br />
<br />
result =<br />
01 00 00 00 01 c9 97 a5 e5 6e 10 41 02 fa 20 9c 6a 85 2d d9 06 60 a2 0b 2d 9c 35 <br />
24 23 ed ce 25 85 7f cd 37 04 00 00 00 00 43 41 04 11 db 93 e1 dc db 8a 01 6b 49 <br />
84 0f 8c 53 bc 1e b6 8a 38 2e 97 b1 48 2e ca d7 b1 48 a6 90 9a 5c b2 e0 ea dd fb <br />
84 cc f9 74 44 64 f8 2e 16 0b fa 9b 8b 64 f9 d4 c0 3f 99 9b 86 43 f6 56 b4 12 a3 <br />
ac ff ff ff ff 02 00 ca 9a 3b 00 00 00 00 43 41 04 ae 1a 62 fe 09 c5 f5 1b 13 90 <br />
5f 07 f0 6b 99 a2 f7 15 9b 22 25 f3 74 cd 37 8d 71 30 2f a2 84 14 e7 aa b3 73 97 <br />
f5 54 a7 df 5f 14 2c 21 c1 b7 30 3b 8a 06 26 f1 ba de d5 c7 2a 70 4f 7e 6c d8 4c <br />
ac 00 28 6b ee 00 00 00 00 43 41 04 11 db 93 e1 dc db 8a 01 6b 49 84 0f 8c 53 bc <br />
1e b6 8a 38 2e 97 b1 48 2e ca d7 b1 48 a6 90 9a 5c b2 e0 ea dd fb 84 cc f9 74 44 <br />
64 f8 2e 16 0b fa 9b 8b 64 f9 d4 c0 3f 99 9b 86 43 f6 56 b4 12 a3 ac 00 00 00 00 <br />
01 00 00 00 <br />
</pre><br />
<br />
To understand where that raw dump has come from, it may be useful to examine tests/ec-key.cpp in [https://gitorious.org/libbitcoin/libbitcoin libbitcoin],<br />
<br />
[https://gitorious.org/libbitcoin/libbitcoin libbitcoin] has a unit test under tests/ec-key.cpp (make ec-key && ./bin/tests/ec-key). There is also a working OP_CHECKSIG implementation in src/script.cpp under script::op_checksig(). See also the unit test: tests/script-test.cpp<br />
<br />
<source lang="cpp"><br />
#include <iostream><br />
#include <iomanip><br />
#include <bitcoin/util/serializer.hpp><br />
#include <bitcoin/util/elliptic_curve_key.hpp><br />
#include <bitcoin/util/sha256.hpp><br />
#include <bitcoin/util/assert.hpp><br />
#include <bitcoin/util/logger.hpp><br />
#include <bitcoin/types.hpp><br />
#include <openssl/ecdsa.h><br />
#include <openssl/obj_mac.h><br />
using libbitcoin::elliptic_curve_key;<br />
using libbitcoin::serializer;<br />
using libbitcoin::hash_digest;<br />
using libbitcoin::data_chunk;<br />
using libbitcoin::log_info;<br />
using libbitcoin::log_fatal;<br />
<br />
int main()<br />
{<br />
serializer ss;<br />
// blk number 170, tx 1, input 0<br />
// version = 1<br />
ss.write_4_bytes(1);<br />
// 1 inputs<br />
ss.write_var_uint(1);<br />
<br />
// input 0<br />
// prevout hash<br />
ss.write_hash(hash_digest{0x04, 0x37, 0xcd, 0x7f, 0x85, 0x25, 0xce, 0xed, 0x23, 0x24, 0x35, 0x9c, 0x2d, 0x0b, 0xa2, 0x60, 0x06, 0xd9, 0x2d, 0x85, 0x6a, 0x9c, 0x20, 0xfa, 0x02, 0x41, 0x10, 0x6e, 0xe5, 0xa5, 0x97, 0xc9});<br />
// prevout index <br />
ss.write_4_bytes(0);<br />
<br />
// input script after running OP_CHECKSIG for this tx is a single<br />
// OP_CHECKSIG opcode<br />
data_chunk raw_data;<br />
raw_data = {0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3};<br />
data_chunk raw_script;<br />
raw_script = data_chunk();<br />
raw_script.push_back(raw_data.size());<br />
libbitcoin::extend_data(raw_script, raw_data);<br />
raw_script.push_back(172);<br />
ss.write_var_uint(raw_script.size());<br />
ss.write_data(raw_script);<br />
// sequence<br />
ss.write_4_bytes(0xffffffff);<br />
<br />
// 2 outputs for this tx<br />
ss.write_var_uint(2);<br />
<br />
// output 0<br />
ss.write_8_bytes(1000000000);<br />
// script for output 0<br />
raw_data = {0x04, 0xae, 0x1a, 0x62, 0xfe, 0x09, 0xc5, 0xf5, 0x1b, 0x13, 0x90, 0x5f, 0x07, 0xf0, 0x6b, 0x99, 0xa2, 0xf7, 0x15, 0x9b, 0x22, 0x25, 0xf3, 0x74, 0xcd, 0x37, 0x8d, 0x71, 0x30, 0x2f, 0xa2, 0x84, 0x14, 0xe7, 0xaa, 0xb3, 0x73, 0x97, 0xf5, 0x54, 0xa7, 0xdf, 0x5f, 0x14, 0x2c, 0x21, 0xc1, 0xb7, 0x30, 0x3b, 0x8a, 0x06, 0x26, 0xf1, 0xba, 0xde, 0xd5, 0xc7, 0x2a, 0x70, 0x4f, 0x7e, 0x6c, 0xd8, 0x4c};<br />
// when data < 75, we can just write it's length as a single byte ('special'<br />
// opcodes)<br />
raw_script = data_chunk();<br />
raw_script.push_back(raw_data.size());<br />
libbitcoin::extend_data(raw_script, raw_data);<br />
// OP_CHECKSIG<br />
raw_script.push_back(172);<br />
// now actually write the script<br />
ss.write_var_uint(raw_script.size());<br />
ss.write_data(raw_script);<br />
<br />
// output 0<br />
ss.write_8_bytes(4000000000);<br />
// script for output 0<br />
raw_data = {0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3};<br />
// when data < 75, we can just write it's length as a single byte ('special'<br />
raw_script.push_back(raw_data.size());<br />
libbitcoin::extend_data(raw_script, raw_data);<br />
// OP_CHECKSIG<br />
raw_script.push_back(172);<br />
// now actually write the script<br />
ss.write_var_uint(raw_script.size());<br />
ss.write_data(raw_script);<br />
<br />
// End of 2 outputs<br />
<br />
// locktime<br />
ss.write_4_bytes(0);<br />
<br />
// write hash_type_code<br />
ss.write_4_bytes(1);<br />
<br />
// Dump hex to screen<br />
log_info() << "hashing:";<br />
{<br />
auto log_obj = log_info();<br />
log_obj << std::hex;<br />
for (int val: ss.get_data())<br />
log_obj << std::setfill('0') << std::setw(2) << val << ' ';<br />
}<br />
log_info();<br />
<br />
data_chunk raw_tx = {0x01, 0x00, 0x00, 0x00, 0x01, 0xc9, 0x97, 0xa5, 0xe5, 0x6e, 0x10, 0x41, 0x02, 0xfa, 0x20, 0x9c, 0x6a, 0x85, 0x2d, 0xd9, 0x06, 0x60, 0xa2, 0x0b, 0x2d, 0x9c, 0x35, 0x24, 0x23, 0xed, 0xce, 0x25, 0x85, 0x7f, 0xcd, 0x37, 0x04, 0x00, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3, 0xac, 0xff, 0xff, 0xff, 0xff, 0x02, 0x00, 0xca, 0x9a, 0x3b, 0x00, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, 0xae, 0x1a, 0x62, 0xfe, 0x09, 0xc5, 0xf5, 0x1b, 0x13, 0x90, 0x5f, 0x07, 0xf0, 0x6b, 0x99, 0xa2, 0xf7, 0x15, 0x9b, 0x22, 0x25, 0xf3, 0x74, 0xcd, 0x37, 0x8d, 0x71, 0x30, 0x2f, 0xa2, 0x84, 0x14, 0xe7, 0xaa, 0xb3, 0x73, 0x97, 0xf5, 0x54, 0xa7, 0xdf, 0x5f, 0x14, 0x2c, 0x21, 0xc1, 0xb7, 0x30, 0x3b, 0x8a, 0x06, 0x26, 0xf1, 0xba, 0xde, 0xd5, 0xc7, 0x2a, 0x70, 0x4f, 0x7e, 0x6c, 0xd8, 0x4c, 0xac, 0x00, 0x28, 0x6b, 0xee, 0x00, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3, 0xac, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00};<br />
BITCOIN_ASSERT(raw_tx == ss.get_data());<br />
<br />
hash_digest tx_hash = libbitcoin::generate_sha256_hash(ss.get_data());<br />
<br />
data_chunk pubkey{0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3};<br />
// Leave out last byte since that's the hash_type_code (SIGHASH_ALL in this<br />
// case)<br />
data_chunk signature{0x30, 0x44, 0x02, 0x20, 0x4e, 0x45, 0xe1, 0x69, 0x32, 0xb8, 0xaf, 0x51, 0x49, 0x61, 0xa1, 0xd3, 0xa1, 0xa2, 0x5f, 0xdf, 0x3f, 0x4f, 0x77, 0x32, 0xe9, 0xd6, 0x24, 0xc6, 0xc6, 0x15, 0x48, 0xab, 0x5f, 0xb8, 0xcd, 0x41, 0x02, 0x20, 0x18, 0x15, 0x22, 0xec, 0x8e, 0xca, 0x07, 0xde, 0x48, 0x60, 0xa4, 0xac, 0xdd, 0x12, 0x90, 0x9d, 0x83, 0x1c, 0xc5, 0x6c, 0xbb, 0xac, 0x46, 0x22, 0x08, 0x22, 0x21, 0xa8, 0x76, 0x8d, 0x1d, 0x09};<br />
BITCOIN_ASSERT(signature.size() == 70);<br />
<br />
elliptic_curve_key key;<br />
if (!key.set_public_key(pubkey))<br />
{<br />
log_fatal() << "unable to set EC public key";<br />
return -1;<br />
}<br />
<br />
log_info() << "checksig returns: " << (key.verify(tx_hash, signature) ? "true" : "false");<br />
return 0;<br />
}<br />
<br />
</source><br />
<br />
==References==<br />
<references/><br />
<br />
[[Category:Technical]]<br />
[[Category:Developer]]</div>
Smtp
https://en.bitcoin.it/w/index.php?title=OP_CHECKSIG&diff=34868
OP CHECKSIG
2013-01-09T22:53:59Z
<p>Smtp: /* How it works */</p>
<hr />
<div>OP_CHECKSIG is [[Script|script]] opcode used to verify that the signature for a tx input is valid. OP_CHECKSIG expects two values to be on the stack, these are, in order of stack depth, the public key and the signature of the script. These two values are normally obtained by running the scriptSig script of the transaction input we are attempting to validate. After the scriptSig script is run the script is deleted but the stack is left as is, and then then scriptPubKey script from the previous transaction output that is now being spent is run, generally concluding in an OP_CHECKSIG. <br />
<br />
The standard scriptPubKey checks that the public key (actually a hash of) is a particular value, and that OP_CHECKSIG passes.<br />
<br />
For normal transaction inputs if the creator of the current transaction can successfully create a ScriptSig signature that uses the right public key for the ScriptPubKey of the transaction output they are attempting to spend, that transaction input is considered valid. <br />
<br />
== Parameters ==<br />
<br />
In addition to the script code itself and the stack parameters, to operate OP_CHECKSIG needs to know the current transaction and the index of current transaction input.<br />
<br />
== How it works ==<br />
Firstly always this (the default) procedure is applied:<br />
[[File:Bitcoin_OpCheckSig_InDetail.png|thumb|right|Signature verification process of the default procedure]]<br />
# the public key and the signature are popped from the stack, in that order. If the hash-type value is 0, then it is replaced by the last_byte of the signature. Then the last byte of the signature is always deleted.<br />
# A new subscript is created from the instruction from the most recently parsed OP_CODESEPARATOR (last one in script) to the end of the script. If there is no OP_CODESEPARATOR the entire script becomes the subscript (hereby referred to as subScript)<br />
# The sig is deleted from subScript.<br />
# All OP_CODESEPARATORS are removed from subScript<br />
# The hashtype is removed from the last byte of the sig and stored<br />
# A copy is made of the current transaction (hereby referred to txCopy)<br />
# The scripts for all transaction inputs in txCopy are set to empty scripts (exactly 1 byte 0x00)<br />
# The script for the current transaction input in txCopy is set to subScript (lead in by its length as a var-integer encoded!)<br />
<br />
Now depending on the hashtype various things can happen to txCopy, these will be discussed individually.<br />
<br />
'''Hashtype Values (from script.h):'''<br />
{|class="wikitable"<br />
! Name !! Value<br />
|-<br />
| SIGHASH_ALL || 0x00000001<br />
|-<br />
| SIGHASH_NONE || 0x00000002<br />
|-<br />
| SIGHASH_SINGLE || 0x00000003<br />
|-<br />
| SIGHASH_ANYONECANPAY || 0x00000080<br />
|}<br />
<br />
<ol><br />
<li> If (hashtype&31) = SIGHASH_NONE then apply the SIGHASH_NONE-procedure<br />
<li> If (hashtype&31) = SIGHASH_SINGLE then apply the SIGHASH_SINGLE-procedure<br />
<li> If hashtype & SIGHASH_ANYONECANPAY then apply the SIGHASH_ANYONECANPAY-procedure<br />
</ol><br />
Hence, hashtype SIGHASH_ANYONECANPAY may be applied also after any other hashtype-procedure<ref>[http://sourceforge.net/projects/bitcoin/files/Bitcoin/bitcoin-0.7.1/bitcoin-0.7.1-linux.tar.gz file src/src/script.cpp in bitcoin-0.7.1]</ref>. Besides the four listed hashtypes only a hashtype of value 0 appears a few types in the (main) block chain (and is handled like SIGHASH_ALL).<br />
<br />
=== Hashtype SIGHASH_ALL (default) ===<br />
<br />
No special further handling occurs in the default case. Think of this as "sign '''all''' of the outputs." Which is already done by the default procedure.<br />
<br />
=== Procedure for Hashtype SIGHASH_NONE ===<br />
<br />
# The output of txCopy is set to a vector of zero size.<br />
# All other inputs aside from the current input in txCopy have their nSequence index set to zero<br />
<br />
Think of this as "sign '''none''' of the outputs-- I don't care where the bitcoins go."<br />
<br />
=== Procedure for Hashtype SIGHASH_SINGLE ===<br />
<br />
# The output of txCopy is resized to the size of the current input index+1<br />
# All other txCopy outputs aside from the output that is the same as the current input index are set to a blank script and a value of (long) -1;<br />
# All other txCopy inputs aside from the current input are set to have an nSequence index of zero<br />
<br />
Think of this as "sign '''one''' of the outputs-- I don't care where the other outputs go."<br />
<br />
=== Procedure for Hashtype SIGHASH_ANYONECANPAY ===<br />
<br />
# The txCopy input vector is resized to a length of one<br />
# The current input is set as the first and only member of this vector<br />
<br />
Think of this as "Let other people add inputs to this transaction, I don't care where the rest of the bitcoins come from."<br />
<br />
== Final signature ==<br />
<br />
An array of bytes is constructed from the serialized txCopy + four bytes for the hash type. This array is sha256 hashed twice, then the public key is used to to check the supplied signature against the hash. <br />
<br />
== Return values ==<br />
<br />
OP_CHECKSIG will push true to the stack if the check passed, false otherwise.<br />
OP_CHECKSIG_VERIFY leaves nothing on the stack but will cause the script eval to fail immediately if the check does not pass.<br />
<br />
== Code samples and raw dumps ==<br />
<br />
Taking the first transaction in Bitcoin which is in block number 170, we would get after serialising the transaction but before we hash+sign (or verify) it:<br />
<br />
* http://blockexplorer.com/block/00000000d1145790a8694403d4063f323d499e655c83426834d4ce2f8dd4a2ee<br />
* http://blockexplorer.com/tx/f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16<br />
<br />
See also [https://gitorious.org/libbitcoin/libbitcoin libbitcoin] for code samples.<br />
<br />
<pre><br />
01 00 00 00 version<br />
01 number of inputs (var_uint)<br />
<br />
input 0:<br />
c9 97 a5 e5 6e 10 41 02 input address hash<br />
fa 20 9c 6a 85 2d d9 06 <br />
60 a2 0b 2d 9c 35 24 23 <br />
ed ce 25 85 7f cd 37 04<br />
00 00 00 00 input index<br />
<br />
48 size of script (var_uint)<br />
47 push 71 bytes to stack<br />
30 44 02 20 4e 45 e1 69<br />
32 b8 af 51 49 61 a1 d3<br />
a1 a2 5f df 3f 4f 77 32<br />
e9 d6 24 c6 c6 15 48 ab<br />
5f b8 cd 41 02 20 18 15<br />
22 ec 8e ca 07 de 48 60<br />
a4 ac dd 12 90 9d 83 1c<br />
c5 6c bb ac 46 22 08 22<br />
21 a8 76 8d 1d 09 01<br />
ff ff ff ff sequence<br />
<br />
02 number of outputs (var_uint)<br />
<br />
output 0:<br />
00 ca 9a 3b 00 00 00 00 amount = 10.00000000<br />
43 size of script (var_uint)<br />
script for output 0:<br />
41 push 65 bytes to stack<br />
04 ae 1a 62 fe 09 c5 f5 <br />
1b 13 90 5f 07 f0 6b 99 <br />
a2 f7 15 9b 22 25 f3 74 <br />
cd 37 8d 71 30 2f a2 84 <br />
14 e7 aa b3 73 97 f5 54 <br />
a7 df 5f 14 2c 21 c1 b7 <br />
30 3b 8a 06 26 f1 ba de <br />
d5 c7 2a 70 4f 7e 6c d8 <br />
4c <br />
ac OP_CHECKSIG<br />
<br />
output 1:<br />
00 28 6b ee 00 00 00 00 amount = 40.00000000<br />
43 size of script (var_uint)<br />
script for output 1:<br />
41 push 65 bytes to stack<br />
04 11 db 93 e1 dc db 8a <br />
01 6b 49 84 0f 8c 53 bc <br />
1e b6 8a 38 2e 97 b1 48 <br />
2e ca d7 b1 48 a6 90 9a<br />
5c b2 e0 ea dd fb 84 cc <br />
f9 74 44 64 f8 2e 16 0b <br />
fa 9b 8b 64 f9 d4 c0 3f <br />
99 9b 86 43 f6 56 b4 12 <br />
a3 <br />
ac OP_CHECKSIG<br />
<br />
00 00 00 00 locktime<br />
01 00 00 00 hash_code_type (added on)<br />
<br />
result =<br />
01 00 00 00 01 c9 97 a5 e5 6e 10 41 02 fa 20 9c 6a 85 2d d9 06 60 a2 0b 2d 9c 35 <br />
24 23 ed ce 25 85 7f cd 37 04 00 00 00 00 43 41 04 11 db 93 e1 dc db 8a 01 6b 49 <br />
84 0f 8c 53 bc 1e b6 8a 38 2e 97 b1 48 2e ca d7 b1 48 a6 90 9a 5c b2 e0 ea dd fb <br />
84 cc f9 74 44 64 f8 2e 16 0b fa 9b 8b 64 f9 d4 c0 3f 99 9b 86 43 f6 56 b4 12 a3 <br />
ac ff ff ff ff 02 00 ca 9a 3b 00 00 00 00 43 41 04 ae 1a 62 fe 09 c5 f5 1b 13 90 <br />
5f 07 f0 6b 99 a2 f7 15 9b 22 25 f3 74 cd 37 8d 71 30 2f a2 84 14 e7 aa b3 73 97 <br />
f5 54 a7 df 5f 14 2c 21 c1 b7 30 3b 8a 06 26 f1 ba de d5 c7 2a 70 4f 7e 6c d8 4c <br />
ac 00 28 6b ee 00 00 00 00 43 41 04 11 db 93 e1 dc db 8a 01 6b 49 84 0f 8c 53 bc <br />
1e b6 8a 38 2e 97 b1 48 2e ca d7 b1 48 a6 90 9a 5c b2 e0 ea dd fb 84 cc f9 74 44 <br />
64 f8 2e 16 0b fa 9b 8b 64 f9 d4 c0 3f 99 9b 86 43 f6 56 b4 12 a3 ac 00 00 00 00 <br />
01 00 00 00 <br />
</pre><br />
<br />
To understand where that raw dump has come from, it may be useful to examine tests/ec-key.cpp in [https://gitorious.org/libbitcoin/libbitcoin libbitcoin],<br />
<br />
[https://gitorious.org/libbitcoin/libbitcoin libbitcoin] has a unit test under tests/ec-key.cpp (make ec-key && ./bin/tests/ec-key). There is also a working OP_CHECKSIG implementation in src/script.cpp under script::op_checksig(). See also the unit test: tests/script-test.cpp<br />
<br />
<source lang="cpp"><br />
#include <iostream><br />
#include <iomanip><br />
#include <bitcoin/util/serializer.hpp><br />
#include <bitcoin/util/elliptic_curve_key.hpp><br />
#include <bitcoin/util/sha256.hpp><br />
#include <bitcoin/util/assert.hpp><br />
#include <bitcoin/util/logger.hpp><br />
#include <bitcoin/types.hpp><br />
#include <openssl/ecdsa.h><br />
#include <openssl/obj_mac.h><br />
using libbitcoin::elliptic_curve_key;<br />
using libbitcoin::serializer;<br />
using libbitcoin::hash_digest;<br />
using libbitcoin::data_chunk;<br />
using libbitcoin::log_info;<br />
using libbitcoin::log_fatal;<br />
<br />
int main()<br />
{<br />
serializer ss;<br />
// blk number 170, tx 1, input 0<br />
// version = 1<br />
ss.write_4_bytes(1);<br />
// 1 inputs<br />
ss.write_var_uint(1);<br />
<br />
// input 0<br />
// prevout hash<br />
ss.write_hash(hash_digest{0x04, 0x37, 0xcd, 0x7f, 0x85, 0x25, 0xce, 0xed, 0x23, 0x24, 0x35, 0x9c, 0x2d, 0x0b, 0xa2, 0x60, 0x06, 0xd9, 0x2d, 0x85, 0x6a, 0x9c, 0x20, 0xfa, 0x02, 0x41, 0x10, 0x6e, 0xe5, 0xa5, 0x97, 0xc9});<br />
// prevout index <br />
ss.write_4_bytes(0);<br />
<br />
// input script after running OP_CHECKSIG for this tx is a single<br />
// OP_CHECKSIG opcode<br />
data_chunk raw_data;<br />
raw_data = {0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3};<br />
data_chunk raw_script;<br />
raw_script = data_chunk();<br />
raw_script.push_back(raw_data.size());<br />
libbitcoin::extend_data(raw_script, raw_data);<br />
raw_script.push_back(172);<br />
ss.write_var_uint(raw_script.size());<br />
ss.write_data(raw_script);<br />
// sequence<br />
ss.write_4_bytes(0xffffffff);<br />
<br />
// 2 outputs for this tx<br />
ss.write_var_uint(2);<br />
<br />
// output 0<br />
ss.write_8_bytes(1000000000);<br />
// script for output 0<br />
raw_data = {0x04, 0xae, 0x1a, 0x62, 0xfe, 0x09, 0xc5, 0xf5, 0x1b, 0x13, 0x90, 0x5f, 0x07, 0xf0, 0x6b, 0x99, 0xa2, 0xf7, 0x15, 0x9b, 0x22, 0x25, 0xf3, 0x74, 0xcd, 0x37, 0x8d, 0x71, 0x30, 0x2f, 0xa2, 0x84, 0x14, 0xe7, 0xaa, 0xb3, 0x73, 0x97, 0xf5, 0x54, 0xa7, 0xdf, 0x5f, 0x14, 0x2c, 0x21, 0xc1, 0xb7, 0x30, 0x3b, 0x8a, 0x06, 0x26, 0xf1, 0xba, 0xde, 0xd5, 0xc7, 0x2a, 0x70, 0x4f, 0x7e, 0x6c, 0xd8, 0x4c};<br />
// when data < 75, we can just write it's length as a single byte ('special'<br />
// opcodes)<br />
raw_script = data_chunk();<br />
raw_script.push_back(raw_data.size());<br />
libbitcoin::extend_data(raw_script, raw_data);<br />
// OP_CHECKSIG<br />
raw_script.push_back(172);<br />
// now actually write the script<br />
ss.write_var_uint(raw_script.size());<br />
ss.write_data(raw_script);<br />
<br />
// output 0<br />
ss.write_8_bytes(4000000000);<br />
// script for output 0<br />
raw_data = {0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3};<br />
// when data < 75, we can just write it's length as a single byte ('special'<br />
raw_script.push_back(raw_data.size());<br />
libbitcoin::extend_data(raw_script, raw_data);<br />
// OP_CHECKSIG<br />
raw_script.push_back(172);<br />
// now actually write the script<br />
ss.write_var_uint(raw_script.size());<br />
ss.write_data(raw_script);<br />
<br />
// End of 2 outputs<br />
<br />
// locktime<br />
ss.write_4_bytes(0);<br />
<br />
// write hash_type_code<br />
ss.write_4_bytes(1);<br />
<br />
// Dump hex to screen<br />
log_info() << "hashing:";<br />
{<br />
auto log_obj = log_info();<br />
log_obj << std::hex;<br />
for (int val: ss.get_data())<br />
log_obj << std::setfill('0') << std::setw(2) << val << ' ';<br />
}<br />
log_info();<br />
<br />
data_chunk raw_tx = {0x01, 0x00, 0x00, 0x00, 0x01, 0xc9, 0x97, 0xa5, 0xe5, 0x6e, 0x10, 0x41, 0x02, 0xfa, 0x20, 0x9c, 0x6a, 0x85, 0x2d, 0xd9, 0x06, 0x60, 0xa2, 0x0b, 0x2d, 0x9c, 0x35, 0x24, 0x23, 0xed, 0xce, 0x25, 0x85, 0x7f, 0xcd, 0x37, 0x04, 0x00, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3, 0xac, 0xff, 0xff, 0xff, 0xff, 0x02, 0x00, 0xca, 0x9a, 0x3b, 0x00, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, 0xae, 0x1a, 0x62, 0xfe, 0x09, 0xc5, 0xf5, 0x1b, 0x13, 0x90, 0x5f, 0x07, 0xf0, 0x6b, 0x99, 0xa2, 0xf7, 0x15, 0x9b, 0x22, 0x25, 0xf3, 0x74, 0xcd, 0x37, 0x8d, 0x71, 0x30, 0x2f, 0xa2, 0x84, 0x14, 0xe7, 0xaa, 0xb3, 0x73, 0x97, 0xf5, 0x54, 0xa7, 0xdf, 0x5f, 0x14, 0x2c, 0x21, 0xc1, 0xb7, 0x30, 0x3b, 0x8a, 0x06, 0x26, 0xf1, 0xba, 0xde, 0xd5, 0xc7, 0x2a, 0x70, 0x4f, 0x7e, 0x6c, 0xd8, 0x4c, 0xac, 0x00, 0x28, 0x6b, 0xee, 0x00, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3, 0xac, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00};<br />
BITCOIN_ASSERT(raw_tx == ss.get_data());<br />
<br />
hash_digest tx_hash = libbitcoin::generate_sha256_hash(ss.get_data());<br />
<br />
data_chunk pubkey{0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3};<br />
// Leave out last byte since that's the hash_type_code (SIGHASH_ALL in this<br />
// case)<br />
data_chunk signature{0x30, 0x44, 0x02, 0x20, 0x4e, 0x45, 0xe1, 0x69, 0x32, 0xb8, 0xaf, 0x51, 0x49, 0x61, 0xa1, 0xd3, 0xa1, 0xa2, 0x5f, 0xdf, 0x3f, 0x4f, 0x77, 0x32, 0xe9, 0xd6, 0x24, 0xc6, 0xc6, 0x15, 0x48, 0xab, 0x5f, 0xb8, 0xcd, 0x41, 0x02, 0x20, 0x18, 0x15, 0x22, 0xec, 0x8e, 0xca, 0x07, 0xde, 0x48, 0x60, 0xa4, 0xac, 0xdd, 0x12, 0x90, 0x9d, 0x83, 0x1c, 0xc5, 0x6c, 0xbb, 0xac, 0x46, 0x22, 0x08, 0x22, 0x21, 0xa8, 0x76, 0x8d, 0x1d, 0x09};<br />
BITCOIN_ASSERT(signature.size() == 70);<br />
<br />
elliptic_curve_key key;<br />
if (!key.set_public_key(pubkey))<br />
{<br />
log_fatal() << "unable to set EC public key";<br />
return -1;<br />
}<br />
<br />
log_info() << "checksig returns: " << (key.verify(tx_hash, signature) ? "true" : "false");<br />
return 0;<br />
}<br />
<br />
</source><br />
<br />
==References==<br />
<references/><br />
<br />
[[Category:Technical]]<br />
[[Category:Developer]]</div>
Smtp
https://en.bitcoin.it/w/index.php?title=OP_CHECKSIG&diff=34867
OP CHECKSIG
2013-01-09T22:51:38Z
<p>Smtp: /* How it works */ other hashtypes</p>
<hr />
<div>OP_CHECKSIG is [[Script|script]] opcode used to verify that the signature for a tx input is valid. OP_CHECKSIG expects two values to be on the stack, these are, in order of stack depth, the public key and the signature of the script. These two values are normally obtained by running the scriptSig script of the transaction input we are attempting to validate. After the scriptSig script is run the script is deleted but the stack is left as is, and then then scriptPubKey script from the previous transaction output that is now being spent is run, generally concluding in an OP_CHECKSIG. <br />
<br />
The standard scriptPubKey checks that the public key (actually a hash of) is a particular value, and that OP_CHECKSIG passes.<br />
<br />
For normal transaction inputs if the creator of the current transaction can successfully create a ScriptSig signature that uses the right public key for the ScriptPubKey of the transaction output they are attempting to spend, that transaction input is considered valid. <br />
<br />
== Parameters ==<br />
<br />
In addition to the script code itself and the stack parameters, to operate OP_CHECKSIG needs to know the current transaction and the index of current transaction input.<br />
<br />
== How it works ==<br />
Firstly always this (the default) procedure is applied:<br />
[[File:Bitcoin_OpCheckSig_InDetail.png|thumb|right|Signature verification process of the default procedure]]<br />
# the public key and the signature are popped from the stack, in that order. If the hash-type value is 0, then it is replaced by the last_byte of the signature. Then the last byte of the signature is always deleted.<br />
# A new subscript is created from the instruction from the most recently parsed OP_CODESEPARATOR (last one in script) to the end of the script. If there is no OP_CODESEPARATOR the entire script becomes the subscript (hereby referred to as subScript)<br />
# The sig is deleted from subScript.<br />
# All OP_CODESEPARATORS are removed from subScript<br />
# The hashtype is removed from the last byte of the sig and stored<br />
# A copy is made of the current transaction (hereby referred to txCopy)<br />
# The scripts for all transaction inputs in txCopy are set to empty scripts (exactly 1 byte 0x00)<br />
# The script for the current transaction input in txCopy is set to subScript (lead in by its length as a var-integer encoded!)<br />
<br />
Now depending on the hashtype various things can happen to txCopy, these will be discussed individually.<br />
<br />
'''Hashtype Values (from script.h):'''<br />
{|class="wikitable"<br />
! Name !! Value<br />
|-<br />
| SIGHASH_ALL || 0x00000001<br />
|-<br />
| SIGHASH_NONE || 0x00000002<br />
|-<br />
| SIGHASH_SINGLE || 0x00000003<br />
|-<br />
| SIGHASH_ANYONECANPAY || 0x00000080<br />
|}<br />
<br />
<ol><br />
<li> If (Hashtype&31) = SIGHASH_NONE then apply the SIGHASH_NONE-procedure<br />
<li> If (Hashtype&31) = SIGHASH_SINGLE then apply the SIGHASH_SINGLE-procedure<br />
<li> If Hashtype & SIGHASH_ANYONECANPAY then apply the SIGHASH_ANYONECANPAY-procedure<br />
</ol><br />
Hence, Hashtype SIGHASH_ANYONECANPAY may be applied also after any other hashtype-procedure<ref>[http://sourceforge.net/projects/bitcoin/files/Bitcoin/bitcoin-0.7.1/bitcoin-0.7.1-linux.tar.gz file src/src/script.cpp in bitcoin-0.7.1]</ref>. Besides the four listed Hashtypes only a hashtype of value 0 appears a few types in the (main) block chain (and is handled like SIGHASH_ALL).<br />
<br />
=== Hashtype SIGHASH_ALL (default) ===<br />
<br />
No special further handling occurs in the default case. Think of this as "sign '''all''' of the outputs." Which is already done by the default procedure.<br />
<br />
=== Procedure for Hashtype SIGHASH_NONE ===<br />
<br />
# The output of txCopy is set to a vector of zero size.<br />
# All other inputs aside from the current input in txCopy have their nSequence index set to zero<br />
<br />
Think of this as "sign '''none''' of the outputs-- I don't care where the bitcoins go."<br />
<br />
=== Procedure for Hashtype SIGHASH_SINGLE ===<br />
<br />
# The output of txCopy is resized to the size of the current input index+1<br />
# All other txCopy outputs aside from the output that is the same as the current input index are set to a blank script and a value of (long) -1;<br />
# All other txCopy inputs aside from the current input are set to have an nSequence index of zero<br />
<br />
Think of this as "sign '''one''' of the outputs-- I don't care where the other outputs go."<br />
<br />
=== Procedure for Hashtype SIGHASH_ANYONECANPAY ===<br />
<br />
# The txCopy input vector is resized to a length of one<br />
# The current input is set as the first and only member of this vector<br />
<br />
Think of this as "Let other people add inputs to this transaction, I don't care where the rest of the bitcoins come from."<br />
<br />
== Final signature ==<br />
<br />
An array of bytes is constructed from the serialized txCopy + four bytes for the hash type. This array is sha256 hashed twice, then the public key is used to to check the supplied signature against the hash. <br />
<br />
== Return values ==<br />
<br />
OP_CHECKSIG will push true to the stack if the check passed, false otherwise.<br />
OP_CHECKSIG_VERIFY leaves nothing on the stack but will cause the script eval to fail immediately if the check does not pass.<br />
<br />
== Code samples and raw dumps ==<br />
<br />
Taking the first transaction in Bitcoin which is in block number 170, we would get after serialising the transaction but before we hash+sign (or verify) it:<br />
<br />
* http://blockexplorer.com/block/00000000d1145790a8694403d4063f323d499e655c83426834d4ce2f8dd4a2ee<br />
* http://blockexplorer.com/tx/f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16<br />
<br />
See also [https://gitorious.org/libbitcoin/libbitcoin libbitcoin] for code samples.<br />
<br />
<pre><br />
01 00 00 00 version<br />
01 number of inputs (var_uint)<br />
<br />
input 0:<br />
c9 97 a5 e5 6e 10 41 02 input address hash<br />
fa 20 9c 6a 85 2d d9 06 <br />
60 a2 0b 2d 9c 35 24 23 <br />
ed ce 25 85 7f cd 37 04<br />
00 00 00 00 input index<br />
<br />
48 size of script (var_uint)<br />
47 push 71 bytes to stack<br />
30 44 02 20 4e 45 e1 69<br />
32 b8 af 51 49 61 a1 d3<br />
a1 a2 5f df 3f 4f 77 32<br />
e9 d6 24 c6 c6 15 48 ab<br />
5f b8 cd 41 02 20 18 15<br />
22 ec 8e ca 07 de 48 60<br />
a4 ac dd 12 90 9d 83 1c<br />
c5 6c bb ac 46 22 08 22<br />
21 a8 76 8d 1d 09 01<br />
ff ff ff ff sequence<br />
<br />
02 number of outputs (var_uint)<br />
<br />
output 0:<br />
00 ca 9a 3b 00 00 00 00 amount = 10.00000000<br />
43 size of script (var_uint)<br />
script for output 0:<br />
41 push 65 bytes to stack<br />
04 ae 1a 62 fe 09 c5 f5 <br />
1b 13 90 5f 07 f0 6b 99 <br />
a2 f7 15 9b 22 25 f3 74 <br />
cd 37 8d 71 30 2f a2 84 <br />
14 e7 aa b3 73 97 f5 54 <br />
a7 df 5f 14 2c 21 c1 b7 <br />
30 3b 8a 06 26 f1 ba de <br />
d5 c7 2a 70 4f 7e 6c d8 <br />
4c <br />
ac OP_CHECKSIG<br />
<br />
output 1:<br />
00 28 6b ee 00 00 00 00 amount = 40.00000000<br />
43 size of script (var_uint)<br />
script for output 1:<br />
41 push 65 bytes to stack<br />
04 11 db 93 e1 dc db 8a <br />
01 6b 49 84 0f 8c 53 bc <br />
1e b6 8a 38 2e 97 b1 48 <br />
2e ca d7 b1 48 a6 90 9a<br />
5c b2 e0 ea dd fb 84 cc <br />
f9 74 44 64 f8 2e 16 0b <br />
fa 9b 8b 64 f9 d4 c0 3f <br />
99 9b 86 43 f6 56 b4 12 <br />
a3 <br />
ac OP_CHECKSIG<br />
<br />
00 00 00 00 locktime<br />
01 00 00 00 hash_code_type (added on)<br />
<br />
result =<br />
01 00 00 00 01 c9 97 a5 e5 6e 10 41 02 fa 20 9c 6a 85 2d d9 06 60 a2 0b 2d 9c 35 <br />
24 23 ed ce 25 85 7f cd 37 04 00 00 00 00 43 41 04 11 db 93 e1 dc db 8a 01 6b 49 <br />
84 0f 8c 53 bc 1e b6 8a 38 2e 97 b1 48 2e ca d7 b1 48 a6 90 9a 5c b2 e0 ea dd fb <br />
84 cc f9 74 44 64 f8 2e 16 0b fa 9b 8b 64 f9 d4 c0 3f 99 9b 86 43 f6 56 b4 12 a3 <br />
ac ff ff ff ff 02 00 ca 9a 3b 00 00 00 00 43 41 04 ae 1a 62 fe 09 c5 f5 1b 13 90 <br />
5f 07 f0 6b 99 a2 f7 15 9b 22 25 f3 74 cd 37 8d 71 30 2f a2 84 14 e7 aa b3 73 97 <br />
f5 54 a7 df 5f 14 2c 21 c1 b7 30 3b 8a 06 26 f1 ba de d5 c7 2a 70 4f 7e 6c d8 4c <br />
ac 00 28 6b ee 00 00 00 00 43 41 04 11 db 93 e1 dc db 8a 01 6b 49 84 0f 8c 53 bc <br />
1e b6 8a 38 2e 97 b1 48 2e ca d7 b1 48 a6 90 9a 5c b2 e0 ea dd fb 84 cc f9 74 44 <br />
64 f8 2e 16 0b fa 9b 8b 64 f9 d4 c0 3f 99 9b 86 43 f6 56 b4 12 a3 ac 00 00 00 00 <br />
01 00 00 00 <br />
</pre><br />
<br />
To understand where that raw dump has come from, it may be useful to examine tests/ec-key.cpp in [https://gitorious.org/libbitcoin/libbitcoin libbitcoin],<br />
<br />
[https://gitorious.org/libbitcoin/libbitcoin libbitcoin] has a unit test under tests/ec-key.cpp (make ec-key && ./bin/tests/ec-key). There is also a working OP_CHECKSIG implementation in src/script.cpp under script::op_checksig(). See also the unit test: tests/script-test.cpp<br />
<br />
<source lang="cpp"><br />
#include <iostream><br />
#include <iomanip><br />
#include <bitcoin/util/serializer.hpp><br />
#include <bitcoin/util/elliptic_curve_key.hpp><br />
#include <bitcoin/util/sha256.hpp><br />
#include <bitcoin/util/assert.hpp><br />
#include <bitcoin/util/logger.hpp><br />
#include <bitcoin/types.hpp><br />
#include <openssl/ecdsa.h><br />
#include <openssl/obj_mac.h><br />
using libbitcoin::elliptic_curve_key;<br />
using libbitcoin::serializer;<br />
using libbitcoin::hash_digest;<br />
using libbitcoin::data_chunk;<br />
using libbitcoin::log_info;<br />
using libbitcoin::log_fatal;<br />
<br />
int main()<br />
{<br />
serializer ss;<br />
// blk number 170, tx 1, input 0<br />
// version = 1<br />
ss.write_4_bytes(1);<br />
// 1 inputs<br />
ss.write_var_uint(1);<br />
<br />
// input 0<br />
// prevout hash<br />
ss.write_hash(hash_digest{0x04, 0x37, 0xcd, 0x7f, 0x85, 0x25, 0xce, 0xed, 0x23, 0x24, 0x35, 0x9c, 0x2d, 0x0b, 0xa2, 0x60, 0x06, 0xd9, 0x2d, 0x85, 0x6a, 0x9c, 0x20, 0xfa, 0x02, 0x41, 0x10, 0x6e, 0xe5, 0xa5, 0x97, 0xc9});<br />
// prevout index <br />
ss.write_4_bytes(0);<br />
<br />
// input script after running OP_CHECKSIG for this tx is a single<br />
// OP_CHECKSIG opcode<br />
data_chunk raw_data;<br />
raw_data = {0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3};<br />
data_chunk raw_script;<br />
raw_script = data_chunk();<br />
raw_script.push_back(raw_data.size());<br />
libbitcoin::extend_data(raw_script, raw_data);<br />
raw_script.push_back(172);<br />
ss.write_var_uint(raw_script.size());<br />
ss.write_data(raw_script);<br />
// sequence<br />
ss.write_4_bytes(0xffffffff);<br />
<br />
// 2 outputs for this tx<br />
ss.write_var_uint(2);<br />
<br />
// output 0<br />
ss.write_8_bytes(1000000000);<br />
// script for output 0<br />
raw_data = {0x04, 0xae, 0x1a, 0x62, 0xfe, 0x09, 0xc5, 0xf5, 0x1b, 0x13, 0x90, 0x5f, 0x07, 0xf0, 0x6b, 0x99, 0xa2, 0xf7, 0x15, 0x9b, 0x22, 0x25, 0xf3, 0x74, 0xcd, 0x37, 0x8d, 0x71, 0x30, 0x2f, 0xa2, 0x84, 0x14, 0xe7, 0xaa, 0xb3, 0x73, 0x97, 0xf5, 0x54, 0xa7, 0xdf, 0x5f, 0x14, 0x2c, 0x21, 0xc1, 0xb7, 0x30, 0x3b, 0x8a, 0x06, 0x26, 0xf1, 0xba, 0xde, 0xd5, 0xc7, 0x2a, 0x70, 0x4f, 0x7e, 0x6c, 0xd8, 0x4c};<br />
// when data < 75, we can just write it's length as a single byte ('special'<br />
// opcodes)<br />
raw_script = data_chunk();<br />
raw_script.push_back(raw_data.size());<br />
libbitcoin::extend_data(raw_script, raw_data);<br />
// OP_CHECKSIG<br />
raw_script.push_back(172);<br />
// now actually write the script<br />
ss.write_var_uint(raw_script.size());<br />
ss.write_data(raw_script);<br />
<br />
// output 0<br />
ss.write_8_bytes(4000000000);<br />
// script for output 0<br />
raw_data = {0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3};<br />
// when data < 75, we can just write it's length as a single byte ('special'<br />
raw_script.push_back(raw_data.size());<br />
libbitcoin::extend_data(raw_script, raw_data);<br />
// OP_CHECKSIG<br />
raw_script.push_back(172);<br />
// now actually write the script<br />
ss.write_var_uint(raw_script.size());<br />
ss.write_data(raw_script);<br />
<br />
// End of 2 outputs<br />
<br />
// locktime<br />
ss.write_4_bytes(0);<br />
<br />
// write hash_type_code<br />
ss.write_4_bytes(1);<br />
<br />
// Dump hex to screen<br />
log_info() << "hashing:";<br />
{<br />
auto log_obj = log_info();<br />
log_obj << std::hex;<br />
for (int val: ss.get_data())<br />
log_obj << std::setfill('0') << std::setw(2) << val << ' ';<br />
}<br />
log_info();<br />
<br />
data_chunk raw_tx = {0x01, 0x00, 0x00, 0x00, 0x01, 0xc9, 0x97, 0xa5, 0xe5, 0x6e, 0x10, 0x41, 0x02, 0xfa, 0x20, 0x9c, 0x6a, 0x85, 0x2d, 0xd9, 0x06, 0x60, 0xa2, 0x0b, 0x2d, 0x9c, 0x35, 0x24, 0x23, 0xed, 0xce, 0x25, 0x85, 0x7f, 0xcd, 0x37, 0x04, 0x00, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3, 0xac, 0xff, 0xff, 0xff, 0xff, 0x02, 0x00, 0xca, 0x9a, 0x3b, 0x00, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, 0xae, 0x1a, 0x62, 0xfe, 0x09, 0xc5, 0xf5, 0x1b, 0x13, 0x90, 0x5f, 0x07, 0xf0, 0x6b, 0x99, 0xa2, 0xf7, 0x15, 0x9b, 0x22, 0x25, 0xf3, 0x74, 0xcd, 0x37, 0x8d, 0x71, 0x30, 0x2f, 0xa2, 0x84, 0x14, 0xe7, 0xaa, 0xb3, 0x73, 0x97, 0xf5, 0x54, 0xa7, 0xdf, 0x5f, 0x14, 0x2c, 0x21, 0xc1, 0xb7, 0x30, 0x3b, 0x8a, 0x06, 0x26, 0xf1, 0xba, 0xde, 0xd5, 0xc7, 0x2a, 0x70, 0x4f, 0x7e, 0x6c, 0xd8, 0x4c, 0xac, 0x00, 0x28, 0x6b, 0xee, 0x00, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3, 0xac, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00};<br />
BITCOIN_ASSERT(raw_tx == ss.get_data());<br />
<br />
hash_digest tx_hash = libbitcoin::generate_sha256_hash(ss.get_data());<br />
<br />
data_chunk pubkey{0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3};<br />
// Leave out last byte since that's the hash_type_code (SIGHASH_ALL in this<br />
// case)<br />
data_chunk signature{0x30, 0x44, 0x02, 0x20, 0x4e, 0x45, 0xe1, 0x69, 0x32, 0xb8, 0xaf, 0x51, 0x49, 0x61, 0xa1, 0xd3, 0xa1, 0xa2, 0x5f, 0xdf, 0x3f, 0x4f, 0x77, 0x32, 0xe9, 0xd6, 0x24, 0xc6, 0xc6, 0x15, 0x48, 0xab, 0x5f, 0xb8, 0xcd, 0x41, 0x02, 0x20, 0x18, 0x15, 0x22, 0xec, 0x8e, 0xca, 0x07, 0xde, 0x48, 0x60, 0xa4, 0xac, 0xdd, 0x12, 0x90, 0x9d, 0x83, 0x1c, 0xc5, 0x6c, 0xbb, 0xac, 0x46, 0x22, 0x08, 0x22, 0x21, 0xa8, 0x76, 0x8d, 0x1d, 0x09};<br />
BITCOIN_ASSERT(signature.size() == 70);<br />
<br />
elliptic_curve_key key;<br />
if (!key.set_public_key(pubkey))<br />
{<br />
log_fatal() << "unable to set EC public key";<br />
return -1;<br />
}<br />
<br />
log_info() << "checksig returns: " << (key.verify(tx_hash, signature) ? "true" : "false");<br />
return 0;<br />
}<br />
<br />
</source><br />
<br />
==References==<br />
<references/><br />
<br />
[[Category:Technical]]<br />
[[Category:Developer]]</div>
Smtp
https://en.bitcoin.it/w/index.php?title=OP_CHECKSIG&diff=34862
OP CHECKSIG
2013-01-09T17:53:33Z
<p>Smtp: /* Parameters */ hashtype can be extracted from signature and but if it is given MUST match it -- thus it is not needed as parameter.</p>
<hr />
<div>OP_CHECKSIG is [[Script|script]] opcode used to verify that the signature for a tx input is valid. OP_CHECKSIG expects two values to be on the stack, these are, in order of stack depth, the public key and the signature of the script. These two values are normally obtained by running the scriptSig script of the transaction input we are attempting to validate. After the scriptSig script is run the script is deleted but the stack is left as is, and then then scriptPubKey script from the previous transaction output that is now being spent is run, generally concluding in an OP_CHECKSIG. <br />
<br />
The standard scriptPubKey checks that the public key (actually a hash of) is a particular value, and that OP_CHECKSIG passes.<br />
<br />
For normal transaction inputs if the creator of the current transaction can successfully create a ScriptSig signature that uses the right public key for the ScriptPubKey of the transaction output they are attempting to spend, that transaction input is considered valid. <br />
<br />
== Parameters ==<br />
<br />
In addition to the script code itself and the stack parameters, to operate OP_CHECKSIG needs to know the current transaction and the index of current transaction input.<br />
<br />
== How it works ==<br />
Firstly always this (the default) procedure is applied:<br />
[[File:Bitcoin_OpCheckSig_InDetail.png|thumb|right|Signature verification process of the default procedure]]<br />
# the public key and the signature are popped from the stack, in that order. If the hash-type value is 0, then it is replaced by the last_byte of the signature. Then the last byte of the signature is always deleted.<br />
# A new subscript is created from the instruction from the most recently parsed OP_CODESEPARATOR (last one in script) to the end of the script. If there is no OP_CODESEPARATOR the entire script becomes the subscript (hereby referred to as subScript)<br />
# The sig is deleted from subScript.<br />
# All OP_CODESEPARATORS are removed from subScript<br />
# The hashtype is removed from the last byte of the sig and stored<br />
# A copy is made of the current transaction (hereby referred to txCopy)<br />
# The scripts for all transaction inputs in txCopy are set to empty scripts (exactly 1 byte 0x00)<br />
# The script for the current transaction input in txCopy is set to subScript (lead in by its length as a var-integer encoded!)<br />
<br />
Now depending on the hashtype various things can happen to txCopy, these will be discussed individually<br />
<br />
<br />
'''Hashtype Values (from script.h):'''<br />
{|class="wikitable"<br />
! Name !! Value<br />
|-<br />
| SIGHASH_ALL || 0x00000001<br />
|-<br />
| SIGHASH_NONE || 0x00000002<br />
|-<br />
| SIGHASH_SINGLE || 0x00000003<br />
|-<br />
| SIGHASH_ANYONECANPAY || 0x00000080<br />
|}<br />
<br />
<ol><br />
<li> If Hashtype = SIGHASH_NONE then apply the SIGHASH_NONE-procedure<br />
<li> If Hashtype = SIGHASH_SINGLE then apply the SIGHASH_SINGLE-procedure<br />
<li> If Hashtype & SIGHASH_ANYONECANPAY then apply the SIGHASH_ANYONECANPAY-procedure<br />
</ol><br />
Hence, Hashtype SIGHASH_ANYONECANPAY may be applied also after any other hashtype-procedure<ref>[http://sourceforge.net/projects/bitcoin/files/Bitcoin/bitcoin-0.7.1/bitcoin-0.7.1-linux.tar.gz file src/src/script.cpp in bitcoin-0.7.1]</ref>.<br />
<br />
=== Hashtype SIGHASH_ALL (default) ===<br />
<br />
No special further handling occurs in the default case. Think of this as "sign '''all''' of the outputs." Which is already done by the default procedure.<br />
<br />
=== Procedure for Hashtype SIGHASH_NONE ===<br />
<br />
# The output of txCopy is set to a vector of zero size.<br />
# All other inputs aside from the current input in txCopy have their nSequence index set to zero<br />
<br />
Think of this as "sign '''none''' of the outputs-- I don't care where the bitcoins go."<br />
<br />
=== Procedure for Hashtype SIGHASH_SINGLE ===<br />
<br />
# The output of txCopy is resized to the size of the current input index+1<br />
# All other txCopy outputs aside from the output that is the same as the current input index are set to a blank script and a value of (long) -1;<br />
# All other txCopy inputs aside from the current input are set to have an nSequence index of zero<br />
<br />
Think of this as "sign '''one''' of the outputs-- I don't care where the other outputs go."<br />
<br />
=== Procedure for Hashtype SIGHASH_ANYONECANPAY ===<br />
<br />
# The txCopy input vector is resized to a length of one<br />
# The current input is set as the first and only member of this vector<br />
<br />
Think of this as "Let other people add inputs to this transaction, I don't care where the rest of the bitcoins come from."<br />
<br />
== Final signature ==<br />
<br />
An array of bytes is constructed from the serialized txCopy + four bytes for the hash type. This array is sha256 hashed twice, then the public key is used to to check the supplied signature against the hash. <br />
<br />
== Return values ==<br />
<br />
OP_CHECKSIG will push true to the stack if the check passed, false otherwise.<br />
OP_CHECKSIG_VERIFY leaves nothing on the stack but will cause the script eval to fail immediately if the check does not pass.<br />
<br />
== Code samples and raw dumps ==<br />
<br />
Taking the first transaction in Bitcoin which is in block number 170, we would get after serialising the transaction but before we hash+sign (or verify) it:<br />
<br />
* http://blockexplorer.com/block/00000000d1145790a8694403d4063f323d499e655c83426834d4ce2f8dd4a2ee<br />
* http://blockexplorer.com/tx/f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16<br />
<br />
See also [https://gitorious.org/libbitcoin/libbitcoin libbitcoin] for code samples.<br />
<br />
<pre><br />
01 00 00 00 version<br />
01 number of inputs (var_uint)<br />
<br />
input 0:<br />
c9 97 a5 e5 6e 10 41 02 input address hash<br />
fa 20 9c 6a 85 2d d9 06 <br />
60 a2 0b 2d 9c 35 24 23 <br />
ed ce 25 85 7f cd 37 04<br />
00 00 00 00 input index<br />
<br />
48 size of script (var_uint)<br />
47 push 71 bytes to stack<br />
30 44 02 20 4e 45 e1 69<br />
32 b8 af 51 49 61 a1 d3<br />
a1 a2 5f df 3f 4f 77 32<br />
e9 d6 24 c6 c6 15 48 ab<br />
5f b8 cd 41 02 20 18 15<br />
22 ec 8e ca 07 de 48 60<br />
a4 ac dd 12 90 9d 83 1c<br />
c5 6c bb ac 46 22 08 22<br />
21 a8 76 8d 1d 09 01<br />
ff ff ff ff sequence<br />
<br />
02 number of outputs (var_uint)<br />
<br />
output 0:<br />
00 ca 9a 3b 00 00 00 00 amount = 10.00000000<br />
43 size of script (var_uint)<br />
script for output 0:<br />
41 push 65 bytes to stack<br />
04 ae 1a 62 fe 09 c5 f5 <br />
1b 13 90 5f 07 f0 6b 99 <br />
a2 f7 15 9b 22 25 f3 74 <br />
cd 37 8d 71 30 2f a2 84 <br />
14 e7 aa b3 73 97 f5 54 <br />
a7 df 5f 14 2c 21 c1 b7 <br />
30 3b 8a 06 26 f1 ba de <br />
d5 c7 2a 70 4f 7e 6c d8 <br />
4c <br />
ac OP_CHECKSIG<br />
<br />
output 1:<br />
00 28 6b ee 00 00 00 00 amount = 40.00000000<br />
43 size of script (var_uint)<br />
script for output 1:<br />
41 push 65 bytes to stack<br />
04 11 db 93 e1 dc db 8a <br />
01 6b 49 84 0f 8c 53 bc <br />
1e b6 8a 38 2e 97 b1 48 <br />
2e ca d7 b1 48 a6 90 9a<br />
5c b2 e0 ea dd fb 84 cc <br />
f9 74 44 64 f8 2e 16 0b <br />
fa 9b 8b 64 f9 d4 c0 3f <br />
99 9b 86 43 f6 56 b4 12 <br />
a3 <br />
ac OP_CHECKSIG<br />
<br />
00 00 00 00 locktime<br />
01 00 00 00 hash_code_type (added on)<br />
<br />
result =<br />
01 00 00 00 01 c9 97 a5 e5 6e 10 41 02 fa 20 9c 6a 85 2d d9 06 60 a2 0b 2d 9c 35 <br />
24 23 ed ce 25 85 7f cd 37 04 00 00 00 00 43 41 04 11 db 93 e1 dc db 8a 01 6b 49 <br />
84 0f 8c 53 bc 1e b6 8a 38 2e 97 b1 48 2e ca d7 b1 48 a6 90 9a 5c b2 e0 ea dd fb <br />
84 cc f9 74 44 64 f8 2e 16 0b fa 9b 8b 64 f9 d4 c0 3f 99 9b 86 43 f6 56 b4 12 a3 <br />
ac ff ff ff ff 02 00 ca 9a 3b 00 00 00 00 43 41 04 ae 1a 62 fe 09 c5 f5 1b 13 90 <br />
5f 07 f0 6b 99 a2 f7 15 9b 22 25 f3 74 cd 37 8d 71 30 2f a2 84 14 e7 aa b3 73 97 <br />
f5 54 a7 df 5f 14 2c 21 c1 b7 30 3b 8a 06 26 f1 ba de d5 c7 2a 70 4f 7e 6c d8 4c <br />
ac 00 28 6b ee 00 00 00 00 43 41 04 11 db 93 e1 dc db 8a 01 6b 49 84 0f 8c 53 bc <br />
1e b6 8a 38 2e 97 b1 48 2e ca d7 b1 48 a6 90 9a 5c b2 e0 ea dd fb 84 cc f9 74 44 <br />
64 f8 2e 16 0b fa 9b 8b 64 f9 d4 c0 3f 99 9b 86 43 f6 56 b4 12 a3 ac 00 00 00 00 <br />
01 00 00 00 <br />
</pre><br />
<br />
To understand where that raw dump has come from, it may be useful to examine tests/ec-key.cpp in [https://gitorious.org/libbitcoin/libbitcoin libbitcoin],<br />
<br />
[https://gitorious.org/libbitcoin/libbitcoin libbitcoin] has a unit test under tests/ec-key.cpp (make ec-key && ./bin/tests/ec-key). There is also a working OP_CHECKSIG implementation in src/script.cpp under script::op_checksig(). See also the unit test: tests/script-test.cpp<br />
<br />
<source lang="cpp"><br />
#include <iostream><br />
#include <iomanip><br />
#include <bitcoin/util/serializer.hpp><br />
#include <bitcoin/util/elliptic_curve_key.hpp><br />
#include <bitcoin/util/sha256.hpp><br />
#include <bitcoin/util/assert.hpp><br />
#include <bitcoin/util/logger.hpp><br />
#include <bitcoin/types.hpp><br />
#include <openssl/ecdsa.h><br />
#include <openssl/obj_mac.h><br />
using libbitcoin::elliptic_curve_key;<br />
using libbitcoin::serializer;<br />
using libbitcoin::hash_digest;<br />
using libbitcoin::data_chunk;<br />
using libbitcoin::log_info;<br />
using libbitcoin::log_fatal;<br />
<br />
int main()<br />
{<br />
serializer ss;<br />
// blk number 170, tx 1, input 0<br />
// version = 1<br />
ss.write_4_bytes(1);<br />
// 1 inputs<br />
ss.write_var_uint(1);<br />
<br />
// input 0<br />
// prevout hash<br />
ss.write_hash(hash_digest{0x04, 0x37, 0xcd, 0x7f, 0x85, 0x25, 0xce, 0xed, 0x23, 0x24, 0x35, 0x9c, 0x2d, 0x0b, 0xa2, 0x60, 0x06, 0xd9, 0x2d, 0x85, 0x6a, 0x9c, 0x20, 0xfa, 0x02, 0x41, 0x10, 0x6e, 0xe5, 0xa5, 0x97, 0xc9});<br />
// prevout index <br />
ss.write_4_bytes(0);<br />
<br />
// input script after running OP_CHECKSIG for this tx is a single<br />
// OP_CHECKSIG opcode<br />
data_chunk raw_data;<br />
raw_data = {0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3};<br />
data_chunk raw_script;<br />
raw_script = data_chunk();<br />
raw_script.push_back(raw_data.size());<br />
libbitcoin::extend_data(raw_script, raw_data);<br />
raw_script.push_back(172);<br />
ss.write_var_uint(raw_script.size());<br />
ss.write_data(raw_script);<br />
// sequence<br />
ss.write_4_bytes(0xffffffff);<br />
<br />
// 2 outputs for this tx<br />
ss.write_var_uint(2);<br />
<br />
// output 0<br />
ss.write_8_bytes(1000000000);<br />
// script for output 0<br />
raw_data = {0x04, 0xae, 0x1a, 0x62, 0xfe, 0x09, 0xc5, 0xf5, 0x1b, 0x13, 0x90, 0x5f, 0x07, 0xf0, 0x6b, 0x99, 0xa2, 0xf7, 0x15, 0x9b, 0x22, 0x25, 0xf3, 0x74, 0xcd, 0x37, 0x8d, 0x71, 0x30, 0x2f, 0xa2, 0x84, 0x14, 0xe7, 0xaa, 0xb3, 0x73, 0x97, 0xf5, 0x54, 0xa7, 0xdf, 0x5f, 0x14, 0x2c, 0x21, 0xc1, 0xb7, 0x30, 0x3b, 0x8a, 0x06, 0x26, 0xf1, 0xba, 0xde, 0xd5, 0xc7, 0x2a, 0x70, 0x4f, 0x7e, 0x6c, 0xd8, 0x4c};<br />
// when data < 75, we can just write it's length as a single byte ('special'<br />
// opcodes)<br />
raw_script = data_chunk();<br />
raw_script.push_back(raw_data.size());<br />
libbitcoin::extend_data(raw_script, raw_data);<br />
// OP_CHECKSIG<br />
raw_script.push_back(172);<br />
// now actually write the script<br />
ss.write_var_uint(raw_script.size());<br />
ss.write_data(raw_script);<br />
<br />
// output 0<br />
ss.write_8_bytes(4000000000);<br />
// script for output 0<br />
raw_data = {0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3};<br />
// when data < 75, we can just write it's length as a single byte ('special'<br />
raw_script.push_back(raw_data.size());<br />
libbitcoin::extend_data(raw_script, raw_data);<br />
// OP_CHECKSIG<br />
raw_script.push_back(172);<br />
// now actually write the script<br />
ss.write_var_uint(raw_script.size());<br />
ss.write_data(raw_script);<br />
<br />
// End of 2 outputs<br />
<br />
// locktime<br />
ss.write_4_bytes(0);<br />
<br />
// write hash_type_code<br />
ss.write_4_bytes(1);<br />
<br />
// Dump hex to screen<br />
log_info() << "hashing:";<br />
{<br />
auto log_obj = log_info();<br />
log_obj << std::hex;<br />
for (int val: ss.get_data())<br />
log_obj << std::setfill('0') << std::setw(2) << val << ' ';<br />
}<br />
log_info();<br />
<br />
data_chunk raw_tx = {0x01, 0x00, 0x00, 0x00, 0x01, 0xc9, 0x97, 0xa5, 0xe5, 0x6e, 0x10, 0x41, 0x02, 0xfa, 0x20, 0x9c, 0x6a, 0x85, 0x2d, 0xd9, 0x06, 0x60, 0xa2, 0x0b, 0x2d, 0x9c, 0x35, 0x24, 0x23, 0xed, 0xce, 0x25, 0x85, 0x7f, 0xcd, 0x37, 0x04, 0x00, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3, 0xac, 0xff, 0xff, 0xff, 0xff, 0x02, 0x00, 0xca, 0x9a, 0x3b, 0x00, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, 0xae, 0x1a, 0x62, 0xfe, 0x09, 0xc5, 0xf5, 0x1b, 0x13, 0x90, 0x5f, 0x07, 0xf0, 0x6b, 0x99, 0xa2, 0xf7, 0x15, 0x9b, 0x22, 0x25, 0xf3, 0x74, 0xcd, 0x37, 0x8d, 0x71, 0x30, 0x2f, 0xa2, 0x84, 0x14, 0xe7, 0xaa, 0xb3, 0x73, 0x97, 0xf5, 0x54, 0xa7, 0xdf, 0x5f, 0x14, 0x2c, 0x21, 0xc1, 0xb7, 0x30, 0x3b, 0x8a, 0x06, 0x26, 0xf1, 0xba, 0xde, 0xd5, 0xc7, 0x2a, 0x70, 0x4f, 0x7e, 0x6c, 0xd8, 0x4c, 0xac, 0x00, 0x28, 0x6b, 0xee, 0x00, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3, 0xac, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00};<br />
BITCOIN_ASSERT(raw_tx == ss.get_data());<br />
<br />
hash_digest tx_hash = libbitcoin::generate_sha256_hash(ss.get_data());<br />
<br />
data_chunk pubkey{0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3};<br />
// Leave out last byte since that's the hash_type_code (SIGHASH_ALL in this<br />
// case)<br />
data_chunk signature{0x30, 0x44, 0x02, 0x20, 0x4e, 0x45, 0xe1, 0x69, 0x32, 0xb8, 0xaf, 0x51, 0x49, 0x61, 0xa1, 0xd3, 0xa1, 0xa2, 0x5f, 0xdf, 0x3f, 0x4f, 0x77, 0x32, 0xe9, 0xd6, 0x24, 0xc6, 0xc6, 0x15, 0x48, 0xab, 0x5f, 0xb8, 0xcd, 0x41, 0x02, 0x20, 0x18, 0x15, 0x22, 0xec, 0x8e, 0xca, 0x07, 0xde, 0x48, 0x60, 0xa4, 0xac, 0xdd, 0x12, 0x90, 0x9d, 0x83, 0x1c, 0xc5, 0x6c, 0xbb, 0xac, 0x46, 0x22, 0x08, 0x22, 0x21, 0xa8, 0x76, 0x8d, 0x1d, 0x09};<br />
BITCOIN_ASSERT(signature.size() == 70);<br />
<br />
elliptic_curve_key key;<br />
if (!key.set_public_key(pubkey))<br />
{<br />
log_fatal() << "unable to set EC public key";<br />
return -1;<br />
}<br />
<br />
log_info() << "checksig returns: " << (key.verify(tx_hash, signature) ? "true" : "false");<br />
return 0;<br />
}<br />
<br />
</source><br />
<br />
==References==<br />
<references/><br />
<br />
[[Category:Technical]]<br />
[[Category:Developer]]</div>
Smtp
https://en.bitcoin.it/w/index.php?title=OP_CHECKSIG&diff=34861
OP CHECKSIG
2013-01-09T17:51:13Z
<p>Smtp: /* How it works */</p>
<hr />
<div>OP_CHECKSIG is [[Script|script]] opcode used to verify that the signature for a tx input is valid. OP_CHECKSIG expects two values to be on the stack, these are, in order of stack depth, the public key and the signature of the script. These two values are normally obtained by running the scriptSig script of the transaction input we are attempting to validate. After the scriptSig script is run the script is deleted but the stack is left as is, and then then scriptPubKey script from the previous transaction output that is now being spent is run, generally concluding in an OP_CHECKSIG. <br />
<br />
The standard scriptPubKey checks that the public key (actually a hash of) is a particular value, and that OP_CHECKSIG passes.<br />
<br />
For normal transaction inputs if the creator of the current transaction can successfully create a ScriptSig signature that uses the right public key for the ScriptPubKey of the transaction output they are attempting to spend, that transaction input is considered valid. <br />
<br />
== Parameters ==<br />
<br />
In addition to the script code itself and the stack parameters, to operate OP_CHECKSIG needs to know the current transaction, the index of current transaction input, and sometimes the current hashtype (discussed later).<br />
<br />
== How it works ==<br />
Firstly always this (the default) procedure is applied:<br />
[[File:Bitcoin_OpCheckSig_InDetail.png|thumb|right|Signature verification process of the default procedure]]<br />
# the public key and the signature are popped from the stack, in that order. If the hash-type value is 0, then it is replaced by the last_byte of the signature. Then the last byte of the signature is always deleted.<br />
# A new subscript is created from the instruction from the most recently parsed OP_CODESEPARATOR (last one in script) to the end of the script. If there is no OP_CODESEPARATOR the entire script becomes the subscript (hereby referred to as subScript)<br />
# The sig is deleted from subScript.<br />
# All OP_CODESEPARATORS are removed from subScript<br />
# The hashtype is removed from the last byte of the sig and stored<br />
# A copy is made of the current transaction (hereby referred to txCopy)<br />
# The scripts for all transaction inputs in txCopy are set to empty scripts (exactly 1 byte 0x00)<br />
# The script for the current transaction input in txCopy is set to subScript (lead in by its length as a var-integer encoded!)<br />
<br />
Now depending on the hashtype various things can happen to txCopy, these will be discussed individually<br />
<br />
<br />
'''Hashtype Values (from script.h):'''<br />
{|class="wikitable"<br />
! Name !! Value<br />
|-<br />
| SIGHASH_ALL || 0x00000001<br />
|-<br />
| SIGHASH_NONE || 0x00000002<br />
|-<br />
| SIGHASH_SINGLE || 0x00000003<br />
|-<br />
| SIGHASH_ANYONECANPAY || 0x00000080<br />
|}<br />
<br />
<ol><br />
<li> If Hashtype = SIGHASH_NONE then apply the SIGHASH_NONE-procedure<br />
<li> If Hashtype = SIGHASH_SINGLE then apply the SIGHASH_SINGLE-procedure<br />
<li> If Hashtype & SIGHASH_ANYONECANPAY then apply the SIGHASH_ANYONECANPAY-procedure<br />
</ol><br />
Hence, Hashtype SIGHASH_ANYONECANPAY may be applied also after any other hashtype-procedure<ref>[http://sourceforge.net/projects/bitcoin/files/Bitcoin/bitcoin-0.7.1/bitcoin-0.7.1-linux.tar.gz file src/src/script.cpp in bitcoin-0.7.1]</ref>.<br />
<br />
=== Hashtype SIGHASH_ALL (default) ===<br />
<br />
No special further handling occurs in the default case. Think of this as "sign '''all''' of the outputs." Which is already done by the default procedure.<br />
<br />
=== Procedure for Hashtype SIGHASH_NONE ===<br />
<br />
# The output of txCopy is set to a vector of zero size.<br />
# All other inputs aside from the current input in txCopy have their nSequence index set to zero<br />
<br />
Think of this as "sign '''none''' of the outputs-- I don't care where the bitcoins go."<br />
<br />
=== Procedure for Hashtype SIGHASH_SINGLE ===<br />
<br />
# The output of txCopy is resized to the size of the current input index+1<br />
# All other txCopy outputs aside from the output that is the same as the current input index are set to a blank script and a value of (long) -1;<br />
# All other txCopy inputs aside from the current input are set to have an nSequence index of zero<br />
<br />
Think of this as "sign '''one''' of the outputs-- I don't care where the other outputs go."<br />
<br />
=== Procedure for Hashtype SIGHASH_ANYONECANPAY ===<br />
<br />
# The txCopy input vector is resized to a length of one<br />
# The current input is set as the first and only member of this vector<br />
<br />
Think of this as "Let other people add inputs to this transaction, I don't care where the rest of the bitcoins come from."<br />
<br />
== Final signature ==<br />
<br />
An array of bytes is constructed from the serialized txCopy + four bytes for the hash type. This array is sha256 hashed twice, then the public key is used to to check the supplied signature against the hash. <br />
<br />
== Return values ==<br />
<br />
OP_CHECKSIG will push true to the stack if the check passed, false otherwise.<br />
OP_CHECKSIG_VERIFY leaves nothing on the stack but will cause the script eval to fail immediately if the check does not pass.<br />
<br />
== Code samples and raw dumps ==<br />
<br />
Taking the first transaction in Bitcoin which is in block number 170, we would get after serialising the transaction but before we hash+sign (or verify) it:<br />
<br />
* http://blockexplorer.com/block/00000000d1145790a8694403d4063f323d499e655c83426834d4ce2f8dd4a2ee<br />
* http://blockexplorer.com/tx/f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16<br />
<br />
See also [https://gitorious.org/libbitcoin/libbitcoin libbitcoin] for code samples.<br />
<br />
<pre><br />
01 00 00 00 version<br />
01 number of inputs (var_uint)<br />
<br />
input 0:<br />
c9 97 a5 e5 6e 10 41 02 input address hash<br />
fa 20 9c 6a 85 2d d9 06 <br />
60 a2 0b 2d 9c 35 24 23 <br />
ed ce 25 85 7f cd 37 04<br />
00 00 00 00 input index<br />
<br />
48 size of script (var_uint)<br />
47 push 71 bytes to stack<br />
30 44 02 20 4e 45 e1 69<br />
32 b8 af 51 49 61 a1 d3<br />
a1 a2 5f df 3f 4f 77 32<br />
e9 d6 24 c6 c6 15 48 ab<br />
5f b8 cd 41 02 20 18 15<br />
22 ec 8e ca 07 de 48 60<br />
a4 ac dd 12 90 9d 83 1c<br />
c5 6c bb ac 46 22 08 22<br />
21 a8 76 8d 1d 09 01<br />
ff ff ff ff sequence<br />
<br />
02 number of outputs (var_uint)<br />
<br />
output 0:<br />
00 ca 9a 3b 00 00 00 00 amount = 10.00000000<br />
43 size of script (var_uint)<br />
script for output 0:<br />
41 push 65 bytes to stack<br />
04 ae 1a 62 fe 09 c5 f5 <br />
1b 13 90 5f 07 f0 6b 99 <br />
a2 f7 15 9b 22 25 f3 74 <br />
cd 37 8d 71 30 2f a2 84 <br />
14 e7 aa b3 73 97 f5 54 <br />
a7 df 5f 14 2c 21 c1 b7 <br />
30 3b 8a 06 26 f1 ba de <br />
d5 c7 2a 70 4f 7e 6c d8 <br />
4c <br />
ac OP_CHECKSIG<br />
<br />
output 1:<br />
00 28 6b ee 00 00 00 00 amount = 40.00000000<br />
43 size of script (var_uint)<br />
script for output 1:<br />
41 push 65 bytes to stack<br />
04 11 db 93 e1 dc db 8a <br />
01 6b 49 84 0f 8c 53 bc <br />
1e b6 8a 38 2e 97 b1 48 <br />
2e ca d7 b1 48 a6 90 9a<br />
5c b2 e0 ea dd fb 84 cc <br />
f9 74 44 64 f8 2e 16 0b <br />
fa 9b 8b 64 f9 d4 c0 3f <br />
99 9b 86 43 f6 56 b4 12 <br />
a3 <br />
ac OP_CHECKSIG<br />
<br />
00 00 00 00 locktime<br />
01 00 00 00 hash_code_type (added on)<br />
<br />
result =<br />
01 00 00 00 01 c9 97 a5 e5 6e 10 41 02 fa 20 9c 6a 85 2d d9 06 60 a2 0b 2d 9c 35 <br />
24 23 ed ce 25 85 7f cd 37 04 00 00 00 00 43 41 04 11 db 93 e1 dc db 8a 01 6b 49 <br />
84 0f 8c 53 bc 1e b6 8a 38 2e 97 b1 48 2e ca d7 b1 48 a6 90 9a 5c b2 e0 ea dd fb <br />
84 cc f9 74 44 64 f8 2e 16 0b fa 9b 8b 64 f9 d4 c0 3f 99 9b 86 43 f6 56 b4 12 a3 <br />
ac ff ff ff ff 02 00 ca 9a 3b 00 00 00 00 43 41 04 ae 1a 62 fe 09 c5 f5 1b 13 90 <br />
5f 07 f0 6b 99 a2 f7 15 9b 22 25 f3 74 cd 37 8d 71 30 2f a2 84 14 e7 aa b3 73 97 <br />
f5 54 a7 df 5f 14 2c 21 c1 b7 30 3b 8a 06 26 f1 ba de d5 c7 2a 70 4f 7e 6c d8 4c <br />
ac 00 28 6b ee 00 00 00 00 43 41 04 11 db 93 e1 dc db 8a 01 6b 49 84 0f 8c 53 bc <br />
1e b6 8a 38 2e 97 b1 48 2e ca d7 b1 48 a6 90 9a 5c b2 e0 ea dd fb 84 cc f9 74 44 <br />
64 f8 2e 16 0b fa 9b 8b 64 f9 d4 c0 3f 99 9b 86 43 f6 56 b4 12 a3 ac 00 00 00 00 <br />
01 00 00 00 <br />
</pre><br />
<br />
To understand where that raw dump has come from, it may be useful to examine tests/ec-key.cpp in [https://gitorious.org/libbitcoin/libbitcoin libbitcoin],<br />
<br />
[https://gitorious.org/libbitcoin/libbitcoin libbitcoin] has a unit test under tests/ec-key.cpp (make ec-key && ./bin/tests/ec-key). There is also a working OP_CHECKSIG implementation in src/script.cpp under script::op_checksig(). See also the unit test: tests/script-test.cpp<br />
<br />
<source lang="cpp"><br />
#include <iostream><br />
#include <iomanip><br />
#include <bitcoin/util/serializer.hpp><br />
#include <bitcoin/util/elliptic_curve_key.hpp><br />
#include <bitcoin/util/sha256.hpp><br />
#include <bitcoin/util/assert.hpp><br />
#include <bitcoin/util/logger.hpp><br />
#include <bitcoin/types.hpp><br />
#include <openssl/ecdsa.h><br />
#include <openssl/obj_mac.h><br />
using libbitcoin::elliptic_curve_key;<br />
using libbitcoin::serializer;<br />
using libbitcoin::hash_digest;<br />
using libbitcoin::data_chunk;<br />
using libbitcoin::log_info;<br />
using libbitcoin::log_fatal;<br />
<br />
int main()<br />
{<br />
serializer ss;<br />
// blk number 170, tx 1, input 0<br />
// version = 1<br />
ss.write_4_bytes(1);<br />
// 1 inputs<br />
ss.write_var_uint(1);<br />
<br />
// input 0<br />
// prevout hash<br />
ss.write_hash(hash_digest{0x04, 0x37, 0xcd, 0x7f, 0x85, 0x25, 0xce, 0xed, 0x23, 0x24, 0x35, 0x9c, 0x2d, 0x0b, 0xa2, 0x60, 0x06, 0xd9, 0x2d, 0x85, 0x6a, 0x9c, 0x20, 0xfa, 0x02, 0x41, 0x10, 0x6e, 0xe5, 0xa5, 0x97, 0xc9});<br />
// prevout index <br />
ss.write_4_bytes(0);<br />
<br />
// input script after running OP_CHECKSIG for this tx is a single<br />
// OP_CHECKSIG opcode<br />
data_chunk raw_data;<br />
raw_data = {0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3};<br />
data_chunk raw_script;<br />
raw_script = data_chunk();<br />
raw_script.push_back(raw_data.size());<br />
libbitcoin::extend_data(raw_script, raw_data);<br />
raw_script.push_back(172);<br />
ss.write_var_uint(raw_script.size());<br />
ss.write_data(raw_script);<br />
// sequence<br />
ss.write_4_bytes(0xffffffff);<br />
<br />
// 2 outputs for this tx<br />
ss.write_var_uint(2);<br />
<br />
// output 0<br />
ss.write_8_bytes(1000000000);<br />
// script for output 0<br />
raw_data = {0x04, 0xae, 0x1a, 0x62, 0xfe, 0x09, 0xc5, 0xf5, 0x1b, 0x13, 0x90, 0x5f, 0x07, 0xf0, 0x6b, 0x99, 0xa2, 0xf7, 0x15, 0x9b, 0x22, 0x25, 0xf3, 0x74, 0xcd, 0x37, 0x8d, 0x71, 0x30, 0x2f, 0xa2, 0x84, 0x14, 0xe7, 0xaa, 0xb3, 0x73, 0x97, 0xf5, 0x54, 0xa7, 0xdf, 0x5f, 0x14, 0x2c, 0x21, 0xc1, 0xb7, 0x30, 0x3b, 0x8a, 0x06, 0x26, 0xf1, 0xba, 0xde, 0xd5, 0xc7, 0x2a, 0x70, 0x4f, 0x7e, 0x6c, 0xd8, 0x4c};<br />
// when data < 75, we can just write it's length as a single byte ('special'<br />
// opcodes)<br />
raw_script = data_chunk();<br />
raw_script.push_back(raw_data.size());<br />
libbitcoin::extend_data(raw_script, raw_data);<br />
// OP_CHECKSIG<br />
raw_script.push_back(172);<br />
// now actually write the script<br />
ss.write_var_uint(raw_script.size());<br />
ss.write_data(raw_script);<br />
<br />
// output 0<br />
ss.write_8_bytes(4000000000);<br />
// script for output 0<br />
raw_data = {0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3};<br />
// when data < 75, we can just write it's length as a single byte ('special'<br />
raw_script.push_back(raw_data.size());<br />
libbitcoin::extend_data(raw_script, raw_data);<br />
// OP_CHECKSIG<br />
raw_script.push_back(172);<br />
// now actually write the script<br />
ss.write_var_uint(raw_script.size());<br />
ss.write_data(raw_script);<br />
<br />
// End of 2 outputs<br />
<br />
// locktime<br />
ss.write_4_bytes(0);<br />
<br />
// write hash_type_code<br />
ss.write_4_bytes(1);<br />
<br />
// Dump hex to screen<br />
log_info() << "hashing:";<br />
{<br />
auto log_obj = log_info();<br />
log_obj << std::hex;<br />
for (int val: ss.get_data())<br />
log_obj << std::setfill('0') << std::setw(2) << val << ' ';<br />
}<br />
log_info();<br />
<br />
data_chunk raw_tx = {0x01, 0x00, 0x00, 0x00, 0x01, 0xc9, 0x97, 0xa5, 0xe5, 0x6e, 0x10, 0x41, 0x02, 0xfa, 0x20, 0x9c, 0x6a, 0x85, 0x2d, 0xd9, 0x06, 0x60, 0xa2, 0x0b, 0x2d, 0x9c, 0x35, 0x24, 0x23, 0xed, 0xce, 0x25, 0x85, 0x7f, 0xcd, 0x37, 0x04, 0x00, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3, 0xac, 0xff, 0xff, 0xff, 0xff, 0x02, 0x00, 0xca, 0x9a, 0x3b, 0x00, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, 0xae, 0x1a, 0x62, 0xfe, 0x09, 0xc5, 0xf5, 0x1b, 0x13, 0x90, 0x5f, 0x07, 0xf0, 0x6b, 0x99, 0xa2, 0xf7, 0x15, 0x9b, 0x22, 0x25, 0xf3, 0x74, 0xcd, 0x37, 0x8d, 0x71, 0x30, 0x2f, 0xa2, 0x84, 0x14, 0xe7, 0xaa, 0xb3, 0x73, 0x97, 0xf5, 0x54, 0xa7, 0xdf, 0x5f, 0x14, 0x2c, 0x21, 0xc1, 0xb7, 0x30, 0x3b, 0x8a, 0x06, 0x26, 0xf1, 0xba, 0xde, 0xd5, 0xc7, 0x2a, 0x70, 0x4f, 0x7e, 0x6c, 0xd8, 0x4c, 0xac, 0x00, 0x28, 0x6b, 0xee, 0x00, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3, 0xac, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00};<br />
BITCOIN_ASSERT(raw_tx == ss.get_data());<br />
<br />
hash_digest tx_hash = libbitcoin::generate_sha256_hash(ss.get_data());<br />
<br />
data_chunk pubkey{0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3};<br />
// Leave out last byte since that's the hash_type_code (SIGHASH_ALL in this<br />
// case)<br />
data_chunk signature{0x30, 0x44, 0x02, 0x20, 0x4e, 0x45, 0xe1, 0x69, 0x32, 0xb8, 0xaf, 0x51, 0x49, 0x61, 0xa1, 0xd3, 0xa1, 0xa2, 0x5f, 0xdf, 0x3f, 0x4f, 0x77, 0x32, 0xe9, 0xd6, 0x24, 0xc6, 0xc6, 0x15, 0x48, 0xab, 0x5f, 0xb8, 0xcd, 0x41, 0x02, 0x20, 0x18, 0x15, 0x22, 0xec, 0x8e, 0xca, 0x07, 0xde, 0x48, 0x60, 0xa4, 0xac, 0xdd, 0x12, 0x90, 0x9d, 0x83, 0x1c, 0xc5, 0x6c, 0xbb, 0xac, 0x46, 0x22, 0x08, 0x22, 0x21, 0xa8, 0x76, 0x8d, 0x1d, 0x09};<br />
BITCOIN_ASSERT(signature.size() == 70);<br />
<br />
elliptic_curve_key key;<br />
if (!key.set_public_key(pubkey))<br />
{<br />
log_fatal() << "unable to set EC public key";<br />
return -1;<br />
}<br />
<br />
log_info() << "checksig returns: " << (key.verify(tx_hash, signature) ? "true" : "false");<br />
return 0;<br />
}<br />
<br />
</source><br />
<br />
==References==<br />
<references/><br />
<br />
[[Category:Technical]]<br />
[[Category:Developer]]</div>
Smtp
https://en.bitcoin.it/w/index.php?title=OP_CHECKSIG&diff=34860
OP CHECKSIG
2013-01-09T17:49:12Z
<p>Smtp: /* Procedure for Hashtype SIGHASH_ANYONECANPAY */</p>
<hr />
<div>OP_CHECKSIG is [[Script|script]] opcode used to verify that the signature for a tx input is valid. OP_CHECKSIG expects two values to be on the stack, these are, in order of stack depth, the public key and the signature of the script. These two values are normally obtained by running the scriptSig script of the transaction input we are attempting to validate. After the scriptSig script is run the script is deleted but the stack is left as is, and then then scriptPubKey script from the previous transaction output that is now being spent is run, generally concluding in an OP_CHECKSIG. <br />
<br />
The standard scriptPubKey checks that the public key (actually a hash of) is a particular value, and that OP_CHECKSIG passes.<br />
<br />
For normal transaction inputs if the creator of the current transaction can successfully create a ScriptSig signature that uses the right public key for the ScriptPubKey of the transaction output they are attempting to spend, that transaction input is considered valid. <br />
<br />
== Parameters ==<br />
<br />
In addition to the script code itself and the stack parameters, to operate OP_CHECKSIG needs to know the current transaction, the index of current transaction input, and sometimes the current hashtype (discussed later).<br />
<br />
== How it works ==<br />
Firstly always this (the default) procedure is applied:<br />
[[File:Bitcoin_OpCheckSig_InDetail.png|thumb|right|Signature verification process of the default procedure]]<br />
# the public key and the signature are popped from the stack, in that order. If the hash-type value is 0, then it is replaced by the last_byte of the signature. Then the last byte of the signature is always deleted.<br />
# A new subscript is created from the instruction from the most recently parsed OP_CODESEPARATOR (last one in script) to the end of the script. If there is no OP_CODESEPARATOR the entire script becomes the subscript (hereby referred to as subScript)<br />
# The sig is deleted from subScript.<br />
# All OP_CODESEPARATORS are removed from subScript<br />
# The hashtype is removed from the last byte of the sig and stored<br />
# A copy is made of the current transaction (hereby referred to txCopy)<br />
# The scripts for all transaction inputs in txCopy are set to empty scripts (exactly 1 byte 0x00)<br />
# The script for the current transaction input in txCopy is set to subScript (lead in by its length as a var-integer encoded!)<br />
<br />
Now depending on the hashtype various things can happen to txCopy, these will be discussed individually<br />
<br />
<br />
'''Hashtype Values (from script.h):'''<br />
{|class="wikitable"<br />
! Name !! Value<br />
|-<br />
| SIGHASH_ALL || 0x00000001<br />
|-<br />
| SIGHASH_NONE || 0x00000002<br />
|-<br />
| SIGHASH_SINGLE || 0x00000003<br />
|-<br />
| SIGHASH_ANYONECANPAY || 0x00000080<br />
|}<br />
<br />
<ol><br />
<li> If Hashtype = SIGHASH_NONE then apply the SIGHASH_NONE-procedure<br />
<li> If Hashtype = SIGHASH_SINGLE then apply the SIGHASH_SINGLE-procedure<br />
<li> If Hashtype & SIGHASH_ANYONECANPAY then apply the SIGHASH_ANYONECANPAY-procedure<br />
</ol><br />
Hence, Hashtype ANYONECANPAY may be applied also to one of the other two hash_type procedures<ref>[http://sourceforge.net/projects/bitcoin/files/Bitcoin/bitcoin-0.7.1/bitcoin-0.7.1-linux.tar.gz file src/src/script.cpp in bitcoin-0.7.1]</ref>.<br />
<br />
=== Hashtype SIGHASH_ALL (default) ===<br />
<br />
No special further handling occurs in the default case. Think of this as "sign '''all''' of the outputs." Which is already done by the default procedure.<br />
<br />
=== Procedure for Hashtype SIGHASH_NONE ===<br />
<br />
# The output of txCopy is set to a vector of zero size.<br />
# All other inputs aside from the current input in txCopy have their nSequence index set to zero<br />
<br />
Think of this as "sign '''none''' of the outputs-- I don't care where the bitcoins go."<br />
<br />
=== Procedure for Hashtype SIGHASH_SINGLE ===<br />
<br />
# The output of txCopy is resized to the size of the current input index+1<br />
# All other txCopy outputs aside from the output that is the same as the current input index are set to a blank script and a value of (long) -1;<br />
# All other txCopy inputs aside from the current input are set to have an nSequence index of zero<br />
<br />
Think of this as "sign '''one''' of the outputs-- I don't care where the other outputs go."<br />
<br />
=== Procedure for Hashtype SIGHASH_ANYONECANPAY ===<br />
<br />
# The txCopy input vector is resized to a length of one<br />
# The current input is set as the first and only member of this vector<br />
<br />
Think of this as "Let other people add inputs to this transaction, I don't care where the rest of the bitcoins come from."<br />
<br />
== Final signature ==<br />
<br />
An array of bytes is constructed from the serialized txCopy + four bytes for the hash type. This array is sha256 hashed twice, then the public key is used to to check the supplied signature against the hash. <br />
<br />
== Return values ==<br />
<br />
OP_CHECKSIG will push true to the stack if the check passed, false otherwise.<br />
OP_CHECKSIG_VERIFY leaves nothing on the stack but will cause the script eval to fail immediately if the check does not pass.<br />
<br />
== Code samples and raw dumps ==<br />
<br />
Taking the first transaction in Bitcoin which is in block number 170, we would get after serialising the transaction but before we hash+sign (or verify) it:<br />
<br />
* http://blockexplorer.com/block/00000000d1145790a8694403d4063f323d499e655c83426834d4ce2f8dd4a2ee<br />
* http://blockexplorer.com/tx/f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16<br />
<br />
See also [https://gitorious.org/libbitcoin/libbitcoin libbitcoin] for code samples.<br />
<br />
<pre><br />
01 00 00 00 version<br />
01 number of inputs (var_uint)<br />
<br />
input 0:<br />
c9 97 a5 e5 6e 10 41 02 input address hash<br />
fa 20 9c 6a 85 2d d9 06 <br />
60 a2 0b 2d 9c 35 24 23 <br />
ed ce 25 85 7f cd 37 04<br />
00 00 00 00 input index<br />
<br />
48 size of script (var_uint)<br />
47 push 71 bytes to stack<br />
30 44 02 20 4e 45 e1 69<br />
32 b8 af 51 49 61 a1 d3<br />
a1 a2 5f df 3f 4f 77 32<br />
e9 d6 24 c6 c6 15 48 ab<br />
5f b8 cd 41 02 20 18 15<br />
22 ec 8e ca 07 de 48 60<br />
a4 ac dd 12 90 9d 83 1c<br />
c5 6c bb ac 46 22 08 22<br />
21 a8 76 8d 1d 09 01<br />
ff ff ff ff sequence<br />
<br />
02 number of outputs (var_uint)<br />
<br />
output 0:<br />
00 ca 9a 3b 00 00 00 00 amount = 10.00000000<br />
43 size of script (var_uint)<br />
script for output 0:<br />
41 push 65 bytes to stack<br />
04 ae 1a 62 fe 09 c5 f5 <br />
1b 13 90 5f 07 f0 6b 99 <br />
a2 f7 15 9b 22 25 f3 74 <br />
cd 37 8d 71 30 2f a2 84 <br />
14 e7 aa b3 73 97 f5 54 <br />
a7 df 5f 14 2c 21 c1 b7 <br />
30 3b 8a 06 26 f1 ba de <br />
d5 c7 2a 70 4f 7e 6c d8 <br />
4c <br />
ac OP_CHECKSIG<br />
<br />
output 1:<br />
00 28 6b ee 00 00 00 00 amount = 40.00000000<br />
43 size of script (var_uint)<br />
script for output 1:<br />
41 push 65 bytes to stack<br />
04 11 db 93 e1 dc db 8a <br />
01 6b 49 84 0f 8c 53 bc <br />
1e b6 8a 38 2e 97 b1 48 <br />
2e ca d7 b1 48 a6 90 9a<br />
5c b2 e0 ea dd fb 84 cc <br />
f9 74 44 64 f8 2e 16 0b <br />
fa 9b 8b 64 f9 d4 c0 3f <br />
99 9b 86 43 f6 56 b4 12 <br />
a3 <br />
ac OP_CHECKSIG<br />
<br />
00 00 00 00 locktime<br />
01 00 00 00 hash_code_type (added on)<br />
<br />
result =<br />
01 00 00 00 01 c9 97 a5 e5 6e 10 41 02 fa 20 9c 6a 85 2d d9 06 60 a2 0b 2d 9c 35 <br />
24 23 ed ce 25 85 7f cd 37 04 00 00 00 00 43 41 04 11 db 93 e1 dc db 8a 01 6b 49 <br />
84 0f 8c 53 bc 1e b6 8a 38 2e 97 b1 48 2e ca d7 b1 48 a6 90 9a 5c b2 e0 ea dd fb <br />
84 cc f9 74 44 64 f8 2e 16 0b fa 9b 8b 64 f9 d4 c0 3f 99 9b 86 43 f6 56 b4 12 a3 <br />
ac ff ff ff ff 02 00 ca 9a 3b 00 00 00 00 43 41 04 ae 1a 62 fe 09 c5 f5 1b 13 90 <br />
5f 07 f0 6b 99 a2 f7 15 9b 22 25 f3 74 cd 37 8d 71 30 2f a2 84 14 e7 aa b3 73 97 <br />
f5 54 a7 df 5f 14 2c 21 c1 b7 30 3b 8a 06 26 f1 ba de d5 c7 2a 70 4f 7e 6c d8 4c <br />
ac 00 28 6b ee 00 00 00 00 43 41 04 11 db 93 e1 dc db 8a 01 6b 49 84 0f 8c 53 bc <br />
1e b6 8a 38 2e 97 b1 48 2e ca d7 b1 48 a6 90 9a 5c b2 e0 ea dd fb 84 cc f9 74 44 <br />
64 f8 2e 16 0b fa 9b 8b 64 f9 d4 c0 3f 99 9b 86 43 f6 56 b4 12 a3 ac 00 00 00 00 <br />
01 00 00 00 <br />
</pre><br />
<br />
To understand where that raw dump has come from, it may be useful to examine tests/ec-key.cpp in [https://gitorious.org/libbitcoin/libbitcoin libbitcoin],<br />
<br />
[https://gitorious.org/libbitcoin/libbitcoin libbitcoin] has a unit test under tests/ec-key.cpp (make ec-key && ./bin/tests/ec-key). There is also a working OP_CHECKSIG implementation in src/script.cpp under script::op_checksig(). See also the unit test: tests/script-test.cpp<br />
<br />
<source lang="cpp"><br />
#include <iostream><br />
#include <iomanip><br />
#include <bitcoin/util/serializer.hpp><br />
#include <bitcoin/util/elliptic_curve_key.hpp><br />
#include <bitcoin/util/sha256.hpp><br />
#include <bitcoin/util/assert.hpp><br />
#include <bitcoin/util/logger.hpp><br />
#include <bitcoin/types.hpp><br />
#include <openssl/ecdsa.h><br />
#include <openssl/obj_mac.h><br />
using libbitcoin::elliptic_curve_key;<br />
using libbitcoin::serializer;<br />
using libbitcoin::hash_digest;<br />
using libbitcoin::data_chunk;<br />
using libbitcoin::log_info;<br />
using libbitcoin::log_fatal;<br />
<br />
int main()<br />
{<br />
serializer ss;<br />
// blk number 170, tx 1, input 0<br />
// version = 1<br />
ss.write_4_bytes(1);<br />
// 1 inputs<br />
ss.write_var_uint(1);<br />
<br />
// input 0<br />
// prevout hash<br />
ss.write_hash(hash_digest{0x04, 0x37, 0xcd, 0x7f, 0x85, 0x25, 0xce, 0xed, 0x23, 0x24, 0x35, 0x9c, 0x2d, 0x0b, 0xa2, 0x60, 0x06, 0xd9, 0x2d, 0x85, 0x6a, 0x9c, 0x20, 0xfa, 0x02, 0x41, 0x10, 0x6e, 0xe5, 0xa5, 0x97, 0xc9});<br />
// prevout index <br />
ss.write_4_bytes(0);<br />
<br />
// input script after running OP_CHECKSIG for this tx is a single<br />
// OP_CHECKSIG opcode<br />
data_chunk raw_data;<br />
raw_data = {0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3};<br />
data_chunk raw_script;<br />
raw_script = data_chunk();<br />
raw_script.push_back(raw_data.size());<br />
libbitcoin::extend_data(raw_script, raw_data);<br />
raw_script.push_back(172);<br />
ss.write_var_uint(raw_script.size());<br />
ss.write_data(raw_script);<br />
// sequence<br />
ss.write_4_bytes(0xffffffff);<br />
<br />
// 2 outputs for this tx<br />
ss.write_var_uint(2);<br />
<br />
// output 0<br />
ss.write_8_bytes(1000000000);<br />
// script for output 0<br />
raw_data = {0x04, 0xae, 0x1a, 0x62, 0xfe, 0x09, 0xc5, 0xf5, 0x1b, 0x13, 0x90, 0x5f, 0x07, 0xf0, 0x6b, 0x99, 0xa2, 0xf7, 0x15, 0x9b, 0x22, 0x25, 0xf3, 0x74, 0xcd, 0x37, 0x8d, 0x71, 0x30, 0x2f, 0xa2, 0x84, 0x14, 0xe7, 0xaa, 0xb3, 0x73, 0x97, 0xf5, 0x54, 0xa7, 0xdf, 0x5f, 0x14, 0x2c, 0x21, 0xc1, 0xb7, 0x30, 0x3b, 0x8a, 0x06, 0x26, 0xf1, 0xba, 0xde, 0xd5, 0xc7, 0x2a, 0x70, 0x4f, 0x7e, 0x6c, 0xd8, 0x4c};<br />
// when data < 75, we can just write it's length as a single byte ('special'<br />
// opcodes)<br />
raw_script = data_chunk();<br />
raw_script.push_back(raw_data.size());<br />
libbitcoin::extend_data(raw_script, raw_data);<br />
// OP_CHECKSIG<br />
raw_script.push_back(172);<br />
// now actually write the script<br />
ss.write_var_uint(raw_script.size());<br />
ss.write_data(raw_script);<br />
<br />
// output 0<br />
ss.write_8_bytes(4000000000);<br />
// script for output 0<br />
raw_data = {0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3};<br />
// when data < 75, we can just write it's length as a single byte ('special'<br />
raw_script.push_back(raw_data.size());<br />
libbitcoin::extend_data(raw_script, raw_data);<br />
// OP_CHECKSIG<br />
raw_script.push_back(172);<br />
// now actually write the script<br />
ss.write_var_uint(raw_script.size());<br />
ss.write_data(raw_script);<br />
<br />
// End of 2 outputs<br />
<br />
// locktime<br />
ss.write_4_bytes(0);<br />
<br />
// write hash_type_code<br />
ss.write_4_bytes(1);<br />
<br />
// Dump hex to screen<br />
log_info() << "hashing:";<br />
{<br />
auto log_obj = log_info();<br />
log_obj << std::hex;<br />
for (int val: ss.get_data())<br />
log_obj << std::setfill('0') << std::setw(2) << val << ' ';<br />
}<br />
log_info();<br />
<br />
data_chunk raw_tx = {0x01, 0x00, 0x00, 0x00, 0x01, 0xc9, 0x97, 0xa5, 0xe5, 0x6e, 0x10, 0x41, 0x02, 0xfa, 0x20, 0x9c, 0x6a, 0x85, 0x2d, 0xd9, 0x06, 0x60, 0xa2, 0x0b, 0x2d, 0x9c, 0x35, 0x24, 0x23, 0xed, 0xce, 0x25, 0x85, 0x7f, 0xcd, 0x37, 0x04, 0x00, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3, 0xac, 0xff, 0xff, 0xff, 0xff, 0x02, 0x00, 0xca, 0x9a, 0x3b, 0x00, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, 0xae, 0x1a, 0x62, 0xfe, 0x09, 0xc5, 0xf5, 0x1b, 0x13, 0x90, 0x5f, 0x07, 0xf0, 0x6b, 0x99, 0xa2, 0xf7, 0x15, 0x9b, 0x22, 0x25, 0xf3, 0x74, 0xcd, 0x37, 0x8d, 0x71, 0x30, 0x2f, 0xa2, 0x84, 0x14, 0xe7, 0xaa, 0xb3, 0x73, 0x97, 0xf5, 0x54, 0xa7, 0xdf, 0x5f, 0x14, 0x2c, 0x21, 0xc1, 0xb7, 0x30, 0x3b, 0x8a, 0x06, 0x26, 0xf1, 0xba, 0xde, 0xd5, 0xc7, 0x2a, 0x70, 0x4f, 0x7e, 0x6c, 0xd8, 0x4c, 0xac, 0x00, 0x28, 0x6b, 0xee, 0x00, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3, 0xac, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00};<br />
BITCOIN_ASSERT(raw_tx == ss.get_data());<br />
<br />
hash_digest tx_hash = libbitcoin::generate_sha256_hash(ss.get_data());<br />
<br />
data_chunk pubkey{0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3};<br />
// Leave out last byte since that's the hash_type_code (SIGHASH_ALL in this<br />
// case)<br />
data_chunk signature{0x30, 0x44, 0x02, 0x20, 0x4e, 0x45, 0xe1, 0x69, 0x32, 0xb8, 0xaf, 0x51, 0x49, 0x61, 0xa1, 0xd3, 0xa1, 0xa2, 0x5f, 0xdf, 0x3f, 0x4f, 0x77, 0x32, 0xe9, 0xd6, 0x24, 0xc6, 0xc6, 0x15, 0x48, 0xab, 0x5f, 0xb8, 0xcd, 0x41, 0x02, 0x20, 0x18, 0x15, 0x22, 0xec, 0x8e, 0xca, 0x07, 0xde, 0x48, 0x60, 0xa4, 0xac, 0xdd, 0x12, 0x90, 0x9d, 0x83, 0x1c, 0xc5, 0x6c, 0xbb, 0xac, 0x46, 0x22, 0x08, 0x22, 0x21, 0xa8, 0x76, 0x8d, 0x1d, 0x09};<br />
BITCOIN_ASSERT(signature.size() == 70);<br />
<br />
elliptic_curve_key key;<br />
if (!key.set_public_key(pubkey))<br />
{<br />
log_fatal() << "unable to set EC public key";<br />
return -1;<br />
}<br />
<br />
log_info() << "checksig returns: " << (key.verify(tx_hash, signature) ? "true" : "false");<br />
return 0;<br />
}<br />
<br />
</source><br />
<br />
==References==<br />
<references/><br />
<br />
[[Category:Technical]]<br />
[[Category:Developer]]</div>
Smtp
https://en.bitcoin.it/w/index.php?title=Economic_majority&diff=34859
Economic majority
2013-01-09T17:40:21Z
<p>Smtp: </p>
<hr />
<div>The theory that the power to control the bitcoin protocol is held by those who hold bitcoins.<br />
<br />
As long as mining is conducted for economic gain, then any change adopted by the miners needs to be supported by the '''economic majority of the [[Mining|miners]]''' for it to be successfully implemented.<br />
<br />
While miners could adopt changes that are not welcomed by those holding bitcoins and start mining using the changes, their mined coins might not be accepted by users that refuse to adopt the changes. Thus those miners would then, in that instance, not gain economically from adopting the change. This scenario exists regardless of whether or not the miners adopting the change had 51% of the hashing strength.<br />
<br />
So the ability for a protocol change to be successfully implemented ultimately rests with those who accept bitcoins in exchange for value.<br />
<br />
Generally those will be the merchants. Just as a consumer has the ability to boycott a business if the consumer has a problem with how they operate, Bitcoin consumers have the ability to boycott merchants as well. Thus a Bitcoin merchant might not adopt a protocol change that would not be welcomed by its consumers.<br />
<br />
So by default, ultimately a protocol change has to be welcomed by those who mine bitcoins resp. generate new valid blocks which lengthen the most [[difficulty|difficult]] [[block chain]].<br />
<br />
Credit goes to Meni Rosenfield for first coining the term<ref>[http://bitcoin.stackexchange.com/questions/3945/how-could-the-bitcoin-protocol-be-changed-has-this-ever-occurred#comment4983_3948 How could the bitcoin protocol be changed? Has this ever occurred?]</ref>.<br />
<br />
==References==<br />
<references /></div>
Smtp
https://en.bitcoin.it/w/index.php?title=Economic_majority&diff=34858
Economic majority
2013-01-09T17:38:54Z
<p>Smtp: </p>
<hr />
<div>The theory that the power to control the bitcoin protocol is held by those who hold bitcoins.<br />
<br />
As long as mining is conducted for economic gain, then any change adopted by the miners needs to be supported by the '''economic majority of the [[Mining|miners]]''' for it to be successfully implemented.<br />
<br />
While miners could adopt changes that are not welcomed by those holding bitcoins and start mining using the changes, their mined coins might not be accepted by users that refuse to adopt the changes. Thus those miners would then, in that instance, not gain economically from adopting the change. This scenario exists regardless of whether or not the miners adopting the change had 51% of the hashing strength.<br />
<br />
So the ability for a protocol change to be successfully implemented ultimately rests with those who accept bitcoins in exchange for value.<br />
<br />
Generally those will be the merchants. Just as a consumer has the ability to boycott a business if the consumer has a problem with how they operate, Bitcoin consumers have the ability to boycott merchants as well. Thus a Bitcoin merchant might not adopt a protocol change that would not be welcomed by its consumers.<br />
<br />
So by default, ultimately a protocol change has to be welcomed by those who mine bitcoins resp. generate new valid blocks which lengthen the (main/most difficult) block chain.<br />
<br />
Credit goes to Meni Rosenfield for first coining the term<ref>[http://bitcoin.stackexchange.com/questions/3945/how-could-the-bitcoin-protocol-be-changed-has-this-ever-occurred#comment4983_3948 How could the bitcoin protocol be changed? Has this ever occurred?]</ref>.<br />
<br />
==References==<br />
<references /></div>
Smtp
https://en.bitcoin.it/w/index.php?title=Economic_majority&diff=34857
Economic majority
2013-01-09T17:34:35Z
<p>Smtp: </p>
<hr />
<div>The theory that the power to control the bitcoin protocol is held by those who hold bitcoins.<br />
<br />
As long as mining is conducted for economic gain, then any change adopted by the miners needs to be supported by the '''economic majority of the [[Mining|miners]]''' for it to be successfully implemented.<br />
<br />
While miners could adopt changes that are not welcomed by those holding bitcoins and start mining using the changes, their mined coins might not be accepted by users that refuse to adopt the changes. Thus those miners would then, in that instance, not gain economically from adopting the change. This scenario exists regardless of whether or not the miners adopting the change had 51% of the hashing strength.<br />
<br />
So the ability for a protocol change to be successfully implemented ultimately rests with those who accept bitcoins in exchange for value.<br />
<br />
Generally those will be the merchants. Just as a consumer has the ability to boycott a business if the consumer has a problem with how they operate, Bitcoin consumers have the ability to boycott merchants as well. Thus a Bitcoin merchant might not adopt a protocol change that would not be welcomed by its consumers.<br />
<br />
So by default, ultimately a protocol change has to be welcomed by those who hold bitcoins.<br />
<br />
Credit goes to Meni Rosenfield for first coining the term<ref>[http://bitcoin.stackexchange.com/questions/3945/how-could-the-bitcoin-protocol-be-changed-has-this-ever-occurred#comment4983_3948 How could the bitcoin protocol be changed? Has this ever occurred?]</ref>.<br />
<br />
==References==<br />
<references /></div>
Smtp
https://en.bitcoin.it/w/index.php?title=Economic_majority&diff=34856
Economic majority
2013-01-09T17:33:05Z
<p>Smtp: very importnat difference to theory!!</p>
<hr />
<div>The theory that the power to control the bitcoin protocol is held by those who hold bitcoins.<br />
<br />
As long as mining is conducted for economic gain, then any change adopted by the miners needs to be supported by the '''economic majority of the miners''' for it to be successfully implemented.<br />
<br />
While miners could adopt changes that are not welcomed by those holding bitcoins and start mining using the changes, their mined coins might not be accepted by users that refuse to adopt the changes. Thus those miners would then, in that instance, not gain economically from adopting the change. This scenario exists regardless of whether or not the miners adopting the change had 51% of the hashing strength.<br />
<br />
So the ability for a protocol change to be successfully implemented ultimately rests with those who accept bitcoins in exchange for value.<br />
<br />
Generally those will be the merchants. Just as a consumer has the ability to boycott a business if the consumer has a problem with how they operate, Bitcoin consumers have the ability to boycott merchants as well. Thus a Bitcoin merchant might not adopt a protocol change that would not be welcomed by its consumers.<br />
<br />
So by default, ultimately a protocol change has to be welcomed by those who hold bitcoins.<br />
<br />
Credit goes to Meni Rosenfield for first coining the term<ref>[http://bitcoin.stackexchange.com/questions/3945/how-could-the-bitcoin-protocol-be-changed-has-this-ever-occurred#comment4983_3948 How could the bitcoin protocol be changed? Has this ever occurred?]</ref>.<br />
<br />
==References==<br />
<references /></div>
Smtp
https://en.bitcoin.it/w/index.php?title=Script&diff=34855
Script
2013-01-09T17:07:45Z
<p>Smtp: /* Withdrawn and drafted opcodes */ I dislike red link color</p>
<hr />
<div>Bitcoin uses a scripting system for [[transactions]]. [[Wikipedia:FORTH|Forth]]-like, Script is simple, stack-based, and processed from left to right. It is purposefully not Turing-complete, with no loops.<br />
<br />
A script is essentially a list of instructions recorded with each transaction that describe how the next person wanting to spend the Bitcoins being transferred can gain access to them.<br />
<br />
Scripts are big-endian and their sequences of bytes is interpreted as a sequence of opcodes with operands. Only opcodes with byte values less than 0x4f have additional operands.<br />
<br />
== Scripts and Bitcoin transactions ==<br />
The script for a typical Bitcoin transfer to destination Bitcoin address D simply encumbers future spending of the bitcoins with two things: the spender must provide<br />
# a public key that, when hashed, yields destination address D embedded in the script, and<br />
# a signature to show evidence of the private key corresponding to the public key just provided.<br />
<br />
Scripting provides the flexibility to change the parameters of what's needed to spend transferred Bitcoins. For example, the scripting system could be used to require two private keys, or a combination of several, or even no keys at all.<br />
<br />
A transaction is valid if nothing in the combined script triggers failure and the top stack item exists and is true (non-zero). The party who originally ''stored'' the Bitcoins now being spent, dictates the script operations that will occur ''last'' in order to release them for use in another transaction. The party wanting to spend them must provide the input(s) to the previously recorded script that results in those operations occurring last leaving behind true (non-zero) on the stack.<br><br />
Only the very first transaction in each bitcoin block has no input script (the entry there is called "coinbase"), because the Bitcoins created with the block are created from hot air and not released by a previous recorded script.<br />
<br />
== Stack ==<br />
<br />
The stacks hold byte vectors (there is the (main) stack and an alternative stack). Byte vectors are interpreted as little-endian variable-length integers with the most significant bit determining the sign of the integer. Thus 0x81 represents -1. 0x80 is another representation of zero (so called negative 0). Byte vectors are interpreted as Booleans where False is represented by any representation of zero, and True is represented by any representation of non-zero.<br />
<br />
== Opcode overview ==<br />
<br />
For each opcode is given: its nemonic without the leading OP_, its hexadecimal byte value, the number of stack items needed (poped) during execution, a semicolon and the number of stack items which has been pushed (after execution). A * after the needed stack items indicates that further bytes from the script following the current opcode are needed. A # indicates that items on the alternative stack are poped/pushed. A @ indicates that further (global) data from the transaction is needed. A / indicates alternatives of a value. <br/><br />
Different colors indicate different semantic execution groups of opcodes:<br />
{| style="background:none; font-size:100%; padding:0; border-collapse:collapse; text-align:center; line-height:2em;" border="0" align="center" <br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | copy a fixed number of bytes but at most 75 onto stack<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | copy bytes onto stack which number is given by a 1, 2 or 4 byte value.<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | copy 1 specific byte onto stack<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | undefined opcode<br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | a pseudo-opcode, unassigned for scripts<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | NOP or opcode is part of a IF-flow-control construction<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00ff00;" | (stack conditionally) invalidation of the script this opcode is part of<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | stack item is moved between main stack and alternate stack<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | stack item(s) is/are moved, copied or deleted<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0;" | byte vectors are appended or divided or their size is determined<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff;" | byte vectors are interpreted bit-position-independently<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | byte vectors are interpreted and processed as signed integers<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | a hash value is computed or a signature checked<br />
|}<br />
<p><br />
===Opcode byte-matrix===<br />
The opcode value 0x00 with nemonic OP_FALSE is also named OP_0 and the opcode value 0x51 with nemonic OP_1 as also named OP_TRUE.<br />
{| style="background:none; font-size:100%; padding:0; border-collapse:collapse; text-align:center; line-height:2em;" border="0" align="center" <br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" |_FALSE<br/> 0x00 <br/> 0 ; 1(0) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x01<br/> 0 *; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x02<br/> 0 *; 1(2)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x03<br/> 0 *; 1(3)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x04<br/> 0 *; 1(4)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x04<br/> 0 *; 1(5)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x06<br/> 0 *; 1(6)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x07<br/> 0 *; 1(7)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x08<br/> 0 *; 1(8)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x09<br/> 0 *; 1(9)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0a<br/> 0 *; 1(10)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0b<br/> 0 *; 1(11)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0c<br/> 0 *; 1(12)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0d<br/> 0 *; 1(13)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0e<br/> 0 *; 1(14)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0f<br/> 0 *; 1(15)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x10 <br/> 0 *; 1(16) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x11 <br/> 0 *; 1(17)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x12 <br/> 0 *; 1(18)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x13 <br/> 0 *; 1(19)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x14 <br/> 0 *; 1(20)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x15 <br/> 0 *; 1(21)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x16 <br/> 0 *; 1(22)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x17 <br/> 0 *; 1(23)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x18 <br/> 0 *; 1(24)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x19 <br/> 0 *; 1(25)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1a <br/> 0 *; 1(26)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1b <br/> 0 *; 1(27)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1c <br/> 0 *; 1(28)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1d <br/> 0 *; 1(29)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1e <br/> 0 *; 1(30)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1f <br/> 0 *; 1(31)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x20 <br/> 0 *; 1(32) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x21 <br/> 0 *; 1(33)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x22 <br/> 0 *; 1(34)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x23 <br/> 0 *; 1(35)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x24 <br/> 0 *; 1(36)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x25 <br/> 0 *; 1(37)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x26 <br/> 0 *; 1(38)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x27 <br/> 0 *; 1(39)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x28 <br/> 0 *; 1(40)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x29 <br/> 0 *; 1(41)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2a <br/> 0 *; 1(42)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2b <br/> 0 *; 1(43)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2c <br/> 0 *; 1(44)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2d <br/> 0 *; 1(45)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2e <br/> 0 *; 1(46)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2f <br/> 0 *; 1(47)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x30 <br/> 0 *; 1(48) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x31 <br/> 0 *; 1(49)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x32 <br/> 0 *; 1(50)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x33 <br/> 0 *; 1(51)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x34 <br/> 0 *; 1(52)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x35 <br/> 0 *; 1(53)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x36 <br/> 0 *; 1(54)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x37 <br/> 0 *; 1(55)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x38 <br/> 0 *; 1(56)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x39 <br/> 0 *; 1(57)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3a <br/> 0 *; 1(58)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3b <br/> 0 *; 1(59)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3c <br/> 0 *; 1(60)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3d <br/> 0 *; 1(61)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3e <br/> 0 *; 1(62)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3f <br/> 0 *; 1(63)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x40 <br/> 0 *; 1(64) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x41 <br/> 0 *; 1(65)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x42 <br/> 0 *; 1(66)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x43 <br/> 0 *; 1(67)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x44 <br/> 0 *; 1(68)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x45 <br/> 0 *; 1(69)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x46 <br/> 0 *; 1(70)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x47 <br/> 0 *; 1(71)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x48 <br/> 0 *; 1(72)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x49 <br/> 0 *; 1(73)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x4a <br/> 0 *; 1(74)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x4b <br/> 0 *; 1(75)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA1 <br/> 0x4c <br/> 0 *; 1(0 - 255)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA2 <br/> 0x4d <br/> 0 *; 1(0 - 2^16-1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA4 <br/> 0x4e <br/> 0 *; 1(0 - 2^32-1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _1NEGATE <br/> 0x4f <br/> 0 ; 1(1)<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED <br/> 0x50 <br/> <br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _1 <br/> 0x51 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _2 <br/> 0x52 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _3 <br/> 0x53 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _4 <br/> 0x54 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _5 <br/> 0x55 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _6 <br/> 0x56 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _7 <br/> 0x57 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _8 <br/> 0x58 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _9 <br/> 0x59 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _10 <br/> 0x5a <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _11 <br/> 0x5b <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _12 <br/> 0x5c <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _13 <br/> 0x5d <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _14 <br/> 0x5e <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _15 <br/> 0x5f <br/> 0 ; 1(1)<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _16 <br/> 0x60 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP <br/> 0x61 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VER <br/> 0x62 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _IF <br/> 0x63 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOTIF <br/> 0x64 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VERIF <br/> 0x65 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VERNOTIF <br/> 0x66 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _ELSE <br/> 0x67 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _ENDIF <br/> 0x68 <br/> 0 ; 0<br />
| style="border:3px solid #808080; background-color:#00ff00;" | _VERIFY <br/> 0x69 <br/> 1 ; 0/1<br />
| style="border:3px solid #808080; background-color:#00ff00;" | _RETURN <br/> 0x6a <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | _TOALTSTACK <br/> 0x6b <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | _FROMALTSTACK <br/> 0x6c <br/> 0 #; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2DROP <br/> 0x6d <br/> 2 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2DUP <br/> 0x6e <br/> 2 ; 4<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _3DUP <br/> 0x6f <br/> 3 ; 6<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2OVER <br/> 0x70 <br/> 4 ; 6<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2ROT <br/> 0x71 <br/> 6 ; 6<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2SWAP <br/> 0x72 <br/> 4 ; 4<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _IFDUP <br/> 0x73 <br/> 1 ; 1/2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DEPTH <br/> 0x74 <br/> 0 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DROP <br/> 0x75 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DUP <br/> 0x76 <br/> 1 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _NIP <br/> 0x77 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _OVER <br/> 0x78 <br/> 2 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _PICK <br/> 0x79 <br/> 1+n+1 ; n+2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _ROLL <br/> 0x7a <br/> 1+n+1 ; n+1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _ROT <br/> 0x7b <br/> 3 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _SWAP <br/> 0x7c <br/> 2 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _TUCK <br/> 0x7d <br/> 2 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _CAT <br/> 0x7e <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _SUBSTR <br/> 0x7f <br/> 3 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _LEFT <br/> 0x80 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _RIGHT <br/> 0x81 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0;" | _SIZE <br/> 0x82 <br/> 1 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _INVERT <br/> 0x83 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _AND <br/> 0x84 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _OR <br/> 0x85 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _XOR <br/> 0x86 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff;" | _EQUAL <br/> 0x87 <br/> 2 ; 1<br />
| style="border:3px solid #808080; background-color:#c080ff;" | _EQUALVERIFY <br/> 0x88 <br/> 2 ; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED1 <br/> 0x89 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED2 <br/> 0x8a <br/><br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _1ADD <br/> 0x8b <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _1SUB <br/> 0x8c <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _2MUL <br/> 0x8d <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _2DIV <br/> 0x8e <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NEGATE <br/> 0x8f <br/> 1 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _ABS <br/> 0x90 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NOT <br/> 0x91 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _0NOTEQUAL <br/> 0x92 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _ADD <br/> 0x93 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _SUB <br/> 0x94 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _MUL <br/> 0x95 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _DIV <br/> 0x96 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _MOD <br/> 0x97 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _LSHIFT <br/> 0x98 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _RSHIFT <br/> 0x99 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _BOOLAND <br/> 0x9a <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _BOOLOR <br/> 0x9b <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NUMEQUAL <br/> 0x9c <br/> 2 ; 1<br />
| style="border:3px solid #808080; background-color:#8080ff;" | _NUMEQUALVERIFY <br/> 0x9d <br/> 2 ; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NUMNOTEQUAL <br/> 0x9e <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _LESSTHAN <br/> 0x9f <br/> 2 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _GREATERTHAN <br/> 0xa0 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _LESSTHANOREQUAL <br/> 0xa1 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _GREATERTHANOREQUAL <br/> 0xa2 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _MIN <br/> 0xa3 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _MAX <br/> 0xa4 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _WITHIN <br/> 0xa5 <br/> 3 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _RIPEMD160 <br/> 0xa6 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _SHA1 <br/> 0xa7 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _SHA256 <br/> 0xa8 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _HASH160 <br/> 0xa9 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _HASH256 <br/> 0xaa <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CODESEPARATOR <br/> 0xab <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CHECKSIG <br/> 0xac <br/> 2 @; 1<br />
| style="border:3px solid #808080; background-color:#a0d0ff;" | _CHECKSIGVERIFY <br/> 0xad <br/> 2 @; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CHECKMULTISIG <br/> 0xae <br/> 2n+2 @; 1<br />
| style="border:3px solid #808080; background-color:#a0d0ff;" | _CHECKMULTISIGVERIFY <br/> 0xaf <br/> 2n+2 @; 0/1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP1 <br/> 0xb0 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP2 <br/> 0xb1 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP3 <br/> 0xb2 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP4 <br/> 0xb3 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP5 <br/> 0xb4 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP6 <br/> 0xb5 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP7 <br/> 0xb6 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP8 <br/> 0xb7 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP9 <br/> 0xb8 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP10 <br/> 0xb9 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xba <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbe <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xca <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xce <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xda <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xde <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xea <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xeb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xec <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xed <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xee <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xef <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xfa <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _SMALLINTEGER <br/> 0xfb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEYS <br/> 0xfc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEYHASH <br/> 0xfd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEY <br/> 0xfe <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _INVALIDOPCODE <br/> 0xff <br/><br />
|}<br><br />
Except later pseudo-opcode changes, the definition of OP_NOP1 - OP_NOP10 and the change of the evaluation of OP_RETURN (did no invalidation previously) which both occured in bitcoin version 0.3.6 in July 2010 were the last changes regarding opcodes <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.2.0/bitcoin-0.2.0-linux.tar.gz file src/srcipt.cpp in bitcoin-0.2.0]</ref> <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.3.3/bitcoin-0.3.3-linux.tar.gz file src/srcipt.cpp in bitcoin-0.3.3]</ref> <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.3.6/bitcoin-0.3.6-linux.tar.gz file src/srcipt.cpp in bitcoin-0.3.6]</ref>.<br />
<br />
== Opcode descriptions ==<br />
It follows for each opcode less than decimal 185 (hexa 0xba) a description for its usage. The columns entitled ''nemonic'', ''decimal'' and ''Hex'' should be evident. The column ''input'' gives the needed items of the stack (and the alternate stack) and the column ''output'' indicates the resulting items on the stack (and the alternate stack). The naming of the entries in these two columns is chosen to reflect their interpretation. ''x'',''x0'',''x1'',... means arbitrary or no interpretation, ''a'', ''b'' and ''c'' as a signed integer value, ''n'',''index'',''size'' and ''depth'' non-negative integer values, ''Boolean'' as either a true or false.<br><br />
Some of the more complicated opcodes are disabled out of concern that the client might have (and has) a bug in the current implementation due to the historically not as 2-complement interpretations of the byte vectors as numerical values (the most significant byte holds the sign of the byte vectors).<br />
<br />
=== Push data from instruction onto stack ===<br />
<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_FALSE, OP_0<br />
|0<br />
|0x00<br />
|Nothing<br />
|Empty string<br />
|A byte vector of length 0 is pushed onto the stack. (Thus, it is not a no-op!)<br />
|-<br />
|(no official nemonics)<br />
|1 - 75<br />
|0x01 - 0x4b<br />
|(operand)<br />
|x<br />
|The next <opcode>-many bytes are to be pushed onto the stack.<br />
|-<br />
|OP_PUSHDATA1<br />
|76<br />
|0x4c<br />
|(operands)<br />
|x<br />
|The next byte contains the number of bytes to be pushed onto the stack which follow this byte.<br />
|-<br />
|OP_PUSHDATA2<br />
|77<br />
|0x4d<br />
|(operands)<br />
|x<br />
|The next two bytes contain the number of bytes to be pushed onto the stack which follow theses 2 bytes.<br />
|-<br />
|OP_PUSHDATA4<br />
|78<br />
|0x4e<br />
|(operands)<br />
|x<br />
|The next four bytes contain the number of bytes to be pushed onto the stack which follow theses 4 bytes.<br />
|-<br />
|OP_1NEGATE<br />
|79<br />
|0x4f<br />
|Nothing<br />
| -1<br />
|The byte with value -1 is pushed onto the stack.<br />
|-<br />
|OP_1, OP_TRUE<br />
|81<br />
|0x51<br />
|Nothing<br />
|1<br />
|The byte with value 1 is pushed onto the stack.<br />
|-<br />
|OP_2 - OP_16<br />
|82 - 96<br />
|0x52 - 0x60<br />
|Nothing<br />
|2-16<br />
|The byte with value <opcode>-80 (thus, one of 2 - 16) is pushed onto the stack.<br />
|}<br />
<br />
=== Flow control ===<br />
<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_NOP<br />
|97<br />
|0x61<br />
|Nothing<br />
|Nothing<br />
|Does nothing.<br />
|-<br />
|OP_IF<br />
|99<br />
|0x63<br />
|Boolean<br />
|Nothing<br />
|If the top stack value is not 0, the statements are executed. The top stack value is removed. Lead in a logcial ''<value> then [statements] [else [statements]] endif'' expression<br />
|-<br />
|OP_NOTIF<br />
|100<br />
|0x64<br />
|Boolean<br />
|Nothing<br />
|If the top stack value is 0, the statements are executed. The top stack value is removed. Lead in a logcial ''<value> then [statements] [else [statements]] endif'' expression <br />
|-<br />
|OP_ELSE<br />
|103<br />
|0x67<br />
|Nothing<br />
|Nothing<br />
|If the preceeding OP_IF or OP_NOTIF or OP_ELSE was not executed then these statements are and if the preceding OP_IF or OP_NOTIF or OP_ELSE was executed then these statements are not. <br />
|-<br />
|OP_ENDIF<br />
|104<br />
|0x68<br />
|Nothing<br />
|Nothing<br />
|Ends a logcial ''If <value> then [statements] [else [statements]] '' expression<br />
|-<br />
|OP_VERIFY<br />
|105<br />
|0x69<br />
|Boolean<br />
|Nothing / False<br />
|If top stack value is not true then marks transaction as '''invalid''' . A value true is removed, but false is not.<br />
|-<br />
|OP_RETURN<br />
|106<br />
|0x6a<br />
|Nothing<br />
|Nothing<br />
|Marks transaction as '''invalid'''. <br />
|}<br />
<br />
===Stack item organization===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_TOALTSTACK<br />
|107<br />
|0x6b<br />
|x1 (alt)<br />
|(alt x1)<br />
|Puts the input onto the top of the alt stack. Removes it from the (main) stack.<br />
|-<br />
|OP_FROMALTSTACK<br />
|108<br />
|0x6c<br />
|(alt x1)<br />
|x1 (alt)<br />
|Puts the input onto the top of the (main) stack. Removes it from the alt stack.<br />
|-<br />
|OP_2DROP<br />
|109<br />
|0x6d<br />
|x1 x2<br />
|Nothing<br />
|Removes the top two stack items.<br />
|-<br />
|OP_2DUP<br />
|110<br />
|0x6e<br />
|x1 x2<br />
|x1 x2 x1 x2<br />
|Duplicates the top two stack items.<br />
|-<br />
|OP_3DUP<br />
|111<br />
|0x6f<br />
|x1 x2 x3<br />
|x1 x2 x3 x1 x2 x3<br />
|Duplicates the top three stack items.<br />
|-<br />
|OP_2OVER<br />
|112<br />
|0x70<br />
|x1 x2 x3 x4<br />
|x1 x2 x3 x4 x1 x2<br />
|Copies the pair of items two spaces back in the stack to the front.<br />
|-<br />
|OP_2ROT<br />
|113<br />
|0x71<br />
|x1 x2 x3 x4 x5 x6<br />
|x3 x4 x5 x6 x1 x2<br />
|The fifth and sixth items back are moved to the top of the stack.<br />
|-<br />
|OP_2SWAP<br />
|114<br />
|0x72<br />
|x1 x2 x3 x4<br />
|x3 x4 x1 x2<br />
|Swaps the top two pairs of items.<br />
|-<br />
|OP_IFDUP<br />
|115<br />
|0x73<br />
|x<br />
|x / x x<br />
|If the top stack value is not 0, duplicate it.<br />
|-<br />
|OP_DEPTH<br />
|116<br />
|0x74<br />
|Nothing<br />
|depth<br />
|Puts the number of stack items onto the stack as one little-endian coded byte-vector<br />
|-<br />
|OP_DROP<br />
|117<br />
|0x75<br />
|x<br />
|Nothing<br />
|Removes the top stack item.<br />
|-<br />
|OP_DUP<br />
|118<br />
|0x76<br />
|x<br />
|x x<br />
|Duplicates the top stack item.<br />
|-<br />
|OP_NIP<br />
|119<br />
|0x77<br />
|x1 x2<br />
|x2<br />
|Removes the second-to-top stack item.<br />
|-<br />
|OP_OVER<br />
|120<br />
|0x78<br />
|x1 x2<br />
|x1 x2 x1<br />
|Copies the second-to-top stack item to the top.<br />
|-<br />
|OP_PICK<br />
|121<br />
|0x79<br />
|xn ... x2 x1 x0 <n><br />
|xn ... x2 x1 x0 xn<br />
|The item ''n'' back in the stack is copied to the top.<br />
|-<br />
|OP_ROLL<br />
|122<br />
|0x7a<br />
|xn ... x2 x1 x0 <n><br />
|... x2 x1 x0 xn<br />
|The item ''n'' back in the stack is moved to the top.<br />
|-<br />
|OP_ROT<br />
|123<br />
|0x7b<br />
|x1 x2 x3<br />
|x2 x3 x1<br />
|The top three items on the stack are rotated to the left.<br />
|-<br />
|OP_SWAP<br />
|124<br />
|0x7c<br />
|x1 x2<br />
|x2 x1<br />
|The top two items on the stack are swapped.<br />
|-<br />
|OP_TUCK<br />
|125<br />
|0x7d<br />
|x1 x2<br />
|x2 x1 x2<br />
|The item at the top of the stack is copied and inserted before the second-to-top item.<br />
|}<br />
<br />
=== Splice ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_CAT<br />
|126<br />
|0x7e<br />
|x1 x2<br />
|out<br />
|Concatenates two strings resp. byte vectors. ''Currently disabled.''<br />
|-<br />
|OP_SUBSTR<br />
|127<br />
|0x7f<br />
|x index size<br />
|out<br />
|Returns the section started at position <index> and of length <size> of a string resp. byte vector. ''Currently disabled.''<br />
|-<br />
|OP_LEFT<br />
|128<br />
|0x80<br />
|x index<br />
|out<br />
|Keeps only characters left of the specified point in a string. ''Currently disabled.''<br />
|-<br />
|OP_RIGHT<br />
|129<br />
|0x81<br />
|x index<br />
|out<br />
|Keeps only characters right of the specified point in a string. ''Currently disabled.''<br />
|-<br />
|OP_SIZE<br />
|130<br />
|0x82<br />
|x<br />
|x size<br />
|Returns the length of the input string resp. byte vector resp. stack item.<br />
|}<br />
<br />
=== Bitwise logic ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_INVERT<br />
|131<br />
|0x83<br />
|x1<br />
|x0<br />
|Flips all of the bits in the input. ''Currently disabled.''<br />
|-<br />
|OP_AND<br />
|132<br />
|0x84<br />
|x1 x2<br />
|x0<br />
|Boolean ''and'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_OR<br />
|133<br />
|0x85<br />
|x1 x2<br />
|x0<br />
|Boolean ''or'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_XOR<br />
|134<br />
|0x86<br />
|x1 x2<br />
|x0<br />
|Boolean ''exclusive or'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_EQUAL<br />
|135<br />
|0x87<br />
|x1 x2<br />
|Boolean<br />
|Returns 1 if the inputs are byte-wise equal, 0 otherwise.<br />
|-<br />
|OP_EQUALVERIFY<br />
|136<br />
|0x88<br />
|x1 x2<br />
|Nothing / false<br />
|Same as OP_EQUAL, but runs OP_VERIFY afterward.<br />
|}<br />
<br />
=== Arithmetic ===<br />
<br />
(In very early versions, the implemented arithmetic opcodes were limited to maximal 4 byte vectors.)<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_1ADD<br />
|139<br />
|0x8b<br />
|a<br />
|c<br />
|1 is added to the input.<br />
|-<br />
|OP_1SUB<br />
|140<br />
|0x8c<br />
|a<br />
|c<br />
|1 is subtracted from the input.<br />
|-<br />
|OP_2MUL<br />
|141<br />
|0x8d<br />
|a<br />
|c<br />
|The input is multiplied by 2. ''Currently disabled.''<br />
|-<br />
|OP_2DIV<br />
|142<br />
|0x8e<br />
|a<br />
|c<br />
|The input is divided by 2. ''Currently disabled.''<br />
|-<br />
|OP_NEGATE<br />
|143<br />
|0x8f<br />
|a<br />
|c<br />
|The sign of the input is flipped. Numerically the value is multiplied by -1<br />
|-<br />
|OP_ABS<br />
|144<br />
|0x90<br />
|a<br />
|c<br />
|The input is negative, its sign is flipped.<br />
|-<br />
|OP_NOT<br />
|145<br />
|0x91<br />
|a<br />
|Boolean<br />
|If the input is 0 or 1, it is flipped. Otherwise the output will be 0. Test whether its value equals 0<br />
|-<br />
|OP_0NOTEQUAL<br />
|146<br />
|0x92<br />
|a<br />
|Boolean<br />
|Returns 0 if the input is 0. 1 otherwise. Test whether its value is unequal 0<br />
|-<br />
|OP_ADD<br />
|147<br />
|0x93<br />
|a b<br />
|c<br />
|a is added to b.<br />
|-<br />
|OP_SUB<br />
|148<br />
|0x94<br />
|a b<br />
|c<br />
|b is subtracted from a.<br />
|-<br />
|OP_MUL<br />
|149<br />
|0x95<br />
|a b<br />
|c<br />
|a is multiplied by b. ''Currently disabled.''<br />
|-<br />
|OP_DIV<br />
|150<br />
|0x96<br />
|a b<br />
|c<br />
|a is divided by b (b should be not 0). ''Currently disabled.''<br />
|-<br />
|OP_MOD<br />
|151<br />
|0x97<br />
|a b<br />
|c<br />
|Returns the remainder after dividing a by b (b should be not 0). ''Currently disabled.''<br />
|-<br />
|OP_LSHIFT<br />
|152<br />
|0x98<br />
|a b<br />
|c<br />
|Shifts a left by b bits, preserving sign. ''Currently disabled.''<br />
|-<br />
|OP_RSHIFT<br />
|153<br />
|0x99<br />
|a b<br />
|c<br />
|Shifts a right by b bits, preserving sign. ''Currently disabled.''<br />
|-<br />
|OP_BOOLAND<br />
|154<br />
|0x9a<br />
|a b<br />
|Boolean<br />
|If both a and b are not 0, the output is 1. Otherwise 0.<br />
|-<br />
|OP_BOOLOR<br />
|155<br />
|0x9b<br />
|a b<br />
|Boolean<br />
|If a or b is not 0, the output is 1. Otherwise 0.<br />
|-<br />
|OP_NUMEQUAL<br />
|156<br />
|0x9c<br />
|a b<br />
|Boolean<br />
|Returns 1 if the numbers are equal, 0 otherwise.<br />
|-<br />
|OP_NUMEQUALVERIFY<br />
|157<br />
|0x9d<br />
|a b<br />
|Nothing / False<br />
|Same as OP_NUMEQUAL, but runs OP_VERIFY afterward.<br />
|-<br />
|OP_NUMNOTEQUAL<br />
|158<br />
|0x9e<br />
|a b<br />
|Boolean<br />
|Returns 1 if the numbers are not equal, 0 otherwise.<br />
|-<br />
|OP_LESSTHAN<br />
|159<br />
|0x9f<br />
|a b<br />
|Boolean<br />
|Returns 1 if a is less than b, 0 otherwise.<br />
|-<br />
|OP_GREATERTHAN<br />
|160<br />
|0xa0<br />
|a b<br />
|Boolean<br />
|Returns 1 if a is greater than b, 0 otherwise.<br />
|-<br />
|OP_LESSTHANOREQUAL<br />
|161<br />
|0xa1<br />
|a b<br />
|Boolean<br />
|Returns 1 if a is less than or equal to b, 0 otherwise.<br />
|-<br />
|OP_GREATERTHANOREQUAL<br />
|162<br />
|0xa2<br />
|a b<br />
|Boolean<br />
|Returns 1 if a is greater than or equal to b, 0 otherwise.<br />
|-<br />
|OP_MIN<br />
|163<br />
|0xa3<br />
|a b<br />
|a / b<br />
|Returns the smaller of a and b.<br />
|-<br />
|OP_MAX<br />
|164<br />
|0xa4<br />
|a b<br />
| a / b<br />
|Returns the larger of a and b.<br />
|-<br />
|OP_WITHIN<br />
|165<br />
|0xa5<br />
|x min max<br />
|Boolean<br />
|Returns 1 if x is within the specified range (left-inclusive) , 0 otherwise. min may be greater than max<br />
|}<br />
<br />
=== Crypto ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_RIPEMD160<br />
|166<br />
|0xa6<br />
|x<br />
|hash20<br />
|The input is hashed using RIPEMD-160.<br />
|-<br />
|OP_SHA1<br />
|167<br />
|0xa7<br />
|x<br />
|hash20<br />
|The input is hashed using SHA-1.<br />
|-<br />
|OP_SHA256<br />
|168<br />
|0xa8<br />
|x<br />
|hash32<br />
|The input is hashed using SHA-256.<br />
|-<br />
|OP_HASH160<br />
|169<br />
|0xa9<br />
|x<br />
|hash20<br />
|The input is hashed twice: first with SHA-256 and then with RIPEMD-160.<br />
|-<br />
|OP_HASH256<br />
|170<br />
|0xaa<br />
|x<br />
|hash32<br />
|The input is hashed two times with SHA-256.<br />
|-<br />
|OP_CODESEPARATOR<br />
|171<br />
|0xab<br />
|Nothing<br />
|Nothing<br />
|All of the signature checking opcodes will only match signatures to the data after the most recently-executed OP_CODESEPARATOR.<br />
|-<br />
|[[OP_CHECKSIG]]<br />
|172<br />
|0xac<br />
|sig pubkey<br />
|Boolean<br />
|The entire transaction's outputs, inputs, and script (from the most recently-executed OP_CODESEPARATOR to the end) are hashed. The signature used by OP_CHECKSIG must be a valid signature for a further, extern specified hash and the given public key. If it is, 1 is returned, 0 otherwise.<br />
|-<br />
|OP_CHECKSIGVERIFY<br />
|173<br />
|0xad<br />
|sig pubkey<br />
|Nothing / False<br />
|Same as OP_CHECKSIG, but OP_VERIFY is executed afterward.<br />
|-<br />
|OP_CHECKMULTISIG<br />
|174<br />
|0xae<br />
|sig1 sig2 ... <number of signatures> pub1 pub2 <number of public keys><br />
|Boolean<br />
|For each signature and public key pair, OP_CHECKSIG is executed. If more public keys than signatures are listed, some key/sig pairs can fail. All signatures need to match a public key. If all signatures are valid, 1 is returned, 0 otherwise. Due to a bug, one extra unused value is removed from the stack.<br />
|-<br />
|OP_CHECKMULTISIGVERIFY<br />
|175<br />
|0xaf<br />
|sig1 sig2 ... <number of signatures> pub1 pub2 ... <number of public keys><br />
|Nothing / False<br />
|Same as OP_CHECKMULTISIG, but OP_VERIFY is executed afterward.<br />
|}<br />
<br />
=== Expansion opcodes ===<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_NOP1-OP_NOP10<br />
|176-185<br />
|0xb0-0xb9<br />
|The opcode has no effect.<br />
|}<br />
<br />
=== Version opcodes ===<br />
Version opcodes are disabled since bitcoin 0.2.0 and should not be used (maybe reassigned in the future).<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_VER<br />
|98<br />
|0x62<br />
|Script evalution is triggered invalid (Formerly pushed the bitcoin-serialize version onto stack).<br />
|-<br />
|OP_VERIF<br />
|101<br />
|0x65<br />
|Script evalution is triggered invalid (Formerly top stack item was popped and =< compared to present version)<br />
|-<br />
|OP_VERNOTIF<br />
|102<br />
|0x66<br />
|Script evalution is triggered invalid (Formerly top stack item was popped and > compared to present version)<br />
|}<br />
<br />
=== Reserved opcodes ===<br />
Each opcode not assigned (currently also every opcode value > 185) is also reserved. Using any unassigned opcode triggers the script evaluation to be invalid.<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_RESERVED<br />
|80<br />
|0x50<br />
|Script evalution is triggered invalid-<br />
|-<br />
|OP_RESERVED1<br />
|137<br />
|0x89<br />
|Script evalution is triggered invalid.<br />
|-<br />
|OP_RESERVED2<br />
|138<br />
|0x8a<br />
|Script evalution is triggered invalid.<br />
|}<br />
<br />
===Pseudo-opcodes===<br />
These nemonics are used internally for assisting with transaction matching. They are invalid if used in actual scripts.<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_PUBKEYHASH<br />
|253<br />
|0xfd<br />
|Represents a public key hashed with OP_HASH160.<br />
|-<br />
|OP_PUBKEY<br />
|254<br />
|0xfe<br />
|Represents a public key compatible with OP_CHECKSIG.<br />
|-<br />
|OP_INVALIDOPCODE<br />
|255<br />
|0xff<br />
|Matches any opcode that is not yet assigned.<br />
|}<br />
<br />
==Scripts in bitcoin transactions==<br />
It follows a list of important (most occuring) scripts to see opcodes "at work". Keep in mind that all constants actually use the data-pushing instructions above. At start of a (transaction input) script evaluation, the stack is always empty. <br />
<br />
===Standard transaction to bitcoin address===<br />
<br />
scriptPubKey: OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG<br />
scriptSig: <sig> <pubKey><br />
<br />
To demonstrate how scripts look on the wire, here is a raw scriptPubKey:<br />
<pre> 76 A9 14<br />
OP_DUP OP_HASH160 Bytes to push<br />
<br />
89 AB CD EF AB BA AB BA AB BA AB BA AB BA AB BA AB BA AB BA 88 AC<br />
Data to push OP_EQUALVERIFY OP_CHECKSIG</pre><br />
<br />
Note: scriptSig is in the input of the spending transaction and scriptPubKey is in the output of the previously storing transaction, i.e. its "available bitcoins".<br />
<br />
Here is how each instruction is processed:<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
| <sig> <pubKey> OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| scriptSig and scriptPubKey are combined.<br />
|-<br />
|<sig> <pubKey><br />
| OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| Constants are added to the stack.<br />
|-<br />
|<sig> <pubKey> <pubKey><br />
| OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| Top stack item is duplicated.<br />
|-<br />
|<sig> <pubKey> <pubHashA><br />
|<pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG<br />
| Top stack item is hashed.<br />
|-<br />
|<sig> <pubKey> <pubHashA> <pubKeyHash><br />
|OP_EQUALVERIFY OP_CHECKSIG<br />
| Constant added.<br />
|-<br />
|<sig> <pubKey><br />
|OP_CHECKSIG<br />
| Equality is checked between the top two stack items.<br />
|-<br />
|true<br />
|Empty.<br />
|Signature is checked for top two stack items.<br />
|}<br />
<br />
===Transaction to IP address (and generation transaction)===<br />
<br />
scriptPubKey: <pubKey> OP_CHECKSIG<br />
scriptSig: <sig><br />
<br />
Checking process:<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
|<sig> <pubKey> OP_CHECKSIG<br />
|scriptSig and scriptPubKey are combined.<br />
|-<br />
|<sig> <pubKey><br />
| OP_CHECKSIG<br />
|Constants are added to the stack.<br />
|-<br />
|true<br />
|Empty.<br />
|Signature is checked for top two stack items.<br />
|}<br />
<br />
In the case of a '''coin generation transaction''' (the first transaction of each block), there is no scriptSig, resp. its code ("coinbase") is completly ignored for the transaction. Only the scriptPubKey is used.<br />
<br />
===Transaction with a message===<br />
<br />
It's possible to add arbitrary data to any transaction by just adding some data along with OP_DROP. <br />
scriptPubKey: <message> OP_DROP <pubKey> OP_CHECKSIG<br />
scriptSig: <sig><br />
<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
|<sig> <message> OP_DROP <pubKey> OP_CHECKSIG<br />
|<br />
|-<br />
|<sig><br />
|<message> OP_DROP <pubKey> OP_CHECKSIG<br />
|scriptSig added to the stack.<br />
|-<br />
|<sig> <message><br />
|OP_DROP <pubKey> OP_CHECKSIG<br />
|The message has been put.<br />
|-<br />
|<sig><br />
|<pubKey> OP_CHECKSIG<br />
|Top stack item has been removed.<br />
|-<br />
|<sig> <pubKey><br />
|OP_CHECKSIG<br />
|Checking signature against the public key.<br />
|-<br />
|true<br />
|Empty.<br />
|Stack holds the value of signature check now.<br />
|}<br />
<br />
===Examples of non standard transaction on Testnet===<br />
<br />
These two links below show a non standard transaction. It just prepends the hex of "bob" and the operation OP_DROP<br />
which just removes it. As you can see they can be spent as normal.<br />
<br />
Input non-std transaction:<br />
http://blockexplorer.com/testnet/t/6ttfeb55B1<br />
<br />
Spent by:<br />
http://blockexplorer.com/testnet/t/AFdRB1CHS3<br />
<br />
==Script validation==<br />
A script evaluation is considered invalid, if any of these conditions meets:<br><br />
<ul><br />
<li>the total size of the script exceeds (currently) 10000 bytes<br />
<li>there are more than (currently) 201 opcodes of opcode value > 0x60 in the script<br />
<li>each instruction is (currently) limited to maximal 520 bytes. This effects only the opcodes OP_PUSHDATA2 and OP_PUSHDATA4<br />
<li>the executed opcode of the script has insufficient input (from stack, from script or from anywhere)<br />
<li>the opcode is not defined (for execution) - indicated by white or light gray background color in the table<br />
<li>the opcode is disabled (currently 15 opcodes) - indicated by white font color in the opcode overview matrix<br />
<li>stack overflow occurs during execution of the opcode (currently the number of items on the stack and on the alternate stack is limited to 1000)<br />
<li>the opcodes OP_VERIF and OP_NOTVERIF invalidate a script which contains this opcode (even if this opcode is not executed!)<br />
<li>the opcodes OP_ELSE or OP_ENDIF has no matching OP_IF<br><br />
<li>the script execution has been finished but there is (at least) an unmatched OP_IF<br><br />
<li>the opcodes OP_VERIFY, OP_EQUALVERIFY, OP_NUMEQUALVERIFY, OP_CHECKSIGVERIFY and OP_CHECKMULTISIGVERIFY invalidate the script if the stack-top item is false<br />
<li>the execution of OP_RETURN<br />
<!--li>alt stack overflow occurs (only possible during execution of OP_TOALTSTACK)--><br />
<li>the numerical value of the top-stack item is negative or greater than the number of items - 2 on the stack if OP_PICK or OP_ROLL shall be executed<br />
<li>an item used as public key or signature for each of the opcodes OP_CHECKSIG, OP_CHECKSIGVERIFY, OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY can be neither a public key or signature (for the given hash)<br />
<li>the number of signature items or the number of public key items on the stack is negative for OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY<br />
<li>there or more signatures items than public key items on the stack for OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY<br />
<li>there are (currently) more than 20 public key items on the stack for OP_CHECKMULTISIG or CHECKMULTISIGVERIFY<br />
<li>the sum of opcodes > 0x60 and the number of public keys in all executed OP_CHECKMULTISIG or CHECKMULTISIGVERIFY exceeds (currently) 201<br />
<li>the script execution has been finished and the stack is empty or the top-stack item is false (numerical value 0)<br />
</ul><br />
else the script evaluation is considered to be valid.<ref>[http://sourceforge.net/projects/bitcoin/files/Bitcoin/bitcoin-0.7.1/bitcoin-0.7.1-linux.tar.gz file src/src/script.cpp in bitcoin-0.7.1]</ref><br />
'''If invalidation of a script is triggered then the script is immediately finished.''' These arbitrary looking limitations of 10000, 201, 520, 1000 and 20 might be increased in the future -- they serve to prevent strong slow down of the evaluation of a script while not restricting its practical usage really.<br />
<br />
==Withdrawn and drafted opcodes==<br />
<br />
<ul><br />
<li> byte value 0x89 OP_NOTEQUAL defined in pre-0.1.0 bitcoin versions. Since 0.1.0 removed because of security concerns. <br />
<li> byte value 0xb1 [[BIP 0012 | OP_EVAL]] withdraw - poll was triggered but insufficient support. <br />
<li> byte value 0xb2 [[BIP 0017 | OP_CHECKHASHVERIFY]] withdraw - poll was triggered but insufficient support.<br />
</ul><br />
<br />
==See Also==<br />
* [[Transactions]]<br />
* [[Contracts]]<br />
<br />
==References==<br />
<references/><br />
<ul><br />
<li>[http://www.zorinaq.com/pub/bitcoin-0.1.0.tgz file src/script.cpp in bitcoin-0.1.0]</li><br />
</ul><br />
[[Category:Technical]]<br />
[[Category:Vocabulary]]</div>
Smtp
https://en.bitcoin.it/w/index.php?title=Script&diff=34854
Script
2013-01-09T17:06:14Z
<p>Smtp: /* redrawn and drafted opcodes */</p>
<hr />
<div>Bitcoin uses a scripting system for [[transactions]]. [[Wikipedia:FORTH|Forth]]-like, Script is simple, stack-based, and processed from left to right. It is purposefully not Turing-complete, with no loops.<br />
<br />
A script is essentially a list of instructions recorded with each transaction that describe how the next person wanting to spend the Bitcoins being transferred can gain access to them.<br />
<br />
Scripts are big-endian and their sequences of bytes is interpreted as a sequence of opcodes with operands. Only opcodes with byte values less than 0x4f have additional operands.<br />
<br />
== Scripts and Bitcoin transactions ==<br />
The script for a typical Bitcoin transfer to destination Bitcoin address D simply encumbers future spending of the bitcoins with two things: the spender must provide<br />
# a public key that, when hashed, yields destination address D embedded in the script, and<br />
# a signature to show evidence of the private key corresponding to the public key just provided.<br />
<br />
Scripting provides the flexibility to change the parameters of what's needed to spend transferred Bitcoins. For example, the scripting system could be used to require two private keys, or a combination of several, or even no keys at all.<br />
<br />
A transaction is valid if nothing in the combined script triggers failure and the top stack item exists and is true (non-zero). The party who originally ''stored'' the Bitcoins now being spent, dictates the script operations that will occur ''last'' in order to release them for use in another transaction. The party wanting to spend them must provide the input(s) to the previously recorded script that results in those operations occurring last leaving behind true (non-zero) on the stack.<br><br />
Only the very first transaction in each bitcoin block has no input script (the entry there is called "coinbase"), because the Bitcoins created with the block are created from hot air and not released by a previous recorded script.<br />
<br />
== Stack ==<br />
<br />
The stacks hold byte vectors (there is the (main) stack and an alternative stack). Byte vectors are interpreted as little-endian variable-length integers with the most significant bit determining the sign of the integer. Thus 0x81 represents -1. 0x80 is another representation of zero (so called negative 0). Byte vectors are interpreted as Booleans where False is represented by any representation of zero, and True is represented by any representation of non-zero.<br />
<br />
== Opcode overview ==<br />
<br />
For each opcode is given: its nemonic without the leading OP_, its hexadecimal byte value, the number of stack items needed (poped) during execution, a semicolon and the number of stack items which has been pushed (after execution). A * after the needed stack items indicates that further bytes from the script following the current opcode are needed. A # indicates that items on the alternative stack are poped/pushed. A @ indicates that further (global) data from the transaction is needed. A / indicates alternatives of a value. <br/><br />
Different colors indicate different semantic execution groups of opcodes:<br />
{| style="background:none; font-size:100%; padding:0; border-collapse:collapse; text-align:center; line-height:2em;" border="0" align="center" <br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | copy a fixed number of bytes but at most 75 onto stack<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | copy bytes onto stack which number is given by a 1, 2 or 4 byte value.<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | copy 1 specific byte onto stack<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | undefined opcode<br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | a pseudo-opcode, unassigned for scripts<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | NOP or opcode is part of a IF-flow-control construction<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00ff00;" | (stack conditionally) invalidation of the script this opcode is part of<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | stack item is moved between main stack and alternate stack<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | stack item(s) is/are moved, copied or deleted<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0;" | byte vectors are appended or divided or their size is determined<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff;" | byte vectors are interpreted bit-position-independently<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | byte vectors are interpreted and processed as signed integers<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | a hash value is computed or a signature checked<br />
|}<br />
<p><br />
===Opcode byte-matrix===<br />
The opcode value 0x00 with nemonic OP_FALSE is also named OP_0 and the opcode value 0x51 with nemonic OP_1 as also named OP_TRUE.<br />
{| style="background:none; font-size:100%; padding:0; border-collapse:collapse; text-align:center; line-height:2em;" border="0" align="center" <br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" |_FALSE<br/> 0x00 <br/> 0 ; 1(0) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x01<br/> 0 *; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x02<br/> 0 *; 1(2)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x03<br/> 0 *; 1(3)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x04<br/> 0 *; 1(4)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x04<br/> 0 *; 1(5)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x06<br/> 0 *; 1(6)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x07<br/> 0 *; 1(7)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x08<br/> 0 *; 1(8)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x09<br/> 0 *; 1(9)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0a<br/> 0 *; 1(10)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0b<br/> 0 *; 1(11)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0c<br/> 0 *; 1(12)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0d<br/> 0 *; 1(13)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0e<br/> 0 *; 1(14)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0f<br/> 0 *; 1(15)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x10 <br/> 0 *; 1(16) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x11 <br/> 0 *; 1(17)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x12 <br/> 0 *; 1(18)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x13 <br/> 0 *; 1(19)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x14 <br/> 0 *; 1(20)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x15 <br/> 0 *; 1(21)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x16 <br/> 0 *; 1(22)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x17 <br/> 0 *; 1(23)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x18 <br/> 0 *; 1(24)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x19 <br/> 0 *; 1(25)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1a <br/> 0 *; 1(26)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1b <br/> 0 *; 1(27)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1c <br/> 0 *; 1(28)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1d <br/> 0 *; 1(29)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1e <br/> 0 *; 1(30)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1f <br/> 0 *; 1(31)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x20 <br/> 0 *; 1(32) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x21 <br/> 0 *; 1(33)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x22 <br/> 0 *; 1(34)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x23 <br/> 0 *; 1(35)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x24 <br/> 0 *; 1(36)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x25 <br/> 0 *; 1(37)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x26 <br/> 0 *; 1(38)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x27 <br/> 0 *; 1(39)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x28 <br/> 0 *; 1(40)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x29 <br/> 0 *; 1(41)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2a <br/> 0 *; 1(42)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2b <br/> 0 *; 1(43)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2c <br/> 0 *; 1(44)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2d <br/> 0 *; 1(45)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2e <br/> 0 *; 1(46)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2f <br/> 0 *; 1(47)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x30 <br/> 0 *; 1(48) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x31 <br/> 0 *; 1(49)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x32 <br/> 0 *; 1(50)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x33 <br/> 0 *; 1(51)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x34 <br/> 0 *; 1(52)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x35 <br/> 0 *; 1(53)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x36 <br/> 0 *; 1(54)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x37 <br/> 0 *; 1(55)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x38 <br/> 0 *; 1(56)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x39 <br/> 0 *; 1(57)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3a <br/> 0 *; 1(58)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3b <br/> 0 *; 1(59)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3c <br/> 0 *; 1(60)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3d <br/> 0 *; 1(61)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3e <br/> 0 *; 1(62)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3f <br/> 0 *; 1(63)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x40 <br/> 0 *; 1(64) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x41 <br/> 0 *; 1(65)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x42 <br/> 0 *; 1(66)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x43 <br/> 0 *; 1(67)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x44 <br/> 0 *; 1(68)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x45 <br/> 0 *; 1(69)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x46 <br/> 0 *; 1(70)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x47 <br/> 0 *; 1(71)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x48 <br/> 0 *; 1(72)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x49 <br/> 0 *; 1(73)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x4a <br/> 0 *; 1(74)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x4b <br/> 0 *; 1(75)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA1 <br/> 0x4c <br/> 0 *; 1(0 - 255)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA2 <br/> 0x4d <br/> 0 *; 1(0 - 2^16-1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA4 <br/> 0x4e <br/> 0 *; 1(0 - 2^32-1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _1NEGATE <br/> 0x4f <br/> 0 ; 1(1)<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED <br/> 0x50 <br/> <br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _1 <br/> 0x51 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _2 <br/> 0x52 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _3 <br/> 0x53 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _4 <br/> 0x54 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _5 <br/> 0x55 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _6 <br/> 0x56 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _7 <br/> 0x57 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _8 <br/> 0x58 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _9 <br/> 0x59 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _10 <br/> 0x5a <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _11 <br/> 0x5b <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _12 <br/> 0x5c <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _13 <br/> 0x5d <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _14 <br/> 0x5e <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _15 <br/> 0x5f <br/> 0 ; 1(1)<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _16 <br/> 0x60 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP <br/> 0x61 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VER <br/> 0x62 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _IF <br/> 0x63 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOTIF <br/> 0x64 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VERIF <br/> 0x65 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VERNOTIF <br/> 0x66 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _ELSE <br/> 0x67 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _ENDIF <br/> 0x68 <br/> 0 ; 0<br />
| style="border:3px solid #808080; background-color:#00ff00;" | _VERIFY <br/> 0x69 <br/> 1 ; 0/1<br />
| style="border:3px solid #808080; background-color:#00ff00;" | _RETURN <br/> 0x6a <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | _TOALTSTACK <br/> 0x6b <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | _FROMALTSTACK <br/> 0x6c <br/> 0 #; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2DROP <br/> 0x6d <br/> 2 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2DUP <br/> 0x6e <br/> 2 ; 4<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _3DUP <br/> 0x6f <br/> 3 ; 6<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2OVER <br/> 0x70 <br/> 4 ; 6<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2ROT <br/> 0x71 <br/> 6 ; 6<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2SWAP <br/> 0x72 <br/> 4 ; 4<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _IFDUP <br/> 0x73 <br/> 1 ; 1/2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DEPTH <br/> 0x74 <br/> 0 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DROP <br/> 0x75 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DUP <br/> 0x76 <br/> 1 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _NIP <br/> 0x77 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _OVER <br/> 0x78 <br/> 2 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _PICK <br/> 0x79 <br/> 1+n+1 ; n+2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _ROLL <br/> 0x7a <br/> 1+n+1 ; n+1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _ROT <br/> 0x7b <br/> 3 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _SWAP <br/> 0x7c <br/> 2 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _TUCK <br/> 0x7d <br/> 2 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _CAT <br/> 0x7e <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _SUBSTR <br/> 0x7f <br/> 3 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _LEFT <br/> 0x80 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _RIGHT <br/> 0x81 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0;" | _SIZE <br/> 0x82 <br/> 1 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _INVERT <br/> 0x83 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _AND <br/> 0x84 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _OR <br/> 0x85 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _XOR <br/> 0x86 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff;" | _EQUAL <br/> 0x87 <br/> 2 ; 1<br />
| style="border:3px solid #808080; background-color:#c080ff;" | _EQUALVERIFY <br/> 0x88 <br/> 2 ; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED1 <br/> 0x89 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED2 <br/> 0x8a <br/><br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _1ADD <br/> 0x8b <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _1SUB <br/> 0x8c <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _2MUL <br/> 0x8d <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _2DIV <br/> 0x8e <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NEGATE <br/> 0x8f <br/> 1 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _ABS <br/> 0x90 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NOT <br/> 0x91 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _0NOTEQUAL <br/> 0x92 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _ADD <br/> 0x93 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _SUB <br/> 0x94 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _MUL <br/> 0x95 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _DIV <br/> 0x96 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _MOD <br/> 0x97 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _LSHIFT <br/> 0x98 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _RSHIFT <br/> 0x99 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _BOOLAND <br/> 0x9a <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _BOOLOR <br/> 0x9b <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NUMEQUAL <br/> 0x9c <br/> 2 ; 1<br />
| style="border:3px solid #808080; background-color:#8080ff;" | _NUMEQUALVERIFY <br/> 0x9d <br/> 2 ; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NUMNOTEQUAL <br/> 0x9e <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _LESSTHAN <br/> 0x9f <br/> 2 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _GREATERTHAN <br/> 0xa0 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _LESSTHANOREQUAL <br/> 0xa1 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _GREATERTHANOREQUAL <br/> 0xa2 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _MIN <br/> 0xa3 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _MAX <br/> 0xa4 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _WITHIN <br/> 0xa5 <br/> 3 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _RIPEMD160 <br/> 0xa6 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _SHA1 <br/> 0xa7 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _SHA256 <br/> 0xa8 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _HASH160 <br/> 0xa9 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _HASH256 <br/> 0xaa <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CODESEPARATOR <br/> 0xab <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CHECKSIG <br/> 0xac <br/> 2 @; 1<br />
| style="border:3px solid #808080; background-color:#a0d0ff;" | _CHECKSIGVERIFY <br/> 0xad <br/> 2 @; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CHECKMULTISIG <br/> 0xae <br/> 2n+2 @; 1<br />
| style="border:3px solid #808080; background-color:#a0d0ff;" | _CHECKMULTISIGVERIFY <br/> 0xaf <br/> 2n+2 @; 0/1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP1 <br/> 0xb0 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP2 <br/> 0xb1 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP3 <br/> 0xb2 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP4 <br/> 0xb3 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP5 <br/> 0xb4 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP6 <br/> 0xb5 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP7 <br/> 0xb6 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP8 <br/> 0xb7 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP9 <br/> 0xb8 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP10 <br/> 0xb9 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xba <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbe <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xca <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xce <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xda <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xde <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xea <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xeb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xec <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xed <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xee <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xef <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xfa <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _SMALLINTEGER <br/> 0xfb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEYS <br/> 0xfc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEYHASH <br/> 0xfd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEY <br/> 0xfe <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _INVALIDOPCODE <br/> 0xff <br/><br />
|}<br><br />
Except later pseudo-opcode changes, the definition of OP_NOP1 - OP_NOP10 and the change of the evaluation of OP_RETURN (did no invalidation previously) which both occured in bitcoin version 0.3.6 in July 2010 were the last changes regarding opcodes <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.2.0/bitcoin-0.2.0-linux.tar.gz file src/srcipt.cpp in bitcoin-0.2.0]</ref> <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.3.3/bitcoin-0.3.3-linux.tar.gz file src/srcipt.cpp in bitcoin-0.3.3]</ref> <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.3.6/bitcoin-0.3.6-linux.tar.gz file src/srcipt.cpp in bitcoin-0.3.6]</ref>.<br />
<br />
== Opcode descriptions ==<br />
It follows for each opcode less than decimal 185 (hexa 0xba) a description for its usage. The columns entitled ''nemonic'', ''decimal'' and ''Hex'' should be evident. The column ''input'' gives the needed items of the stack (and the alternate stack) and the column ''output'' indicates the resulting items on the stack (and the alternate stack). The naming of the entries in these two columns is chosen to reflect their interpretation. ''x'',''x0'',''x1'',... means arbitrary or no interpretation, ''a'', ''b'' and ''c'' as a signed integer value, ''n'',''index'',''size'' and ''depth'' non-negative integer values, ''Boolean'' as either a true or false.<br><br />
Some of the more complicated opcodes are disabled out of concern that the client might have (and has) a bug in the current implementation due to the historically not as 2-complement interpretations of the byte vectors as numerical values (the most significant byte holds the sign of the byte vectors).<br />
<br />
=== Push data from instruction onto stack ===<br />
<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_FALSE, OP_0<br />
|0<br />
|0x00<br />
|Nothing<br />
|Empty string<br />
|A byte vector of length 0 is pushed onto the stack. (Thus, it is not a no-op!)<br />
|-<br />
|(no official nemonics)<br />
|1 - 75<br />
|0x01 - 0x4b<br />
|(operand)<br />
|x<br />
|The next <opcode>-many bytes are to be pushed onto the stack.<br />
|-<br />
|OP_PUSHDATA1<br />
|76<br />
|0x4c<br />
|(operands)<br />
|x<br />
|The next byte contains the number of bytes to be pushed onto the stack which follow this byte.<br />
|-<br />
|OP_PUSHDATA2<br />
|77<br />
|0x4d<br />
|(operands)<br />
|x<br />
|The next two bytes contain the number of bytes to be pushed onto the stack which follow theses 2 bytes.<br />
|-<br />
|OP_PUSHDATA4<br />
|78<br />
|0x4e<br />
|(operands)<br />
|x<br />
|The next four bytes contain the number of bytes to be pushed onto the stack which follow theses 4 bytes.<br />
|-<br />
|OP_1NEGATE<br />
|79<br />
|0x4f<br />
|Nothing<br />
| -1<br />
|The byte with value -1 is pushed onto the stack.<br />
|-<br />
|OP_1, OP_TRUE<br />
|81<br />
|0x51<br />
|Nothing<br />
|1<br />
|The byte with value 1 is pushed onto the stack.<br />
|-<br />
|OP_2 - OP_16<br />
|82 - 96<br />
|0x52 - 0x60<br />
|Nothing<br />
|2-16<br />
|The byte with value <opcode>-80 (thus, one of 2 - 16) is pushed onto the stack.<br />
|}<br />
<br />
=== Flow control ===<br />
<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_NOP<br />
|97<br />
|0x61<br />
|Nothing<br />
|Nothing<br />
|Does nothing.<br />
|-<br />
|OP_IF<br />
|99<br />
|0x63<br />
|Boolean<br />
|Nothing<br />
|If the top stack value is not 0, the statements are executed. The top stack value is removed. Lead in a logcial ''<value> then [statements] [else [statements]] endif'' expression<br />
|-<br />
|OP_NOTIF<br />
|100<br />
|0x64<br />
|Boolean<br />
|Nothing<br />
|If the top stack value is 0, the statements are executed. The top stack value is removed. Lead in a logcial ''<value> then [statements] [else [statements]] endif'' expression <br />
|-<br />
|OP_ELSE<br />
|103<br />
|0x67<br />
|Nothing<br />
|Nothing<br />
|If the preceeding OP_IF or OP_NOTIF or OP_ELSE was not executed then these statements are and if the preceding OP_IF or OP_NOTIF or OP_ELSE was executed then these statements are not. <br />
|-<br />
|OP_ENDIF<br />
|104<br />
|0x68<br />
|Nothing<br />
|Nothing<br />
|Ends a logcial ''If <value> then [statements] [else [statements]] '' expression<br />
|-<br />
|OP_VERIFY<br />
|105<br />
|0x69<br />
|Boolean<br />
|Nothing / False<br />
|If top stack value is not true then marks transaction as '''invalid''' . A value true is removed, but false is not.<br />
|-<br />
|OP_RETURN<br />
|106<br />
|0x6a<br />
|Nothing<br />
|Nothing<br />
|Marks transaction as '''invalid'''. <br />
|}<br />
<br />
===Stack item organization===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_TOALTSTACK<br />
|107<br />
|0x6b<br />
|x1 (alt)<br />
|(alt x1)<br />
|Puts the input onto the top of the alt stack. Removes it from the (main) stack.<br />
|-<br />
|OP_FROMALTSTACK<br />
|108<br />
|0x6c<br />
|(alt x1)<br />
|x1 (alt)<br />
|Puts the input onto the top of the (main) stack. Removes it from the alt stack.<br />
|-<br />
|OP_2DROP<br />
|109<br />
|0x6d<br />
|x1 x2<br />
|Nothing<br />
|Removes the top two stack items.<br />
|-<br />
|OP_2DUP<br />
|110<br />
|0x6e<br />
|x1 x2<br />
|x1 x2 x1 x2<br />
|Duplicates the top two stack items.<br />
|-<br />
|OP_3DUP<br />
|111<br />
|0x6f<br />
|x1 x2 x3<br />
|x1 x2 x3 x1 x2 x3<br />
|Duplicates the top three stack items.<br />
|-<br />
|OP_2OVER<br />
|112<br />
|0x70<br />
|x1 x2 x3 x4<br />
|x1 x2 x3 x4 x1 x2<br />
|Copies the pair of items two spaces back in the stack to the front.<br />
|-<br />
|OP_2ROT<br />
|113<br />
|0x71<br />
|x1 x2 x3 x4 x5 x6<br />
|x3 x4 x5 x6 x1 x2<br />
|The fifth and sixth items back are moved to the top of the stack.<br />
|-<br />
|OP_2SWAP<br />
|114<br />
|0x72<br />
|x1 x2 x3 x4<br />
|x3 x4 x1 x2<br />
|Swaps the top two pairs of items.<br />
|-<br />
|OP_IFDUP<br />
|115<br />
|0x73<br />
|x<br />
|x / x x<br />
|If the top stack value is not 0, duplicate it.<br />
|-<br />
|OP_DEPTH<br />
|116<br />
|0x74<br />
|Nothing<br />
|depth<br />
|Puts the number of stack items onto the stack as one little-endian coded byte-vector<br />
|-<br />
|OP_DROP<br />
|117<br />
|0x75<br />
|x<br />
|Nothing<br />
|Removes the top stack item.<br />
|-<br />
|OP_DUP<br />
|118<br />
|0x76<br />
|x<br />
|x x<br />
|Duplicates the top stack item.<br />
|-<br />
|OP_NIP<br />
|119<br />
|0x77<br />
|x1 x2<br />
|x2<br />
|Removes the second-to-top stack item.<br />
|-<br />
|OP_OVER<br />
|120<br />
|0x78<br />
|x1 x2<br />
|x1 x2 x1<br />
|Copies the second-to-top stack item to the top.<br />
|-<br />
|OP_PICK<br />
|121<br />
|0x79<br />
|xn ... x2 x1 x0 <n><br />
|xn ... x2 x1 x0 xn<br />
|The item ''n'' back in the stack is copied to the top.<br />
|-<br />
|OP_ROLL<br />
|122<br />
|0x7a<br />
|xn ... x2 x1 x0 <n><br />
|... x2 x1 x0 xn<br />
|The item ''n'' back in the stack is moved to the top.<br />
|-<br />
|OP_ROT<br />
|123<br />
|0x7b<br />
|x1 x2 x3<br />
|x2 x3 x1<br />
|The top three items on the stack are rotated to the left.<br />
|-<br />
|OP_SWAP<br />
|124<br />
|0x7c<br />
|x1 x2<br />
|x2 x1<br />
|The top two items on the stack are swapped.<br />
|-<br />
|OP_TUCK<br />
|125<br />
|0x7d<br />
|x1 x2<br />
|x2 x1 x2<br />
|The item at the top of the stack is copied and inserted before the second-to-top item.<br />
|}<br />
<br />
=== Splice ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_CAT<br />
|126<br />
|0x7e<br />
|x1 x2<br />
|out<br />
|Concatenates two strings resp. byte vectors. ''Currently disabled.''<br />
|-<br />
|OP_SUBSTR<br />
|127<br />
|0x7f<br />
|x index size<br />
|out<br />
|Returns the section started at position <index> and of length <size> of a string resp. byte vector. ''Currently disabled.''<br />
|-<br />
|OP_LEFT<br />
|128<br />
|0x80<br />
|x index<br />
|out<br />
|Keeps only characters left of the specified point in a string. ''Currently disabled.''<br />
|-<br />
|OP_RIGHT<br />
|129<br />
|0x81<br />
|x index<br />
|out<br />
|Keeps only characters right of the specified point in a string. ''Currently disabled.''<br />
|-<br />
|OP_SIZE<br />
|130<br />
|0x82<br />
|x<br />
|x size<br />
|Returns the length of the input string resp. byte vector resp. stack item.<br />
|}<br />
<br />
=== Bitwise logic ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_INVERT<br />
|131<br />
|0x83<br />
|x1<br />
|x0<br />
|Flips all of the bits in the input. ''Currently disabled.''<br />
|-<br />
|OP_AND<br />
|132<br />
|0x84<br />
|x1 x2<br />
|x0<br />
|Boolean ''and'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_OR<br />
|133<br />
|0x85<br />
|x1 x2<br />
|x0<br />
|Boolean ''or'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_XOR<br />
|134<br />
|0x86<br />
|x1 x2<br />
|x0<br />
|Boolean ''exclusive or'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_EQUAL<br />
|135<br />
|0x87<br />
|x1 x2<br />
|Boolean<br />
|Returns 1 if the inputs are byte-wise equal, 0 otherwise.<br />
|-<br />
|OP_EQUALVERIFY<br />
|136<br />
|0x88<br />
|x1 x2<br />
|Nothing / false<br />
|Same as OP_EQUAL, but runs OP_VERIFY afterward.<br />
|}<br />
<br />
=== Arithmetic ===<br />
<br />
(In very early versions, the implemented arithmetic opcodes were limited to maximal 4 byte vectors.)<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_1ADD<br />
|139<br />
|0x8b<br />
|a<br />
|c<br />
|1 is added to the input.<br />
|-<br />
|OP_1SUB<br />
|140<br />
|0x8c<br />
|a<br />
|c<br />
|1 is subtracted from the input.<br />
|-<br />
|OP_2MUL<br />
|141<br />
|0x8d<br />
|a<br />
|c<br />
|The input is multiplied by 2. ''Currently disabled.''<br />
|-<br />
|OP_2DIV<br />
|142<br />
|0x8e<br />
|a<br />
|c<br />
|The input is divided by 2. ''Currently disabled.''<br />
|-<br />
|OP_NEGATE<br />
|143<br />
|0x8f<br />
|a<br />
|c<br />
|The sign of the input is flipped. Numerically the value is multiplied by -1<br />
|-<br />
|OP_ABS<br />
|144<br />
|0x90<br />
|a<br />
|c<br />
|The input is negative, its sign is flipped.<br />
|-<br />
|OP_NOT<br />
|145<br />
|0x91<br />
|a<br />
|Boolean<br />
|If the input is 0 or 1, it is flipped. Otherwise the output will be 0. Test whether its value equals 0<br />
|-<br />
|OP_0NOTEQUAL<br />
|146<br />
|0x92<br />
|a<br />
|Boolean<br />
|Returns 0 if the input is 0. 1 otherwise. Test whether its value is unequal 0<br />
|-<br />
|OP_ADD<br />
|147<br />
|0x93<br />
|a b<br />
|c<br />
|a is added to b.<br />
|-<br />
|OP_SUB<br />
|148<br />
|0x94<br />
|a b<br />
|c<br />
|b is subtracted from a.<br />
|-<br />
|OP_MUL<br />
|149<br />
|0x95<br />
|a b<br />
|c<br />
|a is multiplied by b. ''Currently disabled.''<br />
|-<br />
|OP_DIV<br />
|150<br />
|0x96<br />
|a b<br />
|c<br />
|a is divided by b (b should be not 0). ''Currently disabled.''<br />
|-<br />
|OP_MOD<br />
|151<br />
|0x97<br />
|a b<br />
|c<br />
|Returns the remainder after dividing a by b (b should be not 0). ''Currently disabled.''<br />
|-<br />
|OP_LSHIFT<br />
|152<br />
|0x98<br />
|a b<br />
|c<br />
|Shifts a left by b bits, preserving sign. ''Currently disabled.''<br />
|-<br />
|OP_RSHIFT<br />
|153<br />
|0x99<br />
|a b<br />
|c<br />
|Shifts a right by b bits, preserving sign. ''Currently disabled.''<br />
|-<br />
|OP_BOOLAND<br />
|154<br />
|0x9a<br />
|a b<br />
|Boolean<br />
|If both a and b are not 0, the output is 1. Otherwise 0.<br />
|-<br />
|OP_BOOLOR<br />
|155<br />
|0x9b<br />
|a b<br />
|Boolean<br />
|If a or b is not 0, the output is 1. Otherwise 0.<br />
|-<br />
|OP_NUMEQUAL<br />
|156<br />
|0x9c<br />
|a b<br />
|Boolean<br />
|Returns 1 if the numbers are equal, 0 otherwise.<br />
|-<br />
|OP_NUMEQUALVERIFY<br />
|157<br />
|0x9d<br />
|a b<br />
|Nothing / False<br />
|Same as OP_NUMEQUAL, but runs OP_VERIFY afterward.<br />
|-<br />
|OP_NUMNOTEQUAL<br />
|158<br />
|0x9e<br />
|a b<br />
|Boolean<br />
|Returns 1 if the numbers are not equal, 0 otherwise.<br />
|-<br />
|OP_LESSTHAN<br />
|159<br />
|0x9f<br />
|a b<br />
|Boolean<br />
|Returns 1 if a is less than b, 0 otherwise.<br />
|-<br />
|OP_GREATERTHAN<br />
|160<br />
|0xa0<br />
|a b<br />
|Boolean<br />
|Returns 1 if a is greater than b, 0 otherwise.<br />
|-<br />
|OP_LESSTHANOREQUAL<br />
|161<br />
|0xa1<br />
|a b<br />
|Boolean<br />
|Returns 1 if a is less than or equal to b, 0 otherwise.<br />
|-<br />
|OP_GREATERTHANOREQUAL<br />
|162<br />
|0xa2<br />
|a b<br />
|Boolean<br />
|Returns 1 if a is greater than or equal to b, 0 otherwise.<br />
|-<br />
|OP_MIN<br />
|163<br />
|0xa3<br />
|a b<br />
|a / b<br />
|Returns the smaller of a and b.<br />
|-<br />
|OP_MAX<br />
|164<br />
|0xa4<br />
|a b<br />
| a / b<br />
|Returns the larger of a and b.<br />
|-<br />
|OP_WITHIN<br />
|165<br />
|0xa5<br />
|x min max<br />
|Boolean<br />
|Returns 1 if x is within the specified range (left-inclusive) , 0 otherwise. min may be greater than max<br />
|}<br />
<br />
=== Crypto ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_RIPEMD160<br />
|166<br />
|0xa6<br />
|x<br />
|hash20<br />
|The input is hashed using RIPEMD-160.<br />
|-<br />
|OP_SHA1<br />
|167<br />
|0xa7<br />
|x<br />
|hash20<br />
|The input is hashed using SHA-1.<br />
|-<br />
|OP_SHA256<br />
|168<br />
|0xa8<br />
|x<br />
|hash32<br />
|The input is hashed using SHA-256.<br />
|-<br />
|OP_HASH160<br />
|169<br />
|0xa9<br />
|x<br />
|hash20<br />
|The input is hashed twice: first with SHA-256 and then with RIPEMD-160.<br />
|-<br />
|OP_HASH256<br />
|170<br />
|0xaa<br />
|x<br />
|hash32<br />
|The input is hashed two times with SHA-256.<br />
|-<br />
|OP_CODESEPARATOR<br />
|171<br />
|0xab<br />
|Nothing<br />
|Nothing<br />
|All of the signature checking opcodes will only match signatures to the data after the most recently-executed OP_CODESEPARATOR.<br />
|-<br />
|[[OP_CHECKSIG]]<br />
|172<br />
|0xac<br />
|sig pubkey<br />
|Boolean<br />
|The entire transaction's outputs, inputs, and script (from the most recently-executed OP_CODESEPARATOR to the end) are hashed. The signature used by OP_CHECKSIG must be a valid signature for a further, extern specified hash and the given public key. If it is, 1 is returned, 0 otherwise.<br />
|-<br />
|OP_CHECKSIGVERIFY<br />
|173<br />
|0xad<br />
|sig pubkey<br />
|Nothing / False<br />
|Same as OP_CHECKSIG, but OP_VERIFY is executed afterward.<br />
|-<br />
|OP_CHECKMULTISIG<br />
|174<br />
|0xae<br />
|sig1 sig2 ... <number of signatures> pub1 pub2 <number of public keys><br />
|Boolean<br />
|For each signature and public key pair, OP_CHECKSIG is executed. If more public keys than signatures are listed, some key/sig pairs can fail. All signatures need to match a public key. If all signatures are valid, 1 is returned, 0 otherwise. Due to a bug, one extra unused value is removed from the stack.<br />
|-<br />
|OP_CHECKMULTISIGVERIFY<br />
|175<br />
|0xaf<br />
|sig1 sig2 ... <number of signatures> pub1 pub2 ... <number of public keys><br />
|Nothing / False<br />
|Same as OP_CHECKMULTISIG, but OP_VERIFY is executed afterward.<br />
|}<br />
<br />
=== Expansion opcodes ===<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_NOP1-OP_NOP10<br />
|176-185<br />
|0xb0-0xb9<br />
|The opcode has no effect.<br />
|}<br />
<br />
=== Version opcodes ===<br />
Version opcodes are disabled since bitcoin 0.2.0 and should not be used (maybe reassigned in the future).<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_VER<br />
|98<br />
|0x62<br />
|Script evalution is triggered invalid (Formerly pushed the bitcoin-serialize version onto stack).<br />
|-<br />
|OP_VERIF<br />
|101<br />
|0x65<br />
|Script evalution is triggered invalid (Formerly top stack item was popped and =< compared to present version)<br />
|-<br />
|OP_VERNOTIF<br />
|102<br />
|0x66<br />
|Script evalution is triggered invalid (Formerly top stack item was popped and > compared to present version)<br />
|}<br />
<br />
=== Reserved opcodes ===<br />
Each opcode not assigned (currently also every opcode value > 185) is also reserved. Using any unassigned opcode triggers the script evaluation to be invalid.<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_RESERVED<br />
|80<br />
|0x50<br />
|Script evalution is triggered invalid-<br />
|-<br />
|OP_RESERVED1<br />
|137<br />
|0x89<br />
|Script evalution is triggered invalid.<br />
|-<br />
|OP_RESERVED2<br />
|138<br />
|0x8a<br />
|Script evalution is triggered invalid.<br />
|}<br />
<br />
===Pseudo-opcodes===<br />
These nemonics are used internally for assisting with transaction matching. They are invalid if used in actual scripts.<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_PUBKEYHASH<br />
|253<br />
|0xfd<br />
|Represents a public key hashed with OP_HASH160.<br />
|-<br />
|OP_PUBKEY<br />
|254<br />
|0xfe<br />
|Represents a public key compatible with OP_CHECKSIG.<br />
|-<br />
|OP_INVALIDOPCODE<br />
|255<br />
|0xff<br />
|Matches any opcode that is not yet assigned.<br />
|}<br />
<br />
==Scripts in bitcoin transactions==<br />
It follows a list of important (most occuring) scripts to see opcodes "at work". Keep in mind that all constants actually use the data-pushing instructions above. At start of a (transaction input) script evaluation, the stack is always empty. <br />
<br />
===Standard transaction to bitcoin address===<br />
<br />
scriptPubKey: OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG<br />
scriptSig: <sig> <pubKey><br />
<br />
To demonstrate how scripts look on the wire, here is a raw scriptPubKey:<br />
<pre> 76 A9 14<br />
OP_DUP OP_HASH160 Bytes to push<br />
<br />
89 AB CD EF AB BA AB BA AB BA AB BA AB BA AB BA AB BA AB BA 88 AC<br />
Data to push OP_EQUALVERIFY OP_CHECKSIG</pre><br />
<br />
Note: scriptSig is in the input of the spending transaction and scriptPubKey is in the output of the previously storing transaction, i.e. its "available bitcoins".<br />
<br />
Here is how each instruction is processed:<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
| <sig> <pubKey> OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| scriptSig and scriptPubKey are combined.<br />
|-<br />
|<sig> <pubKey><br />
| OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| Constants are added to the stack.<br />
|-<br />
|<sig> <pubKey> <pubKey><br />
| OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| Top stack item is duplicated.<br />
|-<br />
|<sig> <pubKey> <pubHashA><br />
|<pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG<br />
| Top stack item is hashed.<br />
|-<br />
|<sig> <pubKey> <pubHashA> <pubKeyHash><br />
|OP_EQUALVERIFY OP_CHECKSIG<br />
| Constant added.<br />
|-<br />
|<sig> <pubKey><br />
|OP_CHECKSIG<br />
| Equality is checked between the top two stack items.<br />
|-<br />
|true<br />
|Empty.<br />
|Signature is checked for top two stack items.<br />
|}<br />
<br />
===Transaction to IP address (and generation transaction)===<br />
<br />
scriptPubKey: <pubKey> OP_CHECKSIG<br />
scriptSig: <sig><br />
<br />
Checking process:<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
|<sig> <pubKey> OP_CHECKSIG<br />
|scriptSig and scriptPubKey are combined.<br />
|-<br />
|<sig> <pubKey><br />
| OP_CHECKSIG<br />
|Constants are added to the stack.<br />
|-<br />
|true<br />
|Empty.<br />
|Signature is checked for top two stack items.<br />
|}<br />
<br />
In the case of a '''coin generation transaction''' (the first transaction of each block), there is no scriptSig, resp. its code ("coinbase") is completly ignored for the transaction. Only the scriptPubKey is used.<br />
<br />
===Transaction with a message===<br />
<br />
It's possible to add arbitrary data to any transaction by just adding some data along with OP_DROP. <br />
scriptPubKey: <message> OP_DROP <pubKey> OP_CHECKSIG<br />
scriptSig: <sig><br />
<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
|<sig> <message> OP_DROP <pubKey> OP_CHECKSIG<br />
|<br />
|-<br />
|<sig><br />
|<message> OP_DROP <pubKey> OP_CHECKSIG<br />
|scriptSig added to the stack.<br />
|-<br />
|<sig> <message><br />
|OP_DROP <pubKey> OP_CHECKSIG<br />
|The message has been put.<br />
|-<br />
|<sig><br />
|<pubKey> OP_CHECKSIG<br />
|Top stack item has been removed.<br />
|-<br />
|<sig> <pubKey><br />
|OP_CHECKSIG<br />
|Checking signature against the public key.<br />
|-<br />
|true<br />
|Empty.<br />
|Stack holds the value of signature check now.<br />
|}<br />
<br />
===Examples of non standard transaction on Testnet===<br />
<br />
These two links below show a non standard transaction. It just prepends the hex of "bob" and the operation OP_DROP<br />
which just removes it. As you can see they can be spent as normal.<br />
<br />
Input non-std transaction:<br />
http://blockexplorer.com/testnet/t/6ttfeb55B1<br />
<br />
Spent by:<br />
http://blockexplorer.com/testnet/t/AFdRB1CHS3<br />
<br />
==Script validation==<br />
A script evaluation is considered invalid, if any of these conditions meets:<br><br />
<ul><br />
<li>the total size of the script exceeds (currently) 10000 bytes<br />
<li>there are more than (currently) 201 opcodes of opcode value > 0x60 in the script<br />
<li>each instruction is (currently) limited to maximal 520 bytes. This effects only the opcodes OP_PUSHDATA2 and OP_PUSHDATA4<br />
<li>the executed opcode of the script has insufficient input (from stack, from script or from anywhere)<br />
<li>the opcode is not defined (for execution) - indicated by white or light gray background color in the table<br />
<li>the opcode is disabled (currently 15 opcodes) - indicated by white font color in the opcode overview matrix<br />
<li>stack overflow occurs during execution of the opcode (currently the number of items on the stack and on the alternate stack is limited to 1000)<br />
<li>the opcodes OP_VERIF and OP_NOTVERIF invalidate a script which contains this opcode (even if this opcode is not executed!)<br />
<li>the opcodes OP_ELSE or OP_ENDIF has no matching OP_IF<br><br />
<li>the script execution has been finished but there is (at least) an unmatched OP_IF<br><br />
<li>the opcodes OP_VERIFY, OP_EQUALVERIFY, OP_NUMEQUALVERIFY, OP_CHECKSIGVERIFY and OP_CHECKMULTISIGVERIFY invalidate the script if the stack-top item is false<br />
<li>the execution of OP_RETURN<br />
<!--li>alt stack overflow occurs (only possible during execution of OP_TOALTSTACK)--><br />
<li>the numerical value of the top-stack item is negative or greater than the number of items - 2 on the stack if OP_PICK or OP_ROLL shall be executed<br />
<li>an item used as public key or signature for each of the opcodes OP_CHECKSIG, OP_CHECKSIGVERIFY, OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY can be neither a public key or signature (for the given hash)<br />
<li>the number of signature items or the number of public key items on the stack is negative for OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY<br />
<li>there or more signatures items than public key items on the stack for OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY<br />
<li>there are (currently) more than 20 public key items on the stack for OP_CHECKMULTISIG or CHECKMULTISIGVERIFY<br />
<li>the sum of opcodes > 0x60 and the number of public keys in all executed OP_CHECKMULTISIG or CHECKMULTISIGVERIFY exceeds (currently) 201<br />
<li>the script execution has been finished and the stack is empty or the top-stack item is false (numerical value 0)<br />
</ul><br />
else the script evaluation is considered to be valid.<ref>[http://sourceforge.net/projects/bitcoin/files/Bitcoin/bitcoin-0.7.1/bitcoin-0.7.1-linux.tar.gz file src/src/script.cpp in bitcoin-0.7.1]</ref><br />
'''If invalidation of a script is triggered then the script is immediately finished.''' These arbitrary looking limitations of 10000, 201, 520, 1000 and 20 might be increased in the future -- they serve to prevent strong slow down of the evaluation of a script while not restricting its practical usage really.<br />
<br />
==Withdrawn and drafted opcodes==<br />
<br />
<ul><br />
<li> byte value 0x89 [[OP_NOTEQUAL]] defined in pre-0.1.0 bitcoin versions. Since 0.1.0 removed because of security concerns. <br />
<li> byte value 0xb1 [[BIP 0012 | OP_EVAL]] withdraw - poll was triggered but insufficient support. <br />
<li> byte value 0xb2 [[BIP 0017 | OP_CHECKHASHVERIFY]] withdraw - poll was triggered but insufficient support.<br />
</ul><br />
<br />
==See Also==<br />
* [[Transactions]]<br />
* [[Contracts]]<br />
<br />
==References==<br />
<references/><br />
<ul><br />
<li>[http://www.zorinaq.com/pub/bitcoin-0.1.0.tgz file src/script.cpp in bitcoin-0.1.0]</li><br />
</ul><br />
[[Category:Technical]]<br />
[[Category:Vocabulary]]</div>
Smtp
https://en.bitcoin.it/w/index.php?title=Script&diff=34853
Script
2013-01-09T16:59:04Z
<p>Smtp: /* See Also */</p>
<hr />
<div>Bitcoin uses a scripting system for [[transactions]]. [[Wikipedia:FORTH|Forth]]-like, Script is simple, stack-based, and processed from left to right. It is purposefully not Turing-complete, with no loops.<br />
<br />
A script is essentially a list of instructions recorded with each transaction that describe how the next person wanting to spend the Bitcoins being transferred can gain access to them.<br />
<br />
Scripts are big-endian and their sequences of bytes is interpreted as a sequence of opcodes with operands. Only opcodes with byte values less than 0x4f have additional operands.<br />
<br />
== Scripts and Bitcoin transactions ==<br />
The script for a typical Bitcoin transfer to destination Bitcoin address D simply encumbers future spending of the bitcoins with two things: the spender must provide<br />
# a public key that, when hashed, yields destination address D embedded in the script, and<br />
# a signature to show evidence of the private key corresponding to the public key just provided.<br />
<br />
Scripting provides the flexibility to change the parameters of what's needed to spend transferred Bitcoins. For example, the scripting system could be used to require two private keys, or a combination of several, or even no keys at all.<br />
<br />
A transaction is valid if nothing in the combined script triggers failure and the top stack item exists and is true (non-zero). The party who originally ''stored'' the Bitcoins now being spent, dictates the script operations that will occur ''last'' in order to release them for use in another transaction. The party wanting to spend them must provide the input(s) to the previously recorded script that results in those operations occurring last leaving behind true (non-zero) on the stack.<br><br />
Only the very first transaction in each bitcoin block has no input script (the entry there is called "coinbase"), because the Bitcoins created with the block are created from hot air and not released by a previous recorded script.<br />
<br />
== Stack ==<br />
<br />
The stacks hold byte vectors (there is the (main) stack and an alternative stack). Byte vectors are interpreted as little-endian variable-length integers with the most significant bit determining the sign of the integer. Thus 0x81 represents -1. 0x80 is another representation of zero (so called negative 0). Byte vectors are interpreted as Booleans where False is represented by any representation of zero, and True is represented by any representation of non-zero.<br />
<br />
== Opcode overview ==<br />
<br />
For each opcode is given: its nemonic without the leading OP_, its hexadecimal byte value, the number of stack items needed (poped) during execution, a semicolon and the number of stack items which has been pushed (after execution). A * after the needed stack items indicates that further bytes from the script following the current opcode are needed. A # indicates that items on the alternative stack are poped/pushed. A @ indicates that further (global) data from the transaction is needed. A / indicates alternatives of a value. <br/><br />
Different colors indicate different semantic execution groups of opcodes:<br />
{| style="background:none; font-size:100%; padding:0; border-collapse:collapse; text-align:center; line-height:2em;" border="0" align="center" <br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | copy a fixed number of bytes but at most 75 onto stack<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | copy bytes onto stack which number is given by a 1, 2 or 4 byte value.<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | copy 1 specific byte onto stack<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | undefined opcode<br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | a pseudo-opcode, unassigned for scripts<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | NOP or opcode is part of a IF-flow-control construction<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00ff00;" | (stack conditionally) invalidation of the script this opcode is part of<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | stack item is moved between main stack and alternate stack<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | stack item(s) is/are moved, copied or deleted<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0;" | byte vectors are appended or divided or their size is determined<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff;" | byte vectors are interpreted bit-position-independently<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | byte vectors are interpreted and processed as signed integers<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | a hash value is computed or a signature checked<br />
|}<br />
<p><br />
===Opcode byte-matrix===<br />
The opcode value 0x00 with nemonic OP_FALSE is also named OP_0 and the opcode value 0x51 with nemonic OP_1 as also named OP_TRUE.<br />
{| style="background:none; font-size:100%; padding:0; border-collapse:collapse; text-align:center; line-height:2em;" border="0" align="center" <br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" |_FALSE<br/> 0x00 <br/> 0 ; 1(0) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x01<br/> 0 *; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x02<br/> 0 *; 1(2)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x03<br/> 0 *; 1(3)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x04<br/> 0 *; 1(4)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x04<br/> 0 *; 1(5)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x06<br/> 0 *; 1(6)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x07<br/> 0 *; 1(7)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x08<br/> 0 *; 1(8)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x09<br/> 0 *; 1(9)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0a<br/> 0 *; 1(10)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0b<br/> 0 *; 1(11)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0c<br/> 0 *; 1(12)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0d<br/> 0 *; 1(13)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0e<br/> 0 *; 1(14)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x0f<br/> 0 *; 1(15)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x10 <br/> 0 *; 1(16) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x11 <br/> 0 *; 1(17)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x12 <br/> 0 *; 1(18)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x13 <br/> 0 *; 1(19)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x14 <br/> 0 *; 1(20)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x15 <br/> 0 *; 1(21)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x16 <br/> 0 *; 1(22)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x17 <br/> 0 *; 1(23)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x18 <br/> 0 *; 1(24)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x19 <br/> 0 *; 1(25)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1a <br/> 0 *; 1(26)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1b <br/> 0 *; 1(27)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1c <br/> 0 *; 1(28)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1d <br/> 0 *; 1(29)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1e <br/> 0 *; 1(30)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x1f <br/> 0 *; 1(31)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x20 <br/> 0 *; 1(32) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x21 <br/> 0 *; 1(33)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x22 <br/> 0 *; 1(34)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x23 <br/> 0 *; 1(35)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x24 <br/> 0 *; 1(36)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x25 <br/> 0 *; 1(37)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x26 <br/> 0 *; 1(38)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x27 <br/> 0 *; 1(39)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x28 <br/> 0 *; 1(40)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x29 <br/> 0 *; 1(41)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2a <br/> 0 *; 1(42)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2b <br/> 0 *; 1(43)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2c <br/> 0 *; 1(44)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2d <br/> 0 *; 1(45)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2e <br/> 0 *; 1(46)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x2f <br/> 0 *; 1(47)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x30 <br/> 0 *; 1(48) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x31 <br/> 0 *; 1(49)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x32 <br/> 0 *; 1(50)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x33 <br/> 0 *; 1(51)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x34 <br/> 0 *; 1(52)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x35 <br/> 0 *; 1(53)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x36 <br/> 0 *; 1(54)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x37 <br/> 0 *; 1(55)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x38 <br/> 0 *; 1(56)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x39 <br/> 0 *; 1(57)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3a <br/> 0 *; 1(58)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3b <br/> 0 *; 1(59)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3c <br/> 0 *; 1(60)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3d <br/> 0 *; 1(61)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3e <br/> 0 *; 1(62)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x3f <br/> 0 *; 1(63)<br />
|- <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x40 <br/> 0 *; 1(64) <br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x41 <br/> 0 *; 1(65)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x42 <br/> 0 *; 1(66)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x43 <br/> 0 *; 1(67)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x44 <br/> 0 *; 1(68)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x45 <br/> 0 *; 1(69)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x46 <br/> 0 *; 1(70)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x47 <br/> 0 *; 1(71)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x48 <br/> 0 *; 1(72)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x49 <br/> 0 *; 1(73)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x4a <br/> 0 *; 1(74)<br />
| style="border:1px solid #aaaaaa; background-color:gold;" | - <br/> 0x4b <br/> 0 *; 1(75)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA1 <br/> 0x4c <br/> 0 *; 1(0 - 255)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA2 <br/> 0x4d <br/> 0 *; 1(0 - 2^16-1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffff00;" | _PUSHDATA4 <br/> 0x4e <br/> 0 *; 1(0 - 2^32-1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _1NEGATE <br/> 0x4f <br/> 0 ; 1(1)<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED <br/> 0x50 <br/> <br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _1 <br/> 0x51 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _2 <br/> 0x52 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _3 <br/> 0x53 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _4 <br/> 0x54 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _5 <br/> 0x55 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _6 <br/> 0x56 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _7 <br/> 0x57 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _8 <br/> 0x58 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _9 <br/> 0x59 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _10 <br/> 0x5a <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _11 <br/> 0x5b <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _12 <br/> 0x5c <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _13 <br/> 0x5d <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _14 <br/> 0x5e <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _15 <br/> 0x5f <br/> 0 ; 1(1)<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffb000;" | _16 <br/> 0x60 <br/> 0 ; 1(1)<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP <br/> 0x61 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VER <br/> 0x62 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _IF <br/> 0x63 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOTIF <br/> 0x64 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VERIF <br/> 0x65 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _VERNOTIF <br/> 0x66 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _ELSE <br/> 0x67 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _ENDIF <br/> 0x68 <br/> 0 ; 0<br />
| style="border:3px solid #808080; background-color:#00ff00;" | _VERIFY <br/> 0x69 <br/> 1 ; 0/1<br />
| style="border:3px solid #808080; background-color:#00ff00;" | _RETURN <br/> 0x6a <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | _TOALTSTACK <br/> 0x6b <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff8080;" | _FROMALTSTACK <br/> 0x6c <br/> 0 #; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2DROP <br/> 0x6d <br/> 2 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2DUP <br/> 0x6e <br/> 2 ; 4<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _3DUP <br/> 0x6f <br/> 3 ; 6<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2OVER <br/> 0x70 <br/> 4 ; 6<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2ROT <br/> 0x71 <br/> 6 ; 6<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _2SWAP <br/> 0x72 <br/> 4 ; 4<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _IFDUP <br/> 0x73 <br/> 1 ; 1/2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DEPTH <br/> 0x74 <br/> 0 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DROP <br/> 0x75 <br/> 1 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _DUP <br/> 0x76 <br/> 1 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _NIP <br/> 0x77 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _OVER <br/> 0x78 <br/> 2 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _PICK <br/> 0x79 <br/> 1+n+1 ; n+2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _ROLL <br/> 0x7a <br/> 1+n+1 ; n+1<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _ROT <br/> 0x7b <br/> 3 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _SWAP <br/> 0x7c <br/> 2 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#ff4040;" | _TUCK <br/> 0x7d <br/> 2 ; 3<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _CAT <br/> 0x7e <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _SUBSTR <br/> 0x7f <br/> 3 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _LEFT <br/> 0x80 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0; color:white" | _RIGHT <br/> 0x81 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#f000f0;" | _SIZE <br/> 0x82 <br/> 1 ; 2<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _INVERT <br/> 0x83 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _AND <br/> 0x84 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _OR <br/> 0x85 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff; color:white" | _XOR <br/> 0x86 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#c000ff;" | _EQUAL <br/> 0x87 <br/> 2 ; 1<br />
| style="border:3px solid #808080; background-color:#c080ff;" | _EQUALVERIFY <br/> 0x88 <br/> 2 ; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED1 <br/> 0x89 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _RESERVED2 <br/> 0x8a <br/><br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _1ADD <br/> 0x8b <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _1SUB <br/> 0x8c <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _2MUL <br/> 0x8d <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _2DIV <br/> 0x8e <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NEGATE <br/> 0x8f <br/> 1 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _ABS <br/> 0x90 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NOT <br/> 0x91 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _0NOTEQUAL <br/> 0x92 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _ADD <br/> 0x93 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _SUB <br/> 0x94 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _MUL <br/> 0x95 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _DIV <br/> 0x96 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _MOD <br/> 0x97 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _LSHIFT <br/> 0x98 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff; color:white" | _RSHIFT <br/> 0x99 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _BOOLAND <br/> 0x9a <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _BOOLOR <br/> 0x9b <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NUMEQUAL <br/> 0x9c <br/> 2 ; 1<br />
| style="border:3px solid #808080; background-color:#8080ff;" | _NUMEQUALVERIFY <br/> 0x9d <br/> 2 ; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _NUMNOTEQUAL <br/> 0x9e <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _LESSTHAN <br/> 0x9f <br/> 2 ; 1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _GREATERTHAN <br/> 0xa0 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _LESSTHANOREQUAL <br/> 0xa1 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _GREATERTHANOREQUAL <br/> 0xa2 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _MIN <br/> 0xa3 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _MAX <br/> 0xa4 <br/> 2 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#8000ff;" | _WITHIN <br/> 0xa5 <br/> 3 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _RIPEMD160 <br/> 0xa6 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _SHA1 <br/> 0xa7 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _SHA256 <br/> 0xa8 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _HASH160 <br/> 0xa9 <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _HASH256 <br/> 0xaa <br/> 1 ; 1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CODESEPARATOR <br/> 0xab <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CHECKSIG <br/> 0xac <br/> 2 @; 1<br />
| style="border:3px solid #808080; background-color:#a0d0ff;" | _CHECKSIGVERIFY <br/> 0xad <br/> 2 @; 0/1<br />
| style="border:1px solid #aaaaaa; background-color:#00c0f0;" | _CHECKMULTISIG <br/> 0xae <br/> 2n+2 @; 1<br />
| style="border:3px solid #808080; background-color:#a0d0ff;" | _CHECKMULTISIGVERIFY <br/> 0xaf <br/> 2n+2 @; 0/1<br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP1 <br/> 0xb0 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP2 <br/> 0xb1 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP3 <br/> 0xb2 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP4 <br/> 0xb3 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP5 <br/> 0xb4 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP6 <br/> 0xb5 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP7 <br/> 0xb6 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP8 <br/> 0xb7 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP9 <br/> 0xb8 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#00d000;" | _NOP10 <br/> 0xb9 <br/> 0 ; 0<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xba <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbe <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xbf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xc9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xca <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xce <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xcf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xd9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xda <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xde <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xdf <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xe9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xea <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xeb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xec <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xed <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xee <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xef <br/><br />
|-<br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf0 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf1 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf2 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf3 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf4 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf5 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf6 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf7 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf8 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xf9 <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | - <br/> 0xfa <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _SMALLINTEGER <br/> 0xfb <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEYS <br/> 0xfc <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEYHASH <br/> 0xfd <br/><br />
| style="border:1px solid #aaaaaa; background-color:#f0f0f0;" | _PUBKEY <br/> 0xfe <br/><br />
| style="border:1px solid #aaaaaa; background-color:#ffffff;" | _INVALIDOPCODE <br/> 0xff <br/><br />
|}<br><br />
Except later pseudo-opcode changes, the definition of OP_NOP1 - OP_NOP10 and the change of the evaluation of OP_RETURN (did no invalidation previously) which both occured in bitcoin version 0.3.6 in July 2010 were the last changes regarding opcodes <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.2.0/bitcoin-0.2.0-linux.tar.gz file src/srcipt.cpp in bitcoin-0.2.0]</ref> <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.3.3/bitcoin-0.3.3-linux.tar.gz file src/srcipt.cpp in bitcoin-0.3.3]</ref> <ref>[http://mirror.transact.net.au/pub/sourceforge/b/project/bi/bitcoin/Bitcoin/bitcoin-0.3.6/bitcoin-0.3.6-linux.tar.gz file src/srcipt.cpp in bitcoin-0.3.6]</ref>.<br />
<br />
== Opcode descriptions ==<br />
It follows for each opcode less than decimal 185 (hexa 0xba) a description for its usage. The columns entitled ''nemonic'', ''decimal'' and ''Hex'' should be evident. The column ''input'' gives the needed items of the stack (and the alternate stack) and the column ''output'' indicates the resulting items on the stack (and the alternate stack). The naming of the entries in these two columns is chosen to reflect their interpretation. ''x'',''x0'',''x1'',... means arbitrary or no interpretation, ''a'', ''b'' and ''c'' as a signed integer value, ''n'',''index'',''size'' and ''depth'' non-negative integer values, ''Boolean'' as either a true or false.<br><br />
Some of the more complicated opcodes are disabled out of concern that the client might have (and has) a bug in the current implementation due to the historically not as 2-complement interpretations of the byte vectors as numerical values (the most significant byte holds the sign of the byte vectors).<br />
<br />
=== Push data from instruction onto stack ===<br />
<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_FALSE, OP_0<br />
|0<br />
|0x00<br />
|Nothing<br />
|Empty string<br />
|A byte vector of length 0 is pushed onto the stack. (Thus, it is not a no-op!)<br />
|-<br />
|(no official nemonics)<br />
|1 - 75<br />
|0x01 - 0x4b<br />
|(operand)<br />
|x<br />
|The next <opcode>-many bytes are to be pushed onto the stack.<br />
|-<br />
|OP_PUSHDATA1<br />
|76<br />
|0x4c<br />
|(operands)<br />
|x<br />
|The next byte contains the number of bytes to be pushed onto the stack which follow this byte.<br />
|-<br />
|OP_PUSHDATA2<br />
|77<br />
|0x4d<br />
|(operands)<br />
|x<br />
|The next two bytes contain the number of bytes to be pushed onto the stack which follow theses 2 bytes.<br />
|-<br />
|OP_PUSHDATA4<br />
|78<br />
|0x4e<br />
|(operands)<br />
|x<br />
|The next four bytes contain the number of bytes to be pushed onto the stack which follow theses 4 bytes.<br />
|-<br />
|OP_1NEGATE<br />
|79<br />
|0x4f<br />
|Nothing<br />
| -1<br />
|The byte with value -1 is pushed onto the stack.<br />
|-<br />
|OP_1, OP_TRUE<br />
|81<br />
|0x51<br />
|Nothing<br />
|1<br />
|The byte with value 1 is pushed onto the stack.<br />
|-<br />
|OP_2 - OP_16<br />
|82 - 96<br />
|0x52 - 0x60<br />
|Nothing<br />
|2-16<br />
|The byte with value <opcode>-80 (thus, one of 2 - 16) is pushed onto the stack.<br />
|}<br />
<br />
=== Flow control ===<br />
<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_NOP<br />
|97<br />
|0x61<br />
|Nothing<br />
|Nothing<br />
|Does nothing.<br />
|-<br />
|OP_IF<br />
|99<br />
|0x63<br />
|Boolean<br />
|Nothing<br />
|If the top stack value is not 0, the statements are executed. The top stack value is removed. Lead in a logcial ''<value> then [statements] [else [statements]] endif'' expression<br />
|-<br />
|OP_NOTIF<br />
|100<br />
|0x64<br />
|Boolean<br />
|Nothing<br />
|If the top stack value is 0, the statements are executed. The top stack value is removed. Lead in a logcial ''<value> then [statements] [else [statements]] endif'' expression <br />
|-<br />
|OP_ELSE<br />
|103<br />
|0x67<br />
|Nothing<br />
|Nothing<br />
|If the preceeding OP_IF or OP_NOTIF or OP_ELSE was not executed then these statements are and if the preceding OP_IF or OP_NOTIF or OP_ELSE was executed then these statements are not. <br />
|-<br />
|OP_ENDIF<br />
|104<br />
|0x68<br />
|Nothing<br />
|Nothing<br />
|Ends a logcial ''If <value> then [statements] [else [statements]] '' expression<br />
|-<br />
|OP_VERIFY<br />
|105<br />
|0x69<br />
|Boolean<br />
|Nothing / False<br />
|If top stack value is not true then marks transaction as '''invalid''' . A value true is removed, but false is not.<br />
|-<br />
|OP_RETURN<br />
|106<br />
|0x6a<br />
|Nothing<br />
|Nothing<br />
|Marks transaction as '''invalid'''. <br />
|}<br />
<br />
===Stack item organization===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_TOALTSTACK<br />
|107<br />
|0x6b<br />
|x1 (alt)<br />
|(alt x1)<br />
|Puts the input onto the top of the alt stack. Removes it from the (main) stack.<br />
|-<br />
|OP_FROMALTSTACK<br />
|108<br />
|0x6c<br />
|(alt x1)<br />
|x1 (alt)<br />
|Puts the input onto the top of the (main) stack. Removes it from the alt stack.<br />
|-<br />
|OP_2DROP<br />
|109<br />
|0x6d<br />
|x1 x2<br />
|Nothing<br />
|Removes the top two stack items.<br />
|-<br />
|OP_2DUP<br />
|110<br />
|0x6e<br />
|x1 x2<br />
|x1 x2 x1 x2<br />
|Duplicates the top two stack items.<br />
|-<br />
|OP_3DUP<br />
|111<br />
|0x6f<br />
|x1 x2 x3<br />
|x1 x2 x3 x1 x2 x3<br />
|Duplicates the top three stack items.<br />
|-<br />
|OP_2OVER<br />
|112<br />
|0x70<br />
|x1 x2 x3 x4<br />
|x1 x2 x3 x4 x1 x2<br />
|Copies the pair of items two spaces back in the stack to the front.<br />
|-<br />
|OP_2ROT<br />
|113<br />
|0x71<br />
|x1 x2 x3 x4 x5 x6<br />
|x3 x4 x5 x6 x1 x2<br />
|The fifth and sixth items back are moved to the top of the stack.<br />
|-<br />
|OP_2SWAP<br />
|114<br />
|0x72<br />
|x1 x2 x3 x4<br />
|x3 x4 x1 x2<br />
|Swaps the top two pairs of items.<br />
|-<br />
|OP_IFDUP<br />
|115<br />
|0x73<br />
|x<br />
|x / x x<br />
|If the top stack value is not 0, duplicate it.<br />
|-<br />
|OP_DEPTH<br />
|116<br />
|0x74<br />
|Nothing<br />
|depth<br />
|Puts the number of stack items onto the stack as one little-endian coded byte-vector<br />
|-<br />
|OP_DROP<br />
|117<br />
|0x75<br />
|x<br />
|Nothing<br />
|Removes the top stack item.<br />
|-<br />
|OP_DUP<br />
|118<br />
|0x76<br />
|x<br />
|x x<br />
|Duplicates the top stack item.<br />
|-<br />
|OP_NIP<br />
|119<br />
|0x77<br />
|x1 x2<br />
|x2<br />
|Removes the second-to-top stack item.<br />
|-<br />
|OP_OVER<br />
|120<br />
|0x78<br />
|x1 x2<br />
|x1 x2 x1<br />
|Copies the second-to-top stack item to the top.<br />
|-<br />
|OP_PICK<br />
|121<br />
|0x79<br />
|xn ... x2 x1 x0 <n><br />
|xn ... x2 x1 x0 xn<br />
|The item ''n'' back in the stack is copied to the top.<br />
|-<br />
|OP_ROLL<br />
|122<br />
|0x7a<br />
|xn ... x2 x1 x0 <n><br />
|... x2 x1 x0 xn<br />
|The item ''n'' back in the stack is moved to the top.<br />
|-<br />
|OP_ROT<br />
|123<br />
|0x7b<br />
|x1 x2 x3<br />
|x2 x3 x1<br />
|The top three items on the stack are rotated to the left.<br />
|-<br />
|OP_SWAP<br />
|124<br />
|0x7c<br />
|x1 x2<br />
|x2 x1<br />
|The top two items on the stack are swapped.<br />
|-<br />
|OP_TUCK<br />
|125<br />
|0x7d<br />
|x1 x2<br />
|x2 x1 x2<br />
|The item at the top of the stack is copied and inserted before the second-to-top item.<br />
|}<br />
<br />
=== Splice ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_CAT<br />
|126<br />
|0x7e<br />
|x1 x2<br />
|out<br />
|Concatenates two strings resp. byte vectors. ''Currently disabled.''<br />
|-<br />
|OP_SUBSTR<br />
|127<br />
|0x7f<br />
|x index size<br />
|out<br />
|Returns the section started at position <index> and of length <size> of a string resp. byte vector. ''Currently disabled.''<br />
|-<br />
|OP_LEFT<br />
|128<br />
|0x80<br />
|x index<br />
|out<br />
|Keeps only characters left of the specified point in a string. ''Currently disabled.''<br />
|-<br />
|OP_RIGHT<br />
|129<br />
|0x81<br />
|x index<br />
|out<br />
|Keeps only characters right of the specified point in a string. ''Currently disabled.''<br />
|-<br />
|OP_SIZE<br />
|130<br />
|0x82<br />
|x<br />
|x size<br />
|Returns the length of the input string resp. byte vector resp. stack item.<br />
|}<br />
<br />
=== Bitwise logic ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_INVERT<br />
|131<br />
|0x83<br />
|x1<br />
|x0<br />
|Flips all of the bits in the input. ''Currently disabled.''<br />
|-<br />
|OP_AND<br />
|132<br />
|0x84<br />
|x1 x2<br />
|x0<br />
|Boolean ''and'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_OR<br />
|133<br />
|0x85<br />
|x1 x2<br />
|x0<br />
|Boolean ''or'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_XOR<br />
|134<br />
|0x86<br />
|x1 x2<br />
|x0<br />
|Boolean ''exclusive or'' between each bit in the inputs. ''Currently disabled.''<br />
|-<br />
|OP_EQUAL<br />
|135<br />
|0x87<br />
|x1 x2<br />
|Boolean<br />
|Returns 1 if the inputs are byte-wise equal, 0 otherwise.<br />
|-<br />
|OP_EQUALVERIFY<br />
|136<br />
|0x88<br />
|x1 x2<br />
|Nothing / false<br />
|Same as OP_EQUAL, but runs OP_VERIFY afterward.<br />
|}<br />
<br />
=== Arithmetic ===<br />
<br />
(In very early versions, the implemented arithmetic opcodes were limited to maximal 4 byte vectors.)<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_1ADD<br />
|139<br />
|0x8b<br />
|a<br />
|c<br />
|1 is added to the input.<br />
|-<br />
|OP_1SUB<br />
|140<br />
|0x8c<br />
|a<br />
|c<br />
|1 is subtracted from the input.<br />
|-<br />
|OP_2MUL<br />
|141<br />
|0x8d<br />
|a<br />
|c<br />
|The input is multiplied by 2. ''Currently disabled.''<br />
|-<br />
|OP_2DIV<br />
|142<br />
|0x8e<br />
|a<br />
|c<br />
|The input is divided by 2. ''Currently disabled.''<br />
|-<br />
|OP_NEGATE<br />
|143<br />
|0x8f<br />
|a<br />
|c<br />
|The sign of the input is flipped. Numerically the value is multiplied by -1<br />
|-<br />
|OP_ABS<br />
|144<br />
|0x90<br />
|a<br />
|c<br />
|The input is negative, its sign is flipped.<br />
|-<br />
|OP_NOT<br />
|145<br />
|0x91<br />
|a<br />
|Boolean<br />
|If the input is 0 or 1, it is flipped. Otherwise the output will be 0. Test whether its value equals 0<br />
|-<br />
|OP_0NOTEQUAL<br />
|146<br />
|0x92<br />
|a<br />
|Boolean<br />
|Returns 0 if the input is 0. 1 otherwise. Test whether its value is unequal 0<br />
|-<br />
|OP_ADD<br />
|147<br />
|0x93<br />
|a b<br />
|c<br />
|a is added to b.<br />
|-<br />
|OP_SUB<br />
|148<br />
|0x94<br />
|a b<br />
|c<br />
|b is subtracted from a.<br />
|-<br />
|OP_MUL<br />
|149<br />
|0x95<br />
|a b<br />
|c<br />
|a is multiplied by b. ''Currently disabled.''<br />
|-<br />
|OP_DIV<br />
|150<br />
|0x96<br />
|a b<br />
|c<br />
|a is divided by b (b should be not 0). ''Currently disabled.''<br />
|-<br />
|OP_MOD<br />
|151<br />
|0x97<br />
|a b<br />
|c<br />
|Returns the remainder after dividing a by b (b should be not 0). ''Currently disabled.''<br />
|-<br />
|OP_LSHIFT<br />
|152<br />
|0x98<br />
|a b<br />
|c<br />
|Shifts a left by b bits, preserving sign. ''Currently disabled.''<br />
|-<br />
|OP_RSHIFT<br />
|153<br />
|0x99<br />
|a b<br />
|c<br />
|Shifts a right by b bits, preserving sign. ''Currently disabled.''<br />
|-<br />
|OP_BOOLAND<br />
|154<br />
|0x9a<br />
|a b<br />
|Boolean<br />
|If both a and b are not 0, the output is 1. Otherwise 0.<br />
|-<br />
|OP_BOOLOR<br />
|155<br />
|0x9b<br />
|a b<br />
|Boolean<br />
|If a or b is not 0, the output is 1. Otherwise 0.<br />
|-<br />
|OP_NUMEQUAL<br />
|156<br />
|0x9c<br />
|a b<br />
|Boolean<br />
|Returns 1 if the numbers are equal, 0 otherwise.<br />
|-<br />
|OP_NUMEQUALVERIFY<br />
|157<br />
|0x9d<br />
|a b<br />
|Nothing / False<br />
|Same as OP_NUMEQUAL, but runs OP_VERIFY afterward.<br />
|-<br />
|OP_NUMNOTEQUAL<br />
|158<br />
|0x9e<br />
|a b<br />
|Boolean<br />
|Returns 1 if the numbers are not equal, 0 otherwise.<br />
|-<br />
|OP_LESSTHAN<br />
|159<br />
|0x9f<br />
|a b<br />
|Boolean<br />
|Returns 1 if a is less than b, 0 otherwise.<br />
|-<br />
|OP_GREATERTHAN<br />
|160<br />
|0xa0<br />
|a b<br />
|Boolean<br />
|Returns 1 if a is greater than b, 0 otherwise.<br />
|-<br />
|OP_LESSTHANOREQUAL<br />
|161<br />
|0xa1<br />
|a b<br />
|Boolean<br />
|Returns 1 if a is less than or equal to b, 0 otherwise.<br />
|-<br />
|OP_GREATERTHANOREQUAL<br />
|162<br />
|0xa2<br />
|a b<br />
|Boolean<br />
|Returns 1 if a is greater than or equal to b, 0 otherwise.<br />
|-<br />
|OP_MIN<br />
|163<br />
|0xa3<br />
|a b<br />
|a / b<br />
|Returns the smaller of a and b.<br />
|-<br />
|OP_MAX<br />
|164<br />
|0xa4<br />
|a b<br />
| a / b<br />
|Returns the larger of a and b.<br />
|-<br />
|OP_WITHIN<br />
|165<br />
|0xa5<br />
|x min max<br />
|Boolean<br />
|Returns 1 if x is within the specified range (left-inclusive) , 0 otherwise. min may be greater than max<br />
|}<br />
<br />
=== Crypto ===<br />
<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Input<br />
!Output<br />
!Description<br />
|-<br />
|OP_RIPEMD160<br />
|166<br />
|0xa6<br />
|x<br />
|hash20<br />
|The input is hashed using RIPEMD-160.<br />
|-<br />
|OP_SHA1<br />
|167<br />
|0xa7<br />
|x<br />
|hash20<br />
|The input is hashed using SHA-1.<br />
|-<br />
|OP_SHA256<br />
|168<br />
|0xa8<br />
|x<br />
|hash32<br />
|The input is hashed using SHA-256.<br />
|-<br />
|OP_HASH160<br />
|169<br />
|0xa9<br />
|x<br />
|hash20<br />
|The input is hashed twice: first with SHA-256 and then with RIPEMD-160.<br />
|-<br />
|OP_HASH256<br />
|170<br />
|0xaa<br />
|x<br />
|hash32<br />
|The input is hashed two times with SHA-256.<br />
|-<br />
|OP_CODESEPARATOR<br />
|171<br />
|0xab<br />
|Nothing<br />
|Nothing<br />
|All of the signature checking opcodes will only match signatures to the data after the most recently-executed OP_CODESEPARATOR.<br />
|-<br />
|[[OP_CHECKSIG]]<br />
|172<br />
|0xac<br />
|sig pubkey<br />
|Boolean<br />
|The entire transaction's outputs, inputs, and script (from the most recently-executed OP_CODESEPARATOR to the end) are hashed. The signature used by OP_CHECKSIG must be a valid signature for a further, extern specified hash and the given public key. If it is, 1 is returned, 0 otherwise.<br />
|-<br />
|OP_CHECKSIGVERIFY<br />
|173<br />
|0xad<br />
|sig pubkey<br />
|Nothing / False<br />
|Same as OP_CHECKSIG, but OP_VERIFY is executed afterward.<br />
|-<br />
|OP_CHECKMULTISIG<br />
|174<br />
|0xae<br />
|sig1 sig2 ... <number of signatures> pub1 pub2 <number of public keys><br />
|Boolean<br />
|For each signature and public key pair, OP_CHECKSIG is executed. If more public keys than signatures are listed, some key/sig pairs can fail. All signatures need to match a public key. If all signatures are valid, 1 is returned, 0 otherwise. Due to a bug, one extra unused value is removed from the stack.<br />
|-<br />
|OP_CHECKMULTISIGVERIFY<br />
|175<br />
|0xaf<br />
|sig1 sig2 ... <number of signatures> pub1 pub2 ... <number of public keys><br />
|Nothing / False<br />
|Same as OP_CHECKMULTISIG, but OP_VERIFY is executed afterward.<br />
|}<br />
<br />
=== Expansion opcodes ===<br />
{| class="wikitable"<br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_NOP1-OP_NOP10<br />
|176-185<br />
|0xb0-0xb9<br />
|The opcode has no effect.<br />
|}<br />
<br />
=== Version opcodes ===<br />
Version opcodes are disabled since bitcoin 0.2.0 and should not be used (maybe reassigned in the future).<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_VER<br />
|98<br />
|0x62<br />
|Script evalution is triggered invalid (Formerly pushed the bitcoin-serialize version onto stack).<br />
|-<br />
|OP_VERIF<br />
|101<br />
|0x65<br />
|Script evalution is triggered invalid (Formerly top stack item was popped and =< compared to present version)<br />
|-<br />
|OP_VERNOTIF<br />
|102<br />
|0x66<br />
|Script evalution is triggered invalid (Formerly top stack item was popped and > compared to present version)<br />
|}<br />
<br />
=== Reserved opcodes ===<br />
Each opcode not assigned (currently also every opcode value > 185) is also reserved. Using any unassigned opcode triggers the script evaluation to be invalid.<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_RESERVED<br />
|80<br />
|0x50<br />
|Script evalution is triggered invalid-<br />
|-<br />
|OP_RESERVED1<br />
|137<br />
|0x89<br />
|Script evalution is triggered invalid.<br />
|-<br />
|OP_RESERVED2<br />
|138<br />
|0x8a<br />
|Script evalution is triggered invalid.<br />
|}<br />
<br />
===Pseudo-opcodes===<br />
These nemonics are used internally for assisting with transaction matching. They are invalid if used in actual scripts.<br />
{| class="wikitable" <br />
|-<br />
!Nemonic<br />
!Decimal<br />
!Hex<br />
!Description<br />
|-<br />
|OP_PUBKEYHASH<br />
|253<br />
|0xfd<br />
|Represents a public key hashed with OP_HASH160.<br />
|-<br />
|OP_PUBKEY<br />
|254<br />
|0xfe<br />
|Represents a public key compatible with OP_CHECKSIG.<br />
|-<br />
|OP_INVALIDOPCODE<br />
|255<br />
|0xff<br />
|Matches any opcode that is not yet assigned.<br />
|}<br />
<br />
==Scripts in bitcoin transactions==<br />
It follows a list of important (most occuring) scripts to see opcodes "at work". Keep in mind that all constants actually use the data-pushing instructions above. At start of a (transaction input) script evaluation, the stack is always empty. <br />
<br />
===Standard transaction to bitcoin address===<br />
<br />
scriptPubKey: OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG<br />
scriptSig: <sig> <pubKey><br />
<br />
To demonstrate how scripts look on the wire, here is a raw scriptPubKey:<br />
<pre> 76 A9 14<br />
OP_DUP OP_HASH160 Bytes to push<br />
<br />
89 AB CD EF AB BA AB BA AB BA AB BA AB BA AB BA AB BA AB BA 88 AC<br />
Data to push OP_EQUALVERIFY OP_CHECKSIG</pre><br />
<br />
Note: scriptSig is in the input of the spending transaction and scriptPubKey is in the output of the previously storing transaction, i.e. its "available bitcoins".<br />
<br />
Here is how each instruction is processed:<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
| <sig> <pubKey> OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| scriptSig and scriptPubKey are combined.<br />
|-<br />
|<sig> <pubKey><br />
| OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| Constants are added to the stack.<br />
|-<br />
|<sig> <pubKey> <pubKey><br />
| OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG <br />
| Top stack item is duplicated.<br />
|-<br />
|<sig> <pubKey> <pubHashA><br />
|<pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG<br />
| Top stack item is hashed.<br />
|-<br />
|<sig> <pubKey> <pubHashA> <pubKeyHash><br />
|OP_EQUALVERIFY OP_CHECKSIG<br />
| Constant added.<br />
|-<br />
|<sig> <pubKey><br />
|OP_CHECKSIG<br />
| Equality is checked between the top two stack items.<br />
|-<br />
|true<br />
|Empty.<br />
|Signature is checked for top two stack items.<br />
|}<br />
<br />
===Transaction to IP address (and generation transaction)===<br />
<br />
scriptPubKey: <pubKey> OP_CHECKSIG<br />
scriptSig: <sig><br />
<br />
Checking process:<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
|<sig> <pubKey> OP_CHECKSIG<br />
|scriptSig and scriptPubKey are combined.<br />
|-<br />
|<sig> <pubKey><br />
| OP_CHECKSIG<br />
|Constants are added to the stack.<br />
|-<br />
|true<br />
|Empty.<br />
|Signature is checked for top two stack items.<br />
|}<br />
<br />
In the case of a '''coin generation transaction''' (the first transaction of each block), there is no scriptSig, resp. its code ("coinbase") is completly ignored for the transaction. Only the scriptPubKey is used.<br />
<br />
===Transaction with a message===<br />
<br />
It's possible to add arbitrary data to any transaction by just adding some data along with OP_DROP. <br />
scriptPubKey: <message> OP_DROP <pubKey> OP_CHECKSIG<br />
scriptSig: <sig><br />
<br />
{| class="wikitable" <br />
|-<br />
! Stack <br />
! Script <br />
! Description <br />
|-<br />
|Empty.<br />
|<sig> <message> OP_DROP <pubKey> OP_CHECKSIG<br />
|<br />
|-<br />
|<sig><br />
|<message> OP_DROP <pubKey> OP_CHECKSIG<br />
|scriptSig added to the stack.<br />
|-<br />
|<sig> <message><br />
|OP_DROP <pubKey> OP_CHECKSIG<br />
|The message has been put.<br />
|-<br />
|<sig><br />
|<pubKey> OP_CHECKSIG<br />
|Top stack item has been removed.<br />
|-<br />
|<sig> <pubKey><br />
|OP_CHECKSIG<br />
|Checking signature against the public key.<br />
|-<br />
|true<br />
|Empty.<br />
|Stack holds the value of signature check now.<br />
|}<br />
<br />
===Examples of non standard transaction on Testnet===<br />
<br />
These two links below show a non standard transaction. It just prepends the hex of "bob" and the operation OP_DROP<br />
which just removes it. As you can see they can be spent as normal.<br />
<br />
Input non-std transaction:<br />
http://blockexplorer.com/testnet/t/6ttfeb55B1<br />
<br />
Spent by:<br />
http://blockexplorer.com/testnet/t/AFdRB1CHS3<br />
<br />
==Script validation==<br />
A script evaluation is considered invalid, if any of these conditions meets:<br><br />
<ul><br />
<li>the total size of the script exceeds (currently) 10000 bytes<br />
<li>there are more than (currently) 201 opcodes of opcode value > 0x60 in the script<br />
<li>each instruction is (currently) limited to maximal 520 bytes. This effects only the opcodes OP_PUSHDATA2 and OP_PUSHDATA4<br />
<li>the executed opcode of the script has insufficient input (from stack, from script or from anywhere)<br />
<li>the opcode is not defined (for execution) - indicated by white or light gray background color in the table<br />
<li>the opcode is disabled (currently 15 opcodes) - indicated by white font color in the opcode overview matrix<br />
<li>stack overflow occurs during execution of the opcode (currently the number of items on the stack and on the alternate stack is limited to 1000)<br />
<li>the opcodes OP_VERIF and OP_NOTVERIF invalidate a script which contains this opcode (even if this opcode is not executed!)<br />
<li>the opcodes OP_ELSE or OP_ENDIF has no matching OP_IF<br><br />
<li>the script execution has been finished but there is (at least) an unmatched OP_IF<br><br />
<li>the opcodes OP_VERIFY, OP_EQUALVERIFY, OP_NUMEQUALVERIFY, OP_CHECKSIGVERIFY and OP_CHECKMULTISIGVERIFY invalidate the script if the stack-top item is false<br />
<li>the execution of OP_RETURN<br />
<!--li>alt stack overflow occurs (only possible during execution of OP_TOALTSTACK)--><br />
<li>the numerical value of the top-stack item is negative or greater than the number of items - 2 on the stack if OP_PICK or OP_ROLL shall be executed<br />
<li>an item used as public key or signature for each of the opcodes OP_CHECKSIG, OP_CHECKSIGVERIFY, OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY can be neither a public key or signature (for the given hash)<br />
<li>the number of signature items or the number of public key items on the stack is negative for OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY<br />
<li>there or more signatures items than public key items on the stack for OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY<br />
<li>there are (currently) more than 20 public key items on the stack for OP_CHECKMULTISIG or CHECKMULTISIGVERIFY<br />
<li>the sum of opcodes > 0x60 and the number of public keys in all executed OP_CHECKMULTISIG or CHECKMULTISIGVERIFY exceeds (currently) 201<br />
<li>the script execution has been finished and the stack is empty or the top-stack item is false (numerical value 0)<br />
</ul><br />
else the script evaluation is considered to be valid.<ref>[http://sourceforge.net/projects/bitcoin/files/Bitcoin/bitcoin-0.7.1/bitcoin-0.7.1-linux.tar.gz file src/src/script.cpp in bitcoin-0.7.1]</ref><br />
'''If invalidation of a script is triggered then the script is immediately finished.''' These arbitrary looking limitations of 10000, 201, 520, 1000 and 20 might be increased in the future -- they serve to prevent strong slow down of the evaluation of a script while not restricting its practical usage really.<br />
<br />
==redrawn and drafted opcodes==<br />
<br />
<ul><br />
<li> byte value 0x89 [[OP_NOTEQUAL]] defined in pre-0.1.0 bitcoin versions<br />
<li> byte value 0xb1 [[BIP 0012 | OP_EVAL]] poll is running <br />
<li> byte value 0xb2 [[BIP 0017 | OP_CHECKHASHVERIFY]] poll is running<br />
</ul><br />
<br />
==See Also==<br />
* [[Transactions]]<br />
* [[Contracts]]<br />
<br />
==References==<br />
<references/><br />
<ul><br />
<li>[http://www.zorinaq.com/pub/bitcoin-0.1.0.tgz file src/script.cpp in bitcoin-0.1.0]</li><br />
</ul><br />
[[Category:Technical]]<br />
[[Category:Vocabulary]]</div>
Smtp
https://en.bitcoin.it/w/index.php?title=OP_CHECKSIG&diff=34849
OP CHECKSIG
2013-01-09T12:43:49Z
<p>Smtp: /* How it works */ signature deleted its last byte</p>
<hr />
<div>OP_CHECKSIG is [[Script|script]] opcode used to verify that the signature for a tx input is valid. OP_CHECKSIG expects two values to be on the stack, these are, in order of stack depth, the public key and the signature of the script. These two values are normally obtained by running the scriptSig script of the transaction input we are attempting to validate. After the scriptSig script is run the script is deleted but the stack is left as is, and then then scriptPubKey script from the previous transaction output that is now being spent is run, generally concluding in an OP_CHECKSIG. <br />
<br />
The standard scriptPubKey checks that the public key (actually a hash of) is a particular value, and that OP_CHECKSIG passes.<br />
<br />
For normal transaction inputs if the creator of the current transaction can successfully create a ScriptSig signature that uses the right public key for the ScriptPubKey of the transaction output they are attempting to spend, that transaction input is considered valid. <br />
<br />
== Parameters ==<br />
<br />
In addition to the script code itself and the stack parameters, to operate OP_CHECKSIG needs to know the current transaction, the index of current transaction input, and sometimes the current hashtype (discussed later).<br />
<br />
== How it works ==<br />
Firstly always this (the default) procedure is applied:<br />
[[File:Bitcoin_OpCheckSig_InDetail.png|thumb|right|Signature verification process of the default procedure]]<br />
# the public key and the signature are popped from the stack, in that order. If the hash-type value is 0, then it is replaced by the last_byte of the signature. Then the last byte of the signature is always deleted.<br />
# A new subscript is created from the instruction from the most recently parsed OP_CODESEPARATOR (last one in script) to the end of the script. If there is no OP_CODESEPARATOR the entire script becomes the subscript (hereby referred to as subScript)<br />
# The sig is deleted from subScript.<br />
# All OP_CODESEPARATORS are removed from subScript<br />
# The hashtype is removed from the last byte of the sig and stored<br />
# A copy is made of the current transaction (hereby referred to txCopy)<br />
# The scripts for all transaction inputs in txCopy are set to empty scripts (exactly 1 byte 0x00)<br />
# The script for the current transaction input in txCopy is set to subScript (lead in by its length as a var-integer encoded!)<br />
<br />
Now depending on the hashtype various things can happen to txCopy, these will be discussed individually<br />
<br />
<br />
'''Hashtype Values (from script.h):'''<br />
{|class="wikitable"<br />
! Name !! Value<br />
|-<br />
| SIGHASH_ALL || 0x00000001<br />
|-<br />
| SIGHASH_NONE || 0x00000002<br />
|-<br />
| SIGHASH_SINGLE || 0x00000003<br />
|-<br />
| SIGHASH_ANYONECANPAY || 0x00000080<br />
|}<br />
<br />
<ol><br />
<li> If Hashtype = SIGHASH_NONE then apply the SIGHASH_NONE-procedure<br />
<li> If Hashtype = SIGHASH_SINGLE then apply the SIGHASH_SINGLE-procedure<br />
<li> If Hashtype & SIGHASH_ANYONECANPAY then apply the SIGHASH_ANYONECANPAY-procedure<br />
</ol><br />
Hence, Hashtype ANYONECANPAY may be applied also to one of the other two hash_type procedures<ref>[http://sourceforge.net/projects/bitcoin/files/Bitcoin/bitcoin-0.7.1/bitcoin-0.7.1-linux.tar.gz file src/src/script.cpp in bitcoin-0.7.1]</ref>.<br />
<br />
=== Hashtype SIGHASH_ALL (default) ===<br />
<br />
No special further handling occurs in the default case. Think of this as "sign '''all''' of the outputs." Which is already done by the default procedure.<br />
<br />
=== Procedure for Hashtype SIGHASH_NONE ===<br />
<br />
# The output of txCopy is set to a vector of zero size.<br />
# All other inputs aside from the current input in txCopy have their nSequence index set to zero<br />
<br />
Think of this as "sign '''none''' of the outputs-- I don't care where the bitcoins go."<br />
<br />
=== Procedure for Hashtype SIGHASH_SINGLE ===<br />
<br />
# The output of txCopy is resized to the size of the current input index+1<br />
# All other txCopy outputs aside from the output that is the same as the current input index are set to a blank script and a value of (long) -1;<br />
# All other txCopy inputs aside from the current input are set to have an nSequence index of zero<br />
<br />
Think of this as "sign '''one''' of the outputs-- I don't care where the other outputs go."<br />
<br />
=== Procedure for Hashtype SIGHASH_ANYONECANPAY ===<br />
<br />
# The txCopy input vector is resized to a length of one<br />
# The current input is set as the first and only member of this vector<br />
<br />
This can be combined with ALL/SINGLE/NONE. Think of this as "Let other people add inputs to this transaction, I don't care where the rest of the bitcoins come from."<br />
<br />
== Final signature ==<br />
<br />
An array of bytes is constructed from the serialized txCopy + four bytes for the hash type. This array is sha256 hashed twice, then the public key is used to to check the supplied signature against the hash. <br />
<br />
== Return values ==<br />
<br />
OP_CHECKSIG will push true to the stack if the check passed, false otherwise.<br />
OP_CHECKSIG_VERIFY leaves nothing on the stack but will cause the script eval to fail immediately if the check does not pass.<br />
<br />
== Code samples and raw dumps ==<br />
<br />
Taking the first transaction in Bitcoin which is in block number 170, we would get after serialising the transaction but before we hash+sign (or verify) it:<br />
<br />
* http://blockexplorer.com/block/00000000d1145790a8694403d4063f323d499e655c83426834d4ce2f8dd4a2ee<br />
* http://blockexplorer.com/tx/f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16<br />
<br />
See also [https://gitorious.org/libbitcoin/libbitcoin libbitcoin] for code samples.<br />
<br />
<pre><br />
01 00 00 00 version<br />
01 number of inputs (var_uint)<br />
<br />
input 0:<br />
c9 97 a5 e5 6e 10 41 02 input address hash<br />
fa 20 9c 6a 85 2d d9 06 <br />
60 a2 0b 2d 9c 35 24 23 <br />
ed ce 25 85 7f cd 37 04<br />
00 00 00 00 input index<br />
<br />
48 size of script (var_uint)<br />
47 push 71 bytes to stack<br />
30 44 02 20 4e 45 e1 69<br />
32 b8 af 51 49 61 a1 d3<br />
a1 a2 5f df 3f 4f 77 32<br />
e9 d6 24 c6 c6 15 48 ab<br />
5f b8 cd 41 02 20 18 15<br />
22 ec 8e ca 07 de 48 60<br />
a4 ac dd 12 90 9d 83 1c<br />
c5 6c bb ac 46 22 08 22<br />
21 a8 76 8d 1d 09 01<br />
ff ff ff ff sequence<br />
<br />
02 number of outputs (var_uint)<br />
<br />
output 0:<br />
00 ca 9a 3b 00 00 00 00 amount = 10.00000000<br />
43 size of script (var_uint)<br />
script for output 0:<br />
41 push 65 bytes to stack<br />
04 ae 1a 62 fe 09 c5 f5 <br />
1b 13 90 5f 07 f0 6b 99 <br />
a2 f7 15 9b 22 25 f3 74 <br />
cd 37 8d 71 30 2f a2 84 <br />
14 e7 aa b3 73 97 f5 54 <br />
a7 df 5f 14 2c 21 c1 b7 <br />
30 3b 8a 06 26 f1 ba de <br />
d5 c7 2a 70 4f 7e 6c d8 <br />
4c <br />
ac OP_CHECKSIG<br />
<br />
output 1:<br />
00 28 6b ee 00 00 00 00 amount = 40.00000000<br />
43 size of script (var_uint)<br />
script for output 1:<br />
41 push 65 bytes to stack<br />
04 11 db 93 e1 dc db 8a <br />
01 6b 49 84 0f 8c 53 bc <br />
1e b6 8a 38 2e 97 b1 48 <br />
2e ca d7 b1 48 a6 90 9a<br />
5c b2 e0 ea dd fb 84 cc <br />
f9 74 44 64 f8 2e 16 0b <br />
fa 9b 8b 64 f9 d4 c0 3f <br />
99 9b 86 43 f6 56 b4 12 <br />
a3 <br />
ac OP_CHECKSIG<br />
<br />
00 00 00 00 locktime<br />
01 00 00 00 hash_code_type (added on)<br />
<br />
result =<br />
01 00 00 00 01 c9 97 a5 e5 6e 10 41 02 fa 20 9c 6a 85 2d d9 06 60 a2 0b 2d 9c 35 <br />
24 23 ed ce 25 85 7f cd 37 04 00 00 00 00 43 41 04 11 db 93 e1 dc db 8a 01 6b 49 <br />
84 0f 8c 53 bc 1e b6 8a 38 2e 97 b1 48 2e ca d7 b1 48 a6 90 9a 5c b2 e0 ea dd fb <br />
84 cc f9 74 44 64 f8 2e 16 0b fa 9b 8b 64 f9 d4 c0 3f 99 9b 86 43 f6 56 b4 12 a3 <br />
ac ff ff ff ff 02 00 ca 9a 3b 00 00 00 00 43 41 04 ae 1a 62 fe 09 c5 f5 1b 13 90 <br />
5f 07 f0 6b 99 a2 f7 15 9b 22 25 f3 74 cd 37 8d 71 30 2f a2 84 14 e7 aa b3 73 97 <br />
f5 54 a7 df 5f 14 2c 21 c1 b7 30 3b 8a 06 26 f1 ba de d5 c7 2a 70 4f 7e 6c d8 4c <br />
ac 00 28 6b ee 00 00 00 00 43 41 04 11 db 93 e1 dc db 8a 01 6b 49 84 0f 8c 53 bc <br />
1e b6 8a 38 2e 97 b1 48 2e ca d7 b1 48 a6 90 9a 5c b2 e0 ea dd fb 84 cc f9 74 44 <br />
64 f8 2e 16 0b fa 9b 8b 64 f9 d4 c0 3f 99 9b 86 43 f6 56 b4 12 a3 ac 00 00 00 00 <br />
01 00 00 00 <br />
</pre><br />
<br />
To understand where that raw dump has come from, it may be useful to examine tests/ec-key.cpp in [https://gitorious.org/libbitcoin/libbitcoin libbitcoin],<br />
<br />
[https://gitorious.org/libbitcoin/libbitcoin libbitcoin] has a unit test under tests/ec-key.cpp (make ec-key && ./bin/tests/ec-key). There is also a working OP_CHECKSIG implementation in src/script.cpp under script::op_checksig(). See also the unit test: tests/script-test.cpp<br />
<br />
<source lang="cpp"><br />
#include <iostream><br />
#include <iomanip><br />
#include <bitcoin/util/serializer.hpp><br />
#include <bitcoin/util/elliptic_curve_key.hpp><br />
#include <bitcoin/util/sha256.hpp><br />
#include <bitcoin/util/assert.hpp><br />
#include <bitcoin/util/logger.hpp><br />
#include <bitcoin/types.hpp><br />
#include <openssl/ecdsa.h><br />
#include <openssl/obj_mac.h><br />
using libbitcoin::elliptic_curve_key;<br />
using libbitcoin::serializer;<br />
using libbitcoin::hash_digest;<br />
using libbitcoin::data_chunk;<br />
using libbitcoin::log_info;<br />
using libbitcoin::log_fatal;<br />
<br />
int main()<br />
{<br />
serializer ss;<br />
// blk number 170, tx 1, input 0<br />
// version = 1<br />
ss.write_4_bytes(1);<br />
// 1 inputs<br />
ss.write_var_uint(1);<br />
<br />
// input 0<br />
// prevout hash<br />
ss.write_hash(hash_digest{0x04, 0x37, 0xcd, 0x7f, 0x85, 0x25, 0xce, 0xed, 0x23, 0x24, 0x35, 0x9c, 0x2d, 0x0b, 0xa2, 0x60, 0x06, 0xd9, 0x2d, 0x85, 0x6a, 0x9c, 0x20, 0xfa, 0x02, 0x41, 0x10, 0x6e, 0xe5, 0xa5, 0x97, 0xc9});<br />
// prevout index <br />
ss.write_4_bytes(0);<br />
<br />
// input script after running OP_CHECKSIG for this tx is a single<br />
// OP_CHECKSIG opcode<br />
data_chunk raw_data;<br />
raw_data = {0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3};<br />
data_chunk raw_script;<br />
raw_script = data_chunk();<br />
raw_script.push_back(raw_data.size());<br />
libbitcoin::extend_data(raw_script, raw_data);<br />
raw_script.push_back(172);<br />
ss.write_var_uint(raw_script.size());<br />
ss.write_data(raw_script);<br />
// sequence<br />
ss.write_4_bytes(0xffffffff);<br />
<br />
// 2 outputs for this tx<br />
ss.write_var_uint(2);<br />
<br />
// output 0<br />
ss.write_8_bytes(1000000000);<br />
// script for output 0<br />
raw_data = {0x04, 0xae, 0x1a, 0x62, 0xfe, 0x09, 0xc5, 0xf5, 0x1b, 0x13, 0x90, 0x5f, 0x07, 0xf0, 0x6b, 0x99, 0xa2, 0xf7, 0x15, 0x9b, 0x22, 0x25, 0xf3, 0x74, 0xcd, 0x37, 0x8d, 0x71, 0x30, 0x2f, 0xa2, 0x84, 0x14, 0xe7, 0xaa, 0xb3, 0x73, 0x97, 0xf5, 0x54, 0xa7, 0xdf, 0x5f, 0x14, 0x2c, 0x21, 0xc1, 0xb7, 0x30, 0x3b, 0x8a, 0x06, 0x26, 0xf1, 0xba, 0xde, 0xd5, 0xc7, 0x2a, 0x70, 0x4f, 0x7e, 0x6c, 0xd8, 0x4c};<br />
// when data < 75, we can just write it's length as a single byte ('special'<br />
// opcodes)<br />
raw_script = data_chunk();<br />
raw_script.push_back(raw_data.size());<br />
libbitcoin::extend_data(raw_script, raw_data);<br />
// OP_CHECKSIG<br />
raw_script.push_back(172);<br />
// now actually write the script<br />
ss.write_var_uint(raw_script.size());<br />
ss.write_data(raw_script);<br />
<br />
// output 0<br />
ss.write_8_bytes(4000000000);<br />
// script for output 0<br />
raw_data = {0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3};<br />
// when data < 75, we can just write it's length as a single byte ('special'<br />
raw_script.push_back(raw_data.size());<br />
libbitcoin::extend_data(raw_script, raw_data);<br />
// OP_CHECKSIG<br />
raw_script.push_back(172);<br />
// now actually write the script<br />
ss.write_var_uint(raw_script.size());<br />
ss.write_data(raw_script);<br />
<br />
// End of 2 outputs<br />
<br />
// locktime<br />
ss.write_4_bytes(0);<br />
<br />
// write hash_type_code<br />
ss.write_4_bytes(1);<br />
<br />
// Dump hex to screen<br />
log_info() << "hashing:";<br />
{<br />
auto log_obj = log_info();<br />
log_obj << std::hex;<br />
for (int val: ss.get_data())<br />
log_obj << std::setfill('0') << std::setw(2) << val << ' ';<br />
}<br />
log_info();<br />
<br />
data_chunk raw_tx = {0x01, 0x00, 0x00, 0x00, 0x01, 0xc9, 0x97, 0xa5, 0xe5, 0x6e, 0x10, 0x41, 0x02, 0xfa, 0x20, 0x9c, 0x6a, 0x85, 0x2d, 0xd9, 0x06, 0x60, 0xa2, 0x0b, 0x2d, 0x9c, 0x35, 0x24, 0x23, 0xed, 0xce, 0x25, 0x85, 0x7f, 0xcd, 0x37, 0x04, 0x00, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3, 0xac, 0xff, 0xff, 0xff, 0xff, 0x02, 0x00, 0xca, 0x9a, 0x3b, 0x00, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, 0xae, 0x1a, 0x62, 0xfe, 0x09, 0xc5, 0xf5, 0x1b, 0x13, 0x90, 0x5f, 0x07, 0xf0, 0x6b, 0x99, 0xa2, 0xf7, 0x15, 0x9b, 0x22, 0x25, 0xf3, 0x74, 0xcd, 0x37, 0x8d, 0x71, 0x30, 0x2f, 0xa2, 0x84, 0x14, 0xe7, 0xaa, 0xb3, 0x73, 0x97, 0xf5, 0x54, 0xa7, 0xdf, 0x5f, 0x14, 0x2c, 0x21, 0xc1, 0xb7, 0x30, 0x3b, 0x8a, 0x06, 0x26, 0xf1, 0xba, 0xde, 0xd5, 0xc7, 0x2a, 0x70, 0x4f, 0x7e, 0x6c, 0xd8, 0x4c, 0xac, 0x00, 0x28, 0x6b, 0xee, 0x00, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3, 0xac, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00};<br />
BITCOIN_ASSERT(raw_tx == ss.get_data());<br />
<br />
hash_digest tx_hash = libbitcoin::generate_sha256_hash(ss.get_data());<br />
<br />
data_chunk pubkey{0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3};<br />
// Leave out last byte since that's the hash_type_code (SIGHASH_ALL in this<br />
// case)<br />
data_chunk signature{0x30, 0x44, 0x02, 0x20, 0x4e, 0x45, 0xe1, 0x69, 0x32, 0xb8, 0xaf, 0x51, 0x49, 0x61, 0xa1, 0xd3, 0xa1, 0xa2, 0x5f, 0xdf, 0x3f, 0x4f, 0x77, 0x32, 0xe9, 0xd6, 0x24, 0xc6, 0xc6, 0x15, 0x48, 0xab, 0x5f, 0xb8, 0xcd, 0x41, 0x02, 0x20, 0x18, 0x15, 0x22, 0xec, 0x8e, 0xca, 0x07, 0xde, 0x48, 0x60, 0xa4, 0xac, 0xdd, 0x12, 0x90, 0x9d, 0x83, 0x1c, 0xc5, 0x6c, 0xbb, 0xac, 0x46, 0x22, 0x08, 0x22, 0x21, 0xa8, 0x76, 0x8d, 0x1d, 0x09};<br />
BITCOIN_ASSERT(signature.size() == 70);<br />
<br />
elliptic_curve_key key;<br />
if (!key.set_public_key(pubkey))<br />
{<br />
log_fatal() << "unable to set EC public key";<br />
return -1;<br />
}<br />
<br />
log_info() << "checksig returns: " << (key.verify(tx_hash, signature) ? "true" : "false");<br />
return 0;<br />
}<br />
<br />
</source><br />
<br />
==References==<br />
<references/><br />
<br />
[[Category:Technical]]<br />
[[Category:Developer]]</div>
Smtp
https://en.bitcoin.it/w/index.php?title=OP_CHECKSIG&diff=34848
OP CHECKSIG
2013-01-09T12:38:15Z
<p>Smtp: /* Parameters */ typically (or always?) the hashtype can be fetched from sig from the stack -- thus sometimes (please correct if you have preciser infos)</p>
<hr />
<div>OP_CHECKSIG is [[Script|script]] opcode used to verify that the signature for a tx input is valid. OP_CHECKSIG expects two values to be on the stack, these are, in order of stack depth, the public key and the signature of the script. These two values are normally obtained by running the scriptSig script of the transaction input we are attempting to validate. After the scriptSig script is run the script is deleted but the stack is left as is, and then then scriptPubKey script from the previous transaction output that is now being spent is run, generally concluding in an OP_CHECKSIG. <br />
<br />
The standard scriptPubKey checks that the public key (actually a hash of) is a particular value, and that OP_CHECKSIG passes.<br />
<br />
For normal transaction inputs if the creator of the current transaction can successfully create a ScriptSig signature that uses the right public key for the ScriptPubKey of the transaction output they are attempting to spend, that transaction input is considered valid. <br />
<br />
== Parameters ==<br />
<br />
In addition to the script code itself and the stack parameters, to operate OP_CHECKSIG needs to know the current transaction, the index of current transaction input, and sometimes the current hashtype (discussed later).<br />
<br />
== How it works ==<br />
Firstly always this (the default) procedure is applied:<br />
[[File:Bitcoin_OpCheckSig_InDetail.png|thumb|right|Signature verification process of the default procedure]]<br />
# the public key and the signature are popped from the stack, in that order.<br />
# A new subscript is created from the instruction from the most recently parsed OP_CODESEPARATOR (last one in script) to the end of the script. If there is no OP_CODESEPARATOR the entire script becomes the subscript (hereby referred to as subScript)<br />
# The sig is deleted from subScript.<br />
# All OP_CODESEPARATORS are removed from subScript<br />
# The hashtype is removed from the last byte of the sig and stored<br />
# A copy is made of the current transaction (hereby referred to txCopy)<br />
# The scripts for all transaction inputs in txCopy are set to empty scripts (exactly 1 byte 0x00)<br />
# The script for the current transaction input in txCopy is set to subScript (lead in by its length as a var-integer encoded!)<br />
<br />
Now depending on the hashtype various things can happen to txCopy, these will be discussed individually<br />
<br />
<br />
'''Hashtype Values (from script.h):'''<br />
{|class="wikitable"<br />
! Name !! Value<br />
|-<br />
| SIGHASH_ALL || 0x00000001<br />
|-<br />
| SIGHASH_NONE || 0x00000002<br />
|-<br />
| SIGHASH_SINGLE || 0x00000003<br />
|-<br />
| SIGHASH_ANYONECANPAY || 0x00000080<br />
|}<br />
<br />
<ol><br />
<li> If Hashtype = SIGHASH_NONE then apply the SIGHASH_NONE-procedure<br />
<li> If Hashtype = SIGHASH_SINGLE then apply the SIGHASH_SINGLE-procedure<br />
<li> If Hashtype & SIGHASH_ANYONECANPAY then apply the SIGHASH_ANYONECANPAY-procedure<br />
</ol><br />
Hence, Hashtype ANYONECANPAY may be applied also to one of the other two hash_type procedures<ref>[http://sourceforge.net/projects/bitcoin/files/Bitcoin/bitcoin-0.7.1/bitcoin-0.7.1-linux.tar.gz file src/src/script.cpp in bitcoin-0.7.1]</ref>.<br />
<br />
=== Hashtype SIGHASH_ALL (default) ===<br />
<br />
No special further handling occurs in the default case. Think of this as "sign '''all''' of the outputs." Which is already done by the default procedure.<br />
<br />
=== Procedure for Hashtype SIGHASH_NONE ===<br />
<br />
# The output of txCopy is set to a vector of zero size.<br />
# All other inputs aside from the current input in txCopy have their nSequence index set to zero<br />
<br />
Think of this as "sign '''none''' of the outputs-- I don't care where the bitcoins go."<br />
<br />
=== Procedure for Hashtype SIGHASH_SINGLE ===<br />
<br />
# The output of txCopy is resized to the size of the current input index+1<br />
# All other txCopy outputs aside from the output that is the same as the current input index are set to a blank script and a value of (long) -1;<br />
# All other txCopy inputs aside from the current input are set to have an nSequence index of zero<br />
<br />
Think of this as "sign '''one''' of the outputs-- I don't care where the other outputs go."<br />
<br />
=== Procedure for Hashtype SIGHASH_ANYONECANPAY ===<br />
<br />
# The txCopy input vector is resized to a length of one<br />
# The current input is set as the first and only member of this vector<br />
<br />
This can be combined with ALL/SINGLE/NONE. Think of this as "Let other people add inputs to this transaction, I don't care where the rest of the bitcoins come from."<br />
<br />
== Final signature ==<br />
<br />
An array of bytes is constructed from the serialized txCopy + four bytes for the hash type. This array is sha256 hashed twice, then the public key is used to to check the supplied signature against the hash. <br />
<br />
== Return values ==<br />
<br />
OP_CHECKSIG will push true to the stack if the check passed, false otherwise.<br />
OP_CHECKSIG_VERIFY leaves nothing on the stack but will cause the script eval to fail immediately if the check does not pass.<br />
<br />
== Code samples and raw dumps ==<br />
<br />
Taking the first transaction in Bitcoin which is in block number 170, we would get after serialising the transaction but before we hash+sign (or verify) it:<br />
<br />
* http://blockexplorer.com/block/00000000d1145790a8694403d4063f323d499e655c83426834d4ce2f8dd4a2ee<br />
* http://blockexplorer.com/tx/f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16<br />
<br />
See also [https://gitorious.org/libbitcoin/libbitcoin libbitcoin] for code samples.<br />
<br />
<pre><br />
01 00 00 00 version<br />
01 number of inputs (var_uint)<br />
<br />
input 0:<br />
c9 97 a5 e5 6e 10 41 02 input address hash<br />
fa 20 9c 6a 85 2d d9 06 <br />
60 a2 0b 2d 9c 35 24 23 <br />
ed ce 25 85 7f cd 37 04<br />
00 00 00 00 input index<br />
<br />
48 size of script (var_uint)<br />
47 push 71 bytes to stack<br />
30 44 02 20 4e 45 e1 69<br />
32 b8 af 51 49 61 a1 d3<br />
a1 a2 5f df 3f 4f 77 32<br />
e9 d6 24 c6 c6 15 48 ab<br />
5f b8 cd 41 02 20 18 15<br />
22 ec 8e ca 07 de 48 60<br />
a4 ac dd 12 90 9d 83 1c<br />
c5 6c bb ac 46 22 08 22<br />
21 a8 76 8d 1d 09 01<br />
ff ff ff ff sequence<br />
<br />
02 number of outputs (var_uint)<br />
<br />
output 0:<br />
00 ca 9a 3b 00 00 00 00 amount = 10.00000000<br />
43 size of script (var_uint)<br />
script for output 0:<br />
41 push 65 bytes to stack<br />
04 ae 1a 62 fe 09 c5 f5 <br />
1b 13 90 5f 07 f0 6b 99 <br />
a2 f7 15 9b 22 25 f3 74 <br />
cd 37 8d 71 30 2f a2 84 <br />
14 e7 aa b3 73 97 f5 54 <br />
a7 df 5f 14 2c 21 c1 b7 <br />
30 3b 8a 06 26 f1 ba de <br />
d5 c7 2a 70 4f 7e 6c d8 <br />
4c <br />
ac OP_CHECKSIG<br />
<br />
output 1:<br />
00 28 6b ee 00 00 00 00 amount = 40.00000000<br />
43 size of script (var_uint)<br />
script for output 1:<br />
41 push 65 bytes to stack<br />
04 11 db 93 e1 dc db 8a <br />
01 6b 49 84 0f 8c 53 bc <br />
1e b6 8a 38 2e 97 b1 48 <br />
2e ca d7 b1 48 a6 90 9a<br />
5c b2 e0 ea dd fb 84 cc <br />
f9 74 44 64 f8 2e 16 0b <br />
fa 9b 8b 64 f9 d4 c0 3f <br />
99 9b 86 43 f6 56 b4 12 <br />
a3 <br />
ac OP_CHECKSIG<br />
<br />
00 00 00 00 locktime<br />
01 00 00 00 hash_code_type (added on)<br />
<br />
result =<br />
01 00 00 00 01 c9 97 a5 e5 6e 10 41 02 fa 20 9c 6a 85 2d d9 06 60 a2 0b 2d 9c 35 <br />
24 23 ed ce 25 85 7f cd 37 04 00 00 00 00 43 41 04 11 db 93 e1 dc db 8a 01 6b 49 <br />
84 0f 8c 53 bc 1e b6 8a 38 2e 97 b1 48 2e ca d7 b1 48 a6 90 9a 5c b2 e0 ea dd fb <br />
84 cc f9 74 44 64 f8 2e 16 0b fa 9b 8b 64 f9 d4 c0 3f 99 9b 86 43 f6 56 b4 12 a3 <br />
ac ff ff ff ff 02 00 ca 9a 3b 00 00 00 00 43 41 04 ae 1a 62 fe 09 c5 f5 1b 13 90 <br />
5f 07 f0 6b 99 a2 f7 15 9b 22 25 f3 74 cd 37 8d 71 30 2f a2 84 14 e7 aa b3 73 97 <br />
f5 54 a7 df 5f 14 2c 21 c1 b7 30 3b 8a 06 26 f1 ba de d5 c7 2a 70 4f 7e 6c d8 4c <br />
ac 00 28 6b ee 00 00 00 00 43 41 04 11 db 93 e1 dc db 8a 01 6b 49 84 0f 8c 53 bc <br />
1e b6 8a 38 2e 97 b1 48 2e ca d7 b1 48 a6 90 9a 5c b2 e0 ea dd fb 84 cc f9 74 44 <br />
64 f8 2e 16 0b fa 9b 8b 64 f9 d4 c0 3f 99 9b 86 43 f6 56 b4 12 a3 ac 00 00 00 00 <br />
01 00 00 00 <br />
</pre><br />
<br />
To understand where that raw dump has come from, it may be useful to examine tests/ec-key.cpp in [https://gitorious.org/libbitcoin/libbitcoin libbitcoin],<br />
<br />
[https://gitorious.org/libbitcoin/libbitcoin libbitcoin] has a unit test under tests/ec-key.cpp (make ec-key && ./bin/tests/ec-key). There is also a working OP_CHECKSIG implementation in src/script.cpp under script::op_checksig(). See also the unit test: tests/script-test.cpp<br />
<br />
<source lang="cpp"><br />
#include <iostream><br />
#include <iomanip><br />
#include <bitcoin/util/serializer.hpp><br />
#include <bitcoin/util/elliptic_curve_key.hpp><br />
#include <bitcoin/util/sha256.hpp><br />
#include <bitcoin/util/assert.hpp><br />
#include <bitcoin/util/logger.hpp><br />
#include <bitcoin/types.hpp><br />
#include <openssl/ecdsa.h><br />
#include <openssl/obj_mac.h><br />
using libbitcoin::elliptic_curve_key;<br />
using libbitcoin::serializer;<br />
using libbitcoin::hash_digest;<br />
using libbitcoin::data_chunk;<br />
using libbitcoin::log_info;<br />
using libbitcoin::log_fatal;<br />
<br />
int main()<br />
{<br />
serializer ss;<br />
// blk number 170, tx 1, input 0<br />
// version = 1<br />
ss.write_4_bytes(1);<br />
// 1 inputs<br />
ss.write_var_uint(1);<br />
<br />
// input 0<br />
// prevout hash<br />
ss.write_hash(hash_digest{0x04, 0x37, 0xcd, 0x7f, 0x85, 0x25, 0xce, 0xed, 0x23, 0x24, 0x35, 0x9c, 0x2d, 0x0b, 0xa2, 0x60, 0x06, 0xd9, 0x2d, 0x85, 0x6a, 0x9c, 0x20, 0xfa, 0x02, 0x41, 0x10, 0x6e, 0xe5, 0xa5, 0x97, 0xc9});<br />
// prevout index <br />
ss.write_4_bytes(0);<br />
<br />
// input script after running OP_CHECKSIG for this tx is a single<br />
// OP_CHECKSIG opcode<br />
data_chunk raw_data;<br />
raw_data = {0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3};<br />
data_chunk raw_script;<br />
raw_script = data_chunk();<br />
raw_script.push_back(raw_data.size());<br />
libbitcoin::extend_data(raw_script, raw_data);<br />
raw_script.push_back(172);<br />
ss.write_var_uint(raw_script.size());<br />
ss.write_data(raw_script);<br />
// sequence<br />
ss.write_4_bytes(0xffffffff);<br />
<br />
// 2 outputs for this tx<br />
ss.write_var_uint(2);<br />
<br />
// output 0<br />
ss.write_8_bytes(1000000000);<br />
// script for output 0<br />
raw_data = {0x04, 0xae, 0x1a, 0x62, 0xfe, 0x09, 0xc5, 0xf5, 0x1b, 0x13, 0x90, 0x5f, 0x07, 0xf0, 0x6b, 0x99, 0xa2, 0xf7, 0x15, 0x9b, 0x22, 0x25, 0xf3, 0x74, 0xcd, 0x37, 0x8d, 0x71, 0x30, 0x2f, 0xa2, 0x84, 0x14, 0xe7, 0xaa, 0xb3, 0x73, 0x97, 0xf5, 0x54, 0xa7, 0xdf, 0x5f, 0x14, 0x2c, 0x21, 0xc1, 0xb7, 0x30, 0x3b, 0x8a, 0x06, 0x26, 0xf1, 0xba, 0xde, 0xd5, 0xc7, 0x2a, 0x70, 0x4f, 0x7e, 0x6c, 0xd8, 0x4c};<br />
// when data < 75, we can just write it's length as a single byte ('special'<br />
// opcodes)<br />
raw_script = data_chunk();<br />
raw_script.push_back(raw_data.size());<br />
libbitcoin::extend_data(raw_script, raw_data);<br />
// OP_CHECKSIG<br />
raw_script.push_back(172);<br />
// now actually write the script<br />
ss.write_var_uint(raw_script.size());<br />
ss.write_data(raw_script);<br />
<br />
// output 0<br />
ss.write_8_bytes(4000000000);<br />
// script for output 0<br />
raw_data = {0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3};<br />
// when data < 75, we can just write it's length as a single byte ('special'<br />
raw_script.push_back(raw_data.size());<br />
libbitcoin::extend_data(raw_script, raw_data);<br />
// OP_CHECKSIG<br />
raw_script.push_back(172);<br />
// now actually write the script<br />
ss.write_var_uint(raw_script.size());<br />
ss.write_data(raw_script);<br />
<br />
// End of 2 outputs<br />
<br />
// locktime<br />
ss.write_4_bytes(0);<br />
<br />
// write hash_type_code<br />
ss.write_4_bytes(1);<br />
<br />
// Dump hex to screen<br />
log_info() << "hashing:";<br />
{<br />
auto log_obj = log_info();<br />
log_obj << std::hex;<br />
for (int val: ss.get_data())<br />
log_obj << std::setfill('0') << std::setw(2) << val << ' ';<br />
}<br />
log_info();<br />
<br />
data_chunk raw_tx = {0x01, 0x00, 0x00, 0x00, 0x01, 0xc9, 0x97, 0xa5, 0xe5, 0x6e, 0x10, 0x41, 0x02, 0xfa, 0x20, 0x9c, 0x6a, 0x85, 0x2d, 0xd9, 0x06, 0x60, 0xa2, 0x0b, 0x2d, 0x9c, 0x35, 0x24, 0x23, 0xed, 0xce, 0x25, 0x85, 0x7f, 0xcd, 0x37, 0x04, 0x00, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3, 0xac, 0xff, 0xff, 0xff, 0xff, 0x02, 0x00, 0xca, 0x9a, 0x3b, 0x00, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, 0xae, 0x1a, 0x62, 0xfe, 0x09, 0xc5, 0xf5, 0x1b, 0x13, 0x90, 0x5f, 0x07, 0xf0, 0x6b, 0x99, 0xa2, 0xf7, 0x15, 0x9b, 0x22, 0x25, 0xf3, 0x74, 0xcd, 0x37, 0x8d, 0x71, 0x30, 0x2f, 0xa2, 0x84, 0x14, 0xe7, 0xaa, 0xb3, 0x73, 0x97, 0xf5, 0x54, 0xa7, 0xdf, 0x5f, 0x14, 0x2c, 0x21, 0xc1, 0xb7, 0x30, 0x3b, 0x8a, 0x06, 0x26, 0xf1, 0xba, 0xde, 0xd5, 0xc7, 0x2a, 0x70, 0x4f, 0x7e, 0x6c, 0xd8, 0x4c, 0xac, 0x00, 0x28, 0x6b, 0xee, 0x00, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3, 0xac, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00};<br />
BITCOIN_ASSERT(raw_tx == ss.get_data());<br />
<br />
hash_digest tx_hash = libbitcoin::generate_sha256_hash(ss.get_data());<br />
<br />
data_chunk pubkey{0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3};<br />
// Leave out last byte since that's the hash_type_code (SIGHASH_ALL in this<br />
// case)<br />
data_chunk signature{0x30, 0x44, 0x02, 0x20, 0x4e, 0x45, 0xe1, 0x69, 0x32, 0xb8, 0xaf, 0x51, 0x49, 0x61, 0xa1, 0xd3, 0xa1, 0xa2, 0x5f, 0xdf, 0x3f, 0x4f, 0x77, 0x32, 0xe9, 0xd6, 0x24, 0xc6, 0xc6, 0x15, 0x48, 0xab, 0x5f, 0xb8, 0xcd, 0x41, 0x02, 0x20, 0x18, 0x15, 0x22, 0xec, 0x8e, 0xca, 0x07, 0xde, 0x48, 0x60, 0xa4, 0xac, 0xdd, 0x12, 0x90, 0x9d, 0x83, 0x1c, 0xc5, 0x6c, 0xbb, 0xac, 0x46, 0x22, 0x08, 0x22, 0x21, 0xa8, 0x76, 0x8d, 0x1d, 0x09};<br />
BITCOIN_ASSERT(signature.size() == 70);<br />
<br />
elliptic_curve_key key;<br />
if (!key.set_public_key(pubkey))<br />
{<br />
log_fatal() << "unable to set EC public key";<br />
return -1;<br />
}<br />
<br />
log_info() << "checksig returns: " << (key.verify(tx_hash, signature) ? "true" : "false");<br />
return 0;<br />
}<br />
<br />
</source><br />
<br />
==References==<br />
<references/><br />
<br />
[[Category:Technical]]<br />
[[Category:Developer]]</div>
Smtp