Commit graph

465 commits

Author SHA1 Message Date
Andy Polyakov
ef39fba64c Simplify $name_affine.ct_eq().
By @ebfull's suggestion.
2022-04-18 19:04:03 +02:00
Andy Polyakov
3507ba6ffe Omit 'infinity' field from affine coordinates structure. 2022-04-13 22:23:23 +02:00
Andy Polyakov
872065c8a1 Add 'repr-c' feature to facilitate FFI. 2022-02-17 17:06:02 +01:00
Jack Grigg
53f65f7e6d Changelog and comment cleanups 2022-01-03 13:56:07 +00:00
str4d
738fb60796
Merge pull request #28 from zcash/27-remove-std-feature-flag
Remove `std` feature flag
2021-12-25 12:36:29 +00:00
str4d
c10960351d
Fix typo in code comment
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-12-25 12:20:18 +00:00
Jack Grigg
21fd9e2c1b Remove std feature flag
Closes zcash/pasta_curves#27.
2021-12-22 05:41:04 +00:00
Jack Grigg
69cf8f5f77 Remove CurveAffine::{read, write}
This removes the last dependency on `std::io`.
2021-12-22 05:22:56 +00:00
Jack Grigg
f874d29238 Remove FieldExt::rand
This removes a dependency on the `getrandom` crate in no-std mode, which
doesn't work on some no-std targets that `getrandom` doesn't support.
2021-12-22 05:15:06 +00:00
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
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
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
porcuquine
65a138cd77 Re-export group crate. 2021-09-02 13:19:32 -07:00
Jack Grigg
fd7a6edbb1 ff 0.11, group 0.11 2021-09-02 18:10:05 +01:00
Jack Grigg
43251286c0 Enable Pasta curve elements to be used with group::Wnaf 2021-08-06 01:23:27 +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
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
ccbfaf6a20 Remove large temprary stack allocations from SqrtTables::new 2021-04-28 14:21:45 +12: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
Daira Hopwood
a1194672c5 Update hash_to_field to correct a discrepancy with the Hashing to Elliptic Curves Internet Draft
pointed out in the NCC audit.

Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2021-03-27 14:39:39 +00:00
Jack Grigg
901ef2381e clippy: Allow binary operators in Mul impls for curves
We use binary operators specifically to implement constant-time scalar
multiplication.
2021-03-03 22:00:22 +00:00
Jack Grigg
a3921fd38c clippy: Allow too-many-arguments on F*::montgomery_reduce
We need to reduce from eight limbs to four, so we need eight arguments.
2021-03-03 22:00:22 +00:00
Jack Grigg
c13fc16ead clippy: Allow single-character names where necessary 2021-03-03 22:00:22 +00:00
Jack Grigg
b06937103d clippy: Use *Assign to implement arithmetic::Group trait 2021-03-03 22:00:22 +00:00
Jack Grigg
d40ed36d50 Move Pasta implementations into root 2021-03-03 21:59:08 +00:00
Jack Grigg
b36356667f Rename crate to pasta_curves and remove halo2 code 2021-03-03 21:59:08 +00:00
str4d
5e05845936
Remove unnecessary identity check from Group::random impl
Co-authored-by: ebfull <ewillbefull@gmail.com>
2021-03-03 11:11:13 +13:00
Jack Grigg
62e50ae6bd Fix Group::random implementation for Pallas and Vesta
Also removes the broken CurveAffine::from_bytes_wide and unused
CurveAffine::to_bytes_wide methods.
2021-03-02 21:29:59 +00:00
Jack Grigg
0a4db20d82 impl group::cofactor::CofactorGroup for Pallas and Vesta
Prime-order groups can be treated as a group with a cofactor of 1,
allowing them to be used in cofactor-aware protocols like RedDSA.
2021-03-01 20:27:34 +00:00
Sean Bowe
cb59a40ff8
Move PLONK integration tests into the tests subdirectory. 2021-02-26 08:22:19 -07:00
Sean Bowe
ef86a936ff
Remove print statements from tests. 2021-02-26 08:22:13 -07:00
Sean Bowe
d92b1c4fb9
Relocate computation of the degree of the constraint system to the ConstraintSystem struct. 2021-02-26 08:22:05 -07:00
Jack Grigg
e41fd7ca12 Move SHA-256 gadget and chip into examples 2021-02-25 20:01:44 +00:00
Jack Grigg
c64346467b Add Table16 circuit layout example 2021-02-25 20:01:44 +00:00
Jack Grigg
3fa36d7a60 Add test for circuit_dot_graph using SHA-256 2021-02-25 20:01:44 +00:00
therealyingtong
5f4a08898e SHA-256 benchmarks 2021-02-25 20:01:44 +00:00