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
Deirdre Connolly
be22ef64e5
At least fewer M_i() rounds for test cases
2020-08-14 02:04:12 -04:00
Deirdre Connolly
41c8076dab
Add test vectors that aren't being consumed right now
2020-08-14 02:04:12 -04:00
Deirdre Connolly
14d502a54b
Compute pedersen hash to point in scalar field
2020-08-14 02:04:12 -04:00
Deirdre Connolly
8ececebea7
A space
...
Co-authored-by: teor <teor@riseup.net>
2020-08-14 02:04:12 -04:00
Deirdre Connolly
3b01dc50ef
Use unicode scalar field characters instead of LaTeX
...
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2020-08-14 02:04:12 -04:00
Deirdre Connolly
1d494a2b7a
Docstring wrap
2020-08-14 02:04:12 -04:00
Deirdre Connolly
e22afa3c8f
Generate uniformly random scalar w/ Fr::from_bytes_wide()
...
Which reduces mod r always.
2020-08-14 02:04:12 -04:00
Deirdre Connolly
c46cda920f
Add primitive merkle_crh_sapling function
2020-08-14 02:04:12 -04:00
Deirdre Connolly
10a9aa5844
Add prf_nf and use in From impl to derive Sapling Nullifier
2020-08-14 02:04:12 -04:00
Deirdre Connolly
eb731a6e2f
Add note commitment tree Position type
2020-08-14 02:04:12 -04:00
Deirdre Connolly
65f8f2c613
Add mixing_pedersen_hash
...
Tidy constructors for NoteCommitment
2020-08-14 02:04:12 -04:00
Deirdre Connolly
ed888b38ef
Correctly generate a sapling NoteCommitment from the NoteCommitmentRandomness
2020-08-14 02:04:12 -04:00
Deirdre Connolly
b6385ca36f
Move commitment types into commitments module
...
Docs, tidy
2020-08-14 02:04:12 -04:00
Deirdre Connolly
4ccec84768
Add explicit pedersen_hash function
2020-08-14 02:04:12 -04:00
Deirdre Connolly
83c41869e1
Improve docs
2020-08-14 02:04:12 -04:00
Deirdre Connolly
caef323f9b
pedersen_hash_to_point() works, with submethods using bitvec
...
Also tidy, document
2020-08-14 02:04:12 -04:00
Deirdre Connolly
919557c20c
My BitSlice doesn't have a known size at compile time?
...
error[E0277]: the size for values of type cannot be known at compilation time
2020-08-14 02:04:12 -04:00
Deirdre Connolly
579f1ed134
Flesh out windowed_pedersen_commitment_r
2020-08-14 02:04:12 -04:00
Deirdre Connolly
9d87f30d18
Start of, but currently unfinished, Sapling note commitment / Windowed Pedersen Commitment
2020-08-14 02:04:12 -04:00
Deirdre Connolly
f64e0c4bc5
Sapling value commitment, half done Sapling note commitment
2020-08-14 02:04:12 -04:00
Deirdre Connolly
823b06b219
Break out subtypes into modules, including arbitrary's
2020-08-14 02:04:12 -04:00
Deirdre Connolly
dfb10ab10f
Add NoteCommitment.extract_u()
2020-08-14 02:04:12 -04:00
Deirdre Connolly
33730a05cb
Do not confuse a NoteCommitment for U(NoteCommitment)
2020-08-14 02:04:12 -04:00
Deirdre Connolly
0f46a9b6a8
NoteCommitments, renames, ValueCommitment, strategies, stub commit()
2020-08-14 02:04:12 -04:00
Deirdre Connolly
fa053e2b0b
Derive a Sprout nullifier from a nullifier seed (rho) and spending key
2020-08-14 02:04:12 -04:00
Deirdre Connolly
0d618a3abf
Start treestate module
2020-08-14 02:04:12 -04:00
Deirdre Connolly
28a7420079
Remove unused imports
2020-08-14 02:04:12 -04:00
Deirdre Connolly
15899bc6d3
More Note refinements
2020-08-14 02:04:12 -04:00
Deirdre Connolly
2c285985c8
Move nullifiers to respective note modules, pull in existing types from keys
2020-08-14 02:04:12 -04:00
Jane Lusby
8b78a55c71
Start work implementing sprout note commitment function
2020-08-14 02:04:12 -04:00
teor
0e21a70b88
feature: Implement CompactDifficulty to Work ( #838 )
...
* Implement CompactDifficulty to Work
* Add Bitcoin test vectors for difficulty
2020-08-14 09:48:15 +10:00
Henry de Valence
07917421cb
Correct coinbase check ( #898 )
...
* chain: add Transaction::is_coinbase()
This matches the check in zcashd/src/primitives/transaction.h:682
(CTransaction::IsCoinBase).
* chain: correct Block::is_coinbase_first
This matches zcashd/src/main.cpp:3968-3974 in CheckBlock.
Previously, the check allowed the first transaction to have multiple coinbase inputs.
* chain: return slices from Transaction::inputs()/outputs()
They're slices internally so we might as well just expose them that way.
2020-08-13 14:04:43 -07:00
Henry de Valence
36093b4721
Tweak light client root hash definition.
...
This changes the `light_client_root_hash` field to `light_client_root_bytes` to
hint that it's unparsed, and makes it public to match the rest of the
`BlockHeader` fields. The `LightClientRootHash` serialization methods are
hidden from the public API, so that the `LightClientRootHash` has to be
constructed by the method on the `Block`.
2020-08-11 19:13:50 -04:00
dependabot[bot]
5cb61136c9
build(deps): bump tracing from 0.1.18 to 0.1.19 ( #872 )
...
Bumps [tracing](https://github.com/tokio-rs/tracing ) from 0.1.18 to 0.1.19.
- [Release notes](https://github.com/tokio-rs/tracing/releases )
- [Commits](https://github.com/tokio-rs/tracing/compare/tracing-0.1.18...tracing-0.1.19 )
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-08-11 10:18:54 -07:00
Henry de Valence
f8a24f9c11
Rename script fields to lock/unlock scripts. ( #866 )
...
This is slightly clearer and more correct than the previous pk_script.
2020-08-10 11:49:38 -07:00
teor
7afd76f5fb
feature: Add light_client_root_hash(network) to Block
...
* use the right variant in LightClientRootHash::from_bytes()
* make block.header.light_client_root_hash pub(super)
* add tests for LightClientRootHash and block.light_client_root_hash
2020-08-10 18:54:42 +10:00
teor
ee6f0de14d
refactor: Move NetworkUpgrade to zebra-chain
2020-08-10 18:54:42 +10:00
teor
c4eb136426
feature: Add a LightClientRootHash type
2020-08-10 18:54:42 +10:00
teor
53ce01fd23
fix: Rename the light client hash field
2020-08-10 18:54:42 +10:00
Henry de Valence
a987394782
Add KaTeX to rendered docs. ( #832 )
...
This adds a single test formula to the `zebra-chain` docs. We can remove it
after merging this and running it through CI to confirm that it works.
2020-08-05 17:34:30 -07:00
teor
d49c11ee70
fix: Allow PROPTEST_CASES to override the lower block case default
2020-08-05 02:07:05 -07:00
teor
ac7a4ae517
fix: Speed up the block round trip proptest
...
Reduce the number of cases run by the block round trip proptest, to
speed up the Zebra tests.
2020-08-04 22:35:01 -07:00
teor
78b5bf5e9a
refactor: Move the difficulty tests into their own file
2020-08-04 15:24:52 -04:00
teor
efb9313460
fix: Resolve a type ambiguity in a proptest
...
For some reason, implementing
`PartialOrd<BlockHeaderHash> for ExpandedDifficulty` (or its converse)
makes this unrelated code ambiguous.
2020-08-04 12:29:07 +10:00
teor
c8b502a5da
feature: Compare ExpandedDifficulty and BlockHeaderHash
2020-08-04 12:29:07 +10:00
teor
b7fac7b3bc
feature: Make ExpandedDifficulty use U256 internally
...
Adds a dependency on the primitive-types crate.
Also adds custom hex debug formatting for compact and expanded
difficulties.
2020-08-04 12:29:07 +10:00
teor
c04d1b7b8f
doc: Consensus-critical difficulty encodings
2020-08-04 12:29:07 +10:00
teor
06157a7c8e
Update the BlockHeader fields for Heartwood ( #767 )
...
The Heartwood upgrade changes the meaning of the hashFinalSaplingRoot to
hashLightClientRoot. Since we don't know the network upgrade heights in
zebra-chain, we just use [u8; 32] for now.
2020-08-04 12:15:28 +10:00
dependabot[bot]
f3b65f9609
build(deps): bump tracing from 0.1.17 to 0.1.18
...
Bumps [tracing](https://github.com/tokio-rs/tracing ) from 0.1.17 to 0.1.18.
- [Release notes](https://github.com/tokio-rs/tracing/releases )
- [Commits](https://github.com/tokio-rs/tracing/compare/tracing-0.1.17...tracing-0.1.18 )
Signed-off-by: dependabot[bot] <support@github.com>
2020-08-03 15:49:30 -04:00
teor
195948e5b1
feature: Add an ExpandedDifficulty type and conversion
...
Also add tests.
2020-08-03 10:28:31 +10:00
teor
c4dec3fb36
feature: Make a CompactDifficulty wrapper
...
Wrap the compact difficulty "bits" field in a CompactDifficulty struct,
and rename the header field for clarity.
2020-08-03 10:28:31 +10:00
Jane Lusby
1015db25a8
remap the state storage to only store blocks once ( #741 )
2020-07-31 09:21:54 +10:00
Henry de Valence
7d0a3debb6
chain: ensure impl Deserialize for Amount validates data.
...
This uses serde's try_from attribute to run deserialized values through the
TryFrom impl. Also adds a test to make sure that validation actually does
happen.
2020-07-28 12:20:40 -07:00
teor
5ece62f0a5
fix: Update comments for Heartwood's hashChainHistoryRoot
2020-07-27 14:00:56 -04:00
Henry de Valence
4aa00ad216
Align crate versions and user-agent with NU numbers.
...
We had a brief discussion on discord and it seemed like we had consensus on the
following versioning policy:
* zebrad: match major version to NU version, so we will start by releasing
zebrad 3.0.0;
* zebra-* libraries: start by matching zebrad's version, then increment major
versions of each library as we need to make breaking changes (potentially
faster than the zebrad version, always respecting semver but making no
guarantees about the longevity of major releases).
This commit sets all of the crate versions to 3.0.0-alpha.0 -- the -alpha.0
marks it as a prerelease not subject to perfect adherence to compatibility
guarantees.
2020-07-24 11:46:37 -07:00
teor
41225660fb
doc: The genesis coinbase is the same in every network
2020-07-23 03:46:24 -04:00
Jane Lusby
7d4e717182
Add block locator request to state layer ( #712 )
...
* Add block locator request to state layer
* pass genesis in request
* Update zebrad/src/commands/start/sync.rs
* fix errors
2020-07-22 18:01:31 -07:00
Henry de Valence
90ec2982bf
docs: fix broken links
2020-07-22 17:55:52 -07:00
Alfredo Garcia
db2eb80b3e
Create consensus utils and move byte_reverse_hex function to it ( #705 )
...
* move byte_reverse_hex function
2020-07-22 12:29:14 +10:00
Jane Lusby
b8de256c48
remove serialization error variant of EquihashError
2020-07-22 11:09:22 +10:00
teor
1b0c0f027f
Add Hard-Coded Checkpoint Lists ( #674 )
...
* Add checkpoint list generation scripts
* Limit the checkpoint block data size
* Limit the checkpoint height gap
* Add Mainnet and Testnet checkpoint lists
* Parse hard-coded checkpoint lists
The lists were generated using the following limits:
- 256 MB spacing, based on block byte size, and
- 2000 blocks.
2020-07-21 23:11:51 +10:00
dependabot[bot]
474de52e5c
build(deps): bump displaydoc from 0.1.6 to 0.1.7 ( #689 )
...
Bumps [displaydoc](https://github.com/yaahc/displaydoc ) from 0.1.6 to 0.1.7.
- [Release notes](https://github.com/yaahc/displaydoc/releases )
- [Commits](https://github.com/yaahc/displaydoc/commits )
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-07-20 11:00:15 -07:00
Alfredo Garcia
fe2a468417
add favicon to generated docs ( #681 )
2020-07-17 16:45:29 -07:00
teor
1915634d2b
Check for bad heights or hashes in checkpoint lists ( #639 )
...
* Add MIN and MAX for BlockHeight and LockTime
* Remove duplicate test cases
* fix a comment about the minimum lock time
The minimum LockTime::Time is 5 November 1985 00:53:20 UTC, so the first
day that only contains valid times is 6 November 1985 (in all timezones).
Similarly, the maximum LockTime::Time is 7 February 2106 06::28::15 UTC,
so the last day that only contains valid times in all time zones is
5 February 2106.
* fix: Reject checkpoint lists with bad hashes or heights
Reject the all-zeroes hash, because it is the parent hash of the genesis
block, and should never appear in a checkpoint list.
Reject checkpoint heights that are greater than the maximum block
height.
2020-07-16 15:09:22 +10:00
teor
a19fdd9f25
fix: Rename to is_time_valid_at
2020-07-15 09:16:54 -07:00
teor
b2bb872df0
Use Unicode for section reference
...
Co-authored-by: Henry de Valence <hdevalence@hdevalence.ca>
2020-07-15 09:16:54 -07:00
teor
c2e4f7b0a5
refactor: Move the local clock check to a BlockHeader method
2020-07-15 09:16:54 -07:00
teor
5548dffd3b
refactor: Move the coinbase first check to a Block method
2020-07-15 09:16:54 -07:00
teor
e452ba1c13
fix: Use matches!() based on a new nightly clippy lint
2020-07-15 12:50:11 +10:00
Jane Lusby
06fff62561
remove git dependency on equihash crate
2020-07-10 07:52:52 -04:00
Alfredo Garcia
5d6a5ca329
Add consensus coinbase checks ( #593 )
...
* add coinbase check and test case
Co-authored-by: Jane Lusby <jane@zfnd.org>
2020-07-10 09:13:44 +10:00
Jane Lusby
0474a79669
Add cool helpers for using zcash_serialize / zcash_deserialize ( #586 )
...
Co-authored-by: Dimitris Apostolou <dimitris.apostolou@icloud.com>
2020-07-09 15:29:31 -04:00
Henry de Valence
8b72781fe1
deps: Update redjubjub to 0.2
...
Closes #606 .
2020-07-09 15:20:23 -04:00
Alfredo Garcia
f14e577ea9
apply clippy code suggestions
2020-07-07 18:33:14 -04:00
Henry de Valence
68f57b2577
Update ed25519-zebra to 1.0.
2020-07-07 11:49:21 -07:00
Henry de Valence
e54438f4e4
Update zebra-chain/src/block/header.rs
2020-07-07 11:13:49 -07:00
Dimitris Apostolou
ba81d7d4c0
Fix typos
2020-07-07 11:13:49 -07:00
Jane Lusby
a733580fd8
add proptests for invalid forms of input ( #550 )
...
* add proptests for invalid forms of input
* apply proptests to each valid block we have
* start moving equihash logic to BlockHeader
* provide an error based interface
* cleanup logging in dependent crate
* use is_equihash_solution_valid everywhere
* switch to proper equihash crate branch
2020-07-07 11:01:02 -07:00
Alfredo Garcia
db30e53470
Create a test for block size ( #558 )
...
* add block size limit test
* calculate max_transactions_in_block and max_inputs_in_tx
* abstract block generation
* move all test vectors to zebra-test
2020-07-07 10:37:32 +10:00
Alfredo Garcia
d736355f9f
Add ZIP143 and ZIP243 test vectors ( #585 )
2020-07-03 09:45:40 +10:00
teor
c8829d8408
fix: Adjust bounds on the LockTime Arbitrary impl
...
The previous code could generate LockTime::Time with (u32::MAX + 1),
but the maximum valid value is u32::MAX due to the field size.
2020-07-02 14:30:34 +10:00
Jane Lusby
00e750654a
add nullifier types ( #568 )
...
* add nullifier types
* Apply suggestions from code review
Co-authored-by: Deirdre Connolly <deirdre@zfnd.org>
* add zcash_deserialize impls
* Add docs
Co-authored-by: Deirdre Connolly <deirdre@zfnd.org>
2020-07-01 17:57:32 -07:00
Jane Lusby
c216f5ca25
Refine type for MAC ( #577 )
2020-07-01 17:57:03 -07:00
Jane Lusby
8281b9040c
Start work on new Amount type ( #554 )
2020-07-01 16:31:30 -07:00
teor
7bace99569
fix: Update a comment with the correct parity-zcash path
2020-07-01 16:03:14 -04:00
Jane Lusby
6cbb6d4574
consolidate arbitrary impls to one file in zebra-chain ( #553 )
...
* consolidate arbitrary impls to one file in zebra-chain
* move the ones I missed
* move test-vectors
Co-authored-by: Jane Lusby <jane@zfnd.org>
2020-06-30 14:23:38 -07:00
Jane Lusby
afd0e90a74
Implement equihash verification ( #549 )
...
This change brings in the `equihash` crate from librustzcash and uses it to add a basic `is_valid` test for `EquihashSolutions`.
Co-authored-by: Jane Lusby <jane@zfnd.org>
2020-06-26 11:21:02 -07:00
Alfredo Garcia
9cbd369a59
Refactor block module to have submodules ( #512 )
...
* create hash submodule for block
* create header submodule for block
* create serialize submodule for block
* add newline to hash.rs (fmt)
* Update zebra-chain/src/block/tests.rs
Co-authored-by: Jane Lusby <jlusby42@gmail.com>
Co-authored-by: Henry de Valence <hdevalence@hdevalence.ca>
Co-authored-by: Jane Lusby <jlusby42@gmail.com>
2020-06-25 09:18:05 -07:00
teor
a9efb8715e
chain: Update the note about time truncation
2020-06-24 18:22:36 +10:00
teor
3f5e2695e3
chain: Tweak the version and time test bounds
...
Use MAX constants for the block header version and time arbitrary test
ranges. Reduces the block header time arbitrary test range from 2**32 to
2**32-1 (u32::MAX). (2**32 is an invalid time value, which gets
truncated to 0 during serialization.)
Also add some comments about DateTime conversions.
Part of #477 .
2020-06-24 18:22:36 +10:00
teor
719aa75581
chain: Add a comment about transaction sizes
...
We don't need to check transaction sizes yet, because we aren't
parsing or generating transactions outside of blocks.
Part of #483 .
2020-06-24 18:22:36 +10:00
Henry de Valence
e8561d8f9e
rename zebra-test-vectors to zebra-test
2020-06-22 20:23:02 -07:00
teor
d8b48f885b
consensus: Add a checkpoint verifier stub ( #502 )
...
consensus: Add a checkpoint verifier stub
This stub only verifies blocks whose hashes are in the checkpoint
list.
It doesn't have tests, chain child verifies to their ancestors, or
support checkpoint maximum height queries.
Part of #429 .
2020-06-22 08:51:43 +10:00
Henry de Valence
a0e0e2302b
Update ed25519-zebra to 0.4
2020-06-16 14:35:42 -07:00
Henry de Valence
9ddcccdcb4
Update ed25519-zebra to 0.3
2020-06-16 00:42:25 -04:00
Henry de Valence
a023ba9b16
Add serde bounds to zebra-chain structures. ( #231 )
2020-06-15 15:08:14 -07:00
teor
210e11a86d
chain: Check the maximum block size when parsing
...
The maximum block size is 2,000,000 bytes. This commit also limits the
maximum transaction size in parsed blocks. (See #484 for the
corresponding limit on mempool transactions.)
The proptests might test the maximum block size, but they are
randomised. So we also want to explicitly test large block sizes.
(See #482 for these test cases and tests.)
Part of #477 .
2020-06-15 11:00:48 -07:00
teor
585fa7a1ae
chain: Verify the solutionSize field in block headers
...
Verify the value of the equihash solution size field in block headers.
This field isn't stored in the BlockHeader struct, so we need to verify
it at parse time.
Part of #477 .
2020-06-15 19:04:43 +10:00
Jane Lusby
9f802cd8dd
Wrap Transaction in Arc
2020-06-06 18:13:17 -04:00
Deirdre Connolly
b263489af6
Export ed25519 zebra ( #445 )
...
And use that one, and our similar redjubjub export, everywhere.
Fixes #405
* Move PRs to 'In Progress' column on project board when created
2020-06-06 18:10:32 -04:00
teor
f1de07889c
Fix a typo in a comment in block.rs
2020-06-04 04:49:23 -04:00
Jane Lusby
e9af80b875
Add initial version of zebra-state ( #414 )
...
* rename zebra-storage to zebra-state
* Setup initial skeleton for zebra-state
* add test
* Apply suggestions from code review
Co-authored-by: Henry de Valence <hdevalence@hdevalence.ca>
* move shared test vectors to a common crate
Co-authored-by: Jane Lusby <jane@zfnd.org>
Co-authored-by: Henry de Valence <hdevalence@hdevalence.ca>
2020-06-02 16:16:17 -07:00
dependabot-preview[bot]
145d9a1835
Bump proptest from 0.9.6 to 0.10.0
...
Bumps [proptest](https://github.com/altsysrq/proptest ) from 0.9.6 to 0.10.0.
- [Release notes](https://github.com/altsysrq/proptest/releases )
- [Changelog](https://github.com/AltSysrq/proptest/blob/master/CHANGELOG.md )
- [Commits](https://github.com/altsysrq/proptest/commits )
Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-05-29 15:06:40 -04:00
dependabot-preview[bot]
e317b68b1d
Bump proptest-derive from 0.1.2 to 0.2.0
...
Bumps [proptest-derive](https://github.com/AltSysrq/proptest ) from 0.1.2 to 0.2.0.
- [Release notes](https://github.com/AltSysrq/proptest/releases )
- [Changelog](https://github.com/AltSysrq/proptest/blob/master/CHANGELOG.md )
- [Commits](https://github.com/AltSysrq/proptest/compare/proptest-derive-0.1.2...proptest-derive-0.2.0 )
Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-05-28 23:00:29 -04:00
Jane Lusby
4a2d2a359c
add cargo fmt to ci ( #403 )
...
* add cargo fmt to ci
* rebase on main
* switch to stable
Co-authored-by: Jane Lusby <jane@zfnd.org>
2020-05-27 19:12:25 -07:00
Jane Lusby
4dc307f2f3
fix last warnings
2020-05-27 15:42:29 -04:00
Jane Lusby
b6b35364f3
cleanup warnings throughout codebase
2020-05-27 15:42:29 -04:00
Deirdre Connolly
8d29d05761
Upgrade sha2 to 0.8.2 release
...
Resolves #326
2020-05-23 21:32:37 -04:00
Kiminuo
6465689555
transaction/hash.rs: Add FromStr implementation (issue #299 )
...
Co-authored-by: Deirdre Connolly <durumcrustulum@gmail.com>
2020-05-14 15:30:11 -04:00
Deirdre Connolly
6ed6ccd62e
Clean up imports and some doc comments
2020-04-29 22:42:52 -04:00
Deirdre Connolly
7367daef9f
Tidy TransparentAddress FromStr/Display
2020-04-22 02:17:17 -04:00
Deirdre Connolly
df7ed7ae81
Move note encryption types around ( #362 )
...
* Move around and dedupe note *Cipertext types
* Bump code coverage test timeout to 5 minutes
* Try uploading coverage to codecov.io
2020-04-19 14:45:25 -04:00
Deirdre Connolly
21eca164d8
Refine Output description ephemeral_key to jubjub::AffinePoint
...
And impl Arbitrary for Output to support better generation of those points in proptests.
2020-04-18 22:05:13 -04:00
Deirdre Connolly
7a4be955be
Remove todo
2020-04-18 22:05:13 -04:00
Deirdre Connolly
b53be18c8f
Remove unused From<[u8; 32]> for SpendAuthorizingKey
2020-04-18 04:40:31 -04:00
Deirdre Connolly
630d021886
Remove unused From<[u8; 32]> for ProofAuthorizingKey
2020-04-18 04:40:31 -04:00
Deirdre Connolly
d445799626
Remove the Deref's and make the From's consistent for all key types
2020-04-18 04:40:31 -04:00
Deirdre Connolly
37337c9e44
Remove some impl Deref's and PartialEq's that weren't used
...
Add some impl From<T> for [u8; 32] 's
2020-04-18 04:40:31 -04:00
Deirdre Connolly
f8022442cf
Remove some currently unused From impls for [u8; 32]
2020-04-18 04:40:31 -04:00
Deirdre Connolly
252acd85d8
Tidy imports
2020-04-18 04:40:31 -04:00
Deirdre Connolly
2156c6143b
Complete impl Arbitrary for TransmissionKey
2020-04-18 04:40:31 -04:00
Deirdre Connolly
abcca2c76b
Finish Sapling keys roundtrip proptest
2020-04-18 04:40:31 -04:00
Deirdre Connolly
001b39c588
Impl PartialEq for AuthorizingKey and FullViewingKey
2020-04-18 04:40:31 -04:00
Deirdre Connolly
5d430cff12
Do not try to make a jubjub extended point work as a scalar in redjubjub PublicKey From impl
2020-04-18 04:40:31 -04:00
Deirdre Connolly
94c6d74ecb
Add sapling key derivation bech32 encoding roundtrip proptest
...
And fix SpendingKey Display impl bug.
2020-04-18 04:40:31 -04:00
Deirdre Connolly
9daa1ba3c8
Impl PartialEq for some Sapling keys
2020-04-18 04:40:31 -04:00
Deirdre Connolly
ba3ba6d2d9
Impl From<SpendingKey> for Diversifier
...
This is the _DefaultDiversifier_ method.
2020-04-18 04:40:31 -04:00
Deirdre Connolly
16f1e3061f
Impl From<(AuthorizingKey, NullifierDerivingKey)> for IncomingViewingKey
2020-04-18 04:40:31 -04:00
Deirdre Connolly
e508d09e9b
Move sapling key tests to own module, test key derivation against test vectors
...
Impl a few From<[u8; 32]>'s for a few key types.
2020-04-18 04:40:31 -04:00
Deirdre Connolly
ce1415a8ee
Add generated test vectors from zcash-hackworks/zcash-test-vectors
2020-04-18 04:40:31 -04:00
Deirdre Connolly
f01ea1b4fa
Fix some Sprout key doc/message nits
2020-04-18 04:40:31 -04:00
Deirdre Connolly
adab7335b6
Impl From<[u8; 32]>/Display/FromStr for Sapling SpendingKey, including network field
2020-04-18 04:40:31 -04:00
Deirdre Connolly
68c281c590
Impl Display/FromStr for Sapling IncomingViewingKey, including network field
2020-04-18 04:40:31 -04:00
Deirdre Connolly
cdfcdc4751
Tidy imports
2020-04-18 04:40:31 -04:00
Deirdre Connolly
3eeb9925eb
Impl Debug, Display, and FromStr for Sapling FullViewingKey
2020-04-18 04:40:31 -04:00
Deirdre Connolly
c30a5a64b2
Get Sapling zaddr encoding roundtrip proptest working for now
...
TransmissionKey is just the jubjub affine point identity for now. :/
2020-04-18 04:40:31 -04:00
Deirdre Connolly
aa18937b60
Add network, impl Display and FromStr for SaplingShieldedAddress
2020-04-18 04:40:31 -04:00
Deirdre Connolly
ef9ab8b0ab
Remove Debug test
2020-04-18 04:40:31 -04:00
Deirdre Connolly
01599a0735
Fix unneeded initial value and mut
2020-04-18 04:40:31 -04:00
Deirdre Connolly
23cd346f28
Add missing doc comment for sapling addresses
2020-04-18 04:40:31 -04:00
Deirdre Connolly
43e60fd9a9
Lots of doc improvements
2020-04-18 04:40:31 -04:00
Deirdre Connolly
33821d427d
Add a lazy derive_keys_and_addresses test
2020-04-18 04:40:31 -04:00
Deirdre Connolly
f9d6625fae
All Sapling key derivation looks to be working
...
Modulo actual test vectors! Currently testing with random data each time to
just see if all the types derive without panicking.
2020-04-18 04:40:31 -04:00
Deirdre Connolly
b7bd642910
Clippy pass
2020-04-18 04:40:31 -04:00
Deirdre Connolly
bc13bccb8d
Add a bunch of stuff for JubJub GroupHash, FindGroupHash, etc
...
Until it can be imported into the jubjub crate and upstreamed.
It has been ported from the types used in zcash_primitives and cleaned up
but still needs testing.
2020-04-18 04:40:31 -04:00
Deirdre Connolly
4acce5aa30
Remove static lifetime on some constants
2020-04-18 04:40:31 -04:00
Deirdre Connolly
7e2ae70d66
Wrap AuthorizingKey around redjubjub::PublicKey<SpendAuth>
...
And derive From's and Into's for it, halfway through full key derivation via a test case.
2020-04-18 04:40:31 -04:00
Deirdre Connolly
8388b13ac9
Turn all type aliases into wrapper types with impl Deref
2020-04-18 04:40:31 -04:00
Deirdre Connolly
b9deef2956
Break out crh_ivk() and invoke in IncomingViewingKey derivation
...
There is only one invocation of this PRF but it's nice to keep it consistent with
the PRF^expand ones we have too.
2020-04-18 04:40:31 -04:00
Deirdre Connolly
786677e07b
Add and use prf_addr() for sprout key derivation
2020-04-18 04:40:31 -04:00
Deirdre Connolly
13f2c229d9
Add prf_expand() and use that in sapling key derivation
2020-04-18 04:40:31 -04:00
Deirdre Connolly
b3db623e29
Fill out SaplingShieldedAddress impls and some tests
2020-04-18 04:40:31 -04:00
Deirdre Connolly
451e592b28
Tidy keys::sapling, add commented out Arbitrary impl for now
2020-04-18 04:40:31 -04:00
Deirdre Connolly
7402a54379
Add bech32
2020-04-18 04:40:31 -04:00
Deirdre Connolly
743330fd0b
Make several types wrap jubjub types and impl Deref
2020-04-18 04:40:31 -04:00
Deirdre Connolly
145afb7bda
2 Blakes, 2 Serious
2020-04-18 04:40:31 -04:00
Deirdre Connolly
39278a3095
Parameterize AuthorizingKey as PublicKeyBytes<SpendAuth>
2020-04-18 04:40:31 -04:00
Deirdre Connolly
097d4617df
Update sapling keys derived from spending key via blake2b
2020-04-18 04:40:31 -04:00
Deirdre Connolly
b167a3b96e
Create our own Scalar alias for now
2020-04-18 04:40:31 -04:00
Deirdre Connolly
8add92445c
Add jubjub, replace blake2 with blake2b_simd
2020-04-18 04:40:31 -04:00
Deirdre Connolly
1219f1b552
Improve FullViewingKey doc comment
2020-04-18 04:40:31 -04:00
Deirdre Connolly
ebe5cce3bb
Better doc comment for sapling::TranmissionKey
2020-04-18 04:40:31 -04:00
Deirdre Connolly
b175d1f1ba
Typo
...
Co-Authored-By: Daira Hopwood <daira@jacaranda.org>
2020-04-18 04:40:31 -04:00
Deirdre Connolly
f5bdd449ee
Derive OVK via Blake2b as PRF^expand with t=2
...
Co-Authored-By: Daira Hopwood <daira@jacaranda.org>
2020-04-18 04:40:31 -04:00
Deirdre Connolly
98a91ab92f
Add simple FullViewingKey for now
2020-04-18 04:40:31 -04:00
Deirdre Connolly
8e42c6d8b0
Add stub for SaplingShieldedAddress
2020-04-18 04:40:31 -04:00
Deirdre Connolly
e2743c0b15
Add all simple types for Sapling key derivation tree
2020-04-18 04:40:31 -04:00
Deirdre Connolly
62d30c0a33
Add blake2 dependency
2020-04-18 04:40:31 -04:00
Deirdre Connolly
21a8a29404
Better doc comments for Sprout SpendingKey fields
2020-04-15 03:22:48 -04:00
Deirdre Connolly
dd930c678b
Impl Display as the inverse of FromStr for SproutShieldedAddress
...
And add proptests for zcash (de)serialization and human-readable roundstrips.
2020-04-15 03:22:48 -04:00
Deirdre Connolly
75fbef462d
Add proptest-regressions for new sprout spending key proptests
2020-04-15 03:22:48 -04:00
Deirdre Connolly
e057e120bb
Impl Display/FromStr/ZcashSerialize/ZcashDeserialize for Sprout SpendingKey
...
Includes new field because the raw and Base58Check encoding depends on it.
2020-04-15 03:22:48 -04:00
Deirdre Connolly
6dc0830ea6
Impl Default for Network, as Mainnet
2020-04-15 03:22:48 -04:00
Deirdre Connolly
e83cddf4c6
Impl Display/FromStr/ZcashSerialize/ZcashDeserialize for Sprout IncomingViewingKeys
...
To match the raw and Base58Check encodings as in
https://zips.z.cash/protocol/protocol.pdf#sproutinviewingkeyencoding
2020-04-15 03:22:48 -04:00
Deirdre Connolly
05ca1c0c8a
Refine JoinSplit ephemeral keys to be x25519_dalek::PublicKey
...
Impls PartialEq and Eq and Arbitrary on JoinSplit because PublicKey
does not impl them and we can't do it directly.
Resolves #313
2020-04-13 15:32:04 -04:00
Deirdre Connolly
955a4ebc3c
Rename SpendDescription to Spend, OutputDescription to Output
2020-04-09 17:17:21 -04:00
Deirdre Connolly
2a7838d8e5
Clear up doc comments on SpendingKey
2020-03-28 02:42:13 -04:00
Deirdre Connolly
760edf9271
Tidy *serialize for TransparentAddress with match on network
2020-03-28 02:42:13 -04:00
Deirdre Connolly
a6d511eb71
s/weird/invalid/
2020-03-28 02:42:13 -04:00
Deirdre Connolly
2e063998fb
Add a new() and impl From<[u8; 32]> for SpendingKey
...
Currently fills/receives 32 random bytes and forces the top 4 bits to
zero, ala clamping. If there is a nicer way to csprng'ly fill 252 bits
without clamping, that would be nicer, less bias.
2020-03-28 02:42:13 -04:00
Deirdre Connolly
5f7f851481
Add an explicit test for Display trait on SproutShieldedAddress
2020-03-28 02:42:13 -04:00
Deirdre Connolly
ba25817943
Impl FromStr, tidy Debug for SproutShieldedAddress
2020-03-28 02:42:13 -04:00
Deirdre Connolly
2bd0f53647
Impl FromStr, tidy Debug and Display impls for TransparentAddress
2020-03-28 02:42:13 -04:00
Deirdre Connolly
6e4c80c6f3
Make a note to update to the crates.io version of sha2 when available
2020-03-28 02:42:13 -04:00
Deirdre Connolly
fa1fa60531
Use a match on network inside SproutShieldedAddress::zcash_serialize()
2020-03-28 02:42:13 -04:00
Deirdre Connolly
afccdc3af6
Fix typos and doc comments
2020-03-28 02:42:13 -04:00
Deirdre Connolly
34f4bf05cd
Tidy
2020-03-28 02:42:13 -04:00
Deirdre Connolly
9a20b20070
Better doc comment for IncomingViewingKey
2020-03-28 02:42:13 -04:00
Deirdre Connolly
3bad5304b2
Explicitly use sha2::compress256
2020-03-28 02:42:13 -04:00
Deirdre Connolly
ffac1a33d7
Impl Debug for PayingKey
2020-03-28 02:42:13 -04:00
Deirdre Connolly
2fa566a35f
Impl Debug and Display for SproutShieldedAddress
2020-03-28 02:42:13 -04:00
Deirdre Connolly
caa06c901d
Update zebra-chain/src/addresses/sprout.rs doc comment
...
Co-Authored-By: Daira Hopwood <daira@jacaranda.org>
2020-03-28 02:42:13 -04:00
Deirdre Connolly
66b33172e4
Impl Arbitrary for SproutShieldedAddress and add roundtrip test
2020-03-28 02:42:13 -04:00
Deirdre Connolly
fae9da7dd9
Impl PartialEq and Eq for SproutShieldedAddress
2020-03-28 02:42:13 -04:00
Deirdre Connolly
a7e5d37296
Use updated RustCrypto/hashes source of sha2
2020-03-28 02:42:13 -04:00
Deirdre Connolly
720a507ba3
Use compress feature flag with hashes crate and re-exported compress256
2020-03-28 02:42:13 -04:00
Deirdre Connolly
48dbcab00e
Clippy tidy
2020-03-28 02:42:13 -04:00
Deirdre Connolly
a241cb536a
Add a TODO comment
2020-03-28 02:42:13 -04:00
Deirdre Connolly
f84a8c682a
Derive PayingKey's from SpendingKey's
...
And test that we can still derive TransmissionKey's from PayingKey's,
as they are aliases for x25519_dalek PublicKey/StaticSecret types that already
impl From<_> for each other.
2020-03-28 02:42:13 -04:00
Deirdre Connolly
ee32de2b86
Derive Sprout ReceivingKey's from SpendingKey's via SHA256Compress
...
Test is incomplete, also the type aliases block us from impl'ing Debug or Display.
2020-03-28 02:42:13 -04:00
Deirdre Connolly
bba58807bb
Pull in fork of sha2 that exposes compress256 round function
2020-03-28 02:42:13 -04:00
Deirdre Connolly
ecbd1bf825
Make ReceivingKey a type alias for x25519_dalek::StaticSecret
...
Plus some doc comments
2020-03-28 02:42:13 -04:00
Deirdre Connolly
c836dcf3b6
Docs
2020-03-28 02:42:13 -04:00
Deirdre Connolly
c3700c1a37
Update SproutShieldedAddress types
...
Use magics module.
Stub out key types, including a TransmissionKey alias for x25519_dalek::PublicKey
2020-03-28 02:42:13 -04:00
Deirdre Connolly
01afa09575
Move magic bytes to nested private modules for t-addrs
2020-03-28 02:42:13 -04:00
Deirdre Connolly
1e71793357
Filling out Sprout and Sapling Shielded Addresses
2020-03-28 02:42:13 -04:00
Deirdre Connolly
7af9b80f3b
Add the beginnings of Sprout and Sapling key types
2020-03-28 02:42:13 -04:00
Deirdre Connolly
b4832ab7cb
Add x25519-dalek as dependency
2020-03-28 02:42:13 -04:00
Deirdre Connolly
b03d70090f
Module-level doc comments
2020-03-28 02:42:13 -04:00
Deirdre Connolly
ea773c7a4b
Add module-level doc comment for keys/transparent.rs
2020-03-28 02:42:13 -04:00
Deirdre Connolly
532bbaf460
Impl zcash_deserialize for secp256k1::PublicKey
2020-03-28 02:42:13 -04:00
Deirdre Connolly
3fbfd10f2c
Finish migration of TransparentAddress out of addresses.rs
2020-03-28 02:42:13 -04:00
Deirdre Connolly
7ea39fbdce
Use secp256k1 serde flag to make keys serializable
2020-03-28 02:42:13 -04:00
Deirdre Connolly
bd247067ae
Move TransparentAddress stuff to its own module
2020-03-28 02:42:13 -04:00
Henry de Valence
824193eeeb
Add block 434873 with a bad version field.
2020-03-18 21:34:02 -04:00
Henry de Valence
6ec934a8d7
impl FromStr for BlockHeaderHash
...
This is very convenient for putting block hashes in the source code.
2020-03-18 21:34:02 -04:00
Henry de Valence
dd8ba287bf
Correct block version parsing.
2020-03-18 21:34:02 -04:00
Deirdre Connolly
2a155cadfc
Fix some clippy lints
2020-03-12 22:02:17 -04:00
Deirdre Connolly
b9240971fd
Add impl Arbitrary for TransparentAddress and a roundtrip proptest
...
addresses.rs is now large with just transparent stuff, i am already planning to break this up
further in the addresses/ module.
2020-03-12 22:02:17 -04:00
Deirdre Connolly
4b53c2eac3
Remove AddressPayloadHash, move hashing to TransparentAddress method
2020-03-12 22:02:17 -04:00
Deirdre Connolly
a5f4db7528
Move just the Network enum to -chain, keep everything else in -network
2020-03-12 22:02:17 -04:00
Deirdre Connolly
b68e1e2d55
Move Network, Magic, and magics to zebra-chain
2020-03-12 22:02:17 -04:00
Deirdre Connolly
14120cf828
Clean up comments
2020-03-12 22:02:17 -04:00
Deirdre Connolly
27d960c61e
Remove an answered XXX
2020-03-12 22:02:17 -04:00
Deirdre Connolly
5602ed66a9
Add tests, use Base58Check, not Base58
2020-03-12 22:02:17 -04:00
Deirdre Connolly
f11821fcc8
base58 to string
2020-03-12 22:02:17 -04:00
Deirdre Connolly
9887b7c8b7
Fix up TransparentAddresses
2020-03-12 22:02:17 -04:00
Deirdre Connolly
16ee53a909
Impl zcash_(de)serialize for TransparentAddress
2020-03-12 22:02:17 -04:00
Deirdre Connolly
72ddc7d7a1
Add AddressPayloadHash type
...
Includes From impls for Script, secp256k1::PublicKey
2020-03-12 22:02:17 -04:00
Deirdre Connolly
9a4e4e4236
Stub out transparent addresses, keys with secp256k1
2020-03-12 22:02:17 -04:00
Deirdre Connolly
0998b90392
Stub out sprout, sapling key modules
2020-03-12 22:02:17 -04:00
Deirdre Connolly
db86ef6e8b
Pull in secp256k1 wrapper crate as a dep
2020-02-28 13:19:47 -05:00
Henry de Valence
ff3efd504c
Add Zebra logo to all workspace crates.
...
Also add html_root_url attributes.
2020-02-26 21:25:35 -08:00
Deirdre Connolly
af455f9896
Refine Note types a little more
2020-02-22 22:24:26 -05:00
Deirdre Connolly
a6a3a640ca
Tidied up some note encryption types
2020-02-22 18:33:51 -05:00
Deirdre Connolly
8aefadd00f
Add multiple types to lay out NotePlaintext's for sprout and sapling
2020-02-22 18:33:51 -05:00
Deirdre Connolly
1a10975389
Add memo test vector for invalid utf8 bytes
2020-02-22 18:33:51 -05:00
Henry de Valence
afa2c2347f
fmt
2020-02-21 06:48:25 -05:00
Deirdre Connolly
272c3479a8
Remove unused BlockTestVector struct
...
Resolves #260
2020-02-20 15:05:13 -05:00
Henry de Valence
2d2603cf65
Add a CoinbaseData field, replacing Vec<u8>.
...
The CoinbaseData field can only be constructed by the transaction parser, so we
can ensure that a coinbase input is always serializable, as CoinbaseData
instances can't be constructed outside of the parser that maintains the data
size invariant.
2020-02-19 15:42:20 -05:00
Henry de Valence
b443d7a4be
Fix clippy lints.
2020-02-14 18:23:41 -05:00
Henry de Valence
d887faf16f
Add PartialOrd, Ord to BlockHeight.
2020-02-14 18:23:41 -05:00
Henry de Valence
c4d72177c2
Add a Block::coinbase_height() method.
2020-02-14 18:23:41 -05:00
Henry de Valence
56d7391f6d
Add convenience methods to Transaction.
...
Because we represent each transaction version as a different variant of the
Transaction enum, we end up in a situation where fields that are common to
different transaction versions are awkward to access, requiring a match
statement with identical match arms.
To fix this, this commit adds the following convenience methods:
* `Transaction::inputs() -> impl Iterator<Item=&TransparentInput>`;
* `Transaction::outputs() -> impl Iterator<Item=&TransparentOutput>`;
* `Transaction::lock_time() -> LockTime`;
* `Transaction::expiry_height() -> Option<ExpiryHeight>`;
The last returns an `Option` because the field is only present in V3 and V4
transactions.
There are some remaining fields that do not get common accessors, because it
probably doesn't make sense to access independently of knowing the transaction
version: `joinsplit_data`, `shielded_data`, `value_balance`.
2020-02-14 18:23:41 -05:00
Henry de Valence
44b299d15c
Parse block heights in coinbase transactions.
...
BIP34, which is included in Zcash, encodes the block height into each
block by adding it into the unused BitcoinScript field of the block's
coinbase transaction. However, this is done just by requiring that the
script pushes the block height onto the stack when it executes, and
there are multiple different ways to push data onto the stack in
BitcoinScript. Also, the genesis block does not include the block
height, by accident.
Because we want to *parse* transactions into an algebraic data type that
encodes their structural properties, rather than allow possibly-invalid
data to float through the internals of our node, we want to extract the
block height upfront and store it separately from the rest of the
coinbase data, which is inert. So the serialization code now contains
just enough logic to parse BitcoinScript-encoded block heights, and
special-case the encoding of the genesis block.
Elsewhere in the source code, the `LockTime` struct requires that we
must use block heights less than 500,000,000 (above which the number is
interpreted as a unix timestamp, not a height). To unify invariants, we
ensure that the parsing logic works with block heights up to
500,000,000, even though these are unlikely to ever be used for Zcash.
2020-02-14 18:23:41 -05:00
Henry de Valence
5059c23e99
Add test vectors for genesis & early blocks.
2020-02-14 18:23:41 -05:00
Henry de Valence
4957567409
Represent coinbase inputs explicitly.
...
Coinbase inputs are handled differently from other inputs and have
different consensus rules, so they should be represented differently in
the source code. This lets us discard extraneous details (for instance,
it's not necessary to maintain the all-zero hash) and specialize logic.
2020-02-14 18:23:41 -05:00
Deirdre Connolly
99e3b16476
Make Memo a wrapper for Box<[u8; 512]>
2020-02-13 15:04:04 -05:00
Deirdre Connolly
ea8fa5ef46
Not public for the moment
2020-02-13 15:04:04 -05:00
Deirdre Connolly
01fcce53f4
Move memo to its own module under note_encryption, turn try_from into a match cmp
2020-02-13 15:04:04 -05:00
Deirdre Connolly
54b1172dc8
Avoid a few heap allocations that aren't strictly needed
2020-02-13 15:04:04 -05:00
Deirdre Connolly
2468acb9db
Add some docs to clarify that a Memo is a 'plaintext' type, the parent note will be encrypted
2020-02-13 15:04:04 -05:00
Deirdre Connolly
d7ccf255e1
Update memo link to spec
...
Co-Authored-By: Henry de Valence <hdevalence@hdevalence.ca>
2020-02-13 15:04:04 -05:00
Deirdre Connolly
362f773762
Tidy tests
2020-02-13 15:04:04 -05:00
Deirdre Connolly
30a7647682
Move over various EncryptedCiphertext types from transaction/ module
2020-02-13 15:04:04 -05:00
Deirdre Connolly
ecaaa21d1c
Improve test for Memo::from support
2020-02-13 15:04:04 -05:00
Deirdre Connolly
b8f7487e54
Use AsRef<[u8]>> in From impl
2020-02-13 15:04:04 -05:00
Deirdre Connolly
8572c70716
impl From<String> for Memo
...
I want From<str> but need Sized
2020-02-13 15:04:04 -05:00
Deirdre Connolly
d4d1cf8d7b
Add memo type with Debug impl and some test cases
2020-02-13 15:04:04 -05:00
Henry de Valence
3c6fda8e0b
Make the BlockHeaderHash conversions work on borrows.
2020-02-10 09:03:56 -08:00
Henry de Valence
5f6bf188ff
Derive Hash for BlockHeaderHash.
...
This allows using BlockHeaderHashes in HashSets, HashMaps, etc.
2020-02-10 09:03:56 -08:00
Henry de Valence
ebf60b8840
Make BlockHeader fields public.
2020-02-10 09:03:56 -08:00
Deirdre Connolly
824f206dbe
Add several Debug impls for existing types
...
Resolves #237
2020-02-07 21:30:48 -08:00
Deirdre Connolly
866acde6e8
Add BLOCK_MAINNET_415000_BYTES test vector and a test to deserialize it
...
And println! it, for human eyeballs checking.
Resolves #218
Also changes the header constant to use _BYTES.
2020-02-07 13:42:21 -08:00
Henry de Valence
972d16518f
Make ZcashSerialize infallible mod its Writer.
...
Closes #158 .
As discussed on the issue, this makes it possible to safely serialize
data into hashes, and encourages serializable data to make illegal
states unrepresentable.
2020-02-05 19:48:43 -05:00
Henry de Valence
f04f4f0b98
Apply clippy fixes
2020-02-05 12:42:32 -08:00
Deirdre Connolly
b860461644
Update test block header hash
2020-02-04 18:04:53 -05:00
Deirdre Connolly
6dedb7e101
Write and read the equihash solution compactsize on (de)serialize
2020-02-04 18:04:53 -05:00
Deirdre Connolly
a79969b38f
Add comment around sha256d_flush test
2020-02-04 18:04:53 -05:00
Deirdre Connolly
4fcb66ad3b
Read and write the block header version, which is fixed at 4
2020-02-04 18:04:53 -05:00
Deirdre Connolly
7ebb5ccd41
Add a simple test to check that our mainnet blockheader test vector deserializes without error
2020-02-04 18:04:53 -05:00
Deirdre Connolly
9257d838bd
Use Result::expect() in test (de)serializations
2020-02-04 18:04:53 -05:00
Deirdre Connolly
9b6a9d8e86
Remove debugging variable assignments
2020-02-04 18:04:53 -05:00
Deirdre Connolly
d12db25acb
Cleanup
2020-02-04 18:04:53 -05:00
Deirdre Connolly
54628d889e
Add proptests-regressions/block/tests.txt
2020-02-04 18:04:53 -05:00
Deirdre Connolly
36e9bb162f
Move block type tests and proptest support impls to block::tests
2020-02-04 18:04:53 -05:00
Deirdre Connolly
6508540a92
Remove derive(Arbitrary) on BlockHeader
2020-02-04 18:04:53 -05:00
Deirdre Connolly
b758a8f753
Extend blockheaderhash unit test to check a single (de)serialization case roundtrip
2020-02-04 18:04:53 -05:00
Deirdre Connolly
dab99ba861
Impl Zcash(De)Serialization for Block
2020-02-04 18:04:53 -05:00
Deirdre Connolly
f5c135ee1b
Use updated EquihashSolution in BlockHeader
2020-02-04 18:04:53 -05:00
Deirdre Connolly
4d7bd3e2d7
derive(Copy) on SaplingNoteTreeRootHash
2020-02-04 18:04:53 -05:00
Deirdre Connolly
0f4d3e4a6d
derive(Arbitrary) on MerkleTreeRootHash
2020-02-04 18:04:53 -05:00
Deirdre Connolly
d5800e168c
Add a roundtrip (de)serialization proptest for EquihashSolution
2020-02-04 18:04:53 -05:00
Deirdre Connolly
c2bb6c15f8
Implement a bunch of traits for EquihashSolution
2020-02-04 18:04:53 -05:00
Deirdre Connolly
e82cf0f5a8
Add BlockHeaderHash (de)serialization roundtrip proptest
2020-02-04 18:04:53 -05:00
Deirdre Connolly
69164a6943
Add test for BlockHeaderHash::from(BlockHeader)
2020-02-04 18:04:53 -05:00
Deirdre Connolly
29e1be2442
Impl Zcash(De)Serialize for BlockHeader
2020-02-04 18:04:53 -05:00
Deirdre Connolly
e9d1f91d67
Make MerkleTreeRootHash wrapped array public
2020-02-04 18:04:53 -05:00
Deirdre Connolly
3ea4a6a9ab
Move transaction test vectors around
...
Resolves #210
2020-02-04 18:04:53 -05:00
Deirdre Connolly
1ca55846eb
Little test to exercise sha256dWriter::flush()
2020-02-04 18:04:53 -05:00
dependabot-preview[bot]
73463c33f4
Bump ed25519-zebra from 0.1.0 to 0.2.0
...
Bumps [ed25519-zebra](https://github.com/ZcashFoundation/ed25519-zebra ) from 0.1.0 to 0.2.0.
- [Release notes](https://github.com/ZcashFoundation/ed25519-zebra/releases )
- [Changelog](https://github.com/ZcashFoundation/ed25519-zebra/blob/main/CHANGELOG.md )
- [Commits](https://github.com/ZcashFoundation/ed25519-zebra/compare/0.1.0...0.2.0 )
Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-01-30 20:51:20 -08:00
Deirdre Connolly
359a7dc5eb
Add some proptest shrinkage
2020-01-28 03:48:23 -05:00
Deirdre Connolly
46fa30a66a
Don't use Utc::now() in our LockTime strategy
2020-01-28 03:48:23 -05:00
Deirdre Connolly
ac3c31b1c2
Rearrange and tidy imports
2020-01-28 03:48:23 -05:00
Deirdre Connolly
157add149a
Note that shielded_data::EncryptedCiphertext should move as part of note encryption work
...
Co-Authored-By: Henry de Valence <hdevalence@hdevalence.ca>
2020-01-28 03:48:23 -05:00
Deirdre Connolly
101f0a5c0a
Remove commented out asserts in serialize
...
Co-Authored-By: Henry de Valence <hdevalence@hdevalence.ca>
2020-01-28 03:48:23 -05:00
Deirdre Connolly
cdeaeaa3d6
Remove commented out asserts
...
Co-Authored-By: Henry de Valence <hdevalence@hdevalence.ca>
2020-01-28 03:48:23 -05:00
Deirdre Connolly
09e34f258f
Note that joinsplit::EncryptedCiphertext structs should move as part of note encryption work
...
Co-Authored-By: Henry de Valence <hdevalence@hdevalence.ca>
2020-01-28 03:48:23 -05:00
Deirdre Connolly
283d06bb08
Add (de)serialization roundtrip proptext for shielded_data::(Encrypted,Out)Ciphertext
2020-01-28 03:48:23 -05:00
Deirdre Connolly
2df20b9e6c
Add (de)serialization roundtrip proptext for joinsplit::EncryptedCiphertext
2020-01-28 03:48:23 -05:00
Deirdre Connolly
f379b36208
Add v4 transaction proptest shrinkage
2020-01-28 03:48:23 -05:00
Deirdre Connolly
a259a6b4b1
Add and use v4_strategy()
2020-01-28 03:48:23 -05:00
Deirdre Connolly
a93e2db44b
Add and use OutCiphertext
...
Instead of [u64; 10].
2020-01-28 03:48:23 -05:00
Deirdre Connolly
289f8ec9ca
impl Arbitrary for SpendDescription and refine impl for ShieldedData
2020-01-28 03:48:23 -05:00
Deirdre Connolly
f8781c3415
Refine Arbitrary impl for JoinSplitData<P>
2020-01-28 03:48:23 -05:00
Deirdre Connolly
90086d4d2d
derive(Arbitrary) on Sapling*Note*Tree types
2020-01-28 03:48:23 -05:00
Deirdre Connolly
100c5b15ec
Impl Arbitrary for ShieldedData and derive it for other types
...
Wraps the construction of redjubjub Signature so we don't
need an explicit impl for it.
2020-01-28 03:48:23 -05:00
Deirdre Connolly
7632863454
Impl Arbitrary for JoinSplitData<P>
...
Wraps the construction of ed25519 PublicKeyBytes and Signature so we don't
need an explicit impl for ed25519 types.
2020-01-28 03:48:23 -05:00
Deirdre Connolly
7e34a543ff
Impl Arbitrary for Groth16Proof
2020-01-28 03:48:23 -05:00
Deirdre Connolly
b47e886eed
Add transaction v3 proptest strategy
2020-01-28 03:48:23 -05:00
Deirdre Connolly
b786e1e19c
derive Arbitrary on BlockHeight
2020-01-28 03:48:23 -05:00
Deirdre Connolly
9cbc60a2d7
Proptest v1 and v2 transaction variants
2020-01-28 03:48:23 -05:00
Deirdre Connolly
31b759a924
Update (de)serialization to use EncryptedCiphertext types
2020-01-28 03:48:23 -05:00
Deirdre Connolly
ffd64d4b71
Add shielded_data::EncryptedCiphertext
2020-01-28 03:48:23 -05:00
Deirdre Connolly
95f3c61e53
Add joinsplit::EncryptedCiphertext and derive(Arbitrary) on JoinSplit*
2020-01-28 03:48:23 -05:00
Deirdre Connolly
7d520f8133
Impl Arbitrary for Bctv14Proof
2020-01-28 03:48:23 -05:00
Deirdre Connolly
f4df61eb47
Remove commented out extra Arbitrary impl for Locktime
2020-01-28 03:48:23 -05:00
Deirdre Connolly
b0c0055915
Transaction::V1 round trip proptest
2020-01-28 03:48:23 -05:00
Deirdre Connolly
dfb28b7854
Stubbing out an Arbitrary impl for variant V1 of the Transaction enum
2020-01-28 03:48:23 -05:00
Deirdre Connolly
1ee79b79d3
Add proptest-regressions for transaction/tests.rs
2020-01-28 03:48:23 -05:00
Deirdre Connolly
eb5b3dfefc
Add zcash_[de]serialize roundtrip proptest for Script type
2020-01-28 03:48:23 -05:00
Deirdre Connolly
86f631f9b7
Truncate LockTime::Time datetimes to only seconds for proptests
2020-01-28 03:48:23 -05:00
Deirdre Connolly
71d5571e39
Add roundtrip proptest for LockTime serialization/deserialization
...
Relates to #150
2020-01-28 03:48:23 -05:00
Henry de Valence
60f3f35d89
Refine Ed25519 byte arrays to ed25519-zebra types.
2020-01-24 16:43:31 -05:00
Henry de Valence
2e04610be3
Fix doc errors (missing links, etc).
2020-01-24 13:38:23 -08:00
Henry de Valence
4d5c8c7940
Clarify Transaction docs to point to iterator methods.
...
Closes #191 .
2020-01-24 13:38:23 -08:00
Henry de Valence
41021c65ad
Implement transaction (de)serialization.
2019-12-31 02:46:39 -05:00
Henry de Valence
53cae4647e
Make invalid ShieldedData unrepresentable.
...
ShieldedData objects must have at least one spend or output; using Either
ensures that at least one must be present. This is similar to the
JoinSplitData case, but slightly more complicated: rather than enforcing that
one list has at least one element (which can be done as `(first, rest)`), here
we need to use Either. This has the downside that it is possible to construct
multiple equivalent internal representations (choosing whether a spend or
output goes in the `first` slot), but this easily fixed with a custom PartialEq
implementation.
2019-12-31 02:46:39 -05:00
Henry de Valence
3a7ddbad2d
Add another convenience method for arrays, this time 64 bytes.
2019-12-31 02:46:39 -05:00
Henry de Valence
049998c751
Fix publicity for SaplingNoteTreeRootHash
2019-12-31 02:46:39 -05:00
Henry de Valence
8ff4139c1f
Use Groth16Proof in ShieldedData, not just JoinSplits.
2019-12-31 02:46:39 -05:00
Henry de Valence
92ddf0542f
Provide impl Zcash[De]Serialize for Vec<T: Zcash[De]Serialize>.
...
This replaces the read_list function and makes the code significantly cleaner.
The only downside is that it loses exact preallocation, but this is probably not a big deal.
2019-12-31 02:46:39 -05:00
Henry de Valence
1199cfa23e
impl Zcash[De]Serialize for Script
2019-12-31 02:46:39 -05:00
Henry de Valence
392825c4cb
Add Zcash[De]Serialize bound to ZkSnarkProof.
2019-12-31 02:46:39 -05:00
Henry de Valence
fa1e168fb5
Ensure that invalid JoinSplitDatas are unrepresentable.
...
All JoinSplitDatas must contain at least one JoinSplit.
2019-12-31 02:46:39 -05:00
Henry de Valence
c26304d983
Correct an error in transaction modeling.
...
In the previous transaction modeling I defined the structs so that the number
of old and new commitments for a JoinSplit were variable, when in fact the
Sprout design fixes both to be 2. So now they are hardcoded as 2 in the source
code as well. This commit also fixes some missing `pub` fields on the
`JoinSplit` struct.
2019-12-31 02:46:39 -05:00
Henry de Valence
056127dc94
Copy a transaction test vector from librustzcash.
2019-12-31 02:46:39 -05:00
Henry de Valence
2965187b91
Upgrade tokio, futures, hyper to released versions.
2019-12-13 17:42:15 -05:00
Henry de Valence
4315235d52
Use RedJubjub types in zebra-chain. ( #142 )
2019-12-12 14:23:19 -05:00
Henry de Valence
c013895cd7
Update Transaction definition. ( #105 )
...
* Added a few more top-level fields for the Transaction struct
* Add a placeholder Script type.
This could alternately use bytes::Bytes to save some allocations
but I don't think this is important to get perfectly now. In the future, we
will want to have all of the script handling code in the zebra-script crate,
but we will need to have a container type for an encoded script in zebra-chain,
because otherwise zebra-chain would depend on zebra-script and not the other
way around.
* Rename Transaction{Input,Output} -> Transparent{Input,Output}.
These are only *transparent* inputs and outputs, so by putting Transparent in
the name (instead of Transaction) it's more clear that a transaction's inputs
or outputs can also be shielded.
* Add a LockTime enum.
* First attempt at a Transaction enum.
This attempts to map the versioning and field presence rules into an ADT, so
that structurally invalid transactions (e.g., a BCTV14 proof in a Sapling
transaction) are unrepresentable.
* Update zebra-chain/src/transaction.rs
Co-Authored-By: Daira Hopwood <daira@jacaranda.org>
* Add fixme note on type refinement.
* Rename Transaction variants according to version.
* Split transaction.rs into submodules.
* Start filling in spend, output descriptions.
* Progress on JoinSplit data structures.
This has a lot of duplication and should really use generics to abstract over
Sprout-on-BCTV14 or Sprout-on-Groth16.
* Add data types for Bctv14 and Groth16 proofs.
This also adds a trait to abstract over them.
* Make JoinSplit descriptions generic over the proof system.
* Update zebra-chain/src/transaction/joinsplit.rs
2019-12-05 15:56:58 -05:00
Deirdre Connolly
51b888c0ff
Impl custom Debug for TransactionHash
...
Resolves #104
2019-12-05 10:07:47 -08:00
Henry de Valence
f00c16a624
Require that compactsize encodings are canonical.
2019-11-20 11:59:54 -05:00
Henry de Valence
68a6837cc1
Add a bytes round-trip test for compactsize encoding.
2019-11-20 11:59:54 -05:00
Henry de Valence
986b5ee46b
Fix overlapping range in compactsize encoding.
2019-11-20 11:59:54 -05:00
Henry de Valence
ca24aaf58e
Add the seed for the failing proptest case.
2019-11-20 11:59:54 -05:00
Henry de Valence
2b9991e4e7
Add a basic proptest for compactsize encodings.
...
There's a compiler warning about overlapping ranges so this test should catch the bug.
2019-11-20 11:59:54 -05:00
Henry de Valence
5b801400c1
Update zebra-chain/Cargo.toml
2019-10-17 09:33:10 -07:00
Deirdre Connolly
96ad551681
Remove unnecessary write_all impl
2019-10-17 09:33:10 -07:00
Deirdre Connolly
65d988471a
Implement custom Debug for Sha256dChecksum
...
Relates to #63
2019-10-17 09:33:10 -07:00
Deirdre Connolly
539a16979b
Implement custom Debug impl for BlockHeaderHash
...
Includes a testcase and write_all implementation for Sha256dWriter.
Related to #63
2019-10-17 09:33:10 -07:00
Henry de Valence
f6e62b0f5e
Remove failure from zebra-chain, zebra-network.
...
Failure uses a distinct Fail trait rather than the standard library's
Error trait, which causes a lot of interoperability problems with tower
and other Error-using crates. Since failure was created, the standard
library's Error trait was improved, and its conveniences are now
available without the custom Fail trait using `thiserror` (for easy
error derives) and `anyhow` (for a better boxed Error).
2019-10-16 13:16:52 -04:00
Deirdre Connolly
e1f2eaa446
Add details about max_count to read_list docstring
2019-10-09 22:25:37 -04:00
Deirdre Connolly
dd1b9166b0
Implement Zcash(De)Serialize for BlockHeaderHash, use general read_list for getheaders/headers
2019-10-09 22:25:37 -04:00
Deirdre Connolly
eed69063f6
Add read_list to ReadZcashExt
2019-10-09 22:25:37 -04:00
Henry de Valence
92dc7a5ea1
Fix authorship, license information. ( #55 )
...
* Fix authorship, license information.
I *thought* I had done a sed pass over the Cargo defaults when doing
repository initialization, but I guess I missed it or something.
Anyways, fixed now.
2019-10-08 09:25:59 -07:00
Henry de Valence
47513b1ae7
Suppress warnings from stub functions.
...
This just replaces a bunch of variable names with underscored variants
while the function bodies are still `unimplemented!()`.
2019-09-30 21:32:57 -04:00
Henry de Valence
1323fa7af7
Update zebra-chain/src/transaction.rs
2019-09-27 19:22:34 -07:00
Deirdre Connolly
2739970113
Fill out TransactionHash and rename
...
Resolves #35
2019-09-27 19:22:34 -07:00
Deirdre Connolly
b21b09bf8e
Moved stub TxHash into zebra_chain::transaction
2019-09-27 19:22:34 -07:00
Deirdre Connolly
29591df47e
Use the BlockHeaderHash from zebra-chain in the Inv message parsing
2019-09-27 19:22:34 -07:00
Henry de Valence
958fca8e68
Parse inv messages, refactor inventory vectors.
...
This removes the inventory vector structs from `zebra-chain` (as they
are really part of the network protocol) and refactors them into a
single `InventoryHash` type. This corresponds to Bitcoin's "inventory
vector" but with a different, better name (it's not a vector, it's just
a typed hash of some other item).
2019-09-27 20:41:45 -04:00
Henry de Valence
64b210b53c
Add a read_32_bytes helper method.
...
These are starting to stack up but I think until generic arrays arrive
the cure is worse than the disease :S
2019-09-27 20:41:45 -04:00
Deirdre Connolly
19258d6f54
Remove duplicate from MerkleTree
2019-09-26 23:41:25 -04:00
Deirdre Connolly
b4b72829b2
Sanity: checked
2019-09-26 23:41:25 -04:00
Deirdre Connolly
6236909210
Update zebra-chain/src/transaction.rs
...
Co-Authored-By: Henry de Valence <hdevalence@hdevalence.ca>
2019-09-26 23:41:25 -04:00
Deirdre Connolly
4e85bdb51b
Explain in BlockHeaderHash docstrings block hash vs block header hash
2019-09-26 23:41:25 -04:00
Deirdre Connolly
df5a5f56dd
Add equihash_solution to the lib.rs, impl Zcash(De)Serialize for Block
2019-09-26 23:41:25 -04:00
Deirdre Connolly
f4a6fec2d8
Comment out EquihashSolution::fmt for now
2019-09-26 23:41:25 -04:00
Deirdre Connolly
3f2a1b4f2c
Move around MerkleTree* structs
2019-09-26 23:41:25 -04:00