Commit Graph

639 Commits

Author SHA1 Message Date
Andrew Poelstra 42960b959f eliminate type parameter from `Encodable` trait 2019-07-11 17:21:19 +00:00
Andrew Poelstra b734d6488a make consensus_encode return the encoded length 2019-07-11 17:15:32 +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
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
Andrew Poelstra cded694381
Merge pull request #277 from jonasnick/rand
Remove unused rand dependency
2019-07-03 20:42:44 +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
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
Jonas Nick 30f24a39d0 Remove confusing mentions of SPV 2019-06-07 13:12:07 +00: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 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 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
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
Nadav Ivgi 473b491409
Implement util::misc::signed_msg_hash() 2019-04-28 09:01:42 +03: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 9daf7fa9dc util::key add serde de/serialization 2019-03-21 18:27:42 +00: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
Andrew Poelstra 4dbf431ecd key: implement ToString and FromStr for PublicKey 2019-03-04 01:06:19 +00:00
Carl Dong e5b59120c5 Add copyright notice to PSBT-related files 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 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
Andrew Poelstra fc47c477ab key: add some missing functionality 2019-02-27 01:56:38 +00: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
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
Steven Roose f80e882813
Remove Address::p2pk
There is no address format for p2pk.
2019-02-07 20:02:21 +00: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 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 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
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
Carl Dong ff5c4a1806 Bump secp to 0.12 2019-01-15 12:58:54 -05: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
Andrew Poelstra 5a5158e120
Merge pull request #198 from sgeisler/safe-opcodes
Safe opcodes 1.14.0
2018-12-14 16:32:29 +00: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
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
Kaz Wesley 6b67c8cdff squashme: work around lack of associated constants 2018-11-11 14:58:33 -08: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
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
evgeniy.scherbina bc41772f89 added p2wkh, p2sh-p2wkh tests 2018-09-27 18:54:20 +03: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
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
Steven Roose 8edfbec1cb Implement serde serialiation for Address 2018-09-11 18:37:36 +01: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 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 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 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
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
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 94f3d4b0f9 update to secp256k1 0.10.0 2018-08-20 15:28:43 +00:00
Aleksei 356d13e465 Add some useful standard trait implementations 2018-08-20 12:11:17 +03: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
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
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
Carl Dong d4f28b6785 Add conversion between u32 and ChildNumber, fix docs 2018-08-10 13:49:45 -07: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
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
Sebastian Geisler 00cca03edd use bitcoin-bech32 v0.8.0 and adapt internal API usage 2018-07-25 21:09:46 +02:00
Roman Zeyde 69ea2a760b
Fix 2 small typos in comments 2018-06-09 22:27:40 +03: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 33261c7a12
Merge pull request #91 from TheBlueMatt/master
Check in fuzz inputs for all current targets
2018-06-04 18:32:19 +00: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
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
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
Igor Aleksanov 13f1fe1f08
Merge branch 'master' into data-method-in-impl-array-newtype 2018-05-17 19:07:08 +03: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
Matt Corallo 0e1d927b47 Only provide the required TxIn to bip143 sighash_all.
This resolves an very unergonomic API by allowing iteration over a
Transaction being signed's inputs without needing to take a
conflicting reference to the transaction.

The API is still relateively unsafe in that its very easy to
generate bogus sighashes with it, but this is much better than it
was, and its not clear how to fix it further.
2018-04-02 12:42:59 -04:00
Matt Corallo 855b377d51 Fix crash in Address::from_str if input isn't long enough 2018-03-21 18:44:10 -04:00
Matt Corallo 6826d8f35c Stub out Sha2 calls when fuzzing to mask all but the first byte 2018-03-21 18:44:10 -04:00
Andrew Poelstra 64987e349c minor nits to get compilation to work on rustc 1.14 (currently shipping Debian version) 2018-03-21 18:49:46 +00:00
Tamas Blummer 1a87244b2b Implement Segwit addresses 2018-03-20 18:26:51 +01:00
Andrew Poelstra 65d8df08b8 address: implement Bech32 support 2018-03-13 14:48:01 +00:00
Andrew Poelstra 9884bec577 add docs indicating change in Sha256dHash debug output 2018-03-12 21:50:35 +00:00
Andrew Poelstra 8968b081ca util: add Debug output for Sha256d and Hash160 which don't reverse the bytes 2018-03-12 21:27:09 +00:00
Andrew Poelstra ee1dfcf4a2 base58: remove Base58 traits, replace with encode/decode functions 2018-03-12 21:27:07 +00:00
Tamas Blummer 77ce6f18d0 Moved blockchain and patricia_tree to rust-memblocks 2018-03-09 17:22:31 +01:00
Andrew Poelstra 066c49305f update secp256k1 to latest version with minimized dependencies 2018-02-20 16:19:29 +00:00
Andrew Poelstra 047c0c149d remove `num` crate dependency 2018-02-18 15:21:13 +00:00
Andrew Poelstra 91a786d22c
Merge pull request #42 from tamasblummer/add_low_u64
add low_u64 to Uint256 and Uit128 types
2018-02-18 14:57:37 +00:00
Andrew Poelstra 3547d27430
Merge pull request #40 from tamasblummer/unit_debug_fix
fixing debug output for Uint256 and Uint128
2018-02-18 14:57:00 +00:00
Andrew Poelstra 7930d14124
Merge pull request #38 from apoelstra/bip143
util: add `bip143` module to create BIP143 signature hashes
2018-02-16 22:13:55 +00:00
Andrew Poelstra 9f092a6f31 remove all use of mem::uninitialized and mem::copy_nonoverlapping 2018-02-14 16:53:49 +00:00
Tamas Blummer 19f96fe62c add low_u64 to Uint256 and Uit128 types 2018-02-11 14:19:58 +01:00
Tamas Blummer e05f45beb0 fixing debug output for Uint256 and Uint128 2018-02-11 14:04:35 +01:00
Andrew Poelstra f233fcac61 util: add `bip143` module to create BIP143 signature hashes 2018-01-15 17:54:32 +00:00
Andrew Poelstra c691d0e382 util: add Sha256dEncoder to allow streaming data into a hash
This is needed to for a sane BIP143 implementation. Should be exactly equivalent to
serializing data into a vector then hashing that vector for all types.
2017-12-06 16:50:47 +00:00
Andrew Poelstra 8f7bd858fb
update byteorder to 1.1 from 0.3 2017-07-28 16:19:44 +00:00
Andrew Poelstra e3c793f702 uint: bugfix in trailing_zeroes() 2016-08-26 16:20:26 +00:00
Andrew Poelstra af10b153be segwit: add transaction/block serialization support for BIP141/BIP144; bump to 0.8
Do not yet support new sighash type
2016-08-24 16:24:55 +00:00
Andrew Poelstra 9d2826d5d1 bip32: error API cleanups 2016-06-24 19:45:42 +00:00
Andrew Poelstra f7d4ae8265 bip32: add accessor for the tweak used in public key derivation 2016-06-24 19:25:47 +00:00
Andrew Poelstra 14af175a11 Resurrect BIP32 support 2016-06-24 19:15:57 +00:00
Andrew Poelstra 1e47019221 cargo-clippy cleanups 2016-06-21 14:35:27 +00:00
Andrew Poelstra 1dbd1c28dc Implement stdlib Error trait for util::Error type 2016-06-20 01:25:54 +00:00
Andrew Poelstra 46681bbcac contracthash: expose key tweak in new function
Needed for applications where the tweak and the secret key material are on different
devices (and the one with the secret material does not want to know how to compute
the tweak itself).
2016-06-10 18:36:15 +00:00
Andrew Poelstra 35832e3da0 Remove some unused trait imports 2016-05-27 18:36:42 +00:00
Andrew Poelstra 96b4b050fd Serialize Sha256Hash without allocations 2016-05-03 20:16:30 +00:00
Andrew Poelstra f906c2fddd Add `first_push_as_number` function to contracthash templates
This is a bit of a hack to let users of the contracthash API to determine
how many sigs are required when signing a multisig contract.
2016-03-29 17:24:34 +00:00
Andrew Poelstra f18157e774 Minor code changes for new rustc/clippy. No effects. Update minor version number 2016-02-18 19:44:29 +00:00
Andrew Poelstra 5f308887c9 Fix test added for serde transaction roundtrip 2016-02-18 18:02:04 +00:00
Andrew Poelstra b88d04f0bc Add serde impls for all Transaction types
Bump version number; introduce rust-jsonrpc dependency
2016-02-10 03:37:24 +00:00
Andrew Poelstra 16f5878a03 Add a bunch of Ord/PartialOrd impls for stuff 2015-12-20 15:38:02 -06:00
Andrew Poelstra 45ef239a34 Add unsigned Decimal type 2015-12-19 20:13:59 -06:00
Andrew Poelstra a7c2dc6bb6 Add some accessors to the `Privkey` structure 2015-12-02 10:58:18 -06:00
Andrew Poelstra 1bbd492da6 Add nonnegative() utility function to Decimal 2015-11-30 14:23:15 -06:00
Andrew Poelstra 2962eb9d44 Add Display impl for Decimal 2015-11-30 14:08:45 -06:00
Andrew Poelstra a9cd31ccba Add addition and subtraction impls to Decimal 2015-11-30 14:03:57 -06:00
Andrew Poelstra 21ccd713ba Add helper from_hex() function for Sha256dHash 2015-11-30 11:03:04 -06:00
Andrew Poelstra 950e756316 Add formatters for Sha256dHash 2015-11-30 09:19:53 -06:00
Andrew Poelstra 76729f33ca Fix `Decimal` serialization of negative numbers 2015-11-30 09:13:48 -06:00
Andrew Poelstra a8ffce4904 Fix Script de/serialization (version -> 0.4.4) 2015-11-30 07:11:24 -06:00
Andrew Poelstra e58f536c31 Add `Decimal` type for de/serializing values 2015-11-22 10:51:19 -06:00
Andrew Poelstra c3c6983789 Replace serde_json with strason in tests 2015-11-22 09:46:05 -06:00
Andrew Poelstra 66eb08aab5 [BREAKING CHANGE] Make `script::Builder` implement the actual Builder pattern
Rather than having methods taking &mut self, have them consume self
and return another Builder, so that methods can be chained.

Bump major version number.
2015-11-04 11:04:54 -06:00
Andrew Poelstra 5e03adc9aa Changes for cargo-clippy warnings 2015-10-28 11:27:23 -05:00
Andrew Poelstra 67c0b8fba7 More Error implementations 2015-10-25 12:55:48 -05:00
Andrew Poelstra 34edf48b93 Implement Error for base58 error type 2015-10-25 10:16:05 -05:00
Andrew Poelstra 3491c5057e Make contracthashtool check that the number of keys matches the template's requirement
This is easy to satisfy given that the template-to-script code takes a
slice of keys. Just do &keys[..n_keys] if you have too many keys. (If
you have too few you're SOL no matter what.) This way we can catch
likely configuration errors without putting much of a burden on users
who legitimately have more keys than the template requires.

Also add a method required_keys() to Template so that users can check
how many keys they ought to have.
2015-10-25 08:37:32 -05:00
Andrew Poelstra 8defba2fb3 Expose ability to tweak secret keys for contract hash 2015-10-14 22:50:06 -05:00
Andrew Poelstra 38d2ef5d73 Add `from_script` method to Address for generating P2SH addresses 2015-10-14 22:24:09 -05:00
Andrew Poelstra ed34bb30f1 Add support for deserializing a script into a contracthash template
This is something Matt's contracthashtool does, so to copy its functionality
I need to support it. And it also seems generally useful.
2015-10-14 22:01:26 -05:00
Andrew Poelstra c1f81ea3c3 Add support for WIF private keys as well as addresses 2015-10-14 19:25:43 -05:00
Andrew Poelstra 16e2a3519b Implement basic contract-hash support
Does not do stuff like validating the form of contracts, since this seems like
more of an application thing. Does not even distinguish a "nonce", just assumes
the contract has whatever uniqueness is needed baked in.
2015-10-14 15:29:19 -05:00
Andrew Poelstra dba71d9253 [BREAKING CHANGE] Minor library updates
Breaking changes are:
    opcode::All::from_u8 is now From<u8>
    script::Builder::from_vec is now From<Vec<u8>>
    script::Script::from_vec is now From<Vec<u8>>
2015-10-14 09:14:09 -05:00
Andrew Poelstra eeb4655886 More updates for RFC 1214 2015-09-20 16:44:05 -05:00
Andrew Poelstra 14db7ee902 Fix for rustc RFC 1214; also add missing docs 2015-09-20 15:30:18 -05:00
Andrew Poelstra 00421970a1 Fix for serde changes 2015-09-20 13:10:20 -05:00
Andrew Poelstra 99a4845719 Get library building on stable 2015-09-20 12:22:39 -05:00
Andrew Poelstra adaf50a408 *** ALL TESTS PASS WITH RUSTC HEAD ***
There is still a lot of work to do modernizing the library, but the code
compiles cleanly with all unit tests passing now. Probably not much can
be done now until wizards-wallet is in better shape and the library is
actually in use.
2015-05-10 14:32:26 -05:00
Andrew Poelstra b21acd440e Get compiling for secp256k1 changes 2015-04-13 22:40:32 -05:00
Andrew Poelstra 17e27ec09f *** IT COMPILES ON RUSTC NIGHTLY ***
Many unit test failures, but this is progress.
2015-04-10 20:55:59 -05:00
Andrew Poelstra 3117f95b62 Checkpoint commit: into warnings! 2015-04-10 18:15:57 -05:00
Andrew Poelstra 1d78dccb9e Checkpoint commit -- we're onto move errors :D 2015-04-10 13:34:31 -05:00
Andrew Poelstra e5a3e84c41 Checkpoint commit (nope, not yet to small commit sizes :))
This is mostly fixing compile errors in `cargo test`. We are down
to 3 in `cargo build` and 14 in `cargo test`, at least for this
round.
2015-04-08 17:23:45 -05:00
Andrew Poelstra 08a20f8764 Checkpoint commit
Work is stalled on some other library work (to give better lifetime
requirements on `eventual::Future` and avoid some unsafety), so
committing here.

