Skip to main content

Static analysis tool to detect ZKP vulnerabilities in Circom circuits.

Project description

Circheck

Circheck is a static analysis tool for Circom source code, designed to detect security vulnerabilities in Zero-Knowledge Proof (ZKP) circuits written in the Circom language. This tool helps developers and users ensure the security and integrity of their ZKP projects by analyzing the source code and identifying potential issues during circuit design.

Features

Circheck detects a variety of potential issues in Circom circuits, including:

  • Unconstrained Output Signals: Detects output signals that are not constrained by any constraints.
  • Unconstrained Component Inputs: Identifies input signals to components that are not constrained and may accept unchecked values.
  • Data Flow Constraint Discrepancy: Finds signals that depend on others via dataflow but lack corresponding constraint dependencies.
  • Unused Component Outputs: Warns when outputs of components are not used or checked in the circuit.
  • Unused Signals: Identifies signals that are declared but never used in any computation or constraint.
  • Type Mismatch: Detects potential type mismatches, such as signals flowing into templates like Num2Bits without proper range checks.
  • Assignment Misuse: Finds assignment misuse, where a variable is assigned using the wrong operator.
  • Divide by Zero: Warns of potential divide-by-zero issues in the circuit.
  • Non-deterministic Data Flow: Flags conditional assignments depending on signals, which may lead to non-deterministic data flows.

Installation

To install Circheck, you can clone the repository and install the required dependencies:

git clone https://github.com/dangduongminhnhat/Circheck.git
cd Circheck
pip install -r requirements.txt

or you can install Circheck via pip, use the following command:

pip install circheck

Usage

Circheck is a static analysis tool designed to detect ZKP vulnerabilities in Circom circuits. You can use it via the command line interface (CLI) to analyze Circom code and generate reports.

Command Line Arguments

  • input: Required - The path to the Circom file you want to analyze.
  • --json: Optional - If specified, the tool will output a JSON report to the given file. The output file must end with .json.

Example Usage

  1. Basic Analysis: To analyze a Circom file and print the report to the console:

    circheck path/to/your/file.circom
    

    This will run the analysis and display the results directly in the terminal.

  2. Generate JSON Report: To analyze the Circom file and save the report in a JSON file:

    circheck path/to/your/file.circom --json path/to/output/report.json
    

    This will run the analysis and save the results in the specified JSON file.

Example Output:

When you run the tool, you'll see progress information printed to the terminal, such as:

PS C:\Users\GAMING\Desktop\Capstone_Project> circheck .\demo.circom --json .\result.json
[Info]       Generating AST for: .\demo.circom
[Success]    AST generated successfully.
[Success]    Type checking passed.
[Info]       Creating CDG: SingleAssignment0, in .\demo.circom
[Info]       Building conditional dependency edges of SingleAssignment0...
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████| 5/5 [00:00<?, ?it/s]
[Info]       Building condition constraint edges of SingleAssignment0...
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████| 5/5 [00:00<?, ?it/s]
[Success]    CDG created successfully.
[Info]       Starting the analysis process of graph SingleAssignment0.
[Info]       Detecting unconstrainted output...
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<?, ?it/s]
[Info]       Detecting unconstrained component input...
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████| 5/5 [00:00<?, ?it/s]
[Info]       Detecting data flow constraint discrepancy...
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████| 3/3 [00:00<?, ?it/s]
[Info]       Detecting unused component output...
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████| 5/5 [00:00<?, ?it/s]
[Info]       Detecting type mismatch...
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████| 5/5 [00:00<?, ?it/s]
[Info]       Detecting assignment misuse...
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████| 7/7 [00:00<?, ?it/s]
[Info]       Detecting unused signals...
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████| 7/7 [00:00<?, ?it/s]
[Info]       Detecting nondeterministic data flow...
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████| 7/7 [00:00<?, ?it/s]
[Success]    Detection completed successfully.
[Timeit]     Analysis completed in 0.30 s

If there are any warnings or issues detected, they will be printed like this:

[Warning]    In .\demo.circom:4:4
             Signal 'out' depends on 'a' via dataflow, but there is no corresponding constraint dependency.
[Warning]    In .\demo.circom:5:4
             Variable out is assigned using <-- instead of <==.
âš  Total warnings: 2

Example JSON Output:

If you specify a JSON output file, the results will also be saved to the file. For example:

[Success] Saved report to path/to/output/report.json

The JSON file will contain detailed information about the analysis, including detected vulnerabilities. A sample JSON output might look like this:

{
  "SingleAssignment0": {
    "data flow constraint discrepancy": {
      ".\\demo.circom:4:4": [
        "Signal 'out' depends on 'a' via dataflow, but there is no corresponding constraint dependency."
      ]
    },
    "assignment missue": {
      ".\\demo.circom:5:4": [
        "Variable out is assigned using <-- instead of <==."
      ]
    }
  }
}

License

Licensed under the MIT License © 2025 Dang Duong Minh Nhat.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

circheck-0.3.0.tar.gz (61.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

circheck-0.3.0-py3-none-any.whl (64.3 kB view details)

Uploaded Python 3

File details

Details for the file circheck-0.3.0.tar.gz.

File metadata

  • Download URL: circheck-0.3.0.tar.gz
  • Upload date:
  • Size: 61.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.4

File hashes

Hashes for circheck-0.3.0.tar.gz
Algorithm Hash digest
SHA256 65baf8cfdb6fc51bd6a5999a7202ad386cc3a56da1b0f0b2807cf531f14735ad
MD5 2d0e7f516d562b8c61e7029ea216c568
BLAKE2b-256 5747d81c14735cd8ce9c7f5a095e9f8294e640923efe9da08cea2553e0f53968

See more details on using hashes here.

File details

Details for the file circheck-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: circheck-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 64.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.4

File hashes

Hashes for circheck-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9a30a45b7f7f40737c25338ab986dfc416e950ede61c92410f0bb0a263840b1d
MD5 e57ca023bb96a2638dc7bf590c62f805
BLAKE2b-256 1ae1f815192470812c637ad2faa308b4be729056edfd2f6eda1a6e4067b41c3b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page