Commit Graph

301 Commits

Author SHA1 Message Date
Jack Grigg 38f87c2e73 ff: Add PrimeField::ReprEndianness associated type
This enables generic code to reliably operate on the bits of an encoded
field element, by converting them to and from a known (little)
endianness.

The BitAnd and Shr bounds on PrimeField are now removed, as users can
perform these operations themselves as needed.
2020-05-02 18:54:02 +12:00
Jack Grigg 55568b4d6e ff: Remove frobenius_map from Field trait
It is only used internally in the bls12_381 crate, and field extensions
aren't exposed anywhere in the Zcash stack.
2020-05-02 16:07:48 +12:00
Jack Grigg 1761ebfb35 ff: Remove SqrtField trait
The sqrt() function is now part of the Field trait. ff_derive returns an
error on fields for which it does not support generating a square root
function.

Note that Fq6 and Fq12 in pairing::bls12_381 leave the function
unimplemented. They will be dropped once the migration to the bls12_381
crate is complete. The equivalent structs in that crate are not exposed.
2020-05-02 16:07:48 +12:00
str4d b02cf3b467
Merge pull request #223 from str4d/remove-primefieldrepr
Remove ff::PrimeFieldRepr
2020-05-01 08:59:41 +12:00
Jack Grigg 49f119fb03 ff: Remove PrimeFieldRepr trait
The ff::PrimeField::Repr associated type now has the minimal necessary
bounds, which can be satisfied by a newtype around a byte array.
2020-04-23 18:15:14 +12:00
Jack Grigg 1fe3e3784c ff: Add Ord bound to PrimeField 2020-04-23 17:31:33 +12:00
Jack Grigg 1a40cfd39c zcash_primitives: Make jubjub::Fs::invert constant time 2020-04-23 16:23:24 +12:00
Jack Grigg 08500ee712 ff: PrimeField: BitAnd<u64, Output = u64> + Shr<u32, Output = Self> 2020-04-23 16:23:24 +12:00
Jack Grigg 1fdca393bb ff: PrimeField::{is_even, is_odd} 2020-04-23 16:23:24 +12:00
Jack Grigg 232f0a50b8 ff: Rework BitIterator to work with both u8 and u64 limb sizes
This enables BitIterator to be used with both the byte encoding and limb
representation of scalars.
2020-04-23 16:23:24 +12:00
Jack Grigg fd79de5408 ff: Add PrimeField: From<u64> constraint 2020-04-23 16:23:24 +12:00
Aditya Kulkarni 3ccadf3017 Add binding signature only if needed 2020-04-04 10:29:30 -07:00
Jack Grigg b6457a905b ff: Move pow_vartime into a trait that is generic over the limb size
The trait is implemented by default for u8 and u64, allowing pow_vartime
to be used with both the byte encoding and limb representation of field
elements.
2020-03-28 00:27:59 +13:00
Jack Grigg 2df2a2b2f2 Merge branch 'develop' 2020-03-14 10:36:58 +13:00
Sean Bowe 100878cd14
Version bump of all crates (except librustzcash) 2020-03-12 15:59:19 -06:00
Sean Bowe b52e4aac3a
Fix Field::random method declarations. 2020-03-03 17:47:29 -07:00
Jack Grigg 2d30c29d06 Pass &impl TxProver to Builder::build
This allows the caller to build multiple transactions with a single
proving backend.
2020-02-08 00:37:31 +00:00
Jack Grigg 76e0f658c1 Rename CommitmentTreeWitness -> MerklePath 2020-02-08 00:36:40 +00:00
Jack Grigg 3a3008caf9 Pass CommitmentTreeWitness directly into Builder::add_sapling_spend
This is more likely to be the data that the caller has available, and
is all we need now that a CommitmentTreeWitness can compute its root.
2020-02-07 17:31:38 +00:00
Jack Grigg 8a210ec271 CommitmentTreeWitness::root(leaf) 2020-02-07 17:21:59 +00:00
Jack Grigg 2064d1c801 Refactor zcash_primitives::merkle_tree::CommitmentTreeWitness
- The internal Option wrapper was an unnecessary leftover from when this
  code was directly inside the prover, where Some(x) represents an
  assigned variable.
