Longfellow ZK 0290cb32
Loading...
Searching...
No Matches
transcript_sumcheck.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_TRANSCRIPT_SUMCHECK_H_
16#define PRIVACY_PROOFS_ZK_LIB_SUMCHECK_TRANSCRIPT_SUMCHECK_H_
17
18#include <stddef.h>
19
20#include "arrays/affine.h"
21#include "arrays/dense.h"
22#include "random/transcript.h"
23#include "sumcheck/circuit.h"
24
25namespace proofs {
26/*
27Fiat-Shamir abstraction for sumcheck protocol.
28This class takes wraps a transcript object and provides the interface for
29sumcheck challenge and response.
30*/
31template <typename Field>
32class TranscriptSumcheck {
33 using Elt = typename Field::Elt;
34 using CPoly = typename Proof<Field>::CPoly;
35 using WPoly = typename Proof<Field>::WPoly;
36 static constexpr size_t kMaxBindings = Proof<Field>::kMaxBindings;
37
38 public:
39 explicit TranscriptSumcheck(Transcript& ts, const Field& F)
40 : ts_(ts), f_(F) {}
41
42 void write_input(const Dense<Field>* X) {
43 // Write column by column to make it compatible with oracle.
44 for (corner_t c = 0; c < X->n0_; ++c) {
45 ts_.write(&X->v_[c], X->n0_, X->n1_, f_);
46 }
47 }
48
49 void begin_circuit(Elt* Q, Elt* G) {
50 ts_.elt(Q, kMaxBindings, f_);
51 ts_.elt(G, kMaxBindings, f_);
52 }
53
54 void begin_layer(Elt& alpha, Elt& beta, size_t layer) {
55 alpha = ts_.elt(f_);
56 beta = ts_.elt(f_);
57 }
58
59 void write(const Elt e[/*n*/], size_t ince, size_t n) {
60 ts_.write(e, ince, n, f_);
61 }
62
63 template <class Poly>
64 Elt /*R*/ round(const Poly& poly) {
65 write_poly(&poly);
66 return ts_.elt(f_);
67 }
68
69 private:
70 template <class Poly>
71 void write_poly(const Poly* poly) {
72 // Do not write the p(1) value to the transcript, as its value is
73 // implied by the constraints, and we can omit it from the proof.
74 for (size_t i = 0; i < Poly::kN; ++i) {
75 if (i != 1) {
76 ts_.write(poly->t_[i], f_);
77 }
78 }
79 }
80 Transcript& ts_;
81 const Field& f_;
82};
83} // namespace proofs
84
85#endif // PRIVACY_PROOFS_ZK_LIB_SUMCHECK_TRANSCRIPT_SUMCHECK_H_
Definition dense.h:37
Definition poly.h:24
Definition transcript.h:65
Definition gf2_128.h:63