Access blockchain data from Bitcoin smart contracts: Part 5

This post was first published on Medium.

Building upon the foundation laid out in previous parts of the series, we have demonstrated how to implement relative locktime in Bitcoin, without new opcode OP_CheckSequenceVerify.

Timelock

A timelock restricts the spending of some bitcoins until a specified future time or block height. There are two types of timelocks:

  1. Absolute: for example, one can provably lock up 1,100,000 bitcoins until block height 800,000, or until January 1st, 2025.
  2. Relative: for example, one can lock up 21 bitcoins that can only be spent after 100 blocks or 3 days.

To enable absolute and relative timelocks, new opcodes OP_CheckLockTimeVerify/OP_CLTV and OP_CheckSequenceVerify/OP_CSV were introduced in BIP65 and BIP68/112/113, respectively.

Relative locktime without OP_CSV

Restoring the original Bitcoin protocol, Bitcoin SV has reverted the aforementioned changes. It turns out OP_CSV can be implemented with the original protocol.

a screenshot of a flow diagram of Timelocked TX
Relative Transaction Timelocks

In Part 1, we have shown how to access the block containing a given contract UTXO. Combining this block header with the specified relative timelock, we can know the earliest block that the UTXO can be spent. We demand any block after the deadline to be available for unlocking the UTXO, essentially placing a relative timelock on it as OP_CSV does. The full code is listed below.

a screenshot of csv code
CheckSequenceVerify Contact

Line 11 shows unlocking based on unix time (e.g., in seconds). validateHelper() function at Line 33 verifies both the block containing the UTXO and a latest block are valid (Line 41–42). It also verifies the former block actually contains the UTXO (Line 34–38) using the same technique as in Part 1. Line 15 ensures required time has elapsed since the UTXO is mined.

Line 19 shows unlocking based on block height (e.g., number of blocks). Line 24–25 get heights of the two blocks as in Part 3. Line 27 checks specified number of blocks have been mined after the UTXO.

Summary

Besides OP_CSV, we have previously implemented OP_CLTV without any change to the original Bitcoin protocol. There are two implications:

  1. Both opcodes are not necessary to enabled UTXO-level timelocks, as previously thought.
  2. All use cases enabled by OP_CSV/CLTV, such as lightning networks, sidechains, and CLTV-style payment channels, can be directly built on the original Bitcoin, if desired.

Watch: CoinGeek New York panel, Bitcoin & Blockchain – Can Real Value Come from Real Utility?

New to Bitcoin? Check out CoinGeek’s Bitcoin for Beginners section, the ultimate resource guide to learn more about Bitcoin—as originally envisioned by Satoshi Nakamoto—and blockchain.

Note: This article have been indexed to our site. We do not claim legitimacy, ownership or copyright of any of the content above. To see the article at original source Click Here

Related Posts
Morocco ranked the safest country in North Africa thumbnail

Morocco ranked the safest country in North Africa

Selon une étude publiée par le « Gulf Center for Studies and Research », centre d’études et de recherches du Golfe, le Maroc occupe la 8ème place des 20 pays arabes les plus sûrs de l’année 2021. Cette 8ème place lui vaut d’être le pays le plus sûr de l’Afrique du Nord, car aucun l’autre pays…
Read More
Mexican Peso rises to nine-year high against USD thumbnail

Mexican Peso rises to nine-year high against USD

The Mexican Peso rises to a nine-year high versus USD on Friday. The release of Banxico's March meeting minutes may have helped spur the Peso to more gains. Higher crude Oil prices, a key Mexican export, could also be supporting MXN.  The Mexican Peso (MXN) trades at nine-year highs against the US Dollar (USD) on Friday
Read More
Централните банки ускоряват световния преход от долар към злато thumbnail

Централните банки ускоряват световния преход от долар към злато

Снимка: Bloomberg L.P.​ Централните банки по света увеличават размера на държаното от тях злато, като обемът достига 31-годишен връх през 2021 г., пише Nikkei Asia Review. Регулаторите са натрупали над 4500 тона злато в своите резерви през последното десетилетие, според Световния съвет по златото. Към септември запасите възлизат на приблизително 36 хил. тона, най-голямото количество…
Read More
They ran aground on the ATHEX PPA and OLTH thumbnail

They ran aground on the ATHEX PPA and OLTH

ΟΛΠ-ΟΛΘ: Σαφή αδυναμία στο ταμπλό του ΧΑ δείχνουν κατά τους τελευταίους μήνες τα λιμάνια, με τον ΟΛΠ να υποχρεώνεται χθες σε χαμηλό δωδεκαμήνου και με τον ΟΛΘ να απέχει… χιλιόμετρα από το υψηλό έτους των 29,10 ευρώ.Και όμως, μιλάμε για εταιρείες με άριστη ρευστότητα (θετικό καθαρό ταμείο στις 30/6/2021 στα 65,1 εκατ. για τον ΟΛΠ και…
Read More
UK Tables Crypto Property Bill thumbnail

UK Tables Crypto Property Bill

By Mark Hunter2 weeks agoThu Sep 12 2024 07:33:44 Reading Time: < 1 minute A new bill has been introduced to classify cryptocurrencies and digital assets as personal property under UK law The legislation provides increased legal protection to owners and businesses handling digital assets The bill aims to strengthen the UK’s position as a
Read More
Index Of News
Total
0
Share