Deep Dive into Gateway’s Architecture

As discussed earlier, Wormhole Gateway is a Cosmos-SDK chain for bridging external assets into the Cosmos ecosystem and ensuring unified liquidity across Cosmos chains. However, how does it accomplish this feat? What's the underlying architecture? And, most importantly, is it secure and user-friendly?

In this guide, we'll explore the inner workings of Wormhole Gateway, shedding light on what's happening under the hood. This will answer the common questions that curious minds may have while delving into its usage.

The aim is to boost confidence by educating and increasing awareness about Gateway's inner workings, enabling everyone to experiment with it and expand cross-chain possibilities.

Architecture

Wormhole Gateway comprises several components. However, let's get to know the major ones and how they work together.

Largely, we can say Wormhole Gateway is built using these three components:

  • Cosmos SDK: An SDK that is equipped with several modules and a simple framework for development of custom Chain logic, basically it simplifies blockchain development.

  • IBC Module: Module that simplifies connections with the rest of the Cosmos ecosystem via IBC

  • Proof-of-Authority-Valset: Wormhole’s 19 Guardians which also acts as Gateway’s Validators.

Further, Wormhole Gateway is structured through a set of contracts and modules. Specifically, under the hood, Gateway consists of three Wormhole’s Cosmwasm Smart Contracts and three IBC Middlewares.

The contracts are:

  • The Wormhole Core Bridge: Handles everything related to Wormhole functionality that involves maintaining the current guardian set to publishing and verifying messages.

  • The Wormhole Token Bridge: The Token Bridge contract allows token transfers between blockchains through a lock and mint mechanism, however as a Cosmwasm Smart Contract it does burning and minting of CW20 tokens.

  • IBC Translator Contract: The IBC Translator contract handles the job of translating Wormhole Token Bridge messages into ICS-20 messages and vice versa

Here, is the logical flow of the token transfer:

  • Token Transfer into Cosmos Ecosystem:

    • Redeem the VAA from the Token Bridge to initiate the lock and mint process for token transfer.

    • Mint tokens using Token Factory (a Custom Token-Creation Module)

    • Decode the added information, known as GatewayIbcTokenBridgePayload, which provides essential details for the Gateway to carry out the transfer.

    • Send tokens via IBC to destination cosmos chain.

  • Token Transfer out of Cosmos Ecosystem:

    • Burn the Token Factory tokens.

    • Unlock the CW20 tokens.

    • Give approval to the Token Bridge to utilize the CW20 tokens.

    • Call InitiateTransfer or InitiateTransferWithPayload based on whether the GatewayIbcTokenBridgePayload is of type Simple or ContractControlled..

The 3 IBC Middlewares are:

  • Strangelove’s Packet Forward Middleware: The packet-forward-middleware is an IBC middleware module designed for Cosmos blockchains that make use of the IBC protocol. It allows a chain, incorporating this middleware, to route incoming IBC packets from one chain to another. Simply in Gateway, it facilitates Cosmos-to-Cosmos transfers.

  • Osmosis’ IBC Hooks: The IBC Hooks middleware is employed for transfers from Cosmos to external chains. The wasm hook, an IBC middleware, enables ICS-20 token transfers to initiate contract calls, allowing contracts to interact across different chains while moving tokens. This versatile functionality has various applications, with cross-chain swaps being notably powerful.

  • IBC Composability Middleware: The newly developed IBC Composability middleware by Wormhole enhances the developer experience. It offers Gateway integrators a single message format for memos, which is then directed to either the Packet Forward Middleware (PFM) or the IBC Hooks middleware, depending on the destination chain.

Gateway streamlines access for any Cosmos chain to Wormhole's network of 23+ connected blockchains using just one simple IBC connection.

When an entity bridges a token from Wormhole's connected blockchains to a Cosmos SDK chain through Gateway, the token is locked in a wormhole contract on the source chain. It is then minted as an ICS-20 compatible asset on the Gateway chain, triggered by a VAA message via a relayer. This asset is further locked in Gateway's IBC module and subsequently minted on the destination chain through IBC messages. The resulting ICS-20 asset becomes fungible via Strangelove's packet forward middleware. Additionally, Gateway efficiently utilizes IBC Hooks for seamless integration with CosmWasm contracts.

For Wormhole xAssets transfers between Cosmos chains, the process involves IBC messages from the source chain to Gateway and forwarding from Gateway to the destination Cosmos chain.