Cryptocurrency technical architecture (1) - BTC, ETH

1. BTC (Bitcoin)

(1) Project background

BTC (Bitcoin) is the first cryptocurrency based on decentralization, using peer-to-peer network and consensus initiative, open source code, and using blockchain as the underlying technology. As the world's first cryptocurrency, it is undoubtedly the largest in terms of market capitalization, and after 13 years of bull and bear transitions, it sits on the throne of the most stable cryptocurrency.

(2) Technical framework

As shown in the figure, the Bitcoin system is divided into 6 layers, from bottom to top, the storage layer, data layer, network layer, consensus layer, RPC layer, and application layer.

Among them, the storage layer is mainly used to store log data and blockchain metadata during the operation of the Bitcoin system, and the storage technology mainly uses file systems and LevelDB.

The data layer is mainly used to process various types of data in Bitcoin transactions, such as packaging data into blocks, maintaining blocks into chain structures, encryption and hash calculation of content in blocks, digital signatures of block content and Add timestamps, build transaction data into a Merkle tree, and calculate the hash value of the root node of the Merkle tree, etc. Personally, I understand that the data layer frameworks between different cryptocurrencies are basically similar, and the main differences lie in the consensus mechanism and contract part.

The chain composed of blocks may fork. In the Bitcoin system, nodes always regard the longest chain as the correct chain and continue to add new blocks thereafter.

The network layer is used to build the underlying P2P network of Bitcoin, supports the dynamic joining and leaving of multiple nodes, effectively manages network connections, and provides basic network support services for Bitcoin data transmission and consensus reaching.

The consensus layer mainly uses the PoW (Proof Of Work) consensus algorithm. In the Bitcoin system, each node continuously calculates a random number (Nonce) until it finds a random number that meets the requirements. Within a certain period of time, the first one to find a random number that meets the conditions will get the right to package the block, which builds a proof-of-work mechanism.

The RPC layer implements the RPC service and provides a JSON API for clients to access the underlying blockchain services.

The application layer mainly carries various Bitcoin applications, such as the Bitcoin client provided in the Bitcoin open source code. This layer mainly serves as an RPC client and interacts with the underlying Bitcoin through JSON API. In addition, Bitcoin wallets and derivative applications are built on the application layer.

Bitcoin source code website:

https://github.com/bitcoinhttps://github.com/bitcoin

Ethereum source code website:

ethereum/go-ethereum: Official Go implementation of the Ethereum protocol (github.com)https://github.com/ethereum/go-ethereum

2. ETH (Ethereum)

(1) Project background

ETH (Ethereum) is the native currency of Ethereum. Ethereum was influenced by Bitcoin in 2013 by Vitalik Buterin (V God) and proposed the next generation of cryptocurrency and decentralized application platform. It began to develop through ICO crowdfunding in 2014. On July 30, 2015, Ethereum's public blockchain was launched and Ethereum coins were issued.

Ethereum is the most optimistic cryptocurrency after Bitcoin, and it has been the second most popular cryptocurrency in the stable currency circle since its birth. Ethereum has also continued to evolve over time. More than 70% of NFTs that were popular in the market last year were traded using ETH.

(2) Technical framework

Ethereum is an open public blockchain platform that uses smart contracts to constrain user behavior and provides a decentralized Ethereum Virtual Machine (EVM) for the Ethereum network through its derived cryptocurrency ETH. P2P smart contract.

Early Ethereum smart contracts used POW equity proof, and ETH was obtained through mining. The price is that it requires a large amount of electricity resources to generate enough computing power for mining, and it is often criticized because of issues such as transmission speed, scalability, and gas fees. In order to solve these problems, Ethereum will merge on September 15, 2022, converting from POW to POS.

As shown in the figure, the Ethereum architecture is divided into 7 layers, from bottom to top, the storage layer, data layer, network layer, protocol layer, consensus layer, contract layer, and application layer.

The storage layer is mainly used to store log data and blockchain metadata during the operation of the Ethereum system. The storage technology mainly uses the file system and LevelDB.

The data layer is mainly used to process various types of data in Ethereum transactions, such as packaging data into blocks, maintaining blocks into chain structures, encryption and hash calculation of content in blocks, digital signatures of block content and Add timestamps, build transaction data into a Merkle tree, and calculate the hash value of the root node of the Merkle tree, etc.

