# Building Secure and Watchtower-efficient Bitcoin Payment Channels with BitVMX

**URL:** <https://delvingbitcoin.org/t/building-secure-and-watchtower-efficient-bitcoin-payment-channels-with-bitvmx/1830>\
**Category:** Protocol Design\
**Tags:** lightning\
**Created:** [July 14, 2025, 12:18pm UTC](https://delvingbitcoin.org/t/building-secure-and-watchtower-efficient-bitcoin-payment-channels-with-bitvmx/1830 "2025-07-14T12:18:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SergioDemianLerner](https://delvingbitcoin.org/letter_avatar_proxy/v4/letter/s/779978/32.png) [@SergioDemianLerner](https://delvingbitcoin.org/u/SergioDemianLerner)\
**Post date:** [July 14, 2025, 12:18pm UTC](https://delvingbitcoin.org/t/building-secure-and-watchtower-efficient-bitcoin-payment-channels-with-bitvmx/1830/1 "2025-07-14T12:18:28Z")

</div>

Hi! I’m copypasting here an article I wrote about how to create Watchtower-efficient payment channels with BitVMX. The original article is here: [BitVMX | Building Secure and Watchtower-efficient Bitcoin Payment Channels with BitVMX](https://bitvmx.org/knowledge/building-secure-and-watchtower-efficient-bitcoin-payment-channels-with-bitvmx).

## Intro

This article presents a sample payment channel that uses to support efficient revocations. It can be easily extended to function as a state channel and support Hash-Time Locked Contracts (HTLCs) for lightning-like routing. However, we aim to keep it simple so that it serves as a clear example of BitVMX’s capabilities and how it can be integrated as a subcomponent of other Bitcoin protocols. In this example, BitVMX is used to handle state revocations and enable efficient watchtowers that store only O(1) data per payment channel.

Each state of our toy payment channel has a sequence number _i_, which increments with every state update. When the parties agree to move to the next state (e.g., rebalance the shared account), they must co-sign three transactions. They can use a multisig or MuSig2 scheme to reduce the on-chain footprint. Then, they create two revocation messages—one for each party—signed with Schnorr signatures. A revocation message contains the new state sequence number _i_ and represents the message: “I revoke all states prior to _i_.” In practice, the message is simply the number _i_, signed with a private key designated solely for this purpose.

When Alice wants to unilaterally close the channel, she can only do so by signing the sequence number _i_ using a one-time signature (OTS) scheme. This sequence number defines the state that Alice claims should determine the final balance distribution between her and Bob. If Alice uses an outdated state—say she signs _j_, with _j \< i_—a dispute mechanism is triggered to penalize her. Bob simply needs to present the OTS-signed value j and the Schnorr-signed message “I revoke all states prior to _i_,” which Alice previously issued and which Bob has stored. A Bitcoin script verifies the OTS signature, while a RISC-V program executed via BitVMX verifies the Schnorr signature and checks whether _j \< i_. If this condition holds, Bob wins the dispute and can claim all funds in the channel.

* * *

## Transaction DAG

The figure below illustrates the transaction directed acyclic graph (DAG) created by the protocol. Only the _SetupTx_ is published on-chain; other transactions are published only as needed.

- **Violet boxes** : Transactions published by Alice
- **Pink boxes** : Transactions published by Bob
- **Yellow boxes** : A sequence of transactions issued alternatively by Alice, Bob, or their watchtowers
- **Orange boxes** : Transactions re-created with every state update
- **Gray box** : A transaction issued by a watchtower
- **Green box** : The initial funding transaction, which either owner can issue

 ![](https://delvingbitcoin.org/uploads/default/original/2X/2/28127e8640a68547524613703e885a1971effd3c.jpeg)

The transaction Direct Acyclic Graph (DAG) for a Simple Payment Channel

When Alice publishes _StartTx(j)_, she commits to the sequence number _j_. Either Alice or Bob can then OTS-sign the value _j_ in _AssertTx(j)_. Normally, Alice signs this transaction. However, we must consider whether Bob could disrupt the protocol by signing it himself. If Bob detects that _j_ is not the latest state _i_, he should refrain from signing _AssertTx(j)_—he lacks Alice’s signed sequence number for _j_ and thus cannot initiate a valid dispute. If _j = i_, Bob can safely sign and publish _AssertTx(i)_, which won’t affect the protocol’s integrity.

## Setup

There are two main parties in this protocol: Alice and Bob, referred to as the **owners** of the channel. Optional auxiliary parties, _Wa_ and _Wb_, act as watchtowers for Alice and Bob, respectively.

### Initialization

1. Each owner chooses a hidden pre-image (_Pa_ by Alice and _Pb_ by Bob) and sends the other the corresponding hash (_Ha = H¶_ and _Hb = H(Pb)_).
2. Each owner generates an OTS key pair (pair _A1_ for Alice and _B1_ for _Bob_) for signing sequence values _i_, using 32-bit unsigned integers to allow up to 4 billion updates. Public keys are exchanged.
3. Both parties construct a DAG of co-signed transactions, including:

- _SetupTx_
- BitVMX Dispute Channels
- _AliceWinsTx()_, _BobWinsTx()_
- _TimerForBobTx_, _TimerForAliceTx_
- _TimeoutForAliceTx_, _TimeoutForBobTx_

1. They create the initial transactions: _PayTx(0)_, _AssertTx(0)_, and _StartTx(0)_. These define an initial exit path where each owner can withdraw their initial deposit. No revocation messages exist at this point, so no challenges are possible.
2. Each owner generates another OTS key pair (_A2_ by Alice, _B2_ by Bob) for signing inputs to dispute channels.
3. If watchtowers are used, they provide their OTS public keys to the owners, who create additional dispute channels that only the watchtower can sign.

* * *

## Advancing to the Next State

When a payment occurs (e.g., Alice pays Bob), both parties must advance to the next state and revoke the previous one. Without loss of generality, let’s assume Alice is paying Bob. Bob has an incentive to complete the protocol.

1. **Alice and Bob sign** _PayTx(t)_ and _AssertTx(i)_, exchanging signatures.
2. **Bob signs** _StartTx(t)_ and sends it to Alice. Now Alice can continue with either state, but Bob can only use the old state. Since he received funds, Bob is motivated to proceed.
3. **Alice gives Bob** a revocation message _Ma(i)_, which is a Schnorr signature on _i_, representing: “I, Alice, revoke all states prior to _i_.” Now Alice can only use the new state.
4. **Alice co-signs** _StartTx(t)_ and sends it to Bob. Alice can only use the new state; Bob could use either, but the new state benefits him more.
5. **Bob forwards** Alice’s revocation to his watchtower and issues his own revocation message _Mb(i)_ to Alice. At this point, neither party can safely use the old state.

* * *

## Liveness Guarantees During State Transitions

To prevent a party from stalling the protocol mid-update, the channel includes a timeout mechanism. If Alice issues _StartTx(j)_ but delays or refuses to issue the corresponding _AssertTx(j)_ in a timely manner, Bob can respond by publishing _TimerForAliceTx_. This transaction initiates a countdown, giving Alice a limited window to publish _AssertTx(j)_. If Alice fails to do so before the timer expires, Bob may publish _TimeoutForAliceTx_, which awards him all funds in the channel as a penalty for Alice’s non-cooperation.

The timer is triggered using the preimage _Pa_, which Alice reveals when she publishes _StartTx(j)_. This ensures that only Alice can start this process, and only Bob can enforce the timeout based on her actions.

* * *

## Closing the Channel

If both parties agree to close the channel, they co-sign a payment transaction that spends directly from the SetupTx, distributing the funds accordingly. If funds remain in intermediate connector outputs (used for pre-paying fees or managing dust outputs), they can also be collected and shared.

If one party becomes uncooperative, the other performs a **unilateral close** :

- Publish the latest _StartTx_ and _AssertTx_
- Wait for a potential dispute
- Publish _PayTx_, which is timelocked to allow dispute resolution

The _PayTx_ timeout can be shortened when no dispute occurs, it doesn’t need to match the dispute worse case time, but this complexity is omitted here to keep the transaction DAG simple.

* * *

## Watchtowers

Watchtowers receive periodic revocation messages _M(i)_ for a given payment channel, identified by a monitoring ID (_MoId_). The _MoId_ is derived from the channel’s funding transaction ID and the owner’s public key. If the same watchtower monitors both parties, each will have a distinct _MoId_.

When a watchtower receives a new revocation _M(i)_, it can safely discard all prior revocations for the same _MoId_. This is a significant improvement over Lightning Network watchtowers, which must store a revocation key for every state update. Thanks to BitVMX’s ability to verify complex logic off-chain, revocations become more storage-efficient and secure.

* * *

## HTLCs

(This section is available in the original article since it has more images and this forum restricts to 1 image per post)

* * *

## Summary

This article introduced a sample Bitcoin payment channel that leverages BitVMX to enable efficient state revocations and support for compact watchtower implementations. By encoding state revocation logic through Schnorr-signed messages and verifying them using BitVMX, the protocol achieves robust dispute resolution with minimal on-chain data. The payment channel uses a directed acyclic graph (DAG) of transactions, with one-time signatures (OTS) enforcing state commitments. Watchtowers benefit from an O(1) storage requirement by tracking only the latest revocation message per channel, improving upon the standard Lightning Network approach. We also show how to add HTLCs, PTLCs and other new locking functions. While the design is simplified for clarity, it highlights the extensibility of BitVMX in constructing secure and efficient off-chain Bitcoin protocols.
