Skip to content

Commit

Permalink
fix: Format barretenberg (#2209)
Browse files Browse the repository at this point in the history
The format script from circuits was not catching the barretenberg
folder, so it was not being formatted when `format.sh` was being run.
This fixes the script and runs a format on all of bb, and adds the
missing imports that surfaced this issue.
  • Loading branch information
spalladino authored Sep 11, 2023
1 parent 747de6a commit 0801372
Show file tree
Hide file tree
Showing 96 changed files with 541 additions and 469 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "barretenberg/ecc/curves/bn254/fr.hpp"
#include "barretenberg/polynomials/barycentric.hpp"
#include "barretenberg/ecc/curves/bn254/fr.hpp"
#include <benchmark/benchmark.h>

using namespace benchmark;
Expand Down
139 changes: 69 additions & 70 deletions circuits/cpp/barretenberg/cpp/src/barretenberg/common/fuzzer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,82 +88,79 @@ class FastRandom {
*
* @tparam T
*/
template <typename T> concept SimpleRng = requires(T a)
{
{
a.next()
}
->std::convertible_to<uint32_t>;
};
template <typename T>
concept SimpleRng = requires(T a) {
{
a.next()
} -> std::convertible_to<uint32_t>;
};
/**
* @brief Concept for forcing ArgumentSizes to be size_t
*
* @tparam T
*/
template <typename T> concept InstructionArgumentSizes = requires
{
{
std::make_tuple(T::CONSTANT,
T::WITNESS,
T::CONSTANT_WITNESS,
T::ADD,
T::SUBTRACT,
T::MULTIPLY,
T::DIVIDE,
T::ADD_TWO,
T::MADD,
T::MULT_MADD,
T::MSUB_DIV,
T::SQR,
T::SQR_ADD,
T::SUBTRACT_WITH_CONSTRAINT,
T::DIVIDE_WITH_CONSTRAINTS,
T::SLICE,
T::ASSERT_ZERO,
T::ASSERT_NOT_ZERO)
}
->std::same_as<std::tuple<size_t>>;
};
template <typename T>
concept InstructionArgumentSizes = requires {
{
std::make_tuple(T::CONSTANT,
T::WITNESS,
T::CONSTANT_WITNESS,
T::ADD,
T::SUBTRACT,
T::MULTIPLY,
T::DIVIDE,
T::ADD_TWO,
T::MADD,
T::MULT_MADD,
T::MSUB_DIV,
T::SQR,
T::SQR_ADD,
T::SUBTRACT_WITH_CONSTRAINT,
T::DIVIDE_WITH_CONSTRAINTS,
T::SLICE,
T::ASSERT_ZERO,
T::ASSERT_NOT_ZERO)
} -> std::same_as<std::tuple<size_t>>;
};

/**
* @brief Concept for Havoc Configurations
*
* @tparam T
*/
template <typename T> concept HavocConfigConstraint = requires
{
{
std::make_tuple(T::GEN_MUTATION_COUNT_LOG, T::GEN_STRUCTURAL_MUTATION_PROBABILITY)
}
->std::same_as<std::tuple<size_t>>;
T::GEN_MUTATION_COUNT_LOG <= 7;
};
template <typename T>
concept HavocConfigConstraint =
requires {
{
std::make_tuple(T::GEN_MUTATION_COUNT_LOG, T::GEN_STRUCTURAL_MUTATION_PROBABILITY)
} -> std::same_as<std::tuple<size_t>>;
T::GEN_MUTATION_COUNT_LOG <= 7;
};
/**
* @brief Concept specifying the class used by the fuzzer
*
* @tparam T
*/
template <typename T> concept ArithmeticFuzzHelperConstraint = requires
{
typename T::ArgSizes;
typename T::Instruction;
typename T::ExecutionState;
typename T::ExecutionHandler;
InstructionArgumentSizes<typename T::ArgSizes>;
};
template <typename T>
concept ArithmeticFuzzHelperConstraint = requires {
typename T::ArgSizes;
typename T::Instruction;
typename T::ExecutionState;
typename T::ExecutionHandler;
InstructionArgumentSizes<typename T::ArgSizes>;
};

/**
* @brief Fuzzer uses only composers with check_circuit function
*
* @tparam T
*/
template <typename T> concept CheckableComposer = requires(T a)
{
{
a.check_circuit()
}
->std::same_as<bool>;
};
template <typename T>
concept CheckableComposer = requires(T a) {
{
a.check_circuit()
} -> std::same_as<bool>;
};

/**
* @brief The fuzzer can use a postprocessing function that is specific to the type being fuzzed
Expand All @@ -173,25 +170,23 @@ template <typename T> concept CheckableComposer = requires(T a)
* @tparam Context The class containing the full context
*/
template <typename T, typename Composer, typename Context>
concept PostProcessingEnabled = requires(Composer composer, Context context)
{
{
T::postProcess(&composer, context)
}
->std::same_as<bool>;
};
concept PostProcessingEnabled = requires(Composer composer, Context context) {
{
T::postProcess(&composer, context)
} -> std::same_as<bool>;
};

/**
* @brief This concept is used when we want to limit the number of executions of certain instructions (for example,
* divisions and multiplications in bigfield start to bog down the fuzzer)
*
* @tparam T
*/
template <typename T> concept InstructionWeightsEnabled = requires
{
typename T::InstructionWeights;
T::InstructionWeights::_LIMIT;
};
template <typename T>
concept InstructionWeightsEnabled = requires {
typename T::InstructionWeights;
T::InstructionWeights::_LIMIT;
};

/**
* @brief Mutate the value of a field element
Expand All @@ -202,7 +197,9 @@ template <typename T> concept InstructionWeightsEnabled = requires
* @param havoc_config Mutation configuration
* @return Mutated element
*/
template <typename T, typename FF> inline static FF mutateFieldElement(FF e, T& rng) requires SimpleRng<T>
template <typename T, typename FF>
inline static FF mutateFieldElement(FF e, T& rng)
requires SimpleRng<T>
{
// With a certain probability, we apply changes to the Montgomery form, rather than the plain form. This
// has merit, since the computation is performed in montgomery form and comparisons are often performed
Expand Down Expand Up @@ -292,7 +289,9 @@ template <typename T, typename FF> inline static FF mutateFieldElement(FF e, T&
*
* @tparam T
*/
template <typename T> requires ArithmeticFuzzHelperConstraint<T> class ArithmeticFuzzHelper {
template <typename T>
requires ArithmeticFuzzHelperConstraint<T>
class ArithmeticFuzzHelper {
private:
/**
* @brief Mutator swapping two instructions together
Expand Down Expand Up @@ -599,8 +598,8 @@ template <typename T> requires ArithmeticFuzzHelperConstraint<T> class Arithmeti
template <typename Composer>
// TODO(@Rumata888)(from Zac: maybe try to fix? not comfortable refactoring this myself. Issue #1807)
// NOLINTNEXTLINE(readability-function-size, google-readability-function-size)
inline static void executeInstructions(
std::vector<typename T::Instruction>& instructions) requires CheckableComposer<Composer>
inline static void executeInstructions(std::vector<typename T::Instruction>& instructions)
requires CheckableComposer<Composer>
{
typename T::ExecutionState state;
Composer composer = Composer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ __extension__ using uint128_t = unsigned __int128;
// NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast, cert-dcl58-cpp)
// clang-format on

template <typename T> concept IntegralOrEnum = std::integral<T> || std::is_enum_v<T>;
template <typename T>
concept IntegralOrEnum = std::integral<T> || std::is_enum_v<T>;

namespace serialize {
// Forward declare derived msgpack methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ template <std::integral T, typename A> inline std::ostream& operator<<(std::ostr
}

template <typename T, typename A>
requires(!std::integral<T>) inline std::ostream& operator<<(std::ostream& os, std::vector<T, A> const& arr)
requires(!std::integral<T>)
inline std::ostream& operator<<(std::ostream& os, std::vector<T, A> const& arr)
{
os << "[\n";
for (auto element : arr) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "../blake2s/blake2s.hpp"
#include "blake3s.hpp"
#include "../blake2s/blake2s.hpp"

#include <gtest/gtest.h>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "ecdsa.hpp"
#include "barretenberg/common/serialize.hpp"
#include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp"
#include "barretenberg/ecc/curves/secp256r1/secp256r1.hpp"
#include "barretenberg/serialize/test_helper.hpp"
#include "ecdsa.hpp"
#include <gtest/gtest.h>

using namespace barretenberg;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "./fixed_base_scalar_mul.hpp"
#include "./generator_data.hpp"
#include "./fixed_base_scalar_mul.hpp"
#include "barretenberg/common/streams.hpp"
#include <gtest/gtest.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ std::array<uint8_t, Hash::OUTPUT_SIZE> hmac(const MessageContainer& message, con
* @return Fr output field element as uint512_t( H(10...0 || HMAC(k,m)) || H(00...0 || HMAC(k,m)) ) % r
*/
template <typename Hash, typename Fr, typename MessageContainer, typename KeyContainer>
Fr get_unbiased_field_from_hmac(const MessageContainer& message,
const KeyContainer& key) requires(Hash::OUTPUT_SIZE == 32)
Fr get_unbiased_field_from_hmac(const MessageContainer& message, const KeyContainer& key)
requires(Hash::OUTPUT_SIZE == 32)
{
// Strong assumption that works for now with our suite of Hashers
static_assert(Hash::BLOCK_SIZE > Hash::OUTPUT_SIZE);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

#include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp"
#include "proof_of_possession.hpp"
#include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp"
#include <gtest/gtest.h>

using namespace barretenberg;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp"
#include "schnorr.hpp"
#include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp"
#include <gtest/gtest.h>

using namespace barretenberg;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "block_constraint.hpp"
#include "acir_format.hpp"
#include "barretenberg/plonk/proof_system/types/proof.hpp"
#include "barretenberg/plonk/proof_system/verification_key/verification_key.hpp"
#include "block_constraint.hpp"

#include <gtest/gtest.h>
#include <vector>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "ecdsa_secp256k1.hpp"
#include "acir_format.hpp"
#include "barretenberg/crypto/ecdsa/ecdsa.hpp"
#include "barretenberg/plonk/proof_system/types/proof.hpp"
#include "barretenberg/plonk/proof_system/verification_key/verification_key.hpp"
#include "ecdsa_secp256k1.hpp"

#include <gtest/gtest.h>
#include <vector>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "ecdsa_secp256r1.hpp"
#include "acir_format.hpp"
#include "barretenberg/crypto/ecdsa/ecdsa.hpp"
#include "barretenberg/plonk/proof_system/types/proof.hpp"
#include "barretenberg/plonk/proof_system/verification_key/verification_key.hpp"
#include "ecdsa_secp256r1.hpp"

#include <gtest/gtest.h>
#include <vector>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "recursion_constraint.hpp"
#include "acir_format.hpp"
#include "barretenberg/plonk/proof_system/types/proof.hpp"
#include "barretenberg/plonk/proof_system/verification_key/verification_key.hpp"
#include "recursion_constraint.hpp"

#include <gtest/gtest.h>
#include <vector>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "barretenberg/serialize/test_helper.hpp"
#include "fq.hpp"
#include "barretenberg/serialize/test_helper.hpp"
#include <gtest/gtest.h>

using namespace barretenberg;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "barretenberg/serialize/test_helper.hpp"
#include "fr.hpp"
#include "barretenberg/serialize/test_helper.hpp"
#include <gtest/gtest.h>

using namespace barretenberg;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "barretenberg/numeric/random/engine.hpp"
#include "secp256k1.hpp"
#include "barretenberg/numeric/random/engine.hpp"
#include <gtest/gtest.h>

namespace test_secp256k1 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "barretenberg/numeric/random/engine.hpp"
#include "secp256r1.hpp"
#include "barretenberg/numeric/random/engine.hpp"
#include <gtest/gtest.h>

namespace test_secp256r1 {
Expand Down
Loading

0 comments on commit 0801372

Please sign in to comment.