This Is Hydranet

Lithium protocol

Hydranet’s off-chain network for smart contract-based blockchains

Lithium is Hydranet’s proprietary off-chain protocol for EVM and smart contract-based blockchains. Similar to the Lightning Network, it’s a solution for sending and receiving payments outside the blockchain using state channels. 

Lithium holds all the benefits of off-chain transactions:

  • No network fees 
  • Instant transaction confirmations
  • Trustless solution

Lithium furthermore bring the following capabilities: 

  • Multi-asset state channels:
    Lithium state channels can hold more than one type of asset, for instance, ETH and HDN simultaneously.
  • Multi-hop payment routing
    Similar to the Lightning Network, users of Lithium can send payments to virtually any recipient in the Lithium Network by opening a state channel with just one well-connected peer. This initial connection allows users to leverage the network of interconnected nodes, using them as routers to create a payment pathway to the intended recipient. All payments along the pathway are securely settled using hashed timelock contracts.
  • Multi-channel payment
    Multi-channel payments are payments that are split into smaller parts and sent through different state channels before reassembling at the destination. Practically, this means that if a user has multiple open state channels with different peers and amounts, they don’t need to worry about selecting a specific state channel for their payment; all channels will be used simultaneously to fulfill the payment requirements.
  • Off-Chain Liquidity Pools
    Off-chain liquidity pools allow users to optimize fund management by minimizing the need for on-chain transfers when funding or withdrawing assets from state channels. Instead of moving funds between an on-chain wallet and a state channel, users can transfer funds between the state channel and the off-chain liquidity pool. This method offers several advantages - it significantly reduces gas fees when managing state channel funds, and simplifies the process of providing off-chain liquidity by allowing anyone to provide it without the need to establish and manage their own network nodes.

Lithium’s inner workings

Lithium is composed of a smart contract working in unison with off-chain nodes run by peers in the network. The Lithium smart contract, deployed on the blockchain, contains all the function calls for interacting with Lithium. These functions include opening and closing state channels, as well as depositing and withdrawing funds from them. To enable the Lithium Network on a specific blockchain, at least one Lithium smart contract must be deployed on that blockchain. 

For users to engage in off-chain transactions over the Lithium Network, they must operate Lithium off-chain nodes. These nodes are crucial as they encapsulate all the off-chain protocols and logic necessary for conducting transactions outside the blockchain. Communication between transacting peers is encrypted using the Noise Protocol Framework from LibP2P, ensuring security and privacy.

The Lithium Network uses a Gossip behavior, whereby all off-chain nodes exchange information, such as state channel updates, with one another. This process ensures that all nodes eventually have a consistent view of the network topology, which is vital for efficient payment routing. As in other off-chain networks, payments can be sent to any participant within the network as long as there is an available pathway between the sender and the receiver. A consistent view of the network topology simplifies the discovery of such pathways. 

Moreover, the Lithium Network employs a sub-graph indexer, which, combined with the Gossip behavior, accelerates network synchronization to allow users to connect to the Lithium Network within seconds. The sub-graph indexer continuously monitors the blockchain for Lithium transactions, storing this data in a dedicated database. Users can then retrieve this data upon synchronization without having to inspect the entire blockchain. The database is currently operating on one of Hydranet’s servers, but will eventually get off-loaded to The Graph - a decentralized protocol for indexing and querying blockchain data.

Off-chain liquidity pools

The Lithium contract introduces a novel feature known as off-chain liquidity pools. Such pools make it possible to move funds to and from a state channel without an on-chain transfer (not to be mistaken by transaction), which in turn decreases gas costs for such an operation compared to traditional methods.

The liquidity pools are managed by the Lithium contract deployed on the blockchain and is mainly a feature by which well-established routing nodes, such as Titans in the Hydranet Network, can offer inbound liquidity via renting services without necessitating on-chain transfer of funds, which decreases their operating costs. But individual users that frequently use Hydranet to trade can also use the function to save gas costs.

  1. User A wants to increase their inbound liquidity to receive off-chain payments using Lithium.
  2. User A invokes the liquidity rental function provided by Titans in the Hydranet Network.
  3. The Titan, having previously deposited funds to the Lithium contract, invokes the state channel deposit function. This action transfers funds from the Lithium off-chain pool to User A's state channel without the need for an on-chain transfer of funds.

Although the funds do not physically change addresses, they are allocated and reserved by the Lithium protocol for User A who calls the function. The off-chain liquidity pools also allow other users to provide state channel liquidity in a trustless manner. Users can deposit funds into the Lithium protocol liquidity pool, similar to how Uniswap liquidity pools operate, which other users can then use.

State channel dispute and unilateral closure

As with any financial agreement, disputes between transacting peers may occur for various reasons. Some disputes may arise deliberately due to fraudulent behavior by one of the peers, while other disputes may arise involuntarily due to errors such as connection issues leading to a misalignment of the most recent update. For these reasons, off-chain protocols typically employ various mechanisms to help participants resolve disputes as fair as possible, and the Lithium protocol is no exception.

Lithium includes functions for handling state channel disputes, such as when one peer tries to claim funds they are not entitled to by broadcasting an obsolete state of the channel, or when one peer goes offline, preventing the other peer from closing the channel. The state channel dispute function, also known as a unilateral closure, can be invoked by either peer of the state channel and includes a dispute period during which both peers can challenge the latest broadcasted state. The length of the dispute period is configurable by the peer who opened the channel, serving to prevent misuse of the unilateral closure function and ensuring that malicious actors cannot systematically use it to claim funds they are not entitled to.

Here’s a brief overview of how a unilateral closure may look like: 

  1. User A wants to close their state channel with User B, but User B is offline, preventing a mutual closure. 
  2. User A invokes the unilateral closure function in the Lithium smart contract, initiating the dispute period. 
  3. User B remains offline, and the dispute period ends, allowing User A to settle the state channel on-chain and withdraw their funds according to the settled state of the channel.

A unilateral closure of a state channel can also be invoked by a watchtower. Additionally, a watchtower can challenge the latest broadcasted state during the dispute period on behalf of a peer, if the peer has configured one.


Copyright © 2024