Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void ClientIVC::accumulate(ClientCircuit& circuit, const std::shared_ptr<Verific
circuit.add_recursive_proof(stdlib::recursion::init_default_agg_obj_indices<ClientCircuit>(circuit));

// Construct the prover instance for circuit
prover_instance = std::make_shared<ProverInstance>(circuit, trace_structure);
auto prover_instance = std::make_shared<ProverInstance>(circuit, trace_structure);

// Track the maximum size of each block for all circuits porcessed (for debugging purposes only)
max_block_size_tracker.update(circuit);
Expand Down Expand Up @@ -67,7 +67,7 @@ void ClientIVC::accumulate(ClientCircuit& circuit, const std::shared_ptr<Verific
*/
ClientIVC::Proof ClientIVC::prove()
{
ZoneScoped;
ZoneScopedN("ClientIVC::prove");
max_block_size_tracker.print(); // print minimum structured sizes for each block
return { fold_output.proof, decider_prove(), goblin.prove() };
};
Expand All @@ -78,6 +78,7 @@ bool ClientIVC::verify(const Proof& proof,
const std::shared_ptr<ClientIVC::ECCVMVerificationKey>& eccvm_vk,
const std::shared_ptr<ClientIVC::TranslatorVerificationKey>& translator_vk)
{
ZoneScopedN("ClientIVC::verify");
// Goblin verification (merge, eccvm, translator)
GoblinVerifier goblin_verifier{ eccvm_vk, translator_vk };
bool goblin_verified = goblin_verifier.verify(proof.goblin_proof);
Expand Down Expand Up @@ -111,6 +112,7 @@ bool ClientIVC::verify(Proof& proof, const std::vector<std::shared_ptr<VerifierI
*/
HonkProof ClientIVC::decider_prove() const
{
ZoneScopedN("ClientIVC::decider_prove");
MegaDeciderProver decider_prover(fold_output.accumulator);
return decider_prover.construct_proof();
}
Expand Down
3 changes: 0 additions & 3 deletions barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ class ClientIVC {
ProverFoldOutput fold_output;
std::shared_ptr<ProverInstance> prover_accumulator;
std::shared_ptr<VerifierInstance> verifier_accumulator;
// Note: We need to save the last instance that was folded in order to compute its verification key, this will not
// be needed in the real IVC as they are provided as inputs
std::shared_ptr<ProverInstance> prover_instance;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

main deletion here to free up memory

std::shared_ptr<VerificationKey> instance_vk;

// A flag indicating whether or not to construct a structured trace in the ProverInstance
Expand Down
33 changes: 27 additions & 6 deletions barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class ClientIVCTests : public ::testing::Test {
*/
static bool prove_and_verify(ClientIVC& ivc)
{
ZoneScopedN("ClientIVC::prove_and_verify");
auto proof = ivc.prove();

auto verifier_inst = std::make_shared<VerifierInstance>(ivc.instance_vk);
Expand Down Expand Up @@ -73,13 +74,33 @@ TEST_F(ClientIVCTests, Basic)
{
ClientIVC ivc;

// Initialize the IVC with an arbitrary circuit
Builder circuit_0 = create_mock_circuit(ivc);
ivc.accumulate(circuit_0);
{
// Initialize the IVC with an arbitrary circuit
Builder circuit_0 = create_mock_circuit(ivc);
ivc.accumulate(circuit_0);
}

// Create another circuit and accumulate
Builder circuit_1 = create_mock_circuit(ivc);
ivc.accumulate(circuit_1);
{
// Create another circuit and accumulate
Builder circuit_1 = create_mock_circuit(ivc);
ivc.accumulate(circuit_1);
}

EXPECT_TRUE(prove_and_verify(ivc));
};

/**
* @brief A simple-as-possible test demonstrating IVC for three mock circuits
*
*/
TEST_F(ClientIVCTests, BasicThree)
{
ClientIVC ivc;

for (size_t idx = 0; idx < 3; ++idx) {
Builder circuit = create_mock_circuit(ivc);
ivc.accumulate(circuit);
}

EXPECT_TRUE(prove_and_verify(ivc));
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ TEST_F(MockKernelTest, PinFoldingKernelSizes)
ivc.accumulate(circuit_2);
ivc.accumulate(kernel_circuit);

EXPECT_EQ(ivc.prover_instance->proving_key.log_circuit_size, 17);
EXPECT_EQ(ivc.fold_output.accumulator->proving_key.log_circuit_size, 17);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

core change here is that we don't store the prover_instance anymore, but we can just get the size from the accumulator instead.

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,20 @@ void ExecutionTrace_<Flavor>::populate(Builder& builder, typename Flavor::Provin
proving_key.pub_inputs_offset = trace_data.pub_inputs_offset;
}
if constexpr (IsUltraPlonkOrHonk<Flavor>) {
ZoneScopedN("add_memory_records_to_proving_key");
add_memory_records_to_proving_key(trace_data, builder, proving_key);
}

if constexpr (IsGoblinFlavor<Flavor>) {
ZoneScopedN("add_ecc_op_wires_to_proving_key");
add_ecc_op_wires_to_proving_key(builder, proving_key);
}

// Compute the permutation argument polynomials (sigma/id) and add them to proving key
compute_permutation_argument_polynomials<Flavor>(builder, &proving_key, trace_data.copy_cycles);
{
ZoneScopedN("compute_permutation_argument_polynomials");
compute_permutation_argument_polynomials<Flavor>(builder, &proving_key, trace_data.copy_cycles);
}
}

template <class Flavor>
Expand All @@ -50,6 +55,7 @@ template <class Flavor>
typename ExecutionTrace_<Flavor>::TraceData ExecutionTrace_<Flavor>::construct_trace_data(
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
Expand All @@ -73,15 +79,18 @@ typename ExecutionTrace_<Flavor>::TraceData ExecutionTrace_<Flavor>::construct_t

// Update wire polynomials and copy cycles
// NB: The order of row/column loops is arbitrary but needs to be row/column to match old copy_cycle code
for (uint32_t block_row_idx = 0; block_row_idx < block_size; ++block_row_idx) {
for (uint32_t wire_idx = 0; wire_idx < NUM_WIRES; ++wire_idx) {
uint32_t var_idx = block.wires[wire_idx][block_row_idx]; // an index into the variables array
uint32_t real_var_idx = builder.real_variable_index[var_idx];
uint32_t trace_row_idx = block_row_idx + offset;
// Insert the real witness values from this block into the wire polys at the correct offset
trace_data.wires[wire_idx][trace_row_idx] = builder.get_variable(var_idx);
// Add the address of the witness value to its corresponding copy cycle
trace_data.copy_cycles[real_var_idx].emplace_back(cycle_node{ wire_idx, trace_row_idx });
{
ZoneScopedN("populating wires and copy_cycles");
for (uint32_t block_row_idx = 0; block_row_idx < block_size; ++block_row_idx) {
for (uint32_t wire_idx = 0; wire_idx < NUM_WIRES; ++wire_idx) {
uint32_t var_idx = block.wires[wire_idx][block_row_idx]; // an index into the variables array
uint32_t real_var_idx = builder.real_variable_index[var_idx];
uint32_t trace_row_idx = block_row_idx + offset;
// Insert the real witness values from this block into the wire polys at the correct offset
trace_data.wires[wire_idx][trace_row_idx] = builder.get_variable(var_idx);
// Add the address of the witness value to its corresponding copy cycle
trace_data.copy_cycles[real_var_idx].emplace_back(cycle_node{ wire_idx, trace_row_idx });
}
}
}

Expand Down Expand Up @@ -117,8 +126,7 @@ typename ExecutionTrace_<Flavor>::TraceData ExecutionTrace_<Flavor>::construct_t

template <class Flavor> void ExecutionTrace_<Flavor>::populate_public_inputs_block(Builder& builder)
{
ZoneScopedN("populate block");

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,43 +31,33 @@ template <class Flavor> class ExecutionTrace_ {

TraceData(Builder& builder, ProvingKey& proving_key)
{
ZoneScopedN("TraceData construction");
ZoneScopedN("TraceData constructor");
if constexpr (IsHonkFlavor<Flavor>) {
{
ZoneScopedN("wires initialization");
// Initialize and share the wire and selector polynomials
for (auto [wire, other_wire] : zip_view(wires, proving_key.polynomials.get_wires())) {
wire = other_wire.share();
}
// Initialize and share the wire and selector polynomials
for (auto [wire, other_wire] : zip_view(wires, proving_key.polynomials.get_wires())) {
wire = other_wire.share();
}
{
ZoneScopedN("selector initialization");
for (auto [selector, other_selector] :
zip_view(selectors, proving_key.polynomials.get_selectors())) {
selector = other_selector.share();
}
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 {
{
ZoneScopedN("wires initialization");
// Initialize and share the wire and selector polynomials
for (size_t idx = 0; idx < NUM_WIRES; ++idx) {
wires[idx] = Polynomial(proving_key.circuit_size);
std::string wire_tag = "w_" + std::to_string(idx + 1) + "_lagrange";
proving_key.polynomial_store.put(wire_tag, wires[idx].share());
}
// Initialize and share the wire and selector polynomials
for (size_t idx = 0; idx < NUM_WIRES; ++idx) {
wires[idx] = Polynomial(proving_key.circuit_size);
std::string wire_tag = "w_" + std::to_string(idx + 1) + "_lagrange";
proving_key.polynomial_store.put(wire_tag, wires[idx].share());
}
{
ZoneScopedN("selector initialization");
for (size_t idx = 0; idx < NUM_USED_SELECTORS; ++idx) {
selectors[idx] = Polynomial(proving_key.circuit_size);
std::string selector_tag = builder.selector_names[idx] + "_lagrange";
proving_key.polynomial_store.put(selector_tag, selectors[idx].share());
}
for (size_t idx = 0; idx < Builder::Arithmetization::NUM_SELECTORS; ++idx) {
selectors[idx] = Polynomial(proving_key.circuit_size);
std::string selector_tag = builder.selector_names[idx] + "_lagrange";
proving_key.polynomial_store.put(selector_tag, selectors[idx].share());
}
}
copy_cycles.resize(builder.variables.size());
{
ZoneScopedN("copy cycle initialization");
copy_cycles.resize(builder.variables.size());
}
}
};

Expand Down
5 changes: 4 additions & 1 deletion barretenberg/cpp/src/barretenberg/flavor/flavor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ template <typename FF, typename CommitmentKey_> class ProvingKey_ {
ProvingKey_() = default;
ProvingKey_(const size_t circuit_size, const size_t num_public_inputs)
{
this->commitment_key = std::make_shared<CommitmentKey_>(circuit_size + 1);
{
ZoneScopedN("init commitment key");
this->commitment_key = std::make_shared<CommitmentKey_>(circuit_size + 1);
}
this->evaluation_domain = bb::EvaluationDomain<FF>(circuit_size, circuit_size);
this->circuit_size = circuit_size;
this->log_circuit_size = numeric::get_msb(circuit_size);
Expand Down
11 changes: 9 additions & 2 deletions barretenberg/cpp/src/barretenberg/goblin/goblin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,16 @@ class GoblinProver {
*/
GoblinProof prove(MergeProof merge_proof_in = {})
{
ZoneScopedN("Goblin::prove");
goblin_proof.merge_proof = merge_proof_in.empty() ? std::move(merge_proof) : std::move(merge_proof_in);
prove_eccvm();
prove_translator();
{
ZoneScopedN("prove_eccvm");
prove_eccvm();
}
{
ZoneScopedN("prove_translator");
prove_translator();
}
return goblin_proof;
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ template <size_t NUM_WIRES, bool generalized> struct PermutationMapping {
*/
PermutationMapping(size_t circuit_size)
{
ZoneScopedN("PermutationMapping constructor");
for (uint8_t col_idx = 0; col_idx < NUM_WIRES; ++col_idx) {
sigmas[col_idx].reserve(circuit_size);
if constexpr (generalized) {
Expand Down Expand Up @@ -109,13 +110,13 @@ PermutationMapping<Flavor::NUM_WIRES, generalized> compute_permutation_mapping(

// Go through each cycle
size_t cycle_index = 0;
for (auto& copy_cycle : wire_copy_cycles) {
for (const auto& copy_cycle : wire_copy_cycles) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some changes Facundo suggested (not sure how impactful they are since the compiler is pretty smart usually)

for (size_t node_idx = 0; node_idx < copy_cycle.size(); ++node_idx) {
// Get the indices of the current node and next node in the cycle
cycle_node current_cycle_node = copy_cycle[node_idx];
const cycle_node& current_cycle_node = copy_cycle[node_idx];
// If current node is the last one in the cycle, then the next one is the first one
size_t next_cycle_node_index = (node_idx == copy_cycle.size() - 1 ? 0 : node_idx + 1);
cycle_node next_cycle_node = copy_cycle[next_cycle_node_index];
const cycle_node& next_cycle_node = copy_cycle[next_cycle_node_index];
const auto current_row = current_cycle_node.gate_index;
const auto next_row = next_cycle_node.gate_index;

Expand Down Expand Up @@ -383,10 +384,16 @@ void compute_permutation_argument_polynomials(const typename Flavor::CircuitBuil
}
} else if constexpr (IsUltraFlavor<Flavor>) { // any UltraHonk flavor
// Compute Honk-style sigma and ID polynomials from the corresponding mappings
compute_honk_style_permutation_lagrange_polynomials_from_mapping<Flavor>(
key->polynomials.get_sigmas(), mapping.sigmas, key);
compute_honk_style_permutation_lagrange_polynomials_from_mapping<Flavor>(
key->polynomials.get_ids(), mapping.ids, key);
{
ZoneScopedN("compute_honk_style_permutation_lagrange_polynomials_from_mapping");
compute_honk_style_permutation_lagrange_polynomials_from_mapping<Flavor>(
key->polynomials.get_sigmas(), mapping.sigmas, key);
}
{
ZoneScopedN("compute_honk_style_permutation_lagrange_polynomials_from_mapping");
compute_honk_style_permutation_lagrange_polynomials_from_mapping<Flavor>(
key->polynomials.get_ids(), mapping.ids, key);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ template <class ProverInstances>
void ProtoGalaxyProver_<ProverInstances>::finalise_and_send_instance(std::shared_ptr<Instance> instance,
const std::string& domain_separator)
{
ZoneScopedN("ProtoGalaxyProver::finalise_and_send_instance");
OinkProver<Flavor> oink_prover(instance->proving_key, transcript, domain_separator + '_');

auto [proving_key, relation_params, alphas] = oink_prover.prove();
Expand Down Expand Up @@ -408,6 +409,7 @@ template <class ProverInstances> void ProtoGalaxyProver_<ProverInstances>::accum
template <class ProverInstances>
FoldingResult<typename ProverInstances::Flavor> ProtoGalaxyProver_<ProverInstances>::prove()
{
ZoneScopedN("ProtogalaxyProver::prove");
BB_OP_COUNT_TIME_NAME("ProtogalaxyProver::prove");
// Ensure instances are all of the same size
for (size_t idx = 0; idx < ProverInstances::NUM - 1; ++idx) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ template <typename Curve>
std::shared_ptr<bb::srs::factories::ProverCrs<Curve>> FileCrsFactory<Curve>::get_prover_crs(size_t degree)
{
if (degree != degree_ || !prover_crs_) {
ZoneScopedN("get_prover_crs");
prover_crs_ = std::make_shared<FileProverCrs<Curve>>(degree, path_);
degree_ = degree;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ template <typename Curve> class FileProverCrs : public ProverCrs<Curve> {
FileProverCrs(const size_t num_points, std::string const& path)
: num_points(num_points)
{
ZoneScopedN("FileProverCrs constructor");
monomials_ = scalar_multiplication::point_table_alloc<typename Curve::AffineElement>(num_points);

srs::IO<Curve>::read_transcript_g1(monomials_.get(), num_points, path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ class UltraFlavor {
PartiallyEvaluatedMultivariates() = default;
PartiallyEvaluatedMultivariates(const size_t circuit_size)
{
ZoneScopedN("PartiallyEvaluatedMultivariates constructor");
// Storage is only needed after the first partial evaluation, hence polynomials of
// size (n / 2)
for (auto& poly : this->get_all()) {
Expand Down
33 changes: 19 additions & 14 deletions barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,21 +222,26 @@ template <typename Flavor> class SumcheckProver {
// compute_univariate also takes into account the zk_sumcheck_data.
auto round_univariate = round.compute_univariate(
round_idx, full_polynomials, relation_parameters, pow_univariate, alpha, zk_sumcheck_data);
// Place the evaluations of the round univariate into transcript.
transcript->send_to_verifier("Sumcheck:univariate_0", round_univariate);
FF round_challenge = transcript->template get_challenge<FF>("Sumcheck:u_0");
multivariate_challenge.emplace_back(round_challenge);
// Prepare sumcheck book-keeping table for the next round
partially_evaluate(full_polynomials, multivariate_n, round_challenge);
// Prepare ZK Sumcheck data for the next round
if constexpr (Flavor::HasZK) {
update_zk_sumcheck_data(zk_sumcheck_data, round_challenge, round_idx);
};
pow_univariate.partially_evaluate(round_challenge);
round.round_size = round.round_size >> 1; // TODO(#224)(Cody): Maybe partially_evaluate should do this and
// release memory? // All but final round
// We operate on partially_evaluated_polynomials in place.
{
ZoneScopedN("rest of sumcheck round 1");

// Place the evaluations of the round univariate into transcript.
transcript->send_to_verifier("Sumcheck:univariate_0", round_univariate);
FF round_challenge = transcript->template get_challenge<FF>("Sumcheck:u_0");
multivariate_challenge.emplace_back(round_challenge);
// Prepare sumcheck book-keeping table for the next round
partially_evaluate(full_polynomials, multivariate_n, round_challenge);
// Prepare ZK Sumcheck data for the next round
if constexpr (Flavor::HasZK) {
update_zk_sumcheck_data(zk_sumcheck_data, round_challenge, round_idx);
};
pow_univariate.partially_evaluate(round_challenge);
round.round_size = round.round_size >> 1; // TODO(#224)(Cody): Maybe partially_evaluate should do this and
// release memory? // All but final round
// We operate on partially_evaluated_polynomials in place.
}
for (size_t round_idx = 1; round_idx < multivariate_d; round_idx++) {
ZoneScopedN("sumcheck loop");
// Write the round univariate to the transcript
round_univariate = round.compute_univariate(round_idx,
partially_evaluated_polynomials,
Expand Down
Loading