- CommitmentTreeWitness::from_slice_with_depth is more idiomatic Rust.
2020-02-07 00:06:57 +00:00
François Garillot 865275e2a2
Correcting some trivial Rust option/iterator warts 2020-01-29 13:53:05 -08:00
Jack Grigg 00499b3441
Migrate zcash_primitives benchmarks to criterion 2019-12-19 16:11:11 -06:00
Jack Grigg ec2c304efd
no_std support for ff crate 2019-12-14 12:55:34 +00:00
Jack Grigg 1c9f5742fa
Improve Field::pow API and impl
Renamed to Field::pow_vartime to indicate it is still variable time with
respect to the exponent.
2019-12-14 12:27:48 +00:00
Jack Grigg 3d2acf48ce
Constant-time field square root
WARNING: THIS IS NOT FULLY CONSTANT TIME YET!

This will be fixed once we migrate to the jubjub and bls12_381 crates.
2019-12-13 20:13:30 +00:00
Jack Grigg 40749da9a7
Constant-time field inversion
WARNING: THIS IS NOT ACTUALLY CONSTANT TIME YET!

The jubjub and bls12_381 crates will replace our constant-time usages,
but we NEED to fix ff_derive because other users will expect it to
implement the Field trait correctly.
2019-12-13 19:46:04 +00:00
Jack Grigg 662be3551f
impl ConditionallySelectable for Field 2019-12-12 23:15:48 +00:00
Jack Grigg cded08b0c5
Make Field::square take &self and return Self 2019-12-12 23:09:28 +00:00
Jack Grigg 9dac748224
Make Field::double take &self and return Self 2019-12-12 22:59:18 +00:00
Jack Grigg 91c32f1c7c
Move from Field::negate to Neg operator 2019-12-12 22:52:17 +00:00
Jack Grigg 27c8f34601
Move Field operations to operator-backed traits
The ff_derive, pairing, zcash_primitives::jubjub, and bellman dummy_engine
changes are minimally implemented on top of the existing *_assign()
functions.
2019-12-12 21:19:46 +00:00
zancas 0aa127d7b1
refactor to manage test code and data in separate modules 2019-12-11 23:58:13 +00:00
Jack Grigg e6a8630b35
impl TryFrom<u32> for BranchId 2019-11-27 13:18:31 +00:00
Jack Grigg cd326f2b6a
Consensus parameters for network upgrades 2019-11-27 13:18:30 +00:00
Jack Grigg c24024b8e1
Create a consensus::BranchId enum for type safety
Includes all currently-known consensus branch IDs for the Zcash network.
2019-11-25 21:04:20 +00:00
Aditya Kulkarni 219391ac92 Add missing sighash declaration 2019-11-14 09:54:07 -08:00
str4d 67d700feab
Merge pull request #107 from str4d/transaction-builder-transparent-inputs
Add P2PKH transparent input support to transaction::Builder
2019-11-13 22:15:55 +00:00
Jack Grigg 8d6f882510
Renames after moves 2019-11-13 19:21:47 +00:00
Jack Grigg 8d967c8609
Move transparent input pushing onto TransparentInputs 2019-11-13 19:20:09 +00:00
Jack Grigg d9d50b98ab
Move transparent signing onto TransparentInputs 2019-11-13 19:12:55 +00:00
str4d 5823a695e2
Merge pull request #139 from adityapk00/tx_compare
Implement sorting for TxIDs
2019-11-04 16:29:59 +00:00
str4d 40d22ea2cc
Merge pull request #135 from NikVolf/extern-purge
Remove unneeded "extern crate"
2019-10-31 17:12:26 +00:00
Aditya Kulkarni b479981689
Implement clone for some structs 2019-10-15 17:47:53 +13:00
Aditya Kulkarni 885e09a82f
Create OutPoint from hash and n 2019-10-15 17:47:23 +13:00
Aditya Kulkarni fab9160b26
transparent inputs should use serialize_der() 2019-10-15 17:46:33 +13:00
Aditya Kulkarni 5a177eea27
Make mod serialize public 2019-10-15 17:42:49 +13:00
Jack Grigg 3425eabda2
transaction::Builder::add_transparent_input() 2019-10-15 17:42:46 +13:00
Jack Grigg 70857b0eed
Pass Script to signature_hash by reference 2019-10-15 17:32:34 +13:00
Jack Grigg 42b7f328fb
legacy::Script::address
This is the counterpart to legacy::TransparentAddress::script.
2019-10-15 17:32:34 +13:00
Aditya Kulkarni cd1083e086 Implememt sorting for TxIDs 2019-10-14 13:40:08 -07:00
Jack Grigg 2bbd25b36b
Add prevHash field to CompactBlock
This enables basic verification of chain validity when CompactBlocks are
received without the full header.
2019-10-09 14:11:14 +13:00
Jack Grigg a3b85b8fe6
Compute and store BlockHash inside BlockHeader 2019-10-09 14:11:14 +13:00
NikVolf 7844394364 Remove unneeded extern crate 2019-10-08 16:12:14 +03:00
Jack Grigg 8b08528bb0
zcash_primitives 0.1.0 2019-10-08 17:43:33 +13:00
str4d 2399d9f3e3
Merge pull request #93 from defuse/qed-it-lrz
Bring in QED-it Tests
2019-10-08 13:47:36 +13:00
Jim Posen 93563c3c65 Specify rand_core >= 0.5.1 for OsRng import. 2019-10-05 12:16:10 +02:00
str4d 524055bbb4
Merge pull request #134 from NikVolf/z-rng
Avoid using rand_os crate (fixes warnings)
2019-10-02 17:35:56 -06:00
NikVolf 730d2cbc7e fix outdated example 2019-09-28 12:50:28 +03:00
NikVolf b42477a0bf update from rand_os to fix warnings 2019-09-28 10:48:43 +03:00
Jack Grigg 4ad3988e43
Crate docs 2019-09-24 14:23:59 +01:00
Jack Grigg 7f3036d2c8
Update READMEs 2019-09-24 14:23:55 +01:00
Jack Grigg d9a0b9c83f
CI: Check intra-doc links
Credit: https://twitter.com/tomaka17/status/1176017851410526208
2019-09-24 10:35:12 +01:00
Jack Grigg 1d02363752
Add READMEs to Cargo.toml files
This will cause crates.io to render each crate's README as its
information page.
2019-09-23 14:42:38 +01:00
Taylor Hornby 3701c2b442
Increase the number of pedersen hash generators, exercise all test vectors. 2019-09-17 00:05:54 +01:00
Taylor Hornby 4dff8055bf
Remove unfinished find_group_hash test. 2019-09-16 23:44:14 +01:00
Taylor Hornby e391594e9e
Fix broken linear relation checking 2019-09-16 22:51:11 +01:00
Kobi Gurkan 15b4c37ab0
adds test for linear relation between pedersen hash generators 2019-09-16 22:23:28 +01:00
Aurélien Nicolas 68ba93f5fd
PH test vectors for edge-cases 2019-09-16 21:58:28 +01:00
Aurélien Nicolas 6240c02208
Long and random PH test vectors 2019-09-16 21:57:53 +01:00
Aurélien Nicolas be18eb240c
Move test vectors into own module 2019-09-16 21:57:42 +01:00
Aurélien Nicolas 9080b4ccf3
Many test vectors for pedersen hash 2019-09-16 20:52:11 +01:00
Aurélien Nicolas f5dfe07355
A test vector for pedersen hash 2019-09-16 20:50:22 +01:00
Kobi Gurkan 2edcc12e8e
group_hash: adds test vectors generated by go-jubjub 2019-09-16 20:34:14 +01:00
Kobi Gurkan 7ee61c4f94
pedersen_hash: adds test vectors for the circuit implementation 2019-09-16 20:23:07 +01:00
Kobi Gurkan 15633ad434
pedersen hashes: example of size limit bug 2019-09-16 20:17:50 +01:00
Kobi Gurkan 414d651c9c
pedersen_hash: adds tests for Daniel's vector 2019-09-16 20:12:38 +01:00
Kobi Gurkan 8541b2bde4
pedersen_hash: prints hashes, adds comments 2019-09-16 20:12:33 +01:00
Jack Grigg 0a3b0a9341
Upgrade to hex-literal 0.2 2019-09-12 19:38:51 +01:00
Jack Grigg d6f6b50ecd
Check try_sapling_output_recovery fails with identity as pk_d 2019-09-04 19:48:39 -04:00
Jack Grigg abbd43ff57
Make pk_d validity an invariant of PaymentAddress
Introduces a PaymentAddress::from_parts constructor, and getters for
the diversifier and pk_d fields (which are now private).
2019-09-04 19:48:35 -04:00
Jack Grigg 86142d044c
PaymentAddress::to_bytes 2019-09-04 19:46:46 -04:00
Jack Grigg 73ee19239c
Replace manual address decoding with PaymentAddress::from_bytes 2019-09-04 19:46:46 -04:00
Jack Grigg 0c7eb84d36
impl FromStr for Memo
Memo::from_str was previously shadowing a built-in trait method.
2019-08-24 00:40:32 +01:00
Jack Grigg 7c1d4d9a5b
Log distinct error cases in Equihash verification 2019-08-24 00:40:30 +01:00
Jack Grigg fe93f2ff6b
Rename into_ -> to_ where &self is used. 2019-08-24 00:39:54 +01:00
Jack Grigg 3a8efd9e67
Address various clippy warnings/errors in zcash_primitives 2019-08-24 00:39:49 +01:00
Jack Grigg d78c94b2a2
Move Equihash validator into zcash_primitives 2019-08-24 00:37:00 +01:00
Eirik Ogilvie-Wigley d63fa334ff
Remove unnecessary raw marker
Co-Authored-By: str4d <thestr4d@gmail.com>
2019-08-21 16:14:28 -06:00
Eirik Ogilvie-Wigley 76795a9014 cargo fmt 2019-08-20 22:22:03 -06:00
Eirik Ogilvie-Wigley c28ae31c71 cargo fix --edition-idioms for zcash_primitives 2019-08-20 22:20:22 -06:00
Eirik Ogilvie-Wigley 09882c6d08 Add edition = 2018 2019-08-20 18:31:20 -06:00
Eirik Ogilvie-Wigley b35a819a09 Replace try! macro 2019-08-20 18:24:47 -06:00
Eirik Ogilvie-Wigley f523ac285d cargo fmt 2019-08-20 17:17:21 -06:00
Eirik Ogilvie-Wigley b0d8747697 cargo fix --edition for zcash_primitives 2019-08-20 17:15:07 -06:00
Eirik Ogilvie-Wigley e12d315ab9 Warning cleanup 2019-08-20 16:45:10 -06:00
Eirik Ogilvie-Wigley 81c58172c3 cargo fmt zcash_primitives 2019-08-15 10:39:55 -06:00
Jack Grigg 5fb9b86ba0
Move Jubjub, Pedersen hash and primitives into zcash_primitives 2019-08-14 10:47:22 +01:00
Jack Grigg 2ae5804a67
Move Sprout and Sapling circuits into zcash_proofs 2019-08-14 10:45:55 +01:00
Jack Grigg 7ea6d10480
Move redjubjub into zcash_primitives 2019-08-14 10:43:25 +01:00
Jack Grigg 3211536324
Upgrade to crypto_api_chachapoly >= 0.2.1 2019-08-14 01:12:26 +01:00
Jack Grigg 2f1cae62b1
Upgrade to fpe 0.2 2019-08-14 01:12:23 +01:00
str4d 4a6c9ec425
Comment that we support a minimal set of script opcodes
Co-Authored-By: Daira Hopwood <daira@jacaranda.org>
2019-08-14 00:30:18 +01:00
Jack Grigg a28d94ff2e
Panic if Amount addition or subtraction overflows 2019-08-14 00:16:09 +01:00
Jack Grigg 1760b275a7
Simplify transaction builder tests
Requires impl PartialEq for Transaction, which is implemented as a TxId
comparison (relying on the invariant that Transaction is immutable).
2019-08-13 15:24:08 +01:00
Jack Grigg 3a73f946c5
Simplify structure of transaction builder errors 2019-08-13 15:10:57 +01:00
Jack Grigg e6663212ff
Improve documentation for Amount 2019-08-08 09:21:09 +01:00
Jack Grigg 7c07914bfd
Separate Amount::{from_i64, from_nonnegative_i64} APIs
This is more intuitive than a boolean flag for handling non-negative
Amounts stored in i64 values.
2019-08-08 00:55:23 +01:00
Jack Grigg 59ed258c7f
Make Amount opaque, and use it more
This helps to ensure type-safety of values that are required to satisfy
zatoshi range bounds.
2019-07-27 00:35:29 +01:00
Jack Grigg ab60b8804a
impl operators for Amount 2019-07-27 00:35:28 +01:00
Jack Grigg 0ea4408d46
Amount::{zero, is_positive, is_negative} 2019-07-27 00:35:27 +01:00
Jack Grigg fa50d551c8
Move Amount impl into a submodule 2019-07-27 00:35:26 +01:00
Jack Grigg 17f6bbcc67
Pass tx builder RNG to spend_sig() 2019-07-27 00:35:04 +01:00
Jack Grigg 532299d46e
Allow transaction::Builder RNG to be configured 2019-07-27 00:32:56 +01:00
Jack Grigg 4b61120cd0
Pass tx builder RNG to SaplingNoteEncryption 2019-07-27 00:31:16 +01:00
Jack Grigg a1cd9dfbac
transaction::Builder::add_transparent_output() 2019-07-27 00:28:02 +01:00
Jack Grigg c26188a0bb
TransparentAddress struct for P2PKH and P2SH 2019-07-27 00:28:01 +01:00
Jack Grigg dab3c002b7
Script opcode and data support
Overrides the shift-left operator for pushing opcodes onto the Script,
matching the notation used in zcashd.
2019-07-27 00:28:00 +01:00
Jack Grigg 1862354ea6
Sapling transaction builder 2019-07-27 00:27:50 +01:00
Jack Grigg 01618038bf
TxProver trait to abstract over the circuit parameters
An implementation using local parameters is provided in the zcash_proofs
crate.
2019-07-26 23:56:00 +01:00
str4d 05f098e893
Merge pull request #91 from str4d/upgrade-rand
Upgrade rand crate dependency to 0.7
2019-07-26 23:31:42 +01:00
str4d 5a48d179b8
Merge pull request #90 from adityapk00/paperwallet
Make some methods pub for use in External Wallet Generators

The exposed APIs may change in future crate versions.
2019-07-22 13:25:25 +01:00
Aditya Kulkarni 7f60f0f881 Make some methods in DiversifierKey, DiversiferIndex pub 2019-07-18 16:19:45 -07:00
Jack Grigg 6f9083b5ab
Migrate to rand 0.7 2019-07-19 00:47:40 +02:00
Jack Grigg 8f7adec0d9
Migrate zcash_primitives to rand_core 0.4 2019-07-19 00:46:37 +02:00
Jack Grigg 6149166ccb
Migrate zcash_primitives to rand 0.5 2019-07-19 00:35:06 +02:00
str4d 8361674efc
Merge branch 'master' into blake2_simd 2019-07-18 18:22:20 +02:00
Jack Grigg 504c3eaeae
Address Daira's review comments 2019-07-15 16:33:43 +02:00
Jack Grigg 07dbfbef59
Address Eirik's review comments 2019-07-10 13:53:22 -04:00
Jack Grigg 79006ecbdf
Unify Sapling tree depth constants
When sapling-crypto is refactored, the zcash_primitives::sapling
constant would become the canonical one.
2019-07-10 13:53:22 -04:00
Jack Grigg e67560b154
Document merkle_tree module 2019-07-10 13:53:22 -04:00
Jack Grigg b9cea33804
Move merkle_tree::Node into sapling module
This makes the merkle_tree module properly generic over the tree hash.
It still hard-codes a depth 32 tree, because Rust doesn't yet support
generic sizes, and we are unlikely to need to alter the tree depth in
future circuit changes.
2019-07-10 13:53:22 -04:00
Jack Grigg 263bbe1207
Use Iterator::all() in place of Iterator::fold() 2019-07-10 13:53:22 -04:00
Jack Grigg 98d7621135
Don't assert when parsing a CommitmentTreeWitness 2019-07-10 13:53:22 -04:00
Jack Grigg 9b4186705a
Add serialization APIs to CommitmentTree and IncrementalWitness 2019-07-10 13:53:22 -04:00
Jack Grigg 70a7069058
Helper for serializing Option<T> 2019-07-10 13:53:22 -04:00
Jack Grigg 667d6101c9
Sapling incremental witnesses 2019-07-10 13:53:20 -04:00
Jack Grigg bf74915053
Move CommitmentTreeWitness into zcash_primitives 2019-07-10 13:52:47 -04:00
Jack Grigg f4059a5faa
Sapling commitment tree 2019-07-10 13:44:21 -04:00
Jack Grigg 8f3f95ee08
Sapling commitment tree empty roots 2019-07-10 13:44:21 -04:00
Jack Grigg 785f22ca5a
Move Sapling commitment tree hash into zcash_primitives 2019-07-10 13:44:19 -04:00
Jack Grigg 999dcbfcab
Migrate to blake2b_simd and blake2s_simd crates
The primary reason for migrating is that these crates provide APIs for
setting the personalisation string. This enables us to depend solely on
published crates, and thus publish our own crates.

The SIMD implementations are ported from libsodium.

Closes #67.
2019-07-10 13:12:14 -04:00
Jack Grigg f25a8a557e
Convert zip32 crate into a module of zcash_primitives 2019-06-27 16:14:24 +01:00
str4d 3b6f5e3d5e
Merge pull request #69 from str4d/sapling-note-encryption
Sapling note encryption
2019-06-06 20:50:17 +01:00
Jack Grigg b65aae9bc1
Test both invalid and incorrect diversifiers 2019-06-06 13:56:06 +01:00
Jack Grigg fdb6e208db
Check note plaintext version byte when decrypting 2019-06-06 13:38:34 +01:00
Jack Grigg 060977fe54
Return edwards::Point from sapling_ka_agree
This matches how sapling_ka_agree and kdf_sapling are defined in the
protocol spec. kdf_sapling also now takes ownership of dhsecret to
discourage use of the sapling_ka_agree output elsewhere.
2019-06-06 13:38:33 +01:00
Jack Grigg 9d80be62f9
Simplify Memo::to_utf8 implementation 2019-06-06 13:38:32 +01:00
Jack Grigg 6846ac5f9e
Require that ak in FullViewingKey is prime order 2019-06-06 13:38:31 +01:00
Jack Grigg 75bede4bc8
Use fixed-length arrays instead of Vec 2019-06-06 13:38:30 +01:00