Introduction
Hi!
I’m Alex, and I’m somewhat experienced when it comes to programming but I haven’t done significant work in C++ in some time, and I’ve never worked with Bitcoin Script, the language in which Bitcoin (and Syscoin) smart contracts are written.
So here is how I plan to get ready to become a code contributor.
Plan
-
Transaction Logic
-
Learn Bitcoin Script
- Learn the basics of how the language works
- Learn what opcodes there are and what they do
- Study the existing Syscoin smart contracts
- Write some smart contracts myself
-
Learn Bitcoin Script
-
Client/Wallet Design
- Get an overview over the different parts of Syscoin’s code
-
Learn how the different parts work
- Start with consensus logic
- Fix a first bug or make a first contribution
Resources
- Learning Bitcoin from the Command Line is an open book hosted on github. It’s a goldmine when it comes to learning to work with bitcoin transactions — from using the console to crafting them by hand.
- Overview of Bitcoin Core 0.11 is a wiki book hosted on bitcoin.it. It’s an in-depth look at the code structure of Bitcoin 0.11, so likely a bit outdated but still a good resource to get a general idea of how things work.
What I learned
- Bitcoin/Syscoin Script is written in Reverse Polish notation
- The operators to a function are located left of the function:
2 3 +
instead of2 + 3
- Code is evaluated from left to right
- first_command second_command third_command
- The operators to a function are located left of the function:
- The evaluation of the language works in a very simple way
- the first (leftmost) element of the script is read
1.a. if it is data, the data is pushed to the stack,
1.b. if it is an operation instead data on the is popped, evaluated and potentially a result is pushed. - the next (now leftmost) element of the script is read
- the transaction is valid if the script isn’t terminated prematurely and after it is finished
TRUE
is the topmost stack element.
- the first (leftmost) element of the script is read
- Bitcoin Script opcodes can be found here.
- Bitcoin/Syscoin transactions have smart contracts locking the outputs and inputs
- to be able to spend some input, you first run the
scriptSig
of the vin of the spending transaction followed by thescriptPubKey
of the vout of the funding transaction output.- in reality the stack produced by the
scriptSig
is copied to a new environment and thescriptPubKey
is evaluated then, but for purely understanding the script logic one can just concatenate the two
- in reality the stack produced by the
- to be able to spend some input, you first run the