NP relations
tl;dr: An NP relation is a formalization of an algorithm that verifies a solution to a problem (in time . For example, verifies if is a valid solution to the Sudoku puzzle . NP relations are extremely helpful when formalizing zero-knowledge proofs as a way of “proving knowledge of a witness such that for a public statement ”.
$ $
$ \def\stmt{\mathbf{x}} \def\witn{\mathbf{w}} % \def\td{\mathsf{td}} % \def\zkpSetup{\mathsf{ZKP}.\mathsf{Setup}} \def\zkpProve{\mathsf{ZKP}.\mathsf{Prove}} \def\zkpVerify{\mathsf{ZKP}.\mathsf{Verify}} \def\zkpSim{\mathsf{ZKP}.\mathsf{Sim}} $
What is an NP relation?
An NP relation is a deterministic algorithm that runs in polynomial time in the length of the statement and the witness and outputs either 0 or 1, based on custom checks it performs on or .
NP relations are a useful mathematical formalization of hard problems () whose solutions () are easy to verify (i.e., in polynomial time).
We often denote as .
Examples
Factoring
is an NP relation that checks if factors into prime factors and : i.e., it outputs 1 if and and and , or outputs 0 otherwise.
For a sufficiently large composite number , it is very hard to find its factors and . In fact, there is no known polynomial-time algorithm (in the bit-length of ) for this problem. In this sense, factoring perfectly illustrates the “hard-to-solve-but-easy-to-verify” nature of NP relations.
Merkle tree membership
is an NP relation that outputs 1 if the Merkle proof correctly attests that is the value of the th leaf in the Merkle tree with root hash . Otherwise, it outputs 0.
Note that a zero-knowledge proof for this relation would allow the prover to hide the position of the leaf and its Merkle proof , while convincing the verifier that the value is (somewhere) in the tree. This can be very useful. For example, anonymous payment schemes like Zcash are built on top of such a relation!
Merkle proof aggregation
is an NP relation that outputs 1 if, for all , the Merkle proof correctly attests that is the value of the th leaf in the Merkle tree with root hash . Otherwise, it outputs 0.
A succinct (not necessarily zero-knowledge) proof for this relation would allow the prover to “compress” the proofs for the values. For an example of such a succinct proof when the Merkle tree is algebraic, see our Hyperproofs paper.