Skip to content

Commit

Permalink
Update to support Circom 2.0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
fegge committed Sep 12, 2022
1 parent ff820f1 commit 3cdd3c3
Show file tree
Hide file tree
Showing 43 changed files with 729 additions and 452 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ To output the results to a Sarif file (which can be read by the [VSCode Sarif Vi

![VSCode example image](https://github.com/trailofbits/circomspect/raw/main/doc/vscode.png)

Circomspect supports the same curves that Circom does: BN128, BLS12-381, and Ed448-Goldilocks. If you are using a different curve than the default (BN128) you can set the curve using the command line option `--curve`.

## Analysis Passes

The project currently implements analysis passes for the following types of issues.
Expand Down Expand Up @@ -120,7 +122,7 @@ the prime. If not, there may be multiple correct representations of the input
which could cause issues, since we typically expect the circuit output to be
uniquely determined by the input.

For example, Suppose that we create a component `n2b` given by `Num2Bits(254)` and set the input to `1`. Now, both the binary representation of `1` _and_ the representation of `p + 1` will satisfy the circuit, since both are 254-bit numbers. If you cannot restrict the input size below 254 bits you should use the strict versions `Num2Bits_strict` and `Bits2Num_strict` to convert to and from binary representation. Circomspect will generate a warning if it cannot prove (using constant propagation) that the input size passed to `Num2Bits` or `Bits2Num` is less than 254 bits.
For example, Suppose that we create a component `n2b` given by `Num2Bits(254)` and set the input to `1`. Now, both the binary representation of `1` _and_ the representation of `p + 1` will satisfy the circuit over BN128, since both are 254-bit numbers. If you cannot restrict the input size below the prime size you should use the strict versions `Num2Bits_strict` and `Bits2Num_strict` to convert to and from binary representation. Circomspect will generate a warning if it cannot prove (using constant propagation) that the input size passed to `Num2Bits` or `Bits2Num` is less than the size of the prime in bits.


#### Overly complex functions or templates (Warning)
Expand Down
2 changes: 1 addition & 1 deletion circom_algebra/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "circomspect-circom-algebra"
version = "2.0.0"
authors = ["hermeGarcia <[email protected]>"]
edition = "2018"
license = "LGPL-3.0-only"
authors = ["hermeGarcia <[email protected]>"]
description = "Support crate for the Circomspect static analyzer"
repository = "https://github.com/trailofbits/circomspect"

Expand Down
8 changes: 4 additions & 4 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "circomspect"
version = "0.5.6"
version = "0.6.0"
edition = "2021"
license = "LGPL-3.0-only"
authors = ["Trail of Bits"]
Expand All @@ -14,9 +14,9 @@ anyhow = "1.0"
atty = "0.2.14"
clap = { version = "3.2", features = ["derive"] }
log = "0.4"
parser = { package = "circomspect-parser", version = "2.0.2", path = "../parser" }
parser = { package = "circomspect-parser", version = "2.0.8", path = "../parser" }
pretty_env_logger = "0.4"
program_analysis = { package = "circomspect-program-analysis", version = "0.5.2", path = "../program_analysis" }
program_structure = { package = "circomspect-program-structure", version = "2.0.2", path = "../program_structure" }
program_analysis = { package = "circomspect-program-analysis", version = "0.6.0", path = "../program_analysis" }
program_structure = { package = "circomspect-program-structure", version = "2.0.8", path = "../program_structure" }
serde_json = "1.0.81"
termcolor = "1.1.3"
27 changes: 20 additions & 7 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use anyhow::Result;
use clap::{CommandFactory, Parser};
use parser::ParseResult;
use program_structure::constants::Curve;
use std::io::Write;
use std::path::PathBuf;
use std::process::ExitCode;
Expand All @@ -15,8 +16,9 @@ use program_structure::function_data::FunctionInfo;
use program_structure::report_writer::{StdoutWriter, ReportWriter, SarifWriter};
use program_structure::template_data::TemplateInfo;

const COMPILER_VERSION: &str = "2.0.3";
const COMPILER_VERSION: &str = "2.0.8";
const DEFAULT_LEVEL: &str = "WARNING";
const DEFAULT_CURVE: &str = "BN128";

#[derive(Parser, Debug)]
/// A static analyzer and linter for Circom programs.
Expand All @@ -40,10 +42,18 @@ struct Cli {
/// Enable verbose output
#[clap(short = 'v', long = "verbose")]
verbose: bool,

/// Set curve (BN128, BLS12_381, or GOLDILOCKS)
#[clap(short = 'c', long = "curve", name = "NAME", default_value = DEFAULT_CURVE)]
curve: Curve,
}

fn generate_cfg<Ast: IntoCfg>(ast: Ast, reports: &mut ReportCollection) -> Result<Cfg, Report> {
ast.into_cfg(reports).map_err(Report::from)?.into_ssa().map_err(Report::from)
fn generate_cfg<Ast: IntoCfg>(
ast: Ast,
curve: &Curve,
reports: &mut ReportCollection,
) -> Result<Cfg, Report> {
ast.into_cfg(curve, reports).map_err(Report::from)?.into_ssa().map_err(Report::from)
}

fn analyze_cfg(cfg: &Cfg, reports: &mut ReportCollection) {
Expand All @@ -52,8 +62,8 @@ fn analyze_cfg(cfg: &Cfg, reports: &mut ReportCollection) {
}
}

fn analyze_ast<Ast: IntoCfg>(ast: Ast, reports: &mut ReportCollection) {
match generate_cfg(ast, reports) {
fn analyze_ast<Ast: IntoCfg>(ast: Ast, curve: &Curve, reports: &mut ReportCollection) {
match generate_cfg(ast, curve, reports) {
Ok(cfg) => {
analyze_cfg(&cfg, reports);
}
Expand All @@ -67,6 +77,7 @@ fn analyze_definitions(
functions: &FunctionInfo,
templates: &TemplateInfo,
file_library: &FileLibrary,
curve: &Curve,
writer: &mut StdoutWriter,
) -> ReportCollection {
let mut all_reports = ReportCollection::new();
Expand All @@ -75,15 +86,15 @@ fn analyze_definitions(
for (name, function) in functions {
log_message(&format!("analyzing function '{name}'"));
let mut new_reports = ReportCollection::new();
analyze_ast(function, &mut new_reports);
analyze_ast(function, curve, &mut new_reports);
writer.write(&new_reports, file_library);
all_reports.extend(new_reports);
}
// Analyze all templates.
for (name, template) in templates {
log_message(&format!("analyzing template '{name}'"));
let mut new_reports = ReportCollection::new();
analyze_ast(template, &mut new_reports);
analyze_ast(template, curve, &mut new_reports);
writer.write(&new_reports, file_library);
all_reports.extend(new_reports);
}
Expand Down Expand Up @@ -139,6 +150,7 @@ fn main() -> ExitCode {
&program.functions,
&program.templates,
&program.file_library,
&options.curve,
&mut writer,
));
program.file_library
Expand All @@ -151,6 +163,7 @@ fn main() -> ExitCode {
&library.functions,
&library.templates,
&library.file_library,
&options.curve,
&mut writer,
));
library.file_library
Expand Down
6 changes: 3 additions & 3 deletions parser/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "circomspect-parser"
version = "2.0.2"
version = "2.0.8"
edition = "2018"
build = "build.rs"
license = "LGPL-3.0-only"
Expand All @@ -15,7 +15,7 @@ num-bigint-dig = "0.6.0"
num-traits = "0.2.6"

[dependencies]
program_structure = { package = "circomspect-program-structure", version = "2.0.2", path = "../program_structure" }
program_structure = { package = "circomspect-program-structure", version = "2.0.8", path = "../program_structure" }
lalrpop = { version = "0.18.1", features = ["lexer"] }
lalrpop-util = "0.18.1"
log = "0.4"
Expand All @@ -27,4 +27,4 @@ serde = "1.0.82"
serde_derive = "1.0.91"

[dev-dependencies]
program_structure = { package = "circomspect-program-structure", version = "2.0.2", path = "../program_structure" }
program_structure = { package = "circomspect-program-structure", version = "2.0.8", path = "../program_structure" }
Loading

0 comments on commit 3cdd3c3

Please sign in to comment.