HOPR on Polkadot

Robert Kiel
validitylabs
Published in
3 min readMar 25, 2020

In August 2019, we received a grant from Web3 Foundation to implement an integration for Polkadot into HOPR and create an API that encapsulates the chain-specific functionality in HOPR.

What is HOPR?

HOPR is a decentralised network that allows privacy-preserving data-exchange between its participants and compensates its participants for their services.

Our talk at EthCC3

Structure of HOPR and its transformation

HOPR is by design open and inclusive and this includes as well the choice of the chain that it uses to process its incentives.

Following these principles, the whole protocol is designed to be as chain-agnostic as possible which allows us in theory to have integrations for multiple chains that meet these requirements stated here. These requirements are kept intentionally as low as possible can be easily fulfilled by Ethereum as well Substrate-based chains.

We started the process with a PoC of our reference HOPR client that was tightly coupled with the Ethereum ecosystem and a few Ethereum-specific idioms inside the transformation of packets.

Architecture before the transformation

After a first draft of the API and a specification about the further proceedings, we started to move piece by piece of the chain interactions from the core into a separate module and noticed that there were a few modules that expected an Ethereum-specific behaviour of the underlying chain and made it necessary to reimplement them in a more chain-agnostic way.

Architecture after the transformation

On the other hand, we have the Polkadot API, which introduces itself a few Polkadot-specific patterns into our ecosystem and did not make things easier for us as this added the additional requirement to think of an API that fits to both, Ethereum and Polkadot.

As this came along with a bunch of slight changes that broke the functionality of various modules in our client, we decided to migrate the code from Javascript to Typescript in order to let Typescript automatically check for interfaces that became incompatible to each other. This made our lives a lot easier and discovered a few errors that were not known to us before.

Apart from that, we also noticed that the rest of the ecosystem that we rely on, namely libp2p made some progress, so we decided to catch up with their newest improvements and take advantage of their new stream implementation and their migration from callbacks to Promises. While doing so, we also migrated our own code from Node.js Buffers to Javascript’s TypedArrays that led to better browser-compatibility and allowed us to spread the zero-copy pattern into more modules.

Implementation of the on-chain logic

The integration of Polkadot also came along with necessity to get in touch with the programming language Rust and understand its advances features such as complex traits and macros that allow a dialect of Rust that deviates from the reference implementation.

Despite the high friction when starting with Rust and Substrate at the same time, programming with Rust leads to an improved way of implementing functionality and allowed us to detect a few issues in the rest of our code and brings us closer …

Towards a decentralised future with HOPR

The result of transformation process is now a client with less errors and a significantly improved toolchain that allows us to grow it for our upcoming mainnet release.

Last but not least, we thank Web3 Foundation for their grant and look forward to the release of Polkadot!

--

--