Skip to content

Commit

Permalink
fix: Fixing fuzzing build after composer splitting (#1317)
Browse files Browse the repository at this point in the history
# Description

After the splitting PR the fuzzing build was broken. This PR fixes that
issue. It also adds the fuzzing build to CI so that such breaking
changes get detected in the future
# Checklist:

- [x] I have reviewed my diff in github, line by line.
- [x] Every change is related to the PR description.
- [ ] I have
[linked](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue)
this pull request to the issue(s) that it resolves.
- [ ] There are no unexpected formatting changes, superfluous debug
logs, or commented-out code.
- [ ] The branch has been merged or rebased against the head of its
merge target.
- [x] I'm happy for the PR to be merged at the reviewer's next
convenience.

---------

Co-authored-by: ludamad <[email protected]>
  • Loading branch information
Rumata888 and ludamad authored Aug 1, 2023
1 parent 7f7519d commit 6b2e759
Show file tree
Hide file tree
Showing 16 changed files with 290 additions and 227 deletions.
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>;
};
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

0 comments on commit 6b2e759

Please sign in to comment.