Skip to content

Instantly share code, notes, and snippets.

@esneider
Last active September 22, 2023 17:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esneider/95ebc86510a6e3e9a770d4507f7a9ef6 to your computer and use it in GitHub Desktop.
Save esneider/95ebc86510a6e3e9a770d4507f7a9ef6 to your computer and use it in GitHub Desktop.

Non-custodial lightning escrow for HodlHodl

phase 1: bitcoin funding

  1. seller generates secret A
  2. seller asks hodlhodl to generate a hold invoice with payment hash = hash(A), notice that hodlhodl doesn’t have the preimage A
  3. seller sends a lightning payment to settle the invoice
  4. once hodlhodl receives the payment, it remains on hold since it doesn’t have the preimage A to settle it
  5. hodlhodl lets the seller know it received the payment, so that it can proceed

phase 2: fiat payment

  1. the seller gives the preimage A to the buyer
  2. the buyer sends hash(A) to hodlhodl, and hodlhodl confirms whether the hash matches, so that the seller cannot trick the buyer
  3. the buyer creates an invoice with payment hash = hash(A), and sends it to hodlhodl, which will store it for later use
  4. the buyer sends the fiat payment to the seller

phase 3: settlement

  1. once the seller confirms that it received the fiat payment, hodlhodl will make a lightning payment to fulfill the invoice from the buyer
  2. once the payment is settled, hodlhodl will receive in exchange the payment preimage A, which it can use to finally un-hold the first payment from the seller

Notes

  • The CLTVs of the first payment should be higher than the second payment’s, so that hodlhodl doesn’t have any risk of losing funds
  • The CLTV of the first payment should be high enough to have time to resolve disputes. Maybe a couple of days?
  • Hodlhodl will need to use it’s own funds to make the second payment. Although it cannot loose money, there’s a financial cost associated in being an intermediate node is lightning payments
  • Hodlhodl can’t take or freeze the money at any point, it can only hold it until the first payment expires
  • After making a payment, and giving the preimage to the buyer, if the seller doesn’t collaborate, hodlhodl can confirm that the fiat payment was made, and conclude the transaction with the buyer
  • If the buyer doesn’t collaborate after the seller made the first payment, hodlhodl can fail the payment on hold, and the seller will get all its money back
  • If hodlhodl doesn’t collaborate after the first payment was done, but before the fiat payment was made, the lightning payment will eventually expire, and the seller will get its money back
  • If hodlhodl doesn’t collaborate after the fiat payment was done, the lightning payment will eventually expire, and the seller will get both the fiat and the bitcoins. Not sure how big a problem this is 🤔
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment