arithmetic-circuits module#380
Open
Cesar199999 wants to merge 16 commits into
Open
Conversation
Co-authored-by: Antonio Mejías Gil <anmegi.95@gmail.com> Co-authored-by: Marcin <marcin.gorny.94@protonmail.com>
Co-authored-by: Antonio Mejías Gil <anmegi.95@gmail.com> Co-authored-by: Marcin <marcin.gorny.94@protonmail.com>
Co-authored-by: Cesar Descalzo <Cesar199999@users.noreply.github.com>
Member
|
@Pratyush, as per the discussion in NP-Eng/ligero#25 (comment), this PR adds the arithmetic circuit functionality, ready for review when you get some cycles |
Member
|
Do you think this would be a better fit in ark-relations? Since r1cs (another satisfiability relation) lives in there? |
Author
|
@Pratyush Sure, that makes sense |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
This PR adds a new crate,
arithmetic-circuits, which contains the structuresArithmeticCircuitandExpression, as well as methods for compiling R1CS constraint systems (ark_relations::r1cs::ConstraintSystem) into arithmetic circuits.An
ArithmeticCircuitis a directed acyclic graph where nodes are either variables, constants, or gates for addition and multiplication over a prime fieldF. The circuit is internally represented as a list of nodes, each being a variant of the enumNode:Variable,Constant,Add, andMul. Gates have a left and right input, which are indices for the respective nodes in the array. In order to directly construct an arithmetic circuit, the user must instantiate an emptyArithmeticCircuitstruct and mutate it via its public methods (e.g.new_variable,add,mul), each of which returns the index of the new node in the array. For example, an arithmetic circuit expressing the computation2 * x + ycan be constructed as follows:Since the construction of an arithmetic circuit can be slightly verbose, the crate also provides the struct
Expression, which allows for a more user-friendly way to construct arithmetic circuits. Manually adding nodes to the circuit is not required: expressions can be combined using the usual arithmetic operators, and then converted to a circuit using theto_arithmetic_circuitmethod. For reference, the previous circuit can be expressed as follows:Note that the variables must be labelled uniquely.
Lastly, the crate provides methods for compiling R1CS constraint systems from circom generated
.r1csand.wasmfiles into arithmetic circuits.Discussion NP-Eng/ligero#25