Skip to main content

Blockchain Essentials


Intro Video

Photo of Ermin Kreponic

Ermin Kreponic

Training Architect







Course Details

Greetings! Welcome to this Linux Academy’s Blockchain Essentials course. Blockchain has become a buzzword throughout the decade and has enticed many computer, math, and business enthusiasts, as well as the general public. Most people have heard about it because of the cryptocurrency Bitcoin. Blockchain is a revolutionary technology that has offered the world a new way of performing transactions of assets (not just money) of various kinds. It has also given us a new perspective on how to resolve certain issues related to these transactions, and how to implement different principles. If you wish to learn, in depth, the mechanics behind blockchain, to understand the protocols it uses, and to explore its many applications, then this is a course for you. You will be given a thorough introduction to what blockchain really is, and what is important to know in order to grasp it. You will learn what mathematics are behind it and what kind of algorithms and protocols can be used to implement a blockchain of some kind. And there are a lot of them!

If we retrace some of the events that lead to the creation of blockchain, we can go all the way back to 1962 when Paul Baran wrote a paper about distributed communications networks. In 1982 an interesting thought problem was posed called the Byzantine Generals Problem. It looked for a practical way of achieving communication and consensus between entities, despite the existence of attackers or faulty entities. A solution was given in 1999 with the formulation of the Practical Byzantine Fault Tolerance (PBFT) algorithm. Then in 2009 the first ever implementation of the algorithm was given, in the form of the Bitcoin blockchain.

We will start the course off with the basics: the concept of blockchain and the important terminology you need to comprehend in order to really understand what we are talking about. One way we can define a blockchain is by saying that it is a decentralized mechanism that establishes a consensus for past and current transactions, divided into blocks. From a developer’s perspective, we can say that a blockchain is a type of data structure. Later, we will dig deep into the underlying architecture of blockchains, and the many consensus mechanisms that can be used to run a blockchain. Be prepared to get into the mathematics of how hashing algorithms work, and what they are based on. Prime numbers play an important role in the blockchain world. There will be individual sections dedicated to these consensus mechanisms and mathematical principles. We will also examine the structure of the Bitcoin and Ethereum blockchains, so that we can learn their fundamental similarities and differences. As the course progresses you will see how blockchains can be used for so many different things and situations, not just cryptocurrencies. There will be a section dedicated to these use cases as well.

Some say that blockchains are the future, and that they will be used progressively more and more. They are likely to make an impact in the way we trade assets, store assets, conduct food safety regulation, record patient information in healthcare, perform supply chain management, vote in elections and much more. Join us in this interesting course and dive into the world of blockchain.


Getting Started

About the Author


Lesson Description:


About the Course


Lesson Description:


How to Get Help


Lesson Description:




Lesson Description:


Text Editor VIM


Lesson Description:

This video covers a few basics about the VIM text editor. VIM stands for Vi IMproved and it is an improved version of the older Vi editor. It is used for any kind of Linux interactions through the shell. VIM will be used throughout this course in several videos so it would be beneficial for you to know how to navigate through it. We will go over some of the basic commands that you will need. First, we will install VIM on our machines and then see how we can open/create a file, enter insert mode, how to write to a file, how to save it and how to quit the edit mode.


What is Blockchain Part 1?


Lesson Description:

In this introduction video, we give a general talk about what blockchain is and what it's composed of. We start by defining blockchain as a decentralized mechanism that establishes a consensus for past and current transactions, divided into blocks. We can view blockchains as a data structure of their own. After that, we go over some blockchain characteristics such as transparency, immutability, etc. We also present a historical overview of how blockchain came into existence and where it's going in the future. Finally we touch on an explanation of the different spheres where blockchain is used.

What is Blockchain Part 2?


Lesson Description:

Here we go into a little more detail on the subject of blockchain structure. We get a rough idea about the blockchain architecture and see what each block in a blockchain contains. We teach how blocks are connected to other blocks in the chain and why they are connected in that way. We also briefly introduce the Proof of Work consensus mechanism.

Types of Blockchains Part 1


Lesson Description:

In this video, we start talking about the different types of blockchains that exist as well as their characteristics, differences, and similarities. We cover public and private blockchains this time. Public blockchains are the most common type of blockchain. They are not under anyone’s ownership. Anyone can participate and be a node in the blockchain if they wish. Bitcoin and Ethereum are examples of a public blockchain. In contrast, we also have private blockchains that are permissioned blockchains where the maintenance and usage is limited to a selected group of people (e.g. a company or organization). The group members share the ledger among each other. We can say that the users of public blockchains are anonymous, while users of private blockchains are known. Some known private blockchains are R3, Quorum, and Hyperledger.

Types of Blockchain Part 2


Lesson Description:

Continuing on from where we left off last time, we talk about semi-private blockchains and sidechains in this video. Semi-private blockchains are partially public and partially private. The public part functions like a public blockchain where anyone can engage, while the private part functions like a private blockchain and is limited to a selected group of people. Semi-private blockchains are mainly controlled by a single owner that first deploys the blockchain technology and afterwards finds users. The users are given access to the network as long as they are in line with a pre-established defined criteria. Sidechains are blockchains connected to a main blockchain (parent) where digital assets (e.g. cryptocoins) inside of the parent blockchain can be transferred to the sidechain (child chain). This is a one-way sidechain. In two-way sidechains, assets from the sidechain can be transferred back to the parent chain. Later, we will go over shared ledgers, tokenized blockchains, and tokenless blockchains.

Terminology Part 1


Lesson Description:

On the topic of blockchain terminology, today we are going to cover addresses. Addresses are unique identifiers comprised of 26 to 35 alphanumeric characters used to denote senders and receivers. Users can choose whether or not to reuse addresses they created before or create a new one for each transaction. The reuse of addresses makes it easier to identify which user created it. In the video, we talk about why addresses are crucial for blockchain transactions and explain the process of obtaining an address by generating key pairs and using sha256sum. Creating multi-signature addresses is also possible, but it requires more than one private key.

Terminology Part 2


Lesson Description:

Continuing on the subject of blockchain terminology, we use this video to talk about several blockchain terms, starting with transactions and transaction fees. Transactions are the main units of blockchain technology. They are used for transferring values from one address to another. We go over how transactions function in a blockchain such as Bitcoin and Etherium, and why transaction fees are needed in order for blockchains to work. The bigger the transaction, the bigger the transaction fee. In the video, we also talk about the Turing Complete computability theory used for abstract machines and explain its importance. The theory states that any system of data manipulation rules that simulate a Turing machine is called Turing complete. Lastly, we talk about blockchain blocks and what kind of data they are composed of.

Terminology Part 3


Lesson Description:

As mentioned in the previous video, we start this one off explaining what block explorer, block height, and block rewards are. Block explorer is a web tool used for viewing information about addresses, transactions, transaction histories, and individual blocks in a blockchain network. Block height represents the number of blocks ahead of the given block in the blockchain network. Every block contains a header defining the current block height. Block rewards are rewards for the miners which solve some type of mining puzzle. Further on, we define central ledgers and peer-to-peer networks. A central ledger represents records about all financial transactions of an organization. Centralized ledger means there's a main ledger containing all information in one place. Lastly, we talk about peer-to-peer networks. A P2P network is a type of network where each peer can contact other peers and exchange information. There is no need for one central server.

Terminology Part 4


Lesson Description:

In this video concerning blockchain terminology, we start by explaining a very important blockchain term called smart contracts. Smart contracts are computer programs or protocols used to set the rules of a contract between two parties. Smart contracts can also be called crypto-contracts. They enable us to set certain rules for some agreement we're making, enforce those rules, and transfer the digital currencies between parties if the contract’s conditions are met. Smart contracts are very useful, however, there are some downsides to them we discuss. Oracles are important in the context of smart contracts because they serve as a third-party information source and are a part of the smart contract system. Since smart contracts are not able to access external data that might be necessary for a rule to be executed, oracles can deliver that external data to them. Smart contracts use secure channels during data transfer and are considered secure. Lastly, we talk about what consensus and confirmation mean in the context of blockchains.

Terminology Part 5


Lesson Description:

Moving on with our terms, today we cover the terms cryptocurrency and cryptographic hash function. Cryptocurrencies are considered to be a digital form of money. They are not to be interchanged with the term blockchain, since cryptocurrencies are just one of the many blockchain use cases that exist. Cryptocurrencies use high-end encryption tecniques to create funds and to verify their transfer. Cryptographic hash functions are functions that take an input value of some length, and extract another value of a fixed length from it. Even if two input values differ by only one character, their output hashes will be totally different. We also go through a simple example of how a hash function works.

Terminology Part 6


Lesson Description:

This time we go over several other important terms concerning blockchains. We start with explaining what decentralized apps (DAPPs) and decentralized autonomous organizations (DAOs) are. Dapps are basically applications whose backend runs on multiple computers as part of a decentralized network. Decentralized autonomous organizations or DAOs are software that runs on top of a blockchain. After covering these two terms, we move on to explaining distributed ledgers and distributed networks a bit more. Distributed ledgers are basically distributed databases, while distributed networks are networks that exand across several networks. After that, we cover what the terms "difficulty" and "double spending" mean. Difficulty represents how hard it is (or how long it takes) to find the hash needed to add a new block to a blockchain. Double spending represents an attack where an entitiy tries to spend the same cryptocoins in more than one transaction at the same time. Lastly, we introduce multi-signatures and digital signatures that will be covered in more detail later.

Terminology Part 7


Lesson Description:

Many new terms await us in this video. We start off with talking a bit about the Ethereum blockchain and some terms related to it such as EVM and Solidity. Ethereum is a blockchain technology product based on the Turing complete programming language called Solidity. Ethereum itself is not only a platform and cryptocurrency, but also a programming language. One of its defining features is the Ethereum Virtual Machine (EVM). Afterwards we talk about the Testnet software, used for testing out new features and changes to blockchains without disrupting the primary blockchain software. Blockchains can be updated and their protocols changed. These updates to protocols are called forks. Forks can be hard forks and soft forks. Hard forks are not backwards-compatible, while soft forks are. Lastly, we talk about what hashes and genesis blocks are.

Terminology Part 8


Lesson Description:

In this last terminology video, we introduce several terms for this section. Continuing on from the last video where we talked about hashes, here we start off explaining what a hash rate is, followed by the terms mining and crypto-wallet. A hash rate is simply the speed of computing hashes per second. Hash rates were much slower when bitcoin miners mined with CPUs. Later, Application Specific Integrated Circuits (ASICs) replaced CPUs. We also talk about how the computer's GPU and CPU can be used for mining. Mining is the process of inserting a transaction into a blockchain's ledger where all previous transactions are also recorded. We talk a bit about public and private keys, as well as what nodes are. Nodes are parts of the blockchain network that carry out different functions (e.g. transaction validation, mining, or other tasks) depending on the kind of blockchain and its purpose.

Blockchains Versus Cryptocurrency


Lesson Description:

In order to conclude this section, this time we make a comparison between blockchains and cryptocurrencies. It is important to know that these two are not the same thing and they are fundamentally different. Blockchains are used for data storage, digital identity, transactions, and they all functions on the principles of some consensus mechanism. Cryptocurrencies are a medium of exchange, a store of value and representation of assets. In essence, cryptocurrencies use blockchain technology in order to function and they were the first thing blockchains were utilized for, which is why they are mixed up so often. Blockchains have a variety of usages.


Blockchain Architecture Part 1


Lesson Description:

This time we take a look at blockchain architecture and see what blocks are made out of. We introduce the different elements that make up a bitcoin blockchain block such as block numbers, block sizes, block hashes, versions, hashMerkleRoots, number of transactions, TimeStamps, bits, nonces, hashPreBlocks and transactions. We explain each of these elements and demonstrate their purpose in a block. Some terms will be intuitive, while some will need more explaining. The block number represents the number of a block in a line of blocks. The TimeStamp represents the time when hashing actually took place. The hashMerkleRoot is a special methodology used in order to create a hash. We cover how Merkle Trees work and see how all of this together makes up the blockchain architecture.

Blockchain Architecture Part 2


Lesson Description:

In this video, we continue on the subject of blockchain architecture and go into more detail concerning the terms bits, nonces, difficulty, hashPreBlocks and transactions. The hashPreBlock variable contains the hash of the previous block and is embedded into the current block. The bits are just another representation of difficulty, while the difficulty is determined by the targeted number of zeros that the hash needs to begin with. We know that when mining, it is required to generate a hash of a block that has a specific number of zeros at the beginning. However, this is a simplified way of looking at things. In this video, we discuss this in depth and aim to understand the full picture of what is actually happening through an example.

Blockchain Architecture Part 3


Lesson Description:

Here we continue on from the last video about how a block hash is actually created. We continue talking about the difficulty parameter and see how new difficulties are calculated. In the case of the bitcoin blockchain, a new difficulty is calculated every two weeks. First, it is determined if the difficulty is too high or too low, and then the difficulty is changed to fit the situation. In order to mine a block, the target difficulty needs to be established, which is what we will calculate together. By the end of the video, we will produce our wanted block hash with a certain number number of zeros at the beginning.

Blockchain Architecture Part 4


Lesson Description:

In this video, we compare the block hash we produced in the last video to the target difficulty. The block hash must be smaller than the target difficulty. If this condition is satisfied, then we know we've produced a valid block hash. When we have successfully created our block hash, we will make a quick recap of what we've done.

Blockchain Architecture Part 5


Lesson Description:

In this final video about blockchain architecture, we demonstrate the Proof of Work protocol written in Python code. In the previous videos, the way we calculated certain parameters was based on the Proof of Work algorithm, so here we make a comparison between our calculations and the Python code.

Digital Signature Part 1


Lesson Description:

In this intial video, we introduce digital signatures. We first share what digital signatures are through an example. Then, we examine the underlying mathematics. We show how it is done, do it ourselves, and go through the verification process. Let's say we have two users, User1 and User2. User1 wants to send some document to User2. They would also like to sign the document in some way so that User2 can know the document was signed specifically by User1 and the document hasn't been tampered with in transit. Digital signatures help us achieve this. In short, User1 signs the document with a signing algorithm, then User2 uses a verification algorithm to verify the identity and integrity of the document.

Digital Signature Part 2


Lesson Description:

Continuing on the topic of digital signatures, today we implement the digital signature algorithm (DSA) and see how the mathematics behind it work. The mathematics are not that complex, but there is a lot of manual labor involved to calculate everything. This is why it is not recommended to do manual calculations in practice, but rather use the implementation of this algorithm within a library or part of another program. Otherwise, the implementations have a high chance of containing flaws. The mathematics of digital signatures are based on calculations with prime numbers. The process consists of 11 steps that we begin explaining in this video.

Digital Signature Part 3


Lesson Description:

In the last video, we successfully calculated our public and private keys. Now, we need to make use of these keys and sign a document. We compute the first and second part of the signature. The first part is computed using the modulus operator on the generated public and private key. The second part of the signature is calculated by using the SHA hashing algorithm, along with a few other operations. The modular inverse and recursive algorithm will also be explained.

Digital Signature Part 4


Lesson Description:

In this video, we go through the algorithm of calculating a modular inverse with a smaller number, just so we can see the mathematical procedure of how it is found. The goal is to find the number x, that, when multiplied with Ke, equals the remainder when we divide 1 by q. After going through the whole process, we calculate x that will then be used to plug into the Step 11 equation in order to find s, the second part of the signature.

Digital Signature Part 5


Lesson Description:

Now we have successfully created our signature. We have calculated both parts of the signature, r and s. This signature will only be valid for the specific document it's tied to. If one bit is changed, it will no longer be valid. We talk about the validation process that has four steps.

Blockchain Consensus Mechanisms

Introduction to Blockchain Consensus Mechanisms


Lesson Description:

In this introduction video, we get acquainted with consensus mechanisms. We see some of the important consensus mechanisms used in practice by different blockchains such as proof of work, proof of stake, proof of burn, practical byzantine fault-tolerant mechanism, and others. Proof of work is one of the most-used blockchain consensus mechanisms by many blockchains, one of them being Bitcoin. In the upcoming videos, these mechanisms will be thoroughly explained in individual videos. In theory, a large amount of consensus mechanisms can be created. However, not all of them get implemented. A large portion of them remain theoretical. The mechanisms we talk about are some of the most-used ones in practice.

Proof of Work Part 1


Lesson Description:

We discuss the Proof of Work algorithm in this video. Proof of Work is a consensus algorithm that demands some form of work from users. In most cases, this is the expenditure of computer power. It is based on the principle that a certain amount of computational power needs to be expended before suggesting a value to be entered into the blockchain. Once it validates a new block, it adds it to the blockchain. Proof of Work is very common in cryptocurrencies such as bitcoin and others. Throughout the video, we demonstrate the logic of how Proof of Work functions by taking a look at a bitcoin block and going over the bitcoin mining process. We also take a look at some of the pros and cons associated with this mechanism.

Proof of Work Part 2


Lesson Description:

Continuing from the last video, we proceed with our bitcoin mining process here. We've already been introduced to what kind of content can be found inside a bitcoin block and we've learned about nonces as well. In this video, we give an example of how to create our own target value where the goal is for the block hash value to be smaller than the target value.

Proof of Stake


Lesson Description:

Today we talk about Proof of Stake. Proof of Stake is a consensus algorithm that many different cryptocurrency networks use for reaching a distributed consensus. Proof of Stake was made in opposition to Proof of Work. When a new block needs to be created, a Proof of Stake cryptocurrency system chooses the new person for validation and mining by checking how many coins the person has. The version with more coins gets more mining power. When a transaction starts, it gets placed in a block, and the transaction size is limited to one megabyte. After that, the transaction data gets duplicated on other nodes. Those nodes have the task of checking and verifying transactions in the blocks. We talk about the pros and cons of Proof of Stake. We also make a comparison between Proof of Stake and Proof of Work to highlight their differences and see which aspects of the mechanisms are better than others. For example, the Proof of Work protocol favors the ones with the most power while the Proof of Stake protocol favors the ones with the most stake.

Delegated Proof of Stake Part 1


Lesson Description:

This time we go over Delegated Proof of Stake. DPoS is a consensus algorithm very similar to the Proof of Stake algorithm, so we point out differences aand similarities between the two throughout the video. DPoS is considered to be more democratic than PoS, which is why it is also called digital democracy. The coin holders vote for the delegates or witnesses in an election process. Witnesses then have a mission to create and validate blocks. The witnesses are chosen according to the consensus rules. Usually somewhere between 21 and 101 are picked. Witnesses validate the transactions. After that, they are rewarded with coins. Stakeholders get the amount of votes equivalent to their share of coins. They also have an option to give their stake to other stakeholders who will then vote for both of them. Witnesses produce a block in a few seconds. Each one has a scheduled time for forging. Mining in a DPoS system is called forging. If a witness fails to produce a block, they lose their reputation and will be replaced by a new witness. In some cryptosystems, the witnesses are required to give some coins as a stake. In the case of malicious behavior, they will be taken. The general rule for malicious behavior is that the longer chain is not the faulty one, so witnesses will switch to longer chains in these situations.

Delegated Proof of Stake Part 2


Lesson Description:

In this video, we continue talking about Delegated Proof of Stake. We learn about stake holders, elected delegates, voting processes, validation, and the forming of blocks. In the video, we take a look at a network of nodes where stake holders choose the delegates. They do that by voting for the delegates, and their vote importance is equal to the percentage of stake they own. In the voting part, the delegates are selected, usually a number between 21 to 101. In some configurations, the delegates must submit a fee in order to become delegates. If they try to do something considered harmful to the network, the fee will be confiscated. One stake holder can transfer their voting power to another node, and then the other one votes for both. We also cover the cons of Delegated Proof of Stake. One of them is the problem where the new delegates have trouble becoming delegates because of old nested delegates.

Proof of Burn


Lesson Description:

This time we talk about the Proof of Burn consensus mechanism. We discuss what Proof of Burn is and how it works. Proof of Burn is a consensus mechanism used for destroying cryptocurrencies in a verifiable way. In the case of bitcoin, proof of burn can be used to destroy a certain number of bitcoins relative to the number of altcoins that need to be claimed. If an individual destroys five bitcoins, then the value of altcoins in their possession cannot be higher than five bitcoins. Essentially, by destroying bitcoins, those bitcoins get converted to some other cryptocurrency (altcoins). We can say that this mechanism is a type of mining where value is given to new coins by destroying other coins that have value. In other words, it is a method of destroying cryptocurrencies in a verifiable way. Proof of burn has the following properties: undependability, uncensorbility, and binding.

Practical Byzantine Fault-Tolerant Mechanism


Lesson Description:

In this video, we see what events and problems lead to the idea of blockchain appearing. We talk about the Generals Problem and the Practical Byzantine Fault Tolerance Mechanism. Practical Byzantine Fault Tolerance stems from the Byzantine Generals Problem that was formulated in 1982. The problem describes a situation in which a number of generals is each leading their own part of the Byzantine army. It is important that the generals can all agree whether or not to attack and when, however there are many problems that arise when trying to achieve this communication. The question is, in what way can agreement be enabled between the groups even if there is misleading information being sent among them. The problem was solved in 1999 when the Practical Byzantine Fault tolerance algorithm was formulated. PBFT is the property of a system that is resilient to failures and enables the system to function properly and attain adequate consensus, despite the existence of nodes that are malicious or fail to communicate with other nodes. PBFT aims to secure systems from failing and lower the influence of these kinds of nodes.

Proof of Elapsed Time


Lesson Description:

Today we talk about Proof of Elapsed Time. We learn about Hyperledger Sawtooth cryptonetwork and SGX (Software Guard Extensions), a special set of CPU instructions made by Intel needed for Proof of Elapsed Time. The first step is proving our identity and that is done by SGX. The second step is joining the lottery where we go to “sleep” for the elapsed time we were given. When that time expires, we can validate the network. We introduce the pros and cons of this. We share why Proof of Elapsed Time is considered the best algorithm for permissioned networks and why it's efficient with respect to energy and computing power. Also, we indicate why it is considered decentralized and how that's a problem for Proof of Elapsed Time.

Proof of Importance


Lesson Description:

This time, we go over the Proof of Importance consensus mechanism. We explain several of its main characteristics. POI is a consensus algorithm made by a peer-to-peer cryptocurrency platform called NEM (New Economy Movement). NEM was written in Java. Proof of Importance decides which nodes can add a block to the blockchain. This process is called harvesting. POI gives rating to the nodes that rating decides who will be chosen to harvest (mine). After harvesting a block, the nodes get a transaction fee for their efforts. It is very similar to Proof of Stake, since they both require a stake to compete in a way. POI requires other factors, such as activity clusters and net transfers.

Algorithms and Mathematics behind Blockchain Technology

Cryptography General Talk


Lesson Description:

In this introductory video, we talk about the topics we'll cover in this chapter. This chapter focuses on teaching the underlying mathematics and algorithms behind blockchain. We also cover the significance of prime numbers. Prime numbers form the basis of cryptography. Without them and their properties, the cryptography of today would not exist the way it does. We talk about random numbers as well. Even though random numbers might seem trivial, generating one using a computer is not so trivial. We show how synchronous and asynchronous encryption works, how the RSA and SHA algorithms produce hashes, and more.

Prime Numbers Part 1


Lesson Description:

In order to understand the mathematics behind cryptography and hashing functions, we need to know what prime numbers are. They are the bedrock of cryptography. A prime number is any number divisible only by itself and by 1. Some examples are 3, 7, 11, 19, etc. As we move to infinity, the density of prime numbers decreases. There are several methods to determine if a number is prime or not, however many of them are not computationally efficient. In this video, we focus on explaining what deterministic and probabilistic primality tests are, as well as in what situations they are used.

Prime Numbers Part 2


Lesson Description:

In this video, we focus on deterministic primality tests and go over trial division in more detail. We will see why these algorithms are not used in practice, despite being able to produce correct answers. We provide a small code implementation of trial division to show what it looks like.

Prime Numbers Part 3


Lesson Description:

Continuing on the subject of primality testing, this video goes over Wilson’s theorem, another deterministic algorithm like trial division. Wilson’s theorem is also quite ineffective when it comes to performing primality tests for very large numbers. We provide a small code implementation of Wilson’s theorem to show what it looks like. Notice that this algorithm utilizes the factorial operation as its main operation for testing, as opposed to trial division, which uses division.

Prime Numbers Part 4


Lesson Description:

Now we are going to move on to probabilistic primality tests and look into the Miller-Rabin algorithm in a bit more detail. Probabilistic algorithms give a probabilistic answer about whether a number is a prime or not. It does not guarantee with 100% certainty that the number is a prime, but it does give a certain degree of confidence. This is used for finding extremely large prime numbers. The Miller-Rabin algorithm runs two tests. If both tests fail, then the number is not a prime number. If at least one test passes, then the number is probably a prime number. In the video, we provide a demonstration of this algorithm to show how the process works.

Prime Numbers Part 5


Lesson Description:

Continuing where we left off last time, we finish our demonstration of the Miller-Rabin primality test. We iterate through a for loop that executes the amount of times we set (testNum). The more times it iterates, the more confident we can be about the primality of the number. If we determine a number is prime in the first iteration, and then we run the same test a few more times and all of them say that it is a prime, then we can say the chance of the number being a prime is very high.

Random Number Generation


Lesson Description:

Generating random numbers is an important aspect of cryptography. It might seem trivial, but it's not so simple when it comes to computers. Computers are finite state machines where everything is defined and there is an instruction for everything. In this kind of system where everything has its place, it is impossible to generate a truly random number. Random numbers generated by computers are called pseudo-random numbers. True random numbers can be generated from nature by measuring random fluctuations like noise. In that case, we take a sample from a natural event and get a random value. These are the kinds of things we talk about in this video to show how the concept of randomness is translated to computers, and how we use these random numbers.

RSA - Rivest–Shamir–Adleman Part 1


Lesson Description:

RSA is a cryptographic algorithm created in 1978 by Ron Riverest, Adi Shamir, and Leonard Adleman (hence the name RSA). The reason for its invention was to succeed the less secure NBS algorithm. RSA implements two significant terms: public-key encryption and digital signatures. We talk about both throughout the videos. Public key encryption is a type of encryption where two kinds of keys are generated: public keys known to everyone and private keys known only to a single user. In RSA, public keys are what encrypt data and private keys decrypt it. In this video, we start with the RSA pre-process which is the generation of keys. For all the things we do, we will have a Python implementation of them as an example to help with understanding.

RSA - Rivest–Shamir–Adleman Part 2


Lesson Description:

Here we continue with the RSA algorithm. We start with the process of key exchange. We take a look at an example where one user (Tom) needs to send a message to another user (Terry). Before Tom sends his message to Terry, he needs to encrypt it. When he encrypts it, he needs to share his public key with Terry so that she can encrypt her reply and send it back. Tom will use parameters from Terry’s public key to encrypt his message. Terry will use her private key to decrypt the message. It is important to note that senders do not possess the ability to decrypt their own messages. Only the receiver can do that, so the sender must make sure they don't lose the original message they are sending. Both users need their private and public keys so the exchange can be successful. In this video, we generate all necessary parameters needed for the encryption and decryption of Tom’s message (the public and private keys). We also talk briefly about symmetric and asymmetric cryptography in general and some vulnerabilities related to them.

RSA - Rivest–Shamir–Adleman Part 3


Lesson Description:

Now that we generated our private and public keys, let's move along to implementing how we can encode, encrypt, and decrypt Tom’s message. First, we need to encode Tom’s message. We do that by converting every character of the string to its decimal representation. In this video, we demonstrate how to perform this procedure. When we encode the message, that encoded message will be the one that gets encrypted.

RSA - Rivest–Shamir–Adleman Part 4


Lesson Description:

In this video, we perform the actual encryption of our encoded message as well as its decryption from the receiver side. The encryption is done by sending the encoded message to an encryption function. The encryption function encrypts each decimal character of the encoded message and adds it to a list. The resulting list represents our encrypted message. The decryption process will exponentiate the encrypted message with d and look for mod N. This is done in the decryption function. When the decryption process is done, the last step is decoding each character of the decrypted message.

RSA - Rivest–Shamir–Adleman Part 5


Lesson Description:

So far we have explained the concept and introduced a code implementation for the RSA algorithm. Here we run our Python program and once more go over the encryption and decryption process through a practical example. We open a file containing some text and proceed to both encrypt and decrypt it. We go through each step of the program and see what happens in each step. In the end, we will be able to view a decrypted and decoded version of the message we encrypted. They should be the same, but might be formatted in a different way.

RSA - Rivest–Shamir–Adleman Part 6


Lesson Description:

In this final video concerning RSA, we take a look at how we can create an RSA signature and how the procedure works. Again, we have our sender and receiver Terry and Tom. Terry wants to send Tom a signed message. Terry signs her message with her private key, while the validation of the signature will be conducted with her public key. We use the hashing function SHA-256 to hash our message. When the message is hashed, we then create a signature for the hashed message. The last thing that needs to be done is the verification of the hashed message from Tom’s side.

SHA - Secure Hash Algorithm Part 1


Lesson Description:

In these next few videos, we dive into the logic and functioning of hashing algorithms. We first see what hashing algorithms are and give a general description, and then proceed to talk about the SHA algorithms. SHA is a collection of cryptographic algorithms created by the National Institute of Standards and Technology (NIST). It stands for Secure Hash Algorithm. The purpose of all SHA algorithms is to provide security by altering data with a cryptographic hash function. The resulting data is of a fixed size and cannot be easily reversed by some other party. These kinds of functions are called one-way functions. An n-bit hash is the map of a message of some length to an n-bit hash value. An n-bit cryptographic hash is a one-way n-bit hash that is collision-resistant. Collision-resistant means that it is difficult to have two different input messages that will produce an identical hash. SHA algorithms are used for signing digital certificates. In this introductory video, we show the different kinds of SHA algorithms that exist such as SHA0, SHA1, SHA2 and SHA3.

SHA - Secure Hash Algorithm Part 2


Lesson Description:

Throughout this video we talk about the kind of actions performed in the preprocessing phase of SHA-256. These are the actions that need to be done to prepare the message so it can be hashed. When the data reaches a certain format, that's when it can be hashed. Everything is done according to the SHA-256 standard. If anything is changed, we can no longer say we are talking about the SHA-256 algorithm. So, the first step in the preprocessing phase is message padding. We also talk a bit about the message input size of SHA-256 and see how large of a message we can input into this algorithm to get a hash.

SHA - Secure Hash Algorithm Part 3


Lesson Description:

Here we move on with our preprocessing phase of SHA-256 and take a look at the code implementation of it. The first thing we need to do is provide the message to be hashed. We take that input and store it into a variable inputM first. We create a variable Msg that starts empty. Then, we start filling the Msg variable until it contains everything it needs to be hashed. First we fill Msg with the inputM message, but converted into a binary message. We perform this conversion with the help of a for loop and .format Python function. Then, we add +1 to the end of the Msg. After that, we need to pad the message with a k number of zeros. Watch the video to thoroughly understand these steps.

