Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
maramihali committed Nov 6, 2023
1 parent 44da63f commit 7ffc364
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 180 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,38 +220,3 @@ TEST_F(UltraTranscriptTests, StructureTest)
prover.transcript.deserialize_full_transcript();
EXPECT_EQ(static_cast<Flavor::Commitment>(prover.transcript.sorted_accum_comm), one_group_val * rand_val);
}

// TEST_F(UltraTranscriptTests, FoldingManifestTest)
// {
// using Flavor = flavor::Ultra;
// auto composer = UltraComposer();

// std::vector<std::shared_ptr<ProverInstance_<Flavor>>> insts(2);
// std::generate(insts.begin(), insts.end(), [&]() {
// auto builder = proof_system::UltraCircuitBuilder();
// generate_random_test_circuit(builder);
// return composer.create_instance(builder);
// });

// // artificially make first instance relaxed
// auto log_instance_size = static_cast<size_t>(numeric::get_msb(insts[0]->proving_key->circuit_size));
// std::vector<FF> betas(log_instance_size);
// for (size_t idx = 0; idx < log_instance_size; idx++) {
// betas[idx] = FF::random_element();
// }
// insts[0]->folding_parameters = { betas, FF(1) };

// auto prover = composer.create_folding_prover(insts);
// auto verifier = composer.create_folding_verifier(insts);

// auto prover_res = prover.fold_instances();
// verifier.fold_public_parameters(prover_res.folding_data);

// // Check consistency between the manifests generated by the prover and verifier
// auto prover_manifest = prover.transcript.get_manifest();
// auto verifier_manifest = verifier.transcript.get_manifest();
// for (size_t round = 0; round < prover_manifest.size(); ++round) {
// ASSERT_EQ(prover_manifest[round], verifier_manifest[round])
// << "Prover/Verifier manifest discrepency in round " << round;
// }
// }
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ TEST(Protogalaxy, CombinerOn2Instances)
std::vector<std::shared_ptr<ProverInstance>> instance_data(NUM_INSTANCES);
std::array<std::array<Polynomial, Flavor::NUM_ALL_ENTITIES>, NUM_INSTANCES> storage_arrays;
ProtoGalaxyProver prover;
// auto pow_univariate = PowUnivariate<FF>(/*zeta_pow=*/2);
std::vector<FF> pow_betas = { FF(1), FF(2) };
auto alpha = FF(0); // focus on the arithmetic relation only

Expand Down Expand Up @@ -71,7 +70,6 @@ TEST(Protogalaxy, CombinerOn2Instances)
std::vector<std::shared_ptr<ProverInstance>> instance_data(NUM_INSTANCES);
std::array<std::array<Polynomial, Flavor::NUM_ALL_ENTITIES>, NUM_INSTANCES> storage_arrays;
ProtoGalaxyProver prover;
// auto pow_univariate = PowUnivariate<FF>(/*zeta_pow=*/2);
std::vector<FF> pow_betas = { FF(1), FF(2) };
auto alpha = FF(0); // focus on the arithmetic relation only

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,6 @@ def compute_first_example():
accumulator += zeta_pow * relation_value
zeta_pow *= zeta



# accumulator *= extend_one_entity([1, 2])
return accumulator


Expand Down Expand Up @@ -142,12 +139,9 @@ def compute_second_example():
result += rel(w_l, w_r, w_o, q_m, q_l, q_r, q_o, q_c)
result *= 2

# result *= extend_one_entity([1, 2])
return result

if __name__ == "__main__":
# print(f"First example: \n {compute_first_example()}")
# print(f"Second example:\n {compute_second_example()}")
print(compute_first_example())
print(compute_second_example())
print(f"First example: \n {compute_first_example()}")
print(f"Second example:\n {compute_second_example()}")

Original file line number Diff line number Diff line change
Expand Up @@ -200,68 +200,6 @@ TEST_F(ProtoGalaxyTests, CombinerQuotient)
}
}

// TEST_F(ProtoGalaxyTests, Galaxify)
// {
// auto composer = UltraComposer();

// // Create instance from actual circuit
// std::vector<std::shared_ptr<ProverInstance_<Flavor>>> insts(2);
// auto builder = proof_system::UltraCircuitBuilder();
// auto a = FF::random_element();
// auto b = FF::random_element();
// builder.add_variable(a);
// builder.add_public_variable(a);
// builder.add_public_variable(b);
// insts[1] = composer.create_instance(builder);

// auto instance_size = insts[1]->proving_key->circuit_size;
// auto log_instance_size = static_cast<size_t>(numeric::get_msb(instance_size));

// // Create fake accumulator
// std::array<barretenberg::Polynomial<FF>, NUM_POLYNOMIALS> random_polynomials;
// for (auto& poly : random_polynomials) {
// poly = get_random_polynomial(instance_size);
// }
// auto full_polynomials = construct_ultra_full_polynomials(random_polynomials);
// auto relation_parameters = proof_system::RelationParameters<FF>::get_random();
// auto alpha = FF::random_element();

// auto full_honk_evals =
// ProtoGalaxyProver::compute_full_honk_evaluations(full_polynomials, alpha, relation_parameters);
// std::vector<FF> betas(log_instance_size);
// for (size_t idx = 0; idx < log_instance_size; idx++) {
// betas[idx] = FF::random_element();
// }

// // Construct pow(\vec{betas}) as in the paper
// auto pow_beta = ProtoGalaxyProver::compute_pow_polynomial_at_values(betas, instance_size);

// // Compute the corresponding target sum and create a dummy accumulator
// auto target_sum = FF(0);
// for (size_t i = 0; i < instance_size; i++) {
// target_sum += full_honk_evals[i] * pow_beta[i];
// }

// insts[0] = std::make_shared<Instance>(
// FoldingResult<Flavor>{ .folded_prover_polynomials = full_polynomials,
// .folded_public_inputs = std::vector<FF>{},
// .verification_key = std::make_shared<Flavor::VerificationKey>(),
// .folding_parameters = { betas, target_sum } });
// insts[0]->relation_parameters = relation_parameters;

// // artificially make first instance relaxed

// auto prover = composer.create_folding_prover(insts);
// auto verifier = composer.create_folding_verifier(insts);
// prover.prepare_for_folding();
// auto new_target_sum_prover = prover.galaxify(alpha)[0];

// verifier.prepare_for_folding(prover.transcript.proof_data);
// auto new_target_sum_verifier = verifier.galaxify(alpha)[0];
// info(new_target_sum_prover);
// info(new_target_sum_verifier);
// }

TEST_F(ProtoGalaxyTests, FoldChallenges)
{
using Instances = ProverInstances_<Flavor, 2>;
Expand All @@ -283,26 +221,4 @@ TEST_F(ProtoGalaxyTests, FoldChallenges)
EXPECT_EQ(instances.relation_parameters.eta, expected_eta);
}

// namespace proof_system::honk::instance_tests {

// template <class Flavor> class InstancesTests : public testing::Test {
// using FF = typename Flavor::FF;
// using Builder = typename Flavor::CircuitBuilder;

// public:
// static void test_parameters_to_univariates()
// {

// };
// };

// using FlavorTypes = testing::Types<flavor::Ultra>;
// TYPED_TEST_SUITE(InstancesTests, FlavorTypes);

// TYPED_TEST(InstancesTests, ParametersToUnivariates)
// {
// TestFixture::test_parameters_to_univariates();
// }

// } // namespace proof_system::honk::instance_tests
} // namespace protogalaxy_tests
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ template <class ProverInstances> void ProtoGalaxyProver_<ProverInstances>::prepa
transcript.send_to_verifier(domain_separator + "_public_input_" + std::to_string(i), public_input_i);
}

// TODO(https://github.com/AztecProtocol/barretenberg/issues/752): establish whether we can use the same
// grand product parameters for all instances securely
auto [eta, beta, gamma] = transcript.get_challenges(
domain_separator + "_eta", domain_separator + "_beta", domain_separator + "_gamma");
instance->compute_sorted_accumulator_polynomials(eta);
Expand All @@ -41,12 +39,13 @@ ProverFoldingResult<typename ProverInstances::Flavor> ProtoGalaxyProver_<ProverI
prepare_for_folding();
// TODO(#https://github.com/AztecProtocol/barretenberg/issues/740): Handle the case where we are folding for the
// first time and accumulator is 0
// TODO(#https://github.com/AztecProtocol/barretenberg/issues/763): Fold alpha
auto [alpha, delta] = transcript.get_challenges("alpha", "delta");
auto accumulator = get_accumulator();
auto instance_size = accumulator->prover_polynomials[0].size();
const auto log_instance_size = static_cast<size_t>(numeric::get_msb(instance_size));
auto deltas = compute_round_challenge_pows(log_instance_size, delta);
// This is not OK here

auto perturbator = compute_perturbator(accumulator, deltas, alpha);
for (size_t idx = 0; idx <= log_instance_size; idx++) {
transcript.send_to_verifier("perturbator_" + std::to_string(idx), perturbator[idx]);
Expand All @@ -70,31 +69,17 @@ ProverFoldingResult<typename ProverInstances::Flavor> ProtoGalaxyProver_<ProverI
}
auto combiner_challenge = transcript.get_challenge("combiner_qoutient_challenge");
auto combiner_quotient_at_challenge = combiner_quotient.evaluate(combiner_challenge);

// TODO(https://github.com/AztecProtocol/barretenberg/issues/764): Generalise these formulas as well as computation
// of Lagrange basis
auto vanishing_polynomial_at_challenge = combiner_challenge * (combiner_challenge - FF(1));
auto lagrange_0_at_challenge = FF(1) - combiner_challenge;
// auto lagrange_1_at_challenge = combiner_challenge;

auto new_target_sum = compressed_perturbator * lagrange_0_at_challenge +
vanishing_polynomial_at_challenge * combiner_quotient_at_challenge;

// for (size_t idx = 0; idx < accumulator->prover_polynomials.size(); idx++) {
// auto accumulator_poly = accumulator->prover_polynomials[idx];
// auto instance_poly = accumulator->prover_polynomials[idx];
// assert(accumulator_poly.size() == instance_poly.size());
// for (size_t j = 0; j < accumulator_poly.size(); j++) {
// accumulator_poly[j] =
// accumulator_poly[j] * lagrange_0_at_challenge + instance_poly[j] * lagrange_1_at_challenge;
// }
// }

// i have dk evaluations out of which the first k are not good so we evaluate the rest of the polynomials from
// k+1

// we do barycentric evaluation on the combiner

ProverFoldingResult<Flavor> res;
// res.folded_prover_polynomials = accumulator->prover_polynomials;
res.params.target_sum = new_target_sum;
// res.params.gate_separation_challenges = betas_star;
res.folding_data = transcript.proof_data;
return res;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,6 @@ template <class ProverInstances_> class ProtoGalaxyProver_ {
const FF alpha)
{
size_t common_circuit_size = instances[0]->prover_polynomials._data[0].size();
// Precompute the vector of required powers of zeta
// TODO(https://github.com/AztecProtocol/barretenberg/issues/751): Parallelize this.
// NB: there is a similar TODO in the sumcheck function `compute_univariate`.
// std::vector<FF> pow_challenges(common_circuit_size);
// pow_challenges[0] = pow_univariate.partial_evaluation_constant;
// for (size_t i = 1; i < common_circuit_size; ++i) {
// pow_challenges[i] = pow_challenges[i - 1] * pow_univariate.zeta_pow;
// }

// Determine number of threads for multithreading.
// Note: Multithreading is "on" for every round but we reduce the number of threads from the max available based
Expand Down Expand Up @@ -304,7 +296,6 @@ template <class ProverInstances_> class ProtoGalaxyProver_ {
ProverInstances::NUM>
compute_combiner_quotient(FF compressed_perturbator, ExtendedUnivariateWithRandomization combiner)
{
// degree dk - k - 1 = d(k - 1) - 1
std::array<FF, (Flavor::BATCHED_RELATION_TOTAL_LENGTH - 2) * (ProverInstances::NUM - 1)>
combiner_quotient_evals = {};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,34 +60,16 @@ VerifierFoldingResult<typename VerifierInstances::Flavor> ProtoGalaxyVerifier_<
VerifierInstances::NUM>
combiner_quotient(combiner_quotient_evals);
auto combiner_challenge = transcript.get_challenge("combiner_quotient_challenge");
auto combiner_quotient_at_challenge = combiner_quotient.evaluate(combiner_challenge); // K(\gamma)
// WORKTODO make functions for bigger Z and more lagrange basis
auto combiner_quotient_at_challenge = combiner_quotient.evaluate(combiner_challenge);

auto vanishing_polynomial_at_challenge = combiner_challenge * (combiner_challenge - FF(1));
auto lagrange_0_at_challenge = FF(1) - combiner_challenge;
// auto lagrange_1_at_challenge = combiner_challenge;

auto new_target_sum = perturbator_at_challenge * lagrange_0_at_challenge +
vanishing_polynomial_at_challenge * combiner_quotient_at_challenge;

// auto accumulator_public_inputs = accumulator->public_inputs;
// auto other_public_inputs = verifier_instances[1]->public_inputs;
// std::vector<FF> folded_public_inputs(accumulator->public_input_size);
// // extend either with 0s if the sizes are different
// for (size_t idx = 0; idx < folded_public_inputs.size(); idx++) {
// folded_public_inputs[idx] = lagrange_0_at_challenge * accumulator->public_inputs[idx] +
// lagrange_1_at_challenge * other_public_inputs[idx];
// }
// // all verification keys have the same size
// auto folded_verification_key =
// std::make_shared<VerificationKey>(accumulator->instance_size, accumulator->public_input_size);

// for (size_t idx = 0; idx < (*folded_verification_key).size(); idx++) {
// (*folded_verification_key)[idx] = (*accumulator->verification_key)[idx] * lagrange_0_at_challenge +
// (*verifier_instances[1]->verification_key)[idx] * lagrange_1_at_challenge;
// }
VerifierFoldingResult<Flavor> res;
res.parameters.target_sum = new_target_sum;
// res.folded_verification_key = folded_verification_key;
// res.folded_public_inputs = folded_public_inputs;
return res;
}

Expand Down

0 comments on commit 7ffc364

Please sign in to comment.