37 typedef typename Quad<Field>::index_t index_t;
50 static bool circuit(
const char** why,
claims* cl,
54 if (why ==
nullptr || cl ==
nullptr || CIRCUIT ==
nullptr ||
55 PROOF ==
nullptr || CH ==
nullptr) {
61 ts.begin_circuit(CH->q, CH->g);
63 if (V->n1_ == 1 && V->n0_ == 1 && V->v_[0] == F.zero()) {
67 const desire desires[2] = {
68 {V->n1_ == CIRCUIT->nv,
"V->n1_ != CIRCUIT->nv"},
69 {V->n0_ == CIRCUIT->nc,
"V->n0_ != CIRCUIT->nc"},
72 if (!check(why, 2, desires)) {
77 V->bind_all(CIRCUIT->logc, CH->q, F);
78 V->reshape(CIRCUIT->nv);
79 V->bind_all(CIRCUIT->logv, CH->g, F);
88 .logv = CIRCUIT->logv,
89 .claim = {claimV, claimV},
94 return layers(why, cl, CIRCUIT, PROOF, ts, CH, F);
97 VerifierLayers() =
delete;
105 static bool check(
const char** why,
size_t n,
const desire* d) {
106 for (
size_t i = 0; i < n; ++i) {
117 static bool layer_c(
const char** why, Elt* claim,
size_t logc,
118 const LayerProof<Field>* plr, LayerChallenge<Field>* ch,
119 TranscriptSumcheck<Field>& ts,
const Field& F) {
120 for (
size_t round = 0; round < logc; ++round) {
124 auto tp = plr->cp[round];
125 auto t1 = F.subf(*claim, tp.t_[0]);
126 ch->cb[round] = ts.round(plr->cp[round]);
127 auto p = tp.to_poly(t1);
128 *claim = p.eval_lagrange(ch->cb[round], F);
134 static bool layer_h(
const char** why, Elt* claim,
size_t logw,
135 const LayerProof<Field>* plr, LayerChallenge<Field>* ch,
136 TranscriptSumcheck<Field>& ts,
const Field& F) {
137 for (
size_t round = 0; round < logw; ++round) {
138 for (
size_t hand = 0; hand < 2; ++hand) {
142 auto tp = plr->hp[hand][round];
143 auto t1 = F.subf(*claim, tp.t_[0]);
144 ch->hb[hand][round] = ts.round(tp);
145 auto p = tp.to_poly(t1);
146 *claim = p.eval_lagrange(ch->hb[hand][round], F);
154 static bool layers(
const char** why,
claims* cl,
155 const Circuit<Field>* CIRCUIT,
const Proof<Field>* PROOF,
156 TranscriptSumcheck<Field>& ts, Challenge<Field>* CH,
158 for (
size_t ly = 0; ly < CIRCUIT->nl; ++ly) {
159 auto clr = &CIRCUIT->l.at(ly);
160 auto plr = &PROOF->l[ly];
161 auto challenge = &CH->l[ly];
165 ts.begin_layer(challenge->alpha, challenge->beta, ly);
166 Elt claim = F.addf(cl->claim[0], F.mulf(challenge->alpha, cl->claim[1]));
168 if (!layer_c(why, &claim, CIRCUIT->logc, plr, challenge, ts, F)) {
172 if (!layer_h(why, &claim, clr->logw, plr, challenge, ts, F)) {
181 auto QUAD = clr->quad->clone();
182 QUAD->bind_g(cl->logv, cl->g[0], cl->g[1], challenge->alpha,
186 for (
size_t round = 0; round < clr->logw; ++round) {
187 for (
size_t hand = 0; hand < 2; ++hand) {
188 QUAD->bind_h(challenge->hb[hand][round], hand, F);
195 Eq<Field>::eval(CIRCUIT->logc, CIRCUIT->nc, cl->q, challenge->cb, F);
196 F.mul(got, QUAD->scalar());
197 F.mul(got, plr->wc[0]);
198 F.mul(got, plr->wc[1]);
201 *why =
"got != claim (layer)";
206 ts.write(&plr->wc[0], 1, 2);
212 .claim = {plr->wc[0], plr->wc[1]},
214 .g = {challenge->hb[0], challenge->hb[1]},