The Missing Tool to Cross-Chain Development and Interoperable Blockchains: the Chain Abstraction Layer

Liquality
Liquality
Published in
6 min readOct 3, 2018

--

The Chain Abstraction Layer is a flexible, modular library for developing disintermediated solutions across different blockchains.

Multi-chain Block Explorer

In recent years, there has been an increasing divide between communities in the cryptocurrency space. There are already large divides within the Bitcoin community, and increasingly so between different chains; “third generation” blockchain communities exacerbate the situation by claiming to push both camps into obsolescence.

Certainly there are intrinsic and extrinsic motivations for concentrating on specific chains, but in order for this experiment to succeed, the community as a whole must look ahead at the larger vision of disintermediation: the removal of middlemen. Yet, there does not seem to be a community focused on bridging and combining the efforts of these different ecosystems.

With the Chain Abstraction Layer, Liquality contributors hope to catalyze a new community — one that improves tools to empower developers to continue solving real problems across different blockchains through extending the paradigm of disintermediation.

The Difficulty in Building Cross-Chain

Lacking standards and unified providers for retrieving data and signing transactions across chains, developers are left at the mercy of their own workarounds to build useful solutions. Unfortunately, the difficulty in building across blockchains induces single chain myopia, due to the duplication of efforts in areas including:

  • Querying and broadcasting different chains’ data
  • Signing across different hardware wallet providers
  • Deploying nodes and JSON RPC interfaces

This has led to developers’ over-reliance on a limited number of services, reintroducing single points of failure.

The Chain Abstraction Layer

The Chain Abstraction Layer (CAL) is a flexible, modular library that currently allows developers to easily query and broadcast to multiple chains through a single interface. By normalizing data returned from the different chains, it simplifies the development process.

The Chain Abstraction Layer can be applied in a range of use cases, including:

  • Open Source Block Explorers
  • In-Browser Cross-Chain Interfaces for Software and Hardware Wallets
  • Multi-Token Payments for Decentralized Applications
  • Decentralized, Disintermediated Exchanges and Atomic Swaps

To understand how the CAL normalizes data obtained from both chains, observe how the call to getBlockByNumber functions on both Bitcoin and Ethereum.

Now that both chains have been setup, developers can run bitcoin.getBlockByNumber even though it is not natively supported by a JSON RPC call to Bitcoin Core. bitcoin.getBlockByNumber(1).then((result) => {console.log(result)}) outputs:

{
number: 1,
hash: '46b6...c350',
timestamp: 1526989363,
difficulty: '4.656542373906925e-10',
size: 262,
parentHash: '0f91...2206',
nonce: 0,
confirmations: 1562,
strippedsize: 226,
weight: 940,
version: 536870912,
versionHex: '20000000',
merkleroot: 'e12b...46e0',
tx: [ 'e12b...46e0' ],
time: 1526989363,
mediantime: 1526989363,
bits: '207fffff',
chainwork: '0000...0004',
previousblockhash: '0f91...2206',
nextblockhash: '0f65...5a1d',
height: 1,
transactions: [ 'e12b...46e0' ]
}

And as expected, developers can also run the exact same command on Ethereum where eth_getBlockByNumber is a built-in JSON RPC call. ethereum.getBlockByNumber(1).then((result) => {console.log(result)}) outputs:

{
number: '1',
hash: 'c7fd...2465',
timestamp: '5b8c7418',
difficulty: '0',
size: '03e8',
parentHash: 'b114...c0c0',
nonce: '0000000000000000',
mixHash: '1010...1010',
sha3Uncles: '1dcc...9347',
logsBloom: '0000...0000',
transactionsRoot: '56e8...b421',
stateRoot: '8cdd...6476',
receiptsRoot: '56e8...b421',
miner: '0000000000000000000000000000000000000000',
totalDifficulty: '0',
extraData: '00',
gasLimit: '6691b7',
gasUsed: '043bd6',
transactions: [ '2ac6...1dd2' ],
uncles: []
}

As you might have noticed from the outputs, the CAL has already taken care of some normalization. Some normalized fields include:

  • number
  • hash
  • timestamp
  • difficulty
  • size
  • parentHash
  • nonce

With the CAL, the process for retrieving block information from both Bitcoin and Ethereum has been greatly simplified.

Block Explorer Tutorial: The Chain Abstraction Layer Applied

Provided below are example workflows of developing a multi-chain block explorer with React, both without and with the Chain Abstraction Layer.

Without CAL

For this purpose of this tutorial, it is assumed that the developer has MetaMask installed, as well as an instance of bitcoind with regtest.

Using bitcoin-cli, developers can query the Bitcoin node by first calling getblockhash(blockNumber), then by calling getblock(blockHash):

bitcoin-cli getblockhash 2> 0f658f45d25e532aeeb75f84ecfae977cb71ae435890d4e26e6b58e168555a1dbitcoin-cli getblock 0f658f45d...8555a1d> {
"hash": "0f658f...555a1d",
"confirmations": 1662,
"strippedsize": 226,
"size": 262,
"weight": 940,
"height": 2,
"version": 536870912,
"versionHex": "20000000",
"merkleroot": "2cce42...5ad963",
"tx": [
"2cce42...5ad963"
],
"time": 1526989364,
"mediantime": 1526989363,
"nonce": 0,
"bits": "207fffff",
"difficulty": 4.656542373906925e-10,
"chainwork": "000000...000006",
"previousblockhash": "46b6ef...d0c350",
"nextblockhash": "5d3ccb...51595c"
}

Now onto Ethereum — using web3 provided by MetaMask, developers can query block data by calling web3.eth.getBlock(blockHashOrBlockNumber, callback), which will return the following data:

{
"number": 3,
"hash": "0xef95f2...e34b46",
"parentHash": "0x2302e1...af9c88",
"nonce": "0xfb6e1a62d119228b",
"sha3Uncles": "0x1dcc4d...d49347",
"logsBloom": "0x000000...000000",
"transactionsRoot": "0x3a1b03...415bee",
"stateRoot": "0xf11331...515bcb",
"miner": "0x8888f1f195afa192cfee860698584c030f4c9db1",
"difficulty": BigNumber,
"totalDifficulty": BigNumber,
"size": 616,
"extraData": "0x",
"gasLimit": 3141592,
"gasUsed": 21662,
"timestamp": 1429287689,
"transactions": [
"0x9fc764...836d8b"
],
"uncles": []
}

From the outputs above, it is clear that many of the values returned are similar, but not normalized. For example, it takes two calls to get block info on Bitcoin — to display the proper data, implementing this functionality into a multi-blockchain explorer would require multiple if statements for each subsequent chain, like so:

Though this if statement workaround may suffice for two chains, any subsequent chains would also require duplicate efforts of data normalization.

With CAL

Using the Chain Abstraction Layer, this process is simplified through the normalization of commonalities:

bitcoin.getBlockByNumber(1).then((result) => {console.log(result)})

{
hash: '46b6...c350',
size: 262,
nonce: 0,
difficulty: '4.656542373906925e-10',
number: 1,
timestamp: 1526989363,
parentHash: '0f91...2206',
transactions: [ 'e12b...46e0' ],
...
}

ethereum.getBlockByNumber(1).then((result) => {console.log(result)})

{
hash: '0xc7fd...2465',
number: '0x1',
parentHash: '0xb114...c0c0',
nonce: '0x0000000000000000',
difficulty: '0x0',
size: '0x03e8',
timestamp: undefined,
transactions: [ '0x2ac6...1dd2' ],
...
}

Through the CAL, the following common fields have been normalized in the outputs:

  • number
  • hash
  • timestamp
  • difficulty
  • size
  • parentHash
  • nonce

By including these common fields, developers can easily create a multi-blockchain explorer. Furthermore, the CAL enables easy integration of multiple providers, such as Ledger and MetaMask; here is a comparison between implementing a Ledger provider for Web3 vs CAL.

In the Web3 example, it is possible to setup both a signing and RPC Sub-provider using a Ledger Wallet Sub-provider, but requires some setup. Additionally, notice how all calls are RPC calls made directly to the node.

Using the CAL, providers can be easily added to a client, and calls to nodes are normalized cross-chain.

This allows developers to:

  • Switch providers easily
  • Remove code bloat
  • Call functions without specifying chains
  • Access personal nodes vs. use intermediated services

Empowering Cross-chain Decentralization & Disintermediation

A few weeks ago, $13.5 million in Ether was stolen from Bancor. But isn’t Bancor a decentralized exchange, meaning that it can’t be hacked? The truth is, Bancor may be built on top of a decentralized platform, but it is not disintermediated.

Line 6 of Bancor’s Converter contract shows that there is an owner for the entire contract.

This means that many function calls within the contract such as issuance, destruction, and disablement of transfer functions have a central point of failure — Bancor, the owner of the contract. Ironically, the same vulnerability that enabled the hack against Bancor contracts, also enabled the Bancor team to stop the bleeding by disabling the transfer of tokens.

Owned contracts like Bancor’s highlight vulnerabilities brought about by intermediation. If Bancor had designed the contracts without owners, kill switches, or admin privileges to enable free and open exchange, then Bancor would have never been hacked.

With the CAL, developers are free to use and extend disintermediated atomic swap functionality, which can empower users with just-in-time, peer-to-peer exchange, with no chance of a hack.

How to Move Forward

The Chain Abstraction Layer provides the missing piece of the puzzle for developers looking to create cross-chain solutions to address the pain-points of intermediation.

In the coming weeks, Liquality contributors will release a React UI component library to accompany the CAL, addressing everything from Address Input to Wallet Display.

Critical to reenabling the fundamental human right to transact, the necessary atomic swap components (like hash time locked contracts) can be found in the CAL, enabling developers to create disintermediated exchange functionality.

Ultimately, developers have the choice to either:

  • Address the painpoints brought about by trusted systems and enable peer-to-peer transactions by removing themselves out of the equation; or
  • Reincarnate intermediation and lose the benefits of consensus-based networks

The choice is yours.

If you’d like to try out the CAL and get involved with the free software project, explore the Liquality Github repo and Telegram channel.

The Matrix, 1999

--

--