GithubHelp home page GithubHelp logo

dakk / bitcoinml Goto Github PK

View Code? Open in Web Editor NEW
43.0 4.0 1.0 423 KB

Bitcoin data-structures library for OCaml

Home Page: https://dakk.github.io/bitcoinml/

License: MIT License

Makefile 0.33% OCaml 99.67%
bitcoin ocaml ocaml-library bitcoin-library blockchain cryptocurrency segwit segwit-transactions

bitcoinml's People

Contributors

dakk avatar lojikil avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

bitcoinml's Issues

Script Signature abstract type

Instead of integrating huge external deps, we create a signature engine abstraction; so:

  • bitcoinml alone can't verify scripts
  • a bitcoinml user can provide his custom Signature implementation (ie wrapping secp256k1), if needs script verification

Integrate travis-ci

Travis-ci could reduce the number of error I made publishing new releases on opam-repository.

Merkle root

Provide a module to compute a tx list merke root:

module Merkle : sig
	type t
	val of_txs : Tx.t list -> t
end

Bitcoin network proto

Integrate bitcoin network protocol message parse and serialize.

  • Move message.ml* from caravand to proto.ml* in bitcoinml
  • Docs
  • Integrate tests

Lazy block parsing

Many times it's not necessary to parse the full block but only the headers; so we could define a new type:

type Block.l = {
   header: Header.t;
   txs: Tx.t list Lazy.t;
}

In case of fork, break the glass

In case of 2x fork, we need to add a new network for 2x, and update checkpoint list for both chains (just for redundancy, letchain doesn't need that)

TransactionBuilder

Provide the ability to create a raw transaction, sign it with a keypair, and create the complete tx.

Segwit transaction format

The upcoming activation of segwit, push the need of segwit transaction format support

https://bitcoincore.org/en/segwit_wallet_dev/#transaction-serialization
https://bitcoin.stackexchange.com/questions/49097/what-does-a-segregated-witness-transaction-look-like

The Tx could be a structure like now, but with optional witness fields:

type Witness.t = {
	marker		: uint32;
	flag			: uint32;
	witness		: field list;
	size		: int;
}

type t = {
	hash			: Hash.t;
	version		: int32;
	txin 			: In.t list;
	txout 		: Out.t list;
	locktime		: uint32;

	witness		: Witness.t option;
	size			: int;
} [@@deriving sexp]

The witnessScript reside in a different parte of the tx, but every witnessScript is associated to one txin; could be a smart trick to inflate the wintnessScript inside the txin.

Use this: http://n.bitcoin.ninja/checktx for examples and tests

Tasks:

  • Witness abstract data-structure
  • Parsing
  • Serialization
  • Tx hash and tx size for segwit
  • Tx vsize
  • Witness tests
  • Witness tests - P2WPKH
  • Witness tests - P2WSH
  • Witness tests - P2SH(WPKH)
  • Witness tests - P2SH(WSH)
  • Witness tests - Hash and sizes
  • Block hash and block size for segwit

Wrong hash for segwit transactions

for:
020000000001018123858b74cc156be287dbac5442508483bfe6d9a4165712e5bd0b65a9120a210100000000ffffffff0250c30000000000002200207110c7d8cf7bfa8c93d190d699571c128eac6e922ce0ca3bdf0bc3495109dffc14d606000000000016001499b9280ca4f5eeea13e51770e7a30eb512ed473702483045022100952394943abe1e75d20d4b20622416d0618585bb3266a8122894024a7cfcc6c8022051465780d56717548951fad188fe038f8820c1e054d3a9b90533084cb06625cf012102a3a3756f1e06a4b4764cc3fcf2e804257727e4431b548741f8be057f1628e39900000000

d80c367ee53355ff52bb818545e73f806965a056d2085771e5c3c994af9f640a
but library returns:
df986955f737c0d90fbedc85580bc21ec3951b12dc68b8c611e48c9d4386bb74

Address

Create a module for address representation

Script & segwit

  • Modify Script apis to allow passing of segwit stack data
  • Enable spendable_by for witness addresses
  • Provide a Script.verify working implementation
  • Primitives for creating common scripts
  • Testing framework for script verification
  • Integrate secp verifier on test suite

Varint failure on block 585488

Thread 1 killed on uncaught exception Match_failure("src/varint.ml", 6, 2)
Raised at file "src/varint.ml", line 6, characters 2-125
Called from file "src/varint.ml", line 18, characters 17-36
Called from file "src/tx.ml", line 133, characters 22-39
Called from file "src/tx.ml", line 222, characters 22-41
Called from file "src/tx.ml", line 261, characters 41-74
Called from file "src/tx.ml", line 345, characters 61-68
Called from file "src/block.ml", line 91, characters 12-72
Called from file "camlinternalLazy.ml", line 27, characters 17-27
Re-raised at file "camlinternalLazy.ml", line 34, characters 4-11
Called from file "src/blockchain/chain.ml", line 367, characters 9-22

Test coverage

  • Merkle tree root real bitcoin test
  • Block.Header.check_target tests
  • Segwit transaction tests
  • Multi-input witness txs
  • Lazy block parsing

Script templates

For better handling script templates, we create template modules for each standard script template:

  • Pubkey - input
  • Pubkey - output
  • Pubkey - test
  • Pubkeyhash - input
  • Pubkeyhash - output
  • Pubkeyhash - test
  • Scripthash - input
  • Scripthash - output
  • Scripthash - test
  • Multisig - input
  • Multisig - output
  • Multisig - test
  • Witnessscripthash - input
  • Witnessscripthash - output
  • Witnessscripthash - test
  • Witnesspubkeyhash - input
  • Witnesspubkeyhash - output
  • Witnesspubkeyhash - test
  • WItnesscommitment - output
  • Witnessscripthash - test

Update doc with fun signatures

  • address.mli
  • base58.mli
  • block_lazy.mli
  • block.mli
  • hash.mli
  • merkle.mli
  • params.mli
  • script_verify.mli
  • script.mli
  • tx.mli
  • varint.mli
  • main

Address prefix for testnet

The addresses are always converted with mainnet prefixes; we need to extends Tx.Out.spendable_by from bitcoinml with a prefix optional argument.

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.