Heimdall — Vaibhav Chellani — The all — seeing & all — hearing protector of Matic!

Credits: Pepakura Helmet Heimdall by GimpeeIndustries

Matic Network has a three-layered security architecture in which there are the following entities involved:

1) Block Producers -aka BOR chain: These are involved in batching transactions in blocks to ensure faster confirmation times

2) Validator Layer — aka Heimdall: These are validator nodes that batch the blocks produced by the block producers and push them to the Ethereum

3) Network Watchers -They are actors on the Ethereum, and use fraud proofs to challenge any transaction that they deem fraudulent on the sidechains.

Matic Network -Simplified Architecture Diagram

For better context on Matic’s architecture please refer to the article:What is Matic Network?
Matic Network provides scalable, secure and instant Ethereum transactions using side chains
Get set to deep-dive into Heimdall!

Heimdall is a large group of validator nodes that serve as a bridge to connect the Ethereum chain and Bor. Anyone can become a validator and run a validator node on Matic chain by staking on Ethereum chain.

Responsibilities of validators under Heimdall include the following:

  1. Verifying transactions in the blocks produced by block producer nodes
  2. Creating the Merkle root of 256 or more blocks
  3. Reaching consensus among validators and pushing the Merkle root to the Ethereum
  4. Communicating with other validator nodes and reaching consensus on the set of blocks to be included in a checkpoint
  5. All validators on receiving a checkpoint, verify it querying their block producer nodes if the Merkle root in a checkpoint matches with the Merkle root they produced for the same set of blocks
  6. Pushing a checkpoint to the mainchain after it has been validated by 2/3rd majority of validators on Heimdall

This is what a checkpoint looks like ?

Heimdall chain makes sure that block producer nodes don’t commit any sort of fraud, hence they don’t trust any information they receive from Bor. Heimdall relies only on Ethereum as a source of truth, for everything ranging from incoming new validators, exiting validators, to reward distribution to validators, etc happens on the Ethereum chain. After a validator related action is performed on smart-contract, the validator can submit a validatorJoin or validatorExit or validatorUpdate transaction on Heimdall. All validators query the smart-contract that manages the validators and validates transactions on Heimdall.

Here are some of the problems we have faced while designing the validator node:

  1. Ethereum and Heimdall are friends for sure, but they don’t share `states` with each other, hence sharing information between these two disjointed chains is difficult.
  2. Ethereum stores all information about who Heimdall has appointed as validators, but has no idea which validator will decide the proposer for the next checkpoint.
  3. Validators on Heimdall need to prove that they have agreed on a checkpoint by signing on it. The signatures would be checked on-chain, Tendermint usesed25519curve like bitcoin whereas Ethereum uses secp256k1so a change of signature scheme on Tendermint chain had to be performed to make it Ethereum compatible.
  4. Data on smart contract changes as validators enter, exit, and new state changes occur. How is a newly synced node supposed to validate transactions which involve interaction with another chain in such cases?

Maintaining sync between Ethereum and Heimdall is hard, but not impossible. In the course of development, we came up with several approaches to solve these issues. It took us many iterations on the drawing board to make this work elegantly.

Here is how sending a checkpoint via Heimdall works right now:

  1. Proposer selected from the validator pool creates a checkpoint by calculating the Merkle root of 256 blocks or more while verifying transactions inside the blocks.
  2. A proposer proposes a checkpoint to all the validators. The checkpoint contains meta information about it so that all other validators can validate it.
  3. All validators on receiving a checkpoint checks if the Merkle root for the given blocks matches with what they have.
  4. If the checkpoint is correct, the validators using the Tendermint consensus engine gossip votes to each other.
  5. Once the checkpoint receives votes from 2/3+ of all validators, the checkpoint is queued on Heimdall to be sent to the Ethereum.
  6. This is when the proposer picks up the votes and submits them on the Ethereum proving to the smart contract that the checkpoint has achieved consensus on Heimdall.
  7. The smart contract on Ethereum chain maintains a record of how many checkpoints have been received and by whom were they submitted and other essential data.
  8. Once the transaction on Ethereum is successful the proposer sends another transaction on Heimdall called ACK ; which contains the checkpoint number which has been assigned to the checkpoint by the smart contract to all the validators that the checkpoint transaction has been accepted by Ethereum.
  9. Everyone is such a skeptic on Heimdall that they themselves check with Ethereum whether the checkpoint was right or not and only then process the transaction. It follows the adage — “Don’t trust. Verify” to the boot.
  10. And finally, a checkpoint is confirmed on Heimdall ?

