Skip to content

Commit

Permalink
Merge 8254e6a into dbf2c13
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasxia01 authored Sep 26, 2024
2 parents dbf2c13 + 8254e6a commit 6e72fb1
Show file tree
Hide file tree
Showing 21 changed files with 388 additions and 131 deletions.
Empty file modified barretenberg/cpp/scripts/analyze_client_ivc_bench.py
100644 → 100755
Empty file.
4 changes: 4 additions & 0 deletions barretenberg/cpp/src/barretenberg/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ static constexpr uint32_t CONST_PROOF_SIZE_LOG_N = 28;
// to ensure a constant PG proof size and a PG recursive verifier circuit that is independent of the size of the
// circuits being folded.
static constexpr uint32_t CONST_PG_LOG_N = 20;

static constexpr uint32_t MAX_LOOKUP_TABLES_SIZE = 70000;

static constexpr uint32_t MAX_DATABUS_SIZE = 10;
} // namespace bb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@
#include "barretenberg/stdlib_circuit_builders/ultra_keccak_flavor.hpp"
namespace bb {

template <class Flavor> void ExecutionTrace_<Flavor>::populate_public_inputs_block(Builder& builder)
{
ZoneScopedN("populate_public_inputs_block");
// Update the public inputs block
for (const auto& idx : builder.public_inputs) {
for (size_t wire_idx = 0; wire_idx < NUM_WIRES; ++wire_idx) {
if (wire_idx < 2) { // first two wires get a copy of the public inputs
builder.blocks.pub_inputs.wires[wire_idx].emplace_back(idx);
} else { // the remaining wires get zeros
builder.blocks.pub_inputs.wires[wire_idx].emplace_back(builder.zero_idx);
}
}
for (auto& selector : builder.blocks.pub_inputs.selectors) {
selector.emplace_back(0);
}
}
}

template <class Flavor>
void ExecutionTrace_<Flavor>::populate(Builder& builder, typename Flavor::ProvingKey& proving_key, bool is_structured)
{
Expand Down Expand Up @@ -56,10 +74,13 @@ typename ExecutionTrace_<Flavor>::TraceData ExecutionTrace_<Flavor>::construct_t
Builder& builder, typename Flavor::ProvingKey& proving_key, bool is_structured)
{
ZoneScopedN("construct_trace_data");
TraceData trace_data{ builder, proving_key };

// Complete the public inputs execution trace block from builder.public_inputs
populate_public_inputs_block(builder);
if constexpr (IsPlonkFlavor<Flavor>) {
// Complete the public inputs execution trace block from builder.public_inputs
populate_public_inputs_block(builder);
}

TraceData trace_data{ builder, proving_key };

uint32_t offset = Flavor::has_zero_row ? 1 : 0; // Offset at which to place each block in the trace polynomials
// For each block in the trace, populate wire polys, copy cycles and selector polys
Expand Down Expand Up @@ -87,8 +108,7 @@ typename ExecutionTrace_<Flavor>::TraceData ExecutionTrace_<Flavor>::construct_t
// Insert the selector values for this block into the selector polynomials at the correct offset
// TODO(https://github.com/AztecProtocol/barretenberg/issues/398): implicit arithmetization/flavor consistency
for (size_t selector_idx = 0; selector_idx < NUM_SELECTORS; selector_idx++) {
auto selector_poly = trace_data.selectors[selector_idx];
auto selector = block.selectors[selector_idx];
auto& selector = block.selectors[selector_idx];
for (size_t row_idx = 0; row_idx < block_size; ++row_idx) {
size_t trace_row_idx = row_idx + offset;
trace_data.selectors[selector_idx].set_if_valid_index(trace_row_idx, selector[row_idx]);
Expand All @@ -111,35 +131,19 @@ typename ExecutionTrace_<Flavor>::TraceData ExecutionTrace_<Flavor>::construct_t
return trace_data;
}

template <class Flavor> void ExecutionTrace_<Flavor>::populate_public_inputs_block(Builder& builder)
{
ZoneScopedN("populate_public_inputs_block");
// Update the public inputs block
for (auto& idx : builder.public_inputs) {
for (size_t wire_idx = 0; wire_idx < NUM_WIRES; ++wire_idx) {
if (wire_idx < 2) { // first two wires get a copy of the public inputs
builder.blocks.pub_inputs.wires[wire_idx].emplace_back(idx);
} else { // the remaining wires get zeros
builder.blocks.pub_inputs.wires[wire_idx].emplace_back(builder.zero_idx);
}
}
for (auto& selector : builder.blocks.pub_inputs.selectors) {
selector.emplace_back(0);
}
}
}

template <class Flavor>
void ExecutionTrace_<Flavor>::add_ecc_op_wires_to_proving_key(Builder& builder,
typename Flavor::ProvingKey& proving_key)
requires IsGoblinFlavor<Flavor>
{
// Copy the ecc op data from the conventional wires into the op wires over the range of ecc op gates
auto& ecc_op_selector = proving_key.polynomials.lagrange_ecc_op;
const size_t op_wire_offset = Flavor::has_zero_row ? 1 : 0;

// Copy the ecc op data from the conventional wires into the op wires over the range of ecc op gates
const size_t num_ecc_ops = builder.blocks.ecc_op.size();
for (auto [ecc_op_wire, wire] :
zip_view(proving_key.polynomials.get_ecc_op_wires(), proving_key.polynomials.get_wires())) {
for (size_t i = 0; i < builder.blocks.ecc_op.size(); ++i) {
for (size_t i = 0; i < num_ecc_ops; ++i) {
size_t idx = i + op_wire_offset;
ecc_op_wire.at(idx) = wire[idx];
ecc_op_selector.at(idx) = 1; // construct selector as the indicator on the ecc op block
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ template <class Flavor> class ExecutionTrace_ {
for (auto [selector, other_selector] : zip_view(selectors, proving_key.polynomials.get_selectors())) {
selector = other_selector.share();
}
proving_key.polynomials.set_shifted(); // Ensure shifted wires are set correctly
} else {
// Initialize and share the wire and selector polynomials
for (size_t idx = 0; idx < NUM_WIRES; ++idx) {
Expand Down Expand Up @@ -74,6 +73,14 @@ template <class Flavor> class ExecutionTrace_ {
*/
static void populate(Builder& builder, ProvingKey&, bool is_structured = false);

/**
* @brief Populate the public inputs block
* @details The first two wires are a copy of the public inputs and the other wires and all selectors are zero
*
* @param circuit
*/
static void populate_public_inputs_block(Builder& builder);

private:
/**
* @brief Add the memory records indicating which rows correspond to RAM/ROM reads/writes
Expand Down Expand Up @@ -104,14 +111,6 @@ template <class Flavor> class ExecutionTrace_ {
typename Flavor::ProvingKey& proving_key,
bool is_structured = false);

/**
* @brief Populate the public inputs block
* @details The first two wires are a copy of the public inputs and the other wires and all selectors are zero
*
* @param builder
*/
static void populate_public_inputs_block(Builder& builder);

/**
* @brief Construct and add the goblin ecc op wires to the proving key
* @details The ecc op wires vanish everywhere except on the ecc op block, where they contain a copy of the ecc op
Expand Down
3 changes: 3 additions & 0 deletions barretenberg/cpp/src/barretenberg/flavor/flavor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,9 @@ concept IsGoblinFlavor = IsAnyOf<T, MegaFlavor,
MegaRecursiveFlavor_<UltraCircuitBuilder>,
MegaRecursiveFlavor_<MegaCircuitBuilder>, MegaRecursiveFlavor_<CircuitSimulatorBN254>>;

template <typename T>
concept HasDataBus = IsGoblinFlavor<T>;

template <typename T>
concept IsRecursiveFlavor = IsAnyOf<T, UltraRecursiveFlavor_<UltraCircuitBuilder>,
UltraRecursiveFlavor_<MegaCircuitBuilder>,
Expand Down
2 changes: 1 addition & 1 deletion barretenberg/cpp/src/barretenberg/flavor/flavor.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ TEST(Flavor, Getters)
// set
size_t coset_idx = 0;
for (auto& id_poly : proving_key.polynomials.get_ids()) {
typename Flavor::Polynomial new_poly(proving_key.circuit_size);
id_poly = typename Flavor::Polynomial(proving_key.circuit_size);
for (size_t i = 0; i < proving_key.circuit_size; ++i) {
id_poly.at(i) = coset_idx * proving_key.circuit_size + i;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ template <typename FF, size_t NUM_WIRES, size_t NUM_SELECTORS> class ExecutionTr
Selectors selectors;
bool has_ram_rom = false; // does the block contain RAM/ROM gates
bool is_pub_inputs = false; // is this the public inputs block

uint32_t fixed_size = 0; // Fixed size for use in structured trace
uint32_t trace_offset = 0; // where this block starts in the trace

bool operator==(const ExecutionTraceBlock& other) const = default;

Expand Down Expand Up @@ -104,6 +103,8 @@ template <typename FF, size_t NUM_WIRES, size_t NUM_SELECTORS> class ExecutionTr
}
}
#endif
private:
uint32_t fixed_size = 0; // Fixed size for use in structured trace
};

} // namespace bb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ template <typename FF_> class MegaArith {
aux, lookup, busread, poseidon2_external, poseidon2_internal };
}

auto get_gate_blocks()
{
return RefArray{ arithmetic, delta_range, elliptic, aux,
lookup, busread, poseidon2_external, poseidon2_internal };
}

bool operator==(const MegaTraceBlocks& other) const = default;
};

Expand Down Expand Up @@ -153,7 +159,11 @@ template <typename FF_> class MegaArith {

struct TraceBlocks : public MegaTraceBlocks<MegaTraceBlock> {

E2eStructuredBlockSizes fixed_block_sizes;
TraceBlocks()
{
this->aux.has_ram_rom = true;
this->pub_inputs.is_pub_inputs = true;
}

// Set fixed block sizes for use in structured trace
void set_fixed_block_sizes(TraceStructure setting)
Expand All @@ -178,10 +188,13 @@ template <typename FF_> class MegaArith {
}
}

TraceBlocks()
void compute_offsets(bool is_structured)
{
this->aux.has_ram_rom = true;
this->pub_inputs.is_pub_inputs = true;
uint32_t offset = 1; // start at 1 because the 0th row is unused for selectors for Honk
for (auto& block : this->get()) {
block.trace_offset = offset;
offset += block.get_fixed_size(is_structured);
}
}

void summarize() const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ template <typename FF_> class UltraArith {
aux, lookup, poseidon2_external, poseidon2_internal };
}

auto get_gate_blocks()
{
return RefArray{ arithmetic, delta_range, elliptic, aux, lookup, poseidon2_external, poseidon2_internal };
}

bool operator==(const UltraTraceBlocks& other) const = default;
};

Expand Down Expand Up @@ -90,6 +95,12 @@ template <typename FF_> class UltraArith {

struct TraceBlocks : public UltraTraceBlocks<UltraTraceBlock> {

TraceBlocks()
{
this->aux.has_ram_rom = true;
this->pub_inputs.is_pub_inputs = true;
}

// Set fixed block sizes for use in structured trace
void set_fixed_block_sizes(TraceStructure setting)
{
Expand All @@ -110,10 +121,13 @@ template <typename FF_> class UltraArith {
}
}

TraceBlocks()
void compute_offsets(bool is_structured)
{
this->aux.has_ram_rom = true;
this->pub_inputs.is_pub_inputs = true;
uint32_t offset = 1; // start at 1 because the 0th row is unused for selectors for Honk
for (auto& block : this->get()) {
block.trace_offset = offset;
offset += block.get_fixed_size(is_structured);
}
}

auto get()
Expand All @@ -137,7 +151,7 @@ template <typename FF_> class UltraArith {

size_t get_total_structured_size()
{
size_t total_size = 0;
size_t total_size = 1; // start at 1 because the 0th row is unused for selectors for Honk
for (auto block : this->get()) {
total_size += block.get_fixed_size();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ namespace bb {
template <typename Flavor>
void construct_lookup_table_polynomials(const RefArray<typename Flavor::Polynomial, 4>& table_polynomials,
const typename Flavor::CircuitBuilder& circuit,
size_t dyadic_circuit_size,
size_t additional_offset = 0)
const size_t dyadic_circuit_size,
const size_t additional_offset = 0)
{
// Create lookup selector polynomials which interpolate each table column.
// Our selector polys always need to interpolate the full subgroup size, so here we offset so as to
Expand All @@ -22,8 +22,9 @@ void construct_lookup_table_polynomials(const RefArray<typename Flavor::Polynomi
// | table randomness
// ignored, as used for regular constraints and padding to the next power of 2.
// TODO(https://github.com/AztecProtocol/barretenberg/issues/1033): construct tables and counts at top of trace
ASSERT(dyadic_circuit_size > circuit.get_tables_size() + additional_offset);
size_t offset = dyadic_circuit_size - circuit.get_tables_size() - additional_offset;
const size_t tables_size = circuit.get_tables_size();
ASSERT(dyadic_circuit_size > tables_size + additional_offset);
size_t offset = dyadic_circuit_size - tables_size - additional_offset;

for (const auto& table : circuit.lookup_tables) {
const fr table_index(table.table_index);
Expand All @@ -49,12 +50,12 @@ template <typename Flavor>
void construct_lookup_read_counts(typename Flavor::Polynomial& read_counts,
typename Flavor::Polynomial& read_tags,
typename Flavor::CircuitBuilder& circuit,
size_t dyadic_circuit_size)
const size_t dyadic_circuit_size)
{
const size_t tables_size = circuit.get_tables_size();
// TODO(https://github.com/AztecProtocol/barretenberg/issues/1033): construct tables and counts at top of trace
size_t offset = dyadic_circuit_size - circuit.get_tables_size();
size_t table_offset = dyadic_circuit_size - tables_size;

size_t table_offset = offset; // offset of the present table in the table polynomials
// loop over all tables used in the circuit; each table contains data about the lookups made on it
for (auto& table : circuit.lookup_tables) {
table.initialize_index_map();
Expand Down
Loading

0 comments on commit 6e72fb1

Please sign in to comment.