-
Notifications
You must be signed in to change notification settings - Fork 125
Comments
The comment refers to endomorphism acceleration which allows splitting a scalar k into {k1, k2} and transform scalar multiplication [k]P into a double-scalar-multiplication [k1]P + [k2]λP with k1 and k2 using ~127 bits instead of 254 bits (in our case), so halving the number of total operations. λP is a point that can be quickly computed due to the curve properties, see https://github.com/mratsim/constantine/blob/151f284/sage/derive_endomorphisms.sage#L85-L94 The optimization I propose is a coordinate system change. It is complementary. |
If we want to upstream our changes, we probably need to either find an existing constant-time algorithm or derive one. I suspect it does not matter for a validity roll-up. I will mirror the variable-time approach for now. Footnotes
|
@mratsim I had a nice conversation with @AlekseiVambol today, where he raised the question whether the ExtendedJacobian coordinates approach is really worth it. I am not qualified to make the case, but the argument is twofold (1) using ExtendedJacobian coordinates implies using variable-time computations giving rise to side-channel attacks as described above and (2) the expected speed-up is very small due to the specific constants used on some/most of the halo curves where a=0 and b=3 or b=7. |
We don't have secrets to protect.
~70% of time is spent in MSMs when generating proofs. The speedup is 10% on a computation that takes few seconds to minutes. This can easily save thousands in AWS bills. Now, there are other optimizations with bigger impact than 10%, which is why I marked this one optional. But it's 10% vs normal jacobian coordinates, I expect a bigger speedup against constant-time projective coordinates. |
It seems that some variant of addition for (non-Extended) Jacobian Coordinates is already implemented for all the curves by means of the "new_curve_impl" macro. But it was in the previous version of Halo2: |
In that case there may be more optimizations opportunities since the |
Extended Jacobian would only be used in Multi-Scalar-Multiplication. And in MSMs, all points to accumulate come in affine coordinates hence the only operation that matters is mixed addition. Data is in this paper https://tches.iacr.org/index.php/TCHES/article/download/10972/10279, table 2 and 3, I have all 3 implemented (note that in my lib, projective AND jacobian are constant-time, projective uses the same formulas as Halo2): Reproduction (with Nim programming language installed):
There is a ~20% perf difference on mixed addition |
I agree. If all the input points are in the affine coordinates and in the Pippenger method the size of a chunk is approximately ln(N) + 2 (as it is said to be in the Arkworks implementation), then for large number of points (as in the case of Taiko's supercircuit) the mixed addition will happen more often then usual Extended Jacobian addition. Thus, the Extended Jacobian Coordinates are worthy of being introduced for MSM, but only for it. |
Existing MSM code in https://github.com/taikoxyz/halo2/blob/main/halo2_proofs/src/poly/ipa/msm.rs |
I'm not sure what the quoted code is used for but the MSM code is here: https://github.com/taikoxyz/halo2/blob/main/halo2_proofs/src/arithmetic.rs#L41-L198 |
To measure the performance impact, please follow these instructions:
|
This issue tracks the progress on https://github.com/privacy-scaling-explorations/halo2/issues/187
Original text
The code
The code belongs in the
halo2curves
crate, which we will need to fork (or upstream) and use as dependency forzkevm-circuits
when it is ready.Timeline
The
halo2curves
used use (non-extended) Jacobian coordinates until this PR where they were replaced with homogeneous coordinates a.k.a homogeneous projective coordinates.This issue is about adding Extended Jacobian Coordinates while keeping the homogeneous coordinates which are needed for FFT.
Publications:
The Extended Jacobian Coordinates are discussed in the paper Faster Montgomery multiplication and
Multi-Scalar-Multiplication for SNARKs.
Existing implementations:
The text was updated successfully, but these errors were encountered: