Commit graph

715 commits

Author SHA1 Message Date
Jack Grigg
ab03c3d5e1 Remove field traits from behind std feature flag
Now that we have a default implementation of `SqrtRatio::sqrt_ratio`, we
can use it and `FieldExt` in no-std environments.

We introduce an `alloc` feature flag to form a common feature dependency
between `std` and `sqrt-table`. It is currently unused directly, but
will be used after `CurveAffine` is refactored to remove the `std`
dependency.

Closes zcash/pasta_curves#25.
2021-12-22 05:06:16 +00:00
Jack Grigg
314b1bcb94 Place SqrtTables behind a sqrt-tables feature flag
This enables the crate to be compiled without the tables, instead using
a simple fallback for `SqrtRatio::sqrt_ratio`.
2021-12-22 04:38:14 +00:00
Jack Grigg
96116e20e5 Annotate docs with required feature flags 2021-12-07 14:31:27 +00:00
str4d
c052756831
Merge pull request #20 from zcash/refactor
Refactor the crate APIs
2021-10-01 06:07:38 +13:00
Jack Grigg
a91e262235 Document that the generator in SqrtRatio::sqrt_ratio might change 2021-09-30 13:57:59 +01:00
Jack Grigg
32cc10db46 Move FieldExt::get_lower_32 to SqrtRatio trait
It is only used internally by the table-based square root impl, and we
should probably refactor this further, but for now it can live in the
sqrt extension trait.
2021-09-30 13:57:59 +01:00
Jack Grigg
3a6f71d2f0 Remove FieldExt::{from_bytes, read, to_bytes, write}
- `ff::PrimeField::{from_repr, to_repr}` are direct replacements for
  `FieldExt::{from_bytes, to_bytes}`.
- `FieldExt::{read, write}` were added for reading and writing `halo2`
  proofs, but `halo2::transcript` now handles this internally.
2021-09-23 14:45:02 +01:00
Jack Grigg
ad0360bc1c Remove FieldExt::from_u64 2021-09-23 14:45:02 +01:00
Jack Grigg
11c5ddbc02 Remove FieldExt::{RESCUE_ALPHA, RESCUE_INVALPHA} 2021-09-23 14:45:02 +01:00
Jack Grigg
e31787d462 Remove unnecessary bounds on CurveExt
They are already bounds on `group::Group`, which `CurveExt` inherits
via `group::prime::PrimeCurve`.
2021-09-23 14:45:02 +01:00
Jack Grigg
1b2f581ac1 Move square-root operations from FieldExt into a separate trait 2021-09-23 14:45:02 +01:00
Jack Grigg
0c58a40a98 Remove pasta_curves::arithmetic::Field 2021-09-23 14:44:10 +01:00
Jack Grigg
aeda766c34 Remove FieldExt::ROOT_OF_UNITY
We can use the `ff::PrimeField::root_of_unity` method everywhere we
currently use this associated constant. If there is a more general
need for accessing this as an associated constant, we should consider
that for `ff::PrimeField`.
2021-09-23 14:44:10 +01:00
str4d
275dad22ad
Merge pull request #4 from zcash/no-std
Support no-std builds
2021-09-24 01:39:25 +12:00
str4d
2b350118b0
Fix naming of Tonelli-Shanks
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-09-21 10:44:07 +12:00
Jack Grigg
9999964d17 Add no-std support
We re-introduce the Tonelli-Shank square root algoritm that was removed
in zcash/halo2#120, to use in no-std mode (the table-based impl requires
allocations, and also uses 29kiB of memory which is a problem for
constrained environments that typically need no-std).
2021-09-20 18:56:23 +01:00
Jack Grigg
8fabb44ad4 fields: Use ff::PrimeField instead of FieldExt where possible 2021-09-20 17:41:46 +01:00
Jack Grigg
6a47700b1d fields: Ensure that trait impl dependencies match trait bounds
The `FieldExt` trait was originally the only trait implemented in this
crate. When we added `ff` support, we reworked `FieldExt` to be an
extension trait on top of `ff::PrimeField`, but left the existing impls
in `FieldExt`. This resulted in some circular dependencies that prevent
us from making `FieldExt` conditional (e.g. for no-std support).

This commit removes the cycles like so:

- `ff::PrimeField::{from_repr, to_repr}` were implemented as calls to
  `FieldExt::{from_bytes, to_bytes}`. The field encoding/decoding logic
  is moved into the `ff::PrimeField` trait impl, and `FieldExt` now
  calls into `ff::PrimeField`.

- `ff::Field::sqrt` was implemented in terms of `FieldExt::sqrt_alt`.
  Given that the latter is a trivial wrapper around the `SqrtTables`
  implementation, we duplicate the call to eliminate the cycle.

- `ff::Field::random` used `FieldExt::from_bytes_wide`, which wraps
  either `Fp::from_u512` or `Fq::from_u512`. We now use these internal
  methods directly.
