MarkYnx
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Building the BitVM Bridge with OP_CTV: A Feasible Path Forward ## Overview After extensive consideration, the opcode `OP_CTV` ([CheckTemplateVerify](https://github.com/bitcoin/bips/blob/master/bip-0119.mediawiki)) has been thoroughly studied, reviewed, and is now well understood by the Bitcoin community and its developers. As a result, [Jeremy Rubin](https://x.com/JeremyRubin/status/1889458352889143718) has expressed his support for a covenant upgrade plan aimed at activating `OP_CTV`. It is possible that developers may not have to wait much longer before this feature is officially activated. The BitVM bridge, on the other hand, seeks to establish a trust-minimized bridge system between Bitcoin and various sidechains or sidesystems. Historically, implementing covenants in Bitcoin has typically relied on mechanisms such as a presigning committee, which ensures that transactions are submitted in a predetermined manner. However, this approach often introduces trust assumptions and operational complexity. For those interested in the technical details of how the BitVM bridge works, further information can be found [here](https://bitvm.org/bitvm2). While the latest design of the BitVM bridge has undergone significant changes compared to earlier iterations, it still retains the fundamental principles and key insights necessary for its implementation. Furthermore, it can be used as a reference example to demonstrate a potential approach for implementing the BitVM bridge with the use of `OP_CTV`. In the end, a demo is provided for you to see how the BitVM bridge may work in practice. ## OP_CTV `OP_CTV`, also known as `OP_CHECKTEMPLATEVERIFY`, is a Bitcoin opcode with a straightforward yet powerful function. It verifies whether the element at the top of the stack matches the `DefaultCheckTemplateVerifyHash` of the transaction itself. The `DefaultCheckTemplateVerifyHash` represents a novel approach to computing the digest of a transaction, designed to facilitate more efficient and predictable transaction processing. This digest calculation is particularly noteworthy because it commits to specific fields of a transaction in a carefully chosen order, prioritizing fields that are least likely to change and progressing to those that are more dynamic 1. nVersion 2. nLockTime 3. scriptSig hash (maybe! if it has) 4. input count 5. sequences hash 6. output count 7. outputs hash 8. input index in that case, the`DefaultCheckTemplateVerifyHash` for any transaction can be precomputed in advance. Remarkably, this process does not require prior knowledge of the UTXOs that these transactions will eventually use as their inputs. Furthermore, the locking script of these transactions is pre-committed, enabling the prediction of the subsequent transaction in the sequence. This pre-commitment mechanism ensures a predictable execution flow, providing a clear framework for how the transactions will be executed. The locking script appears straightforward if the goal is merely to select the spent transaction based on its `DefaultCheckTemplateVerifyHash`: ``` <DefaultCheckTemplateVerifyHash of spent transaction> OP_CHECKTEMPLATEVERIFY ``` In addition to BitVM bridge, it can also be applied in the following scenarios: - [Vaults](https://github.com/jamesob/simple-ctv-vault) - [ARK](https://ark-protocol.org/) - [Sapio](https://github.com/sapio-lang/sapio) ## Demo Below figure shows The original BitVM transation graph: ![image](https://hackmd.io/_uploads/S1N7aKHi1x.png) There are four possible paths based on the behavior of the operator and the challenger's actions: 1. Happy Path: If the operator is honest, no one challenges it. In that case, transaction sequence is: Pegin -> Pegout -> Kickoff -> Take1 2. Unhappy Path: Even if the operator is honest, a challenger might still attempt to challenge it, but the challenger won't success eventually. In this case, the transaction sequence would be: Pegin -> Pegout -> Kickoff -> Challenge -> Assert -> Take2 3. Disprove Path: If the operator is malicious and a challenger raises a challenge, the operator will ultimately be penalized. In this case, the transaction sequence would be: Pegin -> Kickoff -> Challenge -> Assert -> Disprove 4. Timeout Path: If the operator is malicious and a challenger raises a challenge, but the operator refuses to issue the assert transaction, the operator will still be penalized after a predefined timeout period. In this case, the transaction sequence would be: Pegin -> Kickoff -> Challenge -> Burn Before `OP_CTV` is activated, a presigning committee is necessary to presign certain transactions from the BitVM transaction graph. These transactions include: Take1, Challenge, Assert, Take2, Disprove, and Burn. The purpose of this presigning process is to ensure that these transactions are executed in the precise order they were originally designed, thereby maintaining the integrity and predictability of the system's operation. To simplify this model without losing its most critical technical aspects. a simple demo shows below: ![image](https://hackmd.io/_uploads/SkzbzqIi1x.png) It only includes two paths, based on the feature of `OP_CTV`, it looks like: 1. Happy Path: If the operator is honest, no one challenges it. In that case, transaction sequence is: Pegin -> Kickoff -> HappyTake 2. Disprove Path: If the operator is malicious and a challenger raises a challenge, the operator will ultimately be penalized. In this case, the transaction sequence would be: Pegin -> Kickoff -> Challenge -> Assert -> Disprove -> Reward. Apart from the paths(Unhappy Path, Timeout Path) we have omitted, certain parts of this transaction graph still differ significantly from the original one. There are several reasons for these differences: 1. In the `OP_CTV` version of the BitVM bridge, Almost every transaction's input in `OP_CTV` version BitVM bridge are from the same transaction, with the exception of Kickoff. This difference arises because, even with `OP_CTV`, it appears impossible for Pegin to commit to Take1 and for Take1 to commit to Kickoff, as was achieved in the presigning committee version. This limitation introduces a critical vulnerability: if Pegin is submitted, a malicious operator could potentially submit a false Kickoff transaction to steal funds from Pegin. ![image](https://hackmd.io/_uploads/S1Fz6cLjJg.png) However, the collateral input of Kickoff (the second input of Kickoff) does not face this issue. This is because the operator is solely responsible for selecting a collateral UTXO from its own funds to issue the Kickoff transaction. As a result, the operator cannot steal funds from itself, and no other party has the ability to exploit this mechanism either. 2. As discussed in the chapter on `OP_CTV`, it commits to all outputs of a specified transaction. However, in the Disprove Path of the BitVM bridge, the challenger must be rewarded for their action in challenging the malicious operator. In the presigning committee version, the challenger can be anyone, as long as they successfully submit the disprove transaction (in practice, this might often be the miner, as miners would have an incentive to front-run the transaction for their own gain). This is precisely why we need P2A ([Pay-to-Anchor](https://bitcoinops.org/en/bitcoin-core-28-wallet-integration-guide/)).With a P2A output, anyone can claim the funds as long as they successfully submit the reward transaction. This ensures that the reward mechanism remains fair and accessible, incentivizing challengers to act against malicious operators while maintaining the integrity of the system. The reason why there are two P2A outputs in the Disprove transaction is that having only one P2A output would result in a transaction that is too small in size, which would then be rejected by the mempool's policy. If the mempool policy could be modified, the fee that is currently burnt could instead be set as the transaction fee paid to the miner. This adjustment would ensure that the transaction complies with the fee rate requirements and does not exceed the maximum allowable fee rate. 3. Actually, even if the malicious operator is slashed, the funds it attempted to claim should ideally be reclaimed by other operators rather than being given as a reward to the challenger. However, implementing such a mechanism could be overly complex for the purposes of a simple demo. That said, it is indeed feasible to design and implement such a system in practice. The repository for the demo can be found [here](https://github.com/bitlayer-org/bitvm-ctv-demo), feel free to explore and enjoy! ## Reference: BIP119 a.k.a OP_CTV: https://github.com/bitcoin/bips/blob/master/bip-0119.mediawiki The upgrade plan of Bitcoin covenant: https://x.com/JeremyRubin/status/1889458352889143718 An introduction of BitVM: https://bitvm.org/bitvm2 P2A: https://bitcoinops.org/en/bitcoin-core-28-wallet-integration-guide/ bitvm-ctv-demo: https://github.com/bitlayer-org/bitvm-ctv-demo

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully