Skip to content

Commit

Permalink
fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
eduadiez committed Jul 19, 2024
1 parent e709dc1 commit c703766
Show file tree
Hide file tree
Showing 16 changed files with 76 additions and 77 deletions.
6 changes: 1 addition & 5 deletions cli/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
fn main() {
vergen::EmitBuilder::builder()
.build_timestamp()
.git_sha(true)
.emit()
.unwrap();
vergen::EmitBuilder::builder().build_timestamp().git_sha(true).emit().unwrap();
}
30 changes: 19 additions & 11 deletions cli/src/bin/cargo-zisk.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
use anyhow::{anyhow, Context, Result};
use cargo_zisk::commands::build_toolchain::BuildToolchainCmd;
use cargo_zisk::commands::install_toolchain::InstallToolchainCmd;
use cargo_zisk::commands::new::NewCmd;
use cargo_zisk::ZISK_VERSION_MESSAGE;
use cargo_zisk::{
commands::{
build_toolchain::BuildToolchainCmd, install_toolchain::InstallToolchainCmd, new::NewCmd,
},
ZISK_VERSION_MESSAGE,
};
use clap::{Parser, Subcommand};
use std::env;
use std::process::{Command, Stdio};
use std::{
env,
process::{Command, Stdio},
};

use std::fs::File;
use std::io::{self, Read, Write};
use std::path::Path;
use std::{
fs::File,
io::{self, Read, Write},
path::Path,
};

// Main enum defining cargo subcommands.
#[derive(Parser)]
Expand Down Expand Up @@ -122,9 +128,11 @@ impl ZiskRun {
gdb_command
);
}


