Commit Graph

440 Commits

Author SHA1 Message Date
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
Deirdre Connolly 60ae9d74e7 Typo
Co-authored-by: Henry de Valence <hdevalence@hdevalence.ca>
2020-08-14 02:04:12 -04:00
Deirdre Connolly fe45c6402a Remove clippy::unit_arg allowance 2020-08-14 02:04:12 -04:00
Deirdre Connolly 2942bad6ff Make diversify_hash() private again 2020-08-14 02:04:12 -04:00
Deirdre Connolly 5a249f8da5 A space
Co-authored-by: Henry de Valence <hdevalence@hdevalence.ca>
2020-08-14 02:04:12 -04:00
Deirdre Connolly 5ba453c2a1 Remove unused SaplingNoteTreeRootHash types re: Heartwood 2020-08-14 02:04:12 -04:00
Deirdre Connolly 68871c5bd4 From<Nullifier> for [u8; 32] 2020-08-14 02:04:12 -04:00
Deirdre Connolly b2584c4a8f A space 2020-08-14 02:04:12 -04:00
Deirdre Connolly 0c299972ec Clarify docstring about the Jubjub prime-order subgroup on generate_trapdoor() 2020-08-14 02:04:12 -04:00
Deirdre Connolly f816761a5c The pedersen hash to point test vectors now pass 2020-08-14 02:04:12 -04:00
Deirdre Connolly 425275ad35 Fix exclusive range, shift up enumerate() indexes with map() 2020-08-14 02:04:12 -04:00