The difference from Bitcoin is that Ethereum introduces the concept of transactions and transaction pools. A transaction refers to the process of sending a signed data packet from one account to another account. The transaction pool stores transactions verified by nodes, and these transactions will be placed in new blocks mined by miners.

Ethereum's Event refers to the log interface provided by the Ethereum Virtual Machine. When an event is called, the corresponding log information is saved in the log file.

Like Bitcoin, Ethereum's system is also based on the P2P network. Each node in the network has both client and server roles.

The protocol layer is the protocol support provided by Ethereum for each module of the system to call each other. It mainly includes HTTP, RPC protocol, LES, ETH protocol, Whipser protocol, etc.

Ethereum implements support for HTTP based on HTTP Client and implements HTTP methods such as GET and POST. External programs need to use the RPC (remote procedure call) protocol when calling Ethereum's API through JSON RPC.

Whisper protocol is used for inter-DApp communication.

The full name of LES is Light Ethereum Sub-protocol, which allows Ethereum nodes to download only the header of the block when acquiring the block synchronously, and then obtain other parts of the block when needed.

The consensus layer has two consensus algorithms in the Ethereum system: PoW (Proof of Work) and PoS (Proof of Stake). Regarding the source code analysis of the Ethereum consensus part, the linked article has a more detailed introduction. https://blog.csdn.net/wcc19840827/article/details/90647000/ https://blog.csdn.net/wcc19840827/article/details/90647000/

The contract layer is divided into two layers. The bottom layer is EVM (Ethereum Virtual Machine), and the upper smart contract runs in EVM. Smart contracts are the collective name for codes running on Ethereum. A smart contract often contains two parts: data and code. The smart contract system codifies the agreement or contract and triggers execution driven by specific events. Therefore, in principle, it is applicable to agreements or contract scenarios regarding security, trust, and long-term nature. In the Ethereum system, the default programming language for smart contracts is Solidity.

The application layer includes DApp (Decentralized Application), Ethereum wallet and other derivative applications, and is currently the layer with the most active developers.

3. Bitcoin VS Ethereum

(1) Main functions

The first generation of blockchain is actually an encrypted digital currency represented by Bitcoin. It is characterized by unblocked point-to-point value transfer and scarcity. The second generation of blockchain is mainly a smart contract platform represented by Ethereum, which can realize automatically executed electronic contracts through blockchain technology, similar to the Android system in mobile phones. Later, most applications of blockchain are Smart contract based functionality.

BTC is mainly used as a virtual currency and stores value, and ETH can also achieve the same function. However, the decentralized ETH network can also achieve some other functions, such as creating and running applications, signing smart contracts, and other functions. types of transactions, and all of these functions are not available in BTC, which can only achieve limited functions. The main purpose of Ethereum is not to build itself as a payment alternative, but to facilitate and monetize the operation of Ethereum so that developers can build and run distributed applications.

(2) Consensus

At their core, both Bitcoin and Ethereum are blockchain technologies. However, when it comes to their consensus algorithms, key differences can be observed. Both Ethereum and Bitcoin have their own unique consensus algorithms, which means they differ in how they verify the validity of information added to the ledger.

The Bitcoin WK consensus is based on the so-called Proof of Work (PoW) algorithm. In this concept, the probability of a person mining a block is based on the amount of computational work he does. Mining rewards are awarded to the first miner who manages to solve a complex cryptographic puzzle for each block. According to the concept of PoW, each network miner competes with all other miners in using computing power.

Ethereum, on the other hand, is based on another algorithm called Proof of Stake (PoS). The probability of validating a new block in this consensus algorithm depends on how many shares someone holds, or in other words - how many coins he has. In a PoS algorithm, block validators do not receive block rewards – instead they are rewarded with network fees. In the case of Ethereum, the reward is called gas. With PoS, there are no mathematical puzzles to solve, and the creator of a new block is selected in a deterministic way.

Interestingly, Ethereum’s block times are quite fast – the time it takes to verify a block. According to data from BitInfoCharts, Bitcoin’s average block time is currently just over 8 minutes, while Ethereum’s block time is around 25 seconds.

 Another point is that Bitcoin can only have a maximum of 21 million, but Ethereum is unlimited.

Guess you like

Origin blog.csdn.net/weixin_62724756/article/details/129338598