Commit Graph

20 Commits

Author SHA1 Message Date
Jane Lusby 8281b9040c
Start work on new Amount type (#554) 2020-07-01 16:31:30 -07: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
Jane Lusby 9f802cd8dd Wrap Transaction in Arc 2020-06-06 18:13: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 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
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 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 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
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 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 a93e2db44b Add and use OutCiphertext
Instead of [u64; 10].
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
Henry de Valence 60f3f35d89 Refine Ed25519 byte arrays to ed25519-zebra types. 2020-01-24 16:43:31 -05:00
Henry de Valence 41021c65ad Implement transaction (de)serialization. 2019-12-31 02:46:39 -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