Exploring Foundry Cheatcodes
List and introduce commonly used Foundry Cheatcodes to write tests and debug smart contracts more efficiently.
Introduce all common consensus algorithms, including PoW, PoS, DPoS, etc.
A consensus algorithm is a rule and protocol in a distributed system by which all nodes reach an agreement on a certain data state or transaction sequence.
In 1982, Leslie Lamport proposed the “Byzantine Generals Problem”, which studies how distributed systems can tolerate faults. The problem is set against the backdrop of a group of generals communicating through messengers to vote on whether to attack or retreat. Due to the possibility of traitors among the generals who may vote maliciously or impersonate other generals, or because messages may be lost or tampered with during transmission, the army ultimately fails to coordinate its actions.

Byzantine Generals
In a computer system, the general is the network node and the messenger is the communication system. How to ensure that all honest nodes can still synchronize and recognize the same “correct” data or transaction status even when the network is unreliable, there is a delay or some nodes are malicious, this problem involves information security, but relying solely on digital signatures cannot solve it, because digital signatures can only verify the integrity and source of the message, but cannot identify when malicious nodes actively send incorrect information. For this reason, we need consensus algorithms.
Consensus algorithms are tools that enable a group of mutually distrustful individuals to reach an agreement in a distributed network, ensuring the secure and fair operation of the blockchain without centralized control. They determine who has the right to generate new blocks (the right to bookkeeping) and how the validity of blocks is verified.
Nodes compete for the right to create blocks by solving complex mathematical problems. The node that solves the problem first gains the right to create the block. Its characteristics are low efficiency, high energy consumption, and high centralization. Security depends on computing power. It is suitable for public chains and value storage.
Block production rights are allocated based on the quantity of tokens held by nodes and the duration of holding (stake). Unlike Proof of Work (PoW), PoS does not require nodes to perform complex computations but instead randomly selects block-producing nodes based on the tokens they hold. However, this may lead to the rich getting richer. Its characteristics include medium efficiency, low energy consumption, and medium centralization. Security depends on the amount of tokens held and it is suitable for public chains, financial applications, and community governance scenarios.
The aim is to elect block-producing nodes (referred to as “witnesses” or “delegates”) through voting by token holders, with these nodes responsible for verifying transactions and generating blocks. DPoS is an improvement on the traditional Proof of Stake (PoS), enhancing the network’s efficiency and decentralization through the introduction of a delegation mechanism. It is characterized by high efficiency, low energy consumption, and a relatively high degree of centralization. Its security relies on the credibility of the witnesses and it is suitable for public chain and community governance scenarios.
Block generation is handled by pre-authorized nodes, and transactions are verified and blocks are generated through pre-authorized nodes (referred to as “authoritative nodes” or “validators”). Unlike PoW and PoS, the core idea of PoA is to trust the authorized nodes rather than competing for block generation rights through computing power or token holdings. Its characteristics are high efficiency, low energy consumption, and high centralization. Security depends on the credibility of the validators, making it suitable for consortium chains, private chains, and test networks.
PoET aims to determine the block-producing nodes through a fair random selection process while reducing energy consumption. Proposed by Intel, PoET is based on Trusted Execution Environment (TEE) technology, ensuring that nodes obtain the right to produce blocks after waiting for a random period of time. Its characteristics include high efficiency, low energy consumption, and moderate centralization. Its security relies on TEE technology and is suitable for consortium chains, private chains, and the Internet of Things.
Proposed by the Solana project, Proof of History (PoH) aims to enhance consensus efficiency and network scalability by proving the sequence of events through a timestamp sequence. PoH is not an independent consensus algorithm but is used in conjunction with Proof of Stake (PoS), where PoS is responsible for selecting block-producing nodes and PoH is responsible for verifying the sequence of events, providing an efficient time ordering and verification mechanism for the blockchain. Despite its reliance on time synchronization and high technical complexity, PoH’s efficiency and security make it an important innovation in the blockchain field. Its features include high efficiency, low energy consumption, and low centralization, with security relying on the timestamp sequence, making it suitable for public chains and financial applications.
Block production rights are competed for based on the storage space provided by nodes. Unlike Proof of Work (PoW), which relies on computing power, PoSpace utilizes the storage resources of nodes to ensure the security and decentralization of the network. The goal of PoSpace is to reduce energy consumption while providing an efficient consensus mechanism. It is characterized by moderate efficiency, low energy consumption, and moderate centralization. Its security depends on storage space and is suitable for public chains, storage networks, and the Internet of Things.
Nodes prove their willingness to participate in consensus by burning tokens and thereby obtain the right to create blocks. The core idea of Proof of Burn (PoB) is to “burn” tokens (i.e., send them to an inaccessible address) to demonstrate the node’s commitment and investment in the network. PoB aims to provide a fair and decentralized consensus mechanism while avoiding the high energy consumption problem of Proof of Work (PoW). Despite its relatively high token-burning and centralization risks, its fairness and decentralization features make it an important innovation in the blockchain field. It is characterized by medium efficiency, low energy consumption, and medium decentralization, with security relying on token burning. It is suitable for public chains and community governance.
Block production rights are competed for based on the storage capacity provided by nodes. Unlike Proof of Work (PoW), which relies on computing power, Proof of Capacity (PoC) utilizes the storage resources of nodes to ensure the security and decentralization of the network. The goal of PoC is to reduce energy consumption while providing an efficient consensus mechanism. It is characterized by medium efficiency, low energy consumption, medium decentralization, and security that depends on storage capacity.
Paxos was proposed by Leslie Lamport in 1990, aiming to solve the problem of multiple nodes reaching consensus on a certain value in distributed systems. Paxos is one of the important algorithms in the field of distributed computing and is widely applied in distributed databases, distributed storage systems, and blockchain, among other areas.
The Paxos algorithm consists of two phases: the prepare phase and the accept phase.
Raft was proposed by Diego Ongaro and John Ousterhout in 2014, aiming to simplify the process by which multiple nodes in a distributed system reach consensus on a certain value. Raft is an alternative to Paxos. By decomposing the consensus process into more understandable modules, it reduces the complexity of the algorithm while maintaining high fault tolerance and consistency.
The Raft algorithm is divided into three main modules: leader election, log replication, and safety.
Byzantine Fault Tolerance (BFT) is a consensus mechanism in distributed systems that ensures consistency even in the presence of Byzantine faults. A Byzantine fault refers to the possibility of nodes malfunctioning in any way, including sending incorrect information, not responding, or engaging in malicious behavior. The goal of BFT is to ensure that the system can still reach consensus in the presence of malicious nodes, and it can typically tolerate no more than one-third of the total number of nodes being malicious.
The BFT algorithm typically includes the following steps:
PBFT (Practical Byzantine Fault Tolerance) is a practical BFT algorithm proposed by Miguel Castro and Barbara Liskov in 1999. It is the first practical algorithm capable of achieving Byzantine fault tolerance in an asynchronous network, and is applicable to distributed systems to reach consensus even in the presence of malicious nodes.
The PBFT algorithm achieves consensus through multiple rounds of message passing and voting mechanisms. Its core process includes the following stages:
Tendermint is an efficient and secure BFT algorithm and blockchain framework proposed by Jae Kwon in 2014. It combines Proof of Stake (PoS) and BFT mechanisms, aiming to address the scalability, security, and decentralization issues of traditional blockchains. Tendermint serves as the core consensus engine of the Cosmos network and is widely used in blockchain development and cross-chain interoperability.
The core idea is to quickly reach network consensus through multiple rounds of voting and signing. The consensus process of Tendermint includes the following stages:
Algorand is an efficient and decentralized blockchain protocol that adopts Pure Proof of Stake (PPoS), cryptographic sortition, and BFT to ensure decentralization and efficiency. It was proposed by Silvio Micali, a professor at the Massachusetts Institute of Technology, in 2017. Algorand aims to address the performance, scalability, and decentralization issues in traditional blockchain technologies. Through its unique consensus mechanism and cryptographic techniques, it achieves a fast, secure, and permissionless blockchain network.
The consensus process of Algorand is divided into the following stages:
Avalanche is an innovative blockchain protocol proposed by Team Rocket in 2018 and officially released in 2020. It aims to address the scalability, decentralization, and security issues of traditional blockchains. Through a unique consensus mechanism and architectural design, Avalanche achieves a high-performance, low-latency blockchain network.
Avalanche adopts the Avalanche Consensus protocol, which is a consensus mechanism based on metastability, random sampling, and BFT algorithm. Its core idea is to quickly reach network consensus through multiple rounds of random sampling and voting.
The features of the Avalanche protocol include:
HotStuff is an efficient BFT algorithm proposed by the VMware Research team in 2019. It is designed to address the complexity and performance bottlenecks of traditional BFT algorithms, such as PBFT, and is particularly suitable for large-scale distributed systems. The core idea of HotStuff is to significantly improve consensus efficiency and scalability through a chaining structure and pipelining design. HotStuff is the core consensus algorithm of Facebook’s blockchain project Libra (now Diem).
The consensus process of HotStuff is based on a chain structure and pipeline design. Its core idea is to divide the consensus process into multiple stages and connect these stages in a chain structure. The consensus process of HotStuff includes the following stages:
