Longfellow ZK 0290cb32
Loading...
Searching...
No Matches
zk_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_ZK_ZK_VERIFIER_H_
16#define PRIVACY_PROOFS_ZK_LIB_ZK_ZK_VERIFIER_H_
17
18#include <stddef.h>
19
20#include <vector>
21
22#include "arrays/dense.h"
23#include "ligero/ligero_param.h"
24#include "ligero/ligero_verifier.h"
25#include "random/transcript.h"
26#include "sumcheck/circuit.h"
27#include "util/log.h"
28#include "zk/zk_common.h"
29#include "zk/zk_proof.h"
30
31namespace proofs {
32// ZK Verifier
33//
34// Verifies a zk proof. See note in the prover for the design.
35// To verify a proof, instantiate the class, then call recv_commitment with
36// the commitment, and finally call verify. It is possible to receive several
37// commitments, or run other protocols between the recv_commitment and verify
38// calls. This allows composing two proofs in parallel.
39// To support this, the interface to both accepts a raw Transcript.
40template <class Field, class RSFactory>
41class ZkVerifier {
42 using Elt = typename Field::Elt;
43
44 public:
45 explicit ZkVerifier(const Circuit<Field>& c, const RSFactory& rsf,
46 size_t rate, size_t nreq, const Field& F)
47 : circ_(c),
48 n_witness_(c.ninputs - c.npub_in),
49 param_(n_witness_ + ZkCommon<Field>::pad_size(c), c.nl, rate, nreq),
50 lqc_(c.nl),
51 rsf_(rsf),
52 f_(F) {
53 ZkCommon<Field>::setup_lqc(c, lqc_, n_witness_);
54 }
55
56 void recv_commitment(const ZkProof<Field>& zk, Transcript& t) const {
57 log(INFO, "verifier: recv commit");
58 LigeroVerifier<Field, RSFactory>::receive_commitment(zk.com, t);
59 }
60
61 // Verifies the proof.
62 bool verify(const ZkProof<Field>& zk, const Dense<Field>& pub,
63 Transcript& tv) const {
64 log(INFO, "verifier: verify");
65
66 ZkCommon<Field>::initialize_sumcheck_fiat_shamir(tv, circ_, pub, f_);
67
68 // Derive constraints on the witness.
70 std::vector<Llc> A;
71 std::vector<Elt> b;
72 const LigeroHash hash_of_A{0xde, 0xad, 0xbe, 0xef};
73 size_t cn = ZkCommon<Field>::verifier_constraints(circ_, pub, zk.proof,
74 /*aux=*/nullptr, A, b, tv,
75 n_witness_, f_);
76
77 const char* why = "";
78 bool ok = LigeroVerifier<Field, RSFactory>::verify(
79 &why, param_, zk.com, zk.com_proof, tv, cn, A.size(), &A[0], hash_of_A,
80 &b[0], &lqc_[0], rsf_, f_);
81
82 log(INFO, "verify done: %s", why);
83 return ok;
84 }
85
86 private:
87 const Circuit<Field>& circ_;
88 const size_t n_witness_;
89 const LigeroParam<Field> param_;
90 std::vector<LigeroQuadraticConstraint> lqc_;
91 const RSFactory& rsf_;
92 const Field& f_;
93};
94} // namespace proofs
95
96#endif // PRIVACY_PROOFS_ZK_LIB_ZK_ZK_VERIFIER_H_
Definition dense.h:37
Definition transcript.h:65
Definition circuit.h:45
Definition gf2_128.h:63
Definition ligero_param.h:426
Definition ligero_param.h:344
Definition ligero_param.h:117
Definition zk_proof.h:47