We’re already at part four of our ARK Core blog series covering the upcoming transaction types and features built into ARK Core v2.6. Next up, we’ll take a closer look into one of the most highly anticipated new transaction types, Hash Time-Locked Contracts (or HTLC for short) — what they are, how they work and how you can use them.

Over the past few weeks, we’ve been exploring all the amazing new features built into our upcoming Core v2.6 upgrade. Following our previous posts covering the introduction of Schnorr’s Multisignatures, Multisignature Server and Multipayments it’s time to turn our attention to HTLC. Let’s explore them together…

Disclaimer

Creating a platform that is user-friendly with a focus on security has always been a signature of everything we’ve built at ARK. Ensuring that the funds of all ARK users are protected and secure from bad actors and potential network attacks is of the highest priority at all times. With that in mind, the ARK Team feels at this stage there is a necessity to be cautious and to not include HTLC in the ARK Mainnet Core 2.6 upgrade, due to potential loss of funds in the event of a double-spend attack initiated by a network rollback and a lack of finality (read more on this below). We actively encourage all community developers to rigorously test the current implementation on Devnet to help improve and refine the functionality of HTLC before the Mainnet release, and earn bounty rewards for doing so!

As previously revealed in the ARK Developer Roadmap blog, we are planning on building a new consensus algorithm for ARK to strengthen the key components of the Core, written from the ground-up and inspired by Tendermint BFT with stronger finality guarantees. The HTLC transaction types will be introduced to ARK Mainnet once the new consensus has been tested and implemented next year. The ARK Core developers will commence work on the new consensus algorithm after the launch of ARK Core 3.0.

In the meantime, you can still get started with testing the new HTLC implementation. It’s currently available on Devnet so that developers can get a head start building apps that will use HTLC or simply help us improve or report bugs related to HTLC in exchange for bounty rewards.

Stay tuned to blog.ark.io for updates on this.

What is HTLC?

HTLC transactions enable two parties to exchange tokens safely and securely at the protocol level, removing the need to trust an individual who could potentially be a bad actor and withdraw from a prior agreement once they have received their tokens. HTLC is a core requirement for cross-chain atomic swaps and ARK Core 2.6 is the first step toward interoperability within the ARK Ecosystem.

A Hashed Time-Lock Contract is a set of transaction types that permits a designated party (the “sender/seller”) to LOCK funds by disclosing the hash of a secret. It also permits a second party (the “recipient/buyer”) to CLAIM the funds once in possession of the secret used to initiate the LOCK, or after a timeout is reached enter a REFUND situation.

As per the above, the HTLC implementation within ARK Core introduces three new transactions:

HTLC_Lock — This transaction enables a sender to lock tokens within their wallet behind a hashed secret password using a one-way hash (SHA-256).

— This transaction enables a sender to lock tokens within their wallet behind a hashed secret password using a one-way hash (SHA-256). HTLC_Claim — This transaction enables the recipient to claim the locked tokens once the sender has revealed the secret password.

— This transaction enables the recipient to claim the locked tokens once the sender has revealed the secret password. HTLC_Refund — This transaction allows the sender to unlock previously locked tokens within their wallet in the event of a dispute or the recipient not claiming them.

Let’s take a look at each transaction more in-depth:

HTLC Lock

When sending an HTLC_Lock transaction to the ARK Public Network, a number of parameters are required for the transaction to be accepted.

amount — Amount of network currency that will be locked. secret_hash — A hash of the secret. The same hash must be used in the corresponding “claim” transaction. expiration_type — Type of the expiration. Either block height or network epoch timestamp-based. expiration — Expiration of transaction in seconds or height depending on selected expiration_type. recipient — The recipient's address.

Once the HTLC_Lock transaction has been applied, the sender will no longer have access to the locked tokens and consequently can only be unlocked with the HTLC_Refund transaction once the configured expiry time has elapsed. The expiration time will commence as soon as the HTLC_Lock transaction has been forged on the network.

Note: All locked tokens will still contribute to your delegate’s vote weight providing the recipient has not claimed them.

HTLC_Claim

The HTLC_Claim transaction requires two parameters that are required for the transaction to be accepted on the ARK Public Network.

lockTransactionId — HTLC_Lock transaction id, to serve as a reference. unlockSecret — In order to issue CLAIM transactions, this must be made visible on the chain. Its hash must be equal to HTLC_Lock.secret_hash.

As the recipient address is specified in the HTLC_Lock transaction, the desired recipient can use the HTLC_Claim transaction to retrieve the aforementioned tokens. The recipient can only process a HTLC_Claim once the HTLC_Lock transaction has been forged on the ARK Public Network.

HTLC_Refund

Retrieving locked tokens can be achieved with the HTLC_Refund transaction. Only one parameter is required for the transaction to be accepted on the ARK Public Network.

lockTransactionId — HTLC_Lock transaction id, to serve as a reference.

The HTLC_Refund transaction can only be initiated once the configured expiry time in the HTLC_Lock transaction has come to completion and can be initiated by anyone (funds become unlocked and again spendable on the sender’s address).

Atomic Swaps

So why do we need HTLC? Since the initial whitepaper release in 2016, a major staple of the outlined vision for the ARK is to create interoperability functionality within ARK’s ecosystem. The implementation of the HTLC transactions within ARK Core 2.6 is the first step to introducing true interoperability between ARK based chains with atomic swaps.

To understand a basic flow of atomic-swap HTLC contracts interacting with each-other check the diagram below. Here we provide an example transaction where Alice is swapping 300 ARK for 3000 NOS with Bob.