Skip to content

Commit

Permalink
chore(bb): small compile improvements (#6665)
Browse files Browse the repository at this point in the history
seems to save about 30seconds building bb bench binaries
  • Loading branch information
ludamad authored May 24, 2024
1 parent 37c50ba commit 61f27b7
Show file tree
Hide file tree
Showing 20 changed files with 67 additions and 44 deletions.
15 changes: 7 additions & 8 deletions barretenberg/cpp/src/barretenberg/common/assert.hpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
#pragma once
#include <cassert>
#include <iostream>
#include <stdexcept>
#include <string>

// NOLINTBEGIN
#if NDEBUG
// Compiler should optimize this out in release builds, without triggering an unused variable warning.
#define DONT_EVALUATE(expression) \
{ \
true ? static_cast<void>(0) : static_cast<void>((expression)); \
}

// NOLINTBEGIN

#if NDEBUG
#define ASSERT(expression) DONT_EVALUATE((expression))
#else
// cassert in wasi-sdk takes one second to compile, only include if needed
#include <cassert>
#include <iostream>
#include <stdexcept>
#include <string>
#define ASSERT(expression) assert((expression))
#endif // NDEBUG

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Note: this is split up from protogalaxy_prover_impl.hpp for compile performance reasons
#include "barretenberg/flavor/flavor.hpp"
#include "barretenberg/ultra_honk/oink_prover.hpp"
#include "protogalaxy_prover_impl.hpp"
namespace bb {

template class ProtoGalaxyProver_<ProverInstances_<GoblinUltraFlavor, 2>>;
template class ProtoGalaxyProver_<ProverInstances_<GoblinUltraFlavor, 3>>;
template class ProtoGalaxyProver_<ProverInstances_<GoblinUltraFlavor, 4>>;
} // namespace bb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "protogalaxy_prover.hpp"
#pragma once
#include "barretenberg/flavor/flavor.hpp"
#include "barretenberg/ultra_honk/oink_prover.hpp"
#include "protogalaxy_prover.hpp"
namespace bb {
template <class ProverInstances>
void ProtoGalaxyProver_<ProverInstances>::finalise_and_send_instance(std::shared_ptr<Instance> instance,
Expand Down Expand Up @@ -207,13 +208,4 @@ FoldingResult<typename ProverInstances::Flavor> ProtoGalaxyProver_<ProverInstanc

return state.result;
}

template class ProtoGalaxyProver_<ProverInstances_<UltraFlavor, 2>>;
template class ProtoGalaxyProver_<ProverInstances_<GoblinUltraFlavor, 2>>;

template class ProtoGalaxyProver_<ProverInstances_<UltraFlavor, 3>>;
template class ProtoGalaxyProver_<ProverInstances_<GoblinUltraFlavor, 3>>;

template class ProtoGalaxyProver_<ProverInstances_<UltraFlavor, 4>>;
template class ProtoGalaxyProver_<ProverInstances_<GoblinUltraFlavor, 4>>;
} // namespace bb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Note: this is split up from protogalaxy_prover_impl.hpp for compile performance reasons
#include "protogalaxy_prover_impl.hpp"

namespace bb {
template class ProtoGalaxyProver_<ProverInstances_<UltraFlavor, 2>>;
template class ProtoGalaxyProver_<ProverInstances_<UltraFlavor, 3>>;
template class ProtoGalaxyProver_<ProverInstances_<UltraFlavor, 4>>;
} // namespace bb
15 changes: 8 additions & 7 deletions barretenberg/cpp/src/barretenberg/relations/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "barretenberg/flavor/flavor.hpp"
#include "barretenberg/polynomials/pow.hpp"
#include "barretenberg/relations/relation_parameters.hpp"
#include <tuple>
namespace bb {

template <typename Flavor> class RelationUtils {
Expand Down Expand Up @@ -54,10 +55,10 @@ template <typename Flavor> class RelationUtils {
*/
static void zero_univariates(auto& tuple)
{
auto set_to_zero = []<size_t, size_t>(auto& element) {
std::fill(element.evaluations.begin(), element.evaluations.end(), FF(0));
auto set_to_zero = [](auto&&... elements) {
(std::fill(elements.evaluations.begin(), elements.evaluations.end(), FF(0)), ...);
};
apply_to_tuple_of_tuples(tuple, set_to_zero);
std::apply([&](auto&&... args) { (std::apply(set_to_zero, args), ...); }, tuple);
}

/**
Expand Down Expand Up @@ -91,11 +92,11 @@ template <typename Flavor> class RelationUtils {
static void scale_univariates(auto& tuple, const RelationSeparator& challenge, FF& current_scalar)
requires(!bb::IsFoldingFlavor<Flavor>)
{
auto scale_by_consecutive_powers_of_challenge = [&]<size_t, size_t>(auto& element) {
element *= current_scalar;
current_scalar *= challenge;
auto scale_by_consecutive_powers_of_challenge = [&](auto&... elements) {
((elements *= current_scalar, current_scalar *= challenge), ...);
};
apply_to_tuple_of_tuples(tuple, scale_by_consecutive_powers_of_challenge);

std::apply([&](auto&&... args) { (std::apply(scale_by_consecutive_powers_of_challenge, args), ...); }, tuple);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#pragma once

#include "barretenberg/crypto/poseidon2/poseidon2.hpp"
#include "barretenberg/stdlib/hash/poseidon2/poseidon2.hpp"
#include "barretenberg/stdlib/primitives/field/field_conversion.hpp"
#include "barretenberg/transcript/transcript.hpp"

namespace bb::stdlib::recursion::honk {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "barretenberg/stdlib_circuit_builders/goblin_ultra_circuit_builder.hpp"
#include "databus.hpp"

using namespace bb;

using Builder = GoblinUltraCircuitBuilder;
using field_ct = stdlib::field_t<Builder>;
using witness_ct = stdlib::witness_t<Builder>;
Expand All @@ -31,8 +33,8 @@ TEST(Databus, CallDataAndReturnData)
// databus mechanism to establish that the return data was indeed formed in this way.

// Define some bus data that conform to the pattern described above
std::array<bb::fr, 4> raw_calldata_values = { 4, 5, 6, 7 };
std::array<bb::fr, 3> raw_return_data_values = { 4, 5, 13 }; // 13 = 6 + 7
std::array<fr, 4> raw_calldata_values = { 4, 5, 6, 7 };
std::array<fr, 3> raw_return_data_values = { 4, 5, 13 }; // 13 = 6 + 7

// Populate the calldata in the databus
std::vector<field_ct> calldata_values;
Expand Down Expand Up @@ -87,7 +89,7 @@ TEST(Databus, BadReadFailure)
databus_ct databus;

// Populate return data with a single arbitrary value
bb::fr actual_value = 13;
fr actual_value = 13;
databus.return_data.set_values({ witness_ct(&builder, actual_value) });

// Read the value from the return data
Expand Down Expand Up @@ -120,11 +122,11 @@ TEST(Databus, BadCopyFailure)
databus_ct databus;

// Populate calldata with a single input
bb::fr input = 13;
fr input = 13;
databus.calldata.set_values({ witness_ct(&builder, input) });

// Populate return data with an output different from the input
bb::fr output = input - 1;
fr output = input - 1;
databus.return_data.set_values({ witness_ct(&builder, output) });

// Attempt to attest that the calldata has been copied into the return data
Expand Down
6 changes: 5 additions & 1 deletion barretenberg/cpp/src/barretenberg/transcript/transcript.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#include "transcript.hpp"
#include "barretenberg/crypto/poseidon2/poseidon2.hpp"

// This file is here to make sure that a transcript object file is created.
bb::NativeTranscriptParams::Fr bb::NativeTranscriptParams::hash(const std::vector<Fr>& data)
{
return crypto::Poseidon2<crypto::Poseidon2Bn254ScalarFieldParams>::hash(data);
}
18 changes: 6 additions & 12 deletions barretenberg/cpp/src/barretenberg/transcript/transcript.hpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
#pragma once

#include "barretenberg/common/serialize.hpp"
#include "barretenberg/crypto/poseidon2/poseidon2.hpp"
// #define LOG_CHALLENGES
// #define LOG_INTERACTIONS

#include "barretenberg/ecc/curves/bn254/fr.hpp"
#include "barretenberg/ecc/curves/bn254/g1.hpp"
#include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp"
#include "barretenberg/ecc/fields/field_conversion.hpp"
#include "barretenberg/honk/proof_system/types/proof.hpp"
#include "barretenberg/stdlib/hash/poseidon2/poseidon2.hpp"
#include "barretenberg/stdlib/primitives/field/field.hpp"
#include "barretenberg/stdlib/primitives/field/field_conversion.hpp"

// #define LOG_CHALLENGES
// #define LOG_INTERACTIONS
#include <concepts>

namespace bb {

Expand Down Expand Up @@ -64,10 +61,7 @@ class TranscriptManifest {
struct NativeTranscriptParams {
using Fr = bb::fr;
using Proof = HonkProof;
static inline Fr hash(const std::vector<Fr>& data)
{
return crypto::Poseidon2<crypto::Poseidon2Bn254ScalarFieldParams>::hash(data);
}
static Fr hash(const std::vector<Fr>& data);
template <typename T> static inline T convert_challenge(const Fr& challenge)
{
return bb::field_conversion::convert_challenge<T>(challenge);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <cstdint>

namespace tests_avm {
using namespace bb;
using namespace bb::avm_trace;

namespace {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <vector>

namespace tests_avm {
using namespace bb;
using namespace bb::avm_trace;

namespace {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <gtest/gtest.h>

namespace tests_avm {
using namespace bb;
using namespace bb::avm_trace;
using namespace testing;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <vector>

namespace tests_avm {
using namespace bb;
using namespace bb::avm_trace;
namespace {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "avm_common.test.hpp"

namespace tests_avm {
using namespace bb;
using namespace bb::avm_trace;

namespace {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <memory>

namespace tests_avm {

using namespace bb;
using namespace bb::avm_trace;
using namespace testing;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "barretenberg/vm/avm_trace/avm_common.hpp"

namespace tests_avm {
using namespace bb;
using namespace bb::avm_trace;

class AvmIndirectMemTests : public ::testing::Test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "barretenberg/vm/avm_trace/constants.hpp"

namespace tests_avm {
using namespace bb;
using namespace bb::avm_trace;

class AvmKernelTests : public ::testing::Test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <gtest/gtest.h>

namespace tests_avm {
using namespace bb;
using namespace bb::avm_trace;
using namespace testing;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "barretenberg/vm/avm_trace/avm_common.hpp"

namespace tests_avm {
using namespace bb;
using namespace bb::avm_trace;

class AvmMemoryTests : public ::testing::Test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "barretenberg/vm/generated/avm_flavor.hpp"

namespace tests_avm {
using namespace bb;

std::vector<ThreeOpParamRow> gen_three_op_params(std::vector<ThreeOpParam> operands,
std::vector<bb::avm_trace::AvmMemoryTag> mem_tags)
Expand Down

0 comments on commit 61f27b7

Please sign in to comment.