Commit Graph

592 Commits

Author SHA1 Message Date
Henry de Valence 1606b28d14 chain: add missing sources to SerializationError 2020-12-01 19:16:41 -08:00
teor 92eb92d1dd
Disable the nightly clippy unnecessary_wraps lint (#1403)
It seems to be a bit broken - some of our functions return `Result` for
consistency with similar functions. But the lint picks them up anyway.
2020-12-01 12:20:57 +10:00
Henry de Valence 4fa119dd1f chain: fix consensus-critical coinbase encoding bug
The `CoinbaseData` parses the block height separately from the rest of the
free-form coinbase data.  However, it had two bugs:

1. It did not require that the height was canonically encoded;
2. Its canonical encoding was incorrect relative to the BIP34-inherited encoding.

This meant that we computed some transaction hashes incorrectly, because when
we re-serialized the coinbase transaction, we would canonically serialize the
coinbase transaction (using the incorrect definition of canonical, bug 2).  And
we didn't notice that the wrong definition of canonical encoding was being used
because we accepted what we thought were non-canonically encoded heights.

The relevant rules are here: 877212414a/src/script/script.h (L307-L346)

This commit changes the encoding to reject non-canonically encoded heights, and
to match the correct encoding rules.  We check that at least one
non-canonically encoded height is correctly rejected using a new test vector.

The database format increments because we saved a bunch of wrongly encoded blocks.

This discrepancy was originally noticed by @teor2345, who pointed out that a
previous version of the block 202 test vector (now preserved as "bad block
202") did not match the block from zcashd.
2020-12-01 10:14:44 +10:00
teor 15be1b81cb Show transaction hashes on merkle failure
Also show the block height and block hash.
2020-12-01 10:14:44 +10:00
Henry de Valence 738b5b0f1b chain: implement Bitcoin Merkle root computation 2020-12-01 10:14:44 +10:00
Alfredo Garcia 4544463059
Inbound `FindBlocks` and `FindHeaders` (#1347)
* implement inbound `FindBlocks`
* Handle inbound peer FindHeaders requests
* handle request before having any chain tip
* Split `find_chain_hashes` into smaller functions

Add a `max_len` argument to support `FindHeaders` requests.

Rewrite the hash collection code to use heights, so we can handle the
`stop` hash and "no intersection" cases correctly.

* Split state height functions into "any chain" and "best chain"
* Rename the best chain block method to `best_block`
* Move fmt utilities to zebra_chain::fmt
* Summarise Debug for some Message variants

Co-authored-by: teor <teor@riseup.net>
Co-authored-by: Jane Lusby <jlusby42@gmail.com>
2020-12-01 07:30:37 +10:00
teor fb2f2a97f2 Delete an outdated canopy activation comment 2020-12-01 07:27:30 +10:00
teor d1ba1146d4 Add intra-doc links 2020-12-01 07:27:30 +10:00
teor b6ce509363 Make order of operations clearer 2020-12-01 07:27:30 +10:00
teor 750f096a99 Implement testnet minimum difficulty 2020-12-01 07:27:30 +10:00
teor bb9c4918bf Implement threshold_bits 2020-12-01 07:27:30 +10:00
teor 75519b0ae9 Implement averaging_window_timespan 2020-12-01 07:27:30 +10:00
teor 741c44cd55 Implement mean_target_difficulty
And enough stub code to actually run it on the context.
2020-12-01 07:27:30 +10:00
Jane Lusby 17fdbe941b fix stdout issue with test framework for cached data tests 2020-11-24 11:04:30 -05:00
dependabot[bot] e832f70c2c build(deps): bump tracing from 0.1.21 to 0.1.22
Bumps [tracing](https://github.com/tokio-rs/tracing) from 0.1.21 to 0.1.22.
- [Release notes](https://github.com/tokio-rs/tracing/releases)
- [Commits](https://github.com/tokio-rs/tracing/compare/tracing-0.1.21...tracing-0.1.22)

Signed-off-by: dependabot[bot] <support@github.com>
2020-11-24 10:55:53 -05:00
Henry de Valence 25fd52be51 chain: tidy Debug for Amount
This avoids printing a bunch of PhantomData.
2020-11-21 14:09:15 -05:00
Henry de Valence b5515123eb chain: add custom Debug for CoinbaseData
The derived Debug impl just shows u8s as numbers, which isn't what we
want.  There are basically two reasonable options here:

1. Hex-encoded bytes
2. Escaped ASCII

I picked (2) because a lot of coinbase data has ascii text in it.
2020-11-21 14:09:15 -05:00
teor 54cb9277ef Allow some new clippy nightly lints 2020-11-17 10:07:37 +10:00
dependabot[bot] 18eb4d1c31 build(deps): bump primitive-types from 0.7.2 to 0.7.3
Bumps [primitive-types](https://github.com/paritytech/parity-common) from 0.7.2 to 0.7.3.
- [Release notes](https://github.com/paritytech/parity-common/releases)
- [Commits](https://github.com/paritytech/parity-common/compare/primitive-types-v0.7.2...primitive-types-v0.7.3)

Signed-off-by: dependabot[bot] <support@github.com>
2020-11-13 15:59:04 -05:00
Jane Lusby a5861e5ad9 use arbitrary for creating work 2020-11-12 09:14:52 -05:00
Jane Lusby b287ea58c2 Add proptest for work roundtrip 2020-11-12 09:14:52 -05:00
Jane Lusby 1bc833dbcc Move work conversion helpers to test code 2020-11-12 09:14:52 -05:00
Jane Lusby c41a7303fa Add helpers for setting work on fake chains 2020-11-12 09:14:52 -05:00
teor 9baec96c18 Add tests for testnet minimum difficulty blocks 2020-11-12 12:30:54 +10:00
teor b2a9ea62fe Round-trip the PoWLimit through the compact representation
`zcashd` converts the PoWLimit into a compact representation before
using it to perform difficulty filter checks.

The Zcash specification converts to compact for the default difficulty
filter, but not for testnet minimum difficulty blocks. (ZIP 205 and
ZIP 208 don't specify this conversion either.) See #1277.
2020-11-12 12:30:54 +10:00
teor 8f838166a8 Make ExpandedDifficulty Debug byte order match Hash
Bugfix on PR #1171.
2020-11-12 12:30:54 +10:00
teor 76a9f5b8c4 Refactor block target spacing into NetworkUpgrade methods
And add a method for the minimum difficulty time gap threshold.
2020-11-12 12:30:54 +10:00
Alfredo Garcia 128643d81e
Call `zebra_test::init` where needed. (#1227)
* Add missing `zebra_test::init()` to zebra-chain
* Add missing `zebra_test::init()` to zebra-consensus
* Add missing `zebra_test::init()` to zebra-network
* Add missing `zebra_test::init()` to zebra-state
* Add missing `zebra_test::init()` to zebra-test
* Add missing `zebra_test::init()` to zebrad
2020-11-10 10:29:25 +10:00
dependabot[bot] e40c7b57c3 build(deps): bump bs58 from 0.3.1 to 0.4.0
Bumps [bs58](https://github.com/mycorrhiza/bs58-rs) from 0.3.1 to 0.4.0.
- [Release notes](https://github.com/mycorrhiza/bs58-rs/releases)
- [Commits](https://github.com/mycorrhiza/bs58-rs/compare/0.3.1...0.4.0)

Signed-off-by: dependabot[bot] <support@github.com>
2020-11-09 09:35:19 -05:00
dependabot[bot] b99ecbd2d7 build(deps): bump blake2b_simd from 0.5.10 to 0.5.11
Bumps [blake2b_simd](https://github.com/oconnor663/blake2_simd) from 0.5.10 to 0.5.11.
- [Release notes](https://github.com/oconnor663/blake2_simd/releases)
- [Commits](https://github.com/oconnor663/blake2_simd/compare/0.5.10...0.5.11)

Signed-off-by: dependabot[bot] <support@github.com>
2020-11-04 19:28:24 -05:00
dependabot[bot] dd7e1bb3f1 build(deps): bump blake2s_simd from 0.5.10 to 0.5.11
Bumps [blake2s_simd](https://github.com/oconnor663/blake2_simd) from 0.5.10 to 0.5.11.
- [Release notes](https://github.com/oconnor663/blake2_simd/releases)
- [Commits](https://github.com/oconnor663/blake2_simd/compare/0.5.10...0.5.11)

Signed-off-by: dependabot[bot] <support@github.com>
2020-11-04 18:54:13 -05:00
dependabot[bot] 578a3ca5ab build(deps): bump sha2 from 0.9.1 to 0.9.2
Bumps [sha2](https://github.com/RustCrypto/hashes) from 0.9.1 to 0.9.2.
- [Release notes](https://github.com/RustCrypto/hashes/releases)
- [Commits](https://github.com/RustCrypto/hashes/compare/sha2-v0.9.1...streebog-v0.9.2)

Signed-off-by: dependabot[bot] <support@github.com>
2020-11-04 18:53:49 -05:00
teor 01aeaae3f8 Placate rustfmt 2020-10-30 14:41:38 -07:00
teor f37f48918b Replace into with Some in difficulty::arbitrary 2020-10-30 14:41:38 -07:00
teor d883462d83 Silence a clippy equal arguments warning
The unit tests need to pass identical arguments to an equality
comparison, to make sure equality is implemented correctly.
2020-10-30 14:40:42 -07:00
teor 1c31225aac
Implement Expanded to Compact Difficulty Conversion (#1196)
* Implement Expanded to Compact Difficulty
* Implement Arbitrary for CompactDifficulty
Remove the derive, and generate values from random block
hashes.
* Implement Arbitrary for ExpandedDifficulty and Work
* Use Arbitrary for CompactDifficulty in Arbitrary for Block
* Test difficulty on all block test vectors
And cleanup some duplicate test code
* Round-trip tests for compact test cases
* Round-trip tests for compact difficulty in block test vectors
* Make Add for Work return PartialCumulativeWork
Remove AddAssign for Work
Rewrite a proptest using Sub for PartialCumulativeWork
Use Arbitrary for Work
* Add roundtrip work sum tests
* Add roundtrip comparison difficulty tests
* Add failing proptest cases due to test bugs
* Use Some(_) rather than _.into()
* Reduce visibility of difficulty type inner values
* Split work and other difficulty proptests
This change makes sure that rejected work values don't disable property
tests on other types.
2020-10-30 11:36:59 +10:00
Jane Lusby 2095b4f0d3 state: insert into nullifier trees 2020-10-29 09:58:56 -07:00
teor 9667ee650f Run deserialize_blockheader on every test vector 2020-10-28 21:24:28 -04:00
teor 456842aa86 Run the equihash tests on every block test vector 2020-10-28 21:24:28 -04:00
Alfredo Garcia bcb027ebc5 change canopy.pdf to stable protocol.pdf 2020-10-28 11:34:53 -04:00
teor d745d2b47c
Stop assuming Mainnet in Address From impls (#1191) 2020-10-22 07:58:52 +10:00
Alfredo Garcia 21ad6ffc47
Reverse displayed endianness of transaction and block hashes (#1171)
* Reverse displayed endianness of transaction and block hashes
* fix zebra-checkpoints utility for new hash order
* Stop using "zebrad revhex" in zebrad-hash-lookup
* Rebuild checkpoint lists in new hash order
This change also adds additional checkpoints to the end of each list.

* Replace TransactionHash with transaction::Hash
This change should have been made in #905, but we missed Debug impls
and some docs.

Co-authored-by: Ramana Venkata <vramana@users.noreply.github.com>
Co-authored-by: teor <teor@riseup.net>
2020-10-22 07:54:02 +10:00
Deirdre Connolly eb56666d30 chain: add ShieldedData::binding_verification_key() 2020-10-20 11:16:22 -04:00
Deirdre Connolly 5a78bbb6c9 Add nullifiers(), and note_commitments() to ShieldedData 2020-10-20 11:16:22 -04:00
Deirdre Connolly f9de91716c Add docstrings for sighash 2020-10-20 11:16:22 -04:00
Deirdre Connolly db54a623b7 Export sighash::HashType 2020-10-20 11:16:22 -04:00
teor efb9bfa5de
Merge pull request #1165 from teor2345/difficulty-tidy
Tidy some difficulty code
2020-10-16 06:50:08 +10:00
teor de04e76564 Reduce the equihash proptest run time
Reduce the default number of cases run by the equihash proptests,
so they run in under 10 seconds on my machine.

Set the PROPTEST_CASES env var to override the default.
2020-10-16 06:49:43 +10:00
teor c3a8fd3894 Check PoWLimit for difficulty threshold 2020-10-15 08:31:18 +10:00
teor 00de709dd8 impl From<U256> for ExpandedDifficulty 2020-10-15 08:31:18 +10:00