Skip to content

zorch.pcs.whir.verifier

WHIR verifier — the verifier half of the multilinear PCS.

verify replays the WHIR rounds from the transcript: it re-derives the folding, out-of-domain and query challenges in the prover's order, checks each round's degree-2 sumcheck message against the running claim, rebuilds the strided query openings from the committed roots, folds each opened 2^k_whir coset as a small MLE at the round's folding challenges (the binary k-fold consistency), and closes on the final-poly constraint. It holds only the public params (code for the RS geometry, tree for the Merkle config) — never the prover's retained codeword.

WhirVerifier dataclass

Bases: VerifierStage[OpeningClaim[WhirCommitment], TrivialClaim, OpeningProof[WhirProof], Transcript]

WHIR PCS verifier. code/tree/params/scheme must match the prover's.

Source code in zorch/pcs/whir/verifier.py
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
@dataclass(frozen=True)
class WhirVerifier(
    VerifierStage[
        OpeningClaim[WhirCommitment],
        TrivialClaim,
        OpeningProof[WhirProof],
        Transcript,
    ]
):
    """WHIR PCS verifier. `code`/`tree`/`params`/`scheme` must
    match the prover's."""

    code: ReedSolomon
    tree: StridedMerkleTree
    params: WhirParams
    scheme: WhirScheme = EqWhirScheme()

    def verify(
        self,
        claim: OpeningClaim[WhirCommitment],
        reduction_proof: OpeningProof[WhirProof],
        transcript: TranscriptT,
    ) -> VerifyResult[TrivialClaim, TranscriptT]:
        """Check the claimed evaluations against the commitment."""
        ok, transcript = self._verify_opening(
            claim.commitment,
            claim.points,
            reduction_proof.values,
            reduction_proof.proof,
            transcript,
        )
        return VerifyResult(TrivialClaim(), transcript, ok)

    def _verify_opening(
        self,
        commitment: WhirCommitment,
        points: Sequence[Array],
        values: Array,
        proof: WhirProof,
        transcript: TranscriptT,
    ) -> tuple[Array, TranscriptT]:
        """Return `(ok, transcript)` where `ok` is a scalar boolean array."""
        if len(points) != 1:
            raise ValueError(f"WHIR opens at one point, got {len(points)}")
        z = points[0]
        m = z.shape[0]
        k = self.params.k_whir
        num_rounds = len(self.params.num_queries)
        if not (0 < num_rounds * k <= m):
            raise ValueError(
                f"num_rounds·k_whir ({num_rounds}·{k}) must fold between 1 and "
                f"num_variables ({m}) inclusive"
            )
        # Fail loud on a structurally malformed proof — a short list would let the
        # round loop silently skip checks (mirrors BasefoldVerifier.verify_batch).
        lengths = {
            "sumcheck_polys": (len(proof.sumcheck_polys), num_rounds * k),
            "folding_pow_witnesses": (len(proof.folding_pow_witnesses), num_rounds * k),
            "query_pow_witnesses": (len(proof.query_pow_witnesses), num_rounds),
            "codeword_roots": (len(proof.codeword_roots), num_rounds - 1),
            "ood_values": (len(proof.ood_values), num_rounds - 1),
            "codeword_openings": (len(proof.codeword_openings), num_rounds - 1),
        }
        bad = {
            name: got_exp
            for name, got_exp in lengths.items()
            if got_exp[0] != got_exp[1]
        }
        if bad:
            raise ValueError(f"malformed WHIR proof: {bad} (got, expected)")
        # This verifier checks a single commitment (one tree); a multi-commitment
        # proof is a prover-side capability its consumer byte-matches without
        # round-tripping here, so reject it loudly rather than silently
        # under-verifying openings 1..n.
        if len(proof.initial_openings) != 1:
            raise ValueError(
                "this verifier checks a single commitment, got "
                f"{len(proof.initial_openings)} initial openings"
            )
        num_polys = proof.initial_openings[0].row.shape[-1]
        if values.ndim != 1 or values.shape[0] != num_polys:
            raise ValueError(
                f"values must be 1-D of length num_polys ({num_polys}), got shape "
                f"{values.shape}"
            )
        # `final_poly` carries the 2^(m − num_rounds·k) residual coefficients in
        # the clear (one coefficient at full fold); a wrong length would surface
        # only as a cryptic shape error inside the jitted body.
        r_dim = m - num_rounds * k
        if proof.final_poly.ndim != 1 or proof.final_poly.shape[0] != (1 << r_dim):
            raise ValueError(
                f"final_poly must be 1-D of length 2^{r_dim} ({1 << r_dim}), got "
                f"shape {proof.final_poly.shape}"
            )
        return _verify_body(self, commitment, z, values, proof, transcript)

verify

verify(
    claim: OpeningClaim[WhirCommitment],
    reduction_proof: OpeningProof[WhirProof],
    transcript: TranscriptT,
) -> VerifyResult[TrivialClaim, TranscriptT]

Check the claimed evaluations against the commitment.

Source code in zorch/pcs/whir/verifier.py
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
def verify(
    self,
    claim: OpeningClaim[WhirCommitment],
    reduction_proof: OpeningProof[WhirProof],
    transcript: TranscriptT,
) -> VerifyResult[TrivialClaim, TranscriptT]:
    """Check the claimed evaluations against the commitment."""
    ok, transcript = self._verify_opening(
        claim.commitment,
        claim.points,
        reduction_proof.values,
        reduction_proof.proof,
        transcript,
    )
    return VerifyResult(TrivialClaim(), transcript, ok)