docsTechnicalSmart ContractsSecrets codes validator

Secret Codes Validator (On-Chain ZKP)

The on-chain secret codes validator leverages Zero-Knowledge Proofs (ZKP)—powerful cryptographic methods that allow users to prove knowledge of a secret without ever revealing it on the blockchain. This means users can claim rewards for completing a challenge without exposing any sensitive or critical information.

What Are Zero-Knowledge Proofs?

Zero-Knowledge Proofs (ZK Proofs) are a set of cryptographic techniques that allow one party (the prover) to demonstrate to another party (the verifier) that a statement is true, without revealing any additional information beyond the fact that the statement is indeed true.

  • ZK Proofs are not mathematical “proofs” in the strictest sense, as there is a small chance—known as the soundness error—that a dishonest prover could convince the verifier of a false statement.
  • In the context of Web3 and blockchain, ZK Proofs are crucial for privacy and scalability. For example, they allow confidential verification of transactions or computations, hiding underlying data while proving validity.

A key objective of ZKPs is that a verifier (V) can delegate a costly computation to an untrusted prover (P), saving the verifier effort and resources while still being able to trust the result.

To build intuition, it helps to study interactive proof systems—protocols between two parties:

  • The prover (unlimited computational power, knows a true statement)
  • The verifier (limited resources, wants to verify the statement)

These protocols require two properties:

  • Completeness: If both parties are honest and the statement is true, the prover can always convince the verifier.
  • Soundness: If the statement is false, a dishonest prover should not be able to convince the verifier (except with a very small probability).

Why Use Zero-Knowledge Proofs?

ZKPs provide several important benefits:

  • Privacy:
    Users can prove they possess information (like a secret code) without disclosing it, preserving privacy.
  • Security:
    No sensitive data is transmitted or stored, reducing the risk of leaks or unauthorized access.
  • Trust:
    Credentials or identities can be verified without sharing all the underlying information.
  • Legal Compliance:
    Minimal personal data exposure helps comply with privacy regulations.
  • Versatility:
    ZKPs can be used for blockchain, secure authentication, and communications.

Preventing Front-Running

Front-running occurs when someone observes a pending transaction in the mempool (for example, a reward claim) and submits their own transaction with a higher gas fee to take advantage and “cut in line.”
ZKPs allow sensitive transaction details (such as codes, amounts, recipients, or conditions) to be hidden while still proving the transaction is valid.

Example:
In CryptoTrophy, if a user receives a winning code and submits a transaction to claim a prize, another user monitoring the mempool could try to “steal” the code by submitting their own transaction with a higher gas fee. With ZKPs, the claim is validated without ever revealing the code, protecting users from such attacks.

Common ZKP Applications in Web3

  • Proving membership in a community without revealing identity
  • Verifying age without exposing the birth date
  • Voting while preserving anonymity

How It Works

Creating an on-chain ZKP validator is complex, but modern tools make the process more accessible.

Conceptual diagram: ZKP contract creation steps

At a high level, our implementation uses:

  • circom to construct the ZKP circuit.
  • snarkjs to generate and verify the zero-knowledge proofs.

Zero-Knowledge Proofs enable secure, privacy-preserving workflows for blockchain rewards, making advanced challenge mechanics possible—without sacrificing user privacy.