Chain Interoperability in PolySwarm

Scalability & privacy enabled with sidechains and a custom Relay

Katherine Yan
PolySwarm
4 min readApr 11, 2019

--

As the blockchain world has grown immensely in size, and coin after coin started popping up in various parts of the world, a daunting question without a definitive answer loomed over the blockchain world: How do we move value from one chain to another?

In the world of fiat currency, exchange rates and methods for exchange have long been established and are used around the clock. Walk into almost any airport and you can swap your countries bills for that of another. In contrast, moving digital currencies from one chain to the next is cumbersome and far more complicated.

Today, blockchain interoperability is virtually non-existent. Moving value across chains is an often insecure process that poses a huge challenge to systems that need to provide cross-chain functionality.

In order to receive and distribute tokens across a variety of different chains, most systems use a centralized exchange scheme in which the user utilizes an in-house ledger to withdraw assets onto a new chain.

However, central exchanges are often slow, over-burdened, and become a single point of failure for the systems that use them.

At the expense of decentralization, these exchanges provide a slow and expensive way to transfer tokens across chains. Often rife with fees and sluggish processing speeds, this method provides a wholly inadequate way of getting your tokens from one chain to the next.

In contrast, PolySwarm has a unique way of relaying tokens between chains that provides the marketplace with increased throughput and decreased latency, without sacrificing the decentralized aspect of its design.

PolySwarm Communities

The PolySwarm marketplace is made up of public and private Communities, each of which acts as a hub for members who have expertise in a specific malware interest. In order to participate in a specific Community, users must maintain a balance of PolySwarm Nectar (NCT) in that Community.

However, NCT lives natively on the Ethereum Mainnet, which is far too slow (~15s block time) and far too expensive to support the sort of micro-transactions required by PolySwarm.

So, rather than transacting directly on the Ethereum Mainnet, PolySwarm participants instead relay NCT from the Mainnet to a given Community’s sidechain and conduct their business there.

To make this easy, PolySwarm created two helpers that work in unison:

  • Balance Manager
  • Relay Daemon

Balance Manager

The Balance Manager is the first step in the process to moving tokens to and from a Community sidechain. The Balance Manager is part of polyswarm-client and provides an interface for the user to withdraw, deposit, or simply maintain a constant balance of NCT in the Community. It can be conveniently spun up with Docker and provides several commands where the user can specify the amount of tokens to be moved, which operation to perform, and additional requirements needed to access the public or private sidechain, including an API-key, keyfile and password.

When prompted to carry out one of the three operations (withdraw, deposit, maintain), the Balance Manager enters an event loop that queries the current NCT balance and executes relay transactions as needed to accomplish the user’s request.

Once the Balance Manager confirms that there is enough tokens for the transfer, it calls a separate function to actually deposit or withdraw the specified amount. This function speaks with the Community’s Relay Daemon, which handles the transfer requests on behalf of the user’s Balance Manager.

Relay Daemon

While the Balance Manager provides an interface for the user to move tokens across chains, it isn’t the one responsible for NCT showing up on the sidechain.

Instead, behind the Balance Manager is a relay daemon constantly watching the ERC20Relay contract on the Ethereum Mainnet. The relay daemon has a WatchTransfers object, which watches for transfer events on the main chain.

When the user uses the Balance Manager to initiate a deposit of tokens onto the Mainnet, a Transfer object for that transaction is created.

The relay daemon then creates a new HandleTransfers object to process the Transfer.

Once the Token object itself is approved, the relay daemon automatically releases an equal amount of tokens from the contract to the user’s side-chain address.

In this way, users who use the Balance Manager to deposit or withdraw tokens from PolySwarm will eventually have their request fulfilled by the relay daemon.

Benefits

The split chain design that the PolySwarm marketplace is built off of provides two key advantages:

  1. Scalability. Today, Ethereum does not scale. With a maximum capacity of only 15 transactions per second, Ethereum’s network would never be able to handle the millions of small scale transactions that occur daily on the PolySwarm marketplace. PolySwarm’s split chain design allows for a much higher number of transactions to occur per second (higher throughput) and enables substantially greater scale than systems built directly on the Ethereum Mainnet (higher bandwidth / larger block sizes).
  2. Confidentiality PolySwarm supports the notion of limited-access, private Communities. The split-chain design makes that possible by shielding transactions that occur within a private Community from those outside of it. This public / private community design would be impossible to make performant on today’s Ethereum mainnet.

Calling all Malware Researchers!

Do you have a knack for reverse engineering JavaScript payloads in PDFs? Macros in Microsoft Office documents? Something else entirely? Monetize that dusty GitHub project and put your talents to work!

Get started at https://docs.polyswarm.io, chat with fellow Experts and PolySwarm developers on our official Discord channel and sign up for your account to track your micro-engine’s performance at https://polyswarm.network. See you on the market!

--

--

Katherine Yan
PolySwarm

software engineer. gamer. outdoors adventurist.