2021-09-20 17:41:46 +01:00
Jack Grigg
87488ec1f6 CI: Add no-std build check 2021-09-20 13:58:41 +01:00
str4d
adf66ae0d1
Merge pull request #19 from zcash/relicense-mit-apache
Relicense `pasta_curves` as MIT OR Apache-2.0
2021-09-18 03:43:40 +12:00
Jack Grigg
bb2564d586 pasta_curves 0.2.1 2021-09-17 16:37:00 +01:00
Jack Grigg
f747efc6ff Relicense pasta_curves as MIT OR Apache-2.0 2021-09-17 16:32:36 +01:00
str4d
5fb3037b9e
Merge pull request #18 from porcuquine/reexport-group
Re-export group crate.
2021-09-06 18:13:41 +01:00
porcuquine
65a138cd77 Re-export group crate. 2021-09-02 13:19:32 -07:00
ebfull
4f85fa5c7f
Merge pull request #17 from zcash/ff-0.11
ff 0.11, group 0.11
2021-09-02 11:45:18 -06:00
Jack Grigg
6a28a85d8b pasta_curves 0.2.0 2021-09-02 18:37:13 +01:00
Jack Grigg
fd7a6edbb1 ff 0.11, group 0.11 2021-09-02 18:10:05 +01:00
Daira Hopwood
bdb1c3797f
Merge pull request #16 from daira/point-bench
Add benchmarks for point operations
2021-08-11 19:01:16 +01:00
Daira Hopwood
329f59493c Add benchmarks for point operations.
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2021-08-11 15:09:34 +01:00
Jack Grigg
1bac885af5 Release 0.1.2 2021-08-06 13:29:03 +01:00
str4d
b786a0c488
Merge pull request #15 from zcash/wnaf-group
Enable Pasta curve elements to be used with `group::Wnaf`
2021-08-06 13:27:11 +01:00
Jack Grigg
43251286c0 Enable Pasta curve elements to be used with group::Wnaf 2021-08-06 01:23:27 +01:00
str4d
d8547d2326
Merge pull request #13 from zcash/cofactorcurve
impl CofactorCurve for Pallas and Vesta
2021-06-04 20:24:31 +01:00
Jack Grigg
15e16839b3 Release 0.1.1 2021-06-04 18:54:09 +01:00
Jack Grigg
a6b018fb0e impl CofactorCurve for Pallas and Vesta
They already implement CofactorGroup (trivially, with the prime-order
subgroup being Self); this just enables Pallas and Vesta to be used in
cofactor-aware protocols that also want to leverage the affine point
representation.
2021-06-04 00:54:39 +01:00
str4d
93df9c0cb9
Merge pull request #12 from zcash/release-0.1.0
Release 0.1.0
2021-06-01 23:48:15 +01:00
Jack Grigg
084d57ab10 Release 0.1.0 2021-06-01 23:40:45 +01:00
Jack Grigg
17b2e5275b Exclude contributor agreement from published crate
Can't contribute to hash-pinned binaries! This file is only needed in
the repo itself.
2021-06-01 23:38:30 +01:00
Jack Grigg
38db112596 Fix clippy lints 2021-06-01 23:34:22 +01:00
Jack Grigg
bc20c5826b Migrate to ff 0.10.0 2021-06-01 23:31:00 +01:00
Jack Grigg
45c57f9352 Bump MSRV to 1.51.0
Necessary for ff 0.10 etc.
2021-06-01 23:22:25 +01:00
Jack Grigg
7663200468 Fill in readme details 2021-06-01 23:19:14 +01:00
Jack Grigg
5d128a6c12 Add rust-toolchain file with MSRV 2021-06-01 23:09:07 +01:00
ebfull
0bd744356a
Merge pull request #11 from zcash/remove-large-stack-allocations
Remove large temporary stack allocations from SqrtTables::new
2021-04-28 16:12:00 -06:00
Jack Grigg
ccbfaf6a20 Remove large temprary stack allocations from SqrtTables::new 2021-04-28 14:21:45 +12:00
Steven
376ba4eeca
Merge pull request #9 from steven-ecc/change-tgppl-to-bosl
Adding BOSL and changing TGPPL references to BOSL
2021-04-26 16:43:21 -07:00
Steven
e6a7d68a3e
Update Cargo.toml
Co-authored-by: ebfull <ewillbefull@gmail.com>
2021-04-26 16:43:07 -07:00
str4d
03fe608296
Merge pull request #5 from dignifiedquire/benches-fp-fq
bench: add baseline benches for Fp and Fq
2021-04-24 01:20:50 +01:00
str4d
b55a6960df
Merge pull request #10 from zcash/curveaffine-coordinates
Replace `(x, y)` tuple with `Coordinates` struct
2021-04-19 22:27:22 +01:00
Jack Grigg
b016b972f8 Replace (x, y) tuple with Coordinates struct
The previous `CurveAffine::get_xy` method returned the coordinates as
`CtOption<(C::Base, C::Base)>`. However, `ConditionallySelectable` is
not implemented for any tuple or array types, making it impossible to
use any of the useful `CtOption` methods like `and_then`. We replace it
with `CurveAffine::coordinates -> CtOption<Coordinates<Self>>` and
`impl ConditionallySelectable for Coordinates` to enable operating over
coordinates in constant time.
2021-04-18 09:21:18 +12:00