Commit Graph

1279 Commits

Author SHA1 Message Date
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 755fb454eb integration with bitcoinconsenus 2018-03-12 17:17:16 +01:00
Andrew Poelstra 21f2baf58e remove script interpreter 2018-03-09 20:30:11 +00:00
Tamas Blummer 77ce6f18d0 Moved blockchain and patricia_tree to rust-memblocks 2018-03-09 17:22:31 +01:00
Andrew Poelstra 7dcca9157b
Merge branch 'master' into is_on_main_chain_public2 2018-03-09 15:09:21 +00:00
Tamás Blummer e530aa98c9
Merge branch 'master' into is_on_main_chain_public2 2018-03-09 16:03:06 +01:00
Andrew Poelstra ab72eabd59
Merge branch 'master' into get_tip_height 2018-03-09 15:01:15 +00:00
Tamas Blummer 5e510366cf is_on_main_chain is a very useful function upstream, make it public 2018-03-03 18:15:05 +01:00
Tamas Blummer 3351f35583 add documentation 2018-02-28 20:27:52 +01:00
Tamas Blummer 50a9d0f51f add get_best_tip_height to blokchain 2018-02-28 20:24:35 +01:00
Tamas Blummer f1503866d7 RawNetworkMessage::command should be public. no harm and useful for debug messages. 2018-02-28 10:42:23 +01:00
Andrew Poelstra 066c49305f update secp256k1 to latest version with minimized dependencies 2018-02-20 16:19:29 +00:00
Andrew Poelstra 23a2c6bc9a remove `jsonrpc` dependency by copying the macro we need into the source 2018-02-18 15:28:39 +00:00
Andrew Poelstra 047c0c149d remove `num` crate dependency 2018-02-18 15:21:13 +00:00
Andrew Poelstra 9562d8afac
Merge pull request #41 from tamasblummer/minimal_alert_message
minimal implementation of alert message
2018-02-18 15:00:55 +00:00
Andrew Poelstra 71bce7b067
Merge pull request #44 from tamasblummer/add_difficulty2
Add difficulty calculation
2018-02-18 14:59:36 +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
Matt Corallo 9052f3b5a2 Fix argument to copy_nonoverlapping in internal_macros
This resolves a segfault due to unsafe code.
2018-02-13 19:08:10 -05:00
Tamas Blummer 3efe511cc6 add difficulty calculation 2018-02-11 19:58:26 +01:00
Tamas Blummer 19f96fe62c add low_u64 to Uint256 and Uit128 types 2018-02-11 14:19:58 +01:00
Tamas Blummer 9fbe941621 minimal implementation of alert message 2018-02-11 14:08:33 +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 b3644b7b6d add constants for OP_CLTV and OP_CSV 2017-12-21 01:10:00 +00:00
Andrew Poelstra 406160a386 transaction: add txid() function that does the right thing for segwit/nonsegwit
With Segwit transactions `bitcoin_hash()` is no longer sufficient to get a txid.
2017-12-09 19:52:09 +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 e5f109221e script: add `to_p2wsh()` and `is_p2swsh()` functions to allow easy segwit output computation 2017-12-06 15:39:37 +00:00
Andrew Poelstra c341e21dc6
remove unnecessary `mut` that nightly rustc has learned to detect 2017-10-06 19:56:50 +00:00
Andrew Poelstra 46439710d9
script: add `is_p2pkh()` function 2017-10-06 19:15:30 +00:00
Andrew Poelstra 8f7bd858fb
update byteorder to 1.1 from 0.3 2017-07-28 16:19:44 +00:00
Andrew Poelstra 2e7be81ea4 add unit test for overflow panic 2017-06-07 16:09:40 +00:00
Daniel Lockyer a74efe6f8c Sanity checks for vector length 2017-06-05 18:06:30 +01:00
Andrew Poelstra cdb452f79f Sanity-check vector length when deserializing 2017-04-17 00:54:38 +00:00
Andrew Poelstra 4b73c3223c Merge pull request #18 from rotwatsb/GetAddr
Add GetAddr message
2016-10-12 11:26:48 +00:00
Steve Bradley f7fed8339d Add GetAddr message 2016-10-10 11:14:12 -04:00
Andrew Poelstra 02718be82f Remove unused `num_cpus` dep 2016-10-10 13:09:40 +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
Demur Rumed 5dda3e2602 Replace time with std::time 2016-07-17 04:02:57 +00:00
Andrew Poelstra 93f103bdb5 script: fix broken push_int in script::Builder 2016-07-14 15:15:34 +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 698a23e32d script: fix Debug impl bugs in Script, PUSHDATA1 not displayed correctly 2016-06-24 00:20:49 +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 50b3e90912 Rename Transaction::scripthash to Transaction::signature_hash
Yes, this is a major release because I misspelled the name of a function :)
2016-06-13 21:25:47 +00:00
Andrew Poelstra 38b2cacf35 Add support for computing transaction sighashes, which is needed for signing 2016-06-12 18:25:23 +00:00
Andrew Poelstra 220775015e [BREAKING CHANGE] [v0.5 -> v0.6] Move nasty script stuff into a feature-gated module 2016-06-12 00:36:46 +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 6ccd157775 Add `into_vec` method to Script 2016-06-02 23:47:29 +00:00
Andrew Poelstra 35832e3da0 Remove some unused trait imports 2016-05-27 18:36:42 +00:00
Andrew Poelstra 30904b67a7 Derive Eq and friends for script::Instruction 2016-05-04 14:03:58 +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 92c3b2459c script: fix macro for future rustc changes 2016-02-18 17:56:51 +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 56b7e7d3f4 Add ntxid support 2015-12-21 11:07:37 -06:00
Andrew Poelstra 16f5878a03 Add a bunch of Ord/PartialOrd impls for stuff 2015-12-20 15:38:02 -06:00
Andrew Poelstra e05e6d2215 [BREAKING CHANGE] Drop UtxoSet
This code was unmaintained, is unlikely to work on the majority of systems
(since it holds the whole utxoset in RAM, and not in a terribly efficient
manner), and has a dependency on `eventual` which has been broken for a
long time.

The library no longer compiles on nightly because of this, and without any
known usecases for `UtxoSet`, nor good ability to test it, I'm simply
removing the code.

I recommend anyone who cares about this extracts the code from the previous
commit and creates a new crate. It should be more featureful anyway, e.g.
support a backing store.
2015-12-19 20:13:59 -06:00
Andrew Poelstra 45ef239a34 Add unsigned Decimal type 2015-12-19 20:13:59 -06:00
Andrew Poelstra 5c69d44397 Add Hash derived impls for all the transaction types 2015-12-19 20:13:59 -06:00
Andrew Poelstra 52b4263539 Remove comment about refcounted pointers; there are no refcounted pointers 2015-12-19 20:13:59 -06:00
Andrew Poelstra c1993a12c6 Add TxOutRef type to blockdata::transaction; don't use it anywhere in the library itself
This is just a convenience type for the (txid, vout) pairs that get produced
a lot in Bitcoin code. To the best of my knowledge there is nowhere this can
be used in the actual library (in particular, TxOutRef.index is a usize for
convenience while TxIn.prev_index is a u32 for correct consensus encoding,
so there is not redundancy here).
2015-12-19 20:13:59 -06:00
Andrew Poelstra e393d0ec3b Add useful Debug/Display for Script 2015-12-19 20:13:59 -06:00
Nicholas Alan Cardin e72e01dfa3 Fix decoding of Pong message 2015-12-17 23:47:40 -05: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
Julius Naperkowski 8c707c5bef Added support for mempool messages 2015-11-23 00:58:09 +01: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
Wladimir J. van der Laan 404176a5ee Fix data leak in CommandString::consensus_encode
A fixed buffer of 12 bytes was unsafely copied from the bytes of a
string - if the string was shorter than that, memory from outside would
leak into the packet.

