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

circom interface with tests #7

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

arasuarun
Copy link
Contributor

A circom interace using the circom-scotia library.

There are different ways to go with how the structs are designed, so keeping this as a draft PR for now. Most of the code is in src/circom/mod.rs with theSpartanCircuit struct. It's a wrapper around an R1CS object with an optional witness vector.

The generate_keys and generate_proof functions are defined outside the struct as they require different generics <G: Group, S: RelaxedR1CSSNARKTrait<G>. Perhaps these could be combined into the struct itself. Not sure what the best way to go about this is.

The circom files for the circuit being tested are in the examples/cube folder. I could also move the tests to be an example in that folder.

src/circom/mod.rs Outdated Show resolved Hide resolved
src/circom/mod.rs Outdated Show resolved Hide resolved
src/circom/mod.rs Outdated Show resolved Hide resolved
@arasuarun
Copy link
Contributor Author

Added a simpler create_snark function that takes r1cs_path, wtns_path, input and directly returns the snark proof. Lemme know if it looks okay and I can remove the old.

let root = current_dir().unwrap().join("examples/cube");
let r1cs_path = root.join("cube.r1cs");
let wtns_path = root.join("cube.wasm");
let mut circuit = SpartanCircuit::new(r1cs_path);
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a simplification here. We can just pass r1cs_path to setup (which returns (pk,vk)) and the setup can internally create a SpartanCircuit object (this will hide the struct from the caller and reduces code that someone needs to write). Isn't it?

}

#[allow(dead_code)]
pub fn create_snark<G: Group, S: RelaxedR1CSSNARKTrait<G>>(
Copy link
Contributor

Choose a reason for hiding this comment

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

This method seems not that useful. In other words, we can just have two methods, one for setup and another for prove. The setup takes the r1cs file path and the prove takes the witness file path (in addition to pk).

@arasuarun arasuarun marked this pull request as ready for review October 16, 2023 17:26
@arasuarun
Copy link
Contributor Author

Changed the interface to avoid having the user use the struct SpartanCircuit. It still has to be pub because it's used in the definition of the SNARK proof returned.

Also, load_r1cs has to be called twice. There doesn't seem to be a quick way to fix that without modifying circom-scotia or exposing the SpartanCircuit struct to the user.

@huitseeker
Copy link

@arasuarun Please open an issue on https://github.com/lurk-lab/circom-scotia with the change you have in mind! We'd love feedback on our APIs.

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.

3 participants