Skip to content

Repository files navigation

Quantum Static Analyzer – Feature Overview

This project introduces a static analysis framework for detecting security-relevant structural vulnerabilities and execution-risk indicators in quantum programs, particularly in hybrid quantum–classical environments.

The tool focuses on analyzing Qiskit-based circuits to identify structural and compilation-induced risks before execution in ideal and noisy simulation environments.


Features Implemented

1. Static Vulnerability Detection

The analyzer inspects quantum circuits at the structural level to identify security-relevant patterns.

The system parses Qiskit circuit representations and applies rule-based analysis to detect vulnerabilities that may not produce compilation errors but can lead to unintended or unsafe behavior during execution.


2. Measurement Misuse Detection

The tool identifies unsafe measurement patterns, including:

  • Operations applied after measurement
  • Incorrect or inconsistent measurement ordering
  • Improper use of classical feedback

These issues can introduce information leakage or unintended circuit behavior in hybrid workflows.


3. Qubit Reuse Analysis

The analyzer detects cases where qubits are reused without proper reset or initialization.

Such patterns may result in residual state leakage, especially in shared or multi-tenant quantum environments.


4. Compilation-Aware Analysis

The system compares circuits before and after transpilation to identify structural changes introduced during compilation.

This includes:

  • Increased circuit depth
  • Additional two-qubit gates
  • SWAP gate insertion due to routing constraints

These transformations may expose circuits to noise, crosstalk, or other security risks.


5. Detection of LLM-Generated Code Anomalies

The analyzer identifies structural anomalies commonly found in AI-generated quantum code, including:

  • Redundant or ineffective gate sequences
  • Inconsistent circuit construction
  • Use of invalid or hallucinated APIs

This supports analysis of quantum programs generated using large language models.


6. Security Report Generation

The system produces structured reports summarizing detected findings, including structural vulnerabilities and runtime-validation signals.

Each report includes:

  • Finding type
  • Rule identifier
  • Security impact (Confidentiality, Integrity, Availability)
  • Evidence from the circuit
  • Suggested mitigation strategies

Project Structure

├── analyzer/             # Core analysis logic
│ └── quantum_security_analyzer.py
├── circuits/            # Example and test circuits
├── reports/             # Generated reports
├── analyze_results.py   # Result analysis
├── report_generator.py  # Report generation
├── make_table.py        # Summary generation
├── run_all.sh          # Pipeline execution script
└── README.md

Create virtual environment

python3 -m venv .venv
source .venv/bin/activate

Install dependencies

pip install -r requirements.txt

Usage

Run full analysis pipeline

./run_all.sh

Generate summary table

python make_table.py

Run result analysis

python analyze_results.py

Run analyzer directly

python analyzer/quantum_security_analyzer.py --input circuits/adder_n10.qasm 

Output

The system generates:

  • Structured vulnerability reports
  • Analysis summaries
  • CSV output (results_table.csv)

Each finding includes detailed information about detected risks and their potential impact.

Testing

The project follows a structured testing methodology focused on validating detection logic and analysis correctness.

Test cases include:

  • Detection of measurement misuse patterns
  • Identification of qubit reuse without reset
  • Verification of transpilation-induced changes
  • Validation of anomaly detection in generated circuits

Example Output

Below is an example analysis result for a quantum circuit:

{
  "rule_id": "RV1",
  "title": "Noise-induced divergence",
  "severity": "medium",
  "message": "Execution context alters output distribution",
  "impact": {
    "confidentiality": false,
    "integrity": true,
    "availability": true
  },
  "metrics": {
    "tvd": 0.7109,
    "fidelity": 0.2890
  }
}

Interpretation

The analyzer detects execution-risk divergence between ideal and noisy simulation outcomes. For RV1, this represents a runtime validation signal rather than a direct structural vulnerability class.

This impacts:

  • Integrity (incorrect results)
  • Availability (reliability under noise)

Output Files

Each analyzed circuit generates a report:

reports/<circuit_name>.json

Example:

reports/adder_n10.json

Reproducing Aggregate Metrics

After results_table.csv has been generated, you can print the aggregate structural and runtime metrics with:

**Note:**Rule counts and coverage percentages are computed over all 101 circuits. Runtime and transpilation means are computed over the 94 circuits with valid execution metrics because 7 analyses failed.

We used a fixed transpiler seed (42), a fixed simulator seed (42), and 4096 shots to improve reproducibility and reduce sampling variance during simulation.

The final experimental environment used to generate the reported results was captured in final_results/requirements_locked.txt.

python3 - <<'PY'
import pandas as pd

df = pd.read_csv("results_table.csv")
m = df[["depth_src", "depth_trans", "tvd", "fidelity"]].mean()

print("source-circuit depth =", round(m["depth_src"], 2))
print("transpiled depth =", round(m["depth_trans"], 2))
print("mean TVD =", round(m["tvd"], 3))
print("mean fidelity =", round(m["fidelity"], 3))
PY

Reported Aggregate Results

Using the locked experimental configuration, the aggregate results are:

  • Source-circuit depth: 15.76
  • Transpiled-circuit depth: 47.64
  • Mean TVD: 0.246
  • Mean fidelity: 0.779

Static vs. Runtime Validation Coverage

Using the locked results table:

  • Static only: 22 / 101 (21.78%)
  • Runtime only: 35 / 101 (34.65%)
  • Both: 29 / 101 (28.71%)
  • Neither: 15 / 101 (14.85%)

These results show that runtime validation contributes substantial additional coverage beyond static rule-based detection alone.

Summary

This project improves quantum software reliability by introducing security-aware static analysis.

It enables early detection of vulnerabilities in quantum circuits, including those introduced by compilation, hybrid execution environments, and automated code generation.

The tool supports safer development and evaluation of quantum programs by identifying risks before deployment.

Dataset

The evaluation corpus contains 101 circuits:

  • 30 benchmark circuits from QASMBench
  • 71 LLM-generated Qiskit circuits created using GPT-4.0 and Claude Opus 4.5
  • of the 71 LLM-generated circuits, 47 were issue-seeking and 24 were clean control cases, based on a manual design-intent review

Acknowledgements

Parts of this project were developed with the assistance of large language models, specifically GPT-4.0 and Claude Opus 4.5. These models were used to support code generation, refinement, and implementation, including the creation of 71 LLM-generated quantum circuits used in the evaluation. They also assisted with improving and debugging the static analyzer, writing rules for vulnerability detection, formatting the security report after circuit execution, and ensuring that the static analyzer produced consistent output across repeated runs. Final implementation decisions, testing, validation, and analysis were reviewed and completed by the project authors.

Some QASM benchmark circuits used in this work were obtained from the Qiskit Benchpress repository:

https://github.com/Qiskit/benchpress/tree/main/benchpress%2Fqasm

About

A static analysis tool for quantum programs that detects security vulnerabilities in Qiskit-based circuits by analyzing circuit structure, execution context, and compilation effects, identifying issues such as measurement misuse, qubit reuse, and transpilation-induced risks in hybrid quantum–classical systems.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages