Coder Social home page Coder Social logo

btcrelay-sol's Introduction

Bitcoin relay solana program

This project is heavily inspired by:

Bitcoin relay is an on-chain program used to verify and store bitcoin blockheaders. This program is completely permissionless and trustless, anyone can write blockheaders as their validity is verified on-chain. To start submitting blockheaders yourself head over to off-chain app repo.

Verification

Program checks blockheader consensus rules:

  • correct PoW difficulty target
  • possible difficulty adjustments
  • previous block hash
  • blockhash is lower than target (block's PoW)
  • timestamp is > median of last 11 blocks
  • timestamp is < current time + 4 hours

Storage

To save on storage costs, the blockheader data is emitted as an Event from the program, and only sha256 fingerprint of that blockheader data is stored on-chain. Another storage costs saving mechanism used is pruning - only last X block headers are kept stored on-chain in a ring buffer. Where X is the pruning factor.

Transaction verification

As merkle roots of the bitcoin blocks from blockheaders are known, they can be used to verify that any transaction was included in a block by its transaction id and merkle proof. However due to pruning, this also means that transaction verification can only be done for transactions confirmed in the last X blocks. Where X is the pruning factor.

Forks

Should a fork on the bitcoin main chain occur, the program provides a way for anyone to submit fork blockheaders, and they automatically become the main chain when their chain work is greater than that of a current main chain in the bitcoin relay program. This can be done in 2 ways, because of solana's ~1.2kB transaction size limitation:

  • smaller forks of <6 blocks can be submitted in a single transaction
  • larger forks of >=6 blocks must be submitted in multiple transactions by opening a new account storing the data

Possible attack vectors

Fake block headers

A party might start submitting valid bitcoin blockheaders to the bitcoin relay and not on the bitcoin main chain. However as those blockheaders must be valid a non-trivial amount of resources must be expedited on PoW. Cost of such an attack depends on whether there is at least 1 honest party submitting blockheaders to the relay:

  • if there are no honest parties, the cost of faking 1 blockheader can be expressed as value of lost bitcoin block reward incurred due to not submitting the blockheader to the main chain, which is currently 6.25 BTC ~ 140k usd
  • if there is at least 1 honest party, the adversary party needs to capture at least 51% of the bitcoin hashing power to overrun the honest chain submitted by honest party

btcrelay-sol's People

Contributors

adambor avatar

Stargazers

Miao Jiang avatar Kunpeng avatar

Watchers

 avatar

Forkers

nickgarfield

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.