Rainbow Bridge

Rainbow Bridge provides a permissionless, trustless bridge to Ethereum ecosystem.

Physical transfer of tokens isn't possible. Let's say DAI (an Ethereum-based coin). If you want to take DAI out of circulation on Ethereum and put it to NEAR, you need to make sure the global circulation doesn't change. This is how they do it:

  1. Tell Ethereum network to transfer DAI somewhere else.
  2. Ethereum network locks DAI in a vault using smart contract, so they're taken out of circulation.
  3. Once it's certain it's locked, tell NEAR to create an equal amount of DAI in new circulation.
  4. NEAR doesn't trust the request, so it asks for proof that it's locked on Ethereum.
  5. The proof is provided to NEAR.
  6. NEAR independently verifies the proof, then creates equivalent DAI to use on NEAR after successful verification.

The procedure is reversed to move DAI from NEAR to Ethereum.

Let's see how that happens with the help of Rainbow Bridge.

The Actors

Rainbow Bridge UI interacts with the user.

The LiteNode is like a blockchain node, except it only stores block headers, dramatically reducing storage space needed. They are smart contracts, one deployed on Ethereum network (storing NEAR Block Headers), and another deployed on NEAR network (storing Ethereum Block Headers). It's also called the "light client".

Relayers are scripts running on traditional servers that periodically read blocks from one blockchain, and communicate them to LiteNode running on the other, keeing LiteNodes up-to-date. Since this requires calculation, it charges gas fee. Each relayer update will update the LiteNode contract on NEAR, but Ethereum's update only every 12-16 hours (due to expensive gas fee).

Connectors are smart contracts responsible for all the logic associated with cross-chain management of a given asset type. They exist in pairs, one on Ethereum, another on NEAR. There is a pair of ETH Connectors responsible for transferring ETH between 2 networks. And another "ERC-20 Connector" pair responsible for transferring ERC-20 tokens. Any type of connector can be written by software writers, to bridge any transfer across the Rainbow Bridge, not just Ethereum and NEAR.

Rainbow Bridge underlying transfer

How does the Rainbow Bridge transfer? Let's say we have 20 DAI.

  1. Using Rainbow Bridge UI, start the transfer of 20 DAI.
  2. Confirm the first of two transaction in MetaMask, and Rainbow Bridge communicates with ERC-20 Connector on Ethereum, transferring and locking 20 DAI in its vault from circulation.
  3. Based on header data in our transaction block, the Rainbow Bridge UI calculates a cryptographic "proof" for locking DAI.
  4. Wait for Relayer to send about 20 Ethereum block headers to LiteNode running on NEAR. This is for security purposes, the same way your crypto exchange makes you wait for confirmations before using deposited funds.
  5. Then, Rainbow Bridge UI takes us to step 2: asking ERC-20 Connector on NEAR to create 20 new DAI for us on NEAR network.
  6. We provide the cryptographic proof generated earlier upon request.
  7. The ERC-20 Connector on NEAR then lookup our Ethereum block header in LiteNode running on NEAR, and make its own independent calculation of cryptographic proof.
  8. If provided proof matches the proof calculated, we know 20 DAI is safely locked away on Etereum, and it's the correct person locking it up, hence we proceed to create (mint) 20 new DAI on NEAR and delivers them to their wallet.

For transferring back, DAI on NEAR are burned (process called "burning"), providing proof of burning to Connector on Ethereum. This will release DAI from vault and sends to our wallet.

Other information

  • There is a delay moving tokens from NEAR to Ethereum, as the LiteNode only performs calculation once every 12-16 hours. Approaches on reducing the delay are proposed.
  • For storage space reason, LiteNode "prunes" (deletes) blocks on NEAR older than 2 weeks. If you transfer Ethereum to NEAR and in between wait for 2 weeks (between step 1 and step 2), you won't be able to complete your transfer, as proof is deleted.
  • NEAR block header design allows computing the history of past blocks for quite a long period, with a single block header. So in theory, the LiteNode on Ethereum only needs a single NEAR block. However, we don't do that as computation on Ethereum is super expensive. Gas costs to perform pruning is a waste of resources.
  • Aurora (we'll speak more about this later) and Rainbow Bridge are created by the same team.
  • Aurora team is working on "auto-finalization" for Rainbow Bridge, so you no longer need to manually initialize step 2 of these transfers. Hence, if you leave for 2 weeks, your transfer proceeds automatically without your intervention.
  • Aurora Bridge has the same concept as Rainbow Bridge.
  • UI and UX of Aurora Bridge differs from Rainbow Bridge UI.

References

  • https://learnnear.club/how-the-near-rainbow-bridge-works/