arkworks-rs / snark

Interfaces for Relations and SNARKs for these relations
https://www.arkworks.rs
Apache License 2.0
769 stars 203 forks source link

provide a higher level API for CS finalization #333

Closed Pratyush closed 3 years ago

Pratyush commented 3 years ago

should we provide a single “finalize” method that takes in a rename OptimizationMode enum and then internally calls inline_lcs or outline_lcs? (This can be a separate PR)

Originally posted by @Pratyush in https://github.com/arkworks-rs/snark/issues/331#issuecomment-751516304

weikengchen commented 3 years ago

I think this is a better API since inlining and outlining is an internal matter. And also, although inlining and outlining apply to R1CS, likely not other systems.

And then, we can require that to_matrices can only be used on a constraint system that has been finalized.

ValarDragon commented 3 years ago

I think this is a better API as well. Perhaps the initial enum options should be

1) No-op
2) Minimize number of constraints
3) Minimize matrix density
Pratyush commented 3 years ago

1 can’t be an option, because we have to remove all symbolic LCs.

By the way, this option should be set when creating the constraint system; that way gadgets can access it during constraint generation time, so that we don’t need the feature flags like we have in the nonnative crate. @weikengchen

On Sun, Dec 27, 2020 at 6:08 PM Dev Ojha notifications@github.com wrote:

I think this is a better API as well. Perhaps the initial enum options should be

1) No-op 2) Minimize number of constraints 3) Minimize matrix density

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/arkworks-rs/snark/issues/333#issuecomment-751548811, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAYSJ6QXIFZ7GQTB7WXU52TSW7SCHANCNFSM4VLGKFYA .

weikengchen commented 3 years ago

Good point. It would be much better if the constraint system has this value, and can be queried from outside.

Now, nonnative has a feature flag "density-optimized", which will use extremely different parameters. The feature flag has to be passed layer by layer and has consistency, which is troublesome.

weikengchen commented 3 years ago

I think this issue is important. And we can aim for a PR soon.

It may have broad usages. For example, we may one day have two algorithms for SW curve addition, one with low density, one with few constraints, but they are drastically different.

It would be hard to make the right decision if the gadgets do not know what the optimization goal is.


I may put up a draft PR soon, which can be our starting point.