Compare commits

...

526 Commits
0.13 ... master

Author SHA1 Message Date
Elichai Turkel 8a40c7b51a
Merge pull request #432 from taoweicn/patch-1
Remove duplicate code
2020-07-02 11:56:56 +03:00
Andrew Poelstra 4af18729b0
Merge pull request #431 from sgeisler/2020-06-01-ruy-compat
Fix ruy rust 1.22 inccompatibility
2020-06-29 12:51:17 +00:00
Sebastian Geisler 139fc02592 Fix #430: ruy rust 1.22 inccompatibility 2020-06-04 22:05:16 +02:00
Tao Wei ed76e0823b
Remove duplicate code
Duplicated with L38
2020-06-03 17:17:13 +08:00
Elichai Turkel f4e26caa94
Merge pull request #415 from shesek/merkleblock-txids
Allow to construct MerkleBlock using the header and txids
2020-05-24 16:32:17 +03:00
Andrew Poelstra 7efde3ae47
Merge pull request #419 from elichai/2020-03-description
Deprecate Error::description
2020-05-23 17:26:38 +00:00
Andrew Poelstra 31a576020b
Merge pull request #425 from TheBlueMatt/2020-04-uint-fuzz
Add fuzz target comparing native u128 to our Uint type
2020-05-21 23:17:35 +00:00
Elichai Turkel 1c88be4df5
Merge pull request #422 from rust-bitcoin/2020-04-remove-alloc
Remove some needless allocations
2020-05-19 13:20:34 +03:00
Elichai Turkel af31017eb1
Remove the cursor overhead, write is implemented on vec these days 2020-05-19 12:57:39 +03:00
Andrew Poelstra c44bad87b2
Merge pull request #424 from jrawsthorne/wtxid-inv
Fix: Change WitnessTransaction inv type to use txid
2020-05-14 13:51:16 +00:00
Matt Corallo 604f1aa56e Add fuzz target comparing native u128 to our Uint type 2020-04-30 19:22:49 -04:00
Steven Roose a9173d61d3
Merge pull request #375 from canndrew/fix-serde-struct-macros
Fix serde struct macros deserialization impls
2020-04-19 19:56:27 +01:00
Jake Rawsthorne 81c061a68c Change WitnessTransaction inv type to use txid 2020-04-14 14:11:44 +01:00
Elichai Turkel 654232a3dc
Deprecate Error::description 2020-04-13 02:15:28 +03:00
Elichai Turkel 25cb3d3539
Remove alloc when hashing for Bitcoin message signing format 2020-04-12 19:04:13 +03:00
Elichai Turkel 41e4471721
Remove alloc when hashing sighash 2020-04-12 19:04:12 +03:00
Andrew Poelstra c3a7d1b27c
Merge pull request #417 from shesek/202003-block-size-weight
Add Block::get_size() and Block::get_weight()
2020-04-07 14:12:15 +00:00
Andrew Poelstra 8d859cf54c
Merge pull request #308 from elichai/2019-08-clippy
Cargo clippy changes
2020-04-05 16:26:07 +00:00
Elichai Turkel a627457032
Merge pull request #412 from stevenroose/export-denom
Export the util::amount::Denomination type
2020-04-05 10:56:57 +03:00
Andrew Poelstra 78183a31e2
Merge pull request #411 from tnull/handshake_example
Added a simple handshake example.
2020-04-04 21:34:57 +00:00
Elichai Turkel 2cc88a99aa
Removed PartialEq,PartialOrd impls, shouldn't be manually impl when Hash is derived 2020-03-29 17:15:15 +03:00
Elichai Turkel a473d01b17
Made some idiomatic changes 2020-03-29 17:15:15 +03:00
Elichai Turkel 3f2d428706
Remove needless references 2020-03-29 17:15:14 +03:00
Elichai Turkel 16eb81e1f7
Replaced slow vec initialization, and dual calls to hashmap 2020-03-29 17:10:27 +03:00
Nadav Ivgi 94032f6817 Add Block::get_size() and Block::get_weight() 2020-03-27 21:54:46 +03:00
Steven Roose a148e06736
Merge pull request #416 from shesek/202003-tx-size
Add Transaction::get_size()
2020-03-25 16:18:23 +00:00
Nadav Ivgi f3b5a7187c
Add Transaction::get_size() 2020-03-23 19:48:41 +02:00
Nadav Ivgi 65efc5cd37 Allow to construct MerkleBlock using the header and txids
Co-Authored-By: Elichai Turkel <elichai.turkel@gmail.com>
2020-03-21 18:23:08 +02:00
Elias Rohrer 827d98d821 Fixed for rust 1.22.0. 2020-03-03 12:18:37 +01:00
Elias Rohrer aa46618da7 Intialize stream reader only once. 2020-03-03 10:48:01 +01:00
Elias Rohrer 40431f3d4f Formatted. 2020-03-03 10:48:01 +01:00
Elias Rohrer b5f5abe0b4 Removed pre-configured IP, now takes IP as argument. 2020-03-03 10:48:01 +01:00
Elias Rohrer 62f5f8e3f9 Removed explicit dependency on rand. 2020-03-03 10:48:01 +01:00
Elias Rohrer 2852083ff3 Using write_all(). 2020-03-03 10:48:01 +01:00
Elias Rohrer c4f0056856 No clone needed. 2020-03-03 10:48:01 +01:00
Elias Rohrer 9d212da0ba Added a simple handshake example. 2020-03-03 10:48:01 +01:00
Steven Roose 826b2e0e2a
Export the util::amount::Denomination type 2020-02-28 11:51:44 +00:00
Steven Roose 9cff794a09
Merge pull request #399 from elichai/2020-01-tests
Add tests based on mutagen outputs
2020-02-24 19:29:19 +00:00
Elichai Turkel 07b30c7fac
Mutation testing: amount: Added tests to fix mutation misses 2020-02-23 15:59:26 +02:00
Elichai Turkel ab6e20c87e
Fix an overflow bug in SignedAmount to_string/fmt 2020-02-23 15:59:26 +02:00
Elichai Turkel abc70781e7
Fix a logic problem in base58 (isn't a real bug) 2020-02-23 15:59:26 +02:00
Elichai Turkel 1d01262d5c
Mutation testing: base58: Added tests to "fix" mutation misses 2020-02-23 15:59:26 +02:00
Elichai Turkel 5d276caf95
Mutation testing: encode: Added tests to "fix" mutation misses 2020-02-23 15:59:26 +02:00
Elichai Turkel eb7369b1db
Simlify consensus_encode vectors 2020-02-23 15:59:23 +02:00
Andrew Poelstra 1b946b0034
Merge pull request #378 from wbnns/readme-links
readme: Add links to CHANGELOG.md and LICENSE
2020-01-24 19:41:29 +00:00
Andrew Poelstra a2bfcb5a89
Merge pull request #395 from pandoracore/fix-construct_uint
Improving `construct_uint` macro
2020-01-24 19:39:32 +00:00
Andrew Poelstra 659f2edb3b
Merge pull request #381 from elichai/2020-01-hex
Remove the hex dependency
2020-01-24 19:14:20 +00:00
Andrew Poelstra bf6828c47f
Merge pull request #398 from elichai/2020-01-json
Yet another MSRV breaking change
2020-01-23 15:20:42 +00:00
Elichai Turkel 399950bf71
Restrict serde-json dev dependency to less than 1.0.45 2020-01-23 11:45:59 +02:00
Will Binns 410e45f378
readme: Add links to CHANGELOG.md and LICENSE 2020-01-23 10:45:18 +01:00
Dr Maxim Orlovsky 9c0f4b1a60 Fixing namespaces in `impl_hashencode` 2020-01-22 13:23:09 +01:00
Steven Roose 930a6ca1dc
Merge pull request #390 from instagibbs/bip143_sighash_notall
Add bip143 sighash support for other flags
2020-01-21 23:26:17 +00:00
Gregory Sanders d1c5c7b08d Deprecate SigHashComponents 2020-01-21 09:50:41 -05:00
Gregory Sanders 908aff50bc Add bip143 sighash support for other flags 2020-01-21 09:50:41 -05:00
Dr Maxim Orlovsky f3e762b555 Improving `construct_uint` macro 2020-01-21 13:16:34 +01:00
Elichai Turkel c19b736566
Remove the hex dependency 2020-01-20 18:50:02 +02:00
Elichai Turkel 5452260884
Merge pull request #392 from instagibbs/wit_scale
Add, use WITNESS_SCALE_FACTOR constant
2020-01-20 18:02:59 +02:00
Gregory Sanders 2916685ca6 small Transaction test cleanup 2020-01-14 11:14:23 -05:00
Gregory Sanders 3624ee82c8 Use witness scaling constant in get_weight 2020-01-14 11:14:23 -05:00
Gregory Sanders 09c0e7fbde Add WITNESS_SCALE_FACTOR constant 2020-01-14 11:14:23 -05:00
Steven Roose e76803be85
Merge pull request #385 from stevenroose/no-bitcoin-hash
Remove the BitcoinHash trait
2020-01-13 16:45:31 +01:00
Steven Roose 8e52b8ce4d
Remove the BitcoinHash trait
Replaced by a `block_hash` method on both `Block` and `BlockHeader`.
2020-01-10 11:34:16 +00:00
Andrew Poelstra 2cba81935d
Merge pull request #380 from stevenroose/bump-0.23
Release v0.23.0
2020-01-09 17:02:43 +00:00
Steven Roose 2326dd6a82
Update secp256k1's rand feature to rand-std 2020-01-09 11:11:49 +00:00
Steven Roose 2f89c943e1
Release v0.23.0 2020-01-07 19:27:05 +00:00
Steven Roose 7587c4bf71
Merge pull request #379 from kiminuo/feature/network_address_debug
Improve fmt::Debug for network/Address
2020-01-07 17:39:14 +00:00
Steven Roose e6bc3ec974
Merge pull request #366 from stevenroose/bump-secp
Release v0.22.0
2020-01-07 16:05:29 +00:00
kiminuo 9e223988fa Improve fmt::Debug for network/Address
Original output:

  "Address {services: ServiceFlags(9), address: [0, 0, 0, 0, 0, 65535, 2560, 1], port: 8333}"

New output:

  * for IPv4: "Address {services: ServiceFlags(NETWORK|WITNESS), address: 10.0.0.1, port: 8333}"
  * for IPv6: "Address {services: ServiceFlags(NETWORK_LIMITED), address: fd87:d87e:eb43::ffff:a00:1, port: 8333}"
2020-01-07 12:30:47 +01:00
Andrew Cann d156c65778 Fix serde struct macros deserialization impls
The Deserialize impls generated by serde_struct_impl and
serde_struct_human_string_impl need to be able to handle serialization
formats which serialize structs as sequences (such as bincode).

This commit adds visit_seq methods to the Visitor types defined by these
macros, in addition to the existing visit_map methods. The
implementation is taken directly from the serde docs:
https://serde.rs/deserialize-struct.html
2020-01-07 13:19:22 +08:00
Steven Roose 448b45a3ba
Bump version to v0.22.0 2020-01-06 22:36:15 +00:00
Steven Roose 0398ef8f48
Update changelog for v0.22.0 2020-01-06 22:36:14 +00:00
Andrew Poelstra 50f3a60712
Merge pull request #349 from pandoracore/hashtypes
Hash new types as specified in #284
2020-01-05 00:46:45 +00:00
Dr Maxim Orlovsky 5fc24dea33 Multiple fixes for hash types and their computing
Unit test for wtxid and SegWit transactions
2020-01-01 13:54:23 +01:00
Dr Maxim Orlovsky 0abe15b1f6 Moving from BitcoinHash to Wtxid for Transactions 2020-01-01 13:52:20 +01:00
Dr Maxim Orlovsky f5a8087105 New hash types: MerkleRoot/Branch, WitnessCommit, SigHash, FilterHash 2020-01-01 13:50:17 +01:00
Dr Maxim Orlovsky 4746ccb88e Final work on Txid and other hashes
Fixing issue with external dependency and hash_newtype macro implementation

Reverting back to the bitcoin_hashes crate after new version release
2020-01-01 13:48:28 +01:00
Dr Maxim Orlovsky d20ab1dbc4 Switching to XpubIdentifier 2020-01-01 13:46:44 +01:00
Dr Maxim Orlovsky 5f4f629bb1 Replaced all hash160, sha256 and sha256d with the new hash types throughout the code
Embedding Txid's in the doc exaples
2020-01-01 13:44:34 +01:00
Dr Maxim Orlovsky 5ef39e34fa Implementing (W)Pubkey/ScriptHash and BlockHash 2020-01-01 13:42:22 +01:00
Dr Maxim Orlovsky ec92a05682 New HashTypes defined according to #284 (WIP), Txid is completed 2020-01-01 13:41:42 +01:00
Steven Roose e2caebc42e
Merge pull request #370 from elichai/2019-12-rawmessage
Add a full round test for RawNetworkMessage
2019-12-23 12:30:11 +01:00
Andrew Poelstra efd2168364
Merge pull request #368 from mauzmorose/bip157-service-flag
bip157: Add NODE_COMPACT_FILTERS Service Flag
2019-12-22 16:48:16 +00:00
Elichai Turkel bc2ba5bb12
Add a full round test for RawNetworkMessage 2019-12-22 14:01:12 +02:00
Elichai Turkel 4c3ad9d233
Merge pull request #367 from mauzmorose/fix-bip157-message
bip157: Fix typo on getcfcheckpt command string
2019-12-22 13:59:54 +02:00
Sofiane Baltaci 8617de51c8 Adapt service_flags_test to reflect changes 2019-12-21 03:36:47 +01:00
Sofiane Baltaci 43789b1d5a Add COMPACT_FILTERS service flag to ServiceFlags fmt::Display impl 2019-12-21 03:06:03 +01:00
Sofiane Baltaci b40d94641d Add bip157 NODE_COMPACT_FILTERS Service Flag 2019-12-21 02:39:30 +01:00
Sofiane Baltaci 2605141ada Fix typo on getcfcheckpt command string 2019-12-20 23:47:40 +01:00
Andrew Poelstra a643ac485c
Merge pull request #364 from kiminuo/feature/explicit-serviceFlags
Convert numeric representation of ServiceFlags to bitwise OR of the f…
2019-12-12 13:35:01 +00:00
kiminuo 74285738ce Convert numeric representation of ServiceFlags to bitwise OR of the flag names
The changes affect only tests
2019-12-12 00:11:13 +01:00
Steven Roose 0f4f060e8b
Merge pull request #363 from kiminuo/feature/remove-old-todos
Remove two old TODO comments [nit]
2019-12-11 16:53:20 +00:00
Steven Roose 024557fe47
Merge pull request #357 from stevenroose/command-str
Various optimizations of the network code
2019-12-11 15:38:52 +00:00
kiminuo 269ddb6f07 Remove some old TODO comments 2019-12-11 08:26:04 +01:00
Andrew Poelstra f6f4ea79d6
Merge pull request #360 from kiminuo/feature/issue-350
Feature/issue 350
2019-12-10 20:52:21 +00:00
Steven Roose a8f14af24d
Prevent panic on oversized CommandString's 2019-12-10 20:20:04 +00:00
Andrew Poelstra fef3390d78
Merge pull request #329 from stevenroose/overloaded-encode-error
Overloaded encode error
2019-12-10 13:23:56 +00:00
Steven Roose 617c07d796
Remove encode::Error::ByteOrder
Functions from the byteorder crate only return downstream io errors on
io calls.
2019-12-09 14:19:11 +00:00
Steven Roose 5f4555bfac
Remove util::misc::hex_bytes in favor of bitcoin_hashes::hex 2019-12-09 14:19:09 +00:00
Steven Roose 0469453da6
Use psbt::Error in PartiallySignedTransaction::from_unsigned_tx 2019-12-09 14:19:07 +00:00
Steven Roose 1eeaccc92e
Add encode::Error::NonMinimalVarInt variant 2019-12-09 14:19:05 +00:00
Steven Roose d02318f423
Remove deprecated std::error::Error::description 2019-12-09 14:18:37 +00:00
Steven Roose 5373428510
Drop unused encode::Error::Secp256k1 variant 2019-12-09 14:17:41 +00:00
Steven Roose 725884bab5
Introduce key::Error 2019-12-09 14:17:39 +00:00
Andrew Poelstra 1d209362eb
Merge pull request #361 from stevenroose/inventory-hash
Implement std:#️⃣:Hash for Inventory
2019-12-09 00:43:03 +00:00
Steven Roose fe3397399e
Add Copy to InvType enum 2019-12-08 20:58:52 +00:00
Steven Roose 671b3173c8
Make internals for CommandString private
The From traits and AsRef and Display implementations
let you do all you want.
2019-12-08 20:58:50 +00:00
Steven Roose 83f55b7f1d
Follow Rust std practice for RejectReason enum 2019-12-08 20:58:49 +00:00
Steven Roose 5c84e9671f
Optimize Reject message 2019-12-08 20:58:46 +00:00
Steven Roose c30d6d12ab
Implement Encodable for Cow<'static, str> 2019-12-08 20:57:46 +00:00
Steven Roose e37fdb7319
Also have getter for CommandString 2019-12-08 20:57:07 +00:00
Steven Roose e2eed78964
nit: Reject is implemented 2019-12-08 20:57:05 +00:00
Steven Roose 50a37f415e
Implement From<String> and From<&'static str> for CommandString 2019-12-08 20:57:04 +00:00
Steven Roose 36838b7918
Make network::CommandString a Cow on 'static 2019-12-08 20:57:03 +00:00
Steven Roose bac3e0308b
Add command method to NetworkMessage
Also make the return type an &'static str
2019-12-08 20:57:00 +00:00
Steven Roose b4c4a9658d
Implement std:#️⃣:Hash for Inventory 2019-12-08 17:49:11 +00:00
Kiminuo d8223bb73c Update travis-fuzz.sh to check that fuzz input file names are allowed on Windows systems 2019-12-08 16:42:43 +00:00
Kiminuo 1b617b8f54 Rename fuzz input file names to allow repo cloning on Windows [fixes #350] 2019-12-08 16:42:43 +00:00
Andrew Poelstra 854718219e
Merge pull request #345 from stevenroose/serviceflags
Add ServiceFlags type
2019-12-06 21:31:46 +00:00
Andrew Poelstra 65cb18d583
Merge pull request #341 from ccdle12/txin-impl-default
Add default trait implementation for TxIn
2019-12-06 21:21:49 +00:00
Steven Roose 3e1e4f92b7
Merge pull request #337 from TheBlueMatt/2019-10-less-deps
Drop hex and byteorder (non-test) deps (and disable useless lints)
2019-12-06 15:38:58 +00:00
Steven Roose 1edc436f8f
Add an extensive Display implementation for ServiceFlags 2019-12-05 20:13:45 +00:00
Elichai Turkel 0ae99100eb
Merge pull request #343 from stevenroose/nit-versionmessage
Nit in VersionMessage documentation
2019-12-05 18:19:43 +02:00
Matt Corallo 824d52fe87 Disable useless lints 2019-12-05 10:41:00 -05:00
Matt Corallo acb43af981 Drop byteorder dependency
Taking an external dependency just to convert ints to byte arrays
is somewhat of a waste, especially when Rust isn't very aggressive
about doing cross-crate LTO.

Note that the latest LLVM pattern-matches this, and while I haven't
tested it, that should mean this means no loss of optimization.
2019-12-05 10:41:00 -05:00
Matt Corallo f1f7718b6c Drop (non-test/serde) hex dep in favor of bitcoin_hashes' fn's 2019-12-05 10:40:59 -05:00
Steven Roose 6ce582bed6
Merge pull request #344 from thomaseizinger/expose=secp256k1-features
Expose secp256k1 features
2019-12-04 23:42:54 +00:00
Steven Roose de18e926c1
Use ServiceFlags type in existing API 2019-12-04 23:28:25 +00:00
Steven Roose fdf4b2f74e
Add ServiceFlags type 2019-12-04 23:28:23 +00:00
Andrew Poelstra 885fc39f48
Merge pull request #347 from elichai/patch-1
Adding MSRV to the readme
2019-11-29 21:26:23 +00:00
Elichai Turkel 62a7f26e9b
Update README.md 2019-11-23 18:44:19 +02:00
Thomas Eizinger 7be4ac0403
Include secp256k1 'serde' feature flag in 'use-serde' feature 2019-11-21 12:06:06 +11:00
Thomas Eizinger 24bb6590d6
Expose secp256k1 'rand' feature flag
By exposing this, we can use the 'rand' dependency of secp256k1
in a project that only depends on rust-bitcoin without having to
add a separate dependency in order to activate the feature flag.
2019-11-21 12:05:46 +11:00
Steven Roose 33ba7eaa36
Nit in VersionMessage documentation 2019-11-19 22:58:49 +00:00
Chris Coverdale 0586ed94c4 Add default trait implementation for TxIn 2019-11-17 16:41:14 +00:00
Andrew Poelstra 700ed54efc
Merge pull request #340 from TheBlueMatt/2019-11-4m-limit
Drop message decode max length to 4_000_000
2019-11-12 20:42:51 +00:00
Matt Corallo fe917765c0 Drop message decode max length to 4_000_000
It has been a long time since Bitcoin's maximum network message
length was 32MB, so we should follow suit. This is also an important
DoS limit, so we should limit it as much as possible.
2019-11-06 16:29:21 -05:00
Andrew Poelstra c8ac25219a
Merge pull request #334 from apoelstra/2019-10-version-0.21
bump version to 0.21.0
2019-10-03 16:09:38 +00:00
Andrew Poelstra fb6f50b0ea bump version to 0.21.0 2019-10-02 15:42:58 +00:00
Carl Dong 242ce14cee
Add reject message (#323)
Add reject message
2019-09-30 14:52:19 +00:00
Dr. Maxim Orlovsky 4b1d4edc14 Improvements to `StreamReader` (#318)
* Generalizing StreamReader to support arbitrary data structures

* Using Read trait and adding test cases
2019-09-23 08:31:52 +02:00
practicalswift 0b08978af2 Fix incorrect documentation for is_p2pk(...) (#331) 2019-09-21 13:33:44 +02:00
Tamas Blummer 1b0e31c233 fixed typo 2019-09-21 13:31:03 +02:00
Tamas Blummer 960e3da75b remove #repr on RejectReason
and typo fix
2019-09-10 20:11:25 +02:00
Steven Roose de9ccdec89
Merge pull request #321 from tamasblummer/add_serde_to_block
[TRIVIAL] enable serde serialization for block and blockheader
2019-09-05 09:36:57 +01:00
Tamas Blummer c93b1ed8ce add reverse mapping 2019-09-03 19:59:48 +02:00
Tamas Blummer 3266c192b6 add reject message 2019-08-27 13:42:46 +02:00
Tamas Blummer 38d5ae4e3f enable serde serialization for block and blockheader 2019-08-24 14:26:18 +02:00
Carl Dong 24361dd2f1
Merge pull request #298 from tamasblummer/upgrade_secp_bitcoinconsensus
upgrade to secp256k1 0.15 and bitcoinconsensus 0.17
2019-08-23 14:18:05 -04:00
Tamás Blummer f01568c85a
use lambda instead of a hash map to find spent outputs (#319)
* use lambda instead of a hash map to find spent outputs
* check for double use of an input
2019-08-23 18:49:31 +02:00
Tamas Blummer 78a4f09861 nit 2019-08-22 16:21:16 +02:00
Tamas Blummer 14e61df578 move rand feature of secp256k1 into dev-dependencies 2019-08-22 08:58:58 +02:00
Tamas Blummer d91fa99df0 add CHANGELOG.md entry 2019-08-21 20:59:40 +02:00
Tamas Blummer 76ec4ad820 single line dependencies. setting cargo version to 0.20.0 2019-08-21 20:13:53 +02:00
Tamas Blummer 9f3e355c5c upgrade to secp256k1 0.15 and bitcoinconsensus 0.17 2019-08-21 19:04:40 +02:00
Andrew Poelstra 8ff904c747
Merge pull request #317 from elichai/2019-08-serde
Remove serde-derive as a dependency
2019-08-20 18:17:22 +00:00
Elichai Turkel 837030b04f
Bump version to 0.19.2 2019-08-20 13:28:58 -04:00
Elichai Turkel 89f73ea686
Add a test for testing as a dependency 2019-08-19 13:29:50 -04:00
Elichai Turkel 52ff97cddc
Deny unused imports and remove unneeded 2019-08-19 13:29:43 -04:00
Elichai Turkel df1a5fd6b5
Remove serde-derive as a dependency 2019-08-19 13:29:38 -04:00
Andrew Poelstra 4556c9c570
Merge pull request #316 from elichai/2019-08-pin-export
Pin serde and re-export bech32
2019-08-16 21:22:11 +00:00
Elichai Turkel 0153061647
Bump version to 0.19.1 2019-08-16 16:08:36 -04:00
Elichai Turkel 747e9ce75c
Pinned serde version and re-export bech32 2019-08-16 16:08:14 -04:00
Andrew Poelstra fbc85105b3
Merge pull request #314 from stevenroose/release-0.19.0
Release v0.19.0
2019-08-16 19:29:03 +00:00
Steven Roose 6651cf942b
Merge pull request #315 from elichai/2019-08-deps
Make secp256k1/rand a dev-dependency
2019-08-16 19:05:02 +01:00
Steven Roose 5a4b5826d7
Add CHANGELOG items about dependencies 2019-08-16 19:00:02 +01:00
Elichai Turkel 3bab3e7ea2
make secp256k1/rand a dev-dependency 2019-08-16 13:18:15 -04:00
Steven Roose a472039301
Release v0.19.0 2019-08-16 16:41:08 +01:00
Carl Dong 166e2bd121
Export some dependencies (#289)
Export some dependencies
2019-08-16 11:19:08 -04:00
Steven Roose c01172780b
Re-export bitcoin_hashes and secp256k1 dependency 2019-08-16 15:52:58 +01:00
Steven Roose 48f4c1989f
Rename bitcoin_hashes dependency to hashes 2019-08-16 15:52:27 +01:00
Carl Dong 5f4de0fb46
Refactor Address (#255)
Refactor Address
2019-08-16 10:22:42 -04:00
Steven Roose 3c390ceb93
Add fuzzer for Address::from_script 2019-08-15 22:29:10 +01:00
Steven Roose 09a65023a2
Add tests for p2shwpkh and p2shwsh 2019-08-15 22:29:09 +01:00
Steven Roose 170abaa82f
Use the new bech32 functions 2019-08-15 22:29:06 +01:00
Steven Roose 3a93f8522c
Format address module 2019-08-15 22:28:46 +01:00
Steven Roose 8de13a3915
Redo the BIP-173 test vectors
Before, non-version-zero segwit addresses were not included.
2019-08-15 22:28:27 +01:00
Steven Roose e469fec839
address: Drop error::Error::description impl 2019-08-15 22:28:25 +01:00
Steven Roose bfdcfee28e
Add Address::from_script constructor 2019-08-15 22:28:20 +01:00
Steven Roose 33e8ba3c7e
Extract roundtrip method from Address tests 2019-08-13 08:47:17 +01:00
Steven Roose 8804a41f1f
Add AddressType enum 2019-08-13 08:47:15 +01:00
Steven Roose 7e0d997150
Remove unused encode::Error variant 2019-08-13 08:47:13 +01:00
Steven Roose 385a657974
Refactor Address
- use AddressError instead of encode::Error
- replace using bech32-bitcoin with Payload::WitnessProgram variant
2019-08-13 08:47:10 +01:00
Andrew Poelstra cc0f1143dc
Merge pull request #309 from elichai/2019-08-amount-precision
Check that the amount precision isn't more than the size of the amount
2019-08-12 17:20:18 +00:00
Tim Ruffing fb272160c3 Remove accidentally added file (#312) 2019-08-11 12:04:19 +02:00
Riccardo Casatta 7d6687451a use BTreeMap instead of HashMap to always serialize the same (#310)
* use BTreeMap instead of HashMap to always serialize the same

* fix rust 1.22 error

* psbt fuzz roundtrip

* psbt fuzz roundtrip on our ser
2019-08-09 17:03:12 +02:00
Tamás Blummer 4ddf6f80b9
Reduce blockfilter memory (#302)
* use same Error type in all methods of BlockFilter

* reduce Blockfilter memory footprint

* amend the example use

* remove unused constant
2019-08-09 16:58:02 +02:00
Elichai Turkel a9e65f36d3
Check that the amount precision isn't more than the size of the amount 2019-08-09 10:41:21 -04:00
Elichai Turkel 4a1830c423 Replaced Read trait with a generic over Read (#307)
Removed tempfile usage from stream_reader
2019-08-07 17:35:22 +02:00
Andrew Poelstra db8c8b497b
Merge pull request #303 from practicalswift/typos
Fix typos
2019-08-05 15:16:17 +00:00
Andrew Poelstra c3f3a2bee0
Merge pull request #304 from Aleru/master
Test negative numbers
2019-08-05 15:15:49 +00:00
Aleru 40c5a568fa add TODOs 2019-08-04 22:27:59 -04:00
practicalswift 8152ed758c Fix typos 2019-08-04 19:27:36 +00:00
Andrew Poelstra 2e915bf7ef
Merge pull request #271 from stevenroose/serde-outpoint
Add special human-readable serde for OutPoint and most bip32 types
2019-08-02 22:01:17 +00:00
Andrew Poelstra caae4b7a3f
Merge pull request #297 from dongcarl/2019-07-codecov
Generate codecov.io reports
2019-07-29 12:32:45 +00:00
Steven Roose cc2ede7a80
Use `$crate::` prefix for uses in macros 2019-07-29 11:30:35 +02:00
Carl Dong 3207ac5ea7
Generate codecov.io reports 2019-07-26 15:48:52 -04:00
Steven Roose 2c2d55d90a
bip32: Implement hex serialization for Fingerprint and ChainCode 2019-07-26 15:32:33 +02:00
Steven Roose 4530e403e0
Use collect_str instead of serialize_str in serde macros 2019-07-26 15:30:47 +02:00
Steven Roose fc6415d652
Add human-readable serde for OutPoint as `<txid>:<vout>` 2019-07-26 15:30:46 +02:00
Steven Roose 3c66418f3a
bip32: Add serde for Extended(Priv|Pub)Key 2019-07-26 15:30:44 +02:00
Tamás Blummer c93a70487f
Add client side block filter (BIP158) (#281)
* add client side block filters with code from murmel. use siphash from bitcoin_hashes pass Bitcoin Core tests upgrade to bitcoin_hashes 0.7

* add filter.filter_id() test use BlockFilter directly

* fixed edge cases of matching empty query sets or or using empty filter
2019-07-26 09:36:25 +02:00
Andrew Poelstra b6c1266102
Merge pull request #293 from stevenroose/bip143-script-code
bip143: Rename witness_script to script_code
2019-07-24 22:43:58 +00:00
Andrew Poelstra a041168205
Merge pull request #265 from apoelstra/2019-05-enc-dec-cleanup
clean up encoding/decoding traits
2019-07-24 19:30:21 +00:00
Andrew Poelstra 0fc7b28cfc
Merge pull request #295 from tamasblummer/forbid_unsafe
forbid unsafe
2019-07-24 17:49:51 +00:00
Tamas Blummer ff2f5d9ec2 forbid unsafe 2019-07-23 23:29:45 +02:00
Steven Roose b312c4de6a
bip143: Rename witness_script to script_code
For p2wsh the scriptCode is the witness script, but for p2wpkh, it's the
equivalent legacy p2pkh output script.
The name scriptCode is used in the BIP, so it's less confusing.
2019-07-15 17:33:23 +02:00
Andrew Poelstra 3b9a94a178 eliminate type parameter from the `Decodable` trait 2019-07-11 17:23:01 +00:00
Andrew Poelstra 42960b959f eliminate type parameter from `Encodable` trait 2019-07-11 17:21:19 +00:00
Andrew Poelstra 87e7ebcf1b prevent compilation on 16-bit targets so we can use `usize` and assume it is 32 bits 2019-07-11 17:15:33 +00:00
Andrew Poelstra b734d6488a make consensus_encode return the encoded length 2019-07-11 17:15:32 +00:00
Andrew Poelstra abb9210c04 make `VarInt::len` and `Transaction::get_weight` return a usize 2019-07-11 17:14:05 +00:00
Andrew Poelstra 7e6ad7c893 rename Encoder to WriteExt and Decoder to ReadExt 2019-07-11 15:01:38 +00:00
Andrew Poelstra 24ebc29005 fix some recent rustc warnings 2019-07-11 15:01:38 +00:00
Andrew Poelstra 783948446c
Merge pull request #268 from erasmospunk/merkleblock
Add a MerkleBlock construction
2019-07-10 17:56:04 +00:00
John L. Jegutanis aae2937d11 Add a MerkleBlock construction
This is a port of the bitcoin-core CPartialMerkleTree and CMerkleBlock classes.
Here they are called PartialMerkleTree and MerkleBlock.

These are useful for SPV clients that wish to verify that a transaction is
present in a specific block in an authenticated way.
2019-07-05 20:44:31 +02:00
John L. Jegutanis 56f98e00a0 Changed constants from `static` to `const` and added 2 new constants 2019-07-05 15:01:54 +02:00
Andrew Poelstra 1a4bb371a1
Merge pull request #286 from apoelstra/2019-06-builder-ext
script: give `Builder` ability to verify-ify opcodes
2019-07-03 21:50:57 +00:00
Andrew Poelstra cded694381
Merge pull request #277 from jonasnick/rand
Remove unused rand dependency
2019-07-03 20:42:44 +00:00
Andrew Poelstra bb48a2cf2f
Merge pull request #274 from stevenroose/readme
Slightly update README
2019-07-03 17:32:38 +00:00
Andrew Poelstra b2727b6ebe
Merge pull request #250 from stevenroose/no-strason
Remove Decimal and replace strason with serde_json
2019-07-03 17:30:21 +00:00
Andrew Poelstra a11412862c script: give `Builder` ability to verify-ify opcodes 2019-06-29 21:26:56 +00:00
Steven Roose 560a709faa Add OutPoint::new() for one-liner construction (#285) 2019-06-24 18:49:20 +02:00
Steven Roose 0343559ae0
Slightly update README 2019-06-17 11:46:54 +01:00
Andrew Poelstra b13e4628f9
Merge pull request #282 from stevenroose/cltv-csv
Rename OP_NOP2 and OP_NOP3 to OP_CLTV and OP_CSV
2019-06-15 19:12:06 +00:00
Steven Roose d2923b7cce
Rename OP_NOP2 and OP_NOP3 to OP_CLTV and OP_CSV 2019-06-13 18:56:35 +01:00
Steven Roose 30201f3924
Remove Decimal and replace strason with serde_json 2019-06-13 18:29:16 +01:00
Jonas Nick 94fba3aa88 Remove unused rand dependency 2019-06-10 13:59:31 +00:00
Matt Corallo 330e0fd587
Merge pull request #276 from jonasnick/remove-spv
Remove confusing mentions of SPV
2019-06-08 06:56:44 -04:00
Jonas Nick 30f24a39d0 Remove confusing mentions of SPV 2019-06-07 13:12:07 +00:00
Matt Corallo 860e74ecb5
Merge pull request #273 from stevenroose/spv-validate
Rename BlockHeader::spv_validate to validate_pow
2019-06-07 08:24:47 -04:00
Andrew Poelstra 5d7e6bb7a4
Merge pull request #272 from TheBlueMatt/2019-05-net-cleanups
Fix DoS in RawNetworkMessage Deserialization
2019-06-07 11:53:31 +00:00
Matt Corallo 0904935f19 Switch Travis fuzzing to 30 seconds per target from an iter count. 2019-06-07 07:11:21 -04:00
Andrew Poelstra a6c1eacd70
Merge pull request #270 from stevenroose/signed-amount
Add Amount and SignedAmount
2019-06-07 09:16:02 +00:00
Steven Roose 093d60bf7f
Rename BlockHeader::spv_validate to validate_pow 2019-06-06 10:39:03 +01:00
Matt Corallo 1b2dc9d6b0 Rename deserialize_raw_network_message to make my afl scripts happy 2019-06-05 07:49:19 -04:00
Carl Dong 836fdce475 fuzz: Add fuzzer for RawNetworkMessage. 2019-06-05 07:49:19 -04:00
Matt Corallo 98796576d2 Fix trivial DoS when deserializing messages from the network 2019-06-05 07:49:19 -04:00
Andrew Poelstra 08c756d20e
Merge pull request #264 from TheBlueMatt/2019-05-faster-enc-dec
Speed up consensus::[d]encode significantly
2019-06-05 11:46:56 +00:00
Steven Roose 7af134ce79
Add fuzz target for Amount parsing 2019-06-04 12:54:12 +01:00
Steven Roose 688d95b463
Add Amount and SignedAmount types 2019-05-31 10:18:59 +01:00
Steven Roose d4282353c9
Two serde quirks from switching dependencies 2019-05-31 10:18:57 +01:00
Matt Corallo 2b6058e335 Decrease travis-fuzz iterations to fix hangs 2019-05-30 11:25:37 -04:00
Matt Corallo fa1ec2028d Speed up Vec<u8> [d]e[n]code operations by dropping the generic 2019-05-30 11:25:37 -04:00
Matt Corallo ee827e4aa3 Drop some unused/not-needed Encodable impls 2019-05-30 11:25:37 -04:00
Matt Corallo 84835f244c Support sendheaders network message decode 2019-05-30 11:25:37 -04:00
Matt Corallo 084f82be21 Swap a few more [d]encoders to slice emit/read functions 2019-05-30 11:25:37 -04:00
Matt Corallo 7015b064dd Add slice consensus encode/decode functions and use for short arrays 2019-05-30 11:25:37 -04:00
Andrew Poelstra 4139f2a1ca
Merge pull request #258 from shesek/signed-msg-hash
Implement util::misc::signed_msg_hash()
2019-05-30 14:35:57 +00:00
Andrew Poelstra e0205fc9fa
Merge pull request #260 from TheBlueMatt/2019-05-headers-no-pub-wrapper
Drop LoneHeaders and just use BlockHeader
2019-05-21 20:30:35 +00:00
Matt Corallo 4f96a87475 Drop LoneHeaders and just use BlockHeader
The protocol has a bug where a 0u8 is pushed at the end of each
block header on the wire in headers messages. WHy this bug came
about is unrealted and shouldn't impact API design.
2019-05-17 17:55:02 -04:00
Andrew Poelstra b471a12487
Merge pull request #257 from stevenroose/bip32-increment
bip32: Add increment method to DerivationPath and ChildNumber
2019-05-04 21:25:21 +00:00
Steven Roose bb8520268e
bip32: Add DerivationPathIterator and related methods
Adds methods
- ChildNumber::increment
- DerivationPath::children_from
- DerivationPath::normal_children
- DerivationPath::hardened_children
2019-05-03 17:58:09 +01:00
Andrew Poelstra b75e154dd8
Merge pull request #256 from stevenroose/nit-changelog
Fix nit in CHANGELOG.md
2019-05-02 20:31:42 +00:00
Nadav Ivgi 473b491409
Implement util::misc::signed_msg_hash() 2019-04-28 09:01:42 +03:00
Steven Roose 8f2719016e
Fix nit in CHANGELOG.md 2019-04-26 15:07:18 +01:00
Andrew Poelstra 214345745b
Merge pull request #248 from apoelstra/2019-03-0.18
bump version to 0.18
2019-03-22 15:22:35 +00:00
Andrew Poelstra b9e44e4ffd bump version to 0.18 2019-03-21 23:20:06 +00:00
Andrew Poelstra b94d0fcf24
Merge pull request #247 from apoelstra/2019-03-contracthash
contracthash: use `PublicKey` and `PrivateKey` types; minor cleanups
2019-03-21 23:05:43 +00:00
Andrew Poelstra dc6189dbb2 contracthash: more cleanups 2019-03-21 21:27:26 +00:00
Andrew Poelstra 01a3a9263c contracthash: use `PublicKey` and `PrivateKey` types; minor cleanups 2019-03-21 21:27:26 +00:00
Andrew Poelstra 3700d100eb contracthash: add fixed test vector 2019-03-21 21:27:26 +00:00
Andrew Poelstra cea49b6522
Merge pull request #246 from apoelstra/2019-03-key-serde
util::key add serde de/serialization
2019-03-21 21:26:25 +00:00
Andrew Poelstra 9daf7fa9dc util::key add serde de/serialization 2019-03-21 18:27:42 +00:00
Carl Dong 221e53b13e
Merge pull request #243 from stevenroose/pubkey-serialize
util:🔑 Provide to_bytes() methods for key types
2019-03-06 21:44:02 -05:00
Carl Dong d667e0f894
Merge pull request #244 from stevenroose/bech32-bump
Bump bitcoin-bech32 dependency
2019-03-06 21:43:36 -05:00
Steven Roose 459059622f
util:🔑 Provide to_bytes() methods for key types
These are mainly utility methods around the existing way to serialize
the key types.
2019-03-05 16:07:52 +00:00
Steven Roose 750da89992
Bump bitcoin-bech32 dependency
This makes the Address::Payload::WitnessProgram inner type compatible
with rust-lightning-invoice's Fallback::SegWitProgram's inner type.
This allows specifying fallbacks from addresses.
2019-03-04 21:15:28 +00:00
Andrew Poelstra 08c6435eb7
Merge pull request #242 from apoelstra/2019-03-0.17.1
bump version to 0.17.1
2019-03-04 20:20:38 +00:00
Andrew Poelstra d5c1200590 bump version to 0.17.1 2019-03-04 17:51:38 +00:00
Andrew Poelstra 7e1a6a4ab7
Merge pull request #241 from apoelstra/2019-03-pubkey-string
key: implement ToString and FromStr for PublicKey
2019-03-04 17:47:36 +00:00
Andrew Poelstra 049f75e502 script: add `push_key` function to Builder to allow serializing public keys more easily 2019-03-04 01:32:35 +00:00
Andrew Poelstra 4dbf431ecd key: implement ToString and FromStr for PublicKey 2019-03-04 01:06:19 +00:00
Andrew Poelstra 8aa964ce43
Merge pull request #239 from apoelstra/2019-02-0.17
bump version to 0.17.0
2019-03-01 19:43:51 +00:00
Andrew Poelstra 8e214ffa90 add #231 to CHANGELOG for 0.17.0 2019-03-01 16:13:56 +00:00
Andrew Poelstra c342bf3731 bump version to 0.17.0 2019-02-28 22:02:45 +00:00
Andrew Poelstra 67e4671457
Merge pull request #103 from dongcarl/psbt
BIP174 (de)serialization support
2019-02-28 17:20:37 +00:00
Carl Dong e5b59120c5 Add copyright notice to PSBT-related files 2019-02-28 11:11:55 -05:00
Carl Dong f74ec3e187 Add fuzz testing for PartiallySignedTransaction 2019-02-28 11:11:55 -05:00
Carl Dong bc73b315cb Add test vectors from BIP174 specification
- Add macro for decoding and unwrapping PartiallySignedTransaction from
  hex string
2019-02-28 11:11:55 -05:00
Carl Dong 39fd567b56 Add Partially Signed Transaction type
- Add merging logic for PartiallySignedTransactions
- Add (en)decoding logic for PartiallySignedTransaction
- Add converting constructor logic from Transaction for
  PartiallySignedTransaction
- Add extracting constructor logic from PartiallySignedTransaction for
  Transaction

Squashed in fixes from stevenroose <stevenroose@gmail.com>

- Prevent PSBT::extract_tx from panicking
- Make PartiallySignedTransaction fields public
2019-02-28 11:11:55 -05:00
Carl Dong badb0f2a77 Add PSBT input data key-value map type
- Implement psbt::Map trait for psbt::Input
- Add (en)decoding logic for psbt::Input

- Implement PSBT (de)serialization trait for relevant psbt::Input types
2019-02-28 11:11:55 -05:00
Carl Dong 9c08dbae47 Add PSBT output data key-value map type
- Implement psbt::Map trait for psbt::Output
- Add (en)decoding logic for psbt::Output

- Implement PSBT (de)serialization trait for relevant psbt::Output types

- Add macro for merging fields for PSBT key-value maps
- Add macro for implementing decoding logic for PSBT key-value maps
- Add convenience macro for implementing both encoding and decoding
  logic for PSBT key-value maps
- Add macro for inserting raw PSBT key-value pairs into PSBT key-value
  maps
- Add macro for getting raw PSBT key-value pairs from PSBT key-value
  maps
2019-02-28 10:54:53 -05:00
Carl Dong 115f8c043c Add PSBT global data key-value map type
- Implement psbt::Map trait for psbt::Global
- Add converting constructor logic from Transaction for psbt::Global
- Add (en)decoding logic for psbt::Global
  - Always deserialize unsigned_tx as non-witness

- Add trait for PSBT (de)serialization
- Implement PSBT (de)serialization trait for relevant psbt::Global types

- Add macros for consensus::encode-backed PSBT (de)serialization
  implementations
- Add macro for implementing encoding logic for PSBT key-value maps
2019-02-28 10:54:53 -05:00
Carl Dong 2715a6e777 Add trait for PSBT key-value maps 2019-02-28 10:54:53 -05:00
Carl Dong 528e39334c Add data types for raw PSBT key-value pairs
- Add (en)decoding logic for said data types
2019-02-28 10:54:53 -05:00
Carl Dong 4fa39c4a3e Add PSBT-specific Error data type
- Implement psbt::Error data type
- Implement conversion from psbt::Error to util::Error
- Create util::psbt module
- Create non-public util::psbt::error module
2019-02-28 10:54:53 -05:00
Andrew Poelstra 919bbeae4a
Merge pull request #238 from apoelstra/2019-02-bip32-keys
Replace `secp256k1` keys with `util::key` keys in BIP32
2019-02-28 13:42:50 +00:00
Andrew Poelstra 4f74ae61c4 bip32: replace rust-secp key types with rust-bitcoin key types
We continue to support only compressed keys when doing key derivation,
but de/serialization of uncompressed keys will now work, and it will
be easier/more consistent to implement PSBT on top of this.
2019-02-27 22:21:40 +00:00
Dr. Maxim Orlovsky 3c21e301aa Better RawNewtorkMessage deserealization from IO stream (#231)
Follow-up to https://github.com/rust-bitcoin/rust-bitcoin/pull/229

While working with remote peers over the network it is required to deserealize RawNetworkMessage from `TCPStream` to read the incoming messages. These messages can be partial – or one TCP packet can contain few of them. To make the library usable for such use cases, I have implemented the required functionality and covered it with unit tests.

Sample usage:
```rust
fn run() -> Result<(), Error> {
    // Opening stream to the remote bitcoind peer
    let mut stream = TcpStream::connect(SocketAddr::from(([37, 187, 0, 47], 8333));
    let start = SystemTime::now();

    // Constructing and sending `version` message to get some messages back from the remote peer
    let since_the_epoch = start.duration_since(UNIX_EPOCH)
        .expect("Time went backwards");
    let version_msg = message::RawNetworkMessage {
        magic: constants::Network::Bitcoin.magic(),
        payload: message::NetworkMessage::Version(message_network::VersionMessage::new(
            0,
            since_the_epoch.as_secs() as i64,
            address::Address::new(receiver, 0),
            address::Address::new(receiver, 0),
            0,
            String::from("macx0r"),
            0
        ))
    };
    stream.write(encode::serialize(&version_msg).as_slice())?;

    // Receiving incoming messages
    let mut buffer = vec![];
    loop {
        let result = StreamReader::new(&mut stream, None).read_messages();
        if let Err(err) = result {
            stream.shutdown(Shutdown::Both)?;
            return Err(Error::DataError(err))
        }
        for msg in result.unwrap() {
            println!("Received message: {:?}", msg.payload);
        }
    }
}
```

Sample output is the following:
```
Received message: Version(VersionMessage { version: 70015, services: 1037, timestamp: 1548637162, receiver: Address {services: 0, address: [0, 0, 0, 0, 0, 65535, 23536, 35968], port: 33716}, sender: Address {services: 1037, address: [0, 0, 0, 0, 0, 0, 0, 0], port: 0}, nonce: 1370726880972892633, user_agent: "/Satoshi:0.17.99/", start_height: 560412, relay: true })
Received message: Verack
Received message: Alert([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 127, 0, 0, 0, 0, 255, 255, 255, 127, 254, 255, 255, 127, 1, 255, 255, 255, 127, 0, 0, 0, 0, 255, 255, 255, 127, 0, 255, 255, 255, 127, 0, 47, 85, 82, 71, 69, 78, 84, 58, 32, 65, 108, 101, 114, 116, 32, 107, 101, 121, 32, 99, 111, 109, 112, 114, 111, 109, 105, 115, 101, 100, 44, 32, 117, 112, 103, 114, 97, 100, 101, 32, 114, 101, 113, 117, 105, 114, 101, 100, 0])
```

Working sample code can be found here: https://github.com/dr-orlovsky/bitcoinbigdata-netlistener
2019-02-27 16:41:28 -05:00
Andrew Poelstra fc47c477ab key: add some missing functionality 2019-02-27 01:56:38 +00:00
Carl Dong 4bf99e79f8
Merge pull request #236 from dongcarl/2019-02-remove-unused-option-decoding
Remove unused Option en/decoding
2019-02-22 10:14:37 -05:00
Carl Dong 04c7f2071d
Merge pull request #235 from dongcarl/2019-02-remove-extraneous-params-clone
Remove extraneous clones in consensus::params
2019-02-21 17:41:08 -05:00
Carl Dong 4c742fbaa1
Merge pull request #237 from dongcarl/2019-02-forbid-unsafe
Forbid unsafe code
2019-02-21 17:37:59 -05:00
Carl Dong 1ad1c11649 Forbid unsafe code 2019-02-20 17:16:21 -05:00
Carl Dong 17c0f4e784 Remove unused Option en/decoding 2019-02-20 17:08:36 -05:00
Carl Dong 2f70c3bc34 Remove extraneous clones in consensus::params 2019-02-20 15:47:31 -05:00
Matt Corallo 084703cba9
Merge pull request #218 from tamasblummer/merkle_root_fix
Merkle root calculation and witness commitment check for Block
2019-02-16 19:05:42 -05:00
Carl Dong d5331e59ed
Merge pull request #233 from stevenroose/derivation-path
bip32: Add DerivationPath type
2019-02-15 09:52:59 -05:00
Steven Roose dce81b623e
bip32: Add additional methods and traits to DerivationPath
- From<&[ChildNumber]> (cloning)
- AsRef<[ChildNumber]>
- std::iter::FromIterator<ChildNumber>
- std::iter::IntoIterator<ChildNumber>
- std::ops::Index (returning &[ChildNumber])

Also add two methods:
- child(&self, ChildNumber) -> DerivationPath
- into_child(self, ChildNumber) -> DerivationPath
2019-02-14 11:16:06 +00:00
Steven Roose 1373969805 bip32: Change test vectors to use DerivationPath 2019-02-14 11:09:39 +00:00
Steven Roose b23de17d55 bip32: Introduce DerivationPath type
Implements Display and FromStr for easy usage with serialized types.
2019-02-14 11:09:34 +00:00
Steven Roose a80cea270a bip32: ChildNumber constructors return Result
They can produce an error if the index is out of range.
2019-02-14 11:08:13 +00:00
Sebastian Geisler cad0fe790f point to IRC 2019-02-12 14:28:57 -08:00
lucash-dev 114ebb0c73 Added contributing part to README 2019-02-12 14:28:57 -08:00
Carl Dong 560dfb7c01
Merge pull request #203 from stevenroose/asm
Extract the Script assembly creator from fmt::Debug
2019-02-11 17:24:03 -05:00
Carl Dong f87e173268
Merge pull request #227 from dongcarl/2019-01-improve-local-testing
Extract travis testing into locally-runnable script
2019-02-11 16:24:05 -05:00
Andrew Poelstra 8ae4aee0d8
Merge pull request #183 from dongcarl/2018-9-pubkey-wrapper
Ready for Review: Introduce util::key and deprecate util::privkey
2019-02-11 21:21:32 +00:00
Carl Dong a944c7fbd0 key: Use correct error for decoding
This change also moves the secp256k1::Error wrapper from util::Error to
consensus::encode::Error, since we do not use it anywhere else. We can
add it back to util::Error once we have instances of secp256k1::Error
that are not related to consensus::encode.
2019-02-11 15:15:03 -05:00
Carl Dong fc448ba47c key: Reword and clarify comments 2019-02-11 15:10:20 -05:00
Carl Dong b3cc3d50ef Integrate newly-added PublicKey with Address
- Switch util::address::Payload::Pubkey variant to wrap
  util:🔑:PublicKey
- Switch util::address::Address::p*k* constructors to use
  util:🔑:PublicKey
- Fix tests for aforementioned switch
- Add convenience methods for util:🔑:PublicKey to
  util:🔑:PrivateKey conversion
- Switch BIP143 tests to use util:🔑:PublicKey
2019-02-11 15:10:13 -05:00
Carl Dong 53a6efe33c Add PublicKey struct encapsulating compressedness
- Move util::privkey to util::key
- Add PublicKey struct to util::key
- Implement de/serialization methods for util:🔑:PublicKey
2019-02-11 14:56:55 -05:00
Carl Dong 60c93c387f Cleanup util::privkey in preparation for PublicKey
- Rename privkey::PrivKey to privkey::PrivateKey
- Remove unnecessary methods for privkey::PrivateKey
- Modify tests to work with above changes
2019-02-11 14:56:49 -05:00
Tamás Blummer 1cd2782122
add BIP157 (Client Side Block Filtering) Messages (#225)
* add BIP57 (Client Side Block Filtering) Messages

* rabased after https://github.com/rust-bitcoin/rust-bitcoin/pull/215
2019-02-08 13:00:51 +01:00
Carl Dong e386d9e2e9
Merge pull request #222 from stevenroose/no-p2pk-addr
Remove Address::p2pk
2019-02-07 16:18:31 -05:00
Steven Roose f80e882813
Remove Address::p2pk
There is no address format for p2pk.
2019-02-07 20:02:21 +00:00
Carl Dong 50fef2d851 Extract travis testing into locally-runnable script 2019-02-04 10:39:37 -05:00
ariard 51971dd533 Fix typos and clarify some comment in blockdata, block, address (#230) 2019-02-04 07:30:41 +01:00
Tamas Blummer d8c93d9935 Implement Witness commitment check for Block. Remove MerkleRoot implementations for types implementing BitcoinHash as
it is misleading. MerkleRoot is defined instead for a Block.
2019-02-01 17:46:26 +01:00
Carl Dong 51aba8bb21
Merge pull request #215 from dongcarl/2018-12-integrate-bitcoin-hashes
Integrate bitcoin_hashes, remove rust-crypto and fuzz_util
2019-01-24 19:58:34 -05:00
Carl Dong ca72a04dd4 Remove rust-crypto dependency
We no longer need rust-crypto after integrating bitcoin_hashes.
2019-01-24 16:27:52 -05:00
Carl Dong 1bbeda87eb Remove fuzz_util module
Not needed anymore as the bitcoin_hashes crate handles this.
2019-01-24 16:27:52 -05:00
Carl Dong 96f9c62b0e Remove unused internal macro 2019-01-24 16:27:52 -05:00
Carl Dong c830fb4629 Remove code deprecated by bitcoin_hashes from util::hash 2019-01-24 16:27:52 -05:00
Carl Dong 99f63a8ca4 Convert codebase from util::hash to bitcoin_hashes
Also replace unsafe transmute with call to read_u64_into
2019-01-24 16:27:52 -05:00
Carl Dong 45aa709467 Implement En/Decodable for sha256d::Hash 2019-01-24 11:31:07 -05:00
Carl Dong b88f00c698 Add bitcoin_hashes dependency, rename some features
Because features and dependencies share the same namespace, and we want
to pass down the optional dependence on serde to bitcoin_hashes, we need
to rename the feature to something other than serde. Right now only
features can be passed down to dependencies.

Note that we could have also renamed the dependency to something like
serde-dep and kept the same feature name, however, dependency renaming
has only been available since cargo 0.27.0

Features that represent optional dependencies have been prefixed with
'use-'. The travis file has also been modified to conform to this
change.
2019-01-24 11:31:07 -05:00
Carl Dong b6ec6a0d62
Merge pull request #212 from TheBlueMatt/2019-01-travis-nightly-bench
Run cargo bench on rustc nightly in travis
2019-01-23 19:25:44 -05:00
Dimitris Apostolou 132ca5ea95 Fix typos 2019-01-23 14:17:29 -05:00
Tamas Blummer 96be35b1d3 it is annoying to have a difference between debug and print for hash 2019-01-23 14:14:29 -05:00
Carl Dong 8584303768 Bump rustc version to 1.22.0 2019-01-22 19:58:18 -05:00
Andrew Poelstra 21bd59cb17
Merge pull request #214 from apoelstra/2019-01-0.16
bump version to 0.16
2019-01-15 21:01:10 +00:00
Andrew Poelstra b5d5ac5ffb bump version to 0.16 2019-01-15 19:07:53 +00:00
Matt Corallo 0d7e13b034 Run cargo bench on rustc nightly in travis, remote useless move 2019-01-15 14:06:24 -05:00
Matt Corallo 2ed4b1f246
Merge pull request #208 from sgeisler/hex_bytes
Use more performant hex_bytes function
2019-01-15 14:06:00 -05:00
Andrew Poelstra 282daaab69
Merge pull request #213 from dongcarl/2019-01-secp-0.12-bump
Bump secp to 0.12
2019-01-15 19:03:03 +00:00
Carl Dong ff5c4a1806 Bump secp to 0.12 2019-01-15 12:58:54 -05:00
Matt Corallo 81bfc4f027
Merge pull request #211 from dongcarl/2019-01-move-user-enum-macro
Internalize unnecessarily exported macros
2019-01-15 12:58:47 -05:00
Carl Dong b2e044f9db Internalize unnecessarily exported macros 2019-01-15 11:53:31 -05:00
Antoine Riard 96c66292c8 Fix comment on transaction version 2019-01-10 18:29:50 -08:00
Sebastian Geisler 4c29fc0e8d Add feature gated hex decode benchmark 2019-01-07 17:49:55 -08:00
Sebastian Geisler 7c7ec02ed2 Remove unused Pair iterator and util::iter module 2019-01-03 17:28:36 -08:00
Sebastian Geisler c6a41651ab Replace slow hex decoding function with optimized version
Fixes #207.
2019-01-03 17:28:32 -08:00
Steven Roose a10d5e15b3
Extract the Script assembly creator from fmt::Debug 2018-12-19 21:17:00 +01:00
Andrew Poelstra 5a5158e120
Merge pull request #198 from sgeisler/safe-opcodes
Safe opcodes 1.14.0
2018-12-14 16:32:29 +00:00
Sebastian Geisler a6d204cbda Fix indentation in opcodes.rs 2018-12-13 15:35:29 -08:00
Andrew Poelstra bb7ca63776
Merge pull request #196 from sgeisler/separate-fuzzing
Move fuzzing code out of utils
2018-12-09 16:33:21 +00:00
Andrew Poelstra 617406228a add some opcode tests 2018-12-09 16:30:23 +00:00
Tamas Blummer bc5f78c170 upgrade byteorder to 1.2 2018-12-08 14:53:23 -08:00
Sebastian Geisler 9fee72cf20 make opcode PR work with 1.14.0 2018-12-04 15:56:18 -08:00
Andrew Poelstra 8a14ddbc27
Merge pull request #191 from sgeisler/base58
Avoid heap usage when encoding to base58
2018-12-04 12:18:02 +00:00
Sebastian Geisler 79a88e1612 Move fuzzing code out of utils 2018-12-03 16:31:13 -08:00
Sebastian Geisler e88612d617 add test case and cleanup 2018-12-03 14:51:55 -08:00
Sebastian Geisler 4a27c1369a avoid heap use when encoding base58 2018-12-03 14:51:53 -08:00
Andrew Poelstra 944c840460
Merge pull request #179 from apoelstra/2018-10-fuzz-outpoint
add fuzzer for transaction::OutPoint
2018-12-03 18:18:13 +00:00
Kaz Wesley 6b67c8cdff squashme: work around lack of associated constants 2018-11-11 14:58:33 -08:00
Kaz Wesley 45234eb09a safe implementation of All -> Ordinary 2018-11-11 14:19:25 -08:00
Kaz Wesley 0bfef68851 newtype implementation of opcodes::All
Removes unsafety when converting u8 -> All
2018-11-11 14:11:06 -08:00
Andrew Poelstra 84df2f05d7
Merge pull request #190 from apoelstra/2018-11-0.15.1
update version to 0.15.1
2018-11-08 22:34:44 +00:00
Andrew Poelstra 05a00e31e1 update version to 0.15.1 2018-11-08 15:05:13 +00:00
Andrew Poelstra 88daac6b43
Merge pull request #189 from shesek/compressed-p2pk
Detect compressed p2pk in script.is_p2pk()
2018-11-08 14:00:30 +00:00
Nadav Ivgi 18fcab6715 Detect compressed p2pk in script.is_p2pk() 2018-11-08 02:37:27 +02:00
Andrew Poelstra 7d7c360153
Merge pull request #188 from apoelstra/2018-11-0.15
Increase version to 0.15
2018-11-07 16:37:57 +00:00
Andrew Poelstra 1a3d3a3eef bump version to 0.15 2018-11-03 15:42:20 +00:00
Andrew Poelstra 91ed0e7fbd move README changelog stuff into CHANGELOG.md 2018-11-03 15:42:20 +00:00
Andrew Poelstra b8a72448df
Merge pull request #153 from rust-bitcoin/2018-08-segwit-ambiguity
transaction: make 0-input de/serialization always use Segwit
2018-11-03 15:29:51 +00:00
Andrew Poelstra c2146e1bbc
Merge pull request #181 from stevenroose/export-network
Export network::constants::Network
2018-10-23 16:18:30 +00:00
Andrew Poelstra 7813c0ae3d
Merge pull request #178 from stevenroose/wif
Add explicit WIF methods for Privkey
2018-10-22 15:28:09 +00:00
Steven Roose 5f912bdeae Implement Debug for PrivKey
It returns a fixed string to prevent accidental data leakage.
2018-10-22 00:06:46 +01:00
Steven Roose f7b95c7533 Add explicit WIF methods for Privkey 2018-10-22 00:05:59 +01:00
Steven Roose 6f4bfe68f3 Export network::constants::Network 2018-10-21 23:28:27 +01:00
Andrew Poelstra 8b6a40f96a add fuzzer for transaction::OutPoint 2018-10-18 23:14:23 +00:00
Andrew Poelstra 0764673c38
Merge pull request #177 from stevenroose/outpoint-fromstr
Implement FromStr for OutPoint
2018-10-18 23:12:47 +00:00
Steven Roose fefd5d4fe2 Implement FromStr for OutPoint 2018-10-18 12:37:02 +01:00
Andrew Poelstra c37ab1f9c2
Merge pull request #174 from jeffbarg/master
Added example for creating an address from a public key
2018-10-12 14:46:30 +00:00
Andrew Poelstra 11a2783235 add comment expanding on the segwit ambiguity 2018-10-10 02:45:09 +00:00
Andrew Poelstra 7f7013db9c fuzz: check that transaction deserialization roundtrips 2018-10-10 02:03:08 +00:00
Andrew Poelstra a181a523c6 remove special case for 0-input 0-output transaction deserialization
This creates two ways to encode an empty transaction; we should use only the
Segwit-enabled one because that's what we do for 0-input non-0-output transactions.
2018-10-10 02:03:08 +00:00
Jeff Barg 1c2564fc08 Added example for creating an address from a public key
Added an example to the address rustdoc (addresses https://github.com/rust-bitcoin/rust-bitcoin/issues/160)
2018-09-29 17:43:28 -04:00
Andrew Poelstra ab838d2c8c
Merge pull request #169 from rust-bitcoin-tools/bip143_add_tests
added p2wkh, p2sh-p2wkh tests for bip143 module
2018-09-27 17:14:26 +00:00
evgeniy.scherbina bc41772f89 added p2wkh, p2sh-p2wkh tests 2018-09-27 18:54:20 +03:00
Andrew Poelstra 98e39b4383 transaction: make 0-input de/serialization always use Segwit 2018-09-27 13:50:35 +00:00
Andrew Poelstra 45140a3251
Merge pull request #156 from dongcarl/2018-8-network-cleanup
Ready for Review: Clean up `network::encodable` and `network::serialize`
2018-09-25 18:29:52 +00:00
Carl Dong c42252c1da Use default impl for Encoder for Sha256dEncoder 2018-09-25 21:20:24 +08:00
Carl Dong 0f42ca69b0 Move relevant names into consensus::encode
- Move network::encodable::* to consensus::encode::*
- Rename Consensus{En,De}codable to {En,De}codable (now under
  consensus::encode)
- Move network::serialize::Error to consensus::encode::Error
- Remove Raw{En,De}coder, implement {En,De}coder for T: {Write,Read}
  instead
- Move network::serialize::Simple{En,De}coder to
  consensus::encode::{En,De}coder
- Rename util::Error::Serialize to util::Error::Encode
- Modify comments to refer to new names
- Modify files to refer to new names
- Expose {En,De}cod{able,er}, {de,}serialize, Params
- Do not return Result for serialize{,_hex} as serializing to a Vec
  should never fail
2018-09-25 21:19:35 +08:00
Carl Dong 8e0e4eb55a Move serialize::BitcoinHash to util:#️⃣:BitcoinHash
- Use Sha256dEncoder for calculating merkle root
- Remove BitcoinHash implementation for Vec<u8>
2018-09-25 21:19:10 +08:00
Carl Dong 97937b1b5f Move network::consensus_params to consensus::params 2018-09-25 21:13:34 +08:00
Carl Dong 7e9d393d03 Remove low-level networking support
- Modify VersionMessage constructor to take in parameters directly that
  would have otherwise been extracted from a Socket (now removed)
2018-09-25 21:13:34 +08:00
Carl Dong 7f11766c65 Remove nu_select macro 2018-09-25 21:13:34 +08:00
Andrew Poelstra 0da693f9a5
Merge pull request #168 from thomaseizinger/from-str-transaction-id
Add FromStr for Sha256dHash
2018-09-20 21:01:52 +00:00
Thomas Eizinger 50e3a4abf2 Add FromStr for Sha256dHash
The FromStr implementation just delegates to the `from_hex` method for
the actual parsing.
2018-09-20 12:18:45 +10:00
Andrew Poelstra 5adf985eae
Merge pull request #167 from rust-bitcoin/branch-0.14.2
bump version to 0.14.2
2018-09-11 18:44:59 +00:00
Andrew Poelstra 625eac636b bump version to 0.14.2 2018-09-11 18:04:02 +00:00
Andrew Poelstra 2c8a6f5eb3
Merge pull request #159 from stevenroose/address-serde
Implement serde serialiation for Address
2018-09-11 18:03:15 +00:00
Steven Roose 8edfbec1cb Implement serde serialiation for Address 2018-09-11 18:37:36 +01:00
Andrew Poelstra 84ccf0b55a
Merge pull request #166 from TheBlueMatt/master
Update fuzz harness stuff
2018-09-07 18:59:27 +00:00
Matt Corallo ac11191f71 Upgrade AFL to 0.4 with persistent mode fuzzing 2018-09-06 16:58:38 -04:00
Matt Corallo 12d9e9803c Update fuzz seeds 2018-09-06 16:58:37 -04:00
Andrew Poelstra cadbe032ea
Merge pull request #158 from rust-bitcoin/2018-08-14.1
increase version to 0.14.1
2018-08-29 00:03:29 +00:00
Andrew Poelstra b7c84a6571 increase version to 0.14.1 2018-08-28 17:15:37 +00:00
Andrew Poelstra 849674651f
Merge pull request #157 from rust-bitcoin/2018-08-pub-use
`pub use` a ton of stuff at the top level
2018-08-28 17:13:40 +00:00
Andrew Poelstra 97c1773ec9 `pub use` a ton of stuff at the top level 2018-08-28 15:57:46 +00:00
Andrew Poelstra fe99a88acf
Merge pull request #152 from rust-bitcoin/2018-08-script-ord
impl PartialOrd, Ord for Script
2018-08-26 15:38:43 +00:00
Andrew Poelstra b33aa6fa6c add unit test for script ordering 2018-08-25 22:09:22 +00:00
Andrew Poelstra 592935b2da
Merge pull request #151 from rust-bitcoin/2018-08-serialization-fixes
Various serialization fixes
2018-08-24 21:17:44 +00:00
Andrew Poelstra cef78d81af fuzz: check that script deserialization roundtrips 2018-08-24 20:31:50 +00:00
Andrew Poelstra ef642295c5 encodable: reject non-compact VarInts on Vec and Box<[T]> lengths 2018-08-24 20:31:46 +00:00
Andrew Poelstra f0221fb79b transaction: reject transactions with Segwit byte set but no witnesses 2018-08-24 19:57:58 +00:00
Andrew Poelstra 68413d306d impl PartialOrd, Ord for Script 2018-08-24 02:20:37 +00:00
Andrew Poelstra d1d3b3fb02
Merge pull request #148 from rust-bitcoin/hex-dep
pin hex to 0.3.2 rather than a git commit
2018-08-22 22:53:50 +00:00
Andrew Poelstra 6d7a5f02c1 pin hex to 0.3.2 rather than a git commit 2018-08-22 22:11:46 +00:00
Andrew Poelstra d792c98df6
Merge pull request #147 from rust-bitcoin/version-0.14
bump version to 0.14.0
2018-08-22 21:54:00 +00:00
Andrew Poelstra 598afd94ca bump version to 0.14.0 2018-08-22 21:18:39 +00:00
Andrew Poelstra 3f9b003348
Merge pull request #136 from rust-bitcoin/2018-08-minimal-push
script: make Instructions iterator enforce minimal pushes
2018-08-22 21:17:10 +00:00
Andrew Poelstra c89a4f5ada
Merge pull request #146 from rust-bitcoin/2018-08-secp-0.11
update rust-secp dependency to 0.11
2018-08-22 20:42:19 +00:00
Andrew Poelstra fc0fec7e19 fuzz: add Script::iter tests to script deserialization test 2018-08-22 20:40:44 +00:00
Andrew Poelstra 08db6fe29f script: let Instructions iterator enforce minimal pushes; remove `IntoIter` impl to force users to choose 2018-08-22 19:55:31 +00:00
Andrew Poelstra 41ebf5468c update rust-secp dependency to 0.11 2018-08-22 19:37:32 +00:00
Andrew Poelstra dbefaef25c
Merge pull request #142 from jeandudey/2018-08-decimal-fromstr
Implement `FromStr` for `UDecimal`/`Decimal`.
2018-08-22 19:00:02 +00:00
Jean Pierre Dudey 9cdc75a930 Forbid exponents larger than 18.
Signed-off-by: Jean Pierre Dudey <jeandudey@hotmail.com>
2018-08-22 14:00:30 -04:00
Jean Pierre Dudey 6902bf826c Fix negative symbol bug in `FromStr` display implementation.
The negative symbol wasn't there when `int_part` was equal to zero.

Signed-off-by: Jean Pierre Dudey <jeandudey@hotmail.com>
2018-08-22 11:26:05 -04:00
Jean Pierre Dudey a915bc194d Fix multiplication logic in decimal parsing functions.
Signed-off-by: Jean Pierre Dudey <jeandudey@hotmail.com>
2018-08-22 07:22:47 -04:00
Jean Pierre Dudey e48e559740 Fix `UDecimal::parse_udecimal` identation.
Signed-off-by: Jean Pierre Dudey <jeandudey@hotmail.com>
2018-08-21 21:31:02 -04:00
Jean Pierre Dudey 455bc66d3c Fix parsing for numbers that are too big to fit in a `Decimal`/`UDecimal`.
Signed-off-by: Jean Pierre Dudey <jeandudey@hotmail.com>
2018-08-21 21:29:07 -04:00
Andrew Poelstra a61ad5d382
Merge pull request #137 from dongcarl/2018-8-better-errors
Fix Error type for SimpleDecoder and SimpleEncoder
2018-08-22 00:55:54 +00:00
Jean Pierre Dudey be0d54738b Add fuzz tests for `Decimal`/`UDecimal` parsing.
Signed-off-by: Jean Pierre Dudey <jeandudey@hotmail.com>
2018-08-21 16:21:29 -04:00
Jean Pierre Dudey 07838568f9 Implement `FromStr` for `Decimal`/`UDecimal`.
Signed-off-by: Jean Pierre Dudey <jeandudey@hotmail.com>
2018-08-21 16:13:58 -04:00
Andrew Poelstra d16fdd63d3
Merge pull request #141 from jeandudey/2018-08-display
Implement `Display` instead of `ToString` for `Address` and `PrivKey`.
2018-08-21 16:41:58 +00:00
Carl Dong bccdd06794 Replace catch-all match arms with specific ones 2018-08-21 01:58:40 -07:00
Carl Dong 0c172941af Replace serialize::Error::Detail with variants
- Add serialize::Error::ParseFailed(&'static str) variant for
  serialization errors without context
- Add appropriate variants to replace network::Error::Detail for
  serialization error with context
- Remove error method from SimpleDecoders
2018-08-21 01:58:40 -07:00
Carl Dong d12a861f85 Remove unnecessary network::Error::Detail variant 2018-08-21 01:58:40 -07:00
Carl Dong 95303a1d28 Use full path in macros to to eliminate uses 2018-08-21 01:58:40 -07:00
Carl Dong e5b5cbfadb Fix Error type for SimpleDecoder and SimpleEncoder
- Separate serialize::Error and network::Error from util::Error
- Remove unneeded propagate_err and consume_err
- Change fuzzing code to ignore Err type
2018-08-21 01:58:40 -07:00
Jean Pierre Dudey df7f084e96 Implement `Display` instead of `ToString` for `Address` and `PrivKey`.
Signed-off-by: Jean Pierre Dudey <jeandudey@hotmail.com>
2018-08-20 19:46:56 -04:00
Andrew Poelstra 77e2fe3dda
Merge pull request #144 from jeandudey/2018-08-address-starts-with
trivial: Use `str::starts_with` method to check bech32 address prefixes.
2018-08-20 23:12:03 +00:00
Andrew Poelstra 3a2e1ce09e
Merge pull request #143 from jeandudey/2018-08-c-conv
Use `as_`,`to_`,`into_` conventions for array types.
2018-08-20 23:11:11 +00:00
Jean Pierre Dudey b78d7a7428 Use `str::starts_with` method to check bech32 address prefixes.
Signed-off-by: Jean Pierre Dudey <jeandudey@hotmail.com>
2018-08-20 18:11:14 -04:00
Jean Pierre Dudey 4dfb98bd70 Use `as_`,`to_`,`into_` conventions for array types.
Signed-off-by: Jean Pierre Dudey <jeandudey@hotmail.com>
2018-08-20 17:20:43 -04:00
Andrew Poelstra 2d961412af
Merge pull request #139 from jeandudey/2018-08-18-outpoint
Rename `TxOutRef` to `OutPoint` and use it in `TxIn`.
2018-08-20 18:18:00 +00:00
Andrew Poelstra ec47b798fe
Merge pull request #125 from jeandudey/2018-08-11-serde-shim
Update to serde 1.0
2018-08-20 18:04:47 +00:00
Jean Pierre Dudey 32631e44ad Rename `TxOutRef` to `OutPoint` and use it in `TxIn`.
Previously this structure was unused, it's now being used by the `TxIn`
structure to simplify the code a little bit and avoid confusions. Also
the rust-lightning source code has an `OutPoint` similar to this one
but with the `vout` index as an `u16` to avoid unsafe conversions.

I've added to new methods to `OutPoint`:

- `null`: Creates a new "null" `OutPoint`.
- `is_null`: Checks if the given `OutPoint` is null.

Signed-off-by: Jean Pierre Dudey <jeandudey@hotmail.com>
2018-08-20 13:46:10 -04:00
Jean Pierre Dudey 1b4aba1d80 Update serde to 1.0 and strason to 0.4
The `serde_struct_impl!` macro has been modified to be compatible
with the serde 1.0 crate, we use this macro and not the `serde_derive`
crate because the latter doesn't support Rust 1.14.0 which is shipped
on Debian stable and we should remain compatible with it.

Two new features were added:

- "serde": enables serialization/deserialization for common types, it pulls
the serde 1.0 dependency.
- "serde-decimal": enables serialization/deserialization for `UDecimal`/`Decimal`,
this pulls the strason 0.4 depdendency and the serde 1.0 dependency.

Signed-off-by: Jean Pierre Dudey <jeandudey@hotmail.com>
2018-08-20 13:42:34 -04:00
Andrew Poelstra 84040caa70
Merge pull request #113 from rust-bitcoin/2018-07-secp-0.10.0
update to secp256k1 0.10.0
2018-08-20 16:05:09 +00:00
Andrew Poelstra 94f3d4b0f9 update to secp256k1 0.10.0 2018-08-20 15:28:43 +00:00
Andrew Poelstra 85ddb66be0
Merge pull request #138 from dongcarl/2018-8-usize-fix
Fix compilation warning when comparing usize and u64 on 32-bit arch
2018-08-20 14:11:26 +00:00
Andrew Poelstra dca4cb4d54
Merge pull request #95 from alekseysidorov/impl-standard-traits
Added Ord and Hash implementations for the Address type
2018-08-20 14:10:05 +00:00
Aleksei 356d13e465 Add some useful standard trait implementations 2018-08-20 12:11:17 +03:00
Carl Dong 9da96e1d46 Fix compilation warning when comparing usize and u64 on 32-bit arch 2018-08-17 10:08:56 -07:00
Andrew Poelstra 6c82001ead
Merge pull request #128 from jeandudey/2018-08-12-bitcoinconsenus
Remove unused "bitcoinconsenus" feature.
2018-08-15 20:55:51 +00:00
Andrew Poelstra a1c9a25d07
Merge pull request #133 from romanz/master
Remove variable shadowing in listener.rs
2018-08-15 20:52:56 +00:00
Roman Zeyde fdbccf055d
Remove variable shadowing in listener.rs 2018-08-15 09:43:35 +03:00
Andrew Poelstra 14f5db070a
Merge pull request #132 from dongcarl/deserialize-fix
Ready for Review: Make deserialize error if input bytes not consumed
2018-08-15 01:35:21 +00:00
Carl Dong 70203831d6 Make deserialize error if input bytes not consumed
- Adjust tests in encodable.rs to account for this change
2018-08-14 16:50:33 -07:00
Andrew Poelstra bf9c749b0c
Merge pull request #129 from dongcarl/bip32-derive-test
Ready for Review: Add derive_* methods to Extended*Key
2018-08-13 20:52:07 +00:00
Carl Dong 60577f286d Add derive_* methods to Extended*Key
- Add derive_pub to ExtendedPubKey
- Add derive_priv to ExtendedPrivKey
- Removed from_path from ExtendedPrivKey as it is superseded by
  derive_priv
- Add checking of derive_pub and derive_priv to test_path
- Add checking of correct error when invoking ckd_pub on a hardened
  ChildNumber
- Add test vector 3 from BIP32 specification
2018-08-12 17:16:33 -07:00
Andrew Poelstra bc7125e955
Merge pull request #119 from jeandudey/2018-08-08-try-op
Remove `try!` macro usage and use the `?` operator instead.
2018-08-12 23:44:43 +00:00
Andrew Poelstra c16ae47871
Merge pull request #127 from jeandudey/2018-08-12-c-hidden
Hidde `From<T>` implementations for error types in Rustdoc.
2018-08-12 23:43:01 +00:00
Jean Pierre Dudey f918311b8a Remove unused "bitcoinconsenus" feature.
Also I've updated the feature name on the README.md, and fixed a typo in
src/blockdata/script.rs

Signed-off-by: Jean Pierre Dudey <jeandudey@hotmail.com>
2018-08-12 16:06:06 -04:00
Jean Pierre Dudey 6e99d2d33c Hidde `From<T>` implementations for error types in Rustdoc.
Signed-off-by: Jean Pierre Dudey <jeandudey@hotmail.com>
2018-08-12 12:57:59 -04:00
Jean Pierre Dudey b2594087db Use the `?` (try) instead of the `try!` macro.
Signed-off-by: Jean Pierre Dudey <jeandudey@hotmail.com>
2018-08-12 12:47:31 -04:00
Andrew Poelstra 24c0f1a3fc
Merge pull request #118 from jeandudey/2018-08-08-bip32-tostring
Implement `Display` trait instead of implementing `ToString` directly.
2018-08-12 13:48:39 +00:00
Andrew Poelstra 147259d957
Merge pull request #126 from dongcarl/bip32-consistency
Ready for Review: Improve consistency for bip32::ChildNumber
2018-08-11 23:38:41 +00:00
Carl Dong c485a74c09 Add helper methods is_normal, is_hardened
- Fix documentation links
2018-08-11 13:29:10 -07:00
Carl Dong 4a5bf52ed9 Improve consistency for bip32::ChildNumber
There seemed to be some confusion as to whether the internal
represenation of a ChildNumber is supposed to be the index (0..2^31-1
for _both_ Normal and Hardened) or the actual number (0..2^31-1 for
Normal and 2^31..2^32-1 for Hardened). This commits fixes this
confusion.

- Make clear that the internal representation is the index rather
  than the actual number
- Make the internal representation non-public
- Provide methods for creating valid ChildNumbers
- Change relevant callers and tests to conform to this new ChildNumber

My rationale for using index rather than the actual number as internal
representation is that the difference between the two enum variants
already encode wether a ChildNumber is a normal one or a hardened one,
so the only bit of extra information left to be encoded is its index.
2018-08-11 12:46:46 -07:00
Andrew Poelstra ebe5133d1a
Merge pull request #110 from D4nte/regtest
Regtest bech32 address support
2018-08-11 17:21:12 +00:00
Andrew Poelstra 259c5902f1
Merge pull request #116 from jeandudey/2018-08-08-module-docs
Fix modules documentation title.
2018-08-11 17:12:50 +00:00
Andrew Poelstra ee9802d813
Merge pull request #120 from dpc/from_secret_key-doc-fix
Simple doc fix for `from_secret_key`
2018-08-11 17:05:29 +00:00
Andrew Poelstra e17c280e4f
Merge pull request #121 from jeandudey/2018-08-10-network
Refactor and add more documentation for the `Network` type.
2018-08-11 16:52:52 +00:00
Andrew Poelstra 6c53593d5f
Merge pull request #122 from dongcarl/childnumber-fixes
Add conversion between u32 and ChildNumber, fix docs
2018-08-10 22:46:22 +00:00
Carl Dong d4f28b6785 Add conversion between u32 and ChildNumber, fix docs 2018-08-10 13:49:45 -07:00
Jean Pierre Dudey 7ecb6b9dea Refactor and add more documentation for the `Network` type.
Signed-off-by: Jean Pierre Dudey <jeandudey@hotmail.com>
2018-08-10 14:56:19 -04:00
Dawid Ciężarkiewicz 1646a80f77 Simple doc fix for `from_secret_key` 2018-08-09 15:41:48 -07:00
Jean Pierre Dudey 0225b530cc Implement `Display` trait instead of implementing `ToString` directly.
ExtendedPubKey and ExtendedPrivKey implemented `ToString` directly but
Rust documentation says to implement `Display` and get the `ToString`
implementation for free.

Signed-off-by: Jean Pierre Dudey <jeandudey@hotmail.com>
2018-08-08 19:11:16 -04:00
Jean Pierre Dudey 77c185d9ec Fix modules documentation title.
Signed-off-by: Jean Pierre Dudey <jeandudey@hotmail.com>
2018-08-08 17:38:50 -04:00
Andrew Poelstra 45c699f005
Merge pull request #112 from TheBlueMatt/2018-07-p2wsh-name
Clarify to_v0_p2wsh docs a bit further
2018-07-28 18:28:00 +00:00
Andrew Poelstra cdb7ca83c9
Merge pull request #107 from savil/remove-rustc-serialize
[code hygiene] remove deprecated rustc-serialize
2018-07-28 18:24:50 +00:00
Matt Corallo 3686cd7201 Clarify to_v0_p2wsh docs a bit further 2018-07-26 15:13:44 -04:00
Savil Srivastava 933dcaeb82 [code hygiene] remove deprecated rustc-serialize
Addresses #96.

Turns out it was being used for hex encoding/decoding, so replaced that with the `hex` crate.

i chose to import the `decode` method as:
```
use hex::decode as hex_decode
```

so that it is clear to the reader what is being decoded when it is called. "decode" is such a generic sounding function name that it would get confusing otherwise.
2018-07-26 09:49:15 -07:00
Franck Royer f05f831569 Regtest has a longer hrp, need to adjust length safety check 2018-07-26 17:06:35 +10:00
Franck Royer 0f31608796 Add support for bech32 regtest address format 2018-07-26 10:51:37 +10:00
Franck Royer ba2879cfac Add test for regtest network 2018-07-26 10:51:15 +10:00
Andrew Poelstra f7ab3241a7
Merge pull request #109 from dongcarl/patch-1
Fix to_v0_p2wsh docs
2018-07-26 00:42:24 +00:00
Carl Dong db76a63669
Fix to_v0_p2wsh docs 2018-07-25 17:11:27 -07:00
Andrew Poelstra a7aff1372e
Merge pull request #100 from sgeisler/bech32-v0.6.1
Use bech32 v0.8.0
2018-07-25 21:24:26 +00:00
Sebastian Geisler 00cca03edd use bitcoin-bech32 v0.8.0 and adapt internal API usage 2018-07-25 21:09:46 +02:00
Andrew Poelstra 9ab2aa52fd
Merge pull request #101 from tamasblummer/is_op_return
check if output is OP_RETURN
2018-06-23 15:19:18 +00:00
Tamas Blummer caeadb42be check if output is OP_RETURN 2018-06-23 14:49:55 +02:00
Igor Aleksanov 2ff5f8e51e Added module with consensus parameters (#93) 2018-06-23 10:23:34 +02:00
Andrew Poelstra 93d426db2e
Merge pull request #99 from rust-bitcoin/2018-06-revert-pr-84
Reverts #84, bumps Cargo minor version number, and re-adds #84
2018-06-22 16:12:53 +00:00
Igor Aleksanov 7988b78c1f Added regtest
Completed regtest integration to the code

Added tests for regtest

Get rid of panics
2018-06-16 22:56:32 +00:00
Andrew Poelstra 5c753fb517 Bump version to 0.13.2 2018-06-16 22:55:27 +00:00
Andrew Poelstra bc5cb3bc31 Revert "Added regtest"
This reverts commit 34e228c699.
2018-06-16 22:55:12 +00:00
Igor Aleksanov 14a920ab7d Added method to convert target from Uint256 to compact form (#86)
Renamed method for getting compact from u256

Removed unnecessary asserts from convert function
2018-06-12 20:58:25 +02:00
Andrew Poelstra 18460e347e
Merge pull request #97 from romanz/master
Fix 2 small typos in comments
2018-06-10 21:09:15 +00:00
Roman Zeyde 69ea2a760b
Fix 2 small typos in comments 2018-06-09 22:27:40 +03:00
Andrew Poelstra 6dc2ad86f0
Merge pull request #92 from rust-bitcoin/version-0.13.1
bump version to 0.13.1
2018-06-04 21:02:20 +00:00
Andrew Poelstra 2db9aeab2d bump version to 0.13.1 2018-06-04 19:29:59 +00:00
Andrew Poelstra 62d080afc7
Merge pull request #83 from tamasblummer/is_coinbase
add is_coin_base
2018-06-04 18:46:03 +00:00
Andrew Poelstra dd176b4177
Merge pull request #84 from popzxc/add-regtest
Added regtest network
2018-06-04 18:42:05 +00:00
Andrew Poelstra fb0c782df6
Merge pull request #89 from tamasblummer/wittness_block
add witness inv types
2018-06-04 18:34:28 +00:00
Andrew Poelstra 33261c7a12
Merge pull request #91 from TheBlueMatt/master
Check in fuzz inputs for all current targets
2018-06-04 18:32:19 +00:00
Andrew Poelstra eebd185a01
Merge pull request #90 from TheBlueMatt/merkle-expose
Expose merkleroot(Vec<Sha256dHash>) publicly
2018-06-04 18:15:35 +00:00
Matt Corallo 63765a2467 Check in good fuzzing starting points for current fuzz targets 2018-06-04 10:36:48 -04:00
Matt Corallo e2403a37fa Don't try to do a base58 checksum if an address is excessively long 2018-06-04 10:23:55 -04:00
Matt Corallo dab2f0b6b6 Switch fuzztarget SHA256 to simply XOR'ing all input bytes 2018-06-04 10:23:26 -04:00
Tamás Blummer 47b2364554
Merge branch 'master' into wittness_block 2018-06-04 04:24:51 +02:00
Matt Corallo b78ab0f60b Expose merkleroot(Vec<Sha256dHash>) publicly
In a project of mine I needed to check the merkle root before
moving some Vec<Transaction>s around, so need to be able to
calculate the merkle root on a Vec<Sha256dHash> directly.
2018-06-01 18:50:31 -04:00
Tamas Blummer 3921899c65 add is_coin_base
add data access as copy
2018-06-01 21:39:51 +02:00
Igor Aleksanov 97908ea058 Merge branch 'master' into add-regtest 2018-05-29 12:21:56 +03:00
Igor Aleksanov 34e228c699 Added regtest
Completed regtest integration to the code

Added tests for regtest

Get rid of panics
2018-05-29 12:21:41 +03:00
Igor Aleksanov 881972b2a5 Fix multiplication for uint256 (#88) 2018-05-28 20:41:07 +02:00
Tamas Blummer 9f2d737045 add witness inv types 2018-05-28 15:24:35 +02:00
Andrew Poelstra feec1cae70
Merge pull request #87 from petertodd/2018-05-remove-cargo-instructions
Remove cargo usage from README
2018-05-27 15:45:07 +00:00
Peter Todd 131ac3b1ac
Remove cargo usage from README
Everyone using rust can be expected to know how to do this, and besides,
the version was wrong. :)
2018-05-26 03:04:06 -04:00
Tamás Blummer ee65534a44
Merge pull request #85 from alekseysidorov/hotfix-network-from-str-err
Hotfix: replace serde error with the io error.
2018-05-24 16:06:14 +02:00
Tamás Blummer cf4024beb4
Merge branch 'master' into hotfix-network-from-str-err 2018-05-20 11:32:19 +02:00
Andrew Poelstra 6b1872e697
Merge pull request #81 from popzxc/data-method-in-impl-array-newtype
Added generation of `data` method in `impl_array_newtype` macro
2018-05-19 17:52:09 +00:00
Andrew Poelstra ab96df162a
Merge branch 'master' into data-method-in-impl-array-newtype 2018-05-19 17:29:53 +00:00
Aleksey Sidorov 5771841144 Replace serde error with the io error. 2018-05-18 12:08:11 +03:00
Tamás Blummer c1ff953b25
Merge pull request #80 from alekseysidorov/improve-network-constant
Implement `FromStr` for Network constant
2018-05-18 09:35:57 +02:00
Igor Aleksanov 13f1fe1f08
Merge branch 'master' into data-method-in-impl-array-newtype 2018-05-17 19:07:08 +03:00
Andrew Poelstra cc23f09b10
Merge branch 'master' into improve-network-constant 2018-05-17 15:00:35 +00:00
Andrew Poelstra 7ffd829e39
Merge pull request #82 from popzxc/impl-display-for-uint
Added `impl Display` to `construct_uint` macro
2018-05-17 14:58:44 +00:00
Igor Aleksanov 582afb1611 Added impl display for uint 2018-05-16 13:13:48 +03:00
Igor Aleksanov 539a74de12 Added test for Sha256dHash::data() 2018-05-16 12:44:30 +03:00
Igor Aleksanov 5df8893ea1 Macro impl_array_newtype now generates method for representing data as array 2018-05-16 12:34:36 +03:00
Aleksei Sidorov 3224cf2b18 Implement `FromStr` for Network constant 2018-05-16 12:22:07 +03:00
829 changed files with 13423 additions and 4864 deletions

View File

@ -1,17 +1,46 @@
language: rust
rust:
- stable
- beta
- nightly
- 1.14.0
cache: cargo
before_install:
- sudo apt-get -qq update
- sudo apt-get install -y binutils-dev libunwind8-dev
addons:
apt:
update: true
packages:
- binutils-dev
- libunwind8-dev
- libcurl4-openssl-dev
- libelf-dev
- libdw-dev
- cmake
- gcc
- libiberty-dev
matrix:
include:
- rust: stable
env: DO_FUZZ=true DO_COV=true AS_DEPENDENCY=true
- rust: beta
env: AS_DEPENDENCY=true
- rust: nightly
env: DO_BENCH=true AS_DEPENDENCY=true
- rust: 1.22.0
env: AS_DEPENDENCY=true
script:
- cargo build --verbose
- cargo test --verbose
- cargo build --verbose --features=bitcoinconsensus
- cargo test --verbose --features=bitcoinconsensus
- if [ "$(rustup show | grep default | grep stable)" != "" ]; then cd fuzz && cargo test --verbose && ./travis-fuzz.sh; fi
- ./contrib/test.sh
after_success: |
if [ "$DO_COV" = true ]; then
wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz &&
tar xzf master.tar.gz &&
cd kcov-master &&
mkdir build &&
cd build &&
cmake .. &&
make &&
make install DESTDIR=../../kcov-build &&
cd ../.. &&
rm -rf kcov-master &&
for file in target/debug/bitcoin-*; do [ -x "${file}" ] || continue; mkdir -p "target/cov/$(basename $file)"; ./kcov-build/usr/local/bin/kcov --exclude-pattern=/.cargo,/usr/lib --verify "target/cov/$(basename $file)" "$file"; done &&
bash <(curl -s https://codecov.io/bash) &&
echo "Uploaded code coverage"; fi

192
CHANGELOG.md Normal file
View File

@ -0,0 +1,192 @@
# 0.23.0 - 2020-01-07
- Update `secp256k1` dependency to `0.17.1`.
- Update `bitcoinconsensus` dependency to `0.19.0-1`.
- Update `bech32` dependency to `0.7.2`.
# 0.22.0 - 2020-01-07
- Add `ServiceFlags` type.
- Add `NetworkMessage::command`.
- Add `key::Error`.
- Add newtypes for specific hashes:
- `Txid`
- `Wtxid`
- `BlockHash`
- `SigHash`
- `PubkeyHash`
- `ScriptHash`
- `WPubkeyHash`
- `WScriptHash`
- `TxMerkleNode`
- `WitnessMerkleNode`
- `WitnessCommitment`
- `XpubIdentifier`
- `FilterHash`
- Refactor `CommandString`.
- Refactor `Reject` message.
- Rename `RejectReason` enum variants.
- Refactor `encode::Error`.
- Implement `Default` for `TxIn`.
- Implement `std::hash::Hash` for `Inventory`.
- Implement `Copy` for `InvType` enum.
- Use `psbt::Error` in `PartiallySignedTransaction::from_unsigned_tx`.
- Drop message decode max length to 4_000_000.
- Drop `hex` and `byteorder` dependencies.
# 0.21.0 - 2019-10-02
* Add [serde to `BlockHeader` and `Block`](https://github.com/rust-bitcoin/rust-bitcoin/pull/321)
* [Clean up `StreamReader` API](https://github.com/rust-bitcoin/rust-bitcoin/pull/318) (breaking change)
* Add [reject message](https://github.com/rust-bitcoin/rust-bitcoin/pull/323) to p2p messages
# 0.20.0 - 2019-08-23
* Update `secp256k1` 0.15 and `bitcoinconsensus` 0.17
# 0.19.0 - 2019-08-16
* Add `Amount` and `SignedAmount` types.
* Add BIP-158 support with `BlockFilter` and related types.
* Add `util::misc::signed_msg_hash()` for signing messages.
* Add `MerkleBlock` and `PartialMerkleTree` types.
* bip32: Support serde serializaton for types and add some utility methods:
* `ChildNumber::increment`
* `DerivationPath::children_from`
* `DerivationPath::normal_children`
* `DerivationPath::hardened_children`
* Add `blockdata::script::Builder::push_verify` to verify-ify an opcode.
* Add `sendheaders` network message.
* Add `OutPoint::new()` method and JSON-serialize as `<txid>:<vout>`.
* Refactor `Address` type:
* Now supports segwit addresses with version >0.
* Add `Address::from_script` constructor.
* Add `Address::address_type` inspector.
* Parsing now returns an `address::Error` instead of `encode::Error`.
* Removed `bitcoin_bech32` dependency for bech32 payloads.
* bip143: Rename `witness_script` to `script_code`
* Rename `BlockHeader::spv_validate` to `validate_pow`
* Rename `OP_NOP2` and `OP_NOP3` to `OP_CLTV` and `OP_CSV`
* psbt: Use `BTreeMap` instead of `HashMap` to ensure serialization roundtrips.
* Drop `Decimal` type.
* Drop `LoneHeaders` type.
* Replace `strason` dependency with (optional) `serde_json`.
* Export the `bitcoin_hashes` and `secp256k1` dependent crates.
* Updated `bitcoin_hashes` dependency to v0.7.
* Removed `rand` and `serde_test` dependencies.
* Internal improvements to consensus encoding logic.
# 0.18.0 - 2019-03-21
* Update `bitcoin-bech32` version to 0.9
* add `to_bytes` method for `util::key` types
* add serde impls for `util::key` types
* contracthash: minor cleanups, use `util::key` types instead of `secp256k1` types
# 0.17.1 - 2019-03-04
* Add some trait impls to `PublicKey` for miniscript interoperability
# 0.17.0 - 2019-02-28 - ``The PSBT Release''
* **Update minimum rustc version to 1.22**.
* [Replace `rust-crypto` with `bitcoin_hashes`; refactor hash types](https://github.com/rust-bitcoin/rust-bitcoin/pull/215)
* [Remove `Address::p2pk`](https://github.com/rust-bitcoin/rust-bitcoin/pull/222/)
* Remove misleading blanket `MerkleRoot` implementation; [it is now only defined for `Block`](https://github.com/rust-bitcoin/rust-bitcoin/pull/218)
* [Add BIP157](https://github.com/rust-bitcoin/rust-bitcoin/pull/215) (client-side block filtering messages)
* Allow network messages [to be deserialized even across multiple packets](https://github.com/rust-bitcoin/rust-bitcoin/pull/231)
* [Replace all key types](https://github.com/rust-bitcoin/rust-bitcoin/pull/183) to better match abstractions needed for PSBT
* [Clean up BIP32](https://github.com/rust-bitcoin/rust-bitcoin/pull/233) in preparation for PSBT; [use new native key types rather than `secp256k1` ones](https://github.com/rust-bitcoin/rust-bitcoin/pull/238/)
* Remove [apparently-used `Option` serialization](https://github.com/rust-bitcoin/rust-bitcoin/pull/236#event-2158116421) code
* Finally merge [PSBT](https://github.com/rust-bitcoin/rust-bitcoin/pull/103) after nearly nine months
# 0.16.0 - 2019-01-15
* Reorganize opcode types to eliminate unsafe code
* Un-expose some macros that were unintentionally exported
* Update rust-secp256k1 dependency to 0.12
* Remove `util::iter::Pair` type which does not belong in this library
* Minor bugfixes and optimizations
# 0.15.1 - 2018-11-08
* [Detect p2pk addresses with compressed keys](https://github.com/rust-bitcoin/rust-bitcoin/pull/189)
# 0.15.0 - 2018-11-03
* [Significant API overhaul](https://github.com/rust-bitcoin/rust-bitcoin/pull/156):
* Remove `nu_select` macro and low-level networking support
* Move `network::consensus_params` to `consensus::params`
* Move many other things into `consensus::params`
* Move `BitcoinHash` from `network::serialize` to `util::hash`; remove impl for `Vec<u8>`
* Rename/restructure error types
* Rename `Consensus{De,En}coder` to `consensus::{De,En}coder`
* Replace `Raw{De,En}coder` with blanket impls of `consensus::{De,En}coder` on `io::Read` and `io::Write`
* make `serialize` and `serialize_hex` infallible
* Make 0-input transaction de/serialization [always use segwit](https://github.com/rust-bitcoin/rust-bitcoin/pull/153)
* Implement `FromStr` and `Display` for many more types
# 0.14.2 - 2018-09-11
* Add serde support for `Address`
# 0.14.1 - 2018-08-28
* Reject non-compact `VarInt`s on various types
* Expose many types at the top level of the crate
* Add `Ord`, `PartialOrd` impls for `Script`
# 0.14.0 - 2018-08-22
* Add [regtest network](https://github.com/rust-bitcoin/rust-bitcoin/pull/84) to `Network` enum
* Add [`Script::is_op_return()`](https://github.com/rust-bitcoin/rust-bitcoin/pull/101/) which is more specific than
`Script::is_provably_unspendable()`
* Update to bech32 0.8.0; [add Regtest bech32 address support](https://github.com/rust-bitcoin/rust-bitcoin/pull/110)
* [Replace rustc-serialize dependency with hex](https://github.com/rust-bitcoin/rust-bitcoin/pull/107) as a stopgap
toward eliminating any extra dependencies for this; clean up the many independent hex encoders and decoders
throughout the codebase.
* [Add conversions between `ChildNumber` and `u32`](https://github.com/rust-bitcoin/rust-bitcoin/pull/126); make
representation non-public; fix documentation
* [Add several derivation convenience](https://github.com/rust-bitcoin/rust-bitcoin/pull/129) to `bip32` extended keys
* Make `deserialize::deserialize()` [enforce no trailing bytes](https://github.com/rust-bitcoin/rust-bitcoin/pull/129)
* Replace `TxOutRef` with `OutPoint`; use it in `TxIn` struct.
* Use modern `as_` `to_` `into_` conventions for array-wrapping types; impl `Display` rather than `ToString` for most types
* Change `script::Instructions` iterator [to allow rejecting non-minimal pushes](https://github.com/rust-bitcoin/rust-bitcoin/pull/136);
fix bug where errors would iterate forever.
* Overhaul `util::Error`; introduce `serialize::Error` [and use it for `SimpleDecoder` and `SimpleDecoder` rather
than parameterizing these over their error type](https://github.com/rust-bitcoin/rust-bitcoin/pull/137).
* Overhaul `UDecimal` and `Decimal` serialization and parsing [and fix many lingering parsing bugs](https://github.com/rust-bitcoin/rust-bitcoin/pull/142)
* [Update to serde 1.0 and strason 0.4](https://github.com/rust-bitcoin/rust-bitcoin/pull/125)
* Update to secp256k1 0.11.0
* Many, many documentation and test improvements.
# 0.13.1
* Add `Display` trait to uints, `FromStr` trait to `Network` enum
* Add witness inv types to inv enum, constants for Bitcoin regtest network, `is_coin_base` accessor for tx inputs
* Expose `merkleroot(Vec<Sha256dHash>)`
# 0.13
* Move witnesses inside the `TxIn` structure
* Add `Transaction::get_weight()`
* Update bip143 `sighash_all` API to be more ergonomic
# 0.12
* The in-memory blockchain was moved into a dedicated project rust-bitcoin-chain.
* Removed old script interpreter
* A new optional feature "bitcoinconsensus" lets this library use Bitcoin Core's native
script verifier, wrappend into Rust by the rust-bitcoinconsenus project.
See `Transaction::verify` and `Script::verify` methods.
* Replaced Base58 traits with `encode_slice`, `check_encode_slice`, from and `from_check` functions in the base58 module.
* Un-reversed the Debug output for Sha256dHash
* Add bech32 support
* Support segwit address types
### 0.11
* Remove `num` dependency at Matt's request; agree this is obnoxious to require all
downstream users to also have a `num` dependency just so they can use `Uint256::from_u64`.

View File

@ -1,7 +1,6 @@
[package]
name = "bitcoin"
version = "0.13.0"
version = "0.23.0"
authors = ["Andrew Poelstra <apoelstra@wpsoftware.net>"]
license = "CC0-1.0"
homepage = "https://github.com/rust-bitcoin/rust-bitcoin/"
@ -16,19 +15,24 @@ name = "bitcoin"
path = "src/lib.rs"
[features]
bitcoinconsenus = ["bitcoinconsensus"]
fuzztarget = ["secp256k1/fuzztarget"]
fuzztarget = ["secp256k1/fuzztarget", "bitcoin_hashes/fuzztarget"]
unstable = []
rand = ["secp256k1/rand-std"]
use-serde = ["serde", "bitcoin_hashes/serde", "secp256k1/serde"]
[dependencies]
bitcoin-bech32 = "0.5.1"
byteorder = "1.1"
rand = "0.3"
rust-crypto = "0.2"
rustc-serialize = "0.3"
serde = "0.6"
strason = "0.3"
bitcoinconsensus = { version = "0.16", optional=true }
bech32 = "0.7.2"
bitcoin_hashes = "0.7.3"
secp256k1 = "0.17.1"
[dependencies.secp256k1]
version = "0.9"
features = [ "rand" ]
bitcoinconsensus = { version = "0.19.0-1", optional = true }
serde = { version = "1", optional = true }
[dev-dependencies]
hex = "=0.3.2"
serde_derive = "<1.0.99"
serde_json = "<1.0.45"
serde_test = "1"
secp256k1 = { version = "0.17.1", features = ["rand-std"] }
# We need to pin ryu (transitive dep from serde_json) to stay compatible with Rust 1.22.0
ryu = "<1.0.5"

106
README.md
View File

@ -1,10 +1,10 @@
[![Status](https://travis-ci.org/rust-bitcoin/rust-bitcoin.png?branch=master)](https://travis-ci.org/rust-bitcoin/rust-bitcoin)
[![Safety Dance](https://img.shields.io/badge/unsafe-forbidden-success.svg)](https://github.com/rust-secure-code/safety-dance/)
# Rust Bitcoin Library
Library with support for de/serialization, parsing and executing on data
structures and network messages related to Bitcoin and other blockchain-based
currencies.
structures and network messages related to Bitcoin.
[Documentation](https://docs.rs/bitcoin/)
@ -14,20 +14,11 @@ Supports (or should support)
* De/serialization of blocks and transactions
* Script de/serialization
* Private keys and address creation, de/serialization and validation (including full BIP32 support)
* PSBT creation, manipulation, merging and finalization
* Pay-to-contract support as in Appendix A of the [Blockstream sidechains whitepaper](https://www.blockstream.com/sidechains.pdf)
For JSONRPC interaction with Bitcoin Core, it is recommended to use [rust-jsonrpc](https://github.com/apoelstra/rust-jsonrpc)
which uses the underlying [strason library](https://github.com/apoelstra/strason)
which parses decimal numbers as strings, preventing precision errors.
# Usage
To use rust-bitcoin, just add the following to your Cargo.toml.
```toml
[dependencies]
bitcoin = "0.12"
```
For JSONRPC interaction with Bitcoin Core, it is recommended to use
[rust-bitcoincore-rpc](https://github.com/rust-bitcoin/rust-bitcoincore-rpc).
# Known limitations
@ -47,12 +38,54 @@ fix specific consensus incompatibilities are welcome.
## Documentation
Currently the [documentation](https://www.wpsoftware.net/rustdoc/bitcoin/)
is very sparse. Patches to add usage examples and to expand on existing
docs would be extremely appreciated.
Currently can be found on [docs.rs/bitcoin](https://docs.rs/bitcoin/).
Patches to add usage examples and to expand on existing docs would be extremely
appreciated.
# Contributing
Contributions are generally welcome. If you intend to make larger changes please
discuss them in an issue before PRing them to avoid duplicate work and
architectural mismatches. If you have any questions or ideas you want to discuss
please join us in
[#rust-bitcoin](http://webchat.freenode.net/?channels=%23rust-bitcoin) on
freenode.
# Policy on Altcoins/Altchains
## Minimum Supported Rust Version (MSRV)
This library should always compile with any combination of features on **Rust 1.22**.
## Installing Rust
Rust can be installed using your package manager of choice or
[rustup.rs](https://rustup.rs). The former way is considered more secure since
it typically doesn't involve trust in the CA system. But you should be aware
that the version of Rust shipped by your distribution might be out of date.
Generally this isn't a problem for `rust-bitcoin` since we support much older
versions (>=1.22) than the current stable one.
## Building
The library can be built and tested using [`cargo`](https://github.com/rust-lang/cargo/):
```
git clone git@github.com:rust-bitcoin/rust-bitcoin.git
cd rust-bitcoin
cargo build
```
You can run tests with:
```
cargo test
```
Please refer to the [`cargo` documentation](https://doc.rust-lang.org/stable/cargo/) for more detailed instructions.
## Pull Requests
Every PR needs at least two reviews to get merged. During the review phase
maintainers and contributors are likely to leave comments and request changes.
Please try to address them, otherwise your PR might get closed without merging
after a longer time of inactivity. If your PR isn't ready for review yet please
mark it by prefixing the title with `WIP: `.
## Policy on Altcoins/Altchains
Patches which add support for non-Bitcoin cryptocurrencies by adding constants
to existing enums (e.g. to set the network message magic-byte sequence) are
@ -66,39 +99,12 @@ cross-chain atomic swaps) are more likely to be accepted than things which
support only a single blockchain.
## Release Notes
# Release Notes
I will try to document all breaking changes here so that people upgrading will know
what they need to change.
See [CHANGELOG.md](CHANGELOG.md).
### 0.11
Remove `num` dependency at Matt's request; agree this is obnoxious to require all
downstream users to also have a `num` dependency just so they can use `Uint256::from_u64`.
### 0.12
* The in-memory blockchain was moved into a dedicated project rust-bitcoin-chain.
* Removed old script interpreter
* A new optional feature "bitcoinconsenus" lets this library use Bitcoin Core's native
script verifier, wrappend into Rust by the rust-bitcoinconsenus project.
See `Transaction::verify` and `Script::verify` methods.
* Replaced Base58 traits with `encode_slice`, `check_encode_slice`, from and `from_check` functions in the base58 module.
* Un-reversed the Debug output for Sha256dHash
* Add bech32 support
* Support segwit address types
### 0.13
* Move witnesses inside the `TxIn` structure
* Add `Transaction::get_weight()`
* Update bip143 `sighash_all` API to be more ergonomic
# Licensing
The code in this project is licensed under the [Creative Commons CC0 1.0
Universal license](LICENSE).

49
contrib/test.sh Executable file
View File

@ -0,0 +1,49 @@
#!/bin/sh -ex
FEATURES="bitcoinconsensus use-serde rand"
if [ "$DO_COV" = true ]
then
export RUSTFLAGS="-C link-dead-code"
fi
# Use toolchain if explicitly specified
if [ -n "$TOOLCHAIN" ]
then
alias cargo="cargo +$TOOLCHAIN"
fi
# Test without any features first
cargo test --verbose
# Test each feature
for feature in ${FEATURES}
do
cargo test --verbose --features="$feature"
done
# Fuzz if told to
if [ "$DO_FUZZ" = true ]
then
(
cd fuzz
cargo test --verbose
./travis-fuzz.sh
)
fi
# Bench if told to
if [ "$DO_BENCH" = true ]
then
cargo bench --features unstable
fi
# Use as dependency if told to
if [ -n "$AS_DEPENDENCY" ]
then
cargo new dep_test
cd dep_test
echo 'bitcoin = { path = "..", features = ["use-serde"] }' >> Cargo.toml
cargo test --verbose
fi

114
examples/handshake.rs Normal file
View File

@ -0,0 +1,114 @@
extern crate bitcoin;
use std::net::{IpAddr, Ipv4Addr, Shutdown, SocketAddr, TcpStream};
use std::time::{SystemTime, UNIX_EPOCH};
use std::{env, process};
use std::io::Write;
use bitcoin::consensus::encode;
use bitcoin::network::{address, constants, message, message_network};
use bitcoin::network::stream_reader::StreamReader;
use bitcoin::secp256k1;
use bitcoin::secp256k1::rand::Rng;
fn main() {
// This example establishes a connection to a Bitcoin node, sends the intial
// "version" message, waits for the reply, and finally closes the connection.
let args: Vec<String> = env::args().collect();
if args.len() < 2 {
eprintln!("not enough arguments");
process::exit(1);
}
let str_address = &args[1];
let address: SocketAddr = str_address.parse().unwrap_or_else(|error| {
eprintln!("Error parsing address: {:?}", error);
process::exit(1);
});
let version_message = build_version_message(address);
let first_message = message::RawNetworkMessage {
magic: constants::Network::Bitcoin.magic(),
payload: version_message,
};
if let Ok(mut stream) = TcpStream::connect(address) {
// Send the message
let _ = stream.write_all(encode::serialize(&first_message).as_slice());
println!("Sent version message");
// Setup StreamReader
let read_stream = stream.try_clone().unwrap();
let mut stream_reader = StreamReader::new(read_stream, None);
loop {
// Loop an retrieve new messages
let reply: message::RawNetworkMessage = stream_reader.read_next().unwrap();
match reply.payload {
message::NetworkMessage::Version(_) => {
println!("Received version message: {:?}", reply.payload);
let second_message = message::RawNetworkMessage {
magic: constants::Network::Bitcoin.magic(),
payload: message::NetworkMessage::Verack,
};
let _ = stream.write_all(encode::serialize(&second_message).as_slice());
println!("Sent verack message");
}
message::NetworkMessage::Verack => {
println!("Received verack message: {:?}", reply.payload);
break;
}
_ => {
println!("Received unknown message: {:?}", reply.payload);
break;
}
}
}
let _ = stream.shutdown(Shutdown::Both);
} else {
eprintln!("Failed to open connection");
}
}
fn build_version_message(address: SocketAddr) -> message::NetworkMessage {
// Building version message, see https://en.bitcoin.it/wiki/Protocol_documentation#version
let my_address = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 0);
// "bitfield of features to be enabled for this connection"
let services = constants::ServiceFlags::NONE;
// "standard UNIX timestamp in seconds"
let timestamp = SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("Time error")
.as_secs();
// "The network address of the node receiving this message"
let addr_recv = address::Address::new(&address, constants::ServiceFlags::NONE);
// "The network address of the node emitting this message"
let addr_from = address::Address::new(&my_address, constants::ServiceFlags::NONE);
// "Node random nonce, randomly generated every time a version packet is sent. This nonce is used to detect connections to self."
let nonce: u64 = secp256k1::rand::thread_rng().gen();
// "User Agent (0x00 if string is 0 bytes long)"
let user_agent = String::from("rust-example");
// "The last block received by the emitting node"
let start_height: i32 = 0;
// Construct the message
message::NetworkMessage::Version(message_network::VersionMessage::new(
services,
timestamp as i64,
addr_recv,
addr_from,
nonce,
user_agent,
start_height,
))
}

View File

@ -13,7 +13,7 @@ honggfuzz_fuzz = ["honggfuzz"]
[dependencies]
honggfuzz = { version = "0.5", optional = true }
afl = { version = "0.3", optional = true }
afl = { version = "0.4", optional = true }
bitcoin = { path = "..", features = ["fuzztarget"] }
# Prevent this from interfering with workspaces
@ -35,3 +35,23 @@ path = "fuzz_targets/deserialize_transaction.rs"
[[bin]]
name = "deserialize_address"
path = "fuzz_targets/deserialize_address.rs"
[[bin]]
name = "deserialize_amount"
path = "fuzz_targets/deserialize_amount.rs"
[[bin]]
name = "outpoint_string"
path = "fuzz_targets/outpoint_string.rs"
[[bin]]
name = "deserialize_psbt"
path = "fuzz_targets/deserialize_psbt.rs"
[[bin]]
name = "deser_net_msg"
path = "fuzz_targets/deser_net_msg.rs"
[[bin]]
name = "uint128_fuzz"
path = "fuzz_targets/uint128_fuzz.rs"

View File

@ -0,0 +1,52 @@
extern crate bitcoin;
fn do_test(data: &[u8]) {
let _: Result<bitcoin::network::message::RawNetworkMessage, _> = bitcoin::consensus::encode::deserialize(data);
}
#[cfg(feature = "afl")]
#[macro_use] extern crate afl;
#[cfg(feature = "afl")]
fn main() {
fuzz!(|data| {
do_test(&data);
});
}
#[cfg(feature = "honggfuzz")]
#[macro_use] extern crate honggfuzz;
#[cfg(feature = "honggfuzz")]
fn main() {
loop {
fuzz!(|data| {
do_test(data);
});
}
}
#[cfg(test)]
mod tests {
fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
let mut b = 0;
for (idx, c) in hex.as_bytes().iter().enumerate() {
b <<= 4;
match *c {
b'A'...b'F' => b |= c - b'A' + 10,
b'a'...b'f' => b |= c - b'a' + 10,
b'0'...b'9' => b |= c - b'0',
_ => panic!("Bad hex"),
}
if (idx & 1) == 1 {
out.push(b);
b = 0;
}
}
}
#[test]
fn duplicate_crash() {
let mut a = Vec::new();
extend_vec_from_hex("00", &mut a);
super::do_test(&a);
}
}

View File

@ -10,10 +10,10 @@ fn do_test(data: &[u8]) {
}
#[cfg(feature = "afl")]
extern crate afl;
#[macro_use] extern crate afl;
#[cfg(feature = "afl")]
fn main() {
afl::read_stdio_bytes(|data| {
fuzz!(|data| {
do_test(&data);
});
}

View File

@ -0,0 +1,74 @@
extern crate bitcoin;
use std::str::FromStr;
fn do_test(data: &[u8]) {
let data_str = String::from_utf8_lossy(data);
// signed
let samt = match bitcoin::util::amount::SignedAmount::from_str(&data_str) {
Ok(amt) => amt,
Err(_) => return,
};
let samt_roundtrip = match bitcoin::util::amount::SignedAmount::from_str(&samt.to_string()) {
Ok(amt) => amt,
Err(_) => return,
};
assert_eq!(samt, samt_roundtrip);
// unsigned
let amt = match bitcoin::util::amount::Amount::from_str(&data_str) {
Ok(amt) => amt,
Err(_) => return,
};
let amt_roundtrip = match bitcoin::util::amount::Amount::from_str(&amt.to_string()) {
Ok(amt) => amt,
Err(_) => return,
};
assert_eq!(amt, amt_roundtrip);
}
#[cfg(feature = "afl")]
#[macro_use] extern crate afl;
#[cfg(feature = "afl")]
fn main() {
fuzz!(|data| {
do_test(&data);
});
}
#[cfg(feature = "honggfuzz")]
#[macro_use] extern crate honggfuzz;
#[cfg(feature = "honggfuzz")]
fn main() {
loop {
fuzz!(|data| {
do_test(data);
});
}
}
#[cfg(test)]
mod tests {
fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
let mut b = 0;
for (idx, c) in hex.as_bytes().iter().enumerate() {
b <<= 4;
match *c {
b'A'...b'F' => b |= c - b'A' + 10,
b'a'...b'f' => b |= c - b'a' + 10,
b'0'...b'9' => b |= c - b'0',
_ => panic!("Bad hex"),
}
if (idx & 1) == 1 {
out.push(b);
b = 0;
}
}
}
#[test]
fn duplicate_crash() {
let mut a = Vec::new();
extend_vec_from_hex("00000000", &mut a);
super::do_test(&a);
}
}

View File

@ -1,14 +1,14 @@
extern crate bitcoin;
type BResult = Result<bitcoin::blockdata::block::Block, bitcoin::util::Error>;
fn do_test(data: &[u8]) {
let _: BResult = bitcoin::network::serialize::deserialize(data);
let _: Result<bitcoin::blockdata::block::Block, _>= bitcoin::consensus::encode::deserialize(data);
}
#[cfg(feature = "afl")]
extern crate afl;
#[macro_use] extern crate afl;
#[cfg(feature = "afl")]
fn main() {
afl::read_stdio_bytes(|data| {
fuzz!(|data| {
do_test(&data);
});
}

View File

@ -0,0 +1,61 @@
extern crate bitcoin;
fn do_test(data: &[u8]) {
let psbt: Result<bitcoin::util::psbt::PartiallySignedTransaction, _> = bitcoin::consensus::encode::deserialize(data);
match psbt {
Err(_) => {},
Ok(psbt) => {
let ser = bitcoin::consensus::encode::serialize(&psbt);
let deser: bitcoin::util::psbt::PartiallySignedTransaction = bitcoin::consensus::encode::deserialize(&ser).unwrap();
// Since the fuzz data could order psbt fields differently, we compare to our deser/ser instead of data
assert_eq!(ser, bitcoin::consensus::encode::serialize(&deser));
}
}
}
#[cfg(feature = "afl")]
#[macro_use] extern crate afl;
#[cfg(feature = "afl")]
fn main() {
fuzz!(|data| {
do_test(&data);
});
}
#[cfg(feature = "honggfuzz")]
#[macro_use] extern crate honggfuzz;
#[cfg(feature = "honggfuzz")]
fn main() {
loop {
fuzz!(|data| {
do_test(data);
});
}
}
#[cfg(test)]
mod tests {
fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
let mut b = 0;
for (idx, c) in hex.as_bytes().iter().enumerate() {
b <<= 4;
match *c {
b'A'...b'F' => b |= c - b'A' + 10,
b'a'...b'f' => b |= c - b'a' + 10,
b'0'...b'9' => b |= c - b'0',
_ => panic!("Bad hex"),
}
if (idx & 1) == 1 {
out.push(b);
b = 0;
}
}
}
#[test]
fn duplicate_crash() {
let mut a = Vec::new();
extend_vec_from_hex("00", &mut a);
super::do_test(&a);
}
}

View File

@ -1,14 +1,52 @@
extern crate bitcoin;
type BResult = Result<bitcoin::blockdata::script::Script, bitcoin::util::Error>;
use bitcoin::util::address::Address;
use bitcoin::network::constants::Network;
use bitcoin::blockdata::script;
use bitcoin::consensus::encode;
fn do_test(data: &[u8]) {
let _: BResult = bitcoin::network::serialize::deserialize(data);
let s: Result<script::Script, _> = encode::deserialize(data);
if let Ok(script) = s {
let _: Vec<script::Instruction> = script.iter(false).collect();
let enforce_min: Vec<script::Instruction> = script.iter(true).collect();
let mut b = script::Builder::new();
for ins in enforce_min {
match ins {
script::Instruction::Error(_) => return,
script::Instruction::Op(op) => { b = b.push_opcode(op); }
script::Instruction::PushBytes(bytes) => {
// Any one-byte pushes, except -0, which can be interpreted as numbers, should be
// reserialized as numbers. (For -1 through 16, this will use special ops; for
// others it'll just reserialize them as pushes.)
if bytes.len() == 1 && bytes[0] != 0x80 && bytes[0] != 0x00 {
if let Ok(num) = script::read_scriptint(bytes) {
b = b.push_int(num);
} else {
b = b.push_slice(bytes);
}
} else {
b = b.push_slice(bytes);
}
}
}
}
assert_eq!(b.into_script(), script);
assert_eq!(data, &encode::serialize(&script)[..]);
// Check if valid address and if that address roundtrips.
if let Some(addr) = Address::from_script(&script, Network::Bitcoin) {
assert_eq!(addr.script_pubkey(), script);
}
}
}
#[cfg(feature = "afl")]
extern crate afl;
#[macro_use] extern crate afl;
#[cfg(feature = "afl")]
fn main() {
afl::read_stdio_bytes(|data| {
fuzz!(|data| {
do_test(&data);
});
}

View File

@ -1,26 +1,35 @@
extern crate bitcoin;
type BResult = Result<bitcoin::blockdata::transaction::Transaction, bitcoin::util::Error>;
fn do_test(data: &[u8]) {
let tx_result: BResult = bitcoin::network::serialize::deserialize(data);
let tx_result: Result<bitcoin::blockdata::transaction::Transaction, _> = bitcoin::consensus::encode::deserialize(data);
match tx_result {
Err(_) => {},
Ok(mut tx) => {
let len = bitcoin::network::serialize::serialize(&tx).unwrap().len() as u64;
let ser = bitcoin::consensus::encode::serialize(&tx);
assert_eq!(&ser[..], data);
let len = ser.len();
let calculated_weight = tx.get_weight();
for input in &mut tx.input {
input.witness = vec![];
}
let no_witness_len = bitcoin::network::serialize::serialize(&tx).unwrap().len() as u64;
assert_eq!(no_witness_len * 3 + len, calculated_weight);
let no_witness_len = bitcoin::consensus::encode::serialize(&tx).len();
// For 0-input transactions, `no_witness_len` will be incorrect because
// we serialize as segwit even after "stripping the witnesses". We need
// to drop two bytes (i.e. eight weight)
if tx.input.is_empty() {
assert_eq!(no_witness_len * 3 + len - 8, calculated_weight);
} else {
assert_eq!(no_witness_len * 3 + len, calculated_weight);
}
},
}
}
#[cfg(feature = "afl")]
extern crate afl;
#[macro_use] extern crate afl;
#[cfg(feature = "afl")]
fn main() {
afl::read_stdio_bytes(|data| {
fuzz!(|data| {
do_test(&data);
});
}
@ -58,7 +67,7 @@ mod tests {
#[test]
fn duplicate_crash() {
let mut a = Vec::new();
extend_vec_from_hex("00", &mut a);
extend_vec_from_hex("000700000001000000010000", &mut a);
super::do_test(&a);
}
}

View File

@ -0,0 +1,88 @@
extern crate bitcoin;
use bitcoin::blockdata::transaction::OutPoint;
use bitcoin::consensus::encode;
use std::str::FromStr;
fn do_test(data: &[u8]) {
let lowercase: Vec<u8> = data.iter().map(|c| match *c {
b'A' => b'a',
b'B' => b'b',
b'C' => b'c',
b'D' => b'd',
b'E' => b'e',
b'F' => b'f',
x => x
}).collect();
let data_str = match String::from_utf8(lowercase) {
Err(_) => return,
Ok(s) => s,
};
match OutPoint::from_str(&data_str) {
Ok(op) => {
assert_eq!(op.to_string().as_bytes(), data_str.as_bytes());
}
Err(_) => {
// If we can't deserialize as a string, try consensus deserializing
let res: Result<OutPoint, _> = encode::deserialize(data);
if let Ok(deser) = res {
let ser = encode::serialize(&deser);
assert_eq!(ser, data);
let string = deser.to_string();
match OutPoint::from_str(&string) {
Ok(destring) => assert_eq!(destring, deser),
Err(_) => panic!()
}
}
}
}
}
#[cfg(feature = "afl")]
#[macro_use] extern crate afl;
#[cfg(feature = "afl")]
fn main() {
fuzz!(|data| {
do_test(&data);
});
}
#[cfg(feature = "honggfuzz")]
#[macro_use] extern crate honggfuzz;
#[cfg(feature = "honggfuzz")]
fn main() {
loop {
fuzz!(|data| {
do_test(data);
});
}
}
#[cfg(test)]
mod tests {
fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
let mut b = 0;
for (idx, c) in hex.as_bytes().iter().enumerate() {
b <<= 4;
match *c {
b'A'...b'F' => b |= c - b'A' + 10,
b'a'...b'f' => b |= c - b'a' + 10,
b'0'...b'9' => b |= c - b'0',
_ => panic!("Bad hex"),
}
if (idx & 1) == 1 {
out.push(b);
b = 0;
}
}
}
#[test]
fn duplicate_crash() {
let mut a = Vec::new();
extend_vec_from_hex("00", &mut a);
super::do_test(&a);
}
}

View File

@ -0,0 +1,101 @@
extern crate bitcoin;
use std::str::FromStr;
fn do_test(data: &[u8]) {
macro_rules! read_ints {
($start: expr) => { {
let mut native = 0;
for c in data[$start..$start + 16].iter() {
native <<= 8;
native |= (*c) as u128;
}
// Note BE:
let uint128 = bitcoin::util::uint::Uint128::from(&[native as u64, (native >> 8*8) as u64][..]);
(native, uint128)
} }
}
macro_rules! check_eq {
($native: expr, $uint: expr) => { {
assert_eq!(&[$native as u64, ($native >> 8*8) as u64], $uint.as_bytes());
} }
}
if data.len() != 16*2 + 1 { return; }
let (a_native, a) = read_ints!(0);
// Checks using only a:
for i in 0..128 {
check_eq!(a_native << i, a << i);
check_eq!(a_native >> i, a >> i);
}
assert_eq!(a_native as u64, a.low_u64());
assert_eq!(a_native as u32, a.low_u32());
assert_eq!(128 - a_native.leading_zeros() as usize, a.bits());
assert_eq!(a_native as u64, bitcoin::util::uint::Uint128::from_u64(a_native as u64).unwrap().low_u64());
// Checks with two numbers:
let (b_native, b) = read_ints!(16);
check_eq!(a_native.wrapping_add(b_native), a + b);
check_eq!(a_native.wrapping_sub(b_native), a - b);
if b_native != 0 {
check_eq!(a_native.wrapping_div(b_native), a / b);
}
check_eq!(a_native.wrapping_mul(b_native), a * b);
check_eq!(a_native & b_native, a & b);
check_eq!(a_native | b_native, a | b);
check_eq!(a_native ^ b_native, a ^ b);
check_eq!(a_native.wrapping_mul((b_native as u32) as u128), a.mul_u32(b.low_u32()));
assert_eq!(a_native > b_native, a > b);
assert_eq!(a_native >= b_native, a >= b);
assert_eq!(a_native < b_native, a < b);
assert_eq!(a_native <= b_native, a <= b);
}
#[cfg(feature = "afl")]
#[macro_use] extern crate afl;
#[cfg(feature = "afl")]
fn main() {
fuzz!(|data| {
do_test(&data);
});
}
#[cfg(feature = "honggfuzz")]
#[macro_use] extern crate honggfuzz;
#[cfg(feature = "honggfuzz")]
fn main() {
loop {
fuzz!(|data| {
do_test(data);
});
}
}
#[cfg(test)]
mod tests {
fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
let mut b = 0;
for (idx, c) in hex.as_bytes().iter().enumerate() {
b <<= 4;
match *c {
b'A'...b'F' => b |= c - b'A' + 10,
b'a'...b'f' => b |= c - b'a' + 10,
b'0'...b'9' => b |= c - b'0',
_ => panic!("Bad hex"),
}
if (idx & 1) == 1 {
out.push(b);
b = 0;
}
}
}
#[test]
fn duplicate_crash() {
let mut a = Vec::new();
extend_vec_from_hex("100000a70000000000000000000000000000000000000000000000000000000054", &mut a);
super::do_test(&a);
}
}

View File

@ -0,0 +1 @@
tb1118755mmmmmmmmmm9264mmmmmmm932772648

View File

@ -0,0 +1 @@
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

View File

@ -0,0 +1 @@
11111111111111

View File

@ -0,0 +1 @@
BC1-71110837GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGWGGGG

View File

@ -0,0 +1 @@
BC1-711154444444444444444444444444444E083dU

View File

@ -0,0 +1 @@
BC1C1;71;711-7111544E083'1-71115111111O1111144E0837U

View File

@ -0,0 +1 @@
11111111111111111111111111111111111111111111

View File

@ -0,0 +1 @@
BC1-71115(4E0831-7111544E0837U7U

View File

@ -0,0 +1 @@
BC1C11111111111111111111111111~~~~~~~~~~~~~~~~~1111E0837U

View File

@ -0,0 +1 @@
BC111544E083'1-711154C1;71@711-7111544E083'1-7111544E0837U

View File

@ -0,0 +1 @@
tb1r70kt564

View File

@ -0,0 +1 @@
tb1170kt564

View File

@ -0,0 +1 @@
BC1C1;XXXXXXXXXXXXXXXXXXXXXXXXAXXX114E544E0<544E7111544E0837U

View File

@ -0,0 +1 @@
BC1C1;71;711-7111544E083'711-711154-7117'11-71115440837U

View File

@ -0,0 +1 @@
BC1C1;71;711-7111544E083'1-7111544E08377-7111544E0837UU

View File

@ -0,0 +1 @@
BC1-3711LLLLLLLLLLLLLL,LLLLLLLLLLLLLLLLL1544E0837U

View File

@ -0,0 +1 @@
tb127kkkkkkkkkkkkkkkkkkkkkkkkkkkkkk0kt56

View File

@ -0,0 +1 @@
BC1C1;71;711-44E083'1-711154SA0837111544E083'1-7111544E0837U

View File

@ -0,0 +1 @@
hhhhhhhhhhhhhhhhRhhhhhhhThhhhhhhhhhhhhhRhhhhhhhh

View File

@ -0,0 +1 @@
BC1EC1-7111544E0A37+111544E0A37U

View File

@ -0,0 +1 @@
BC1C1;71;.11-7111544-7*1'1-7*115C17*1'1-7*115C1CA;71;1C1;71;711-711-7111514E0837U

View File

@ -0,0 +1 @@
tb1118755mmmmmmmmmm9264mmmmmmm132772648

View File

@ -0,0 +1 @@
BC1C1;71;711-710154C1C1;71;711-4E083'1-7111544E0837U

View File

@ -0,0 +1 @@
tb1118755mmmnmmmmmm9264mmb1mmmmm93277264

Some files were not shown because too many files have changed in this diff Show More