-
Notifications
You must be signed in to change notification settings - Fork 212
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
arithmetic-circuits
crate
#380
Open
Cesar199999
wants to merge
14
commits into
arkworks-rs:release-0.5.0
Choose a base branch
from
NP-Eng:cesar/arithmetic-circuits
base: release-0.5.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
arithmetic-circuits
crate
#380
Cesar199999
wants to merge
14
commits into
arkworks-rs:release-0.5.0
from
NP-Eng:cesar/arithmetic-circuits
Conversation
This file contains 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
Co-authored-by: Antonio Mejías Gil <[email protected]> Co-authored-by: Marcin <[email protected]>
Co-authored-by: Antonio Mejías Gil <[email protected]> Co-authored-by: Marcin <[email protected]>
Co-authored-by: Cesar Descalzo <[email protected]>
@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 |
Do you think this would be a better fit in ark-relations? Since r1cs (another satisfiability relation) lives in there? |
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 structuresArithmeticCircuit
andExpression
, as well as methods for compiling R1CS constraint systems (ark_relations::r1cs::ConstraintSystem
) into arithmetic circuits.An
ArithmeticCircuit
is 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 emptyArithmeticCircuit
struct 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 + y
can 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_circuit
method. 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
.r1cs
and.wasm
files into arithmetic circuits.Discussion NP-Eng/ligero#25