Skip to content

Commit

Permalink
more stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
maramihali committed Jan 19, 2024
1 parent 2a772e0 commit 06089f7
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 176 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ bool ProtoGalaxyVerifier_<VerifierInstances>::verify_folding_proof(std::vector<u
}

if (perturbator_coeffs[0] != accumulator->target_sum) {
info("here");
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@ std::array<typename Flavor::GroupElement, 2> DeciderRecursiveVerifier_<Flavor>::
transcript = std::make_shared<Transcript>(builder, proof.proof_data);
auto inst = std::make_unique<Instance>();

auto instance_size = transcript->template receive_from_prover<uint32_t>("instance_size");
auto public_input_size = transcript->template receive_from_prover<uint32_t>("public_input_size");
inst->instance_size = static_cast<size_t>(instance_size.get_value());
inst->public_input_size = static_cast<size_t>(public_input_size.get_value());
inst->log_instance_size = static_cast<size_t>(numeric::get_msb(inst->instance_size));
const auto instance_size = transcript->template receive_from_prover<uint32_t>("instance_size");
const auto public_input_size = transcript->template receive_from_prover<uint32_t>("public_input_size");
const auto log_instance_size =
static_cast<size_t>(numeric::get_msb(static_cast<size_t>(instance_size.get_value())));

for (size_t i = 0; i < inst->public_input_size; ++i) {
for (size_t i = 0; i < static_cast<size_t>(public_input_size.get_value()); ++i) {
auto public_input_i = transcript->template receive_from_prover<FF>("public_input_" + std::to_string(i));
inst->public_inputs.emplace_back(public_input_i);
}
Expand All @@ -50,14 +49,13 @@ std::array<typename Flavor::GroupElement, 2> DeciderRecursiveVerifier_<Flavor>::
RelationParameters<FF>{ eta, beta, gamma, public_input_delta, lookup_grand_product_delta };

for (size_t idx = 0; idx < NUM_SUBRELATIONS - 1; idx++) {

inst->alphas[idx] = transcript->template receive_from_prover<FF>("alpha" + std::to_string(idx));
}

inst->target_sum = transcript->template receive_from_prover<FF>("target_sum");

inst->gate_challenges = std::vector<FF>(inst->log_instance_size);
for (size_t idx = 0; idx < inst->log_instance_size; idx++) {
inst->gate_challenges = std::vector<FF>(log_instance_size);
for (size_t idx = 0; idx < log_instance_size; idx++) {
inst->gate_challenges[idx] =
transcript->template receive_from_prover<FF>("gate_challenge_" + std::to_string(idx));
}
Expand All @@ -76,7 +74,7 @@ std::array<typename Flavor::GroupElement, 2> DeciderRecursiveVerifier_<Flavor>::

VerifierCommitments commitments{ inst->verification_key, inst->witness_commitments };

auto sumcheck = Sumcheck(inst->log_instance_size, transcript, inst->target_sum);
auto sumcheck = Sumcheck(log_instance_size, transcript, inst->target_sum);

auto [multivariate_challenge, claimed_evaluations, sumcheck_verified] =
sumcheck.verify(inst->relation_parameters, inst->alphas, inst->gate_challenges);
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ void ProtoGalaxyRecursiveVerifier_<VerifierInstances>::receive_accumulator(const
const auto instance_size = transcript->template receive_from_prover<uint32_t>(domain_separator + "_instance_size");
const auto public_input_size =
transcript->template receive_from_prover<uint32_t>(domain_separator + "_public_input_size");
inst->instance_size = static_cast<size_t>(instance_size.get_value());
inst->log_instance_size = static_cast<size_t>(numeric::get_msb(inst->instance_size));
inst->public_input_size = static_cast<size_t>(public_input_size.get_value());
inst->instance_size = uint32_t(instance_size.get_value());
inst->log_instance_size = uint32_t(numeric::get_msb(inst->instance_size));
inst->public_input_size = uint32_t(public_input_size.get_value());

for (size_t i = 0; i < inst->public_input_size; ++i) {
auto public_input_i =
Expand Down Expand Up @@ -63,9 +63,9 @@ void ProtoGalaxyRecursiveVerifier_<VerifierInstances>::receive_and_finalise_inst
const auto instance_size = transcript->template receive_from_prover<uint32_t>(domain_separator + "_instance_size");
const auto public_input_size =
transcript->template receive_from_prover<uint32_t>(domain_separator + "_public_input_size");
inst->instance_size = static_cast<size_t>(instance_size.get_value());
inst->instance_size = static_cast<size_t>(uint256_t(instance_size.get_value()));
inst->log_instance_size = static_cast<size_t>(numeric::get_msb(inst->instance_size));
inst->public_input_size = static_cast<size_t>(public_input_size.get_value());
inst->public_input_size = static_cast<size_t>(uint256_t(public_input_size.get_value()));

for (size_t i = 0; i < inst->public_input_size; ++i) {
auto public_input_i =
Expand Down Expand Up @@ -154,6 +154,7 @@ void ProtoGalaxyRecursiveVerifier_<VerifierInstances>::verify_folding_proof(std:
using Transcript = typename Flavor::Transcript;
using ElementNative = typename Flavor::Curve::ElementNative;
using AffineElementNative = typename Flavor::Curve::AffineElementNative;
using ScalarNative = typename Flavor::Curve::ScalarFieldNative;

transcript = std::make_shared<Transcript>(builder, proof);
prepare_for_folding();
Expand All @@ -167,7 +168,12 @@ void ProtoGalaxyRecursiveVerifier_<VerifierInstances>::verify_folding_proof(std:
perturbator_coeffs[idx] = transcript->template receive_from_prover<FF>("perturbator_" + std::to_string(idx));
}

accumulator->target_sum.assert_equal(perturbator_coeffs[0], "F(0) != e");
// TODO(): As currently the stdlib transcript is not creating proper constraints linked to Fiat-Shamir we add an
// additonal gate to ensure assert_equal is correct. This comparison to 0 can be removed here and below once we have
// merged the transcript.
auto zero = FF::from_witness(builder, ScalarNative(0));
zero.assert_equal(accumulator->target_sum - perturbator_coeffs[0], "F(0) != e");

FF perturbator_challenge = transcript->get_challenge("perturbator_challenge");

auto perturbator_at_challenge = evaluate_perturbator(perturbator_coeffs, perturbator_challenge);
Expand All @@ -189,12 +195,13 @@ void ProtoGalaxyRecursiveVerifier_<VerifierInstances>::verify_folding_proof(std:
auto expected_next_target_sum =
perturbator_at_challenge * lagranges[0] + vanishing_polynomial_at_challenge * combiner_quotient_at_challenge;
auto next_target_sum = transcript->template receive_from_prover<FF>("next_target_sum");
expected_next_target_sum.assert_equal(next_target_sum, "next target sum mismatch");
zero.assert_equal(expected_next_target_sum - next_target_sum, "next target sum mismatch");

auto expected_betas_star = update_gate_challenges(perturbator_challenge, accumulator->gate_challenges, deltas);
for (size_t idx = 0; idx < accumulator->log_instance_size; idx++) {
auto beta_star = transcript->template receive_from_prover<FF>("next_gate_challenge_" + std::to_string(idx));
expected_betas_star[idx].assert_equal(beta_star, " next gate challenge mismatch at: " + std::to_string(idx));
zero.assert_equal(beta_star - expected_betas_star[idx],
" next gate challenge mismatch at: " + std::to_string(idx));
}

// Compute ϕ and verify against the data received from the prover
Expand All @@ -209,10 +216,10 @@ void ProtoGalaxyRecursiveVerifier_<VerifierInstances>::verify_folding_proof(std:
expected_comm = expected_comm + instance->witness_commitments.get_all()[comm_idx] * lagranges[inst];
inst++;
}
expected_comm -= random_generator;
auto comm = transcript->template receive_from_prover<Commitment>("next_" + witness_labels[comm_idx]);
comm.x.assert_equal(expected_comm.x);
comm.y.assert_equal(expected_comm.y);
auto res = expected_comm - comm;
random_generator.x.assert_equal(res.x);
random_generator.y.assert_equal(res.y);
comm_idx++;
}

Expand All @@ -225,7 +232,7 @@ void ProtoGalaxyRecursiveVerifier_<VerifierInstances>::verify_folding_proof(std:
inst++;
}
auto next_el = transcript->template receive_from_prover<FF>("next_public_input" + std::to_string(el_idx));
next_el.assert_equal(expected_el, "folded public input mismatch at: " + std::to_string(el_idx));
zero.assert_equal(expected_el - next_el, "folded public input mismatch at: " + std::to_string(el_idx));
el_idx++;
}

Expand All @@ -237,7 +244,8 @@ void ProtoGalaxyRecursiveVerifier_<VerifierInstances>::verify_folding_proof(std:
instance_idx++;
}
auto next_alpha = transcript->template receive_from_prover<FF>("next_alpha_" + std::to_string(alpha_idx));
next_alpha.assert_equal(expected_alpha, "folded relation separator mismatch at: " + std::to_string(alpha_idx));
zero.assert_equal(expected_alpha - next_alpha,
"folded relation separator mismatch at: " + std::to_string(alpha_idx));
}

auto expected_parameters = proof_system::RelationParameters<FF>{};
Expand All @@ -253,22 +261,22 @@ void ProtoGalaxyRecursiveVerifier_<VerifierInstances>::verify_folding_proof(std:
}

auto next_eta = transcript->template receive_from_prover<FF>("next_eta");
next_eta.assert_equal(expected_parameters.eta, "relation parameter eta mismatch");
zero.assert_equal(expected_parameters.eta - next_eta, "relation parameter eta mismatch");

auto next_beta = transcript->template receive_from_prover<FF>("next_beta");
next_beta.assert_equal(expected_parameters.beta, "relation parameter beta mismatch");
zero.assert_equal(expected_parameters.beta - next_beta, "relation parameter beta mismatch");

auto next_gamma = transcript->template receive_from_prover<FF>("next_gamma");
next_gamma.assert_equal(expected_parameters.gamma, "relation parameter gamma mismatch");
zero.assert_equal(expected_parameters.gamma - next_gamma, "relation parameter gamma mismatch");

auto next_public_input_delta = transcript->template receive_from_prover<FF>("next_public_input_delta");
next_public_input_delta.assert_equal(expected_parameters.public_input_delta,
"relation parameter public input delta mismatch");
zero.assert_equal(expected_parameters.public_input_delta - next_public_input_delta,
"relation parameter public input delta mismatch");

auto next_lookup_grand_product_delta =
transcript->template receive_from_prover<FF>("next_lookup_grand_product_delta");
next_lookup_grand_product_delta.assert_equal(expected_parameters.lookup_grand_product_delta,
"relation parameter lookup grand product delta mismatch");
zero.assert_equal(expected_parameters.lookup_grand_product_delta - next_lookup_grand_product_delta,
"relation parameter lookup grand product delta mismatch");

auto acc_vk = std::make_shared<VerificationKey>(instances[0]->instance_size, instances[0]->public_input_size);
auto vk_labels = commitment_labels.get_precomputed();
Expand All @@ -281,9 +289,9 @@ void ProtoGalaxyRecursiveVerifier_<VerifierInstances>::verify_folding_proof(std:
inst++;
}
auto vk = transcript->template receive_from_prover<Commitment>("next_" + vk_labels[vk_idx]);
expected_vk -= random_generator;
vk.x.assert_equal(expected_vk.x);
vk.y.assert_equal(expected_vk.y);
auto res = expected_vk - vk;
random_generator.x.assert_equal(res.x);
random_generator.y.assert_equal(res.y);
vk_idx++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ template <class VerifierInstances> class ProtoGalaxyRecursiveVerifier_ {
* @details In the recursive setting this function doesn't return anything because the equality checks performed by
* the recursive verifier, ensuring the folded ϕ*, e* and β* on the verifier side correspond to what has been sent
* by the prover, are expressed as constraints.
*/
void verify_folding_proof(std::vector<uint8_t> proof);

Expand Down
Loading

0 comments on commit 06089f7

Please sign in to comment.