Basics of Bitcoin Scripts

Published by Martin Schuster on

The Bitcoin scripting language consists of four main attributes:

  • Forth-like
  • Stack-based
  • Reverse-polish Notation
  • Turing incomplete

The first attribute forth-like describes the resemblance of Bitcoin script to the programming language forth, which is also stack-based. Stack-based describes a common and popular data structure where the operations are structured in a linear logical order. The basic idea behind this is last in first out, or LIFO for short. A stack works with two operations push and pop, where push is pushing something onto the stack and pop is popping something of the stack. The third attribute reverse polish describes the notation in a system where operators follow the operands.

Reverse Polish Notation Example

With the fourth attribute, Turing incomplete, the bitcoin scripting language has only limited functionality and cannot make jumps or loops. Because bitcoin scripts are rather simple and don’t need to be as complicated as Ethereum smart contracts, this is fine for bitcoin and also adds a layer of security where malicious parties can’t create scripts that would negatively affect the hash rate of the bitcoin network.

The operations that a Bitcoin script can execute are called op_codes, below is a table with some of these op_codes and an explanation. A complete list can be found under the following link ( 

1OP_CHECKSIGThe entire transaction’s outputs, inputs, and script are hashed. 
2OP_CHECKMULTISIGCompares the first signature against each public key until it finds an ECDSA match.
3OP_ADDa is added to b.
4OP_MAXReturns the larger of a and b.
5OP_RIPEMD160The input is hashed using RIPEMD-160.
6OP_PUBKEYRepresents a public key compatible with OP_CHECKSIG.
Examples for OP_Codes