Commit Graph

219 Commits

Author SHA1 Message Date
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