Replace the unsafe copy by a safe loop. Also add a panic if
an attempt is made to use a command string longer than 12 bytes.
2015-11-08 01:14:10 +01: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 8daf06cc1d Update for latest libsecp: normalize signatures and use "lax DER" parsing 2015-10-26 14:39:25 -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 fdc854edd9 Remove Script() from LowerHex impl of Script
This is easy for downstream to add, not easy for them to remove. Plus scripts
have a pretty recognizable form and are usually obvious from context anyway.
2015-10-14 22:31:12 -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 c67608a435 Remove `Sized` requirement from ConsensusEncodable 2015-09-20 15:34:13 -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 2320f099c1 Remove broken wallet components
This was a fairly small change and gets all unit tests to pass.
2015-09-19 13:39: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 4b1b1c4a74 Fix endianness problems with new librustc ipv6 addresses 2015-05-10 13:08:38 -05:00
Andrew Poelstra 2975c91e37 Remove pile of undefined (and bitrotted) code 2015-05-10 11:12:37 -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 e658ffaeea Rename ScriptBuilder to Builder as per rustc rfc PR 1036 2015-04-09 23:23:56 -05:00
Andrew Poelstra 5350207ff3 Remove hamcrest; add rust-serde (not compiling right now) 2015-04-09 23:23:53 -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 7a2cfe95e7 Minor fixes to namespaces 2015-04-04 13:56:30 -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 0bf5809674 Add time crate 2015-03-26 11:53:49 -05:00
Andrew Poelstra 6db25db975 Bunch of error type changes 2015-03-26 11:52:20 -05:00
Andrew Poelstra 719f616218 Some more renames for librustc changes 2015-03-26 10:44:49 -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 97bfbe790b Add a `clone` to script sat-checker to satisfy new soundness rules
This was actually a soundness bug waiting to happen fwiw...but I'm
still not so happy about it.
2014-09-11 08:03:36 -05:00
Andrew Poelstra e0c9844ff2 Make UtxoSet store (height, txo) pairs rather than just the raw txo
Will take some experimentation to see if this is what I want the API
to be, if the memory usage is acceptable, etc.

This will force a total reindex for wizards-wallet users.

[breaking-change]
2014-09-10 19:58:58 -05:00
Andrew Poelstra 184721db61 Add wallet balance-checking support 2014-09-10 07:19:12 -05:00
Andrew Poelstra ef11e8273b Destroy socket listener on error rather than trying to reconnect; add #derivings
Reconnecting an existing socket simply was not working; the Rust socket
did not expose any methods for reconnection, so I simply tried calling
connect() again. As near as I can tell, this was a no-op --- which makes
sense because both the sending and receiving threads had their own copy
of the Socket, and it's not clear what the synchronization behaviour
should have been.

Instead if the connection fails, we relay this information to the main
thread, wait for an acknowledgement, then simply destroy the listening
thread. The caller can then simply call `start()` again.
2014-09-10 07:15:48 -05:00
Andrew Poelstra 1f41a67194 Make Address public 2014-09-06 11:47:18 -05:00
Andrew Poelstra 2aeb373e73 Fix encode/decode of ChildNumber so that hardened keys do not become normal ones 2014-09-06 11:35:36 -05:00
Andrew Poelstra a240d25611 Wallet support for address creation 2014-09-06 10:30:11 -05:00
Andrew Poelstra 9f56b9c57f Fix wallet serialization to not use "" as a key anywhere
Turns out TOML does not support tables named "", so we instead encode
the accounts list as an array rather than a name-keyed hashmap. This
is fine since the account name is in the account structure itself
anyway.
2014-09-05 11:55:25 -05:00
Andrew Poelstra bc7077fac4 Encodable/Decodable improvements; add `user_enum` macro for string enums 2014-09-05 09:16:22 -05:00
Andrew Poelstra 331e555e4c Use `verify_raw` rather than `verify` to check signatures
`verify` cannot handle illegally padded signatures because it takes an object
of type `Signature`, which is a fixed-size type. This should have been part
of the previous commit --- an important lesson about running the unit tests
before every push!
2014-09-04 20:34:58 -05:00
Andrew Poelstra 20ce3721b7 Fix for upstream 2014-09-04 19:06:52 -05:00
Andrew Poelstra c25862a107 Change UtxoSet to use full TXID as key
Sorry, this is needed to enable proper txid/vout lookups for the address index.
This means any users of wizards-wallet need to rebuild their utxo sets, and
will also mean an increase in RAM usage.
2014-09-02 09:37:31 -05:00
Andrew Poelstra 6250f4fd9c Checkpoint commit -- prefix-filtered address indexing works 2014-09-01 21:37:00 -05:00
Andrew Poelstra 4629472d69 Block in wallet support 2014-09-01 15:11:38 -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 853d644649 Minor cleanup for script analyzer 2014-08-31 19:20:11 -07:00
Andrew Poelstra a8ecf00e35 Fix recursion to carry the execution state stack 2014-08-31 16:55:39 -07:00
Andrew Poelstra 9d283150c9 Fix GT/LT/GTEQ/LTEQ handling to not compare bools
I was trying to do something clever by making sure that the numeric
bounds were consistent with whatever ordering relation we were checking,
AND that the boolean values were also consistent...this is Wrong is the
case of negative numbers, and pointless anyway since I recently fixed
`set_bool_value`, `set_num_lo` and `set_num_hi` to update both numeric
and boolean information if possible, so they will always contain the
same info.
2014-08-31 16:43:26 -07:00
Andrew Poelstra 1515f68748 Minor cleanup of utxoset input checking 2014-08-31 16:35:30 -07:00
Andrew Poelstra d880bd1ccc Ensure execution state stack is empty at the start
We had a single `true` on the execution state stack, which would
allow scripts to have one more OP_ENDIF than they are allowed.
2014-08-31 16:23:47 -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 4ab69b8a77 script tracer: add `op_count` a running opcode count 2014-08-25 21:39:16 -07:00
Andrew Poelstra 46bffa304c script tracer: Put an obvious "opcode failed" message in the pre-execute stack 2014-08-25 16:09:00 -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 3a921e6b9c Add support for `tx` messages 2014-08-23 16:37:01 -07:00
Andrew Poelstra 4ba533514e Add Default impl to Script 2014-08-23 16:20:46 -07:00
Andrew Poelstra 6e6da2a756 Allow transaction inputs to be validated individually 2014-08-23 15:09:50 -07:00
Andrew Poelstra 7eadf72a1a Add serialize_hex method to do string conversion for serializations 2014-08-22 20:53:49 -07:00
Andrew Poelstra 18a61dd560 Add blockdata::constants::max_money 2014-08-22 20:29:16 -07:00
Andrew Poelstra e3445ebef7 Pull script tracing code out of Transcation so it can be used independently 2014-08-22 12:14:39 -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 1522ab841d Generalize consensus encode/decoders for HashMap 2014-08-18 19:49:09 -07:00
Andrew Poelstra e29fdb90c8 fix for upstream 2014-08-18 18:04:32 -07:00
Andrew Poelstra d3ef264b44 Add txid to transaction trace 2014-08-17 17:25:47 -07:00
Andrew Poelstra 7059c21ef4 tx trace: add `executed` boolean, add a trace even for ops that fail 2014-08-17 13:35:57 -07:00
Andrew Poelstra 09679b8d9f Add a copy of the script to ScriptTrace 2014-08-16 19:21:07 -07:00
Andrew Poelstra 62dd2e7cee Add transaction trace capability for debugging scripts 2014-08-16 19:04:57 -07:00
Andrew Poelstra 8d1a3e1f7c Some error improvements 2014-08-16 13:33:13 -07:00
Andrew Poelstra 4c99653933 Move TX validation into Transaction, call from UtxoSet 2014-08-16 12:57:39 -07:00
Andrew Poelstra 8a814e4331 Add P2SH support 2014-08-15 17:37:40 -07:00
Andrew Poelstra fa859b3490 Fix VERIFY-op handling in provably-unspendable code 2014-08-14 20:32:36 -07:00
Andrew Poelstra 07c3d335aa Return proper errors from UtxoSet::update 2014-08-14 20:17:41 -07:00
Andrew Poelstra 61969ce6ee Fix overflow in script 2014-08-14 20:09:54 -07:00
Andrew Poelstra c28c261b74 utxoset: Fix parallel script checking to use only as many threads as CPUs 2014-08-14 17:20:43 -07:00
Andrew Poelstra fc04462682 Implement pruning 2014-08-14 17:05:07 -07:00
Andrew Poelstra d9d7416e32 Fixes for recent stdlib changes 2014-08-14 15:20:39 -07:00
Andrew Poelstra 8e7d763310 Parallelize transaction verification in utxoset
We no longer confirm that chained transactions occur in the correct order
in blocks, which is a minor consensus regression and should be dealt with
in future.
2014-08-13 23:42:01 -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 886dd68eb7 Minor correction to opcode docs 2014-08-12 22:50:40 -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 29d0701faa Fix off-by-one error handling OP_CODESEPARATOR 2014-08-11 22:43:24 -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 dea6d457f4 Clean up `read_uint` as in PR #2 (thanks @jkozera) 2014-08-11 19:20:39 -07:00
Andrew Poelstra 3e25134b2f Added unit tests for three more testnet failures, the latter of which I'm still working on 2014-08-11 19:17:58 -07:00
Andrew Poelstra a87dd0042b Get OP_MULTISIG working 2014-08-10 21:37:12 -07:00
Andrew Poelstra bf09ab2754 Fix script bugs (can now fully validate testnet up to multisig) 2014-08-10 19:35:58 -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 474d04d154 Manually implement Encodable/Decodable/Show for Network
Since TOML will not encode C-like enums as strings, we do it
ourselves. This is also worthwhile so that we can get the
lowercase "bitcoin" and "testnet" as encodings for the actual
enum values, which are more verbose and camel case.
2014-08-03 06:29:19 -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 275c93ab6b Add docs for SimpleDecoder and SimpleEncoder traits 2014-08-01 11:16:18 -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 020295f8c9 Add a bunch of traits to Network so I can use it as a HashMap key 2014-07-29 15:55:25 -07:00
Andrew Poelstra 8cd8947cf3 Implement some more ToJson's 2014-07-29 10:19:21 -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 1938959017 Add `genesis_hash` function to Blockchain 2014-07-28 12:30:45 -07:00
Andrew Poelstra 6f7e73d6b4 Fix nu_select! macro for borrowck 2014-07-26 19:36:38 -07:00
Andrew Poelstra 322c937c3c Fixed borrowck problems with nu_select! in an evil way 2014-07-26 11:28:55 -07:00
Andrew Poelstra b5b7a6b080 Another workaround for https://github.com/rust-lang/rust/issues/15763 2014-07-25 16:50:58 -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 128ebcc6d5 Fix comment in UTXOset for stxo cache ordering 2014-07-25 14:35:46 -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 fe9ca39736 Send new handshake on reconnect 2014-07-24 12:52:28 -07:00
Andrew Poelstra 809bad5ff5 Reconnect on network errors; use Mutexes to control Socket access more precisely 2014-07-24 08:27:40 -07:00
Andrew Poelstra 9be493eeaf Move Local::take() into a scope where it is guaranteed to be used
This was causing a mystery crash. Fixed.
2014-07-23 15:19:44 -07:00
Andrew Poelstra 1be45395da Store TxOuts directly in UtxoSet rather than in Boxes
This gives a significant speedup during deserialization since we
don't have to allocate for every output.
2014-07-23 11:27:03 -07:00
Andrew Poelstra b5c25ff768 Distinguish between network/decode errors in network message decode
It is now visible that EOF (i.e. peer hung up) is interpreted
as a message decode error. Probably what we want to do is reset
the connection on any error. TODO
2014-07-23 11:22:35 -07:00
Andrew Poelstra 9cb86dd21b Change InvalidInput to EndOfFile in several cases 2014-07-22 10:59:58 -07:00
Andrew Poelstra ca6d4cdde4 Workaround for https://github.com/rust-lang/rust/issues/15763 2014-07-21 19:40:29 -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 a3846965e3 blockchain: replace Rc mess with internal raw pointers 2014-07-19 15:23:04 -07:00
Andrew Poelstra 93dadd6a6e Add iterators to patricia tree 2014-07-19 13:02:25 -07:00
Andrew Poelstra 73e8b542c0 Add testnet blockspacing rule 2014-07-18 16:41:09 -07:00
Andrew Poelstra 51038f5810 Add alternate network support to `Blockchain`, `UtxoSet`, `Socket`
Still need to do alternate diffchange rules..
2014-07-18 14:38:35 -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 b5fd47b334 Allow user to change network magic, add constant for testnet
We need to add a "difficulty back to 1 after 20 minutes" difficulty
rule to actually support testnet, but this is a start.
2014-07-18 12:03:38 -07:00
Andrew Poelstra c9ad7c0b58 Initial commit, move into Cargo 2014-07-18 06:56:17 -07:00