# Cairo (Starknet) quantum-crypto vulnerability rules
# All rules use pattern-regex: (not pattern: or patterns:) for opengrep compatibility.
# Language key: cairo

rules:
  - id: cairo-ecdsa-quantum
    pattern-regex: '(?:ecdsa::check_ecdsa_signature|check_ecdsa_signature\b)'
    message: >-
      QUANTUM VULNERABILITY: ECDSA signature verification on the Stark curve detected. The Stark curve is
      an elliptic curve and all ECDSA operations are vulnerable to Shor's algorithm on a
      cryptographically-relevant quantum computer. An attacker with a quantum computer can recover the
      private key from any public key, breaking authentication and non-repudiation guarantees.
    severity: WARNING
    languages: [cairo]
    metadata:
      category: security
      technology: [cairo, 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: cairo-secp256k1-quantum
    pattern-regex: '(?:secp256k1::|Secp256k1Point\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: [cairo]
    metadata:
      category: security
      technology: [cairo, 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: cairo-secp256r1-quantum
    pattern-regex: '(?:secp256r1::|Secp256r1Point\b)'
    message: >-
      QUANTUM VULNERABILITY: secp256r1 (NIST P-256) elliptic curve operations detected. P-256 is a
      NIST-standardised elliptic curve widely used in TLS, FIDO2, and smart contracts. Like all ECC
      curves, it is vulnerable to Shor's algorithm -- a quantum computer can recover private keys from
      public keys, compromising all signatures and key agreements.
    severity: WARNING
    languages: [cairo]
    metadata:
      category: security
      technology: [cairo, 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: cairo-pedersen-quantum
    pattern-regex: '(?:pedersen::pedersen\b|pedersen_hash\b)'
    message: >-
      QUANTUM VULNERABILITY: Pedersen hash detected. The Pedersen hash is constructed over an elliptic
      curve (the Stark curve) and is partially quantum-vulnerable. While hash functions are primarily
      weakened by Grover's algorithm (halving effective security), the ECC-based structure of Pedersen
      also exposes it to potential structural attacks from Shor's algorithm in some use cases.
    severity: WARNING
    languages: [cairo]
    metadata:
      category: security
      technology: [cairo, post-quantum]
      cwe:
        - "CWE-327: Use of a Broken or Risky Cryptographic Algorithm"
      owasp:
        - A02:2021 - Cryptographic Failures
      quantum_vulnerable: true
      quantum_attack: "Grover's Algorithm"
      quantum_risk_score: 6
