Skip to content

Commit

Permalink
chore: fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
junyu0312 committed Jun 26, 2024
1 parent 96a4aac commit 620858d
Show file tree
Hide file tree
Showing 89 changed files with 527 additions and 618 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
components: rustfmt, clippy
- name: Code Style Check
run: cargo fmt --check
- name: Cargo clippy
run: cargo clippy && cargo clippy --features continuation
- name: Build
run: cargo build && cargo clean
- name: Build Playground
Expand Down
64 changes: 32 additions & 32 deletions crates/cli/src/app_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,65 +215,65 @@ pub(crate) fn app() -> App<'static> {
.subcommand_required(true)
}

impl Into<SetupArg> for &ArgMatches {
fn into(self) -> SetupArg {
impl From<&ArgMatches> for SetupArg {
fn from(val: &ArgMatches) -> Self {
SetupArg {
k: *self.get_one::<u32>("K").unwrap(),
host_mode: *self.get_one::<HostMode>("host").unwrap(),
phantom_functions: self
k: *val.get_one::<u32>("K").unwrap(),
host_mode: *val.get_one::<HostMode>("host").unwrap(),
phantom_functions: val
.get_many::<String>("phantom")
.unwrap_or_default()
.map(|v| v.to_string())
.collect::<Vec<_>>(),
wasm_image: WasmImageArg::parse(self),
wasm_image: WasmImageArg::parse(val),
}
}
}

impl Into<RunningArg> for &ArgMatches {
fn into(self) -> RunningArg {
impl From<&ArgMatches> for RunningArg {
fn from(val: &ArgMatches) -> Self {
RunningArg {
output_dir: OutputDirArg::parse(self),
public_inputs: PublicInputsArg::parse(self),
private_inputs: PrivateInputsArg::parse(self),
context_inputs: ContextInputsArg::parse(self),
context_output: ContextOutputArg::parse(self),
output_dir: OutputDirArg::parse(val),
public_inputs: PublicInputsArg::parse(val),
private_inputs: PrivateInputsArg::parse(val),
context_inputs: ContextInputsArg::parse(val),
context_output: ContextOutputArg::parse(val),
}
}
}

impl Into<DryRunArg> for &ArgMatches {
fn into(self) -> DryRunArg {
impl From<&ArgMatches> for DryRunArg {
fn from(val: &ArgMatches) -> Self {
DryRunArg {
wasm_image: WasmImageArg::parse(self).unwrap(),
running_arg: self.into(),
wasm_image: WasmImageArg::parse(val).unwrap(),
running_arg: val.into(),
}
}
}

impl Into<ProveArg> for &ArgMatches {
fn into(self) -> ProveArg {
impl From<&ArgMatches> for ProveArg {
fn from(val: &ArgMatches) -> Self {
ProveArg {
wasm_image: WasmImageArg::parse(self).unwrap(),
output_dir: OutputDirArg::parse(self),
running_arg: self.into(),
mock_test: MockTestArg::parse(self),
file_backend: FileBackendArg::parse(self),
wasm_image: WasmImageArg::parse(val).unwrap(),
output_dir: OutputDirArg::parse(val),
running_arg: val.into(),
mock_test: MockTestArg::parse(val),
file_backend: FileBackendArg::parse(val),
}
}
}

impl Into<VerifyArg> for &ArgMatches {
fn into(self) -> VerifyArg {
impl From<&ArgMatches> for VerifyArg {
fn from(val: &ArgMatches) -> Self {
VerifyArg {
output_dir: OutputDirArg::parse(self),
output_dir: OutputDirArg::parse(val),
}
}
}

impl Into<ZkWasmCli> for ArgMatches {
fn into(self) -> ZkWasmCli {
let subcommand = match self.subcommand() {
impl From<ArgMatches> for ZkWasmCli {
fn from(arg: ArgMatches) -> ZkWasmCli {
let subcommand = match arg.subcommand() {
Some(("setup", sub_matches)) => Subcommands::Setup(sub_matches.into()),
Some(("dry-run", sub_matches)) => Subcommands::DryRun(sub_matches.into()),
Some(("prove", sub_matches)) => Subcommands::Prove(sub_matches.into()),
Expand All @@ -282,8 +282,8 @@ impl Into<ZkWasmCli> for ArgMatches {
};

ZkWasmCli {
name: self.get_one::<String>("NAME").unwrap().to_owned(),
params_dir: self.get_one::<PathBuf>("params").unwrap().to_owned(),
name: arg.get_one::<String>("NAME").unwrap().to_owned(),
params_dir: arg.get_one::<PathBuf>("params").unwrap().to_owned(),
subcommand,
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use serde::Serialize;
pub enum HostMode {
/// Trivial Wasm Host Environment
#[default]
DEFAULT,
Default,

/// Wasm Host Environment with more Zk plugins
STANDARD,
Standard,
}
9 changes: 5 additions & 4 deletions crates/cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::fs::File;
use std::fs::OpenOptions;
use std::fs::{self};
use std::io::Read;
use std::path::Path;
use std::path::PathBuf;

use crate::config::CircuitDataConfig;
Expand Down Expand Up @@ -80,7 +81,7 @@ impl SetupArg {
pub(crate) fn setup_circuit_data(
&self,
name: &str,
params_dir: &PathBuf,
params_dir: &Path,
params: &Params<G1Affine>,
k: u32,
compilation_tables: &CompilationTable,
Expand Down Expand Up @@ -119,14 +120,14 @@ impl SetupArg {

pub(crate) fn setup(
&self,
env_builder: &Box<dyn HostEnvBuilder>,
env_builder: &dyn HostEnvBuilder,
name: &str,
params_dir: &PathBuf,
) -> anyhow::Result<()> {
fs::create_dir_all(params_dir)?;

let wasm_image = self.wasm_image.as_ref().map_or(
wabt::wat2wasm(&TRIVIAL_WASM).map_err(|err| anyhow::anyhow!(err)),
wabt::wat2wasm(TRIVIAL_WASM).map_err(|err| anyhow::anyhow!(err)),
|file| fs::read(file).map_err(|err| anyhow::anyhow!(err)),
)?;
let module = ZkWasmLoader::parse_module(&wasm_image)?;
Expand Down Expand Up @@ -189,7 +190,7 @@ impl SetupArg {
format!("{:x}", md5)
};

let config_path = params_dir.join(&name_of_config(name));
let config_path = params_dir.join(name_of_config(name));

let config = Config {
name: name.to_string(),
Expand Down
47 changes: 22 additions & 25 deletions crates/cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::fs::File;
use std::io::Cursor;
use std::io::Read;
use std::io::Write;
use std::path::Path;
use std::path::PathBuf;

use anyhow::Result;
Expand Down Expand Up @@ -108,7 +109,7 @@ impl Config {
verifying_key: &[u8],
expected_md5: &str,
) -> anyhow::Result<()> {
let verifying_key_md5 = format!("{:x}", md5::compute(&verifying_key));
let verifying_key_md5 = format!("{:x}", md5::compute(verifying_key));

if verifying_key_md5 != expected_md5 {
anyhow::bail!(
Expand All @@ -123,35 +124,35 @@ impl Config {

impl Config {
pub(crate) fn write(&self, fd: &mut File) -> anyhow::Result<()> {
fd.write(&bincode::serialize(self)?)?;
fd.write_all(&bincode::serialize(self)?)?;

Ok(())
}

pub(crate) fn read(fd: &mut File) -> anyhow::Result<Self> {
let mut buf = Vec::new();
fd.read_to_end(&mut buf)?;
let config = bincode::deserialize(&mut buf)?;
let config = bincode::deserialize(&buf)?;

Ok(config)
}
}

impl Config {
fn read_wasm_image(&self, wasm_image: &PathBuf) -> anyhow::Result<Module> {
fn read_wasm_image(&self, wasm_image: &Path) -> anyhow::Result<Module> {
let mut buf = Vec::new();
File::open(&wasm_image)?.read_to_end(&mut buf)?;
File::open(wasm_image)?.read_to_end(&mut buf)?;

self.image_consistent_check(&buf)?;

ZkWasmLoader::parse_module(&buf)
}

fn read_params(&self, params_dir: &PathBuf) -> anyhow::Result<Params<G1Affine>> {
fn read_params(&self, params_dir: &Path) -> anyhow::Result<Params<G1Affine>> {
let path = params_dir.join(name_of_params(self.k));

let mut buf = Vec::new();
File::open(&path)?.read_to_end(&mut buf)?;
File::open(path)?.read_to_end(&mut buf)?;

self.params_consistent_check(&buf)?;

Expand All @@ -166,7 +167,7 @@ impl Config {
expected_md5: &str,
) -> anyhow::Result<CircuitData<G1Affine>> {
let mut buf = Vec::new();
File::open(&path)?.read_to_end(&mut buf)?;
File::open(path)?.read_to_end(&mut buf)?;

let circuit_data_md5 = format!("{:x}", md5::compute(&buf));

Expand All @@ -177,16 +178,16 @@ impl Config {
);
}

let circuit_data = CircuitData::<G1Affine>::read(&mut File::open(&path)?)?;
let circuit_data = CircuitData::<G1Affine>::read(&mut File::open(path)?)?;

Ok(circuit_data)
}

pub(crate) fn dry_run(
self,
env_builder: &Box<dyn HostEnvBuilder>,
wasm_image: &PathBuf,
output_dir: &PathBuf,
env_builder: &dyn HostEnvBuilder,
wasm_image: &Path,
output_dir: &Path,
arg: ExecutionArg,
context_output_filename: Option<String>,
) -> Result<()> {
Expand Down Expand Up @@ -236,10 +237,10 @@ impl Config {

pub(crate) fn prove(
self,
env_builder: &Box<dyn HostEnvBuilder>,
wasm_image: &PathBuf,
params_dir: &PathBuf,
output_dir: &PathBuf,
env_builder: &dyn HostEnvBuilder,
wasm_image: &Path,
params_dir: &Path,
output_dir: &Path,
arg: ExecutionArg,
context_output_filename: Option<String>,
mock_test: bool,
Expand Down Expand Up @@ -309,7 +310,6 @@ impl Config {
println!("{} Build circuit(s)...", style("[6/8]").bold().dim(),);
let instances = result
.public_inputs_and_outputs
.clone()
.iter()
.map(|v| (*v).into())
.collect::<Vec<_>>();
Expand All @@ -321,10 +321,7 @@ impl Config {

let progress_bar = ProgressBar::new(tables.execution_tables.etable.len() as u64);

let mut slices = Slices::new(self.k, tables)?
.into_iter()
.enumerate()
.peekable();
let mut slices = Slices::new(self.k, tables)?.enumerate().peekable();
while let Some((index, circuit)) = slices.next() {
let circuit = circuit?;

Expand Down Expand Up @@ -407,7 +404,7 @@ impl Config {
),
};

proof_piece_info.save_proof_data(&vec![instances.clone()], &proof, &output_dir);
proof_piece_info.save_proof_data(&vec![instances.clone()], &proof, output_dir);

proof_load_info.append_single_proof(proof_piece_info);

Expand All @@ -416,7 +413,7 @@ impl Config {
progress_bar.finish_and_clear();

{
let proof_load_info_path = output_dir.join(&name_of_loadinfo(&self.name));
let proof_load_info_path = output_dir.join(name_of_loadinfo(&self.name));
println!(
"{} Saving proof load info to {:?}...",
style("[8/8]").bold().dim(),
Expand All @@ -428,7 +425,7 @@ impl Config {
Ok(())
}

pub(crate) fn verify(self, params_dir: &PathBuf, output_dir: &PathBuf) -> anyhow::Result<()> {
pub(crate) fn verify(self, params_dir: &Path, output_dir: &PathBuf) -> anyhow::Result<()> {
let mut proofs = {
println!(
"{} Reading proofs from {:?}",
Expand All @@ -440,7 +437,7 @@ impl Config {
ProofGenerationInfo::load(&output_dir.join(&name_of_loadinfo(&self.name)));

let proofs: Vec<ProofInfo<Bn256>> =
ProofInfo::load_proof(&output_dir, &params_dir, &proof_load_info);
ProofInfo::load_proof(output_dir, params_dir, &proof_load_info);

proofs
}
Expand Down
Loading

0 comments on commit 620858d

Please sign in to comment.