Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fixing fuzzing build after composer splitting #1317

Merged
merged 10 commits into from
Aug 1, 2023
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
12 changes: 12 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ jobs:
name: "Build"
command: cond_spot_run_build barretenberg-x86_64-linux-clang 64

barretenberg-x86_64-linux-clang-fuzzing:
docker:
- image: aztecprotocol/alpine-build-image
resource_class: small
steps:
- *checkout
- *setup_env
- run:
name: "Build"
command: cond_spot_run_build barretenberg-x86_64-linux-clang-fuzzing 64

barretenberg-x86_64-linux-clang-assert:
docker:
- image: aztecprotocol/alpine-build-image
Expand Down Expand Up @@ -1006,6 +1017,7 @@ workflows:
- barretenberg-x86_64-linux-gcc: *defaults
- barretenberg-x86_64-linux-clang: *defaults
- barretenberg-x86_64-linux-clang-assert: *defaults
- barretenberg-x86_64-linux-clang-fuzzing: *defaults
- barretenberg-wasm-linux-clang: *defaults
- barretenberg-proof-system-tests: *bb_test
- barretenberg-honk-tests: *bb_test
Expand Down
6 changes: 6 additions & 0 deletions build_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
"rebuildPatterns": ["^circuits/cpp/barretenberg/cpp/"],
"dependencies": []
},
"barretenberg-x86_64-linux-clang-fuzzing": {
"buildDir": "circuits/cpp/barretenberg/cpp",
"dockerfile": "dockerfiles/Dockerfile.x86_64-linux-clang-fuzzing",
"rebuildPatterns": ["^circuits/cpp/barretenberg/cpp/"],
"dependencies": []
},
"barretenberg-x86_64-linux-gcc": {
"buildDir": "circuits/cpp/barretenberg/cpp",
"dockerfile": "dockerfiles/Dockerfile.x86_64-linux-gcc",
Expand Down
12 changes: 12 additions & 0 deletions circuits/cpp/barretenberg/.circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,17 @@ jobs:
# name: "Build"
# command: cond_spot_run_build barretenberg-x86_64-linux-clang-assert 64

x86_64-linux-clang-fuzzing:
docker:
- image: aztecprotocol/alpine-build-image
resource_class: small
steps:
- *checkout
- *setup_env
- run:
name: "Build"
command: cond_spot_run_build barretenberg-x86_64-linux-clang-fuzzing 64

# stdlib-tests:
# docker:
# - image: aztecprotocol/alpine-build-image
Expand Down Expand Up @@ -391,6 +402,7 @@ workflows:
# - x86_64-linux-gcc: *defaults
- x86_64-linux-clang: *defaults
# - x86_64-linux-clang-assert: *defaults
- x86_64-linux-clang-fuzzing: *defaults
# - wasm-linux-clang: *defaults
# - proof-system-tests: *bb_test
# - honk-tests: *bb_test
Expand Down
6 changes: 6 additions & 0 deletions circuits/cpp/barretenberg/build_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
"rebuildPatterns": ["^cpp/"],
"dependencies": []
},
"barretenberg-x86_64-linux-clang-fuzzing": {
"buildDir": "cpp",
"dockerfile": "dockerfiles/Dockerfile.x86_64-linux-clang-fuzzing",
"rebuildPatterns": ["^cpp/"],
"dependencies": []
},
"barretenberg-x86_64-linux-gcc": {
"buildDir": "cpp",
"dockerfile": "dockerfiles/Dockerfile.x86_64-linux-gcc",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM alpine:3.18 AS builder
RUN apk update && \
apk upgrade && \
apk add --no-cache \
build-base \
clang16 \
compiler-rt \
openmp-dev \
cmake \
ninja \
git \
curl \
perl

WORKDIR /usr/src/barretenberg/cpp

COPY . .
# Build the entire project, as we want to check everything builds under clang
RUN cmake --preset fuzzing && cmake --build --preset fuzzing

FROM alpine:3.18
RUN apk update && apk add openmp
COPY --from=builder /usr/src/barretenberg/cpp/srs_db /usr/src/barretenberg/cpp/srs_db
22 changes: 12 additions & 10 deletions circuits/cpp/barretenberg/cpp/src/barretenberg/bb/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
add_executable(
bb
main.cpp
)
if (NOT(FUZZING))
add_executable(
bb
main.cpp
)

target_link_libraries(
bb
PRIVATE
barretenberg
env
)
target_link_libraries(
bb
PRIVATE
barretenberg
env
)
endif()
145 changes: 71 additions & 74 deletions circuits/cpp/barretenberg/cpp/src/barretenberg/common/fuzzer.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include "barretenberg/plonk/composer/standard_composer.hpp"
#include "barretenberg/plonk/composer/turbo_composer.hpp"
#include "barretenberg/proof_system/circuit_builder/standard_circuit_builder.hpp"
#include "barretenberg/proof_system/circuit_builder/turbo_circuit_builder.hpp"
#include <concepts>

#define PARENS ()
Expand Down Expand Up @@ -84,83 +84,80 @@ class FastRandom {
*
* @tparam T
*/
template <typename T> concept SimpleRng = requires(T a)
{
{
a.next()
}
->std::convertible_to<uint32_t>;
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't love how it autoformats concepts with another {} inside the {}, but that's an aside

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>;
// HavocConfigConstraint<typename T::HavocConfig>;
};
template <typename T>
concept ArithmeticFuzzHelperConstraint = requires {
typename T::ArgSizes;
typename T::Instruction;
typename T::ExecutionState;
typename T::ExecutionHandler;
InstructionArgumentSizes<typename T::ArgSizes>;
// HavocConfigConstraint<typename T::HavocConfig>;
};

/**
* @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 @@ -170,31 +167,31 @@ 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 A templated class containing most of the fuzzing logic for a generic Arithmetic class
*
* @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 @@ -497,8 +494,8 @@ template <typename T> requires ArithmeticFuzzHelperConstraint<T> class Arithmeti
* @param instructions
*/
template <typename Composer>
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 Expand Up @@ -590,9 +587,9 @@ template <template <typename> class Fuzzer, uint64_t Composers>
constexpr void RunWithComposers(const uint8_t* Data, const size_t Size, FastRandom& VarianceRNG)
{
if (Composers & 1) {
RunWithComposer<Fuzzer, plonk::StandardPlonkComposer>(Data, Size, VarianceRNG);
RunWithComposer<Fuzzer, proof_system::StandardCircuitBuilder>(Data, Size, VarianceRNG);
}
if (Composers & 2) {
RunWithComposer<Fuzzer, plonk::TurboPlonkComposer>(Data, Size, VarianceRNG);
RunWithComposer<Fuzzer, proof_system::TurboCircuitBuilder>(Data, Size, VarianceRNG);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
add_executable(
grumpkin_srs_gen
grumpkin_srs_gen.cpp
)
if (NOT(FUZZING))
add_executable(
grumpkin_srs_gen
grumpkin_srs_gen.cpp
)

target_link_libraries(
grumpkin_srs_gen
PRIVATE
srs
ecc
crypto_sha256
)
target_link_libraries(
grumpkin_srs_gen
PRIVATE
srs
ecc
crypto_sha256
)
endif()
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
barretenberg_module(stdlib_solidity_helpers plonk proof_system transcript crypto_pedersen_commitment polynomials crypto_sha256 ecc crypto_blake3s stdlib_primitives stdlib_pedersen_commitment stdlib_blake3s stdlib_blake2s srs)

add_executable(solidity_key_gen key_gen.cpp)
if (NOT(FUZZING))
add_executable(solidity_key_gen key_gen.cpp)

add_executable(solidity_proof_gen proof_gen.cpp)
add_executable(solidity_proof_gen proof_gen.cpp)

target_link_libraries(
solidity_key_gen
stdlib_solidity_helpers
)
target_link_libraries(
solidity_key_gen
stdlib_solidity_helpers
)

target_link_libraries(
solidity_proof_gen
stdlib_solidity_helpers
)
target_link_libraries(
solidity_proof_gen
stdlib_solidity_helpers
)
endif()
Loading