Skip to content

Commit

Permalink
chore(bb): -30% compile time (#6610)
Browse files Browse the repository at this point in the history
ClangBuildAnalyzer warned:

```
**** Expensive headers:
6385739 ms: /mnt/user-data/adam/aztec-packages/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/plookup_tables.hpp (included 183 times, avg 34894 ms), included via:
  7x: field.hpp witness.hpp circuit_builders.hpp circuit_simulator.hpp 
  7x: eccvm_flavor.hpp ipa.hpp transcript.hpp proof.hpp field.hpp witness.hpp circuit_builders.hpp circuit_simulator.hpp 
  6x: circuit_builders.hpp circuit_simulator.hpp 
  5x: translator_flavor.hpp kzg.hpp transcript.hpp proof.hpp field.hpp witness.hpp circuit_builders.hpp circuit_simulator.hpp 
  3x: client_ivc.hpp goblin.hpp eccvm_prover.hpp zeromorph.hpp transcript.hpp poseidon2.hpp sponge.hpp poseidon2_permutation.hpp circuit_builders.hpp goblin_ultra_circuit_builder.hpp ultra_circuit_builder.hpp 
  3x: standard_composer.hpp plonk_flavors.hpp ultra_circuit_builder.hpp 
  ...
  ```
  
  I picked the easiest warning here to tackle, good result
  • Loading branch information
ludamad authored May 23, 2024
1 parent de50ddd commit d6838a1
Show file tree
Hide file tree
Showing 12 changed files with 215 additions and 203 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp"
#include "barretenberg/circuit_checker/circuit_checker.hpp"
#include "barretenberg/crypto/pedersen_commitment/pedersen.hpp"
#include "barretenberg/stdlib_circuit_builders/plookup_tables/fixed_base/fixed_base.hpp"

#include <gtest/gtest.h>

using namespace bb;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "barretenberg/crypto/pedersen_commitment/pedersen.hpp"
#include "barretenberg/crypto/pedersen_hash/pedersen.hpp"
#include "barretenberg/crypto/poseidon2/poseidon2.hpp"
#include "barretenberg/numeric/bitop/pow.hpp"
#include "barretenberg/stdlib/hash/blake2s/blake2s.hpp"
#include "barretenberg/stdlib/hash/pedersen/pedersen.hpp"
#include "barretenberg/stdlib/primitives/field/field.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "barretenberg/plonk/composer/ultra_composer.hpp"
#include "barretenberg/plonk/proof_system/widgets/random_widgets/plookup_widget.hpp"
#include "barretenberg/stdlib/primitives/plookup/plookup.hpp"
#include "barretenberg/stdlib_circuit_builders/plookup_tables/fixed_base/fixed_base.hpp"
#include "barretenberg/stdlib_circuit_builders/plookup_tables/sha256.hpp"
#include "barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "barretenberg/numeric/bitop/sparse_form.hpp"
#include "barretenberg/stdlib/primitives/logic/logic.hpp"
#include "barretenberg/stdlib/primitives/uint/uint.hpp"
#include "barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_rho.hpp"
#include "barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_theta.hpp"
namespace bb::stdlib {

using namespace bb::plookup;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "pedersen.hpp"
#include "barretenberg/crypto/pedersen_hash/pedersen.hpp"
#include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp"
namespace bb::stdlib {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp"
#include "barretenberg/numeric/random/engine.hpp"
#include "barretenberg/stdlib/primitives/curves/bn254.hpp"
#include "barretenberg/stdlib_circuit_builders/plookup_tables/fixed_base/fixed_base.hpp"
#include "pedersen.hpp"

using namespace bb;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "./cycle_group.hpp"
#include "barretenberg/stdlib/primitives/plookup/plookup.hpp"
#include "barretenberg/stdlib_circuit_builders/plookup_tables/fixed_base/fixed_base.hpp"
#include "barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp"
namespace bb::stdlib {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "barretenberg/numeric/random/engine.hpp"
#include "barretenberg/stdlib/primitives/field/field.hpp"
#include "barretenberg/stdlib/primitives/witness/witness.hpp"
#include "barretenberg/stdlib_circuit_builders/plookup_tables/fixed_base/fixed_base.hpp"
#include <gtest/gtest.h>

#define STDLIB_TYPE_ALIASES \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "../byte_array/byte_array.hpp"
#include "barretenberg/circuit_checker/circuit_checker.hpp"
#include "barretenberg/numeric/bitop/rotate.hpp"
#include "barretenberg/numeric/bitop/sparse_form.hpp"
#include "barretenberg/numeric/random/engine.hpp"
#include "barretenberg/stdlib/primitives/bigfield/bigfield.hpp"
#include "barretenberg/stdlib/primitives/biggroup/biggroup.hpp"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
#include "plookup_tables.hpp"
#include "barretenberg/common/constexpr_utils.hpp"
#include "barretenberg/stdlib_circuit_builders/plookup_tables/aes128.hpp"
#include "barretenberg/stdlib_circuit_builders/plookup_tables/blake2s.hpp"
#include "barretenberg/stdlib_circuit_builders/plookup_tables/dummy.hpp"
#include "barretenberg/stdlib_circuit_builders/plookup_tables/fixed_base/fixed_base.hpp"
#include "barretenberg/stdlib_circuit_builders/plookup_tables/non_native_group_generator.hpp"
#include "barretenberg/stdlib_circuit_builders/plookup_tables/sha256.hpp"
#include "barretenberg/stdlib_circuit_builders/plookup_tables/uint.hpp"

#include "barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_chi.hpp"
#include "barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_input.hpp"
#include "barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_output.hpp"
#include "barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_rho.hpp"
#include "barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_theta.hpp"
#include <mutex>
namespace bb::plookup {

Expand Down Expand Up @@ -212,4 +225,192 @@ ReadData<bb::fr> get_lookup_accumulators(const MultiTableId id,
return lookup;
}

BasicTable create_basic_table(const BasicTableId id, const size_t index)
{
// we have >50 basic fixed base tables so we match with some logic instead of a switch statement
auto id_var = static_cast<size_t>(id);
if (id_var >= static_cast<size_t>(FIXED_BASE_0_0) && id_var < static_cast<size_t>(FIXED_BASE_1_0)) {
return fixed_base::table::generate_basic_fixed_base_table<0>(
id, index, id_var - static_cast<size_t>(FIXED_BASE_0_0));
}
if (id_var >= static_cast<size_t>(FIXED_BASE_1_0) && id_var < static_cast<size_t>(FIXED_BASE_2_0)) {
return fixed_base::table::generate_basic_fixed_base_table<1>(
id, index, id_var - static_cast<size_t>(FIXED_BASE_1_0));
}
if (id_var >= static_cast<size_t>(FIXED_BASE_2_0) && id_var < static_cast<size_t>(FIXED_BASE_3_0)) {
return fixed_base::table::generate_basic_fixed_base_table<2>(
id, index, id_var - static_cast<size_t>(FIXED_BASE_2_0));
}
if (id_var >= static_cast<size_t>(FIXED_BASE_3_0) && id_var < static_cast<size_t>(HONK_DUMMY_BASIC1)) {
return fixed_base::table::generate_basic_fixed_base_table<3>(
id, index, id_var - static_cast<size_t>(FIXED_BASE_3_0));
}
switch (id) {
case AES_SPARSE_MAP: {
return sparse_tables::generate_sparse_table_with_rotation<9, 8, 0>(AES_SPARSE_MAP, index);
}
case AES_SBOX_MAP: {
return aes128_tables::generate_aes_sbox_table(AES_SBOX_MAP, index);
}
case AES_SPARSE_NORMALIZE: {
return aes128_tables::generate_aes_sparse_normalization_table(AES_SPARSE_NORMALIZE, index);
}
case SHA256_WITNESS_NORMALIZE: {
return sha256_tables::generate_witness_extension_normalization_table(SHA256_WITNESS_NORMALIZE, index);
}
case SHA256_WITNESS_SLICE_3: {
return sparse_tables::generate_sparse_table_with_rotation<16, 3, 0>(SHA256_WITNESS_SLICE_3, index);
}
case SHA256_WITNESS_SLICE_7_ROTATE_4: {
return sparse_tables::generate_sparse_table_with_rotation<16, 7, 4>(SHA256_WITNESS_SLICE_7_ROTATE_4, index);
}
case SHA256_WITNESS_SLICE_8_ROTATE_7: {
return sparse_tables::generate_sparse_table_with_rotation<16, 8, 7>(SHA256_WITNESS_SLICE_8_ROTATE_7, index);
}
case SHA256_WITNESS_SLICE_14_ROTATE_1: {
return sparse_tables::generate_sparse_table_with_rotation<16, 14, 1>(SHA256_WITNESS_SLICE_14_ROTATE_1, index);
}
case SHA256_CH_NORMALIZE: {
return sha256_tables::generate_choose_normalization_table(SHA256_CH_NORMALIZE, index);
}
case SHA256_MAJ_NORMALIZE: {
return sha256_tables::generate_majority_normalization_table(SHA256_MAJ_NORMALIZE, index);
}
case SHA256_BASE28: {
return sparse_tables::generate_sparse_table_with_rotation<28, 11, 0>(SHA256_BASE28, index);
}
case SHA256_BASE28_ROTATE6: {
return sparse_tables::generate_sparse_table_with_rotation<28, 11, 6>(SHA256_BASE28_ROTATE6, index);
}
case SHA256_BASE28_ROTATE3: {
return sparse_tables::generate_sparse_table_with_rotation<28, 11, 3>(SHA256_BASE28_ROTATE3, index);
}
case SHA256_BASE16: {
return sparse_tables::generate_sparse_table_with_rotation<16, 11, 0>(SHA256_BASE16, index);
}
case SHA256_BASE16_ROTATE2: {
return sparse_tables::generate_sparse_table_with_rotation<16, 11, 2>(SHA256_BASE16_ROTATE2, index);
}
case UINT_XOR_ROTATE0: {
return uint_tables::generate_xor_rotate_table<6, 0>(UINT_XOR_ROTATE0, index);
}
case UINT_AND_ROTATE0: {
return uint_tables::generate_and_rotate_table<6, 0>(UINT_AND_ROTATE0, index);
}
case BN254_XLO_BASIC: {
return ecc_generator_tables::ecc_generator_table<bb::g1>::generate_xlo_table(BN254_XLO_BASIC, index);
}
case BN254_XHI_BASIC: {
return ecc_generator_tables::ecc_generator_table<bb::g1>::generate_xhi_table(BN254_XHI_BASIC, index);
}
case BN254_YLO_BASIC: {
return ecc_generator_tables::ecc_generator_table<bb::g1>::generate_ylo_table(BN254_YLO_BASIC, index);
}
case BN254_YHI_BASIC: {
return ecc_generator_tables::ecc_generator_table<bb::g1>::generate_yhi_table(BN254_YHI_BASIC, index);
}
case BN254_XYPRIME_BASIC: {
return ecc_generator_tables::ecc_generator_table<bb::g1>::generate_xyprime_table(BN254_XYPRIME_BASIC, index);
}
case BN254_XLO_ENDO_BASIC: {
return ecc_generator_tables::ecc_generator_table<bb::g1>::generate_xlo_endo_table(BN254_XLO_ENDO_BASIC, index);
}
case BN254_XHI_ENDO_BASIC: {
return ecc_generator_tables::ecc_generator_table<bb::g1>::generate_xhi_endo_table(BN254_XHI_ENDO_BASIC, index);
}
case BN254_XYPRIME_ENDO_BASIC: {
return ecc_generator_tables::ecc_generator_table<bb::g1>::generate_xyprime_endo_table(BN254_XYPRIME_ENDO_BASIC,
index);
}
case SECP256K1_XLO_BASIC: {
return ecc_generator_tables::ecc_generator_table<secp256k1::g1>::generate_xlo_table(SECP256K1_XLO_BASIC, index);
}
case SECP256K1_XHI_BASIC: {
return ecc_generator_tables::ecc_generator_table<secp256k1::g1>::generate_xhi_table(SECP256K1_XHI_BASIC, index);
}
case SECP256K1_YLO_BASIC: {
return ecc_generator_tables::ecc_generator_table<secp256k1::g1>::generate_ylo_table(SECP256K1_YLO_BASIC, index);
}
case SECP256K1_YHI_BASIC: {
return ecc_generator_tables::ecc_generator_table<secp256k1::g1>::generate_yhi_table(SECP256K1_YHI_BASIC, index);
}
case SECP256K1_XYPRIME_BASIC: {
return ecc_generator_tables::ecc_generator_table<secp256k1::g1>::generate_xyprime_table(SECP256K1_XYPRIME_BASIC,
index);
}
case SECP256K1_XLO_ENDO_BASIC: {
return ecc_generator_tables::ecc_generator_table<secp256k1::g1>::generate_xlo_endo_table(
SECP256K1_XLO_ENDO_BASIC, index);
}
case SECP256K1_XHI_ENDO_BASIC: {
return ecc_generator_tables::ecc_generator_table<secp256k1::g1>::generate_xhi_endo_table(
SECP256K1_XHI_ENDO_BASIC, index);
}
case SECP256K1_XYPRIME_ENDO_BASIC: {
return ecc_generator_tables::ecc_generator_table<secp256k1::g1>::generate_xyprime_endo_table(
SECP256K1_XYPRIME_ENDO_BASIC, index);
}
case BLAKE_XOR_ROTATE0: {
return blake2s_tables::generate_xor_rotate_table<6, 0>(BLAKE_XOR_ROTATE0, index);
}
case BLAKE_XOR_ROTATE0_SLICE5_MOD4: {
return blake2s_tables::generate_xor_rotate_table<5, 0, true>(BLAKE_XOR_ROTATE0_SLICE5_MOD4, index);
}
case BLAKE_XOR_ROTATE2: {
return blake2s_tables::generate_xor_rotate_table<6, 2>(BLAKE_XOR_ROTATE2, index);
}
case BLAKE_XOR_ROTATE1: {
return blake2s_tables::generate_xor_rotate_table<6, 1>(BLAKE_XOR_ROTATE1, index);
}
case BLAKE_XOR_ROTATE4: {
return blake2s_tables::generate_xor_rotate_table<6, 4>(BLAKE_XOR_ROTATE4, index);
}
case HONK_DUMMY_BASIC1: {
return dummy_tables::generate_honk_dummy_table<HONK_DUMMY_BASIC1>(HONK_DUMMY_BASIC1, index);
}
case HONK_DUMMY_BASIC2: {
return dummy_tables::generate_honk_dummy_table<HONK_DUMMY_BASIC2>(HONK_DUMMY_BASIC2, index);
}
case KECCAK_INPUT: {
return keccak_tables::KeccakInput::generate_keccak_input_table(KECCAK_INPUT, index);
}
case KECCAK_THETA: {
return keccak_tables::Theta::generate_theta_renormalization_table(KECCAK_THETA, index);
}
case KECCAK_CHI: {
return keccak_tables::Chi::generate_chi_renormalization_table(KECCAK_CHI, index);
}
case KECCAK_OUTPUT: {
return keccak_tables::KeccakOutput::generate_keccak_output_table(KECCAK_OUTPUT, index);
}
case KECCAK_RHO_1: {
return keccak_tables::Rho<1>::generate_rho_renormalization_table(KECCAK_RHO_1, index);
}
case KECCAK_RHO_2: {
return keccak_tables::Rho<2>::generate_rho_renormalization_table(KECCAK_RHO_2, index);
}
case KECCAK_RHO_3: {
return keccak_tables::Rho<3>::generate_rho_renormalization_table(KECCAK_RHO_3, index);
}
case KECCAK_RHO_4: {
return keccak_tables::Rho<4>::generate_rho_renormalization_table(KECCAK_RHO_4, index);
}
case KECCAK_RHO_5: {
return keccak_tables::Rho<5>::generate_rho_renormalization_table(KECCAK_RHO_5, index);
}
case KECCAK_RHO_6: {
return keccak_tables::Rho<6>::generate_rho_renormalization_table(KECCAK_RHO_6, index);
}
case KECCAK_RHO_7: {
return keccak_tables::Rho<7>::generate_rho_renormalization_table(KECCAK_RHO_7, index);
}
case KECCAK_RHO_8: {
return keccak_tables::Rho<8>::generate_rho_renormalization_table(KECCAK_RHO_8, index);
}
default: {
throw_or_abort("table id does not exist");
return sparse_tables::generate_sparse_table_with_rotation<9, 8, 0>(AES_SPARSE_MAP, index);
}
}
}
} // namespace bb::plookup
Loading

0 comments on commit d6838a1

Please sign in to comment.