SHA - Secure Hash Algorithm Part 4


Lesson Description:

In this concluding SHA-256 video, we finish with our message hashing. First we add 64 bits reserved for the length of our message (in binary) to the end of our message. In our case, that will be a 64-bit representation of the number 96 (our message is 12 characters x 8 bits = 96). Then we split our new string into a list of 64 strings of 8 bits called MsgList. If everything is okay, there will be no errors when we run the program, and all elements will be evenly parsed in the list. So, there should be 64 elements in the list per 8 bits. With that, we are finished with the formatting of the string. Now we need to set the initial values for all the variables that the upcoming functions will be using. First, we need to parse the message into 512-bit blocks and represent each block as 16 words of 32-bits in hex.

SHA - Secure Hash Algorithm Part 5


Lesson Description:

In the previous video, the last thing we did was parse our message into 512-bit blocks. In our case, we have only one 512-bit block. The block is divided into 16 words where each word has 32-bits. Now we have gotten to the part where we actually start our SHA-256 hash computation. We introduce several functions that this algorithm uses to produce the final hash. We provide a detailed explanation and the implementation of these functions. First, we initialize an array of predefined hash values that are 32-bit binary strings, and an array of predefined constants, K. After that, we move on to defining the NOT function.

SHA - Secure Hash Algorithm Part 6


Lesson Description:

Moving on with our SHA-256 functions, we start this video by defining the XOR function. The reason we use our custom functions is so that the padding can be nicely represented and the output of our functions is shown in 32 bits. After XOR, we demonstrate the AND, OR, Choice, and Majority functions. The Choice function returns the XOR of two AND functions, more precisely written as: XOR(AND(x,y), AND(NOT(x),z)). The Majority function returns the XOR of an AND and XOR of two AND functions, more precisely written as: XOR(AND(x,y), XOR(AND(x,z), AND(y,z))).

SHA - Secure Hash Algorithm Part 7


Lesson Description:

Continuing on with our functions, this time we talk about the left shift and right shift functions and see how they are best implemented. These functions take the binary number that needs to be shifted as their input, as well as the number of places it needs to be shifted by. If we want to left shift by two, that means we will add two zeroes to the end of the number, as well as delete the first two digits of the binary number. When we have implemented our left and right shifts, we can then use them to implement the rotate right function that uses both of them.

SHA - Secure Hash Algorithm Part 8


Lesson Description:

More functions await us. This time we talk about and implement the Sum0 and Sum1 functions, as well as the sigma0 and sigma1 functions. All of these functions utilize the previous rotate and shift functions implemented last time. Let us take the Sum0 function and analyze it. It performs a rotation of the input by seven bits. Then it rotates it by 18 bits, then it right shifts it by three. Then, it returns the XOR of the first two numbers with the third one. Sound confusing? It will all be clear in the video. The point is that we can see that the result we get after these functions will be much different than the original input, which is the goal of these functions. The other functions work in a very similar way to Sum0. We also talk about mod32Add (mod 32 addition) in detail and see what it does. With that we conclude our functions. Towards the end of the video, we will move on to the next step of our SHA-256 hashing process where we will initialize our working variables to the initial hash values that we set before.

SHA - Secure Hash Algorithm Part 9


Lesson Description:

So, like we mentioned before, every 512-bit block (in our case one 512-bit block) needs to be represented as 16 32-bit words in hex. We take the elements from our MsgList that contain 64 elements per 8 bits, merge each 4 elements together (to get 32 bits), and then place these 32-bit long strings as elements into a new array M. These 32-bit strings are words, so the M array will contain words as elements. It will have precisely 16 elements of 32 bits. We also initialize another array W that will be filled in a very specific way shown in the video.

SHA - Secure Hash Algorithm Part 10


Lesson Description:

In this video, we finish obtaining all the elements for our W array.

SHA - Secure Hash Algorithm Part 11


Lesson Description:

So now our W array is populated with all 64 elements in it. We can conclude from the formula of W that the first 16 elements determine the rest of the list. Now that we've defined all functions and attained all the elements we need for calculating T1 and T2, we can proceed to calculating them and performing rounds. T1 will be calculated according to the formula T1 = h+Sum1(e) + Ch(e,f,g) + K[t] + W[t] and T2 will by calculated as T2 = Sum0(a) + Maj(a,b,c). When the loop is done, we can say that SHA-256 has been calculated and we have the elements that compose the SHA-256. All we need to do now is get our final hash by concatenating H[0] to H[7] elements into one 256-bit value and converting the resulting hash from binary to hex.


General Talk


Lesson Description:

In this introductory lecture we will start discussing the real-world uses of blockchain technology, and go over the elements of trade. Our goal is to be able to facilitate some sort of exchange of some goods or services. In order for us to do that, we need to make sure that we have some sort of currency with which to pay for these goods or services. We need some storage for that currency, some system of exchange, a contract, and the goods themselves. In the next video you will be immersed in an Ethereum case study where we will analyze this cryptocurrency in detail.

Case Study of Ethereum Part 1


Lesson Description:

In the following videos, we will be exploring the Ethereum Blockchain in more depth. Ethereum is a decentralized public blockchain that can be used not only for monetary transactions (making payments, receiving payments, sending or receiving assets), but also for creating smart contracts. Smart contracts are protocols that facilitate many different kinds of functionality. They are like standard contracts, but they have the ability to automatically react to the state of the contract. We will analyze every step of the process of creating blocks, and will break down the block and transactions into smaller parts so we can get a good look and understand what is going on under the hood. This video will give an overview of some of the things we will do. We will talk about what the components of an Ethereum block are and how the block is formed. We will learn what Rinkeby and Ropsten Ethereum test networks are, and how we run a blockchain node.

Case Study of Ethereum Part 2


Lesson Description:

In this video, we will set up our computer to be a node in the Ethereum network so that we will be able to participate in the network and communicate with other nodes. We will install Ethereum, allocate a sufficient amount of RAM (the more RAM you allocate the better), as well as talk about the three syncmodes you can select. The higher the syncmode, the more computational resources you will need. We will perform our first interaction with the network.

Case Study of Ethereum Part 3


Lesson Description:

