Socket
Socket
Sign inDemoInstall

@interlay/btc-relay-sol

Package Overview
Dependencies
60
Maintainers
4
Versions
16
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @interlay/btc-relay-sol

BTC Relay in Solidity


Version published
Weekly downloads
17
increased by1600%
Maintainers
4
Install size
23.4 MB
Created
Weekly downloads
 

Readme

Source

BTC-Relay

Relevant Repositories

Our libs:

  • https://github.com/interlay/compressed-inclusion-proofs
  • https://github.com/crossclaim/btcrelay-sol

External libs:

Background

Chain Relays

Chain relays are on-chain programs or smart contracts deployed on a blockchain A capable of reading and verifying the state of another blockchain B. The underlying technical design and functionality is comparable to that of SPV-Clients. That is, a chain relay stores and maintains block headers of chain B on chain A and allows to verify transaction inclusion proofs. Summarizing, the two main functionalities a chain relay must/should provide are: consensus verification and transaction inclusion verification.

Read more about chain relays in the XCLAIM paper (Section V.B descibes the basic concept of chain relays, while Appendix B provides a formal model of the required functionality for PoW chain relays.).

Architecture

This project is an implementation of a chain relay for Bitcoin on Ethereum. The first implementation of a BTC relay was implemented in Serpent and can be found here. However, as Serpent is outdated (last commit: December 2017), this project aims to implement an updated version in Solidity.

Installation

Install dependencies:

yarn install

Build the contracts and interfaces:

yarn build

Testing

Run the tests:

yarn test

Run with eth-gas-reporter:

export COINMARKETCAP_API_KEY=*****
npx buidler node 
yarn test --network localhost

Gas Costs

npx buidler run scripts/metrics.ts
FunctionGasDescription
constructor1796743Genesis
submitBlockHeader1052991st Header
submitBlockHeader1053112nd Header
submitBlockHeader1052873rd Header
submitBlockHeader1052754th Header
submitBlockHeader1052995th Header
submitBlockHeader1052636th Header
submitBlockHeaderBatch464777Combined
verifyTx62884Inclusion

Summa Relay

Summa have also developed a Bitcoin relay in Solidity. There are a number of differences between the two approaches however. As summarized in the table below, their block submission is significantly cheaper compared to ours. This is primarily due to their more restrictive use of storage and separation of functionality - block submission, difficulty adjustment and fork selection are all separate calls. However, checking transaction inclusion is slightly more involved as the implementation needs to recurse backwards through all ancestors.

InterlaySummaPurposeDescription
616782403903Submit8 Block Headers
23970121520844Submit32 Block Headers
3046232731InclusionCoinbase - Tx Depth 1
6724069510InclusionHeavy (230 Txs) - Tx Depth 1
6732679540InclusionTx Depth 6
67326102364InclusionTx Depth 32

There are two primary motivations for our higher cost in block submission:

  1. The relay should be self-healing, requiring minimal user intervention.
  2. Constant time lookup - given a height we should be able to instantly verify inclusion.

Deployments

yarn deploy

Ropsten

Keywords

FAQs

Last updated on 13 Oct 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc