By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
Consensus mechanisms are the rule‑sets that let a decentralized network agree on a single, tamper‑proof history of transactions without a trusted third party. They turn a bunch of independent nodes into a “virtual” authority, enabling everything from a Uniswap swap (where the price is set by on‑chain state) to an NFT minting dApp that records ownership on a public ledger.
// Minimal staking contract (PoS illustration) contract SimpleStaking { mapping(address => uint256) public stake; uint256 public totalStake; function deposit() external payable { stake[msg.sender] += msg.value; totalStake += msg.value; } // In a real PoS chain the protocol would call `finalizeBlock` // after the validator set signs off.}
block.prevrandao
bash npx hardhat compile npx hardhat run scripts/deploy.js --network goerli
js const block = await provider.getBlock('latest'); console.log('epoch:', block.timestamp / 32_400); // approx. epoch length on Goerli
eth_getFinalizedBlock
Mistake: Assuming PoW “difficulty” is a static number. Correction: Difficulty adjusts each block based on the previous block’s timestamp; hard‑coding it leads to sync failures.
Mistake: Using tx.origin for access control in a PoS‑based dApp. Correction: tx.origin can be spoofed through contract calls; always use msg.sender and, for multi‑sig, verify signatures off‑chain.
tx.origin
msg.sender
Mistake: Forgetting to handle validator slashing in staking contracts. Correction: Include a slash(address malicious, uint256 amount) function that can only be called by the consensus layer (via onlyValidator modifier).
slash(address malicious, uint256 amount)
onlyValidator
Mistake: Deploying a DPoS contract on a pure PoW network and expecting fast finality. Correction: DPoS relies on a small, elected validator set; on PoW the block time dominates, so finality will still be probabilistic.
Mistake: Ignoring the quorum requirement in PBFT/Raft when building a private consortium chain. Correction: Configure the network with at least 3f+1 nodes for PBFT or a majority of votes for Raft; otherwise the chain can stall.
3f+1
Scenario: A contract reads block.prevrandao to pick a random winner for an airdrop. Answer: Safe in PoS because the value is generated by the validator set via a VRF; in PoW it could be manipulated by a miner.
Scenario: Your DPoS chain has 21 delegates, but only 10 are online. What happens to block production? Answer: The protocol will rotate through the active delegates; if a delegate misses its slot, the next online delegate fills the gap, preserving liveness.
Scenario: You implement PBFT with 4 nodes. How many Byzantine nodes can the system tolerate? Answer: Only 0; PBFT needs 3f + 1 nodes, so with 4 nodes you can tolerate f = 1 (i.e., 1 faulty node).
3f + 1
f = 1
block.difficulty
unchecked { … }
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.