Update the FCircuit trait, so that it supports custom data structures for the external inputs. #191
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Update the FCircuit trait, so that it supports custom data structures for the external inputs.
This also eliminates the need of having the
external_inputs_len
method in theFCircuit
.The motivation for this change is that in most practical use cases, the external inputs have a not-naive structure, and the old interface required that to convert the external inputs structure into a vector of finite field elements, which inside the FCircuit would be converted back into a custom data structure. This is specially tedious when dealing with curve points, which converting them from point to field elements and back to the point (both outside (rust native) and inside the circuit (constraints)) is a bit cumbersome. With this update, it's much more straight forward to define the FCircuit with custom external inputs data structures.
For the experimental-frontends, the external inputs keep being an array of field elements.
Context/motivation
When doing more 'real world' use cases, it is convenient to don't have the limitation to just arrays of field elements for the external inputs on the FCircuit. For example, when dealing with elliptic curve points, it required to convert the points to affine to get their coordinates as field elements, then concatenate the various field elements (coordinates) from various points to pass it as
Vec<FpVar<F>>
as theexternal_inputs
to the FCircuit, which then inside the FCircuit that vector gets decomposed back into separated coordinates to rebuild the elliptic curve points (which in order to do so, need to break some of the abstractions to be able to build the specific curve points).This grows in complexity as the data structures needed are more rich.
As an example, suppose we want to have as external inputs the following structure
ExtInpVar
:with this PR, in the
FCircuit
we just need to set the trait parameters:And then we can just directly use that type for the
external_inputs
:The same use case before this PR, would have required much more code, and furthermore it would have needed to remove some of the curve abstractions in order to be able to reconstruct the
GC
points from their coordinates inside theFCircuit
.Full use case example code available at: https://github.com/arnaucube/fold-babyjubjubs/blob/main/src/fcircuit.rs#L53