npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@interlay/btc-relay-sol

v0.3.13

Published

BTC Relay in Solidity

Downloads

4

Readme

BTC-Relay

Relevant Repositories

Our libs:

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

External libs:

  • Summa Bitcoin SPV library: https://github.com/summa-tx/bitcoin-spv/tree/master/solidity
  • Summa Bitcoin Relay: https://github.com/summa-tx/relays/tree/master/solidity
  • Original [Deprecated] BTC-Relay: https://github.com/ethereum/btcrelay/tree/develop/fetchd

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

| Function | Gas | Description | |--------------------------|---------|--------------| | constructor | 1796743 | Genesis | | submitBlockHeader | 105299 | 1st Header | | submitBlockHeader | 105311 | 2nd Header | | submitBlockHeader | 105287 | 3rd Header | | submitBlockHeader | 105275 | 4th Header | | submitBlockHeader | 105299 | 5th Header | | submitBlockHeader | 105263 | 6th Header | | submitBlockHeaderBatch | 464777 | Combined | | verifyTx | 62884 | Inclusion |

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.

| Interlay | Summa | Purpose | Description | |----------|---------|-----------|------------------------------| | 616782 | 403903 | Submit | 8 Block Headers | | 2397012 | 1520844 | Submit | 32 Block Headers | | 30462 | 32731 | Inclusion | Coinbase - Tx Depth 1 | | 67240 | 69510 | Inclusion | Heavy (230 Txs) - Tx Depth 1 | | 67326 | 79540 | Inclusion | Tx Depth 6 | | 67326 | 102364 | Inclusion | Tx 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