But but but… What if a proposer doesn’t submit a checkpoint? ?

11. After a certain interval, the next validators in line send a NoAck transaction to all validators, signaling that a checkpoint hasn't been submitted to the smart contract in a long time and they want to send a checkpoint.

12. Heimdall checks if this is true and allows the next proposer in line to restart the process ?

This two-phase checkpointing allows us to easily keep both the chains in sync and helps us punish proposers who did not submit checkpoint and reward good validators.

We hope this post gave you an overview of how the Validator layer interacts with Ethereum. We will be continuing this series to give you a deeper insight into Heimdall.

May Heimdall reign long!

More from the Polygon Blog
Green Blockchain Summit 2.0: Agenda at a Glance 

Ethereum’s shift to Proof of Stake consensus, known as the Merge, has dramatically cut Polygon’s carbon dioxide emissions, opening the path to going beyond being carbon negative and toward empowering others to do the same. The conversation has shifted from blockchain sustainability to blockchain as a sustainability solution.  Join us for the second chapter of […]

Read More
Robinhood Selects Polygon to Launch Web3 Wallet Beta

Today, we are thrilled to announce that Robinhood has chosen Polygon as the first blockchain network to support its newly launched Web3 wallet. The Robinhood Wallet beta is now live for 10,000 iOS customers out of 1+ million who signed up for the waitlist in May. Together, Polygon and Robinhood are opening access to decentralized […]

Read More
What Is a zkEVM?

Zero-knowledge (ZK) tech is one of the most prominent and promising paths to scaling Ethereum. One popular use of ZK proofs to scale Ethereum is what’s known as a zkEVM (zero-knowledge Ethereum Virtual Machine). So what is a zkEVM, and how does it help us make Ethereum cheaper and more efficient to use? Understanding the […]

Read More
Polygon-Powered Icetea Labs Accelerator Launches With 6 Startups

Polygon has teamed up with Alpha Venture DAO and Icetea Labs to launch the inaugural Icetea Labs Accelerator Program for blockchain startups.  Working in a tight three-way partnership, Polygon is co-creating an accelerator to funnel resources, mentorship, education, and business acumen to promising Web3 companies from around the world. The startups selected for the accelerator […]

Read More
Apply to Polygon Bootcamp Africa and Kickstart Your Web3 Developer Journey

Applications are open for Polygon Bootcamp Africa, launched in partnership with Xend Finance! The eight-week intensive educational course and hackathon combo will put developers in Africa on the Web3 map.  This is Polygon’s biggest step in providing resources to developers, builders, and creators in Africa, and it comes during an important time.  An internet and […]

Read More
Starbucks Taps Polygon for Its 'Starbucks® Odyssey' Web3 Experience 

Today, we are thrilled to announce that Starbucks Coffee Company is working with Polygon to provide the blockchain technology to build its recently announced Web3 experience, Starbucks Odyssey. As a result of the partnership, this new Web3-powered experience will allow Starbucks Rewards loyalty program members and Starbucks partners (employees) in the United States to earn […]

Read More
PolygonInsights - WEEK39

Hola readers! We announced Polygon Bootcamp Africa, an eight-week intensive educational course and hackathon combo, in partnership with Xend Finance, Polygon-based carbon compensation project Coorest has become the first Web3 initiative to have an officially verified carbon standard, and Quadrata, a passport network bringing the identity and compliance layer to public blockchains, is integrating its […]

Read More
From UDC 2022 to Token 2049: A Week for the Devs in APAC

For Web3 developers in Asia, this week was absolutely packed with must-see events. Polygon was there, showing love for the devs in South Korea and Singapore. Here is a rundown of our devrel outreach. Upbit Developers Conference 2022 Some of the best known blockchain developers in Korea and beyond gathered at this year's Upbit Developer […]

Read More
Polygon-Powered Coorest Earns Web3’s First Certified Carbon Standard 

Polygon-based carbon compensation project Coorest has become the first Web3 initiative to have an officially verified carbon standard. The Coorest Carbon Standard (CCS) is certified by an official UN auditor and is a new benchmark for CO2 compensation that leverages distributed ledger technology to eliminate unfair and opaque carbon offset practices. In partnership with Polygon, […]

Read More
crossmenuchevron-down-circle