There are only three errors left in this round :)

Also all the indenting is done, so there should be no more massive
rewrite commits. Depending how invasive the lifetime-error fixes
are, I may even be able to do sanely sized commits from here on.
2015-04-07 17:52:58 -05:00
Andrew Poelstra 200e0fe8e3 Checkpoint commit
27 files changed, 3944 insertions(+), 3812 deletions(-) :} I've
started doing whitespace changes as well, I want everything to
be 4-space tabs from now on.
2015-04-06 20:51:11 -05:00
Andrew Poelstra 811df8a713 Giant collection of fixes ... we are into lifetime errors now :) 2015-04-05 19:10:37 -05:00
Andrew Poelstra 7b89c15ed5 More changes, incl. dropping DumbHasher in favor of SipHasher
only json stuff left in this round of compiler errors :)
2015-04-05 14:43:44 -05:00
Andrew Poelstra 7738722ab5 Checkpoint commit; tons of disorganized changes for rustc
BTW after all this is done I'm gonna indent the entire codebase...
so `git blame` is gonna be totally broken anyway, hence my
capricious cadence of commits.
2015-04-05 12:58:49 -05:00
Andrew Poelstra 160f2f9ea6 Drop ThinVec, many other changes toward updating for librustc 2015-04-04 22:13:19 -05:00
Andrew Poelstra a62a7d736c Several more changes for librustc changes 2015-04-04 13:08:49 -05:00
Andrew Poelstra 467f76a37d MemReader/MemWriter become Cursor, other rustc changes 2015-04-04 12:56:40 -05:00
Andrew Poelstra f1aed644c6 More misc cleanup for rustc changes 2015-03-26 14:21:48 -05:00
Andrew Poelstra 6db25db975 Bunch of error type changes 2015-03-26 11:52:20 -05:00
Andrew Poelstra 11dbc717c4 Show -> Debug 2015-03-26 10:35:31 -05:00
Andrew Poelstra df065c143b fix attributes for compiler changes 2015-03-26 10:31:19 -05:00
Andrew Poelstra 2101e4a56d Rename bitcoin-secp256k1-rs to secp256k1 2015-03-26 10:08:36 -05:00
Andrew Poelstra c3377032f8 Many syntax changes for rustc, incomplete 2015-01-18 17:39:51 -06:00
Andrew Poelstra 6250f4fd9c Checkpoint commit -- prefix-filtered address indexing works 2014-09-01 21:37:00 -05:00
Andrew Poelstra f66b4ff6b3 Fix for upstream, add some address generation benchmarks 2014-09-01 09:24:17 -07:00
Andrew Poelstra 931df9f68d Add Address support 2014-08-31 19:24:31 -07:00
Andrew Poelstra 340b569c73 Add much more agressive provably-false checker
Now unspendable outs are determined by attempting to create a minimal
satisfying input script. If this can't be done, the output is unspendable.
(Unfortunately this "minimal satisfying script" is not (yet) something
that can be shown to the user, since it is more a bundle of constraints
than actual data pushes.)

