Commit graph

504 commits

Author SHA1 Message Date
ea23c12d6a patch: index-based pow_vartime loops (Aeneas/Charon compatibility)
iter().rev() / (0..64).rev() double-ended range iterators have no Aeneas
model. Iteration order and arithmetic identical to upstream: limbs most- to
least-significant, bits high to low. Crate tests: 11/11 fp tests pass
(incl. test_inv, test_inv_2, test_pow_by_t_minus1_over2).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-02 16:53:27 +02:00
Alex Xiong
61310cb97d
Lazy Montgomery reduction via Product accumulator
Introduce `deferred::Product<F>`, a wide 576-bit accumulator (8 limbs
+ 64-bit carry) that replaces the eager `Accumulator = Fp/Fq` in the
DeferredField implementations.

Products are accumulated via an internal `accumulate` method (no
public Add/AddAssign impls), ensuring carry overflow requires 2^64
operations.  At reduction time, `partial_reduce` folds the carry and
top limb back into range using 2^512 ≡ R2 (mod p) and 2^448 ≡ B448
(mod p), producing a value < 2^449 < R*p that is safe for the
existing `montgomery_reduce`.

All existing DeferredField tests continue to pass unchanged—the lazy
accumulator is a drop-in replacement for the eager one.
2026-04-08 14:48:33 +08:00
Alex Xiong
ba38386100
Add tests for DeferredField trait
Test the accumulation-based API for both Fp and Fq: single
mul/square round-trips, inner products at various lengths (0–10,000),
reduce-zero identity, square-vs-mul consistency, mixed mul+square
accumulation, and a regression test with adversarial limb values that
exercise the partial-reduction path.

All tests are written against the DeferredField trait API and will
continue to pass when the eager accumulator is swapped for a lazy one.
2026-04-08 14:48:10 +08:00
Alex Xiong
c1ec4b7830
Introduce DeferredField trait with eager implementations
Add the `deferred` module with a `DeferredField` trait that enables
accumulating multiple unreduced products before performing a single
reduction.  The trait uses an accumulation-based API: callers feed
factor pairs into an `Accumulator` via `mul_accumulate` /
`square_accumulate`, then call `reduce` once at the end.

For now, both Fp and Fq implement the trait with `Accumulator = Self`,
performing eager reduction on each accumulation.  A later commit will
swap in a wide accumulator that defers reduction for real.

The module is feature-gated behind the `deferred` feature flag.
2026-04-08 14:47:20 +08:00
Alex Xiong
03d9e212b5
Extract mul_unreduced/square_unreduced from inline arithmetic
Pure refactor: the schoolbook multiplication and squaring bodies are
extracted into pub(crate) helper methods returning [u64; 8].  mul()
and square() now call through to these helpers followed by
montgomery_reduce(), preserving identical behaviour.

This separation makes the raw 512-bit product available for later
reuse (e.g. deferred reduction / inner-product accumulation) without
duplicating the arithmetic.
2026-04-08 14:45:31 +08:00
Jack Grigg
27f0d1ef1d Raise MSRV to 1.63 2025-04-16 19:19:42 +00:00
Daira Hopwood
0009d0b444 Fix an overflow bug in the square root implementation on 32-bit platforms.
Co-authored-by: Greg Pfeil <greg@electriccoin.co>
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2023-03-02 16:20:45 +00:00
str4d
85e2664209
Merge pull request #55 from zcash/fieldext-finale
Remove `FieldExt` and `Group` traits
2022-12-05 18:53:55 +00:00
Volker Mische
67e5595702 Improve 64-bit to 32-bit limb conversion
The code base is now on Rust 1.56 and Rust edition 2021. As per
https://github.com/zcash/pasta_curves/pull/31#discussion_r824826344
the code can now be simplified. This commit is also adding a test
for the u64_to_u32 function.
2022-11-25 11:17:37 +01:00
Jack Grigg
825cb944de Remove FieldExt trait
One, two! One, two! And through and through
    The vorpal blade went snicker-snack!
He left it dead, and with its head
    He went galumphing back.

Closes zcash/pasta_curves#42.
2022-11-25 05:05:54 +00:00
Jack Grigg
56b73e32ce Move Ord bound from FieldExt to CurveAffine::{Base, Scalar}
This helps with the `FieldExt` removal while deferring the decision on
whether to add an `Ord` bound to `ff::PrimeField`.
2022-11-25 05:05:54 +00:00
Jack Grigg
9862b247d2 Migrate remaining FieldExt constants and methods into ff 2022-11-25 05:05:54 +00:00
Jack Grigg
bedaa0055c Remove unnecessary FieldExt bounds in crate::hashtocurve 2022-11-24 20:48:23 +00:00
Jack Grigg
fbce21598d Remove crate::arithmetic::Group trait
It was only present to enable an FFT implementation in `halo2_proofs`
that is generic over fields and groups, but we can replace it with an
equivalent trait in `halo2_proofs` that can have a blanket impl.
2022-11-24 20:48:23 +00:00
Jack Grigg
4c86de5e10 Remove FieldExt bound from SqrtHasher generic argument 2022-11-24 11:37:41 +00:00
Jack Grigg
0559163953 Remove unused bounds and methods from FieldExt 2022-11-24 11:37:41 +00:00
str4d
1bd803d57b
Merge pull request #53 from lurk-lang/serde-ep-eq
Implement serde for Ep, Eq
2022-11-23 08:57:08 +00:00
Samuel Burnham
5e7d16b811 Implement serde for Ep, Eq 2022-11-20 14:17:08 -05:00
Jack Grigg
1c21a8944c Migrate to ff revision with trait constants 2022-11-19 12:16:10 +00:00
Jack Grigg
6921efd8fd Migrate to ff revision with square root backports 2022-11-19 12:03:54 +00:00
str4d
f8ba48de4e
Merge pull request #48 from filecoin-project/impl-serde
Implement Serde for fields and curves
2022-11-19 12:02:52 +00:00
str4d
191c416a76
Merge pull request #45 from filecoin-project/ec-gpu-020
Update to ec-gpu 0.2 release
2022-11-19 11:58:45 +00:00
Volker Mische
025362ad5a Address code review 2022-10-17 10:18:09 +02:00
Volker Mische
52902e6fdf Implement Serde for fields and curves
Currently Serde is only implemented for `Fp`, `Fq`, `EpAffine` and `EqAffine`.
Support can be enabled with the `serde` feature.
2022-10-14 15:32:57 +02:00
Tomas Krnak
b889295e31 fixup! Add uninline-portable feature 2022-10-13 11:07:19 +02:00
Tomas Krnak
52af8293a8 fixup! Add uninline-portable feature 2022-10-13 10:54:30 +02:00
Volker Mische
fb04f7ad99 Update to ec-gpu 0.2 release
The traits of ec-gpu changed a bit, there's now also a `GpuName`
trait that needs to be implemented.

BREAKING CHANGE: `ec-gpu` v0.2 traits are not compatible with v0.1

All dependencies that use `ec-gpu` need to be on v0.2.
2022-09-07 15:44:48 +02:00
Tomas Krnak
378f5cfd08 Add uninline-portable feature 2022-08-17 17:39:04 +02:00
Jack Grigg
0b8ed00c84 Migrate to Rust 2021 2022-05-04 23:22:15 +00:00
Jack Grigg
3329b4de85 Migrate to ff 0.12, group 0.12
MSRV is now 1.56.0.
2022-05-04 23:22:15 +00:00
ebfull
a80ed3e8aa
Merge pull request #30 from dot-asm/repr-c
Add 'repr-c' feature to facilitate FFI.
2022-04-19 08:04:29 -06:00
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
str4d
2796b6b65e
Merge pull request #31 from vmx/ec-gpu
Implement ec_gpu:GpuField for Fp/Fq
2022-03-24 17:08:37 +00:00
Volker Mische
678cd40419 chore: fix source formatting 2022-03-15 16:25:18 +01:00
David Nevado
8b101d67c4
Add Coordinates constructor 2022-03-12 15:46:43 +01:00
David Nevado
8a3643682f
Change Coordinates attrs back to pub(crate) 2022-03-12 15:44:46 +01:00
Volker Mische
b1f03fbc9c Document helper function 2022-03-11 17:47:17 +01:00
Volker Mische
cc51340dc5
fix: less allocations
Co-authored-by: str4d <thestr4d@gmail.com>
2022-03-11 17:37:47 +01:00
David Nevado
8042906484
Change Coordinates fields to pub 2022-03-07 11:19:15 +01:00
Volker Mische
870939ab03 Implement ec_gpu:GpuField for Fp/Fq
This commit introduces a new feature called "gpu", which enables an
`ec_gpu:GpuField` implementation of `Fp` and `Fq`. This enables the
field arithmetics to be run on a GPU.

The code to convert from a u64 to a u32 vector was taken from
07a84f9727/src/lib.rs (L102-L108)
2022-03-02 14:44:11 +01: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