Skip to content

[Feature] Complete Zero-Knowledge Proof Integration for Privacy-Preserving Meter Readings and Tamper Detection #25

Description

@KarenZita01

Description

The zk_tests.rs (3KB) contains test structures for zero-knowledge proof integration, but there is no actual ZK proof verification logic. The tamper_detection.rs (1.3KB) is a stub with minimal implementation. These modules suggest planned ZK-verified meter readings and tamper-proof reporting, but the implementation is not yet complete. For a utility metering protocol, cryptographic guarantee of meter reading integrity is critical.

ZK/tamper gaps:

  • zk_tests.rs contains test placeholders but no actual ZK verification
  • tamper_detection.rs defines TamperEvent struct but has no detection logic
  • No Merkle tree or accumulator for batch meter reading verification
  • No zk-SNARK/stark verifier integration (needs Groth16 or PLONK verifier on Soroban)
  • Meter readings are stored as plain values with only ED25519 signatures; no zero-knowledge privacy for consumption data
  • No proof-of-location for meter registration (preventing geolocation spoofing)

Technical Context & Impact

  • Affected Components/Files: contracts/utility_contracts/src/zk_tests.rs, contracts/utility_contracts/src/tamper_detection.rs, contracts/utility_contracts/src/lib.rs
  • Impact: Privacy, Data Integrity, Regulatory Compliance

Step-by-Step Implementation Guide

  1. Research Soroban ZK capability: Evaluate available ZK verifiers for Soroban (currently experimental); explore groth16-solana or bellman integration via Soroban host functions
  2. Design ZK circuit for meter readings: Define public inputs (meter_id, timestamp, commitment) and private inputs (actual consumption, user_id)
  3. Implement verify_zk_proof(proof: Bytes, public_inputs: Vec<Bytes>) -> bool: Start with a placeholder that accepts proof format and calls verifier, with graceful fallback to non-ZK mode until verifier is available
  4. Complete tamper detection: Implement detect_tamper(meter_id, readings: Vec<SignedReading>) -> TamperDetectionResult:
    • Check reading sequence: validate readings are monotonically increasing
    • Check reading frequency: flag if readings arrive too frequently (suggests replay)
    • Check cross-meter correlation: flag anomalies vs. neighborhood meters
  5. Add Merkle tree for batch verification: Store DataKey::ReadingMerkleRoot(period) for batch proving all readings in a billing period
  6. Add proof-of-location: Optional register_meter_location(meter_id, geo_hash, signature) using blockchain-based geolocation oracle
  7. Privacy mode: Allow meters to submit H(consumption || salt) instead of raw consumption, revealing only on billing via ZK proof

Verification & Testing Steps

  1. Run existing ZK tests: cargo test zk_tests (should pass with placeholder)
  2. Create mock ZK verifier for testing: test proof generation -> verification roundtrip
  3. Test tamper detection with normal readings (no alert) vs anomalous readings (alert raised)
  4. Test Merkle tree: submit 100 readings -> compute root -> verify individual proof
  5. Test privacy mode: encrypted consumption submitted -> admin cannot read individual consumption -> ZK proof verifies billing total
  6. Run full test suite: cargo test --package utility_contracts

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