{"id":828548,"date":"2025-02-20T14:11:52","date_gmt":"2025-02-20T20:11:52","guid":{"rendered":"https:\/\/newsycanuse.com\/index.php\/2025\/02\/20\/bitcoin-op_cat-use-cases-series-5-drivechain\/"},"modified":"2025-02-20T14:11:52","modified_gmt":"2025-02-20T20:11:52","slug":"bitcoin-op_cat-use-cases-series-5-drivechain","status":"publish","type":"post","link":"https:\/\/newsycanuse.com\/index.php\/2025\/02\/20\/bitcoin-op_cat-use-cases-series-5-drivechain\/","title":{"rendered":"Bitcoin OP_CAT use cases series #5: Drivechain"},"content":{"rendered":"<p>Bitcoins <\/p>\n<div>\n<div>\n<ol>\n<li><a href=\"https:\/\/coingeek.com\">Homepage<\/a><\/li>\n<li> > <\/li>\n<li><a href=\"https:\/\/coingeek.com\/news\/\">News<\/a><\/li>\n<li> > <\/li>\n<li><a href=\"https:\/\/coingeek.com\/news\/category\/tech\/\"><br \/>\n                                Tech<br \/>\n                       <\/a><\/li>\n<li> > <\/li>\n<li>Bitcoin OP_CAT use cases series #5: Drivechain<\/li>\n<\/ol>\n<\/div>\n<p><em>This post was first published on <a href=\"https:\/\/scryptplatform.medium.com\/bitcoin-op-cat-use-cases-series-5-drivechain-e962ee227da5\" target=\"_blank\" rel=\"noreferrer noopener\">Medium<\/a>.<\/em><\/p>\n<p>We have created a <a href=\"https:\/\/coingeek.com\/bitcoin101\/bitcoin-smart-contracts\/\" target=\"_blank\" rel=\"noreferrer noopener\">smart contract<\/a> that operates similarly to the hashrate escrow mechanism in Bitcoin\u2019s Drivechain proposal. However, instead of requiring a substantial protocol upgrade like <a href=\"https:\/\/en.bitcoin.it\/wiki\/BIP_0300\" target=\"_blank\" rel=\"noreferrer noopener\">BIP300<\/a>, it leverages general smart contract functionality to establish a sidechain covenant using OP_CAT.<\/p>\n<figure><img decoding=\"async\" width=\"720\" height=\"411\" src=\"https:\/\/coingeek.com\/wp-content\/uploads\/2025\/02\/OP-CAT.webp\" alt=\"bitcoins OP_CAT\"   loading=\"lazy\"><\/figure>\n<p><strong>Drivechain<\/strong><\/p>\n<p>Drivechain in Bitcoin are a mechanism for implementing <strong>sidechains<\/strong>, which are independent blockchains pegged to Bitcoin. They allow users to transfer BTC between the Bitcoin mainchain and sidechains, enabling new features or experimental technologies without altering the mainchain. Drivechain use a two-way peg system and rely on Bitcoin miners to enforce transfers.<\/p>\n<p><strong>Peg-In: Transferring to a sidechain<\/strong><\/p>\n<ul>\n<li>Users initiate a transaction that locks their bitcoins in a special output on the main Bitcoin chain.<\/li>\n<li>This action generates an equivalent amount of tokens on the chosen sidechain, permitting users to transact under the sidechain\u2019s distinct rules and features.<\/li>\n<\/ul>\n<p><strong>Peg-Out: Returning to the mainchain<\/strong><\/p>\n<ul>\n<li>To move assets back, users execute a transaction on the sidechain that effectively burns the sidechain tokens.<\/li>\n<li>A corresponding withdrawal request is then submitted to the mainchain, to be voted on by miners as detailed below.<\/li>\n<\/ul>\n<p><strong>BIP300: Hashrate escrow<\/strong><\/p>\n<p>The Drivechain proposal for Bitcoin is encapsulated in two Bitcoin Improvement Proposals: <a href=\"https:\/\/en.bitcoin.it\/wiki\/BIP_0300\" target=\"_blank\" rel=\"noreferrer noopener\">BIP300<\/a> for Hashrate Escrows and <a href=\"https:\/\/en.bitcoin.it\/wiki\/BIP_0301\" target=\"_blank\" rel=\"noreferrer noopener\">BIP301<\/a> for Blind Merged Mining. We focus on the former since involves opcode change.<\/p>\n<p>In the Drivechain proposal BIP300, <strong>miner voting<\/strong> is a critical mechanism that governs the approval of withdrawals (peg-outs) from the sidechain back to the main Bitcoin blockchain. <a href=\"https:\/\/coingeek.com\/blackrock-forks-btc-bsv-transactions-coingeek-weekly-livestream-ama-video\/\" target=\"_blank\" rel=\"noreferrer noopener\">Transactions<\/a> are not signed using cryptographic keys. Instead, they are \u201csigned\/voted\u201d by the collective hashpower over time: hashrate-secured escrow. This process functions like a large multisignature arrangement, requiring something akin to 1500 out of 3000 \u201csignatures,\u201d with each mined block representing one signature.<\/p>\n<p>Here\u2019s how miner voting operates in our hashrate escrow contract:<\/p>\n<p><strong>1. Withdrawal Request Creation<\/strong><\/p>\n<p>A user on the sidechain burns their sidechain tokens to initiate a withdrawal request to the main Bitcoin chain.<\/p>\n<p><strong>2. Miner Voting Period<\/strong><\/p>\n<ul>\n<li>The withdrawal request is submitted to Bitcoin miners, who vote on its validity.<\/li>\n<li>This voting process typically spans <strong>3 to 6 months<\/strong>, allowing ample time for miners to evaluate the request.<\/li>\n<\/ul>\n<p><strong>3. Voting Process<\/strong><\/p>\n<ul>\n<li>Miners include a signal in the blocks they mine, either <strong>approving<\/strong> or <strong>rejecting<\/strong> the withdrawal request.<\/li>\n<li>Signals are embedded in block headers or auxiliary data fields, making them visible on the Bitcoin blockchain.<\/li>\n<\/ul>\n<p><strong>4. Consensus Threshold<\/strong><\/p>\n<ul>\n<li>For a withdrawal to be approved, a majority of miners (usually defined as a percentage of the total hashrate, like 51%) must vote in favor of the request during the voting period.<\/li>\n<li>If the required threshold is not met, the withdrawal is denied.<\/li>\n<\/ul>\n<p><strong>Overview<\/strong><\/p>\n<p>Our hashrate escrow of the drivechain implementation features:<\/p>\n<ul>\n<li><strong>Operator Control<\/strong>: Using m-of-n signatures from trusted operators.<\/li>\n<li><strong>Miner Voting<\/strong>: Decentralized consensus for withdrawals.<\/li>\n<li><strong>Dynamic State Updates<\/strong>: The smart contract contains state data that contains values such as vote count and timestamps for voting periods.<\/li>\n<\/ul>\n<p>The contract includes four primary methods: lock, initWithdrawal, vote, and finishWithdrawal.<\/p>\n<p><strong>Operator-controlled state management<\/strong><\/p>\n<ul>\n<li>A group of operators (m-of-n configuration) manage the state transitions.<\/li>\n<li>The operators are responsible for initializing withdrawal proposals.<\/li>\n<li>Their actions are validated through a multisig, ensuring no single party can unilaterally control the funds.<\/li>\n<\/ul>\n<p><strong>Miner voting<\/strong><\/p>\n<ul>\n<li>Miners vote on withdrawal proposals via coinbase transactions.<\/li>\n<li>Voting is based on a two-thirds majority rule, ensuring wide miner participation and decentralized decision-making.<\/li>\n<\/ul>\n<p><strong>Dynamic contract state<\/strong><\/p>\n<ul>\n<li>The smart contract contains state data that contains values such as vote count and timestamps for voting periods.<\/li>\n<li>Each state transition is hashed and stored in an unspendable <a href=\"https:\/\/coingeek.com\/keyring-releases-update-to-support-op_false-op_return\/\" target=\"_blank\" rel=\"noreferrer noopener\">OP_RETURN output<\/a>. Transaction introspection allows us to read this value in the transaction that follows.<\/li>\n<\/ul>\n<p>The contract operates through the following phases:<\/p>\n<ol start=\"1\">\n<li><strong>Lock<\/strong>: Funds are bridged into the drive chain.<\/li>\n<li><strong>InitWithdrawal<\/strong>: Operators propose withdrawals.<\/li>\n<li><strong>Vote<\/strong>: Miners vote to approve or reject proposals.<\/li>\n<li><strong>FinishWithdrawal<\/strong>: Approved withdrawals are executed or state resets for unapproved proposals.<\/li>\n<\/ol>\n<figure><img decoding=\"async\" width=\"708\" height=\"232\" src=\"https:\/\/coingeek.com\/wp-content\/uploads\/2025\/02\/a-call-to-the-lock-method.webp\" alt=\"bitcoins Transaction diagram depicting a call to the lock() method\"   loading=\"lazy\"><figcaption>Transaction diagram depicting a call to the lock() method<\/figcaption><\/figure>\n<figure><img decoding=\"async\" width=\"720\" height=\"362\" src=\"https:\/\/coingeek.com\/wp-content\/uploads\/2025\/02\/a-call-to-the-vote-method.webp\" alt=\"bitcoins Transaction diagram depicting a call to the vote() method\"   loading=\"lazy\"><figcaption>Transaction diagram depicting a call to the vote() method<\/figcaption><\/figure>\n<p><strong>Implementation<\/strong><\/p>\n<p><strong>State representation<\/strong><\/p>\n<p>The contract state includes:<\/p>\n<ul>\n<li>startPeriod: Block height of the last update.<\/li>\n<li>voteCnt: Miner votes for the current withdrawal.<\/li>\n<li>payoutAmt: BTC amount to withdraw.<\/li>\n<li>payoutSPK: ScriptPubKey of the withdrawal output.<\/li>\n<\/ul>\n<p>These values are hashed and enforced to be stored within an unspendable OP_RETURN output by the contract, using <a href=\"https:\/\/scryptplatform.medium.com\/bitcoin-op-cat-use-cases-series-4-recursive-covenants-6a3127a24af4\" target=\"_blank\" rel=\"noreferrer noopener\">recursive covenants<\/a>.<\/p>\n<p><strong>Locking extra funds<\/strong><\/p>\n<p>The lock method validates and bridges BTC to the covenant. It ensures the bridged amount exceeds 10,000 satoshis and verifies state consistency.<\/p>\n<p><strong>Initializing a withdrawal<\/strong><\/p>\n<p>Operators propose withdrawals by providing signatures and specifying payout details. The contract validates these signatures, ensures sufficient time has passed since the last proposal, and updates the state.<\/p>\n<p><strong>Voting on withdrawal<\/strong><\/p>\n<p>Miners vote by using a coinbase transaction. Their votes affect the voteCnt positively or negatively, and the contract enforces single-use votes.<\/p>\n<p><strong>Finalizing a withdrawal<\/strong><\/p>\n<p>Once the voting period ends, withdrawals are finalized if the voteCnt reaches the threshold. The payout amount is sent, and the state is reset for future proposals.<\/p>\n<p>The full code of the smart contract can be found <a href=\"https:\/\/github.com\/sCrypt-Inc\/cat-contracts\/blob\/master\/src\/contracts\/driveChain.ts\" target=\"_blank\" rel=\"noreferrer noopener\">on GitHub<\/a>.<\/p>\n<p><strong>Acknowledgement<\/strong><\/p>\n<p>Our implementation draws inspiration from <a href=\"https:\/\/github.com\/mr-zwets\/upgraded-SHA-gate\" target=\"_blank\" rel=\"noreferrer noopener\">the SHA-gate contract<\/a> designed for Bitcoin Cash. Our work adapts the mechanics of the SHA-gate contract to BTC with OP_CAT re-enabled.<\/p>\n<p>Watch: sCrypt Hackathon students realize there\u2019s more to blockchain<\/p>\n<p><iframe src=\"https:\/\/www.youtube.com\/embed\/Ma1jxiwBOJs?si=7gSDakrrV8ltQ3c_&#038;controls=0\" frameborder=\"0\" allowfullscreen> title=&#8221;YouTube video player&#8221; frameborder=&#8221;0&#8243; allow=&#8221;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share&#8221; referrerpolicy=&#8221;strict-origin-when-cross-origin&#8221; allowfullscreen><\/iframe><\/p>\n<div>\n<p><h3>Tagged:<\/h3>\n<\/p>\n<\/div><\/div>\n<p> Xiaohui Liu <a href=\"https:\/\/coingeek.com\/bitcoin-op_cat-use-cases-series-5-drivechain\/\" class=\"button purchase\" rel=\"nofollow noopener\" target=\"_blank\">Read More<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Homepage &gt; News &gt; Tech &gt; Bitcoin OP_CAT use cases series #5: Drivechain This post was first published on Medium. We have created a smart contract that operates similarly to the hashrate escrow mechanism in Bitcoin\u2019s Drivechain proposal. However, instead of requiring a substantial protocol upgrade like BIP300, it leverages general smart contract functionality to<\/p>\n","protected":false},"author":1,"featured_media":828549,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4041,21967],"tags":[11476],"class_list":["post-828548","post","type-post","status-publish","format-standard","has-post-thumbnail","category-bitcoin","category-cases","tag-bitcoins"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/newsycanuse.com\/index.php\/wp-json\/wp\/v2\/posts\/828548","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/newsycanuse.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/newsycanuse.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/newsycanuse.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/newsycanuse.com\/index.php\/wp-json\/wp\/v2\/comments?post=828548"}],"version-history":[{"count":0,"href":"https:\/\/newsycanuse.com\/index.php\/wp-json\/wp\/v2\/posts\/828548\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/newsycanuse.com\/index.php\/wp-json\/wp\/v2\/media\/828549"}],"wp:attachment":[{"href":"https:\/\/newsycanuse.com\/index.php\/wp-json\/wp\/v2\/media?parent=828548"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/newsycanuse.com\/index.php\/wp-json\/wp\/v2\/categories?post=828548"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/newsycanuse.com\/index.php\/wp-json\/wp\/v2\/tags?post=828548"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}