Ethereum Proof-of-Stake Consensus Interview Questions

Ethereum Proof-of-Stake consensus algorithm interview questions covering Casper FFG and LMD GHOST.

Q1: How does Ethereum consensus work (Proof-of-Stake)?

Answer:

Ethereum 2.0 uses Proof-of-Stake consensus (Casper FFG + LMD GHOST).

Sequence Diagram:

Overall Flow Diagram:

Individual Node Decision Diagram:

Ethereum PoS Components:

1. Beacon Chain:

  • Coordinates validators
  • Manages validator set
  • Handles finality

2. Validator Duties:

  • Proposing: Create blocks (selected randomly)
  • Attesting: Vote on blocks (every epoch)
  • Sync Committee: Light client support

3. Slot and Epoch:

  • Slot: 12 seconds (one block)
  • Epoch: 32 slots (~6.4 minutes)
  • Finality: ~2 epochs (~13 minutes)

4. Fork Choice (LMD GHOST):

  • Latest Message Driven Greedy Heaviest Observed Subtree
  • Follows chain with most attestations
  • Resolves forks

5. Finality (Casper FFG):

  • Finalized blocks cannot be reverted
  • Requires 2/3+ validator stake
  • Checkpoint every epoch

Key Properties:

  • Security: Economic security (stake at risk)
  • Energy: 99.9% less energy than PoW
  • Finality: Checkpoint finality
  • Scalability: Sharding support

Example:

 1class EthereumValidator:
 2    def __init__(self, validator_index, balance):
 3        self.validator_index = validator_index
 4        self.balance = balance  # In ETH
 5        self.activation_epoch = None
 6        self.exit_epoch = None
 7    
 8    def propose_block(self, slot, parent_block):
 9        # Selected as proposer
10        if self.is_proposer(slot):
11            block = {
12                'slot': slot,
13                'parent_root': parent_block.hash,
14                'state_root': self.get_state_root(),
15                'body': self.get_transactions(),
16                'signature': self.sign_block()
17            }
18            return block
19        return None
20    
21    def attest(self, slot, block_root):
22        # Attest to block
23        attestation = {
24            'slot': slot,
25            'index': self.validator_index,
26            'beacon_block_root': block_root,
27            'source': self.get_source_checkpoint(),
28            'target': self.get_target_checkpoint(),
29            'signature': self.sign_attestation()
30        }
31        return attestation
32    
33    def get_rewards(self, epoch):
34        # Calculate rewards based on participation
35        base_reward = self.calculate_base_reward()
36        if self.attested_correctly(epoch):
37            return base_reward
38        else:
39            # Penalty for missing attestations
40            return -base_reward

Slashing Conditions:

  • Double Voting: Two different attestations in same epoch
  • Surround Voting: Attestation surrounds another
  • Proposer Violations: Invalid block proposals

Use Cases:

  • Ethereum 2.0
  • High-security PoS systems

Related Snippets