• Tidak ada hasil yang ditemukan

The Blockchain Structure

Dalam dokumen Mobile Edge Computing (2022) springer (Halaman 93-98)

7.1 The Integration of Blockchain and Mobile Edge Computing

7.1.1 The Blockchain Structure

Blockchain is an open database that maintains an immutably distributed ledger typ- ically deployed in a peer-to-peer network. The structure of blockchain is shown in Fig.7.1and consists of three essential components: transactions, blocks of transac- tion records, and a consensus algorithm. The transaction information includes node pseudonyms, data types, metadata tags, a complete index history of metadata, an encrypted link to transaction records, and a timestamp of a specific transaction. Each transaction is encrypted and signed with digital signatures to guarantee authentic- ity. The digitally signed transactions are arbitrarily packed into a cryptographically tamper-evident data block. The blocks are linked in linear chronological order by hash pointers to form the blockchain. To maintain the consistency and order of the blockchain, a consensus algorithm is designed to generate agreement on the order of the blocks and to validate the correctness of the set of transactions constituting the block.

Fig. 7.1 The blockchain structure

7.1 The Integration of Blockchain and Mobile Edge Computing (MEC) 83 7.1.1.1 Transactions

A transaction is the unit data structure of a blockchain, and it is created by a set of users to indicate the transfer of tokens from a specific sender to a receiver. Transactions generally consist of a recipient address, a sender address, and a token value. The input of a transaction is a reference that contains a cryptographic signature. The output of a transaction specifies an amount and an address. Transactions are bundled and broadcast to each node in the form of a block. As new transactions are distributed throughout the network, they are independently verified by each node. To protect the authenticity of a transaction, the functionalities of cryptographic hashing and asymmetric encryption are utilized, as follows.

Hash function: A cryptographic hash function maps an arbitrary-size binary input into a fixed-size binary output. For example, SHA-256 maps an arbitrary-size input to a binary output 256 bits. The binary output is called a hash value. More- over, the same input will always provide the same hash output. The probability of generating the same output for any two different inputs is negligible; it is thus impossible to reconstruct the input based on a hash output. The hash of a transaction makes it easy to keep track of transactions on the blockchain. In Bitcoin, SHA- 256 and RIPEMD160 are utilized as hash function to produce a bitcoin address.

In Ethereum, Keccak-256 is utilized as a hash function to produce a public key. In addition, signatures and private keys in blockchain frequently use hash functions to ensure security.

Asymmetric encryption: Asymmetric encryption provides a secure method for authentication and confidentiality. Each node in a blockchain has a pair of keys: a public key and a private key. The public key can be shared with anyone to encrypt a message, whereas the private key should only be known to the key’s initiator. In blockchain, the public key is used as the source address of transactions to verify their genuineness. The cryptographic private key is used to sign a transaction, which outputs a fixed-size digital signature for any arbitrary-size input message.

The verification result will be true if the digital signature has the correct private key and input message. An elliptic curve digital signature algorithm is a typical algorithm for digital signing transactions. In the elliptic curve digital signature algorithm, when a user (A) wants to sign a transaction, that user first hashes the transaction and then uses his or her private key to encrypt the hashed transaction.

The user then broadcasts the encrypted transaction. When another user receives the transaction and wants to verify its correctness, that user can decrypt the signature with user A’s public key and hash the received transaction to verify whether the transaction information has been changed.

In blockchain, each transaction is broadcast over the entire network and cross- verified by multiple nodes. The verified transactions are ordered consecutively with linearly ordered timestamps to guarantee correctness.

84 7 The Future of Mobile Edge Computing

Fig. 7.2 Block structure

7.1.1.2 The Block Structure

A blockchain is a sequence of blocks that holds a complete list of transaction records.

A block in a blockchain contains the hash of the current block, the hash of the previous block, a Merkle tree root, a timestamp, a nonce, and transactions, as shown in Fig.7.2.

