## 2 Overview of IoT Security
### Blockchain in IoT Security  
A blockchain is a database of ledgers that allows users to record information such as asset and transaction registries in a fully decentralized manner using a peer-to-peer (P2P) network [14]. Typically, the blocks are linked together chronically, and each block stores data for a certain period. Each data item, e.g., transaction, is written by a particular user in the blockchain, i.e., a miner, following designed protocols and can be verified by all users in the blockchain. A blockchain relies on cryptographic proof using mechanisms such as elliptic curve cryptography (ECC) and SHA-256 hashing to guarantee data authenticity and integrity [46]. The data in each block normally consist of a ledger, e.g., transaction log, and a block header, e.g., a hash code, that links to the prior block. The blockchain records every single trade ever made and facilitates global distributed trust across borders. Centralized authority and services, sometimes known as \"Trusted Third Parties\", are vulnerable to being hacked, compromised, or otherwise adversely affected by external interference. Even if they are trustworthy now, they may behave badly or become corrupt in the future. The blockchain relies on a certain kind of user called a miner to create new blocks and validate and record each transaction in the block. Normally, any user on the blockchain can compete to be a miner of the blockchain by implementing certain computing tasks, e.g., solving a math puzzle. In particular, to append a new block to the blockchain, miners typically need to implement a designed task that involves finding a random number (nonce) that leads the hash of the block header to be less than a certain target. Typically, the blockchain adopts the longest chain rule, where the data stored in the longest chain is considered to be valid. This is based on the assumption that the majority of the users are honest and they will append new blocks to the block with valid data. For instance, in Bitcoin, after six confirmations or blocks, the data in the blocks are confirmed because the probability of the data being replaced is low enough. On the other hand, private blockchains have been proposed. In a private blockchain, there are permitted nodes who are trustworthy and communicate to reach a consensus. A private chain makes this process much faster, but essentially, it relies on the truthfulness of the permitted nodes. As demonstrated by the aforementioned designed protocols, the three most notable features of a blockchain are decentralization, transparency, and immutability [47]. Due to the decentralized nature of blockchains, no single entity can claim ownership over the network. To clarify, immutability denotes that the data stored in the blockchain can never be tampered with. Decentralization means that the system never needs a central authorized party, e.g., a server. Transparency means that any user may view any other user's transactions simply by knowing their public address. These features enhance the safety and utility of the blockchain. A common blockchain architecture is presented in Figure 4. There are two essential parts of a typical block: the block header and the block body. The former can be considered the identifier of the block, which typically contains a timestamp; a hash code of the data in the block, e.g., transactions; the hash code of the previous block's header; and a nonce value. The latter normally holds the data, e.g., a list of transactions. The data are stored in a Merkle tree structure. The Merkle root denotes the root of a hash tree with a hash of all transactions at the leaves, serving as a summary of all transactions. The identifier for a block is the hash of the block header. Additionally, the nonce value is found by miners such that the block hash can satisfy certain requirements based on the consensus protocols. For instance, in Bitcoin, every user can check that the hash of the block header is less than a target. Finding valid nonce values is normally difficult and computationally intensive.