env::set_var("CARGO_TARGET_RISCV64IMA_POLYGON_ZISKOS_ELF_RUNNER", runner_command.to_string());
env::set_var(
"CARGO_TARGET_RISCV64IMA_POLYGON_ZISKOS_ELF_RUNNER",
runner_command.to_string(),
);
// Verify the environment variable is set
println!(
"CARGO_TARGET_RISCV64IMA_POLYGON_ZISKOS_ELF_RUNNER: {}",
Expand Down
24 changes: 6 additions & 18 deletions cli/src/commands/build_toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ impl BuildToolchainCmd {
let repo_url = match github_access_token {
Ok(github_access_token) => {
println!("Detected GITHUB_ACCESS_TOKEN, using it to clone rust.");
format!(
"https://{}@github.com/eduadiez/rust",
github_access_token
)
format!("https://{}@github.com/eduadiez/rust", github_access_token)
}
Err(_) => {
println!("No GITHUB_ACCESS_TOKEN detected. If you get throttled by Github, set it to bypass the rate limit.");
Expand All @@ -50,10 +47,7 @@ impl BuildToolchainCmd {
])
.current_dir(&temp_dir)
.run()?;
Command::new("git")
.args(["reset", "--hard"])
.current_dir(&dir)
.run()?;
Command::new("git").args(["reset", "--hard"]).current_dir(&dir).run()?;
Command::new("git")
.args(["submodule", "update", "--init", "--recursive", "--progress"])
.current_dir(&dir)
Expand All @@ -63,11 +57,8 @@ impl BuildToolchainCmd {
};
// Install our config.toml.
let ci = std::env::var("CI").unwrap_or("false".to_string()) == "true";
let config_toml = if ci {
include_str!("config-ci.toml")
} else {
include_str!("config.toml")
};
let config_toml =
if ci { include_str!("config-ci.toml") } else { include_str!("config.toml") };
let config_file = rust_dir.join("config.toml");
std::fs::write(&config_file, config_toml)
.with_context(|| format!("while writing configuration to {:?}", config_file))?;
Expand All @@ -86,10 +77,7 @@ impl BuildToolchainCmd {
.run()?;

// Remove the existing toolchain from rustup, if it exists.
match Command::new("rustup")
.args(["toolchain", "remove", RUSTUP_TOOLCHAIN_NAME])
.run()
{
match Command::new("rustup").args(["toolchain", "remove", RUSTUP_TOOLCHAIN_NAME]).run() {
Ok(_) => println!("Successfully removed existing toolchain."),
Err(_) => println!("No existing toolchain to remove."),
}
Expand All @@ -111,7 +99,7 @@ impl BuildToolchainCmd {
);

// Copy over the stage2-tools-bin directory to the toolchain bin directory.
/*
/*
let tools_bin_dir = toolchain_dir.parent().unwrap().join("stage2-tools-bin");
let target_bin_dir = toolchain_dir.join("bin");
for tool in tools_bin_dir.read_dir()? {
Expand Down
42 changes: 14 additions & 28 deletions cli/src/commands/install_toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ use clap::Parser;
use dirs::home_dir;
use rand::{distributions::Alphanumeric, Rng};
use reqwest::Client;
use std::fs::{self};
use std::io::Read;
use std::process::Command;
use std::{
fs::{self},
io::Read,
process::Command,
};

#[cfg(target_family = "unix")]
use std::os::unix::fs::PermissionsExt;
Expand All @@ -16,10 +18,7 @@ use crate::{
};

#[derive(Parser)]
#[command(
name = "install-toolchain",
about = "Install the cargo-zisk toolchain."
)]
#[command(name = "install-toolchain", about = "Install the cargo-zisk toolchain.")]
pub struct InstallToolchainCmd {}

impl InstallToolchainCmd {
Expand All @@ -37,10 +36,10 @@ impl InstallToolchainCmd {
if let Ok(entry) = entry {
let entry_path = entry.path();
let entry_name = entry_path.file_name().unwrap();
if entry_path.is_dir()
&& entry_name != "bin"
&& entry_name != "circuits"
&& entry_name != "toolchains"
if entry_path.is_dir() &&
entry_name != "bin" &&
entry_name != "circuits" &&
entry_name != "toolchains"
{
if let Err(err) = fs::remove_dir_all(&entry_path) {
println!("Failed to remove directory {:?}: {}", entry_path, err);
Expand Down Expand Up @@ -83,12 +82,7 @@ impl InstallToolchainCmd {

// Download the toolchain.
let mut file = fs::File::create(toolchain_archive_path)?;
rt.block_on(download_file(
&client,
toolchain_download_url.as_str(),
&mut file,
))
.unwrap();
rt.block_on(download_file(&client, toolchain_download_url.as_str(), &mut file)).unwrap();

// Remove the existing toolchain from rustup, if it exists.
let mut child = Command::new("rustup")
Expand All @@ -113,22 +107,14 @@ impl InstallToolchainCmd {
fs::create_dir_all(toolchain_dir.clone())?;
Command::new("tar")
.current_dir(&root_dir)
.args([
"-xzf",
&toolchain_asset_name,
"-C",
&toolchain_dir.to_string_lossy(),
])
.args(["-xzf", &toolchain_asset_name, "-C", &toolchain_dir.to_string_lossy()])
.status()?;

// Move the toolchain to a randomly named directory in the 'toolchains' folder
let toolchains_dir = root_dir.join("toolchains");
fs::create_dir_all(&toolchains_dir)?;
let random_string: String = rand::thread_rng()
.sample_iter(&Alphanumeric)
.take(10)
.map(char::from)
.collect();
let random_string: String =
rand::thread_rng().sample_iter(&Alphanumeric).take(10).map(char::from).collect();
let new_toolchain_dir = toolchains_dir.join(random_string);
fs::rename(&toolchain_dir, &new_toolchain_dir)?;

Expand Down
5 changes: 1 addition & 4 deletions cli/src/commands/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ impl NewCmd {
" \x1b[1m{}\x1b[0m {} ({})",
Paint::green("Initialized"),
self.name,
std::fs::canonicalize(root)
.expect("failed to canonicalize")
.to_str()
.unwrap()
std::fs::canonicalize(root).expect("failed to canonicalize").to_str().unwrap()
);

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod zisk_opcodes;
mod rom;
mod zisk_opcodes;

pub use zisk_opcodes::*;
pub use rom::*;
pub use zisk_opcodes::*;
4 changes: 3 additions & 1 deletion common/src/rom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ where
let value: IndexMap<String, Value> = Deserialize::deserialize(deserializer)?;
value
.into_iter()
.map(|(k, v)| serde_json::from_value(v).map(|inst| (k, inst)).map_err(serde::de::Error::custom))
.map(|(k, v)| {
serde_json::from_value(v).map(|inst| (k, inst)).map_err(serde::de::Error::custom)
})
.collect()
}

Expand Down
1 change: 1 addition & 0 deletions riscv/riscv2zisk/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions simulator/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 0 additions & 1 deletion state-machines/main/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#[allow(dead_code, unused)]

mod main_sm;
mod main_trace;

Expand Down
9 changes: 8 additions & 1 deletion state-machines/main/src/main_sm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ impl MainSM {
}

impl<F> WCComponent<F> for MainSM {
fn calculate_witness(&self, stage: u32, air_instance: &AirInstance, pctx: &mut ProofCtx<F>, ectx: &ExecutionCtx) {}
fn calculate_witness(
&self,
stage: u32,
air_instance: &AirInstance,
pctx: &mut ProofCtx<F>,
ectx: &ExecutionCtx,
) {
}

fn calculate_plan(&self, ectx: &mut ExecutionCtx) {}
}
Expand Down
2 changes: 1 addition & 1 deletion state-machines/main/src/main_trace.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use proofman::trace;
use p3_goldilocks::Goldilocks;
use proofman::trace;

trace!(MainTrace0 { a: Goldilocks, b: Goldilocks });
1 change: 0 additions & 1 deletion state-machines/mem/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#[allow(dead_code, unused)]

mod mem_sm;
mod mem_trace;

Expand Down
15 changes: 13 additions & 2 deletions state-machines/mem/src/mem_sm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ impl MemSM {

impl WCOpCalculator for MemSM {
// 0:x, 1:module
fn calculate_verify(&self, verify: bool, values: Vec<u64>) -> Result<Vec<u64>, Box<dyn std::error::Error>> {
fn calculate_verify(
&self,
verify: bool,
values: Vec<u64>,
) -> Result<Vec<u64>, Box<dyn std::error::Error>> {
let (x, module) = (values[0], values[1]);

let x_mod = x % module;
Expand All @@ -38,7 +42,14 @@ impl WCOpCalculator for MemSM {
}

impl<F> WCComponent<F> for MemSM {
fn calculate_witness(&self, stage: u32, air_instance: &AirInstance, pctx: &mut ProofCtx<F>, _ectx: &ExecutionCtx) {}
fn calculate_witness(
&self,
stage: u32,
air_instance: &AirInstance,
pctx: &mut ProofCtx<F>,
_ectx: &ExecutionCtx,
) {
}

fn calculate_plan(&self, ectx: &mut ExecutionCtx) {}
}
2 changes: 1 addition & 1 deletion state-machines/mem/src/mem_trace.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use proofman::trace;
use p3_goldilocks::Goldilocks;
use proofman::trace;

trace!(MemTrace0 { x: Goldilocks, q: Goldilocks, x_mod: Goldilocks });
6 changes: 5 additions & 1 deletion witness-computation/src/pil_helpers/public_inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ impl ZiskPublicInputs {
impl From<&[u8]> for ZiskPublicInputs {
fn from(input_bytes: &[u8]) -> Self {
const U64_SIZE: usize = std::mem::size_of::<u64>();
assert_eq!(input_bytes.len(), U64_SIZE * 3, "Input bytes length must be 3 * size_of::<u64>()");
assert_eq!(
input_bytes.len(),
U64_SIZE * 3,
"Input bytes length must be 3 * size_of::<u64>()"
);

ZiskPublicInputs {
a: u64::from_le_bytes(input_bytes[0..U64_SIZE].try_into().unwrap()),
Expand Down

0 comments on commit c703766

Please sign in to comment.