Block hash: A block hash is the principal block identifier. It is a cryptographic digest made by hashing the block header twice with the SHA-256 algorithm. It identifies a block uniquely and unambiguously, and it can be independently derived by any node by simply hashing the block header.

Previous hash: The hash of the previous block, which is a 256-bit hash that points to the previous block, is a necessary data field for the block header. Based on the previous block hash, all blocks are linked together to form a chain. If any block is tampered with, this will cause a change in all subsequent block hash pointers.

When a block and all previous blocks are downloaded from an untrusted node, block hashing can be used to verify whether any block has been modified.

Merkle tree: A Merkle tree represents a transaction set in the form of a binary tree for quick validation and synchronization. In the tree, the leaf nodes are the lowest tier of nodes, and each leaf node is a hash of a transaction. Each non-leaf node is a hash of the concatenation of two child nodes. The root node of the Merkle tree is known as the Merkle digest or root. Adjacent leaves are concatenated pairwise, and the hash of the concatenation constitutes the node’s parent. Parent nodes are concatenated and hashed similarly to generate another level of parent nodes. This process is repeated until a single hash remains, which is the Merkle root. The Merkle tree is useful because it allows users to verify whether a transaction has occurred, based only on the direct branch from the transaction node to the Merkle root path. Moreover, the Merkle root allows tampering of any transaction data to be detected, to ensure their integrity.

Timestamp: The time the block was generated. In blockchain, every block has a timestamp and the timestamp can be referred to as proof of existence. According to Satoshi Nakamoto’s white paper [107], a decentralized timestamp service can resolve the double-spending problem. It can also help improve the traceability and transparency of the data stored in the blockchain.

Nonce: A nonce is random number, and it can be used only once. Each node competes to find the nonce first to obtain the correct packing transactions for the

7.1 The Integration of Blockchain and Mobile Edge Computing (MEC) 85 newly generated block. The nonce is difficult to find and is considered a way to weed out less talented miners. Once the nonce is found, it is added to the hashed block. With this number, the hash value of that block will be rehashed, creating a difficult algorithm.

The first block in any blockchain is termed the genesis block. This block is some- times referred to as block 0. Every block in a blockchain stores a reference to the previous block. However, the genesis block has no previous block for reference.

7.1.1.3 Consensus Algorithms

Blockchain is a distributed decentralized network that provides immutability, pri- vacy, security, and transparency. There is no central authority to validate and verify the transactions, but the transactions are considered secured and verified. This is possible because of consensus. Consensus is a process that allows all nodes to reach a common agreement on the state of a distributed ledger. The consensus problem can be formulated as a Byzantine fault–tolerant problem, that is, how generals can come to a common conclusion in the presence of a small number of traitors and mis- communications. The consensus currently used in most blockchain networks can be split into two categories: probabilistic-finality consensus and absolute-finality con- sensus. In probabilistic-finality consensus, any block in a blockchain can be reverted with a certain probability; attackers could thus accumulate a large amount of com- putational power, or stake, to create a long private chain to replace a valid chain. In absolute-finality consensus, a transaction is immediately finalized once it is included in a block. In other words, a new block generated by a leader node is committed by sufficient nodes before submission to the blockchain. We next present several common consensus strategies in blockchain.

Proof of work (PoW): PoW is a consensus strategy used in Bitcoin, where one node is selected to create a new block in each round of consensus through a com- putational power competition. In the competition, all participants must solve a cryptographic puzzle by using different nonces until the target is reached. The node that first solves the puzzle has the right to create a new block. Solving a PoW puzzle is costly and time-consuming, but it is easy for other nodes to verify. PoW guarantees security, based on the principle that it is impossible for a malicious attacker or group to collect more than 50% of the network’s computational power to control the consensus process. PoW is a probabilistic-finality consensus proto- col to guarantee eventual consistency. In PoW, nodes must consume a great deal of energy to solve the cryptographic puzzle. However, this work is useless and the energy consumed is wasteful. To tackle the resource waste problem of PoW, the idea of proof of useful resources was designed. Primecoin proposed a consensus algorithm to turn useless PoW into a meaningful search for special prime num- bers when seeking a nonce [108]. Permacoin utilized bitcoin mining resources to distributively store an extremely large data provided by an authoritative file dealer based on proof of retrievability [109]. Instead of wasting energy for PoW, proof

86 7 The Future of Mobile Edge Computing of burn allows miners to burn virtual currency tokens and then grants miners the right to write blocks in proportion to the number of burned coins [110].

Proof of stake (PoS): PoS is an energy-saving consensus to replace PoW. Instead of consuming large amounts of computational power to solve a PoW puzzle, PoS selects one node to create the next block based on the amount of stake. PoS is a probabilistic-finality consensus protocol, where the chances of being a block creator depends on “wealth”. Since the richest node is bound to dominate the network, creator selection based on the amount of stake is quite unfair. Therefore, many researchers have proposed new schemes to decide on the node to forge the next block. Peercoin proposed a metric of coin age to measure the amount of held coins and their holding time [111]. In Peercoin, the node with older and larger sets of coins has a higher probability of creating the next block. Compared with PoW, Peercoin can reduce energy consumption and become more efficient.

Ouroboros proposed PoS-based consensus, considering that stakes will shift over time [112]. A secure multiparty coin-flipping protocol was proposed in Ouroboros to guarantee the randomness of the leader election in the block generation process.

To combine the benefits of PoW and PoS, proof of activity was proposed [113].

In proof of activity, the leader in each round of consensus is selected based on a standard PoW-based puzzle competition to generate an empty block header, where the stakeholders participating in the block verification receive a reward.

Delegated PoS (DPoS): The main difference between PoS and DPoS is that PoS involves direct democracy, whereas DPoS involves representative democ- racy [114]. In DPoS, stakeholders vote to elect delegates. The elected delegates are responsible for block creation and verification. Voting in DPoS is important, since it enables stakeholders to give delegates the right to create blocks, instead of creating blocks themselves; DPoS can thus reduce the computational power con- sumption of stakeholders to zero. On the other hand, PoW with plenty of nodes participating in the block verification process. In DPoS, only fewer delegates par- ticipate in the block verification process, thus the block can be confirmed quickly and the transactions can be confirmed quickly. Compared to PoW and PoS, DPoS is a low-cost, high-efficiency consensus protocol. Additionally, stakeholders do not need to worry about dishonest delegates, because these delegates can be easily voted out. There are also cryptocurrencies that implement DPoS, such as BitShares [115] and EoS. The new version of EoS has extended DPoS to DPoS–Byzantine fault tolerance. [116].

• Practical Byzantine fault tolerance (PBFT): PBFT is a Byzantine fault tolerance protocol with low algorithm complexity and high practicality [117]. Even if some nodes are faulty or malicious, network liveness and safety are guaranteed by PBFT, as long as a minimum percentage of nodes are connected, working properly, and behaving honestly. Hyperledger Fabric [118] utilizes PBFT as its consensus algo- rithm. In PBFT, a new block is determined in a round. In each round, a primary node is selected as the leader to broadcast the message sent by the client to other nodes. PBFT can be divided into three phases: pre-prepare, prepare, and commit.

In each phase, a node enters the next phase if it has received votes from over two- thirds of all nodes. PBFT guarantees the nodes maintain a common state and take

7.1 The Integration of Blockchain and Mobile Edge Computing (MEC) 87 Table 7.1 Main consensus comparison

Type Fault tolerance Power

consumption

Scalability

PoW Probabilistic

finality

50% Large Good

PoS Probabilistic

finality

50% Less Good

DPoS Probabilistic

finality

50% Less Good

PBFT Absolute finality 33% Negligible Bad

consistent action in each round of consensus. PBFT achieves strong consistency and is thus an absolute-finality consensus protocol.

In distributed systems, there is no perfect consensus protocol. The consensus protocol should be adopted based on detailed application requirements. We present a simplified comparison of different consensus algorithms in Table7.1.

Dalam dokumen Mobile Edge Computing (2022) springer (Halaman 93-98)