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