Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incomplete SW group operations may be worthwhile #14

Closed
weikengchen opened this issue Nov 13, 2020 · 17 comments
Closed

Incomplete SW group operations may be worthwhile #14

weikengchen opened this issue Nov 13, 2020 · 17 comments
Labels
T-feature Type: new features

Comments

@weikengchen
Copy link
Member

weikengchen commented Nov 13, 2020

This is to be left as a todo for the future.

There seems to be a big gap in constraints & density of complete vs incomplete group operations, as well as operations on affine vs projective.

Ideally, if permitted by completeness and soundness, incomplete + affine can lead to fewer constraints & lower density.

However, it seems to require certain efforts to investigate whether the soundness holds, and to what extent. And completeness would be a separate issue that the application needs to handle. Especially, the application needs to have some sort of "reject sampling" so that it can retry proving until it avoids the incompleteness barriers.

@weikengchen weikengchen changed the title Incomplete group operations may be worthwhile Incomplete SW group operations may be worthwhile Nov 13, 2020
@weikengchen
Copy link
Member Author

A potential fix for completeness during additions is probably this:

  • Assume we are adding multiple points.
  • The prover can instantiate any non-infinity point as the initial value. The prover is supposed to choose a random one.
  • The prover needs to subtract the same point as the end.

Since the initial value is random, it may be able to provide some sort of "reject sampling".

@Pratyush
Copy link
Member

This issue shows that maybe one can do this without exceptions inside the circuit: zcash/zcash#3924

So the idea would be to convert to affine form, check for exceptional cases in the scalar, perform scalar multiplications via the foregoing algorithm, and to then convert back to projective form.

@Pratyush
Copy link
Member

Pratyush commented Nov 13, 2020

@weikengchen weikengchen added T-feature Type: new features help wanted labels Nov 19, 2020
@weikengchen
Copy link
Member Author

For the record, based on a measurement, our current implementation has roughly 12 constraints and 71 non-zeros per addition.

@weikengchen
Copy link
Member Author

weikengchen commented Nov 20, 2020

The solution with without exceptions may have 11 constraints, as follows:

  • Convert each of the two points to their affine forms => getting x/z and y/z, 2 * 2 = 4 constraints. This check also rules out the infinity points.
  • Check the exceptional case; so, it requires that x1 does not equal x2, 1 constraint
  • The foregoing algorithm, 6 constraints

So the saving is not significant.

@weikengchen
Copy link
Member Author

If the projective form is unused, but we only use the affine form, then maybe we can have fewer constraints, I assume:

  • Check x1 does not equal x2 requires 1 constraint => this is because the addition formula will fail for doubling.
  • The foregoing algorithm, 6 constraints.

Given that the affine form is likely to behave very differently from the complete form, it seems better to have a separate trait for it (so, not CurveVar). Any idea on the traits and implementations?

@Pratyush
Copy link
Member

Pratyush commented Nov 20, 2020

The solution with without exceptions may have 11 constraints, as follows:

* Convert each of the two points to their affine forms => getting x/z and y/z, 2 * 2 = 4 constraints. This check also rules out the infinity points.

* Check the exceptional case; so, it requires that x1 does not equal x2, 1 constraint

* The foregoing algorithm, 6 constraints

So the saving is not significant.

I think the idea would be to use the exceptional-addition inside scalar multiplication, where it seems we can do an edge-case once check at the beginning.

So we would have a specialized scalar multiplication, while leaving addition and doubling as-is

@Pratyush
Copy link
Member

By the way, another option for some curves with a cofactor is to convert to an alternate form (eg: edwards), and to perform the scalar arithmetic there, and to then convert back to short weierstrass form.

@zhenfeizhang
Copy link

zhenfeizhang commented Dec 10, 2020

In particular these portions seem relevant: *

Is there an API to call scalar multiplications over an EdwardsVar as in the second link?
Or are the callers expected to do a double-then-add approach?

@weikengchen
Copy link
Member Author

@zhenfeizhang The current library implements group elements on Edward curves as ProjectiveCurve and AffineCurve, so they can use the corresponding interfaces: https://github.com/arkworks-rs/algebra/blob/master/ec/src/models/twisted_edwards_extended.rs

And the ProjectiveCurve interface has mul: https://github.com/arkworks-rs/algebra/blob/master/ec/src/lib.rs#L209, which can be used for scalar mult.

@Pratyush
Copy link
Member

Pratyush commented Dec 18, 2020

see also this paper which reduces the number of muls compared to [ELM02].

NVM, it's slower than [ELM02] because it assumes inversions are expensive. It's instead faster than [CJLM06], which is a followup to [ELM02].

@zhenfeizhang
Copy link

zhenfeizhang commented Dec 19, 2020

I guess there was some misunderstanding. I am wondering about group muls over Vars rather than ProjectiveCurve or AffineCurve. Is there an API for this? Or should the caller do it themselfs?

looking at the code here:
https://github.com/arkworks-rs/crypto-primitives/blob/ce5cc89011b394eb006987a24088947d5099d641/src/commitment/pedersen/constraints.rs#L77

it seems that there isn't an API -- the caller needs to decomposite the scalars and then do the scalar mul.
Is this a fair understanding?

@weikengchen
Copy link
Member Author

@zhenfeizhang
Copy link

LOL. This is likely a private repo :-) I don't have access

@weikengchen
Copy link
Member Author

Sorry, wrong link. This one:

fn scalar_mul_le<'a>(

@zhenfeizhang
Copy link

Yes. Thanks!

@Pratyush
Copy link
Member

Pratyush commented Feb 4, 2021

So, this is implemented now, but without the optimizations from zcash/zcash#3924

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-feature Type: new features
Projects
None yet
Development

No branches or pull requests

3 participants