I Grew Up on a Piano Bench

When I was born in Deer Lodge, Montana my parents lived in a little town called “Opportunity.” We lived there for a year before moving to Deer Lodge. The name “Opportunity” sounds so positive and…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Chain Interoperability in PolySwarm

Scalability & privacy enabled with sidechains and a custom Relay

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.

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.

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:

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.

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.

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

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!

Add a comment

Related posts:

Have you heard of DaaS?

If you are here probably you are following my series on MEAN Stack Development. Even if you came across this article directly with no issues I will try to keep it really simple. We will stick to our…

Bit Project x Society of Women Engineers

Shout out to Society of Women Engineers at UC Davis for letting us join them in their annual outreach event, Project Aspire. We had so much fun interacting with the students, drawing out different…

Fads or Trends?

The following blog is about three random current fashion styles followed by A research-based analyzation on these products. In the world of fashion, styles always seem to be changing. We can…