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

fix clippy issues #1373

Closed
wants to merge 2 commits into from
Closed
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
168 changes: 90 additions & 78 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion zokrates_ark/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl<'a, T: Field + ArkFieldExtensions, I: IntoIterator<Item = Statement<'a, T>>
match cs {
ConstraintSystemRef::CS(rc) => {
let mut cs = rc.borrow_mut();
symbols.extend(self.program.arguments.iter().enumerate().map(|(_, p)| {
symbols.extend(self.program.arguments.iter().map(|p| {
let wire = match p.private {
true => cs.new_witness_variable(|| {
Ok(witness
Expand Down
3 changes: 1 addition & 2 deletions zokrates_ast/src/common/embed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,8 +582,7 @@ pub fn unpack_to_bitwidth<'ast, T: Field>(
#[allow(clippy::needless_collect)]
let outputs: Vec<_> = directive_outputs
.iter()
.enumerate()
.map(|(_, o)| FlatExpression::identifier(*o))
.map(|o| FlatExpression::identifier(*o))
.collect();

// o253, o252, ... o{253 - (bit_width - 1)} are bits
Expand Down
2 changes: 1 addition & 1 deletion zokrates_ast/src/common/position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ impl LocalSourceSpan {

impl Position {
pub fn col(&self, delta: isize) -> Position {
assert!(self.col <= isize::max_value() as usize);
assert!(self.col <= isize::MAX as usize);
assert!(self.col as isize >= delta);
Position {
line: self.line,
Expand Down
2 changes: 1 addition & 1 deletion zokrates_core/src/optimizer/redefinition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ impl<'ast, T: Field> Folder<'ast, T> for RedefinitionOptimizer<T> {
match lc
.value
.iter()
.any(|(variable, _)| self.substitution.get(variable).is_some())
.any(|(variable, _)| self.substitution.contains_key(variable))
{
true =>
// for each summand, check if it is equal to a linear term in our substitution, otherwise keep it as is
Expand Down
5 changes: 3 additions & 2 deletions zokrates_js/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ crate-type = ["cdylib"]
js-sys = "=0.3.58"
serde = { version = "^1.0.59", features = ["derive"] }
serde_json = { version = "1.0", features = ["preserve_order"] }
wasm-bindgen = { version = "=0.2.81", features = ["serde-serialize"] }
wasm-bindgen = { version = "=0.2.92", features = ["serde-serialize"] }
serde-wasm-bindgen = { version = "0.6"}
typed-arena = "1.4.1"
lazy_static = "1.4.0"
zokrates_field = { path = "../zokrates_field" }
Expand All @@ -37,4 +38,4 @@ zokrates_bellman = { path = "../zokrates_bellman", features = ["wasm"] }
[build-dependencies]
json = "0.12.4"
walkdir = "2.3.2"
toml = "0.5.9"
toml = "0.5.9"
41 changes: 20 additions & 21 deletions zokrates_js/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::util::normalize_path;
use rand_0_8::{rngs::StdRng, SeedableRng};
use serde::{Deserialize, Serialize};
use serde_json::to_string_pretty;
use serde_wasm_bindgen::{from_value, to_value};
use std::convert::TryFrom;
use std::io::{Cursor, Write};
use std::path::{Component, PathBuf};
Expand Down Expand Up @@ -57,7 +58,7 @@ impl CompilationResult {
}

pub fn abi(&self) -> JsValue {
JsValue::from_serde(&self.abi).unwrap()
to_value(&self.abi).unwrap()
}

pub fn snarkjs_program(&self) -> Option<js_sys::Uint8Array> {
Expand All @@ -69,7 +70,7 @@ impl CompilationResult {
}

pub fn constraint_count(&self) -> JsValue {
JsValue::from_serde(&self.constraint_count).unwrap()
to_value(&self.constraint_count).unwrap()
}
}

Expand Down Expand Up @@ -189,7 +190,7 @@ impl<'a> Resolver<Error> for JsResolver<'a> {
)));
}

let result: serde_json::Value = value.into_serde().unwrap();
let result: serde_json::Value = from_value(value).unwrap();
let source = result
.get("source")
.ok_or_else(|| Error::new("missing field `source`"))?
Expand Down Expand Up @@ -258,7 +259,7 @@ mod internal {
config: JsValue,
) -> Result<CompilationResult, JsValue> {
let resolver = JsResolver::new(resolve_callback);
let config: serde_json::Value = config.into_serde().unwrap();
let config: serde_json::Value = from_value(config).unwrap();
let with_snarkjs_program = config
.get("snarkjs")
.map(|v| *v == serde_json::Value::Bool(true))
Expand Down Expand Up @@ -308,14 +309,14 @@ mod internal {
) -> Result<ComputationResult, JsValue> {
let input = args.as_string().unwrap();

let config: serde_json::Value = config.into_serde().unwrap();
let config: serde_json::Value = from_value(config).unwrap();
let with_snarkjs_witness = config
.get("snarkjs")
.map(|v| *v == serde_json::Value::Bool(true))
.unwrap_or(false);

let (inputs, signature) = if abi.is_object() {
let abi: Abi = abi.into_serde().map_err(|err| {
let abi: Abi = from_value(abi).map_err(|err| {
JsValue::from_str(&format!("Could not deserialize `abi`: {}", err))
})?;

Expand Down Expand Up @@ -389,7 +390,7 @@ mod internal {
let keypair = B::setup(program, rng);
let tagged_keypair = TaggedKeypair::<T, S>::new(keypair);
Keypair {
vk: JsValue::from_serde(&tagged_keypair.vk).unwrap(),
vk: to_value(&tagged_keypair.vk).unwrap(),
pk: tagged_keypair.pk,
}
}
Expand All @@ -407,7 +408,7 @@ mod internal {
let keypair = B::setup(srs.to_vec(), program).map_err(|e| JsValue::from_str(&e))?;
let tagged_keypair = TaggedKeypair::<T, S>::new(keypair);
Ok(Keypair {
vk: JsValue::from_serde(&tagged_keypair.vk).unwrap(),
vk: to_value(&tagged_keypair.vk).unwrap(),
pk: tagged_keypair.pk,
})
}
Expand All @@ -434,7 +435,7 @@ mod internal {
.map_err(|err| JsValue::from_str(&format!("Could not read witness: {}", err)))?;

let proof = B::generate_proof(prog, ir_witness, pk, rng);
Ok(JsValue::from_serde(&TaggedProof::<T, S>::new(proof.proof, proof.inputs)).unwrap())
Ok(to_value(&TaggedProof::<T, S>::new(proof.proof, proof.inputs)).unwrap())
}

pub fn verify<T: Field, S: Scheme<T>, B: Backend<T, S>>(
Expand All @@ -447,7 +448,7 @@ mod internal {
serde_json::from_value(proof).map_err(|e| JsValue::from_str(&e.to_string()))?;

let result = B::verify(vk, proof);
Ok(JsValue::from_serde(&result).unwrap())
Ok(to_value(&result).unwrap())
}

pub fn format_proof<T: SolidityCompatibleField, S: SolidityCompatibleScheme<T>>(
Expand All @@ -474,7 +475,7 @@ mod internal {
json!([proof_vec])
};

Ok(JsValue::from_serde(&result).unwrap())
Ok(to_value(&result).unwrap())
}

pub fn export_solidity_verifier<T: SolidityCompatibleField, S: SolidityCompatibleScheme<T>>(
Expand Down Expand Up @@ -544,9 +545,7 @@ pub fn compute_witness(

#[wasm_bindgen]
pub fn export_solidity_verifier(vk: JsValue) -> Result<JsValue, JsValue> {
let vk: serde_json::Value = vk
.into_serde()
.map_err(|e| JsValue::from_str(&e.to_string()))?;
let vk: serde_json::Value = from_value(vk).map_err(|e| JsValue::from_str(&e.to_string()))?;

let curve = CurveParameter::try_from(
vk["curve"]
Expand Down Expand Up @@ -577,7 +576,7 @@ pub fn export_solidity_verifier(vk: JsValue) -> Result<JsValue, JsValue> {

#[wasm_bindgen]
pub fn setup(program: &[u8], entropy: JsValue, options: JsValue) -> Result<Keypair, JsValue> {
let options: serde_json::Value = options.into_serde().unwrap();
let options: serde_json::Value = from_value(options).unwrap();

let backend = BackendParameter::try_from(
options["backend"]
Expand Down Expand Up @@ -649,7 +648,7 @@ pub fn setup(program: &[u8], entropy: JsValue, options: JsValue) -> Result<Keypa

#[wasm_bindgen]
pub fn setup_with_srs(srs: &[u8], program: &[u8], options: JsValue) -> Result<Keypair, JsValue> {
let options: serde_json::Value = options.into_serde().unwrap();
let options: serde_json::Value = from_value(options).unwrap();

let scheme = SchemeParameter::try_from(
options["scheme"]
Expand Down Expand Up @@ -725,7 +724,7 @@ pub fn generate_proof(
entropy: JsValue,
options: JsValue,
) -> Result<JsValue, JsValue> {
let options: serde_json::Value = options.into_serde().unwrap();
let options: serde_json::Value = from_value(options).unwrap();

let backend = BackendParameter::try_from(
options["backend"]
Expand Down Expand Up @@ -812,16 +811,16 @@ pub fn generate_proof(

#[wasm_bindgen]
pub fn verify(vk: JsValue, proof: JsValue, options: JsValue) -> Result<JsValue, JsValue> {
let options: serde_json::Value = options.into_serde().unwrap();
let options: serde_json::Value = from_value(options).unwrap();
let backend = BackendParameter::try_from(
options["backend"]
.as_str()
.ok_or_else(|| JsValue::from_str("Invalid options: missing field `backend`"))?,
)
.map_err(|e| JsValue::from_str(&e))?;

let vk: serde_json::Value = vk.into_serde().unwrap();
let proof: serde_json::Value = proof.into_serde().unwrap();
let vk: serde_json::Value = from_value(vk).unwrap();
let proof: serde_json::Value = from_value(proof).unwrap();
let vk_curve = CurveParameter::try_from(
vk["curve"]
.as_str()
Expand Down Expand Up @@ -899,7 +898,7 @@ pub fn verify(vk: JsValue, proof: JsValue, options: JsValue) -> Result<JsValue,

#[wasm_bindgen]
pub fn format_proof(proof: JsValue) -> Result<JsValue, JsValue> {
let proof: serde_json::Value = proof.into_serde().unwrap();
let proof: serde_json::Value = from_value(proof).unwrap();

let curve = CurveParameter::try_from(
proof["curve"]
Expand Down
29 changes: 16 additions & 13 deletions zokrates_proof_systems/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use zokrates_ast::ir;

use rand_0_8::{CryptoRng, RngCore};
use serde::{Deserialize, Serialize};
use std::fmt::Display;
use std::io::{Read, Write};

use zokrates_field::Field;
Expand Down Expand Up @@ -55,11 +56,11 @@ pub enum G2Affine {
Fq(G2AffineFq),
}

impl ToString for G2Affine {
fn to_string(&self) -> String {
impl Display for G2Affine {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
G2Affine::Fq(e) => e.to_string(),
G2Affine::Fq2(e) => e.to_string(),
G2Affine::Fq(e) => e.fmt(f),
G2Affine::Fq2(e) => e.fmt(f),
}
}
}
Expand All @@ -72,20 +73,22 @@ pub struct G2AffineFq2(pub Fq2, pub Fq2);
#[derive(Serialize, Deserialize, Clone)]
pub struct G2AffineFq(pub Fq, pub Fq);

impl ToString for G1Affine {
fn to_string(&self) -> String {
format!("{}, {}", self.0, self.1)
impl Display for G1Affine {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}, {}", self.0, self.1)
}
}

impl ToString for G2AffineFq {
fn to_string(&self) -> String {
format!("{}, {}", self.0, self.1)
impl Display for G2AffineFq {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}, {}", self.0, self.1)
}
}
impl ToString for G2AffineFq2 {
fn to_string(&self) -> String {
format!(

impl Display for G2AffineFq2 {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"[{}, {}], [{}, {}]",
(self.0).0,
(self.0).1,
Expand Down