The first thing that we will do is take a look at Ethereum’s JavaScript API, as well as Ethereum's Github repository where there are a lot of useful things. We will check if syncing is working and take a look at some information, like what Ethereum’s current block is, what the highest block is, etc. We will also check to see if we are actively listening, and we will also get some peer information. The peer information we see about other peers, they see about us as well. In addition, we will check out our own node information. It is important to use the latest version of Geth, so we will perform that check as well. We will try out the getBlock function, and see what other kinds of functions we can use on the blockchain.

Case Study of Ethereum Part 4


Lesson Description:

So far we have installed Ethereum and have seen a little bit of what we can do with it, such as getting block information, submitting a transaction, and similar actions. Now we will learn about the individual elements that make up a block. We want to know what they each represent and from where they are derived. Ethereum has a number of elements. In this video, we will discuss the difficulty parameter and see the formula by which it is generated.

Case Study of Ethereum Part 5


Lesson Description:

Moving on with Ethereum, we will continue with our difficulty calculations. Remember that depending on how old a block is, functions may or may not work on it. Some older functions will only work on old blocks, while some newer functions will only work for new blocks. The difficulty of a block cannot go lower than the minimum difficulty, which is the difficulty of the genesis block. And the difficulty increases or decreases based on which factors contribute to it, what functions are used, and what calculations are performed. We will also talk about some other elements of the block such as parentHash, which is hashed by the Keccak hash, timestamp, gasLimit and nonce.

Case Study of Ethereum Part 6


Lesson Description:

In this video, we will see that we can use the interface, and that the API exists and is compatible with other programming languages. We will install Python PIP and the Ethereum RLP library for serializing data within the header of the block, in order to be able to hash it and create a block hash. We will also install pysha3 and web3. We will see how we can get an individual element of a block, and experiment a bit with different functions.

Case Study of Ethereum Part 7


Lesson Description:

In this video, we will recalculate the total difficulty of the chain we saw in the last video, so that we know where that number comes from and what the origin of that value is. The total difficulty is calculated by adding all the difficulties from the genesis block up to the present. We will take a look at a few ways we can calculate the total difficulty. We will also talk about the stateRoot parameter and how it is determined. Finally, we'll look at the logsBloom parameter, the receiptsRoot and the transactionsRoot.

Case Study of Ethereum Part 8


Lesson Description:

In this video we'll cover transaction receipts, gas and gas limits, and other variables that are associated with gas. These are things like Wei, and the ration tables that show how much something is worth. Wei is the smallest denomination of Ether and is the most used of all denominations. We will also look at the root parameter, which is basically just an intermediate root where we store a value that is computed (the current root hash of the state). We will talk about why we even have gas and gas limits, and make a comparison to how Bitcoin works in this regard.

Case Study of Ethereum Part 9


Lesson Description:

This time, we will talk about uncle blocks and orphan blocks. We will go over what they are and how they work. We'll compare Bitcoin orphan blocks and Ethereum uncle blocks. They are basically the same thing, but treated differently. We have already talked about genesis blocks before, but we will also say a thing or two about them, and so-called stale blocks.

Case Study of Ethereum Part 10


Lesson Description:

How can you have a confirmation of a transaction? After which conditions are met can you be sure that your transaction is valid and that it will remain valid? Why is it necessary for you to wait for additional blocks to be added to the block where your transaction is? These are some of the questions we will answer in this video. In general, it is good enough to wait for 12 blocks, and there should not be any problems. If you want to be on the safe side, you can give it an hour to be a hundred percent sure. We will make sure, manually, by checking for gas, timeout, and block height.

Case Study of Ethereum part 11


Lesson Description:

This video picks up from the previous one, and we'll start here by checking for gas. Afterward, given that all other checks have also been performed, we will perform our main check. This is to make sure that the block our transaction belongs to has remained part of the blockchain twelve blocks later. Finally, when all checks pass, we need to return state 0, meaning that the transaction has been confirmed.

Case Study of Ethereum Part 12


Lesson Description:

Here we will talk about the log files, such as the logBloom. LogBloom is essentially a 256-byte field, and in essence a bloom filter. A bloom filter is a probabilistic data structure. We will discuss what gets logged in Ethereum and talk about how blockchain logs differ from standard log files you would find on a Linux machine. We will examine some transaction logs and talk about canonical signatures.

Case Study of Ethereum Part 13


Lesson Description:

Here we will talk about ERC-20, a standard interface for tokens. The ERC-20 token standard enables the implementation of a standard API for tokens within smart contracts. It gives functionality for transfer tokens and enables tokens to be approved, so that they can be spent by another party on the blockchain. It has six functions, and two events: Transfer and Approval. By using the standard we will be able to understand and figure out how our hash represents the transfer of an event. We will be using the ERC-20 transfer function to do this.

Case Study of Ethereum Part 14


Lesson Description:

We talked a lot about what are the elements of the Ethereum block are. Here we will talk about the hash of the block and how it comes into being. We often say that we create the hash of a header and that is how we obtain the hash of the block. So here we will see how that is done. Basically, we have to take all elements that belong to a block header, serialize, encode, hash it, and then compare the hashes to whatever our result is.

Case Study of Ethereum Part 15


Lesson Description:

In this video, we will talk about mining and block validation. We will talk about DAG (Directed Acyclic Graph), which is used in Ethereum for generating and verifying the data in a block. A DAG is basically a data set from which data is taken. Every 30000 blocks a new DAG is created in Ethereum. We will also discuss the hashimoto function. It performs any calculations you require in order to validate or mine a block, and we'll use it in an example.

Block Mining and Validation Part 1


Lesson Description:

In these next several videos we will be writing a lighter version of the PoW algorithm and implementing the verification of PoW. Doing the full implementation would take a lot of time, computation power and storage and is not necessary for grasping and understanding the essence of what is being shown. From these videos you will learn how the Proof of Work functions from a programming point of view and you will see how the verification of the PoW for a block works. You have seen how we can validate data in a block with a hash of the block after it has been mined, but in these next videos you will see how to actually verify that the block has been mined properly so that it becomes part of the chain. We will start off by taking a look at the Ethereum yellow paper to see using which formulas does Ethereum calculates its PoW. As well as what kind of functions, parameters and definitions it uses so that we can implement them ourselves. For starters, we will need to sync with the Ethereum blockchain, import some types and libraries and define some things before we start implementing our own functions. It is important to prepare the data correctly in order to avoid mistakes being made.

