Longfellow ZK 0290cb32
Loading...
Searching...
No Matches
testing.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_TESTING_H_
16#define PRIVACY_PROOFS_ZK_LIB_SUMCHECK_TESTING_H_
17
18#include <stddef.h>
19
20#include <cstdint>
21#include <memory>
22
23#include "arrays/dense.h"
24#include "random/transcript.h"
25#include "sumcheck/circuit.h"
26#include "sumcheck/prover.h"
27#include "sumcheck/verifier.h"
28#include "util/log.h"
29#include "util/panic.h"
30
31/*
32These are methods that help test modules
33by running the prover or the verifier.
34*/
35namespace proofs {
36template <class Field>
37void run_prover(const Circuit<Field> *C, std::unique_ptr<Dense<Field>> W,
38 Proof<Field> *proof, const Field& F) {
39 typename Prover<Field>::inputs pin;
40
41 Prover<Field> prover(F);
42 auto V = prover.eval_circuit(&pin, C, W->clone(), F);
43
44 check(V != nullptr, "eval_circuit failed.");
45
46 // Ensure the witness satisfies the circuit before making a proof.
47 for (size_t i = 0; i < V->n1_; ++i) {
48 if (V->v_[i] != F.zero()) {
49 log(INFO, "witness failed: non-zero output at %zu", i);
50 }
51 check(V->v_[i] == F.zero(), "witness failed, non-zero output");
52 }
53
54 Transcript tsp((uint8_t *)"testing", 7);
55 prover.prove(proof, nullptr, C, pin, tsp);
56}
57
58template <class Field>
59void run_verifier(const Circuit<Field> *C, std::unique_ptr<Dense<Field>> W,
60 Proof<Field> &proof, const Field& F) {
61 const char *why = "ok";
62 auto V = std::make_unique<Dense<Field>>(F);
63 Transcript tsv((uint8_t *)"testing", 7);
64 check(Verifier<Field>::verify(&why, C, &proof, std::move(V),
65 W->clone(), tsv, F), why);
66}
67} // namespace proofs
68
69#endif // PRIVACY_PROOFS_ZK_LIB_SUMCHECK_TESTING_H_
Definition dense.h:37
Definition prover.h:31
Definition transcript.h:65
Definition circuit.h:45
Definition circuit.h:130