The NEAR-Calimero Bridge

The NEAR-Calimero Bridge

A Deep-Dive into the NEAR to Calimero Bridge (Ref: NEARCON 2K22)

What is the NEAR Protocol?

NEAR Protocol is a public Proof-of-Stake (PoS) blockchain that aims to bring DeFi to the masses with low transfer fees and fast transactions. The concept of sharding is central to NEAR Protocol’s design, which seeks to divide the network’s infrastructure into several segments, for which the nodes only have to handle a fragment of the network transactions.

Sharding creates a more efficient way to retrieve network data and scale the platform by distributing the segments rather than the complete blockchain across network participants.

What is the Calimero Network?

Calimero is a customizable sidechain that is built upon leveraging the NEAR protocol and provides private sharding. Secure private shard infrastructure lets you protect your data while leveraging open-source blockchains' business benefits like being high-performant, incredibly secure, fast, and having infinite scalability, all while supporting sustainability.

It provides fully interoperable cross-contract calls, allows interaction with other private shards over encrypted channels, gives you holding power for public assets, and bridges your Fungible and Non-Fungible Tokens to and from a private shard.

Let's dive: The NEAR to Calimero Bridge

A High-Level Architecture Diagram

calimero-bridge.jpg

Components of the Bridge

Relayer

The relayer receives blocks from a source chain and sends those blocks to a light client contract on the destination chain, establishing a bidirectional bridge between the chains.

Light Client Contract

Calimero on NEAR Client and NEAR on Calimero Client are implementations of the NEAR light client as a contract. The light client contract accepts all the block headers being relayed to it if the blocks meet specific validation criteria.

Prover Contract

The Prover contract can prove everything that happened on a specific chain. The Prover Contract takes the proof data that contains a Merkle path to the block where the transaction originated and a Merkle path to the transaction.

Connectors

The prover contract enables us to build a set of contracts for transferring assets from one chain to another. Calimero supports transferring Fungible and Non-Fungible tokens from one chain to another. There are three types of connectors, viz.:-

The Fungible Token Connectors

The user only needs to trigger the ft_transfer_call when locking Fungible-Tokens on a chain. The bridge service will automatically bridge the token from NEAR to Calimero(When the original token is NEAR). If the original asset is on Calimero, it was the first time minted on Calimero; it never existed on NEAR. This means bridging NEAR would bring a wrapped Fungible Token on NEAR. Similarly, when someone wants to unlock the funds or burn the tokens, they need to make a withdrawal call on the FT contract. The bridge service will automatically update the components.

The Non-Fungible Token Connectors

The Non-Fungible Connectors work precisely similarly to Fungible Token Connectors, except that the user here needs to trigger the nft_transfer_Call for locking the Non-Fungible Tokens.

Cross Shard Contract Call Connector

Cross Shard calls can be executed with a callback using the Calimero Bridge. This essentially means that a contract on Calimero Network can call into contracts on NEAR and get a callback, and the contracts on NEAR can call into Calimero contracts and get a callback.

Where the magic happens: The Bridge Service

The activity workflow

bridge-service.jpg

Using the Bridge Service, the user or an application can instantiate cross-shard calls, i.e., token transfers can be initiated through the Bridge.

Let's take a scenario where you want to transfer some 'X' fungible tokens from one chain to another. To be more precise, let's say the user wants to transfer these tokens from NEAR to Calimero's private shard. The following are the state of actions that happen:-

  1. A Lock method is called on the FT contract on the NEAR mainnet
  2. Once the transaction is completed on the blockchain, the Bridge through the message queue learns that an event has occurred.
  3. The Bridge then makes an RPC call to an archival node on the NEAR mainnet to get the proof of this particular transaction
  4. Before the Bridge service occurs, even the NEAR to Calimero relayer gets notified about this event through the message queue and relays the latest block from NEAR to the light client contract on the Calimero shard.
  5. The mint method from the FT contract on the Calimero shard is called. Proof that NEAR tokens are indeed locked on the mainnet is also supplied.
  6. Now, the prover contract can check the proof by comparing the expected block Merkle root from the light client contract that was supplied with valid block headers from NEAR mainnet
  7. If both the hashes match, wrapped NEAR will be minted onto the Calimero Shard.

Feel free to visit the following resources

Did you find this article valuable?

Support Parth Arora by becoming a sponsor. Any amount is appreciated!