Commit Graph

1241 Commits

Author SHA1 Message Date
Jack Grigg 71586914d4 group: Extract compressed encodings from CurveAffine trait 2020-06-17 11:35:15 +12:00
Jack Grigg 3759fc8aab group: Default implementation of CurveProjective::batch_normalize
For convenience. Implementations will usually override this to take
advantage of implementation-specific batching optimisations.
2020-06-17 11:31:09 +12:00
Jack Grigg ae2d2b59b9 group: Move uncompressed encodings to an UncompressedEncoding trait
Specifications of deployed elliptic curves fall into one of two
categories:
- They specify both compressed and uncompressed encodings, allowing
  implementations to use either depending on performance vs data size
  considerations.
- They specify a single point encoding format using point compression.

I am unaware of any elliptic curve specification that explicitly forbids
compressed encodings.

To support both categories of elliptic curves, we provide the
CurveAffine::Compressed associated type which all curves must define,
and then curves that additionally specify an uncompressed encoding may
implement the UncompressedEncoding trait and its Uncompressed associated
type.

pairing::PairingCurveAffine continues to require that its groups provide
uncompressed encodings, because this is relied upon by bellman::groth16.
We can revisit this restriction when that module is refactored as a
separate crate.
2020-06-17 11:31:07 +12:00
Jack Grigg 4e685a847d Merge branch 'pairing-refactor' 2020-06-17 09:48:24 +12:00
str4d 7b94622ae0
Merge pull request #237 from str4d/bellman-scalar
Replace E: ScalarEngine with Scalar: PrimeField
2020-06-17 09:28:52 +12:00
str4d cf75dc559d
Merge pull request #239 from str4d/heartwood-activation
Set activation heights for Heartwood network upgrade
2020-06-04 16:19:43 +12:00
Jack Grigg 3779c12e31 Set activation heights for Heartwood network upgrade 2020-06-04 15:33:07 +12:00
Jack Grigg 03f086221b pairing: Move PairingCurveAffine::Prepared to MultiMillerLoop trait
Prepared elements are only used by MultiMillerLoop, and we don't need
the ability to "prepare" G1 elements there.
2020-06-03 20:50:02 +12:00
Jack Grigg b9d6df9133 pairing: Extract Engine::miller_loop into a MultiMillerLoop trait
This enables MultiMillerLoop to be conditionally implemented, for
example in libraries where Engine::pairing supports no-std, but
MultiMillerLoop requires an allocator.
2020-05-31 08:35:02 +12:00
Jack Grigg da2e638c7d pairing: Pass affine references to Engine::pairing 2020-05-31 08:34:07 +12:00
Jack Grigg 57bb18ca6f pairing: Move final_exponentiation into a MillerLoopResult trait 2020-05-31 08:34:03 +12:00
Jack Grigg c8bf2e9fb7 pairing: Separate associated types for MillerLoopResult and Gt 2020-05-31 08:22:52 +12:00
Jack Grigg 534c99327a pairing: Remove Engine::Fq and Engine::Fqe
These are unused now that the Base associated types have been removed
from the group traits.
2020-05-31 08:22:52 +12:00
Jack Grigg 5a40a0fe8f group: Remove CurveProjective::Base and CurveAffine::Base
These associated types were completly unused. The only place we need
information about the base field of an elliptic curve is inside Jubjub
when operating over its coordinates to implement EC math inside the
circuit, and we can handle that either concretely, or with a future
trait specifically for that use-case.
2020-05-31 08:22:52 +12:00
Jack Grigg 0a0e513948 ff: Remove ScalarEngine 2020-05-31 02:06:24 +12:00
Jack Grigg 0b2293bcc0 bellman: Replace E: ScalarEngine with Scalar: PrimeField
Instead of imposing the requirement that bellman users explicitly
specify an engine for every proving system, we allow the Rust type
system to figure it out for us. An engine is specifically useful in
places where we require defined relationships between several types;
ff::ScalarEngine only has one type, and thus any usage of it can be
trivially replaced by an explicit Scalar type. This is also more
readable :)
2020-05-31 02:00:10 +12:00
str4d 5ff8562744
Merge pull request #222 from adityapk00/zecwallet_compat
Expose the `hash` and `n` fields of Transparent Outputs
2020-05-23 14:13:31 +12:00
Aditya Kulkarni 4b1d8e5226 Add methods to get OutPoint n, hash 2020-05-22 18:02:44 -07:00
str4d 121231199c
Merge pull request #205 from str4d/taddr-encoding
Implement TransparentAddress encoding and decoding
2020-05-23 12:22:01 +12:00
str4d 8831150825
Merge pull request #232 from str4d/lint-fixes
Lint fixes
2020-05-23 08:03:03 +12:00
Jack Grigg c488732022 Use text directive on sage script doc comment instead of norun
norun is an invalid directive, and no_run would cause the sage script to
be compiled as Rust.
2020-05-22 19:13:33 +12:00
Jack Grigg 2892cf94c1 Migrate to protobuf-codegen-pure 2.14 2020-05-22 18:55:46 +12:00
Jack Grigg 4edff96321 Fix various lints 2020-05-22 18:52:35 +12:00
str4d a22957b575
Merge pull request #231 from str4d/group-remove-encodedpoint
group: CurveAffine and CurveProjective trait refactor
2020-05-21 09:49:34 +12:00
Jack Grigg 5f1607c9b5 group: Rename into_*(&self) -> to_*(&self)
Rust naming convention uses the into_ prefix for methods that consume
self, and the to_ prefix for methods that take an immutable reference.
2020-05-20 11:32:12 +12:00
Jack Grigg ceecd32ac4 group: Remove EncodedPoint::from_affine
The EncodedPoint trait is replaced by explicit bounds on the
CurveAffine::{Uncompressed, Compressed} associated types.
2020-05-20 11:32:12 +12:00
Jack Grigg b77f8dddda group: Remove EncodedPoint::{into_affine, into_affine_unchecked}
Replaced by explicit APIs on the CurveAffine trait.

GroupDecodingError has been moved into pairing::bls12_381::ec, as it is
no longer used by the group traits.
2020-05-20 11:32:12 +12:00
Jack Grigg b0a3713d7e group: Add mixed-addition scalar multiplication bounds to CurveAffine
Replaces the explicit CurveAffine::mul trait method.
2020-05-20 11:32:12 +12:00
Jack Grigg 0941dddc13 group: Return subtle::Choice from CurveAffine::is_identity 2020-05-20 11:32:12 +12:00
Jack Grigg b94d567076 group: Direct-to-affine CurveProjective::batch_normalize
Replaces the mutating CurveProjective::batch_normalization API, and
removes the need for CurveProjective::is_normalized.

The new temporary implementation in pairing::bls12_381::ec is adapted
from bls12_381::g1.
2020-05-20 11:32:12 +12:00
str4d 4969ad4d93
Merge pull request #230 from str4d/group-trait
group crate refactoring
2020-05-19 08:30:53 +12:00
Jack Grigg 669f2b43eb group: Return subtle::Choice from Group::is_identity 2020-05-15 10:24:30 +12:00
Jack Grigg ec88778258 group: Add scalar multiplication bounds to Group
The Scalar associated type is moved from CurveProjective to Group.
2020-05-15 10:24:30 +12:00
Jack Grigg 0df950dc0d group: Add Group::Subgroup associated type
For prime-order groups, this may be Self.
2020-05-15 00:20:32 +12:00
Jack Grigg d2aa87f084 group: Move CurveProjective::double to Group 2020-05-15 00:20:32 +12:00
Jack Grigg e3d84280b9 group: Sum + for<'a> Sum<&'a Self> bounds for Group 2020-05-15 00:20:32 +12:00
Jack Grigg 5397d73e0b group: Define group operations on Group trait
The GroupOps trait represents the group operation (addition), and the
combination of the group operation with group inversion (subtraction).
Group inversion (negation) is constrained directly on the Group trait.
2020-05-15 00:20:32 +12:00
Jack Grigg 69f53febcf group: Introduce Group and PrimeGroup traits
Group represents a cryptographic group with a large prime-order subgroup
and a small cofactor. PrimeGroup further constrains the group to have a
cofactor of one.
2020-05-15 00:20:32 +12:00
Jack Grigg 7203a7a30a Remove Engine associated type from CurveAffine and CurveProjective
The type Curve*::Engine::Fr is equivalent to Curve*::Scalar, making
Engine a redundant associated type.
2020-05-15 00:20:32 +12:00
Jack Grigg 8add78a327 Make CurveProjective::double take &self and return Self 2020-05-15 00:20:32 +12:00
Jack Grigg 4f2220fbb1 group: Rename zero and one to identity and generator 2020-05-15 00:20:32 +12:00
Jack Grigg d7d49285d8 Remove explicit std::marker from Sized bound
Sized is always part of the prelude, and binding on std causes
compilation issues for no-std crates.
2020-05-15 00:20:32 +12:00
str4d 41d9f293d4
Merge pull request #229 from therealyingtong/106-hardcode-sapling-circuit-hashes
Hard-code Sapling circuit hashes in zcash_proofs crate
2020-05-14 17:06:07 +12:00
Jack Grigg f446b45af5 cargo fmt 2020-05-14 16:06:58 +12:00
ying tong 6845154d88
Update zcash_proofs/src/lib.rs
Co-authored-by: str4d <thestr4d@gmail.com>
2020-05-14 11:30:13 +08:00
therealyingtong d480a3840a Hard-code Sapling circuit hashes in zcash_proofs crate
Define the spend_hash, output_hash, sprout_hash circuit hashes as constants in the load_parameters function, so we don't have to take them as function arguments.
2020-05-13 22:36:21 +08:00
str4d 37270776be
Merge pull request #228 from str4d/ff-more-trait-refactoring
ff: More trait refactoring
2020-05-13 09:18:11 +12:00
Jack Grigg c597db59a6 ff: Rename PrimeField::into_repr -> PrimeField::to_repr 2020-05-02 18:55:13 +12:00
Jack Grigg 9114c367f4 ff_derive: Generate modulus representation with correct endianness
Now that PrimeField::ReprEndianness exists, users can obtain a
known-endianness representation from the output of PrimeField::char
(which is a PrimeField::Repr, and should return a representation with
the same endianness as PrimeField::into_repr).
2020-05-02 18:54:02 +12:00
Jack Grigg 15e229509a ff: Move pow_vartime back into Field trait
The only places we don't use constant u64 limbs, we use PrimeField::char
instead (except in a single test where we use a field element).
2020-05-02 18:54:02 +12:00