Block Mining and Validation Part 2


Lesson Description:

In this video we will start implementing the get_cache function. With this function we will get a certain portion of the cache, we will simulate the request of the cache in regard to the block number. We will not have the whole data set, just the cache, that is a downsized dataset from which we will take some data in order to find a nonce for the hash of the block or to validate the block. For mining, you would require the full dataset (the DAG). We will also write the check_pow function. In general, there are many checks that need to be done in order to make sure everything is operating properly. For example, you need to check if something is the right size, if something is initialized, if something is the right type and so on. In the check_pow function we will use the get_cache and the hashimoto_light functions.

Block Mining and Validation Part 3


Lesson Description:

Here we will continue with writing our check_pow function. We have to make comparisons between the mixed hashes to make sure our result falls into a specific range. If both conditions are satisfied then we can say this block has been mined and everything is ok. Other checks can be made as well but will only do the basic ones. We will add the proper formatting to our variables which is essential. If it is not formatted properly and even 1 bit is missed, then everything will be incorrect.

Block Mining and Validation Part 4


Lesson Description:

In this video we will run the script that we created in the previous videos. We will need to do a few alterations to our code to make sure everything works properly and see if the blocks we select are valid or not and why. We will need to change our mix digest, the condition and the result to hexadecimal so we can make an actual comparison. Remember that the mix_hash is fetched from the block while the mix_digest is calculated by the hashimoto_light function, and they need to be the same. The result must be less than or equal to the condition.

Block Mining and Validation Part 5


Lesson Description:

In this video we will do some mining and define a simplified mine_block() function. Same as with the previous functions, we will be using the cache instead of the full data set and the hashimoto_light function. Once everything is written, all that is left to do is test out our code.

Transactions ECDSA Part 1


Lesson Description:

So far we have taken a look at the structure of blocks, but we have not really looked at the structure of transactions independently. This time, we will see what an Ethereum transaction is really composed out of. Transactions are made up of several parts. In this introductory video, we will make an overview of some of these composite parts and give you an idea of what we will be talking about in further videos. Some of the components that make up an Ethereum transaction are the block hash, the block number, the gas price, the transaction index, the nonce of the transaction, v field, etc.

Transactions ECDSA Part 2


Lesson Description:

What we want is to see in detail how a transaction is made in a blockchain. The goal is to be able to sign a transaction and verify a transaction in the Ethereum blockchain. More specifically, the testnet of Ethereum called Rinkeby, that is slightly different than the Ethereum blockchain in terms of variable sizes and consensus mechanism it uses (Proof of Authority). Upon conducting a transaction, we will see how we can find the transaction and individual elements of it, and see how we can use these individual elements to sign or verify a transaction signature. One way of finding the actual transaction is searching each block and transaction manually and comparing the variables, or even better, using a loop or a function to automate this process for us. In the video, we will go over the syntax of such function.

Transactions ECDSA Part 3


Lesson Description:

Now that we have seen in the previous video how we can find a transaction, we now need to learn how a transaction can be signed and verified. In general, any message that is sent, must be signed so that the message integrity can be established so we know who sent it. In our case, our message is our transaction. The first step is getting the keccak hash. Next, we will need to provide a specific set of values for our signature algorithm. We will be using the recommended elliptic curve domain parameters for secp256k1. One of these parameters is our Pcurve, that is a very large prime number and we will define it first. We also have N, that is also a very large number and represents a condition for our private key. Our private key must be a number smaller than N and greater than 1. We will also define our a, b and G points. After that, we will import a few other things that we will need, among them, the greatest common divisor and modular inverse functions that we already created in previous videos.

Transactions ECDSA Part 4


Lesson Description:

Now that we have imported everything we need and created several necessary parameters, let us get to the actual calculations. First, we need to have some message that is going to be signed. This can be any message you want. Then, we need to hash our message using the keccak hash. After that, we need to create our generator point that will be used for creating the verification key. The verification key is calculated by multiplying the generator point with the signing key. The verification key will have two values, X and Y that are located on the secpk256k1 curve. For our signing key, we can choose any value we want, just as long as we respect the condition that it is a value larger than 1 and smaller than N.

Transactions ECDSA Part 5


Lesson Description:

Continuing on where we left off in the previous video, here we will generate a new random point on the secpk256k1 curve called XY1, that we will obtain by multiplying a random number with our GenPoint. After that we will calculate the r and s variables that together represent our signature. Once we have created our signature, we need to go through the verification process. In order to verify our transaction, we will need to calculate parameters w, u1 and u2. When we obtain these parameters we can use them to calculate point XY2.

Transactions ECDSA Part 6


Lesson Description:

Now that we have performed all necessary calculations, we need to test and see if all needed conditions are met. If they are, then we can say that we have conducted a successful signing and verification. We also want to see how we can get an address out of the public key. The address is obtained by first hashing the public key with the keccak hash function. Then, from the resulting 64-bit hash, we take the last 40 bits. These last 40 bits represents our address.

Final Steps

Course Summary


Lesson Description:

In this video, we will give a summary of the course and round up what we have learned throughout all these videos. The goal of this course was for you to gain a deep understanding of blockchain concepts, and the underlying mathematics that make it all possible. At the beginning we covered what blockchain is and what it is used for, and tried to grasp as many blockchain terms as possible. Then, we slowly moved to understanding how it works and what blockchain architecture looks like. After that we aimed for an understanding of all the consensus mechanisms that blockchains can implement, and the importance of digital signatures. Lastly, we dug deep into the mathematics of it all, learning about cryptography and how various hashing functions utilize cryptographical concepts to securely encrypt data.

Job Market


Lesson Description:

Here we will talk a bit about the job market related to blockchain, so that you can get a better idea of what kind of opportunities await you in this area of expertise, and the range of blockchain developer salaries you can expect.

What's Next?


Lesson Description:

Now that you have a solid foundation, the key is to keep on going and continue to invest in yourself. Depending on the path that you wish to take, there are many options available to you. Python is a good start if you have not already learned to use it at an advanced level. The Python course we have here on Linux Academy by Keith will complement the knowledge you have gained here very well. Be sure to invest some time into thinking thoroughly about the next steps you want to take, and try to choose an option that will be the best for you.

Take this course and learn a new skill today.

Transform your learning with our all access plan.

Start 7-Day Free Trial