Address Bitcoin

What is the Stack?

Bitcoin in Action
4 min readFeb 1, 2021

Hello Fellas!

We had a mad idea! We want to talk about all Bitcoin addresses. Often we heard about Pay To Public Key, Pay to Public Key Hash, Pay To Script Hash, and so on. But…But What are they?

These are challenging topics, for that reason we are using a whiteboard (check our video on youtube, Italian language 🍕). To understand deeply, We wrote three books. Book Bitcoin from theory to practice, PocketBook Bitcoin 199 questions and Bitcoin In Action — SegWit, Bitcoin Script e Smart Contracts (Italian language).

We can start by saying, We don’t have addresses but scripts! The addresses are the results of cryptography functions on the public key.

We start with P2PK, Pay to Public key.
Hold on! What does mean PAY to PUBLIC KEY? Will I pay for a public key?
Yes, when we create a transaction, it will unlock through check the Signature on the Public key.

We saw into the previous articles and video, how the signature can be a check on the public key. Hold on: to find out, we must take a step back in time, and understand what is the STACK!

We can be imaging a stack like piled data one above the other. In Bitcoin we have a LIFO stack, LAST IN FIRST OUT. The last element to enter (PUSH) into the stack, is the first element to remove (POP).

Push, which adds an element to the stack
Pop, which removes the most recently element added, that was not yet removed.

Let’s see together one example to better understand the issue.
We want to create a SUM, 2+2. We need to explain that Bitcoin uses a programming language, called Bitcoin Script (what a fantasy! 🦄) to insert the data into the Stack. A characteristic of Bitcoin Script is that it’s Reverse Polish (RPN).

Reverse Polish notation is a syntax used for mathematical formulas.
With the RPN it’s possible to carry out any type of operation, with the advantage of eliminating problems due to parentheses and operator precedence.
Even today some calculators use the RPN.

In the Reverse Polish notation operators follow their operands.
(book-excerpt)

Adress introduction – Italian Language

So, we need to add 22 before the ADD operation.

OP_2 OP_2 OP_ADD

The program inserts the first element into the stack (PUSH).

The program inserts the second element into the stack (PUSH).
In the end, the program uses OP_ADD, its job is to get the first two elements on top, evaluate the SUM and insert the result.

The operation is POP 2, POP 2, PUSH 4.

It’s the first step to understand how Bitcoin validates the transactions and how the addresses are built to satisfy these processes. That’s so cool.

Bitcoin from theory to practice (Amazon)

--

--

Bitcoin in Action

Bitcoin. Money for nerds? Digital gold? Perhaps, but certainly it is a social revolution!