2

How to make spending conditions of a UTXO in Bitcoin such that before a particular timestamp, say t, it can be spent only in one way and, after t, it can be spent only in another way.

2 Answers 2

3

You can do this by creating a P2WSH output with the following script:

OP_IF
  <condition 1>
OP_ELSE
  <timestamp>
  OP_CHECKLOCKTIMEVERIFY
  OP_DROP
  <condition 2>
OP_ENDIF

Then depending on what condition you're taking you put 1 or 0 on top of the initial stack when spending.

You can also do this more privately (and in most cases cheaply) by using P2TR and splitting the two conditions into separate tree leaves. If the first condition consists of a single public key (or a set of keys that can be aggregated) you can use it as the internal key, and when you're taking that condition using the key path you don't even need to reveal a script.

3
  • 2
    @kirti-singh note that after <timestamp> <condition 1> is still valid.
    – bordalix
    Commented Mar 10 at 17:53
  • @bordalix True, how to make it such that after <timestamp>, the <condition 1> does not hold? Commented Mar 11 at 9:30
  • 2
    That's impossible. Transaction validity is by design monotonous, i.e. once a transaction becomes valid it stays valid, unless one of its inputs is spent or a soft fork activates that invalidates it. See also Antoine's answer. Commented Mar 11 at 11:43
2

It's not possible to set spend conditions which expire on a Script. It's sometimes referred to as an "inverse timelock". It is widely believed to not be desirable as a valid Script becoming invalid makes it much harder to reason about reorgs and caching.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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