Longfellow ZK 0290cb32
Loading...
Searching...
No Matches
verifier.h
1// Copyright 2025 Google LLC.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef PRIVACY_PROOFS_ZK_LIB_SUMCHECK_VERIFIER_H_
16#define PRIVACY_PROOFS_ZK_LIB_SUMCHECK_VERIFIER_H_
17
18#include <stddef.h>
19
20#include <memory>
21
22#include "arrays/dense.h"
23#include "random/transcript.h"
24#include "sumcheck/circuit.h"
25#include "sumcheck/transcript_sumcheck.h"
26#include "sumcheck/verifier_layers.h"
27
28namespace proofs {
29// Full sumcheck verifier that verifies the layers
30// via verifier_layers<> and then checks the input
31// binding directly.
32template <class Field>
33class Verifier : public VerifierLayers<Field> {
34 using super = VerifierLayers<Field>;
35 using typename super::claims;
36 using typename super::Elt;
37
38 public:
39 static bool verify(const char** why, const Circuit<Field>* circ,
40 const Proof<Field>* proof,
41 std::unique_ptr<Dense<Field>> V,
42 std::unique_ptr<Dense<Field>> X, Transcript& ts,
43 const Field& F) {
44 if (why == nullptr || circ == nullptr || proof == nullptr ||
45 V == nullptr || X == nullptr) {
46 return false;
47 }
48
49 claims cl{};
50 Challenge<Field> ch(circ->nl);
52 tss.write_input(X.get());
53
54 if (!(super::circuit(why, &cl, circ, proof, &ch, std::move(V), tss,
55 F))) {
56 return false;
57 }
58
59 // Final check on W, the input wires.
60 // bind the copy variables:
61 X->bind_all(circ->logc, cl.q, F);
62 X->reshape(cl.nv);
63
64 // bind the gate variables, for two hands:
65 auto X1 = X->clone();
66 Dense<Field>* VH[2] = {X.get(), X1.get()};
67
68 for (size_t hand = 0; hand < 2; ++hand) {
69 VH[hand]->bind_all(cl.logv, cl.g[hand], F);
70 Elt got = VH[hand]->scalar();
71 if (got != cl.claim[hand]) {
72 *why = "got != cl.claim[hand]";
73 return false;
74 }
75 }
76
77 return true;
78 }
79
80 Verifier() = delete;
81};
82} // namespace proofs
83
84#endif // PRIVACY_PROOFS_ZK_LIB_SUMCHECK_VERIFIER_H_
Definition dense.h:37
Definition transcript_sumcheck.h:32
Definition transcript.h:65
Definition circuit.h:115
Definition circuit.h:45
Definition circuit.h:130
Definition verifier_layers.h:40