Every transaction in a blockchain is signed by the sender. The signing of transactions is done using cryptographic signing algorithms, as described in episode 6 of the podcast.
In some scenarios, to perform an operation on the blockchain, there is a need to have more than one signatures on a transaction. Think of bank accounts with joint holders. Similarly, blockchain wallets could also be owned jointly by a group of accounts. These wallets are called multi-signature wallets or multi-sigs.
Multi-signature wallets are generally implemented using smart contracts. One of the smart-contract function acts as a gatekeeper for other functions and keeps track of the number of accounts needed to call a function. Once enough accounts have called this gatekeeper function, it then forwards the call to the intended function. This is how, in simple terms, multi-sigs work.
Because they are implemented using custom logic on the blockchain, multi-signature wallets can have any combination of signatures configured to use. We can have a threshold, majority, super-majority, specific accounts, and many other kinds of signature configurations in multi-signature wallets as per the need of our application.
Multi-sigs are useful in scenarios where a joint decision is needed to make a transfer or execute a function on a blockchain. For example, the transfer of funds from an organizational account where all or some of the board members must sign the transaction individually.
Generally, to start a technology business, there’s some initial funding required to build the product. Generally, this is done using conventional ways like VC funding or bank loans. The VCs give money and they take some ownership in the company.
There is another way of funding, called crowdfunding. Instead of asking a few VCs and/or banks to give you money, you ask a large number of people to fund your startup and in return, you either give them stake or a right to use your application.
One way of doing crowdfunding is by doing an Initial Coin Offering, better called ICO. In blockchain applications, the developers create tokens so that their users can spend them to use the application. Selling these tokens is a way for the developers to get paid for their work.
In an ICO, these tokens are offered in advance, as a future right to use the application when it is ready to use. To do an ICO, the founder of a blockchain startup generally writes a white paper to detail their idea and its implementation. If the users find the application useful, based on this whitepaper, they purchase tokens to use this application in the future. This purchase of tokens helps the founders to get initial funding to build the application.
If the application becomes successful then the tokens have a lot of demand. The users who acquired these tokens in the ICO can then make profits by selling them at higher prices because of the demand.
Eksik bölüm mü var?
Tokens are digital assets representing a user’s right to use a system/service/application or to participate in a process based on blockchain.
Tokens are similar to cryptocurrencies in terms of issuance and distribution, but they are different in terms of value. A cryptocurrency can be used as a medium of exchange, while a token has value only utility or security value.
Tokens are mainly of two types — utility tokens and security tokens.
Utility tokens are used to represent a user’s right to use a decentralized application. In general, to make sure that the DApp developers are paid for their work, utility tokens are used as a paywall for using DApps. The users have to purchase tokens for an app in order to use it. The value of utility tokens is based on the actual utility and popularity of the underlying DApp.
Security tokens don’t have a utility associated with them, but they are seen more as an investment into a project to make profits. When the market value (users, usage, popularity) of a project or a company increases, the value of securities also increases and the investors can make a profit.
Tokens are created and issued using smart contracts. In token smart contracts, there are specific functions that mint and issue tokens to users. Users can buy the tokens by calling these functions, and by making payments in native cryptocurrency of the blockchain on which the smart contracts are deployed.
Proof of Stake is a blockchain consensus algorithm where the nodes put an economic value on stake to participate in block production. The problem domain is the same — to find out who should produce the next block for the blockchain.
In PoS networks, the block producing nodes are called validator nodes. The reason being — the consensus on blocks is reached via validation and voting and not through winning a race (as in the proof of work networks).
In PoS, the solution is two-fold. First of all, a pool of validators is created. Any node that wishes to become a validator, puts some economic stake in the network. This stake is in the native cryptocurrency of the network and generally has a minimum value threshold. All or a selected subset of nodes who put their stake in the network become part of this pool of validators.
To produce the next block in the chain, one of these validators in the pool is chosen using a round-robin or a pseudo-random algorithm. This selected node then proposes a new block. The other validators validate and vote on this block. If the majority of validators vote in favor of this block, then this block is accepted by the chain. In case the proposed block is bad or it doesn’t follow the rules of the chain, then the block producing validator is punished by the network and their stake is taken away (slashed).
Proof of stake has an advantage over proof of work that it does not waste all that energy in mining.
Blockchains are updated by adding new blocks at the end of the chain. In a permissionless and decentralized network, it is hard to find out who (which node) gets to add the next block. This is like selecting something from a collection of things.
One way of selecting one thing from a group of things is to get them to race against each other. Whoever wins gets selected. This is also how proof of work is used for selecting a miner node from the network of multiple nodes to produce the next block.
Proof of work is basically about producing some data that can be verified easily, but it is hard to produce. In the Bitcoin blockchain, this data is a hash with a predefined number of zeroes as its prefix. As hashing is a completely random process, the only way to produce such a prefixed hash is by trial and error.
All the miner nodes race against each other to find our such a prefixed hash by repeatedly hashing the block data (with different nonce each time). Whoever wins the race and produces a block hash that satisfies the conditions, gets to add the next block and take the rewards.
Because all the nodes constantly hash so much data, they use a lot of computing power too. All this compute power needs a lot of electricity as well. This is why the Bitcoin blockchain consumes so much energy.
In the case of fiat currency, when you spend it, you physically hand over the currency note to the other party. Also, in case of a bank transfer of fiat currency, the update of balances in sender and receiver accounts is done by a centralized server having full control of the transaction and the accounts. In both scenarios, in fiat currency, it is made sure that what is spent is actually spent.
But in the case of a decentralized system with digital currency, there could be scenarios that the already spent currency could be spent again. This is called the problem of double spends.
Before we go further into double spends, it would be good to get a refresher on transactions, blocks, finality, and consensus.
Let’s take an example — if you have a balance of 10 coins on a blockchain. Now you send these 10 coins to a user in a transaction. Then you send the same 10 coins to another user in another transaction. You send both these transactions to two different nodes in the blockchain network. What you have tried to do here is a double spend because you tried to spend the same coins twice.
In a normal situation, one of these transactions will be marked invalid as soon as another one is already included in a block. However, in a rare situation, a network delay could cause a temporary fork on the chain and both of these transactions could be included in different blocks at the same height. In such a scenario, the blockchain could take some time to recover from the fork. Once the canon chain is decided using the consensus and finality rules, one of the blocks would be considered final while the other one invalid. In the interim, both transactions would be considered valid by different nodes and that could cause confusion between the receivers.
When transacting on a blockchain, you must wait for the block, having your transaction, to be finalized before you buy/sell any goods/services based on that transaction.
In a blockchain, the transaction fee is the fee paid to blockchain nodes to include the transaction in a block. Generally, the transaction fee is paid in the native cryptocurrency of the blockchain. For example, in the Bitcoin blockchain, the fee is paid in satoshis which is a smaller denomination of bitcoin.
Nodes — software and hardware. Each transaction execution and verification is consuming CPU and memory on the node. The cost to keep the node running with the optimal hardware needs to be recovered from somewhere. Hence transaction fee.
To get their transactions included in a block, the user “offers” an amount of transaction fee that he can pay for that transaction. The node then decides whether they accept that fee and include the transaction or not. This approach keeps the market open and the transaction fee is decided on the average fee being offered by the users. Some users offer high fees to get their transactions included quickly, others offer a nominal fee (close to the market average) and wait for a node to accept and pick up that transaction.
In blockchains where the size and complexity are not the same for all transactions, the transaction fee depends on the byte size of the transaction and it’s execution complexity. For example, in the Ethereum blockchain, the transactions can also be smart contract calls. Smart contract functions could be of different sizes and complexity. Hence, when a smart contract function is called, the transaction fee depends on the execution complexity of that function. In such cases, the user offers an upper limit for the transaction fee. When executing the transaction, whatever fee is used is taken by the node and the remaining is returned to the user. All of this is done using the algorithms implemented as part of the protocol.
The blockchain grows when new blocks are added. The creation of new blocks requires validation of transactions and including them in blocks by the blockchain nodes. Block rewards are a way to incentivize the nodes for creating new blocks and contributing to the decentralization and security of the blockchain.
Another reason for block rewards is the need to have the cryptocurrency in circulation. For any financial system to work, there must be enough currency in circulation so that the goods and services could be easily priced and bought/sold. The balance of supply and demand for currency is essential.
Block rewards are a mechanism to pump newly minted currency in the system. For example, in Bitcoin, for every newly added block, some new bitcoins are minted and given to the miner of that block. This way, while the nodes are incentivized for adding blocks, new currency also comes in circulation.
The block rewards are not constant forever. Their value depends on the amount of currency currently in circulation, and the amount that needs to be in circulation (demand). Based on the supply and demand of the currency, the block rewards can change. Over a period of time, the block rewards are reduced and tend to go towards zero.
When the block rewards reach zero, the transaction fee becomes on the only incentive for the nodes. Hence the value of the transaction fees is also impacted by the value of block rewards. Transaction fees will be detailed in the next episode.
Bitcoin was created as an alternate financial system after the subprime crisis of 2008. Banks, having too much control over people’s money, failed as a result of the crisis, and a lot of people lost their money. Bitcoin was created as a financial system where no single party had full control.
When a new financial system is created, there are a few things to make sure of:
* Having a medium of exchange i.e. currency.
* Having enough circulation of the currency to balance its supply and demand.
* A mechanism for people to own the currency.
And when the system is decentralized (like Bitcoin), then there is a need to also incentivize the people participating in the decentralization process i.e. hosting the nodes and helping verify the ledger(s).
Bitcoin answered all these questions:
* Block rewards were created to mint new coins and put them in circulation.
* The transaction fee (along with block rewards) was introduced to incentivize the node hosts.
* The total supply was capped so that the supply-demand was balanced.
* The halving of block rewards happens to manage the circulation of new coins.
All these concepts together comprise the overarching topic of blockchain economics.
Would you call every four-wheeled vehicle a car?
Some of them are trucks, some are buses, some are farm tractors. Only a subset of them is cars.
Trucks have a use-case for transporting goods. Buses are for transporting a relatively large group of people. Cars are for family transport.
While having different use-cases, all of them share the core concept of a four-wheeled motorized vehicle.
Now let’s talk about Bitcoin and Blockchain.
Just like a car is just an application of a four-wheeled vehicle, Bitcoin is an application of blockchain.
Bitcoin was invented to create an alternate financial system on which no single party could have control. Some of the pre-existing technical concepts like cryptographic hashing and signing, peer-to-peer networking, consensus in distributed networks, and a few others were brought together to create Bitcoin blockchain.
The exact same concepts could be used to create another blockchain network for another use-case. For example, later Ethereum was created as a smart-contracts platform and not just a cryptocurrency. And many other blockchains have been implemented in the previous decade.
Hence, to conclude, Bitcoin is just an application of more generalized blockchain technology.
When a centralized system stores all the data, it is pretty straight forward to find out the “final” state of data at a particular point in time. Whatever the centralized system has committed to the storage is deemed final. However, when it comes to decentralized systems, it is not that straight forward to determine the final state of data.
In a blockchain, transactions are proposed by calling functions on one of the nodes. They are then broadcasted among other nodes and included in a forthcoming block when one of these nodes chooses to do so. Once included in a block, the transactions, along with the whole block, are verified and committed to the state of the blockchain by all the nodes.
This entire process from the proposal of a block to getting it committed to the blockchain takes some time. Also, blockchain nodes are generally not located at the same place, there communicate with each other via the internet. This also causes network delays in the sharing and replication of data among all the nodes in the network.
Because of these two reasons —time taken by the block production process and network delays — not all the nodes have exactly the same state all the time. For example, when the block with number 5 is proposed by one of the nodes, some other nodes might be having blocks 2 or 3or 4 as their final state. Block 5 might reach all the nodes after some time (a few seconds or even minutes if they have slower bandwidth). There could also be scenarios of temporary forks when a subset of nodes starts building the chain on a different block and when these sub-chains merge some of the intermediate blocks become irrelevant/invalid.
This is why the concept of block finality becomes important. The finality of a block means that the majority of the nodes in a blockchain network have verified and accepted that block and their state has been updated accordingly. Finality assures that the transactions included in a block will not become invalid because of any reason.
Finality could be of following three types:
* Probabilistic Finality: When a convention is followed about finality. For example, in the Bitcoin blockchain, a block is considered final when 6 more blocks have been added to the chain on top of it.
* Deterministic Finality: When an algorithm is used to determine the finality of blocks. This is a novel approach that some blockchains use to get faster and more reliable finality.
* Instant Finality: There are some consensus algorithms that work in such a way that any block produced is considered final. Finality is achieved as soon as the block is produced.
Blockchains are decentralized systems. It means there is no single point of control or failure. This also means multiple parties store the data and continuously trying to reach an agreement (consensus) on the state of the blockchain.
For multiple parties to reach consensus, they must follow some rules. Rules regarding how to decide who would produce blocks and when, the interval between blocks, how big or small the blocks could be, and so on. These rules are together part of the consensus algorithm of the chain.
These rules are updated from time to time to introduce functional optimizations to the blockchains. At this time, when an update is supposed to happen, it is up to the parties to begin following the new rules by updating their nodes (software) or not.
When some of the nodes decide not to update to the new rules, then a fork happens on the chain. Forks are of two types — soft and hard.
A Soft Fork happens when the new rules are compatible with old ones. Even if some of the nodes chose not to update, they could still be part of the chain and participate in the consensus process as per the old rules.
A Hard Fork happens when the new rules are not compatible with the old ones. When some nodes don’t update in this case, they don’t participate in the consensus process on the updated chain. In such cases, depending on how the communities decide (old rules vs. new rules), there could be two different blockchains each following old and new rules separately.
Blockchains are decentralized systems. There is no single point of control or administration. In contrast to other IT systems, there is no admin in a blockchain. Instead, blockchains are governed.
To make any update to the rules of a blockchain, every participant must agree directly or indirectly. Blockchain governance comprises the processes to coordinate this agreement.
In general, there are three main stakeholders of a blockchain:
* Developers who implement the blockchain protocol rules.
* Node hosts who run the blockchain nodes to provide decentralization to the network.
* End users who use the blockchain to process their transactions.
Also, there are a few things that need agreement on how the blockchain would work:
* The consensus mechanism and associated rules.
* The economic incentives for node hosts.
* The transaction fee for users.
All these things must be agreed upon by all three stakeholders in one way or the other, and then coded in the blockchain node software as the core rules.
When there is a need to update any of these rules, blockchain governance processes are used to get the opinion of stakeholders and enact the new rules accordingly.
In different blockchains, different governance processes could be followed. For example, the initial proposals for a change are generally written as an RFC on which the community comments and votes. Once there’s enough discussion and refinement on a proposal, it is then coded in the node software. The node hosts then update to this new version of the node software, and the blockchain as a whole is updated. In some cases, some of the node hosts decide not to update the node software because of their disagreement on the new rules, and in such scenarios, a fork happens on the chain.
Blockchains, depending on who can read the state and who can participate in block production (updating the state), could be classified in mainly two ways:
* Private or Public state
* Permissionless or Permissioned block production
In a permissionless blockchain, anyone can participate in the block production process, while in a permissioned blockchain, only selected nodes can produce blocks.
In a public blockchain, anyone can read the state (data), while in a private blockchain, only the intended users or nodes can read the data.
For example, the Bitcoin blockchain is a public permissionless blockchain. Anyone can read the balance of any account and any node can mine blocks. There is absolutely no restriction.
On the other hand, there are blockchains where only interested parties host nodes in a closed network and are allowed to read the state of the chain. These blockchains are private permissioned blockchains. They are popular among large enterprise use-cases. For example, a supply chain blockchain in which multiple parties like manufacturer, warehouse, retailer, etc. exchange information with each other on the state and value of goods.
There are also scenarios where public permissioned blockchains are deployed. These are popular in governments and NGOs, where the block production is done by selected nodes belonging to government agencies or departments, while the blockchain data could be read by all the citizens and third-party applications.
In some cases, there are hybrid blockchain setups where one network is public while the other is private and they interact with each other to process transactions based on their state and user inputs.
Public and permissionless blockchains provide the maximum amount of security and decentralization as they have a relatively larger number of nodes and it is almost impossible to hack or control a sufficiently decentralized network.
Blockchains, just by themselves, are a collection of nodes sharing data and agreeing on its state. To make blockchains useful for the end-users, applications are built on top of them. Simply put, applications which use a decentralized backend (like a blockchain), are called Decentralized Applications or DApps.
Any user-facing software application mainly has two primary components — Frontend and Backend. The frontend is what the user interacts with while the backend provides the data and processing logic. Similarly, DApps also have these two components, but their backend is a blockchain network instead of a server (or set of servers).
DApps usually provide better ways of communicating with blockchains by adding an abstraction layer on top. One of the best practices with DApps design is that the end-user should get the same user experience as they would get with any other conventional application, while also enjoying the security and decentralization provided by blockchains.
DApps are built in such a way that the frontend could connect to any node in the blockchain network. The business logic for DApps is generally written in smart contracts. In most scenarios, to enable scalability, only the critical business logic is put on the chain in smart contracts while the rest of it stays in conventional systems and services.
Sometimes a DApp may have multiple decentralized backends for optimizations and better decentralization. For example, the business logic is written in smart contracts on a blockchain while the data is stored in decentralized storage systems like IPFS. The DApp frontend then connects to these systems to provide a unified interface to the user.
A simple example of a DApp is software wallet applications that allow the user to query and transfer balance on a blockchain while interacting with a familiar user-interface.
Blockchains are decentralized. Each node in a blockchain network validates and processes all the transactions and stores the copy of the data. Transactions are used to propose updates to the state of the blockchain.
Transactions are initiated using function calls on the blockchain node. For example, in the Bitcoin blockchain, the node software exposes a function called ‘transfer’ which the users can call to transfer bitcoin from one account to another. This function call basically becomes a transfer transaction initiated by the user. Internally, the function, when executed, validates the user’s signature, checks their balance, and does the balance updates to transfer the indicated amount. When the transaction representing this function call is included in a block, all other nodes of the blockchain execute this function individually. This process is followed for each and every transaction. In essence, transactions are function calls and these functions execute business logic.
Smart Contracts allow users to extend the business logic of blockchains. Just the transfer of bitcoin and ether might only help with a subset of financial use cases and cryptocurrencies. For blockchains to be useful in more scenarios, they should be able to execute any kind of business logic and not just transfer of cryptocurrency. This is exactly what smart contracts provide — execution of any kind of business logic on the chain.
In simple terms, a Smart Contract is a collection of functions written in code — just like any other software. They are then deployed on the blockchain by using special transactions that take compiled code of the smart contract as input. Once deployed, users could call smart contract functions just like they would initiate any other transaction on the chain.
For example, a supply-chain smart contract could have a function for recording the location and/or temperature of a shipping container. It could have logic that when the reported temperature goes below a certain value or when the location is within a geo-fence, some amount of cryptocurrency should be transferred from one account to another on the blockchain. This would then allow two parties to track a shipping container and settle payments based on its location and temperature, in the most trustless way possible. Hence making blockchains more useful than just balance transfers.
The term “Wallet” could have several meanings or interpretations in the context of blockchain.
At the very basic level, a wallet is just your key-pair that can hold a token or cryptocurrency balance on a blockchain. In the previous episode, I explained Accounts and Keys. So, a wallet is basically an account and it’s associated keys that may or may not have a balance on a blockchain.
In contrast to the physical wallet in which we keep currency notes, a digital or blockchain wallet does not hold digital currency. Instead, the wallet holds the cryptographic keys so that they could be used is a simpler way. So, another and more widely accepted definition of a blockchain wallet is a software program or a hardware device that could be used to store cryptographic keys associated with one or more blockchain accounts.
A software wallet is a program or an application that generates and stores cryptographic keys for signing blockchain transactions. In addition, some wallets also allow the signing of transactions. These software wallet applications typically have three main functions that users could use. These functions are:
Generate new account + keys using a password or a random seed.
Sign transactions using the generated keys.
Query and show the balance of an account from a blockchain network.
A hardware wallet is a hardware device that does the function of a blockchain wallet. Hardware wallets are more secure than software wallets as they have the keys safely stored on the secured memory area of a purpose-built chip. Using hardware wallets, keys are safe as they can’t be accessed directly as plain text and transactions are signed inside the device itself. Hardware wallets generally connect with a computer using USB and have associated apps that connect to a blockchain network for balances and sending transactions.
Accounts are a way of representing users on the blockchain. Just like we have accounts in banks, generally represented by account numbers or IBANs, we have accounts in blockchains too. In a blockchain, accounts are generally a representation of a user’s cryptographic public key.
Recall from the Transactions and Signing episodes of the podcast — transactions are signed by the users. Signing in a blockchain is done using public-key cryptography.
In public-key cryptography, a user has two keys — one public and the other secret. For simplicity, let’s say that these keys are mathematically obtained random strings that are associated with each other based on logic. This logic could be different for different cryptographic algorithms. Some of them are based on prime numbers and some are based on points on a function curve.
Using these keys, the user can associate their identity with their transactions by signing them. The public key is shared on the blockchain as part of the transaction. The transaction data is signed using the private key of the user and the resulting signature could be verified using the public key of the same user.
The account of a user is represented by either hashing or encoding their public-key in one way or the other. Different blockchains represent accounts differently, using various hash functions.
Accounts are used to hold balances of tokens or cryptocurrencies, on a blockchain. Users could then spend these balances by signing the transactions using the associated private key of the account. Spending a balance means sending it to some other user’s account, using transactions. This way, any kind of user — buyer, seller, etc. could have their accounts and could send tokens to each other. If you do not have an account and the associated keys, you can’t send transactions to a blockchain and hence can’t propose an update to the state of the blockchain.
Block Production is the process of proposing and appending new blocks to the blockchain so that the state of the chain could be updated. The state update happens when the transactions included in the blocks are executed on the chain by all the nodes.
When there are several nodes part of the network, it is important for them to agree on some basic ground rules about how the state of the chain would be updated and how and when the blocks would be produced. In a blockchain, the block proposal, validation, and execution are done based on the rules part of the consensus algorithm being followed by the chain.
In general, blocks are produced by nodes at fixed time intervals — slots. For each block to be produced, one of the nodes is chosen based on the block production and consensus algorithm. Also, not all the nodes in a blockchain produce blocks but only the nodes participating in the process of block production.
For example, in the Bitcoin blockchain, the nodes race to solve a puzzle and the first one solving it gets to produce the block at the next slot. This process is repeated for each block. The puzzle is about finding a “hash” with a specific prefix and this requires a lot of trial and error using a lot of calculations. Arriving at a hash with the right prefix proves that the node has done the required amount of work to solve the puzzle, and hence the algorithm is called “Proof of Work”. The process of solving the puzzle and producing a block using the Proof of Work algorithm is called mining a block. The term “mining” is relevant mainly for chains following the proof of work consensus algorithm.
In different blockchain networks, different types of consensus algorithms are followed to define rules for block production. Another way of finding out which nodes produces the next block is by simply following a round-robin approach. This is generally followed in a blockchain network with a relatively smaller number of nodes.
Signing is the process of associating your identity with information so that it could be verified that the information is coming from you.
In the physical world, we sign documents by putting our initials or signature in ink at the end of the text. When we have to fill a form or submit a document in a public office, this is generally the process for signing.
In the digital world, we sign the data cryptographically. The process of cryptographic signing involves hashing the data and then encrypting that hash with the user’s own private key. The ciphertext of the hash is the signature of the data and it is appended to the data (just like we sign the physical documents at the end).
The signature could be then verified by the receiving party by decrypting the signature using the sender’s public key. The receiver would then hash the data at their end. These two hash values — decrypted signature and hash of the data — must match for the signature to be valid.
Signing in Blockchain
In the context of blockchains, signing is used for verification of transactions and blocks. The users sending transactions must sign them before submitting them to the nodes; also the miners or validators must sign the blocks before proposing them to the chain. The authenticity of the data in a blockchain is verified using cryptographic signing.
Signing is not Encryption
There is a small misconception that all data on a blockchain is encrypted. This is not correct. All the data on a blockchain is signed and signing is not encryption. Signing is used for associating identity with the data while encryption is used for hiding the data. Both have clearly different use-cases.