Below is a method to create a payment channel similar to Bitcoin using the “replace by higher value” strategy, but without using multisignatures.
This is a one-way channel where Alice sends payment to Bob. We can get symmetric channels by having two one-way channels.
There are two types of boxes:
Bob’s box which can be created by anyone, with n “Bob’s tokens” (token id bob). Additionally, Alice needs to ensure that there are exactly n bob-tokens in existence. The box has the following script.
- Any number (up to n) of bob-tokens can be sent to Bob and only to Bob, and that too only in a single tx
- The remaining bob-tokens will be burned
- Only Alice can spend this box
Alice’s box created by Alice containing n quantity of assets (maybe Ergs) using which to pay to Bob. The box has the following script:
- Alice can spend the box after a certain block height h. The payment channel is considered closed after that height. Before that height the box spending condition is as follows:
- Bob can spend the box by burning some amount, say x, of bob-tokens. In return exactly x assets must be sent to Bob. The remaining assets must be sent to Alice
The channel works as follows:
- Bob’s box is created and a payment channel of value n from Alice to Bob is requested.
- Alice verifies that Bob’s box has the correct script and n bob-tokens. Additionally, there are no more bob-tokens anywhere.
- Alice’s box is created by Alice, whose details are verified by Bob.
- Bob assumes that the payment channel is setup,
- Over the course of the channel, Alice makes multiple off-chain payments to Bob by sending multiple un-broadcasted Tx to Bob, each spending Bob’s box and releasing x bob-tokens from it (to Bob), the value of x is incremented each time, accumulating earlier payments.
- Finally Bob decides to close the channel, well before height h. He does so by first spending Bob’s box claiming bob-tokens using the off-chain tx from Alice releasing the highest number of such tokens. Then he claims the same quantity of assets by burning those bob-tokens and spending Alice’s box in a second tx.
[EDIT] protocol has been modified. See post below.