Skip to content

Commit

Permalink
chore: clippy
Browse files Browse the repository at this point in the history
chore: lint
  • Loading branch information
chancehudson committed Jan 16, 2025
1 parent a3ee267 commit 1b6934b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 26 deletions.
2 changes: 1 addition & 1 deletion mopro-ffi/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::path::PathBuf;
use std::fs;
use std::path::PathBuf;

fn main() {
#[cfg(feature = "circom")]
Expand Down
22 changes: 6 additions & 16 deletions mopro-ffi/src/circom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,18 +166,12 @@ pub fn generate_circom_proof_rapidsnark(
}

#[cfg(not(feature = "rapidsnark"))]
pub fn verify_circom_proof_rapidsnark(
zkey_path: String,
proof: String,
) -> Result<bool> {
pub fn verify_circom_proof_rapidsnark(zkey_path: String, proof: String) -> Result<bool> {
anyhow::bail!("rapidsnark feature not enabled")
}

#[cfg(feature = "rapidsnark")]
pub fn verify_circom_proof_rapidsnark(
zkey_path: String,
proof: String,
) -> Result<bool> {
pub fn verify_circom_proof_rapidsnark(zkey_path: String, proof: String) -> Result<bool> {
rapidsnark::verify_proof(&zkey_path, proof)
}

Expand Down Expand Up @@ -323,9 +317,7 @@ mod tests {

#[cfg(feature = "rapidsnark")]
use crate::circom::rapidsnark;
use crate::circom::{
generate_circom_proof_wtns, serialization, verify_circom_proof, WtnsFn,
};
use crate::circom::{generate_circom_proof_wtns, serialization, verify_circom_proof, WtnsFn};
use crate::GenerateProofResult;
use anyhow::bail;
use anyhow::Result;
Expand Down Expand Up @@ -439,12 +431,11 @@ mod tests {
)
.unwrap();
let b = BigInt::from(1u8);
let c = a.clone() * b.clone();
// let c = a.clone() * b.clone();
inputs.insert("a".to_string(), vec![a.to_string()]);
inputs.insert("b".to_string(), vec![b.to_string()]);

let proof_json =
rapidsnark::generate_proof(&zkey_path, inputs, multiplier2_witness)?;
let proof_json = rapidsnark::generate_proof(&zkey_path, inputs, multiplier2_witness)?;
let valid = rapidsnark::verify_proof(&zkey_path, proof_json)?;
if !valid {
bail!("Proof is invalid");
Expand All @@ -466,8 +457,7 @@ mod tests {
let inputs = bytes_to_circuit_inputs(&input_vec);

// Generate Proof
let proof_json =
rapidsnark::generate_proof(&zkey_path, inputs, keccak256256test_witness)?;
let proof_json = rapidsnark::generate_proof(&zkey_path, inputs, keccak256256test_witness)?;
let valid = rapidsnark::verify_proof(&zkey_path, proof_json)?;
if !valid {
bail!("Proof is invalid");
Expand Down
12 changes: 6 additions & 6 deletions mopro-ffi/src/circom/rapidsnark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@ extern "C" {
}

pub fn verify_proof(zkey_path: &str, proof: String) -> Result<bool> {

let mut header_reader = ZkeyHeaderReader::new(&zkey_path);
let mut header_reader = ZkeyHeaderReader::new(zkey_path);
header_reader.read();
let file = File::open(&zkey_path)?;
let file = File::open(zkey_path)?;
let mut reader = std::io::BufReader::new(file);
let proving_key = read_proving_key::<_, Bn254>(&mut reader)?;
// convert out proving key to json so we can
Expand Down Expand Up @@ -124,12 +123,11 @@ pub fn generate_proof(
let mut wtns = witness_fn(bigint_inputs)
.into_iter()
.map(|w| w.to_biguint().unwrap())
.map(|v| {
.flat_map(|v| {
let mut bytes = v.to_bytes_le();
bytes.resize(32, 0);
bytes
})
.flatten()
.collect::<Vec<_>>();

// Convert Rust strings to C strings
Expand All @@ -152,6 +150,8 @@ pub fn generate_proof(
.to_string_lossy()
.into_owned();
free_proof_result(proof_ptr);
Ok(format!("{{ \"proof\": {proof},\"signals\": {public_signals}}}"))
Ok(format!(
"{{ \"proof\": {proof},\"signals\": {public_signals}}}"
))
}
}
6 changes: 3 additions & 3 deletions mopro-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ mod halo2;

#[cfg(feature = "circom")]
pub use circom::{
generate_circom_proof_wtns, serialization::to_ethereum_inputs,
generate_circom_proof_rapidsnark, verify_circom_proof_rapidsnark,
serialization::to_ethereum_proof, verify_circom_proof, WtnsFn,
generate_circom_proof_rapidsnark, generate_circom_proof_wtns,
serialization::to_ethereum_inputs, serialization::to_ethereum_proof, verify_circom_proof,
verify_circom_proof_rapidsnark, WtnsFn,
};

#[cfg(feature = "halo2")]
Expand Down

0 comments on commit 1b6934b

Please sign in to comment.