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) {
122 Elt got = F.addf(plr->cp[round].t_[0], plr->cp[round].t_[1]);
124 *why =
"got != claim (round_c)";
127 ch->cb[round] = ts.round(plr->cp[round]);
128 *claim = plr->cp[round].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) {
141 F.addf(plr->hp[hand][round].t_[0], plr->hp[hand][round].t_[1]);
143 *why =
"got != claim (round_h)";
146 ch->hb[hand][round] = ts.round(plr->hp[hand][round]);
147 *claim = plr->hp[hand][round].eval_lagrange(ch->hb[hand][round], F);
155 static bool layers(
const char** why,
claims* cl,
156 const Circuit<Field>* CIRCUIT,
const Proof<Field>* PROOF,
157 TranscriptSumcheck<Field>& ts, Challenge<Field>* CH,
159 for (
size_t ly = 0; ly < CIRCUIT->nl; ++ly) {
160 auto clr = &CIRCUIT->l.at(ly);
161 auto plr = &PROOF->l[ly];
162 auto challenge = &CH->l[ly];
166 ts.begin_layer(challenge->alpha, challenge->beta, ly);
167 Elt claim = F.addf(cl->claim[0], F.mulf(challenge->alpha, cl->claim[1]));
169 if (!layer_c(why, &claim, CIRCUIT->logc, plr, challenge, ts, F)) {
173 if (!layer_h(why, &claim, clr->logw, plr, challenge, ts, F)) {
182 auto QUAD = clr->quad->clone();
183 QUAD->bind_g(cl->logv, cl->g[0], cl->g[1], challenge->alpha,
187 for (
size_t round = 0; round < clr->logw; ++round) {
188 for (
size_t hand = 0; hand < 2; ++hand) {
189 QUAD->bind_h(challenge->hb[hand][round], hand, F);
196 Eq<Field>::eval(CIRCUIT->logc, CIRCUIT->nc, cl->q, challenge->cb, F);
197 F.mul(got, QUAD->scalar());
198 F.mul(got, plr->wc[0]);
199 F.mul(got, plr->wc[1]);
202 *why =
"got != claim (layer)";
207 ts.write(&plr->wc[0], 1, 2);
213 .claim = {plr->wc[0], plr->wc[1]},
215 .g = {challenge->hb[0], challenge->hb[1]},