Skip to content

Commit

Permalink
feat(keccak): deprecate generate_witness_from_wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
tchataigner committed Jan 15, 2024
1 parent 637b97b commit cd69157
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
2 changes: 0 additions & 2 deletions .cargo/config
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,4 @@ xclippy = [
"-Wrust_2018_idioms",
"-Wtrivial_numeric_casts",
"-Wunused_qualifications",
"-Wclippy::unwrap_used",
"-Wclippy::expect_used"
]
19 changes: 9 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,21 @@
//! Credits to the [Circom language](https://github.com/iden3/circom) team, [Nova-Scotia](https://github.com/nalinbhardwaj/Nova-Scotia),
//! and [ark-circom](https://github.com/gakonst/ark-circom) for their foundational work that this library builds upon.

use std::{
env::current_dir,
fs,
path::{Path, PathBuf},
process::Command,
};

use crate::error::WitnessError::{
self, FailedExecutionError, FileSystemError, LoadWitnessError, MutexError,
WitnessCalculationError,
};
use crate::r1cs::CircomInput;
use crate::reader::load_witness_from_file;
use anyhow::Result;
use bellpepper_core::{num::AllocatedNum, ConstraintSystem, LinearCombination, SynthesisError};
use ff::PrimeField;
use log::{error, info, warn};
use r1cs::{CircomConfig, R1CS};

use crate::reader::load_witness_from_file;
use std::env::current_dir;
use std::fs;
use std::path::{Path, PathBuf};
use std::process::Command;

pub mod error;
pub mod r1cs;
Expand Down Expand Up @@ -84,11 +80,14 @@ pub mod witness;
/// let witness_output = PathBuf::from("output.wtns");
/// let result = generate_witness_from_wasm::<Fr>(witness_dir, input_json, &witness_output);
/// ```
#[deprecated(
note = "generate_witness_from_wasm would use a node CLI to calculate witness. We now expect users to use calculate_witness directly."
)]
pub fn generate_witness_from_wasm<F: PrimeField>(
witness_dir: PathBuf,
witness_input_json: String,
witness_output: impl AsRef<Path>,
) -> Result<Vec<F>, WitnessError> {
) -> std::result::Result<Vec<F>, WitnessError> {
// Create the input.json file.
let root = current_dir().map_err(|err| FileSystemError { source: err.into() })?;
let witness_generator_input = root.join("circom_input.json");
Expand Down
11 changes: 5 additions & 6 deletions src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ use ff::PrimeField;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
use std::collections::HashMap;
use std::fs::File;
use std::fs::OpenOptions;
use std::fs::{File, OpenOptions};
use std::io::{BufReader, Read, Seek, SeekFrom};
use std::path::Path;

Expand Down Expand Up @@ -74,7 +73,7 @@ pub struct R1CSFile<F: PrimeField> {
/// accordingly.
pub(crate) fn load_witness_from_file<F: PrimeField>(
filename: impl AsRef<Path>,
) -> Result<Vec<F>, ReaderError> {
) -> std::result::Result<Vec<F>, ReaderError> {
if filename.as_ref().ends_with("json") {
load_witness_from_json_file::<F>(filename)
} else {
Expand All @@ -88,7 +87,7 @@ pub(crate) fn load_witness_from_file<F: PrimeField>(
/// It leverages a [`BufReader`] for efficient reading and returns a vector of field elements.
fn load_witness_from_bin_file<F: PrimeField>(
filename: impl AsRef<Path>,
) -> Result<Vec<F>, ReaderError> {
) -> std::result::Result<Vec<F>, ReaderError> {
let path_string = filename.as_ref().to_str().ok_or(FilenameError)?.to_string();
let reader = OpenOptions::new()
.read(true)
Expand All @@ -112,7 +111,7 @@ fn load_witness_from_bin_file<F: PrimeField>(
/// parsing and conversion into field elements.
fn load_witness_from_bin_reader<F: PrimeField, R: Read>(
mut reader: R,
) -> Result<Vec<F>, ReaderError> {
) -> std::result::Result<Vec<F>, ReaderError> {
let mut wtns_header = [0u8; 4];
reader
.read_exact(&mut wtns_header)
Expand Down Expand Up @@ -195,7 +194,7 @@ fn load_witness_from_bin_reader<F: PrimeField, R: Read>(
/// for handling human-readable witness data, converting it into a vector of field elements.
fn load_witness_from_json_file<F: PrimeField>(
filename: impl AsRef<Path>,
) -> Result<Vec<F>, ReaderError> {
) -> std::result::Result<Vec<F>, ReaderError> {
let path_string = filename.as_ref().to_str().ok_or(FilenameError)?.to_string();
let reader = OpenOptions::new()
.read(true)
Expand Down

0 comments on commit cd69157

Please sign in to comment.