Skip to content

Commit

Permalink
debugging prints
Browse files Browse the repository at this point in the history
  • Loading branch information
ledwards2225 committed Aug 16, 2023
1 parent 8991b98 commit 9015f23
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,18 @@ template <typename Curve> class ShplonkVerifier_ {
std::span<const OpeningClaim<Curve>> claims,
auto& transcript)
{

const size_t num_claims = claims.size();

const Fr nu = transcript.get_challenge("Shplonk:nu");

size_t prev_num_gates = 0;
(void)prev_num_gates;
if constexpr (Curve::is_stdlib_type) {
// info("Shplonk, init: num gates = ", nu.get_context().get_num_gates());
prev_num_gates = nu.get_context()->get_num_gates();
}

auto Q_commitment = transcript.template receive_from_prover<Commitment>("Shplonk:Q");

const Fr z_challenge = transcript.get_challenge("Shplonk:z");
Expand Down Expand Up @@ -226,15 +234,20 @@ template <typename Curve> class ShplonkVerifier_ {
current_nu *= nu;
}

// If recursion, perform [G] -= ∑ⱼ ρʲ / ( r − xⱼ )⋅[fⱼ] via batch_mul
// If recursion, do batch mul to compute [G] -= ∑ⱼ ρʲ / ( r − xⱼ )⋅[fⱼ]
if constexpr (Curve::is_stdlib_type) {
info("Shplonk: inversions, adds: num gates = ", nu.get_context()->get_num_gates() - prev_num_gates);
prev_num_gates = nu.get_context()->get_num_gates();
G_commitment -= GroupElement::batch_mul(commitments, scalars);
info("Shplonk: batch mul: num gates = ", nu.get_context()->get_num_gates() - prev_num_gates);
prev_num_gates = nu.get_context()->get_num_gates();
}

// [G] += G₀⋅[1] = [G] + (∑ⱼ ρʲ ⋅ vⱼ / ( r − xⱼ ))⋅[1]
if constexpr (Curve::is_stdlib_type) {
auto ctx = nu.get_context();
G_commitment += GroupElement::one(ctx) * G_commitment_constant;
info("Shplonk: final mul add: num gates = ", nu.get_context()->get_num_gates() - prev_num_gates);
} else {
// GroupElement sort_of_one{ x, y };
G_commitment += vk->srs->get_first_g1() * G_commitment_constant;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ template <typename Flavor> bool UltraRecursiveVerifier_<Flavor>::verify_proof(co

RelationParameters<FF> relation_parameters;

transcript = Transcript<Builder>{ builder, proof.proof_data };
size_t prev_num_gates = builder->get_num_gates();

transcript = Transcript<Builder>{ builder, proof.proof_data };

auto commitments = VerifierCommitments(key);
auto commitment_labels = CommitmentLabels();

Expand All @@ -66,8 +68,6 @@ template <typename Flavor> bool UltraRecursiveVerifier_<Flavor>::verify_proof(co
auto public_input_size_native = static_cast<size_t>(public_input_size.get_value());
auto pub_inputs_offset_native = static_cast<size_t>(pub_inputs_offset.get_value());

info("1. num gates = ", builder->get_num_gates());

if (circuit_size_native != key->circuit_size) {
return false;
}
Expand Down Expand Up @@ -109,15 +109,11 @@ template <typename Flavor> bool UltraRecursiveVerifier_<Flavor>::verify_proof(co
// Get permutation challenges
auto [beta, gamma] = transcript.get_challenges("beta", "gamma");

info("2. num gates = ", builder->get_num_gates());

const FF public_input_delta = proof_system::honk::compute_public_input_delta<Flavor>(
public_inputs, beta, gamma, circuit_size, pub_inputs_offset_native);
const FF lookup_grand_product_delta =
proof_system::honk::compute_lookup_grand_product_delta<FF>(beta, gamma, circuit_size);

info("3. num gates = ", builder->get_num_gates());

relation_parameters.beta = beta;
relation_parameters.gamma = gamma;
relation_parameters.public_input_delta = public_input_delta;
Expand All @@ -132,7 +128,8 @@ template <typename Flavor> bool UltraRecursiveVerifier_<Flavor>::verify_proof(co

std::optional sumcheck_output = sumcheck.verify(relation_parameters, transcript);

info("4. num gates = ", builder->get_num_gates());
info("Sumcheck: num gates = ", builder->get_num_gates() - prev_num_gates);
prev_num_gates = builder->get_num_gates();

// // Note(luke): Temporary. Done only to complete manifest through sumcheck. Delete once we proceed to Gemini.
// [[maybe_unused]] FF rho = transcript.get_challenge("rho");
Expand All @@ -157,7 +154,8 @@ template <typename Flavor> bool UltraRecursiveVerifier_<Flavor>::verify_proof(co
++evaluation_idx;
}

info("5. num gates = ", builder->get_num_gates());
info("Batched eval: num gates = ", builder->get_num_gates() - prev_num_gates);
prev_num_gates = builder->get_num_gates();

// Construct vectors of scalars for batched unshifted and to-be-shifted commitments
const size_t NUM_UNSHIFTED = commitments.get_unshifted().size();
Expand All @@ -177,10 +175,12 @@ template <typename Flavor> bool UltraRecursiveVerifier_<Flavor>::verify_proof(co

// Batch the commitments to the unshifted and to-be-shifted polynomials using powers of rho
auto batched_commitment_unshifted = GroupElement::batch_mul(commitments.get_unshifted(), scalars_unshifted);
info("6. num gates = ", builder->get_num_gates());
info("Batch mul (unshifted): num gates = ", builder->get_num_gates() - prev_num_gates);
prev_num_gates = builder->get_num_gates();
auto batched_commitment_to_be_shifted =
GroupElement::batch_mul(commitments.get_to_be_shifted(), scalars_to_be_shifted);
info("7. num gates = ", builder->get_num_gates());
info("Batch mul (to-be-shited): num gates = ", builder->get_num_gates() - prev_num_gates);
prev_num_gates = builder->get_num_gates();

// Produce a Gemini claim consisting of:
// - d+1 commitments [Fold_{r}^(0)], [Fold_{-r}^(0)], and [Fold^(l)], l = 1:d-1
Expand All @@ -191,15 +191,18 @@ template <typename Flavor> bool UltraRecursiveVerifier_<Flavor>::verify_proof(co
batched_commitment_to_be_shifted,
transcript);

info("8. num gates = ", builder->get_num_gates());
info("Gemini: num gates = ", builder->get_num_gates() - prev_num_gates);
prev_num_gates = builder->get_num_gates();
// // Note(luke): Temporary. Done only to complete manifest through Gemini. Delete once we proceed to Shplonk.
// [[maybe_unused]] FF nu = transcript.get_challenge("Shplonk:nu");

// Produce a Shplonk claim: commitment [Q] - [Q_z], evaluation zero (at random challenge z)
auto shplonk_claim = Shplonk::reduce_verification(pcs_verification_key, gemini_claim, transcript);
(void)shplonk_claim;
info("9. num gates = ", builder->get_num_gates());
info("Shplonk: num gates = ", builder->get_num_gates() - prev_num_gates);
prev_num_gates = builder->get_num_gates();

info("Total: num gates = ", builder->get_num_gates());
// DEBUG!
return true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,21 @@ template <typename OuterComposer> class RecursiveVerifierTest : public testing::

big_a* big_b;

// const size_t num_gates = 1 << 17;
// for (size_t i = 0; i < num_gates; ++i) {
// fr a = fr::random_element();
// uint32_t a_idx = builder.add_variable(a);

// fr b = fr::random_element();
// fr c = fr::random_element();
// fr d = a + b + c;
// uint32_t b_idx = builder.add_variable(b);
// uint32_t c_idx = builder.add_variable(c);
// uint32_t d_idx = builder.add_variable(d);

// builder.create_big_add_gate({ a_idx, b_idx, c_idx, d_idx, fr(1), fr(1), fr(1), fr(-1), fr(0) });
// }
// WORKTODO: this provides a way to set the circuit size of the proof to be recursively verified. Formalize this a bit
const size_t num_gates = 1 << 10;
for (size_t i = 0; i < num_gates; ++i) {
fr a = fr::random_element();
uint32_t a_idx = builder.add_variable(a);

fr b = fr::random_element();
fr c = fr::random_element();
fr d = a + b + c;
uint32_t b_idx = builder.add_variable(b);
uint32_t c_idx = builder.add_variable(c);
uint32_t d_idx = builder.add_variable(d);

builder.create_big_add_gate({ a_idx, b_idx, c_idx, d_idx, fr(1), fr(1), fr(1), fr(-1), fr(0) });
}
};

static void create_outer_circuit(InnerBuilder& inner_circuit, OuterBuilder& outer_builder)
Expand All @@ -85,6 +86,8 @@ template <typename OuterComposer> class RecursiveVerifierTest : public testing::
auto prover = inner_composer.create_prover(inner_circuit);
auto proof_to_recursively_verify = prover.construct_proof();

info("Inner circuit size = ", prover.key->circuit_size);

// Compute native verification key
const auto native_verification_key = inner_composer.compute_verification_key(inner_circuit);

Expand All @@ -105,8 +108,8 @@ template <typename OuterComposer> class RecursiveVerifierTest : public testing::
auto recursive_manifest = verifier.transcript.get_manifest();
auto native_manifest = native_verifier.transcript.get_manifest();
// Note: Recursive manifest currently goes only though sumcheck
recursive_manifest.print();
native_manifest.print();
// recursive_manifest.print();
// native_manifest.print();
for (size_t i = 0; i < recursive_manifest.size(); ++i) {
EXPECT_EQ(recursive_manifest[i], native_manifest[i]);
}
Expand Down

0 comments on commit 9015f23

Please sign in to comment.