Commit Graph

121 Commits

Author SHA1 Message Date
Jack Grigg 1124eb3ca9 bellman 0.7.0 2020-08-23 16:23:53 +01:00
Jack Grigg 5f99c52143 bls12_381 0.2.0 2020-08-23 16:23:53 +01:00
Jack Grigg bdb42bcbc8 pairing 0.17.0 2020-08-23 15:31:09 +01:00
Jack Grigg ee3e8fbfbb group 0.7.0 2020-08-23 15:31:09 +01:00
Jack Grigg 55fa366730 ff 0.7.0 2020-08-23 15:31:09 +01:00
Jack Grigg f735e8b83b pairing: Remove BLS12-381 implementation
It is replaced by the bls12_381 crate.
2020-08-19 23:08:19 +01:00
Jack Grigg fdf06032e3 s/{pairing::bls12_381, zcash_primitives::jubjub}/{bls12_381, jubjub}
FINALLY.
2020-08-19 23:08:19 +01:00
Jack Grigg 0db22b1838 bellman: Migrate to bit-vec 0.6 2020-08-14 17:44:17 +01:00
Jack Grigg af9f5f2cf6 bellman: Migrate to sha2 0.9 2020-08-14 17:44:17 +01:00
Jack Grigg 7eaf6493e8 pairing: Require G1 and G2 to be PrimeCurve
Pairings require that G1, G2, and GT are groups of prime order.
2020-08-13 18:17:29 +01:00
Jack Grigg ed6b7eceef group: Hard-code a w-NAF window size of 4
We were already ignoring the actual bit length of the scalar, and
selecting the window size based on the maximum bit length, which
effectively hard-coded a window size of 4.
2020-08-12 08:12:48 +01:00
Jack Grigg 1e8fd4da68 group: CofactorGroup::mul_by_cofactor -> CofactorGroup::clear_cofactor
The generic API now only guarantees that the torsion component is
cleared deterministically; group elements may be multiplied by multiples
of the cofactor (not necessarily the actual cofactor), as long as the
choice of multiplier is fixed for a given implementation.
2020-08-12 08:12:25 +01:00
Henry de Valence 139fc09f10
bellman: add VerificationError (#254)
* bellman: add VerificationError

This adds a distinct VerificationError type to the crate and changes
`verify_proof` to return `Result<(), VerificationError>` rather than
`Result<bool, SynthesisError>`.  This is significantly safer, because it avoids
the need to mix pattern-matching logic with boolean logic (the cause of
RUSTSEC-2019-0004).

* Rename VerificationError variants per review comments.

* Add missing Clone impl to VerificationError.
2020-08-05 22:26:31 +12:00
Jack Grigg ad96a38750 group: Make Wnaf generic over Group
Wnaf was originally generic over CurveProjective; in the prior refactor
commit, we renamed this to CofactorCurve. But w-NAF only requires scalar
multiplication, which is provided by the Group trait, so we relax the
bounds on Wnaf to enable it to be used with any group. We move the
generic w-NAF helper methods from the Curve trait to a new WnafGroup
extension trait, to keep the w-NAF API surface self-contained, and not
expose it to users who aren't using it.
2020-06-17 11:42:11 +12:00
Jack Grigg a105ad675a group: Separate prime and cofactor traits into modules
Instead of having the Group crate hold a Subgroup associated type (and
thus needing to define the subgroup of a prime-order group as itself),
we specify two separate sets of traits for prime-order groups and ones
with a cofactor.

Protocol implementors can either restrict their implementations to only
work with PrimeGroup, or can explicitly choose to support CofactorGroup
and then explicitly handle the subgroup edge cases with e.g.
CofactorGroup::mul_by_cofactor (which would be a no-op for PrimeGroup).

Protocol implementors can also choose to specialise to elliptic curves
if they want to leverage an affine representation and mixed addition in
their protocol for efficiency, or they can ignore those traits and stick
with the simpler group-focused traits.
2020-06-17 11:42:10 +12:00
Jack Grigg d52053d877 group: Renaming prior to trait refactor
This will reduce the size of the subsequent refactor diff.
2020-06-17 11:40:00 +12:00
Jack Grigg df13cd7480 group: Remove "compressed" notion from GroupEncoding
A generic group has a single encoding; for elliptic curves, this
happens to be the compressed encoding.
2020-06-17 11:35:17 +12:00
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
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
Jack Grigg 4edff96321 Fix various lints 2020-05-22 18:52:35 +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
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 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
Jack Grigg c597db59a6 ff: Rename PrimeField::into_repr -> PrimeField::to_repr 2020-05-02 18:55:13 +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
Jack Grigg fb31d09218 ff: Remove Ord bound from PrimeField
ff_derive still implements Ord and PartialOrd for the fields it
implements, because pairing::bls12_381 internally assumes that those are
implemented. Once we delete that implementation, we will remove the Ord
and PartialOrd implementations from ff_derive.
2020-05-02 18:54:02 +12:00