From cd691577d6988e63d0d22ebc89aee3e741b6ee40 Mon Sep 17 00:00:00 2001 From: Thomas Chataigner Date: Fri, 12 Jan 2024 10:36:02 +0100 Subject: [PATCH] feat(keccak): deprecate generate_witness_from_wasm --- .cargo/config | 2 -- src/lib.rs | 19 +++++++++---------- src/reader.rs | 11 +++++------ 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/.cargo/config b/.cargo/config index 7d971cd..6d7d87a 100644 --- a/.cargo/config +++ b/.cargo/config @@ -26,6 +26,4 @@ xclippy = [ "-Wrust_2018_idioms", "-Wtrivial_numeric_casts", "-Wunused_qualifications", - "-Wclippy::unwrap_used", - "-Wclippy::expect_used" ] diff --git a/src/lib.rs b/src/lib.rs index 119126c..9ade2ab 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; @@ -84,11 +80,14 @@ pub mod witness; /// let witness_output = PathBuf::from("output.wtns"); /// let result = generate_witness_from_wasm::(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( witness_dir: PathBuf, witness_input_json: String, witness_output: impl AsRef, -) -> Result, WitnessError> { +) -> std::result::Result, 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"); diff --git a/src/reader.rs b/src/reader.rs index f568a22..6172c6b 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -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; @@ -74,7 +73,7 @@ pub struct R1CSFile { /// accordingly. pub(crate) fn load_witness_from_file( filename: impl AsRef, -) -> Result, ReaderError> { +) -> std::result::Result, ReaderError> { if filename.as_ref().ends_with("json") { load_witness_from_json_file::(filename) } else { @@ -88,7 +87,7 @@ pub(crate) fn load_witness_from_file( /// It leverages a [`BufReader`] for efficient reading and returns a vector of field elements. fn load_witness_from_bin_file( filename: impl AsRef, -) -> Result, ReaderError> { +) -> std::result::Result, ReaderError> { let path_string = filename.as_ref().to_str().ok_or(FilenameError)?.to_string(); let reader = OpenOptions::new() .read(true) @@ -112,7 +111,7 @@ fn load_witness_from_bin_file( /// parsing and conversion into field elements. fn load_witness_from_bin_reader( mut reader: R, -) -> Result, ReaderError> { +) -> std::result::Result, ReaderError> { let mut wtns_header = [0u8; 4]; reader .read_exact(&mut wtns_header) @@ -195,7 +194,7 @@ fn load_witness_from_bin_reader( /// for handling human-readable witness data, converting it into a vector of field elements. fn load_witness_from_json_file( filename: impl AsRef, -) -> Result, ReaderError> { +) -> std::result::Result, ReaderError> { let path_string = filename.as_ref().to_str().ok_or(FilenameError)?.to_string(); let reader = OpenOptions::new() .read(true)