# Circom (ZK circuit) quantum-crypto vulnerability rules
# All rules use pattern-regex: (not pattern: or patterns:) for opengrep compatibility.
# Language key: circom

rules:
  - id: circom-ecdsa-circuit-quantum
    pattern-regex: '(?:include\s*["'']ecdsa\.circom["'']|template\s+ECDSA(?:Verify|Sign)|component\s+\w+\s*=\s*ECDSA)'
    message: >-
      ECC (ECDSA/ECDH) is broken by Shor's algorithm -- all curves (P-256, P-384, secp256k1, Curve25519)
      are equally vulnerable regardless of key size. Migrate: ECDSA  ML-DSA (FIPS 204)  ECDH  ML-KEM
      (FIPS 203).
    severity: WARNING
    languages: [circom]
    metadata:
      category: security
      technology: [circom, post-quantum]
      cwe:
        - "CWE-327: Use of a Broken or Risky Cryptographic Algorithm"
      owasp:
        - A02:2021 - Cryptographic Failures
      quantum_vulnerable: true
      quantum_attack: "Shor's Algorithm"
      quantum_risk_score: 8

  - id: circom-secp256k1-circuit-quantum
    pattern-regex: '(?:include\s*["'']secp256k1\.circom["'']|Secp256k1\b)'
    message: >-
      ECC (ECDSA/ECDH) is broken by Shor's algorithm -- all curves (P-256, P-384, secp256k1, Curve25519)
      are equally vulnerable regardless of key size. Migrate: ECDSA  ML-DSA (FIPS 204)  ECDH  ML-KEM
      (FIPS 203).
    severity: WARNING
    languages: [circom]
    metadata:
      category: security
      technology: [circom, post-quantum]
      cwe:
        - "CWE-327: Use of a Broken or Risky Cryptographic Algorithm"
      owasp:
        - A02:2021 - Cryptographic Failures
      quantum_vulnerable: true
      quantum_attack: "Shor's Algorithm"
      quantum_risk_score: 8

  - id: circom-sha1-circuit-quantum
    pattern-regex: '(?:include\s*["'']sha1\.circom["'']|template\s+SHA1\b|component\s+\w+\s*=\s*SHA1\b)'
    message: >-
      SHA-1 is deprecated and quantum-weakened by Grover's algorithm -- effective security drops from 160
      to 80 bits. Use SHA-256, SHA-384, or SHA-3.
    severity: ERROR
    languages: [circom]
    metadata:
      category: security
      technology: [circom, post-quantum]
      cwe:
        - "CWE-327: Use of a Broken or Risky Cryptographic Algorithm"
        - "CWE-328: Use of Weak Hash"
      owasp:
        - A02:2021 - Cryptographic Failures
      quantum_vulnerable: true
      quantum_attack: "Grover's Algorithm"
      quantum_risk_score: 9

  - id: circom-rsa-verify-quantum
    pattern-regex: '(?:include\s*["'']rsa\.circom["'']|template\s+RSA(?:Verify|Sign)|component\s+\w+\s*=\s*RSA)'
    message: >-
      RSA is broken by Shor's algorithm regardless of key size. Migrate to ML-KEM (FIPS 203) for key
      encapsulation or ML-DSA (FIPS 204) for signatures.
    severity: WARNING
    languages: [circom]
    metadata:
      category: security
      technology: [circom, post-quantum]
      cwe:
        - "CWE-327: Use of a Broken or Risky Cryptographic Algorithm"
      owasp:
        - A02:2021 - Cryptographic Failures
      quantum_vulnerable: true
      quantum_attack: "Shor's Algorithm"
      quantum_risk_score: 8

  - id: circom-md5-circuit-quantum
    pattern-regex: '(?:include\s*["'']md5\.circom["'']|template\s+MD5|component\s+\w+\s*=\s*MD5)'
    message: >-
      MD5 is cryptographically broken and quantum-weakened by Grover's algorithm -- effective security
      drops from 128 to 64 bits. Use SHA-256, SHA-384, or SHA-3.
    severity: ERROR
    languages: [circom]
    metadata:
      category: security
      technology: [circom, post-quantum]
      cwe: ["CWE-327: Use of a Broken or Risky Cryptographic Algorithm"]
      owasp: ["A02:2021 - Cryptographic Failures"]
      quantum_vulnerable: true
      quantum_attack: "Grover Algorithm"
      quantum_risk_score: 9

  - id: circom-des-circuit-quantum
    pattern-regex: '(?:include\s*["'']des\.circom["'']|template\s+DES|component\s+\w+\s*=\s*DES)'
    message: >-
      DES has a 56-bit key -- completely broken classically and trivially quantum-vulnerable. Migrate to
      AES-256-GCM.
    severity: ERROR
    languages: [circom]
    metadata:
      category: security
      technology: [circom, post-quantum]
      cwe: ["CWE-327: Use of a Broken or Risky Cryptographic Algorithm"]
      owasp: ["A02:2021 - Cryptographic Failures"]
      quantum_vulnerable: true
      quantum_attack: "Grover Algorithm"
      quantum_risk_score: 9

  - id: circom-rc4-circuit-quantum
    pattern-regex: '(?:include\s*["'']rc4\.circom["'']|template\s+RC4|component\s+\w+\s*=\s*RC4)'
    message: >-
      RC4 is completely broken and banned by RFC 7465. Migrate to AES-256-GCM or ChaCha20-Poly1305.
    severity: ERROR
    languages: [circom]
    metadata:
      category: security
      technology: [circom, post-quantum]
      cwe: ["CWE-327: Use of a Broken or Risky Cryptographic Algorithm"]
      owasp: ["A02:2021 - Cryptographic Failures"]
      quantum_vulnerable: true
      quantum_attack: "Grover Algorithm"
      quantum_risk_score: 9

  - id: circom-aes128-circuit-quantum
    pattern-regex: '(?:include\s*["'']aes128\.circom["'']|template\s+AES128|component\s+\w+\s*=\s*AES128)'
    message: >-
      AES-128/192 provide only 64/96-bit quantum security under Grover's algorithm. Use AES-256 for
      128-bit post-quantum security.
    severity: WARNING
    languages: [circom]
    metadata:
      category: security
      technology: [circom, post-quantum]
      cwe: ["CWE-326: Inadequate Encryption Strength"]
      owasp: ["A02:2021 - Cryptographic Failures"]
      quantum_vulnerable: true
      quantum_attack: "Grover Algorithm"
      quantum_risk_score: 7

  - id: circom-aes192-circuit-quantum
    pattern-regex: '(?:include\s*["'']aes192\.circom["'']|template\s+AES192|component\s+\w+\s*=\s*AES192)'
    message: >-
      AES-128/192 provide only 64/96-bit quantum security under Grover's algorithm. Use AES-256 for
      128-bit post-quantum security.
    severity: WARNING
    languages: [circom]
    metadata:
      category: security
      technology: [circom, post-quantum]
      cwe: ["CWE-326: Inadequate Encryption Strength"]
      owasp: ["A02:2021 - Cryptographic Failures"]
      quantum_vulnerable: true
      quantum_attack: "Grover Algorithm"
      quantum_risk_score: 6
