πŸ“„

Whitepaper 2.0

Introduction

Harmony:

  • Fully Scalable
  • Secure Sharding
  • Efficient and Fast Consensus
  • Adaptive-Thresholded PoS
  • Scalable Networking Infrastructure
  • Consistent Cross-Shard Transactions
β€£

Consensus Mechanism

Determines how securely and quickly blockchain validators reach consensus on the next block

  • Prepare phase:
    • Leader broadcasts its proposal to all of the validators
    • Validators broadcast their votes to everyone else
      • Votes of each validator need to be counted by all other validators
    • Phase finished when 2f+12f + 1 consistent votes are seen
      • ff = number of malicious validators
      • 3f+13f+1 = total number of validators + leader
  • Commit phase:
    • Similar vote counting process
    • Consensus is reached when 2f+12f+1 consistent votes are seen
  • O(n2)O(n^2) due to the rebroadcasting β†’ not scalable with hundreds of nodes

FBFT (Fast Byzantine Fault Tolerance)

  • Instead of rebroadcasting to ALL other validators, multi-sig signing process to collect validators’ votes in a O(1)O(1)-sized multi-sig
  • Broadcasts it once collected
  • O(N)O(N) because instead of receiving O(N)O(N) signatures, each validator receives only one multi-sig

BLS (Boneh Lynn Chacham) multi-signature (Only require one round-trip of receiving the signatures)

Harmony’s FBFT:

  1. Announce: The leader constructs the new block and broadcasts the header to all validators. Meanwhile, the leader broadcasts the content of the block w/ erasure coding.
  2. Prepare (a): The validators check the validity of the block header, sign the block header with a BLS signature, and send the signature back to the leader.
  3. Prepare (b): The leader waits for at least 2f+12f+1 valid signatures from validators (including the leader itself) and aggregates them into a BLS multi-sig. The the leader broadcasts the aggregated multi-sig along w/ a bitmap indicating which validators have signed.
  4. Commit (a): The validators check that the multi-sig has at least 2f+12f+1 signers, verify the transactions in the block content from Step 1, sign the received message from Step 3, and send it back to the leader.
  5. Commit (b): The leader waits for at least 2f+12f+1 valid signatures from Step 4, aggregates them together into a BLS multi-sig, and creates a bitmap logging all the signers. Finally, the leader commits the new block w/ all the multi-sig and bitmaps attached, and broadcasts the new block for all validators to commit.

Validators w/ more voting shares have more votes than others β†’ NOT a one-signature-one vote

  • Instead of waiting for at least 2f+12f+1 signatures from validators, the leader waits for signatures from validators who collectively possess at least 2f+12f+1 voting shares
β€£

Sharding

PoS based full sharding scheme that is: linearly scalable and provably secure

Beacon chain and multiple shard chains:

  • Beacon chain serves as the randomness beacon and identity register
  • Shard chains store separate blockchain states and process transactions concurrently
β€£

Distributed Randomness Generation

Randomness-based sharding recognized as the most secure solution

Random number must have the following properties:

  1. Unpredictable: No one should be able to predict the random number before it is generated
  2. Unbiaseable: The process of generating the random number should not be biaseable by any participant
  3. Verifiable: The validity of the generated number should be verifiable by any observer
  4. Scalable: The algorithm of randomness generation should scale to a large number of participants

Scalable Randomness Generation w/ VRF and VDF

Harmony’s DRG protocol complexity is O(N)O(N)

Protocol:

  1. A leader sends initinit message with the hash of the last block H(Bnβˆ’1)H(B_{n-1}) to all validators.
  2. For each validator ii, after receiving the initinit message, a VRF is computed to create a random number rir_i and a proof pi:(ri,pi)=VRF(ski,H(Bnβˆ’1),v)p_i: (r_i, p_i)=VRF(sk_i, H(B_{n-1}), v), where skisk_i is the secrete key of each validator and vv is the current view number of consensus. Then, each validator sends back (ri,pi)(r_i, p_i) to the leader.
  3. The leader waits until it receives at least f+1f+1 valid random numbers and combines them with an XORXOR operation to get the pre-image of the final randomness pRndpRnd.
  4. The leaders runs BFT among all the validators to reach consensus on the pRndpRnd and commit it to block BnB_n.
  5. After pRndpRnd is committed, the leader starts computing the actual randomness Rnd=VDR(pRnd,T)Rnd=VDR(pRnd, T), where TT is the VDF difficulty and is set algorithmically such that the randomness can only be computed after kk blocks.
  6. Once RndRnd is computed, the leader initiates a BFT among all validators to agree on the validity of RndRnd and finally commit the randomness into the blockchain.

Due to VDF, the leader won’t be able to know the actual randomness RndRnd before pRndpRnd is committed to the blockchain

By the time RndRnd is computed with the BDF, pRndpRnd is already committed in a previous block so the leader cannot manipulate it

Best a malicious leader can do is to either:

  • Blindly commit the randomness β†’ Same as the honest behavior
  • Not commit pRndpRnd β†’ Timeout mechanism will switch the leader and restart the protocol

β€£

Epoch

An epoch is a predetermined time interval during which:

  • The sharding structure is fixed
  • Each shard continuously runs consensus with the same set of validators

At the beginning of the epoch, a random number will be generated using the DRG protocol and sharding structure will be determined by the randomness

Validators who want to validate transactions in epoch ee need to stake their tokens during eβˆ’1e-1

  • Cutoff time for staking is before pRngpRng is committed into the chain

β€£

Staking-based Sharding

Validator Registration

Participants have to stake a certain amount of tokens to be an eligible validator

Number of tokens will determine the number of voting shares assigned to the validator

Each voting share corresponds to one vote in the FBFT consensus

Sharding by Voting Shares

Amount of tokens for a voting share is algorithmically adjusted

At the beginning of each epoch, new validators’ voting shares will be randomly assigned to shards

The new validators join the shard where their voting shares get assigned

πŸ’‘
Single validator can vote in multiple shards? Or are validators created proportional to the staked tokens?

The consensus in a shard is reached by validators who collectively possess at least 2f+12f+1 voting shares

To guarantee the security of a single shard, the amount of voting shares by malicious validators needs to be kept below 1/31/3 of all voting shares in that shard

  • Assumption: Up to 1/41/4 of all the staked tokens belong to malicious validators
  • if we shard by validators, given the assumption above, the single malicious validator will easily possess more than 1/31/3 voting shares in that shard
  • The stakes at each shard is mm times less than the stakes of the whole network (for Harmony m=4m=4) Large-Stake Attack

To prevent LSA, instead of sharding by validators, we shard by voting shares

After the RndRnd is revealed at the start of the current epoch, a random permutation (seeded with RndRnd) on all the voting shares will divided evenly into mm buckets

The shard leader is determined as the validator who possess the first voting share in the bucket

Validators with larger stake have higher chance of being selected as the leader

  • Desirable because large stakers have more incentive to follow the protocol (slashing)
  • More likely to possess more powerful machines with fast and stable network

Adaptive-Threshold PoS

Harmony’s adaptive threshold PoS guarantees the security measure by adaptively adjusting the price small enough that malicious stakers can’t concentrate their voting power in a single shard

Pvote=TSeβˆ’1NumShardβˆ—Ξ»P_{vote} = \frac{{TS_{e-1}}}{NumShard*\lambda}

Ξ»\lambda is a security parameter and TSeβˆ’1TS_{e-1} is the total amount of tokens staked during epoch eβˆ’1e-1

When Ξ»>600\lambda>600, the chance of a single shard having more than 1/31/3 malicious voting shares is negligible

  • Given the defintion of PvoteP_{vote}, the total number of voting shares will be N=TSeβˆ’1Pvote=NumShardβˆ—Ξ»N=\frac{TS_{e-1}}{P_{vote}}=NumShard * \lambda
  • The probability distribution of the number of malicious voting shares in each shard can be modeled as:
    1. P(X=k)=(Kn)(Nβˆ’Knβˆ’k)(Nn)P(X=k)=\frac{\binom{K}{n}\binom{N-K}{n-k}}{\binom{N}{n}}
    2. NN is the total number of voting shares
    3. K=N4K=\frac{N}{4} is the max number of malicious voting shares
    4. n=NNumShardn=\frac{N}{NumShard} is the number of voting shares in each shard
    5. kk is the number of malicious voting shares in a shard

TL;DR: When n is large enough, the probability that a shard contains more than 1/31/3 tokens held by malicious entities is negligible

  • When n=600n=600, the probability a shard contains less than 1/31/3 malicious voting shares is P(X≀200)=0.999997P(X\leq200)=0.999997, shard failure (i.e. consensus cannot be reached) rate of β€œonce in around 1000 years”

β€£

Resharding

Harmony assumes the slowly adaptive corruption model

  • Slowly adaptive: where attackers can corrupt a subset of nodes over time during the epoch

Cuckoo-rule based resharding mechanism

  • After the end of an epoch, the validators who withdrew their stake will be evicted from the network
  • New validators who staked during epoch, get new voting shares
  • Voting shares will be randomly assigned to the shards that have more than the median of the total voting shares
  • Constant number of the voting shares from all shards will be randomly re-distributed to the other half of the shards who have less than the median of total voting shares

This resharding scheme keep the voting shares balanced while fulfilling the security req.

β€£

Fast State Sync

Traditional way of downloading the blockchain history and reconstructing the current state is too slow for resharding to be possible

Downloading the current state within the time window of an epoch is feasible compared to the whole history

Verification required to ensure the current state of download is valid

  • New node downloads historical block headers and validates the headers by checking their signatures
  • Signature verification is costly thus the first block of each will include an additional hash pointer to the first block of the last epoch
  • New node can jump across the blocks within an epoch when tracing hash pointers to genesis block

β€£

Shard Chain and Beacon Chain

β€£

Shard Chain

Shard chain is a blockchain that processes and validates its own transactions and stores its own state

Cross-shard Communication

Breaks the barrier between shards and extends the utility of a single shard beyond itself

Shard-driven: Messages between shards are directly sent by the nodes in the shard w/out external help

Harmony adapts shard-drive for its simplicity and the absence of burden on clients

β€£

Beacon Chain

In effect, the beacon chain is also a shard

Besides processing transactions, the beacon chain is in charge of two additional key functionalities:

  • Generating the random number
  • Accepting stakes, which means that the beacon chain is the chain where stakers deposit their tokens to become validators

Hash Link from Shard Chain

Beacon chain helps strengthen the security and consistency of the shard chains’ states by including the block header from each shard chain

After a new block is committed to a shard chain, its block header will be sent to the beacon chain

Beacon chain checks the validity of the block header by:

  1. The hash of its previous block, which must have already been committed in the beacon chain
  2. The signers of the block’s multi-sig, which must be the correct validators for that shard

Committed block headers at the beacon chain broadcasted to the whole network

Each shard will keep a chain of valid block headers for all other shards, used to check the validity of transactions from other shards

Adding the shard chains’ block headers into beacon chains serves two purposes:

  1. Increases the difficulty of attacking a single shard Attackers have to corrupt both the shard chain and beacon chain
  2. Reduce the network cost of broadcasting the block headers among shards O(N2)O(N^2) if each shard broadcast its headers separately O(N)O(N) with the beacon chain as a central relay
β€£

Blockchain State Sharding

Each shard chain contains its own account state and all the tokens in existence are spread among all the shard

An user account can have multiple balances at different shards

  • Can move balance between shards by issuing a cross-shard transaction

Smart contract account is limited to the specific shard where the contract was created

However, Dapps can instantiate multiple instances of the same smart contract in different shards and let each instance handle a subset of the incoming traffic

β€£

Networking

β€£

Incentive Model

β€£

Consensus Rewards

After a successful commitment of a block, a protocol-defined number of new tokens will be rewarded to all validators who signed the block in proportion to their voting shares (similar logic for transaction fees)

β€£

Stake Slashing

Certain amount of staked tokens will be slashed for any misbehaviors i.e. if a leader failed to finish the consensus process and triggered the leader change process, PvoteP_{vote} staked tokens will be slashed

If validators are proven to sign a dishonest block, all of their stake under the same shard will be slashed

β€£

Stake Withdrawal

β€£

Fork

Chain split that occurs when changes are made to the blockchain’s protocol

Soft Fork

  • Software upgrade to bring new features or functionalities
  • Changes are backward-compatible with the pre-fork blocks
  • End result is a single blockchain

Hard Fork

  • New version is no longer backward-compatible with earlier blocks
  • Chain splits in two: the og and the new
  • Creates an entirely new cryptocurrency