Current limitations:
  - OP_ADD and friends mean the checker gives the script a free pass.
    There is no fundamental reason for this, I just didn't get to it
    yet.

  - Pubkeys are checked for DER encoding but signatures aren't. This
    is because secp256k1 exposes a method for pubkeys, but not one
    for sigs :). Signatures are loosely length checked.
2014-08-31 16:01:24 -07:00
Andrew Poelstra 8f5c28a533 Fixes for rustc changes 2014-08-30 16:08:38 -07:00
Andrew Poelstra 38f8132067 Fix for upstream 2014-08-28 11:13:33 -07:00
Andrew Poelstra 6bf553c6fe Add BIP32 key support; unify array newtyping; improve base58 trait
Sorry for so many things in one commit ... it was an iterative
process depending as I worked on BIP32 to get the other stuff
working. (And I was too lazy to separate it out after the fact.)

A breaking change by the array newtyping is that Show for Sha256dHash
now outputs the slice Show. You have to use `{:x}` to get the old hex
output.
2014-08-28 09:49:03 -07:00
Andrew Poelstra 47c346be71 Add base58 decode/encode functionality 2014-08-24 23:03:47 -07:00
Andrew Poelstra 688a77ef38 Rename Hash->Uint functions to denote endianness 2014-08-24 12:28:02 -07:00
Andrew Poelstra 611b1f57c9 Add a bunch of small hashtypes for cheap'n'collidey hashtables 2014-08-22 11:32:42 -07:00
Andrew Poelstra 8a814e4331 Add P2SH support 2014-08-15 17:37:40 -07:00
Andrew Poelstra d9d7416e32 Fixes for recent stdlib changes 2014-08-14 15:20:39 -07:00
Andrew Poelstra cfe7d5eb26 Use slices rather than allocations in most parts of script 2014-08-13 20:25:28 -07:00
Andrew Poelstra 526f9fc574 Remove -all- CODESEPARATORS before serializing the script, even though only one has effect
I can validate the whole testnet chain now :) onto P2SH!
2014-08-12 21:34:46 -07:00
Andrew Poelstra 38593dd2ab Remove entire signature push operation, not just signature data, when hashing for checksig 2014-08-11 21:40:30 -07:00
Andrew Poelstra a87dd0042b Get OP_MULTISIG working 2014-08-10 21:37:12 -07:00
Andrew Poelstra e01e9ad3be Implement CHECKSIG and CHECKSIGVERIFY
Still need the multisig ops, and p2sh
2014-08-10 13:51:05 -07:00
Andrew Poelstra ecdb750148 Implement script except for crypto opcodes, replace zero_hash by Default
Looks like to implement the crypto opcodes I may need to switch from
rust-crypto to rust-openssl.. or implement RIPEMD-160 for rust-crypto.
In either case I will need to generalize the hash.rs stuff to support
other hashes, so I'm committing here as a checkpoint before doing all
that.
2014-08-05 19:08:06 -07:00
Andrew Poelstra 2986e1f983 Fix for new partial-move rules; swap hash le_hex_string and be_hex_string
I noticed that the little/big endian hex string functions for Sha256dHash
did not match my intuition. What we should have is that the raw bytes
correspond to a little-endian representation (since we convert to Uint256
by transmuting, and Uint256's have little-endian representation) while
the reversed raw bytes are big-endian.

This means that the output from `sha256sum` is "little-endian", while the
standard "zeros on the left" output from bitcoind is "big-endian". This
is correct since we think of blockhashes as being "below the target" when
they have lots of zeros on the left, and we also notice that when hashing
Bitcoin objects with sha256sum that the output hashes are always reversed.

These two functions le_hex_string and be_hex_string should really not be
used outside of the library; the Encodable trait should give access to a
"big endian" representation while ConsensusEncodable gives access to a
"little endian" representation. That way we describe the split in terms
of user-facing/consensus code rather than big/little endian code, which
is a better way of thinking about it. After all, a hash is a collection
of bytes, not a number --- it doesn't have an intrinsic endianness.

Oh, and by the way, to compute a sha256d hash from sha256sum, you do

  echo -n 'data' | sha256sum | xxd -r -p | sha256dsum
2014-08-03 14:52:59 -07:00
Andrew Poelstra a6eb33efd0 Actually encode network message
A pretty serious oversight :) this was not noticed because I was
simultaneously dealing with a serious tcp connection bug in rustc,
and I had thought bitcoind's angry disconnects were a further
symptom of that.
2014-08-02 18:22:27 -07:00
Andrew Poelstra c80ec9bda8 Sha256dHash: add string encoder/decoder 2014-08-01 10:52:10 -07:00
Andrew Poelstra a2ce000b2b Revamp Serializable interface to be similar to Encoder/Encodable
This is a massive simplification, fixes a couple endianness bugs (though
not all of them I don't think), should give a speedup, gets rid of the
`serialize_iter` crap.
2014-08-01 09:01:39 -07:00
Andrew Poelstra a34f2642f1 Implement ToJson for BlockHeader
I think this is what I want to do for everything json-visible...perhaps
I will not be able to keep the macro for it though, since there are
some clever variations on it (e.g. blocks should have their header's
hash as a field, txes should appear as txids unless vebose output is
requested, etc.)
2014-07-28 20:12:10 -07:00
Andrew Poelstra cc942a47f3 Workaround for rustc hiccup in `for` loop restructuring, remove assert from deserialization code
Thanks to the assert change there is a segfault happening :(
2014-07-25 15:52:48 -07:00
Andrew Poelstra 44dc29f013 Fix BIP30 rewind handling; add unsafe annotations to ThinVec::reserve 2014-07-25 12:44:54 -07:00
Andrew Poelstra 46969b3396 Replace PatriciaTree with HashMap for UTXO set
We get a speed up (~5%) and memory savings (~10%) on initial sync from
using a HashMap, though it's hard to tell precisely how much savings
because it's quite nonlinear.

I haven't tested de/serialization. Some work needs to be done there to
split up the UTXO set since it takes forever to saveload.
2014-07-20 16:52:00 -07:00
Andrew Poelstra 54e4ea4586 Rename Serializable::hash() to Serializable::bitcoin_hash()
We were conflicting with the Rust stdlib trait Hash, which is used
by various datastructures which need a general hash. Also implement
Hash for Sha256dHash so that we can use bitcoin hashes as keys for
such data structures.
2014-07-19 16:11:55 -07:00
Andrew Poelstra 93dadd6a6e Add iterators to patricia tree 2014-07-19 13:02:25 -07:00
Andrew Poelstra 8f826a959d Introduce `BitcoinResult`, use it instead of boolean returns in blockchain 2014-07-18 12:40:04 -07:00
Andrew Poelstra c9ad7c0b58 Initial commit, move into Cargo 2014-07-18 06:56:17 -07:00