I have been reading the BitML paper. The language compiles to another language (Balzac [which in turn compiles to Bitcoin Script]), which can do relative and absolute timelocks. Balzac can also do something that looks like an HTLC. So it looks like Balzac could encode Lightning. Can BitML also do this?


In short, yes (kinda).

More in detail, Balzac can perform the operations required for HTLC transactions. The following transaction is redeemable by Alice providing the premimage of h, or by Bob after the timelock block 1550000 expires.

transaction T_BtoA {
    input = B_funds: sig(kA)
    output = 1 BTC:
        fun(x,s:string) . sha256(s) == h && versig(kApub;x)
            || checkBlock 1550000 : versig(kBpub;x)

So, Balzac can be used to express the transactions of an HTLC, or any payment channel.

BitML is designed to express contracts, and compiles to a set of Balzac transactions. Thereby, it cannot be used to express arbitrary transactions. Nonetheless, we can express a similar logic in BitML with the following contract (full code):

  (reveal (h) (withdraw "Alice"))
  (after 1550000 (withdraw "Bob")))

This contract compiles to three transactions, one similar to T_BtoA above, and other two to move the bitcoin from the first transaction to either Alice or Bob. Note that all transactions need to be signed by both participants when stipulating the contract, so they cannot be changed unilaterally.

While BitML can be used to express such transactions, at the moment it cannot express payment channels. With BitML you cannot design contract where the values of transactions are not known at compile time, or that require an unbound number of iterations. However, there is ongoing research to extend BitML with these features.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.