Skip to content

Instantly share code, notes, and snippets.

@elichai
Last active July 2, 2019 14:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elichai/937a1d47c8ac9226b5212b24dc1e5445 to your computer and use it in GitHub Desktop.
Save elichai/937a1d47c8ac9226b5212b24dc1e5445 to your computer and use it in GitHub Desktop.
Schnorr constructions

Pay to Contract

P' = P + H(P||S)G
d' = d + H(P||S)
Examples:

  1. P is a public key, S is a bitcoin script with a locktime for a different Key(Q).
    The owner of P can sign for P' and spend the output regularly(by signing with d').
    OR the owner of Q can provide P and S and then get evaluated by S as a regular script. (and if the script evaluates to true he can get the money)

  2. S is a hash of a document and this is used to timestamp data, not the best way since you need this to be able to sign on the transaction later and this isn't saved anywhere.

Sign to contract

R' = R + H(R||c)G
k' = k + H(R||c)
Examples:

  1. Commit to some data (i.e. timestamps).
  2. Use this as auxilary data for a sidechain/payment channel(liquid, lightning etc.).

Adaptor Signatures

s' = k + ed + t
s'G = R(kG) + eP(dG) + T(tG)
This is only useful in MuSig, otherwise the signer can replace R with whatever he wants, rendering t signature useless.
Examples:

  1. Atomic Swaps:
    Alice and Bob have a 2-Out-of-2 address on both litecoin and bitcoin. Alice want to sell 10LTC to Bob for 1BTC.
    She provides to bob 2 adaptor signatures with the same T, one for the 10LTC and another for the 1BTC.
    Bob in exchange gives her 2 regular schnorr signatures(partial signatures).
    Alice creates a full signature for the 1BTC and broadcast it.
    Bob sees that signature. subtract from it his signature and the adaptor signature, and from that he gets -t.
    Now he get add that to the adaptor signature for the 10LTC, add his signature and get his money.

  2. Same can be done with lightning channels. of course you'll need a TimeLock option to revert the operation in case of non cooperative party.

Math:
Alice1: sa1 = ka1 + e1da + t
Alice2: sa2 = ka2 + e2da + t

Bob1: sb1 = kb1 + e1db
Bob2: sb2 = kb2 + e2db

Alice1 Sends: s' = sa1 + sb1 - t
Bob calculate: s'- sa1 - sb1 == -t

Bob send: s' = sb2 + sa2 + (-t)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment