Hey, hey... Programmer, this is another article for you! The second part of the article on design patterns. Get to know Adapter and Memento.
Hello, today as Innokrea we want to tell you about blockchain. If you’re interested in the world of transactions, cryptocurrencies, and electronic payments, we invite you to read on.
Nowadays, billions, if not more, of payments are made every day, involving various currencies from around the world. In traditional (cash) payments, the transfer of money and authorization took place in a simple manner – typically, two parties can be distinguished in payments: the payer, who is supposed to transfer a certain agreed-upon amount to the recipient, usually in exchange for the delivery of certain goods to the payer. The payer presented the appropriate amount of cash to the recipient. The recipient then had the task of physically verifying (counting) whether the amount presented by the payer matched the agreed amount, and then accepting the money (and usually documenting this fact). At that point, the payment could be considered successfully completed.
Fig. 1: Verification of a physical payment
But what if the recipient cannot verify whether the payer actually has the correct amount of cash or intends to transfer it? This situation arises in cashless transactions (such as those made by card or bank transfer), where the funds in a certain currency are held in the payer’s “virtual wallet” (e.g., on a bank account) and do not have a physical representation. In this case, the involvement of a third, trustworthy party is necessary – one that can confirm that the payer indeed has the funds and ensures they are transferred to the recipient. This entity is called a Trusted Third Party (TTP), and this role is usually fulfilled by banks or similar financial intermediaries.
Fig. 2: Simplified diagram of a transaction with a trusted third party
Unfortunately, this solution has significant drawbacks. First, a large amount of personal data (of both the payer and the recipient) must be shared with the intermediary to allow them to reliably verify the flow of funds. It is challenging to maintain anonymity in such cases, which may be desirable or even necessary in some situations. Another significant problem is that, in some environments, it might be impossible to find a trustworthy entity at all – after all, the transaction parties must also be able to verify the integrity, honesty, and reliability of the intermediary (or intermediaries) to trust them with the regulation of funds flow. This issue is particularly evident in transactions on markets not controlled by any government or when using virtual currencies that do not have a physical presence in circulation (so-called cryptocurrencies).
But what if… all transactions were public, and everyone could check their history? What if each payment was treated as a block in a chain of payments, including information about all previously completed transactions and their order, and once a transaction was confirmed, it could never be modified? By using such a single, shared transaction chain available to everyone, anyone could verify whether the payer actually has the required funds – simply by checking their payment history and seeing if the appropriate amount is still in the account. This technology is called blockchain.
Fig. 3: Using a shared transaction chain in a trust-limited environment
In blockchain with the so-called proof of work mechanism, each transaction is grouped into blocks that must be confirmed before being added to the chain. To confirm a block, many users (called miners) try to find the right hash parameters for the new transaction so that it meets specific conditions (usually, the hash value must be less than a predetermined number). This is a challenging and time-consuming operation – but if a user manages to find the correct value first, they receive a reward. The user who first finds the correct hash broadcasts it to everyone else, who can then verify the correctness of the solution – it’s worth noting that while finding the value that, when added to the hashing process, would yield the correct result is difficult, verifying whether the transaction’s hash with the given parameters meets the conditions is very simple. For the transaction to be confirmed and added to the chain, the majority of users must agree on the hash’s correctness – achieving consensus. Each block in the chain also contains a reference to the previous block (in the form of its hash) – so attempting to alter any transaction would require changing all subsequent blocks, meaning performing the laborious calculations for each subsequent transaction, which is practically impossible.
Since the blockchain mechanism is decentralized, there can be delays in synchronization – for example, when two transactions A and B are attempted almost simultaneously, and some users first learn about A (and start working on finding the right hash), while others first focus on B. Part of the network confirms transaction A, while another part confirms B, creating two versions of the chain. Users continue working on both, but ultimately (usually after adding a certain number of subsequent transactions), the longer chain will be considered valid (if it grows faster, more users are probably working on it), and the shorter one will be discarded. It’s important to note that this also prevents a situation where a user might attempt to spend all their funds in different transactions at the same time – even if multiple versions of the chain temporarily arise, only one will ultimately remain, invalidating the other operations of the dishonest payer. The decentralized nature of the mechanism also brings up several other concerns, the discussion of which could constitute a separate series of posts – interested readers are referred to the article on the Bitcoin currency [1].
Although blockchain with proof of work solves the issue of a lack of a trusted third party through decentralization, prevents any changes or deletion of confirmed transactions, ensures a high degree of anonymity, and guarantees that after some time, all users will agree on the appearance of the transaction chain, this mechanism is not without its drawbacks. Primarily, due to the difficulty of finding a number that would allow the transaction to be described with the appropriate hash, this technology significantly limits the number of transactions that can be carried out per second (Transactions per Second, TPS) – it is estimated that currently, only a few TPS can be confirmed using proof of work, while standard, centralized payment mechanisms (such as Visa) allow for thousands of such transactions [2]. It is also important to note the high resource consumption required to generate the appropriate hash – a unit searching for it must perform very fast, intensive calculations for a long time, raising concerns from both ecological and economic perspectives. Alternative transaction confirmation methods are being proposed, such as proof of stake, where the most trusted users are the wealthiest, as they have the most to gain from the system’s stability. This type of solution can be found in the Ethereum system [3].
The above discussion describes blockchain technology at a high level of abstraction, so some details may have been omitted for readability. If you would like to learn more about the mechanisms used in this process (e.g., hashing), we encourage you to read our articles on cryptography Cryptography – stream ciphers, Cryptography – good password and good practices, Cryptography – randomness in cybersecurity, Cryptography – basic concepts and definitions. Until next time!