diff --git a/.circleci/config.yml b/.circleci/config.yml index 65f39859594..82730b366e8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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 @@ -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 diff --git a/build_manifest.json b/build_manifest.json index 96a2a1a352d..7e5016900dc 100644 --- a/build_manifest.json +++ b/build_manifest.json @@ -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", diff --git a/circuits/cpp/barretenberg/.circleci/config.yml b/circuits/cpp/barretenberg/.circleci/config.yml index 0dc48e614c0..0436b49b804 100644 --- a/circuits/cpp/barretenberg/.circleci/config.yml +++ b/circuits/cpp/barretenberg/.circleci/config.yml @@ -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 @@ -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 diff --git a/circuits/cpp/barretenberg/build_manifest.json b/circuits/cpp/barretenberg/build_manifest.json index f755fc51d6e..564626daca9 100644 --- a/circuits/cpp/barretenberg/build_manifest.json +++ b/circuits/cpp/barretenberg/build_manifest.json @@ -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", diff --git a/circuits/cpp/barretenberg/cpp/dockerfiles/Dockerfile.x86_64-linux-clang-fuzzing b/circuits/cpp/barretenberg/cpp/dockerfiles/Dockerfile.x86_64-linux-clang-fuzzing new file mode 100644 index 00000000000..f9dd7717b23 --- /dev/null +++ b/circuits/cpp/barretenberg/cpp/dockerfiles/Dockerfile.x86_64-linux-clang-fuzzing @@ -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 diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/CMakeLists.txt b/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/CMakeLists.txt index 42ccf9bf15d..910b29b7a14 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/CMakeLists.txt +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/CMakeLists.txt @@ -1,11 +1,13 @@ -add_executable( - bb - main.cpp -) +if (NOT(FUZZING)) + add_executable( + bb + main.cpp + ) -target_link_libraries( - bb - PRIVATE - barretenberg - env -) \ No newline at end of file + target_link_libraries( + bb + PRIVATE + barretenberg + env + ) +endif() \ No newline at end of file diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/common/fuzzer.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/common/fuzzer.hpp index 079ae269f7f..9910a83d609 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/common/fuzzer.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/common/fuzzer.hpp @@ -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 #define PARENS () @@ -84,83 +84,80 @@ class FastRandom { * * @tparam T */ -template concept SimpleRng = requires(T a) -{ - { - a.next() - } - ->std::convertible_to; -}; +template +concept SimpleRng = requires(T a) { + { + a.next() + } -> std::convertible_to; + }; /** * @brief Concept for forcing ArgumentSizes to be size_t * * @tparam T */ -template 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>; -}; +template +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>; + }; /** * @brief Concept for Havoc Configurations * * @tparam T */ -template concept HavocConfigConstraint = requires -{ - { - std::make_tuple(T::GEN_MUTATION_COUNT_LOG, T::GEN_STRUCTURAL_MUTATION_PROBABILITY) - } - ->std::same_as>; - T::GEN_MUTATION_COUNT_LOG <= 7; -}; +template +concept HavocConfigConstraint = + requires { + { + std::make_tuple(T::GEN_MUTATION_COUNT_LOG, T::GEN_STRUCTURAL_MUTATION_PROBABILITY) + } -> std::same_as>; + T::GEN_MUTATION_COUNT_LOG <= 7; + }; /** * @brief Concept specifying the class used by the fuzzer * * @tparam T */ -template concept ArithmeticFuzzHelperConstraint = requires -{ - typename T::ArgSizes; - typename T::Instruction; - typename T::ExecutionState; - typename T::ExecutionHandler; - InstructionArgumentSizes; - // HavocConfigConstraint; -}; +template +concept ArithmeticFuzzHelperConstraint = requires { + typename T::ArgSizes; + typename T::Instruction; + typename T::ExecutionState; + typename T::ExecutionHandler; + InstructionArgumentSizes; + // HavocConfigConstraint; + }; /** * @brief Fuzzer uses only composers with check_circuit function * * @tparam T */ -template concept CheckableComposer = requires(T a) -{ - { - a.check_circuit() - } - ->std::same_as; -}; +template +concept CheckableComposer = requires(T a) { + { + a.check_circuit() + } -> std::same_as; + }; /** * @brief The fuzzer can use a postprocessing function that is specific to the type being fuzzed @@ -170,13 +167,11 @@ template concept CheckableComposer = requires(T a) * @tparam Context The class containing the full context */ template -concept PostProcessingEnabled = requires(Composer composer, Context context) -{ - { - T::postProcess(&composer, context) - } - ->std::same_as; -}; +concept PostProcessingEnabled = requires(Composer composer, Context context) { + { + T::postProcess(&composer, context) + } -> std::same_as; + }; /** * @brief This concept is used when we want to limit the number of executions of certain instructions (for example, @@ -184,17 +179,19 @@ concept PostProcessingEnabled = requires(Composer composer, Context context) * * @tparam T */ -template concept InstructionWeightsEnabled = requires -{ - typename T::InstructionWeights; - T::InstructionWeights::_LIMIT; -}; +template +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 requires ArithmeticFuzzHelperConstraint class ArithmeticFuzzHelper { +template + requires ArithmeticFuzzHelperConstraint +class ArithmeticFuzzHelper { private: /** * @brief Mutator swapping two instructions together @@ -497,8 +494,8 @@ template requires ArithmeticFuzzHelperConstraint class Arithmeti * @param instructions */ template - inline static void executeInstructions( - std::vector& instructions) requires CheckableComposer + inline static void executeInstructions(std::vector& instructions) + requires CheckableComposer { typename T::ExecutionState state; Composer composer = Composer(); @@ -590,9 +587,9 @@ template