Skip to content

ZK proof verification failure due to strict SHA-256 hashing on benign image compression #38

@Tenerife-Q

Description

@Tenerife-Q

Context:
While reviewing the capture-to-mint pipeline, I examined how the system currently anchors image authenticity. In hardware-camera-app/raspberry_pi_camera_app.py (specifically in _upload_and_create_claim), the hardware generates a strict cryptographic hash directly from the image buffer using hashlib.sha256. This exact hash is later verified on-chain through the RISC Zero ZK proof in contracts/src/LensMintVerifier.sol (submitMetadata).

The Problem:
Cryptographic algorithms like SHA-256 are extremely sensitive to any data modification. A single bit of change in the file structure completely alters the resulting hash output.

Impact:
In standard decentralized storage scenarios, when images are routed through Filecoin/IPFS gateways, cached by CDNs, or processed by frontend clients, they frequently undergo minor, visually lossless compression or metadata stripping. If this occurs, the SHA-256 hash will change entirely. Consequently, the ZK proof verification will fail on-chain, even if the image is visually authentic and was genuinely captured by a registered hardware device. This creates a bottleneck for real-world usability.

Proposed Solution:
To resolve this, we can introduce Perceptual Hashing (pHash) combined with a distance-based tolerance threshold in the ZK circuit, shifting the authenticity check from strict byte-matching to visual semantic matching.

  1. Hardware Side (Python): Extract the pHash of the image array at the time of capture and include it in the signed metadata payload alongside the original signature.
  2. ZK Circuit (RISC Zero / Rust): Implement a guest program that calculates the Hamming distance between the originally signed pHash and the pHash of the image currently being verified.
  3. Validation Logic: The ZK circuit will generate a valid proof as long as the Hamming distance is below a strict, predefined threshold. This ensures the system tolerates normal image compression but firmly rejects AI-generated manipulations or structural tampering.

I am planning to address this exact architectural implementation in my GSoC 2026 proposal, focusing on integrating the pHash extraction and writing the Rust-based RISC Zero guest circuits.

I would appreciate any thoughts or feedback on whether this approach aligns with the core team's technical roadmap.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions