Commit Graph

523 Commits

Author SHA1 Message Date
Jane Lusby 86ed13060f
Add tests for `Chain` implementation (#1093)
* Begin work on RFC5 implementation

* I think this is necessary

* holy shit supertrait implemented via subtrait

* implement most of the chain functions

* change to slightly better name

* implement fork

* fix outpoint handling in Chain struct

* update expect for work

* resolve review comment

* split utxo into two sets

* update the Chain definition

* just a little more

* update comment

* Apply suggestions from code review

Co-authored-by: teor <teor@riseup.net>

* apply changes from code review

* remove allow attribute in zebra-state/lib.rs

* Update zebra-state/src/memory_state.rs

Co-authored-by: teor <teor@riseup.net>

* merge ChainSet type into MemoryState

* rename state impl types

* Add error messages to asserts

* checkpoint so I can split off arbitrary changes into a PR

* export proptest impls for use in downstream crates

* add testjob for disabled feature in zebra-chain

* run rustfmt

* try to fix github actions syntax

* differentiate name

* prove that github action tests zebra-chain build without features

* revert change from last commit now that test is running

* remove accidentally introduced newline

* checkpoint

* add module doc comment

* update RFC for utxos

* add missing header

* working proptest for Chain

* apply change from chain impl PR

* setup config for proptests

* Update zebra-chain/src/block/arbitrary.rs

Co-authored-by: teor <teor@riseup.net>

* run rustfmt

Co-authored-by: teor <teor@riseup.net>
2020-10-02 15:51:51 -07:00
teor 28b0e5d197 Improve a test failure message 2020-09-29 11:42:00 -04:00
teor 58041d8a49 Rename TEST_BLOCKS to BLOCKS
To avoid confusion with TESTNET_BLOCKS.

Automated search and replace, made using this script:

sed -i 's/TEST_BLOCKS/BLOCKS/' \
  $(grep -r TEST_BLOCKS zebra* | cut -d: -f1 | sort -u)
2020-09-29 11:42:00 -04:00
teor a35f36dd0b Split TEST_BLOCKS into mainnet and testnet
And add some basic tests to make sure:
* the heights are correct
* the lists aren't truncated or empty
2020-09-29 11:42:00 -04:00
teor 6f371f3436
Add block test vectors for each network upgrade (#1096)
* Move block test vectors into separate files
* Refactor block test vectors into their own module
* Remove some duplicate test vector data

* Add mainnet block test vectors for each network upgrade
* Add testnet block test vectors for each network upgrade

* Update the TEST_BLOCKS list
* Add basic tests using TEST_BLOCKS

* Ignore shell.nix
2020-09-28 12:42:06 +10:00
Jane Lusby 352721bd88
Implement RFC5: State updates `Chain` type (#1069)
* Begin work on RFC5 implementation

* I think this is necessary

* holy shit supertrait implemented via subtrait

* implement most of the chain functions

* change to slightly better name

* implement fork

* fix outpoint handling in Chain struct

* update expect for work

* resolve review comment

* split utxo into two sets

* update the Chain definition

* just a little more

* update comment

* Apply suggestions from code review

Co-authored-by: teor <teor@riseup.net>

* apply changes from code review

* remove allow attribute in zebra-state/lib.rs

* Update zebra-state/src/memory_state.rs

Co-authored-by: teor <teor@riseup.net>

* merge ChainSet type into MemoryState

* rename state impl types

* Add error messages to asserts

* add module doc comment

* update RFC for utxos

* add missing header

Co-authored-by: teor <teor@riseup.net>
2020-09-24 15:46:04 -07:00
Jane Lusby 0b4e974c9e
export proptest impls for use in downstream crates (#1092)
* export proptest impls for use in downstream crates

* add testjob for disabled feature in zebra-chain

* run rustfmt

* try to fix github actions syntax

* differentiate name

* prove that github action tests zebra-chain build without features

* revert change from last commit now that test is running

* remove accidentally introduced newline

* Update .github/workflows/ci.yml

Co-authored-by: Deirdre Connolly <deirdre@zfnd.org>

Co-authored-by: Deirdre Connolly <deirdre@zfnd.org>
2020-09-23 18:52:52 -07:00
Alfredo Garcia 5fbb07460c fix comments, use i32, simplify arms 2020-09-17 16:48:21 -07:00
Alfredo Garcia 4f46474e2c implement add and sub for height 2020-09-17 16:48:21 -07:00
teor 584f2643b7 Update to `RootHash` in comments
We changed the name of the type and function, but forgot the comments.
2020-09-16 12:26:25 -04:00
Ramana Venkata 3f25da996a Add wrapper fn is_time_valid_at in zebra_consensus::block::check
This commit doesn't move the fn itself because it's tests can't
depend on `generate` code which is not exposed to other crates.
2020-09-09 12:48:15 +10:00
Ramana Venkata 7118e4da3c Move is_equihash_solution_valid to zebra-consensus 2020-09-09 12:48:15 +10:00
Henry de Valence ea6017d0dc network: add Network::default_port(). 2020-09-07 11:13:15 -07:00
Jane Lusby 6744f415d2
Implement sighash (#870)
* Implement sighash

* move sighash logic to a separate module

* start filling in more of the alg

* start setting up a test case

* make the test useful

* Iter transaction inputs

* better error message for expect

* add support for zip243 sighash

* ohey first testvector is passing, yayyy

* pass the second testvector

* add last testvector

* move a use statement

* use common deserialization code for amount everywhere

* cleanup attributes

* bring in fixed preimage

* fix discrepancy with spec

* always deserialize as a signed value

* Update zebra-chain/src/transaction/sighash.rs

* update unreachable statements

* add serialization impls for nonnegative amounts

* Apply suggestions from code review

* document sighash fn

* tweek docs

* fix mistake in translation for zip243

* consistent error messages

* reorder because i like it more that way

* document more panics

* Update zebra-chain/src/amount.rs

* Add comment regarding the serialization of spend descriptions in sighash

Co-authored-by: teor <teor@riseup.net>
Co-authored-by: Deirdre Connolly <deirdre@zfnd.org>
2020-09-05 19:31:11 -04:00
Alfredo Garcia 454e75e7c0
Rename old references to BlockHeaderHash and BlockHeight (#1002)
* rename some references

* Apply suggestions from code review

Co-authored-by: Deirdre Connolly <durumcrustulum@gmail.com>
Co-authored-by: teor <teor@riseup.net>

Co-authored-by: Deirdre Connolly <durumcrustulum@gmail.com>
Co-authored-by: teor <teor@riseup.net>
2020-09-04 15:40:48 -07:00
Henry de Valence 0466466c52 chain: rename blockheaderhash reference. 2020-09-04 17:08:41 -04:00
Henry de Valence e96a472099 chain: impl Display for {block, transaction}::Hash
Also add a Display/FromStr round-trip proptest.
2020-09-04 17:08:41 -04:00
Henry de Valence 0a1878d9c3 chain: add docs about transaction and block hashes. 2020-09-04 17:08:41 -04:00
Henry de Valence 2a50298b2e chain: add transaction hash test. 2020-09-04 17:08:41 -04:00
Henry de Valence ca4a5ce30c chain: add Transaction::hash() method.
This makes Transaction and Block have a consistent API.
2020-09-04 17:08:41 -04:00
Jane Lusby 96c8809348
Implement Inventory Tracking RFC (#963)
* Add .cargo to the gitignore file

* Implement Inventory Tracking RFC

* checkpoint

* wire together the inventory registry

* add comment documenting condition

* make inventory registry optional
2020-09-01 14:28:54 -07:00
Henry de Valence 3ed967bcf8 deps: use x25519-dalek's new PartialEq, Eq methods 2020-08-31 13:30:14 -07:00
Deirdre Connolly 447398691a Make SaplingNoteCommitmentTree private for now 2020-08-28 04:46:31 -04:00
Deirdre Connolly b467a75e08 Rename tree::*NoteTreeRootHash to tree::Root 2020-08-28 04:46:31 -04:00
Deirdre Connolly 31d98248ab Expose note types and make note modules private 2020-08-28 04:46:31 -04:00
Deirdre Connolly d795b8bfd9 Add memo to Note, remove NotePlaintext 2020-08-28 04:46:31 -04:00
Deirdre Connolly 5258e891dc Rename sapling::note::OutCiphertext to WrappedNoteKey 2020-08-28 04:46:31 -04:00
Deirdre Connolly cfc60936ce Little more detail to sapling::note::EncryptedNote docstring 2020-08-28 04:46:31 -04:00
Deirdre Connolly d6eecbe935 Rename Sprout EncyptedCiphertext to EncryptedNote 2020-08-28 04:46:31 -04:00
Deirdre Connolly 99b4a400af Make find_group_hash() pub(super) 2020-08-28 04:46:31 -04:00
Deirdre Connolly 7a92496244 Make RANDOMNESS_BEACON_URS pub(super) 2020-08-28 04:46:31 -04:00
Deirdre Connolly c027cfc0d2 Rename SaplingShieldedAddress to Address, make address & commitment private, export their structs 2020-08-28 04:46:31 -04:00
Deirdre Connolly df89a049cb Rename EncryptedCiphertext to EncryptedNote 2020-08-28 04:46:31 -04:00
Ramana Venkata e90137e79b
Update sha2@0.9.1 (#938)
* Update sha2@0.9.1

Fixes #915

* Update zebra-chain/src/sprout/keys.rs

Co-authored-by: Jane Lusby <jlusby42@gmail.com>

* Update zebra-chain/src/sprout/note/nullifiers.rs

Co-authored-by: Jane Lusby <jlusby42@gmail.com>
2020-08-21 16:26:14 -07:00
teor 9a8af731b1 fix: Remove redundant ConsensusBranchId constants 2020-08-20 14:52:09 -04:00
Jane Lusby 1d6183ef84
Make zebra-script wrap the C++ script implementation in zcashconsensus (#708)
* attempt to use zcashconsensus crate in zebra-script

* boop

* update verify fn to use zebra types

* a bit more cleanup

* cleanup

* more

* beep boop

* fix renamed member

* cleaning

* get a real branch id

* remove as of yet unneeded api

* Update zebra-chain/src/transaction.rs

* Update zebra-chain/src/transaction.rs

* more cleanup

* oops wrong dep section

* use a tuple to communicate arg association

* update to use published version of zcash_script

* fix new compiler error

* install llvm on windows

* fix bindgen bug????

* try to get docker file to win

* okay try everything

* fix windows build maybe

* always download choco

* fix paths for moved types

* try a different error message

* try convenience script

* try installing just llvm

* add back one more

* try installing some headers

* try a diff package

* try everything

* remove the minimum

* try newer docker builder image

* cleanup docker image

* cleanup extra ci step
2020-08-18 11:08:53 -07:00
Alfredo Garcia 4dac4d4df7 move `is_coinbase_first` from chain to consensus 2020-08-18 11:03:40 -07:00
Henry de Valence 8e15c16b42 chain: TransparentAddress -> transparent::Address 2020-08-17 11:46:34 -07:00
Henry de Valence ebdceb5197 chain: rename TransactionHash to transaction::Hash 2020-08-17 11:46:34 -07:00
Henry de Valence d49d3d2b30 chain: tweak docs for JoinSplitData, ShieldedData 2020-08-17 11:46:34 -07:00
Henry de Valence 5c176d2f96 chain: move JoinSplit to sprout 2020-08-17 11:46:34 -07:00
Henry de Valence 1fc859d0c5 chain: move Spend, Output into sapling
The ShieldedData container for the spend and output descriptions of a
transaction does *not* move, because it's encoding transaction
structure.  A good sign that this is the right factoring is that the
transaction module now only needs to pull in sapling::{Spend, Output}
and not all the internals.
2020-08-17 11:46:34 -07:00
Henry de Valence d945cd28e8 chain: move Transparent{Input,Output} to transparent
Also bring the `Script` type there too.
2020-08-17 11:46:34 -07:00
Deirdre Connolly 25f63518f4 Allow clippy::unit_arg because of derive(Arbitrary) 2020-08-17 11:46:34 -07:00
Henry de Valence d57390d265 chain: doc tweaks (mostly block::) 2020-08-17 11:46:34 -07:00
Henry de Valence 94d6d448bb chain: rename to block::merkle::{Root, Tree}. 2020-08-17 11:46:34 -07:00
Henry de Valence 2712c4b72a chain: rename BlockHeader to block::Header 2020-08-17 11:46:34 -07:00
Henry de Valence 103b663c40 chain: rename BlockHeight to block::Height 2020-08-17 11:46:34 -07:00
Henry de Valence 61dea90e2f chain: rename BlockHeaderHash to block::Hash
This is the first in a sequence of changes that change the block:: items
to not include Block as a prefix in their name, in accordance with the
Rust API guidelines.
2020-08-17 11:46:34 -07:00
Henry de Valence 04ba696515 chain: remove block::block 2020-08-17 11:46:34 -07:00
Henry de Valence 9766d32fa6 chain: touch up amount docs 2020-08-17 11:46:34 -07:00
Henry de Valence d0ee7a9961 chain: amount::AmountConstraint -> amount::Constraint 2020-08-17 11:46:34 -07:00
Henry de Valence fd548592bf chain: remove clippy::try_error annotation 2020-08-17 11:46:34 -07:00
Henry de Valence dcc1e19129 chain: touch up docs 2020-08-17 11:46:34 -07:00
Henry de Valence ce1e81b274 chain: move merkle_tree to block::merkle.
This Merkle tree is the SHA256d one used only for including transactions
in a block, so it should be kept there in order to not be confused with
other Merkle trees (like the note commitment trees).
2020-08-17 11:46:34 -07:00
Henry de Valence 7298e7c636 chain: create a transparent module. 2020-08-17 11:46:34 -07:00
Henry de Valence e8f923ec86 chain: move Memo into transaction 2020-08-17 11:46:34 -07:00
Henry de Valence 312c66264a chain: extract sprout code into sprout module. 2020-08-17 11:46:34 -07:00
Henry de Valence e06f59ee21 chain: extract sapling code to sapling module 2020-08-17 11:46:34 -07:00
Henry de Valence c5a8cb0c91 chain: create primitives module.
This contains definitions of primitive types used in other structures
and re-exports of component libraries.
2020-08-17 11:46:34 -07:00
Henry de Valence 196e841cd9 chain: rename LightClientRootHash to RootHash
It's not accurate to call it a LightClientRootHash, because it's not
always a root has for a light client -- sometimes it's a different kind
of root hash.
2020-08-17 11:46:34 -07:00
Henry de Valence b296d1e2a3 chain: move Block into a leaf module.
This might make things a little easier to rearrange.  In the future it
would probably be good to change to block::Hash, block::Header, etc.
2020-08-17 11:46:34 -07:00
Henry de Valence 948b067808 chain: move Network, NetworkUpgrade to parameters
Also, avoid using star-imports of the enum variants, which pollutes the
namespace.
2020-08-17 11:46:34 -07:00
Henry de Valence 64d9d55992 chain: organize block tests
This moves the tests::generate module into the block tests.  Because
this whole set of changes is just focused on reorganization, the
generate code is unchanged, but in the future, the code should be
rewritten as a collection of proptest strategies.
2020-08-17 11:46:34 -07:00
Henry de Valence 855b89dec4 chain: create a new work module for proof-of-work
This extracts the `difficulty` module from `block` and the
`equihash_solution` module from the crate root.  The PoW calculations
are significantly more complicated than the other block code and pretty
dissimilar from it, so it makes more sense to create a common proof of
work module.

The `EquihashSolution` and `EQUIHASH_SOLUTION_SIZE` are renamed to
`equihash::Solution` and `equihash::SOLUTION_SIZE` and imported that
way, except in `block/header.rs`, to avoid a conflict with the
`equihash` crate.  In the future it would be better to encapsulate the
equihash solution check into the `equihash::Solution` type so that
callers only need to import our `work::equihash`.

The test organization leaves a little to be desired but I think that
this can be improved as we fill out the proof of work implementation.
2020-08-17 11:46:34 -07:00
Henry de Valence dad6340cd3 chain: move BlockHeight into block 2020-08-17 11:46:34 -07:00
Henry de Valence 5f71bcd0d1 chain: move LockTime into transaction 2020-08-17 11:46:34 -07:00
Henry de Valence 8e9a239687 chain: clean transaction tests module.
This moves the transaction strategies to `arbitrary`, to live with the
other strategy impls (`Arbitrary` is just a default type-associated
strategy), splits the proptests into a new `prop` module, and splits the
test vector checks into a `vector`s module.

This ensures that we keep code in leaf modules and only have
organization (use statements) in non-leaf modules.
2020-08-17 11:46:34 -07:00
Henry de Valence a35604aef3 chain: move amount to a top-level module. 2020-08-17 11:46:34 -07:00
Henry de Valence cee7d0b8eb chain: move serde_helpers into serialization. 2020-08-17 11:46:34 -07:00
Henry de Valence b36fe8f937 chain: move sha256d to serialization module.
This extracts the SHA256d code from being split across two modules and puts it
in one module, under serialization.

The code is unchanged except for three deleted tests:

* `sha256d_flush` in `sha256d_writer` (not a meaningful test);
* `transactionhash_debug` (constructs an invalid transaction hash, and the
  behavior is tested in the next test);
* `decode_state_debug` (we do not need to test the Debug output of
  DecodeState);
2020-08-17 11:46:34 -07:00
Henry de Valence 9f31e551c9 chain: split serialization.rs into files
The code is unchanged except for removing an unneeded clippy annotation in proptests.rs.
2020-08-17 11:46:34 -07:00
Henry de Valence 0d1f56ad2f chain: remove utils module
A catch-all utils module can really easily slip into being a place to stash
miscellaneous functions that don't really belong anywhere in particular.
2020-08-17 11:46:34 -07:00
teor 4bbefeb68e
Implement Add for Work (#894)
* feature: Implement CompactDifficulty to Work

* fix: Test Work on all difficulty test cases

* fix: Add Bitcoin test vectors for difficulty

* feature: Cumulative Work

* impl Add, AddAssign for Work
* derive Default for Work
* test cumulative work

* fix: comments

* fix: More comments

* Fix comment links

* Remove unused import

Co-authored-by: Deirdre Connolly <durumcrustulum@gmail.com>
2020-08-14 20:48:56 -04:00
Deirdre Connolly 616d82faaf Use the jubjub::AffinePoint in the canonical, encoded little-endian byte form in
Pedersen tests

Keeps the librustzcash test vectors with their big-endian byte order
as comments, for greppability.
2020-08-14 02:04:12 -04:00
Deirdre Connolly a2c9011e06 Impl ZcashDeserialize for jubjub::Fq, use in transaction deserialization 2020-08-14 02:04:12 -04:00
Deirdre Connolly 1255cec6a4 Serialize Amount to bytes using byteorder::LittleEndian 2020-08-14 02:04:12 -04:00
Deirdre Connolly 646b506e7a Whoops forgot to add sprout::NoteTreeRootHash 2020-08-14 02:04:12 -04:00
Deirdre Connolly 4914b80cdb Add a TODO about caching Pedersen hash generator points 2020-08-14 02:04:12 -04:00
Deirdre Connolly f753e63f3b Clarify docstring on NoteCommitment::new() 2020-08-14 02:04:12 -04:00
Deirdre Connolly 437f40d3c8 Refine JoinSplit::anchor to be a sprout::NoteTreeRootHash type 2020-08-14 02:04:12 -04:00
Deirdre Connolly 5a5882700c Tidy JoinSplit nullifiers deserialization 2020-08-14 02:04:12 -04:00
Deirdre Connolly 6b13ce3e83 Add Sapling EphemeralPublicKey type that wraps jubjub::AffinePoint 2020-08-14 02:04:12 -04:00
Deirdre Connolly 52a10d2837 Add note about whether sign checks in Amount -> Fr conversion matter
Co-authored-by: Henry de Valence <hdevalence@hdevalence.ca>
2020-08-14 02:04:12 -04:00
Deirdre Connolly 75cad3bb0a Impl TryFrom's for Diversifier and use those to construct Sapling NoteCommitments 2020-08-14 02:04:12 -04:00
Deirdre Connolly c8771ef620 Defer to From/Into [u8; 32] vs Zcash(De)Serialize for sprout::NoteCommitments 2020-08-14 02:04:12 -04:00
Deirdre Connolly 619afffa16 Use convenience Reader/Writer methods to only use From/Into for nullifer serialization
And thus remove duplicative Zcash(De)Serialization impls
2020-08-14 02:04:12 -04:00
Deirdre Connolly 13b6ff1c65 Add 32byte and 64 bytes convenience writer methods to WriteExt 2020-08-14 02:04:12 -04:00
Deirdre Connolly e8fdd0e1f3 Impl TryFrom for Commitments, call from impl ZcashDeserialize 2020-08-14 02:04:12 -04:00
Deirdre Connolly 5d13880461 Remove Zcash(De)Serialize impls for *Commitments 2020-08-14 02:04:12 -04:00
Deirdre Connolly 014afd8e4a Move Pedersen hash functions to their own submodule 2020-08-14 02:04:12 -04:00
Deirdre Connolly be7ea200c8 Accept an Amount<NonNegative> for the value arg of a ValueCommitment constructor 2020-08-14 02:04:12 -04:00
Deirdre Connolly e024e43896 Support nullifier derivation from borrowed Spending, NullifierDeriving keys 2020-08-14 02:04:12 -04:00
Deirdre Connolly 40b5a73a15 impl From<&NullifierDerivingKey>, use that to derive Sapling Nullifier 2020-08-14 02:04:12 -04:00
Deirdre Connolly a8625b7b84 Remove empty doc comment 2020-08-14 02:04:12 -04:00
Deirdre Connolly a3530b0eed Move pedersen_hash() to go with the other Sapling hash functions, for now 2020-08-14 02:04:12 -04:00
Deirdre Connolly 0242df30cb A space 2020-08-14 02:04:12 -04:00
Deirdre Connolly 9d9491c4e8 Index at 1, not 0, the main loop of PedersenHashToPoint, to match spec math 2020-08-14 02:04:12 -04:00
Deirdre Connolly e5c07721b4 Typo fix
Co-authored-by: Henry de Valence <hdevalence@hdevalence.ca>
2020-08-14 02:04:12 -04:00
Deirdre Connolly ca81e48843 Remove an extra line 2020-08-14 02:04:12 -04:00