This is motivated by the “Short-lived Unconfirmed Transactions: Paying for Coffee” example in section 2.1 of the “Advanced ErgoScript Tutorial”:
alice && HEIGHT <= getVar[Int](1).get
This contract allows Alice to pick an expiry height when they create a spending transaction, by specifying it as part of the context extension.
To make things more interesting, consider the following script:
SigmaAnd(ProveDlog(alice), DeserializeContext(0, SSigmaProp))
(Unfortunately, I don’t think the ErgoScript compiler frontend supports deserializeContext
at the moment, so the above is in Scala.)
Now, this allows Alice to specify an arbitrary script at spend time, such that the script must evaluate to true
for it to be mined in a particular block.
The conditions most likely to be attached are those relating to the block header e.g. the block height as per the coffee example, but note that a minimum height can be set instead of a maximum height if this is useful (I’m not sure if this case would be immediately rejected from the mempool, however). Alice can specify true
if they do not want any conditions at all.
The original concept of setting an expiry height on transactions is quite good, and even Zcash has a built-in nExpiryHeight (set to 20 blocks), the main motivation being to provide more certainty for users: if their transaction is not confirmed with 20 blocks, then they probably need to resend, possibly with a higher fee.
Allowing completely arbitrary conditions to be set (other than an expiry height) for a spending transaction to be mined is probably not particularly useful (and the execution cost is almost definitely higher), but I thought it would be interesting nonetheless.