Terabethia: Bridging Contracts & Assets Across Ethereum and the Internet Computer 🌉

Terabethia is a bridge between Ethereum and the Internet Computer that allows contracts on both chains to message each other, as well as mirror & use any Ethereum asset on the IC.

Terabethia
Terabethia
11 min readDec 3, 2021

--

Today we’re super excited to reveal Terabethia, which is one of, if not the most important project currently being worked on at Psychedelic.

Terabethia is a bridge between Ethereum and the Internet Computer, built on a forked version of StarkWare’s messaging protocol & contracts, that will allow contracts on either network to communicate with each other, as well as allow assets to hop back and forth between the two networks!

Important: We are sharing an early look at Terabethia’s repository, but it does not reference the final or upcoming test-net implementation. Don’t consider the repository as a stable or complete release yet. We will further document, polish, and add-in key pieces to the Magic Proxy, the bridge, and more soon.

Terabethia will play an extremely complementary role with the upcoming native IC/Ethereum integration (expected to go live in 2022), by helping mirror and move assets from Ethereum to the Internet Computer so that Ethereum projects and assets can benefit from the L2-like benefits the IC can provide (low fees, transaction speed, etc.).

As well as additional capabilities that are unique to the IC (compared to other L2’s) such as enhanced compute/storage capabilities, hosting/serving front ends directly from smart contracts, native IC/ETH integration, among others.

Similar to the way Ethereum significantly extended the functionality, usefulness, and value of BTC, we think the IC has potential to do the same for Ethereum assets and applications, and could even potentially become the best L2 for Ethereum long term if/when certain things were to happen (ex. EVM equivalence on the IC, which we are working hard with the Foundation to make a reality).

Terabethia will help kick start that vision with its Magic Proxy & Token Factory, two key aspects of the Terabethia bridge protocol that will allow anyone to deposit any ERC20, ERC721, or ERC 1155 token on Ethereum (starting with ERC20 and adding the others soon after), and get a mirrored balance of that token or NFT on the Internet Computer by programmatically spawning a canister for that asset using the equivalent token standards that we’ve created for the IC: DIP20, DIP721, & DIP1155 (coming soon).

This enables seamless and automatic bridging of assets from Ethereum to the Internet Computer without needing to modify or rewrite any contracts or code! (keep reading for more details on how exactly this works)

Terabethia is currently in development and close to releasing an open testnet (but the great news is we’ve already got it working internally).

The Bridge & Messaging Protocol 🛰️

Terabethia at its core is a messaging protocol. As the architecture above shows, it has contracts on both chains (IC & Ethereum) and an intermediary State Sync infrastructure that acts as the bridge between both contracts, relaying messages & events from the IC to Ethereum, and the other way around.

As seen in the graphic above, Terabethia’s architecture is composed of the following pieces:

  • Terabethia (Ethereum): One end of the bridge, the protocol’s contract on Ethereum.
  • Terabethia (IC): The other end of the bridge. The protocol’s contract on the IC.
  • State Sync Infrastructure: An AWS/lambda (for now) infra to send messages Ethereum<->IC.*
  • The Magic Proxies: Contracts for the Ethereum asset mirroring protocol.
  • Token Factory: Service in charge of deploying mirrored token contracts on the IC.

* The State Sync Infrastructure will be removed from AWS once the native IC/Ethereum integration goes live (at which point this piece can be built in a canister on the IC). However starting with this piece being centralized is common practice for many bridges.

Both Terabethia contracts, on Ethereum and the IC, are in charge of receiving messages from other contracts on their respective chains, and relaying them to a destination contract on the opposite network using the State Sync infrastructure. The Ethereum part of the bridge is built using a forked version of StarkWare’s contract, while the IC-side is our own implementation.

It’ll be as easy as using the method sendMessage to send messages from one chain to the ohter; and the method consumeMessage to actively consume and receive a message as the recipient.

When going from IC to ETH, this won’t directly execute contract calls on Ethereum (yet, although the Native IC/ETH integration might enable this). Terabethia will only update the Etherum Contract state with message hashes (32 bytes per message, gas efficient). Messages from the IC need to be manually consumed, eg. the user decides to burn wETH on the IC and then she needs to explicitly call withdraw on Ethereum.

The State Sync AWS infrastructure is in charge of logging, storing, and relaying messages (or events) between Ethereum and the IC, delivering the payload to a receiving contract. Messages are compressed using a hash function, therefore it’s a very small amount of data that needs to be synced & written to contracts.

Why use StarkWare to build Terabethia? 💠

Not only has StarkWare proven to be a trustworthy and thought leader when it comes to L2 solutions (with StarkNet); but double-clicking onto the specific messaging protocol they created to communicate contracts across L1<>L2 is nothing short of amazing.

The main piece we decided to reuse is StarknetMessaging.sol. It uses an efficient design for storing messages, especially when it comes to sending updates back to L1, because it only requires writing a light message hash (32 bytes). This message can be later consumed by a contract that provides input data that can be compressed to matching hash.

With that contract as a solid base-layer, we modified and reduced any unnecessary pieces that created overhead for us and were not needed for our specific use-cases (fact registry, merkle roots, etc.).

How Would You Use Terabethia as a Developer? 🧠

Let’s say you want to use Terabethia to create two contracts that communicate with each other across the IC and Ethereum. First, you need a use case, something you want to achieve:

For example, creating Wrapped Ethereum on the Internet Computer, where a user locks ETH on a contract on Ethereum, and receives a 1:1 balance of WETH on the IC.

You would need to build three pieces: a token contract canister for WETH on the Internet Computer), and two proxy contracts: One proxy contract on Ethereum that can receive ETH, lock it, and talk to Terabethia’s Bridge contract to send a mint message to the 2nd proxy contract on the IC, assigning a balance to a destination address. That proxy will be in charge of sending the received mint order to the WETH Token contract on the Internet Computer.

That is the core architecture any service needs to use the bridge (two contracts on each side of the chain built specifically to interact with Terabethia and each other).

But… if we want to mirror and bring all ERC20, ERC721, and ERC1155 tokens to the IC, that’s a lot of work, right?

Well, not if you use a little magic.

The Terabethia Magic Proxy & Token Factory for Wrapped Ethereum Assets 🧙‍♂️

We’re building the Terabethia Magic Proxy. A key service of the Terabethia bridge protocol for mirroring & automagically sending ANY ERC20 tokens to the IC and back (and soon, any ERC721, or ERC1155!).

One of the magic pieces is that it includes a built-in wrapped token factory on the Internet Computer that’s in charge of deploying the mirrored ERC20 contracts to the IC using equivalent standards we’ve developed: DIP20, DIP, 721, & DIP1155 (coming soon).

There are two magic proxy contracts, one on Ethereum and another on the Internet Computer that can communicate with each other through Terabethia.

They will automatically allow anyone to send ERC20 tokens (and soon ERC721 & ERC1155) to the IC and benefit from its L2-like benefits (low fees, fast transactions, etc.) and other unique features (enhanced compute/storage capabilities, hosting/serving front ends directly from smart contracts, native IC/ETH integration, etc.) without needing to modify or rewrite any contracts or code, or frankly needing to do anything at all!

How will the user experience be? 🤔

Just like any other bridge you know and use today:

1) Users deposit any ERC20, ERC721 or ERC1155 token or NFT to the Bridge’s Magic Proxy on Ethereum (ex. using Terabethia bridge UI).

2) The token is locked on the Magic Proxy contract and a mint request to the IC is requested.

3) The Ethereum Magic Proxy messages the Magic Proxy on the IC) through Terabethia.

4) The Magic Proxy on the IC checks if a wrapped version of that token or NFT already exists on the IC (meaning has that asset been bridged to the IC using Terabethia before or is this the first time).

5) If it does exist, the Magic Proxy tells the existing canister corresponding to the wrapped version of that asset to mint the specified amount (1 WDoge!)

6) If it doesn’t exist on the IC yet, it will tell the Token Factory to deploy a new DIP20 (or DIP721 or DIP1155) canister for the wrapped token, and mint the balance for the user automatically.

7) If the user wants to go back to ETH, it can always burn the wrapped tokens on the IC by returning them to the Magic Proxy, and unlocking their assets back on Ethereum.

The Magic Proxy & Token Factory Handle it All

No need to deploy that ERC20’s mirrored token contract on the IC ♾️ The Magic Proxy is seamlessly integrated with the Token Factory, and if a wrapped contract for that Ethereum asset wasn’t deployed already on the Internet computer, it will auto-deploy one.

And no need for anyone to deploy proxy contracts for EACH token 📡 Why? Because it’s a magic proxy, that’s why! It acts as a universal proxy for any ERC20, ERC721 or ERC1155 token. It can receive any asset deposit, lock it, and relay a mint message to the IC so the user or destination address receives an equivalent amount of that asset wrapped on the Internet Computer, the same way it works with other L2’s.

A protocol for seamless/on-demand access to Ethereum assets on the IC.

What’s more, Terabethia’s Token Factory will be natively integrated to CAP, DAB, and Cover. That means all mirrored ERC20, ERC721, & ERC1155 token contracts deployed on the IC (into DIP20, DIP721, & DIP1155 contract equivalents) will have built-in transaction histories, they will be auto-surfaced in DAB’s token & NFT registries so they surface in all wallets & UI’s that support DAB.

As for the Cover integration, these token contracts will have their code verified from the get-go in Cover so you can verify that the canister code for the mirrored assets on the IC exactly matches the original Ethereum contract for that asset, and that no malicious code exists.

Coming With a UI & dApp to Accompany the Protocol ⭐

Not only you’ll be able to deposit directly to the Magic Proxy contract’s address to move your Ethereum assets to the Internet Computer…

We will build a Terabethia UI/App so anyone can access this service through their browser. It will be as simple as setting the destination address on the IC, choosing the Ethereum asset you’ll want to mint/send to the IC, and done!

Terabethia, and the proxies, will work their magic and bring your Ethereum assets to the Internet Computer. Then it’ll just be a matter of having the receiver claim their tokens!

Why Build Terabethia & the Magic Proxy?

Why build Terabethia and the Magic Proxy, even with the upcoming native IC Ethereum integration? While that native integration is a great move, it will only allow canisters to hold Ethereum assets on Ethereum and make calls to them, it won’t actually enable Ethereum assets to exist on the IC.

To start unlocking all the L2-like benefits the Internet Computer has to offer , there is still a need for a bridge that allows mirroring Ethereum assets onto the Internet Computer to have them start benefiting from the unique benefits and enhanced capabilities the IC has compared to other L2’s.

Terabethia will enable that, and many other cross-chain use cases by allowing contracts across these chains to communicate and send events/messages to each other. The Magic Proxy is just one example of that. Anyone can build their own use-cases on top of the bridge. For example in the future we can enable other cool use cases like allowing a DAO on Ethereum to own and control canisters on the IC.

The Road to L2 Competitivity 🤝

All things considered, it’s still important to note that this road towards the IC providing competitive L2-like benefits for Ethereum is long, and many steps need to be taken.

Being EVM equivalent is the biggest one, and as mentioned we are actively working with the Dfinity Foundation to make that happen. We are also researching how the IC canoffer new types of rollups that leverage the IC’s unique characteristics, such as the IC’s native security, provided by its deterministic computation & threshold cryptography.

Our Next Steps 🗺️

A lot to tell still! We’ll be sharing more updates in the upcoming weeks as we get closer to releasing the testnet version of Terabethia so that developers can start building on top of Terabethia and the Magic Proxy/Token Factory.

At the moment, our next goals down the line are:

  1. Releasing the testnet version of Terabethia
  2. Releasing Wrapped Ethereum on the Internet Computer as an example build.
  3. Releasing the Magic Proxy & Token Factory to first enable any ERC20 token to be bridged to the IC
  4. Adding ERC721 & ERC1155 support to the Magic Proxy & Token Factory to enable any NFT to be bridged to the IC
  5. Turn Terabethia into an open internet service / community-owned DAO.

Terabethia as a Fully Trustless Open Internet Service 🌎

As with most other projects in Psychedelic, once suitable DAO frameworks start emerging in the IC ecosystem (one such framework Psychedelic might decide to create), we will turn Terabethia into an open internet service.

Once that happens, Terabethia would be a fully community owned & governed bridge protocol, controlled by a DAO and token holders. One unique and super cool aspect of how Terabethia will work as an open internet service is that thanks to the bridge itself and the upcoming native IC-Ethereum integration, the entire Terabethia protocol (including contracts on both the IC & Ethereum), will all be controlled by a single Terabethia DAO/set of token holders.

Stay tuned to our socials and find us on the Psychedelic Discord to follow the development of the bridge! If you’ve got feedback, we’ll be happy to hear it.

--

--

Terabethia
Terabethia

Terabethia is an Ethereum & Internet Computer bridge that allows IC<>Ethereum contracts to communicate, and assets to be seamlessly bridged across both chains.