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

Arkworks adapter for Groth16 Backend #701

Merged
merged 35 commits into from
Jan 5, 2024

Conversation

irfanbozkurt
Copy link
Contributor

@irfanbozkurt irfanbozkurt commented Nov 28, 2023

  • Adds an adapter converting arkworks circuits (bls12-381) to lambdaworks QAP.
  • Adds tests that proves arkworks circuits using lambdaworks groth16 backend
  • Solves a small bug in QAP implementation (number of gates function)

@codecov-commenter
Copy link

codecov-commenter commented Nov 28, 2023

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (86c7efa) 95.41% compared to head (7c981ba) 95.44%.

Files Patch % Lines
provers/groth16/src/r1cs.rs 88.46% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #701      +/-   ##
==========================================
+ Coverage   95.41%   95.44%   +0.02%     
==========================================
  Files         137      139       +2     
  Lines       31164    31367     +203     
==========================================
+ Hits        29735    29938     +203     
  Misses       1429     1429              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@irfanbozkurt irfanbozkurt changed the title Groth16 import r1cs from LRO csv Arkworks adapter for Groth16 Backend Dec 4, 2023
@irfanbozkurt irfanbozkurt marked this pull request as ready for review December 4, 2023 22:23
@irfanbozkurt irfanbozkurt requested review from schouhy, ajgara and a team as code owners December 4, 2023 22:23
diegokingston
diegokingston previously approved these changes Dec 11, 2023
@MauroToscano
Copy link
Collaborator

You have conflicts, but it can be merged

MauroToscano
MauroToscano previously approved these changes Jan 3, 2024
diegokingston
diegokingston previously approved these changes Jan 3, 2024
Copy link
Collaborator

@MauroToscano MauroToscano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A test with a failing case would be nice. This can be merged, but it needs a follow up

let borrowed_cs_ref = binding.deref();

let ark_witness = &borrowed_cs_ref.witness_assignment;
let ark_io = &borrowed_cs_ref.instance_assignment[1..].to_vec();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment why is it 1, so it's not a magical number

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was unnecessary. Removed.

Comment on lines 102 to 105
assert_eq!(num_of_total_inputs, r.len());
assert_eq!(num_of_total_inputs, o.len());
assert!(num_of_total_inputs > 0);
assert!(num_of_public_inputs <= num_of_total_inputs);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can panic, it should return an Error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is only for testing purposes. I moved the method to an utils.rs file within the tests.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that's the case you can add the conditional compile flag, the cfg tests. Or just move it to the test module

r,
o,
num_of_gates: next_power_of_two,
num_of_public_inputs: r1cs.number_of_inputs + 1, // Compansate for "1"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo, compansate. Also, it doesn't say why so it's not quite useful

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary 1. My mistake. Removed.

Comment on lines 11 to 18
pub fn to_lambda<F: PrimeField>(
cs: &ConstraintSystemRef<F>,
) -> (QuadraticArithmeticProgram, Vec<FrElement>) {
(
QuadraticArithmeticProgram::from_r1cs(r1cs_from_arkworks_cs(cs)),
extract_witness_from_arkworks_cs(cs),
)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ark_cs_to_lambda_cs would be a better that name

Also I'd document with /// what this is doing, the QAP is clear, but you need to check the code to realize the second parameter is the witness

diegokingston
diegokingston previously approved these changes Jan 4, 2024
MauroToscano
MauroToscano previously approved these changes Jan 5, 2024
Comment on lines 102 to 105
assert_eq!(num_of_total_inputs, r.len());
assert_eq!(num_of_total_inputs, o.len());
assert!(num_of_total_inputs > 0);
assert!(num_of_public_inputs <= num_of_total_inputs);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that's the case you can add the conditional compile flag, the cfg tests. Or just move it to the test module

@entropidelic entropidelic added this pull request to the merge queue Jan 5, 2024
Merged via the queue into lambdaclass:main with commit 5f3ffd2 Jan 5, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants