Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: permutation argument optimizations #10960

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,10 @@ class PrivateFunctionExecutionMockCircuitProducer {
mock_databus.populate_kernel_databus(circuit); // populate databus inputs/outputs
ivc.complete_kernel_circuit_logic(circuit); // complete with recursive verifiers etc
} else {
bool use_large_circuit = large_first_app && (circuit_counter == 1); // first circuit is size 2^19
GoblinMockCircuits::construct_mock_app_circuit(circuit, use_large_circuit); // construct mock app
mock_databus.populate_app_databus(circuit); // populate databus outputs
[[maybe_unused]] bool use_large_circuit =
large_first_app && (circuit_counter == 1); // first circuit is size 2^19
GoblinMockCircuits::construct_mock_app_circuit(circuit, false); // construct mock app
mock_databus.populate_app_databus(circuit); // populate databus outputs
}
return circuit;
}
Expand Down
2 changes: 2 additions & 0 deletions barretenberg/cpp/src/barretenberg/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ static constexpr uint32_t CONST_PG_LOG_N = 20;
static constexpr uint32_t CONST_ECCVM_LOG_N = 15;

static constexpr uint32_t MAX_LOOKUP_TABLES_SIZE = 75000;
// static constexpr uint32_t MAX_LOOKUP_TABLES_SIZE = 8;

static constexpr uint32_t MAX_DATABUS_SIZE = 10000;
// static constexpr uint32_t MAX_DATABUS_SIZE = 2;

