Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion circom-prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ rand = { version = "0.8", features = ["std"] }
witnesscalc-adapter = { version = "0.1", optional = true }

# circom-witnesscalc
circom-witnesscalc = { version = "0.2.1", optional = true }
circom-witnesscalc = { git = "https://github.com/iden3/circom-witnesscalc", branch = "main", optional = true }
once_cell = { version = "1.21.3", optional = true }

# rapidsnark
Expand Down
41 changes: 41 additions & 0 deletions circom-prover/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,27 @@ impl CircomProver {
prover::prove(proof_lib, zkey_path.clone(), wit_thread)
}

#[cfg(feature = "circom-witnesscalc")]
pub fn graph_prove(
proof_lib: ProofLib,
json_input_str: String,
graph_bytes: &[u8],
zkey_path: String,
) -> Result<CircomProof> {
use witnesscalc_adapter::parse_witness_to_bigints;

let witness_bytes =
circom_witnesscalc::calc_witness(json_input_str.as_str(), graph_bytes).unwrap();
let witness = parse_witness_to_bigints(&witness_bytes).unwrap();
let wit_thread = std::thread::spawn(move || {
witness
.into_iter()
.map(|w| w.to_biguint().unwrap())
.collect::<Vec<_>>()
});
prover::prove(proof_lib, zkey_path.clone(), wit_thread)
}

pub fn verify(proof_lib: ProofLib, proof: CircomProof, zkey_path: String) -> Result<bool> {
prover::verify(proof_lib, zkey_path, proof)
}
Expand Down Expand Up @@ -94,6 +115,26 @@ mod tests {
assert!(verify_proof(proof, ProofLib::Arkworks));
}

#[cfg(all(feature = "circom-witnesscalc", feature = "arkworks"))]
#[test]
fn test_circom_witnesscalc_arkworks_prove_and_verify_with_graph() {
const GRAPH_PATH: &str = "./test-vectors/multiplier2.bin";
let inputs = HashMap::from([
("a".to_string(), vec!["1".to_string()]),
("b".to_string(), vec!["2".to_string()]),
]);
let input_str = serde_json::to_string(&inputs).unwrap();
let graph_bytes = std::fs::read(GRAPH_PATH).unwrap();
let proof = CircomProver::graph_prove(
ProofLib::Arkworks,
input_str,
&graph_bytes,
ZKEY_PATH.to_string(),
)
.unwrap();
assert!(verify_proof(proof, ProofLib::Arkworks));
}

#[cfg(all(feature = "rustwitness", feature = "rapidsnark"))]
#[test]
fn test_rustwitness_rapidsnark_prove_and_verify() {
Expand Down
2 changes: 1 addition & 1 deletion circom-prover/src/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use witnesscalc_adapter::parse_witness_to_bigints;
type RustWitnessWtnsFn = fn(HashMap<String, Vec<BigInt>>) -> Vec<BigInt>;
/// Witness function signature for witnesscalc_adapter (inputs) -> witness
type WitnesscalcWtnsFn = fn(&str) -> anyhow::Result<Vec<u8>>;
/// Witness function signature for circom-witnesscalc (inputs, graph_path) -> witness
/// Witness function signature for circom-witnesscalc (inputs) -> witness
type CircomWitnessCalcWtnsFn = fn(&str) -> anyhow::Result<Vec<u8>>;

#[derive(Debug, Clone, Copy)]
Expand Down
Loading