Skip to content

Commit

Permalink
chore: Protogalaxy only instantiated with Mega (#8949)
Browse files Browse the repository at this point in the history
* removed instantiations of Protogalaxy with Ultra
* fixed CombinerOn2Keys test: now it's working with Mega
  • Loading branch information
iakovenkos authored Oct 2, 2024
1 parent 57d5cfd commit b8d87f1
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ using namespace benchmark;

namespace bb {

template <typename Flavor>
using Flavor = MegaFlavor;

void _bench_round(::benchmark::State& state, void (*F)(ProtogalaxyProver_<DeciderProvingKeys_<Flavor, 2>>&))
{
using Builder = typename Flavor::CircuitBuilder;
Expand Down Expand Up @@ -48,7 +49,7 @@ void _bench_round(::benchmark::State& state, void (*F)(ProtogalaxyProver_<Decide

void bench_round_mega(::benchmark::State& state, void (*F)(ProtogalaxyProver_<DeciderProvingKeys_<MegaFlavor, 2>>&))
{
_bench_round<MegaFlavor>(state, F);
_bench_round(state, F);
}

BENCHMARK_CAPTURE(bench_round_mega, oink, [](auto& prover) { prover.run_oink_prover_on_each_incomplete_key(); })
Expand Down
30 changes: 15 additions & 15 deletions barretenberg/cpp/src/barretenberg/protogalaxy/combiner.test.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include "barretenberg/honk/utils/testing.hpp"
#include "barretenberg/protogalaxy/protogalaxy_prover_internal.hpp"
#include "barretenberg/relations/ultra_arithmetic_relation.hpp"
#include "barretenberg/stdlib_circuit_builders/ultra_flavor.hpp"
#include "barretenberg/stdlib_circuit_builders/mega_flavor.hpp"
#include "barretenberg/ultra_honk/decider_keys.hpp"
#include <gtest/gtest.h>

using namespace bb;

using Flavor = UltraFlavor;
using Flavor = MegaFlavor;
using Polynomial = typename Flavor::Polynomial;
using FF = typename Flavor::FF;

Expand All @@ -34,7 +34,7 @@ TEST(Protogalaxy, CombinerOn2Keys)
};

auto run_test = [&](bool is_random_input) {
// Combiner test on prover polynomisls containing random values, restricted to only the standard arithmetic
// Combiner test on prover polynomials containing random values, restricted to only the standard arithmetic
// relation.
if (is_random_input) {
std::vector<std::shared_ptr<DeciderProvingKey>> keys_data(NUM_KEYS);
Expand All @@ -58,18 +58,18 @@ TEST(Protogalaxy, CombinerOn2Keys)
auto result_no_skipping = Fun::compute_combiner_no_optimistic_skipping(
keys, gate_separators, univariate_relation_parameters_no_skpping, alphas);
// The expected_result values are computed by running the python script combiner_example_gen.py
auto expected_result = Univariate<FF, 12>(std::array<FF, 12>{ 9704UL,
13245288UL,
75534568UL,
224626280UL,
498269160UL,
934211944UL,
1570203368UL,
2443992168UL,
3593327080UL,
5055956840UL,
6869630184UL,
9072095848UL });
auto expected_result = Univariate<FF, 12>(std::array<FF, 12>{ 11480UL,
14117208UL,
78456280UL,
230777432UL,
508829400UL,
950360920UL,
1593120728UL,
2474857560UL,
3633320152UL,
5106257240UL,
6931417560UL,
9146549848UL });
EXPECT_EQ(result_no_skipping, expected_result);
} else {
std::vector<std::shared_ptr<DeciderProvingKey>> keys_data(NUM_KEYS);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,80 +1,62 @@
# TODO(https://github.com/AztecProtocol/barretenberg/issues/760): Delete this?
import numpy as np

# np.set_printoptions(formatter={'int': hex})

import numpy as np

EXTENDED_RELATION_LENGTH = 12

class Row:
# Construct a set of 'all' polynomials with a very simple structure
def __init__(self, base_poly):
# Constuct polys by adding increasing factors of 2 to an input poly
self.q_m = base_poly + 2 * 0
self.q_c = base_poly + 2 * 1
self.q_l = base_poly + 2 * 2
self.q_r = base_poly + 2 * 3
self.q_o = base_poly + 2 * 4
self.q_4 = base_poly + 2 * 5
self.q_arith = base_poly + 2 * 6
self.q_delta_range = base_poly + 2 * 7
self.q_elliptic = base_poly + 2 * 8
self.q_aux = base_poly + 2 * 9
self.q_lookup = base_poly + 2 * 10
self.q_poseidon2_external_1 = base_poly + 2 * 11
self.q_poseidon2_external_2 = base_poly + 2 * 12
self.sigma_1 = base_poly + 2 * 13
self.sigma_2 = base_poly + 2 * 14
self.sigma_3 = base_poly + 2 * 15
self.sigma_4 = base_poly + 2 * 16
self.id_1 = base_poly + 2 * 17
self.id_2 = base_poly + 2 * 18
self.id_3 = base_poly + 2 * 19
self.id_4 = base_poly + 2 * 20
self.table_1 = base_poly + 2 * 21
self.table_2 = base_poly + 2 * 22
self.table_3 = base_poly + 2 * 23
self.table_4 = base_poly + 2 * 24
self.lagrange_first = base_poly + 2 * 25
self.lagrange_last = base_poly + 2 * 26
self.w_l = base_poly + 2 * 27
self.w_r = base_poly + 2 * 28
self.w_o = base_poly + 2 * 29
self.w_4 = base_poly + 2 * 30
self.sorted_accum = base_poly + 2 * 31
self.z_perm = base_poly + 2 * 32
self.z_lookup = base_poly + 2 * 33
self.table_1_shift = base_poly + 2 * 34
self.table_2_shift = base_poly + 2 * 35
self.table_3_shift = base_poly + 2 * 36
self.table_4_shift = base_poly + 2 * 37
self.w_l_shift = base_poly + 2 * 38
self.w_r_shift = base_poly + 2 * 39
self.w_o_shift = base_poly + 2 * 40
self.w_4_shift = base_poly + 2 * 41
self.sorted_accum_shift = base_poly + 2 * 42
self.z_perm_shift = base_poly + 2 * 43
self.z_lookup_shift = base_poly + 2 * 44
# List of all entities in the correct order
self.entity_names = [
'q_m', 'q_c', 'q_l', 'q_r', 'q_o', 'q_4', 'q_arith', 'q_delta_range', 'q_elliptic', 'q_aux',
'q_lookup', 'q_busread', 'q_poseidon2_external_1', 'q_poseidon2_external_2',
'sigma_1', 'sigma_2', 'sigma_3', 'sigma_4',
'id_1', 'id_2', 'id_3', 'id_4',
'table_1', 'table_2', 'table_3', 'table_4',
'lagrange_first', 'lagrange_last', 'lagrange_ecc_op', 'databus_id',
'w_l', 'w_r', 'w_o', 'w_4', 'z_perm',
'lookup_inverses', 'lookup_read_counts', 'lookup_read_tags',
'ecc_op_wire_1', 'ecc_op_wire_2', 'ecc_op_wire_3', 'ecc_op_wire_4',
'calldata', 'calldata_read_counts', 'calldata_read_tags', 'calldata_inverses',
'secondary_calldata', 'secondary_calldata_read_counts', 'secondary_calldata_read_tags',
'secondary_calldata_inverses', 'return_data', 'return_data_read_counts',
'return_data_read_tags', 'return_data_inverses',
'table_1_shift', 'table_2_shift', 'table_3_shift', 'table_4_shift',
'w_l_shift', 'w_r_shift', 'w_o_shift', 'w_4_shift', 'z_perm_shift'
]

# Initialize each entity
for i, name in enumerate(self.entity_names):
setattr(self, name, np.int64(base_poly + 2 * i)) # Convert result to avoid round ups
print(f"{name}: {getattr(self, name)}")

def arith_relation(self):
return self.q_m * self.w_l * self.w_r + self.q_l * self.w_l + self.q_r * self.w_r + self.q_o * self.w_o + self.q_c
return (self.q_m * self.w_l * self.w_r +
self.q_l * self.w_l +
self.q_r * self.w_r +
self.q_o * self.w_o +
self.q_c)


def extend_one_entity(input):
result = input
delta = input[1]-input[0]
result = list(input) # Start with the input as a list
delta = input[1] - input[0]
for _ in range(2, EXTENDED_RELATION_LENGTH):
result.append(delta + result[-1])
return result

def compute_first_example():
# Construct baseline extensions for the two rows; extentions for all polys will be computed via the Row constructor
baseline_extension_0 = np.array(extend_one_entity([0, 128]))
baseline_extension_0 = np.array(extend_one_entity([0, 200]))
baseline_extension_1 = baseline_extension_0 + 1

# Construct extensions for all polys for the two rows in consideration
row_0_extended = Row(baseline_extension_0)
row_1_extended = Row(baseline_extension_1)

accumulator = np.array([0 for _ in range(EXTENDED_RELATION_LENGTH)])
accumulator = np.zeros(EXTENDED_RELATION_LENGTH, dtype=np.int64) # Use np.int64 for the accumulator
zeta_pow = 1
zeta = 2
for row in [row_0_extended, row_1_extended]:
Expand All @@ -88,7 +70,7 @@ def arith_relation(w_l, w_r, w_o, q_m, q_l, q_r, q_o, q_c):
return q_m * w_l * w_r + q_l * w_l + q_r * w_r + q_o * w_o + q_c

result = 0
# 0 1 2 3 4 5 6 7 8 9 10 11 12
# 0 1 2 3 4 5 6 7 8 9 10 11 12
w_l = np.array([ 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25])
w_r = np.array([ 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26])
w_o = np.array([ 3, 7, 11, 15, 19, 23, 27, 31, 35, 39, 43, 47, 51])
Expand All @@ -98,7 +80,7 @@ def arith_relation(w_l, w_r, w_o, q_m, q_l, q_r, q_o, q_c):
q_o = np.array([-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1])
q_c = np.array([ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
# contribution is zero, but why not?
result += arith_relation(w_l, w_r, w_o, q_m, q_l, q_r, q_o, q_c)
result += arith_relation(w_l, w_r, w_o, q_m, q_l, q_r, q_o, q_c)

w_l = np.array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
w_r = np.array([ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4])
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ std::shared_ptr<typename DeciderVerificationKeys::DeciderVK> ProtogalaxyVerifier
return next_accumulator;
}

template class ProtogalaxyVerifier_<DeciderVerificationKeys_<UltraFlavor, 2>>;
template class ProtogalaxyVerifier_<DeciderVerificationKeys_<MegaFlavor, 2>>;

} // namespace bb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include "barretenberg/flavor/flavor.hpp"
#include "barretenberg/protogalaxy/folding_result.hpp"
#include "barretenberg/stdlib_circuit_builders/mega_flavor.hpp"
#include "barretenberg/stdlib_circuit_builders/ultra_flavor.hpp"
#include "barretenberg/transcript/transcript.hpp"
#include "barretenberg/ultra_honk/decider_keys.hpp"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,10 @@ std::shared_ptr<typename DeciderVerificationKeys::DeciderVK> ProtogalaxyRecursiv
}

// Instantiate the template with specific flavors and builders
template class ProtogalaxyRecursiveVerifier_<
RecursiveDeciderVerificationKeys_<UltraRecursiveFlavor_<UltraCircuitBuilder>, 2>>;
template class ProtogalaxyRecursiveVerifier_<
RecursiveDeciderVerificationKeys_<MegaRecursiveFlavor_<MegaCircuitBuilder>, 2>>;
template class ProtogalaxyRecursiveVerifier_<
RecursiveDeciderVerificationKeys_<UltraRecursiveFlavor_<MegaCircuitBuilder>, 2>>;
template class ProtogalaxyRecursiveVerifier_<
RecursiveDeciderVerificationKeys_<MegaRecursiveFlavor_<UltraCircuitBuilder>, 2>>;
template class ProtogalaxyRecursiveVerifier_<
RecursiveDeciderVerificationKeys_<UltraRecursiveFlavor_<CircuitSimulatorBN254>, 2>>;
template class ProtogalaxyRecursiveVerifier_<
RecursiveDeciderVerificationKeys_<MegaRecursiveFlavor_<CircuitSimulatorBN254>, 2>>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "barretenberg/stdlib/protogalaxy_verifier/recursive_decider_verification_keys.hpp"
#include "barretenberg/stdlib/transcript/transcript.hpp"
#include "barretenberg/stdlib_circuit_builders/mega_recursive_flavor.hpp"
#include "barretenberg/stdlib_circuit_builders/ultra_recursive_flavor.hpp"
#include "barretenberg/ultra_honk/decider_keys.hpp"

namespace bb::stdlib::recursion::honk {
Expand Down

0 comments on commit b8d87f1

Please sign in to comment.