// The number of entries in ProverPolynomials reserved for randomness intended to mask witness commitments, witness
// evaluation at the sumcheck challenge, and, if necessary, the evaluation of the corresponding shift
Expand Down
2 changes: 2 additions & 0 deletions barretenberg/cpp/src/barretenberg/flavor/flavor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ template <typename FF, typename CommitmentKey_> class ProvingKey_ {

// Ranges of the form [start, end) where witnesses have non-zero values (hence the execution trace is "active")
std::vector<std::pair<size_t, size_t>> active_block_ranges;
// The actual polynomial indices corresposponding to the active block ranges
std::vector<uint32_t> active_idxs;

ProvingKey_() = default;
ProvingKey_(const size_t dyadic_circuit_size,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,33 +224,44 @@ void compute_honk_style_permutation_lagrange_polynomials_from_mapping(
using FF = typename Flavor::FF;
const size_t num_gates = proving_key->circuit_size;

size_t domain_size = proving_key->active_idxs.size();
size_t num_threads = calculate_num_threads(domain_size, /*min_iterations_per_thread=*/1 << 5);
size_t thread_size = domain_size / num_threads;
size_t leftover = domain_size % num_threads;

size_t wire_idx = 0;
for (auto& current_permutation_poly : permutation_polynomials) {
ITERATE_OVER_DOMAIN_START(proving_key->evaluation_domain);
auto idx = static_cast<ptrdiff_t>(i);
const auto& current_row_idx = permutation_mappings[wire_idx].row_idx[idx];
const auto& current_col_idx = permutation_mappings[wire_idx].col_idx[idx];
const auto& current_is_tag = permutation_mappings[wire_idx].is_tag[idx];
const auto& current_is_public_input = permutation_mappings[wire_idx].is_public_input[idx];
if (current_is_public_input) {
// We intentionally want to break the cycles of the public input variables.
// During the witness generation, the left and right wire polynomials at idx i contain the i-th public
// input. The CyclicPermutation created for these variables always start with (i) -> (n+i), followed by
// the indices of the variables in the "real" gates. We make i point to -(i+1), so that the only way of
// repairing the cycle is add the mapping
// -(i+1) -> (n+i)
// These indices are chosen so they can easily be computed by the verifier. They can expect the running
// product to be equal to the "public input delta" that is computed in <honk/utils/grand_product_delta.hpp>
current_permutation_poly.at(i) = -FF(current_row_idx + 1 + num_gates * current_col_idx);
} else if (current_is_tag) {
// Set evaluations to (arbitrary) values disjoint from non-tag values
current_permutation_poly.at(i) = num_gates * Flavor::NUM_WIRES + current_row_idx;
} else {
// For the regular permutation we simply point to the next location by setting the evaluation to its
// idx
current_permutation_poly.at(i) = FF(current_row_idx + num_gates * current_col_idx);
}
ITERATE_OVER_DOMAIN_END;
parallel_for(num_threads, [&](size_t j) {
const size_t start = j * thread_size;
const size_t end = (j == num_threads - 1) ? (j + 1) * thread_size + leftover : (j + 1) * thread_size;
for (size_t i = start; i < end; ++i) {
size_t poly_idx = proving_key->active_idxs[i];
auto idx = static_cast<ptrdiff_t>(poly_idx);
const auto& current_row_idx = permutation_mappings[wire_idx].row_idx[idx];
const auto& current_col_idx = permutation_mappings[wire_idx].col_idx[idx];
const auto& current_is_tag = permutation_mappings[wire_idx].is_tag[idx];
const auto& current_is_public_input = permutation_mappings[wire_idx].is_public_input[idx];
if (current_is_public_input) {
// We intentionally want to break the cycles of the public input variables.
// During the witness generation, the left and right wire polynomials at idx i contain the i-th
// public input. The CyclicPermutation created for these variables always start with (i) -> (n+i),
// followed by the indices of the variables in the "real" gates. We make i point to
// -(i+1), so that the only way of repairing the cycle is add the mapping
// -(i+1) -> (n+i)
// These indices are chosen so they can easily be computed by the verifier. They can expect
// the running product to be equal to the "public input delta" that is computed
// in <honk/utils/grand_product_delta.hpp>
current_permutation_poly.at(poly_idx) = -FF(current_row_idx + 1 + num_gates * current_col_idx);
} else if (current_is_tag) {
// Set evaluations to (arbitrary) values disjoint from non-tag values
current_permutation_poly.at(poly_idx) = num_gates * Flavor::NUM_WIRES + current_row_idx;
} else {
// For the regular permutation we simply point to the next location by setting the
// evaluation to its idx
current_permutation_poly.at(poly_idx) = FF(current_row_idx + num_gates * current_col_idx);
}
}
});
wire_idx++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,17 +275,39 @@ static constexpr TraceStructure SMALL_TEST_STRUCTURE{ .ecc_op = 1 << 14,
* @brief A minimal structuring specifically tailored to the medium complexity transaction of the Client IVC
* benchmark.
*/
static constexpr TraceStructure CLIENT_IVC_BENCH_STRUCTURE{ .ecc_op = 1 << 10,
.busread = 1 << 7,
.lookup = 72000,
.pub_inputs = 1 << 7,
.arithmetic = 198000,
.delta_range = 90000,
.elliptic = 9000,
.aux = 136000,
.poseidon2_external = 2500,
.poseidon2_internal = 14000,
// static constexpr TraceStructure CLIENT_IVC_BENCH_STRUCTURE{ .ecc_op = 1 << 10,
// .busread = 1 << 6,
// .lookup = 36000,
// .pub_inputs = 1 << 6,
// .arithmetic = 84000,
// .delta_range = 45000,
// .elliptic = 9000,
// .aux = 68000,
// .poseidon2_external = 2500,
// .poseidon2_internal = 14000,
// .overflow = 0 };
static constexpr TraceStructure CLIENT_IVC_BENCH_STRUCTURE{ .ecc_op = 1 << 11,
.busread = 1 << 8,
.lookup = 144000,
.pub_inputs = 1 << 8,
.arithmetic = 396000,
.delta_range = 180000,
.elliptic = 18000,
.aux = 272000,
.poseidon2_external = 5000,
.poseidon2_internal = 28000,
.overflow = 0 };
// static constexpr TraceStructure CLIENT_IVC_BENCH_STRUCTURE{ .ecc_op = 1 << 10,
// .busread = 1 << 7,
// .lookup = 72000,
// .pub_inputs = 1 << 7,
// .arithmetic = 198000,
// .delta_range = 90000,
// .elliptic = 9000,
// .aux = 136000,
// .poseidon2_external = 2500,
// .poseidon2_internal = 14000,
// .overflow = 0 };

/**
* @brief An example structuring of size 2^18.
Expand Down
Loading
Loading