Skip to content

Commit

Permalink
fix: Fixing fuzzing build after composer splitting
Browse files Browse the repository at this point in the history
  • Loading branch information
Rumata888 committed Jul 31, 2023
1 parent 0bd1772 commit 1f5831c
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 118 deletions.
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_constructors/standard_circuit_constructor.hpp"
#include "barretenberg/proof_system/circuit_constructors/turbo_circuit_constructor.hpp"
#include <concepts>

#define PARENS ()
Expand Down Expand Up @@ -590,9 +590,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::StandardCircuitConstructor>(Data, Size, VarianceRNG);
}
if (Composers & 2) {
RunWithComposer<Fuzzer, plonk::TurboPlonkComposer>(Data, Size, VarianceRNG);
RunWithComposer<Fuzzer, proof_system::TurboCircuitConstructor>(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()
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,11 @@ template <typename Composer> class BigFieldBase {
RANDOMSEED,
_LAST
};
Instruction& operator=(const Instruction& other) = default;

struct Element {
Element() = default;
Element(const Element& other) = default;
Element(const Element&& other) { value = std::move(other.value); };
Element(fq in)
: value(in){};
Element& operator=(const Element& other) = default;
Element(uint64_t v)
: value(v)
{}
fq value;
};
struct TwoArgs {
Expand Down Expand Up @@ -213,8 +209,9 @@ template <typename Composer> class BigFieldBase {
uint8_t out3;
};
union ArgumentContents {
ArgumentContents() { element = Element(fq(0)); }
ArgumentContents& operator=(const ArgumentContents& other) = default;
ArgumentContents()
: randomseed(0)
{}
uint32_t randomseed;
Element element;
TwoArgs twoArgs;
Expand All @@ -229,6 +226,7 @@ template <typename Composer> class BigFieldBase {
OPCODE id;
// Instruction arguments
ArgumentContents arguments;

/**
* @brief Generate a random instruction
*
Expand Down Expand Up @@ -1929,7 +1927,7 @@ extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv)
*/
extern "C" size_t LLVMFuzzerCustomMutator(uint8_t* Data, size_t Size, size_t MaxSize, unsigned int Seed)
{
using FuzzerClass = BigFieldBase<plonk::StandardPlonkComposer>;
using FuzzerClass = BigFieldBase<proof_system::StandardCircuitConstructor>;
auto fast_random = FastRandom(Seed);
auto size_occupied = ArithmeticFuzzHelper<FuzzerClass>::MutateInstructionBuffer(Data, Size, MaxSize, fast_random);
if ((fast_random.next() % 200) < fuzzer_havoc_settings.GEN_LLVM_POST_MUTATION_PROB) {
Expand All @@ -1950,7 +1948,7 @@ extern "C" size_t LLVMFuzzerCustomCrossOver(const uint8_t* Data1,
size_t MaxOutSize,
unsigned int Seed)
{
using FuzzerClass = BigFieldBase<plonk::StandardPlonkComposer>;
using FuzzerClass = BigFieldBase<proof_system::StandardCircuitConstructor>;
auto fast_random = FastRandom(Seed);
auto vecA = ArithmeticFuzzHelper<FuzzerClass>::parseDataIntoInstructions(Data1, Size1);
auto vecB = ArithmeticFuzzHelper<FuzzerClass>::parseDataIntoInstructions(Data2, Size2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ template <typename Composer> class BitArrayFuzzBase {
typedef proof_system::plonk::stdlib::bit_array<Composer> bit_array_t;
typedef proof_system::plonk::stdlib::byte_array<Composer> byte_array_t;
template <size_t NumBytes, size_t NumWords>
static std::vector<uint8_t> to_vector(std::array<plonk::stdlib::uint32<Composer>, NumWords>& a32)
static std::vector<uint8_t> to_vector(std::array<proof_system::plonk::stdlib::uint32<Composer>, NumWords>& a32)
{
/* Convert array of uint32_t to vector of uint8_t */
std::vector<uint8_t> v(NumBytes);
Expand All @@ -60,7 +60,7 @@ template <typename Composer> class BitArrayFuzzBase {
*/
return static_cast<byte_array_t>(bit_array).get_value();
} else if (bit_array.size() - offset == NumBits) {
std::array<plonk::stdlib::uint32<Composer>, NumWords> a32;
std::array<proof_system::plonk::stdlib::uint32<Composer>, NumWords> a32;
bit_array.template populate_uint32_array<NumWords>(offset, a32);
return to_vector<NumBytes, NumWords>(a32);
} else {
Expand Down Expand Up @@ -92,7 +92,7 @@ template <typename Composer> class BitArrayFuzzBase {
*/
return static_cast<byte_array_t>(bit_array).get_value();
} else if (bit_array.size() == NumBits) {
std::array<plonk::stdlib::uint32<Composer>, NumWords> a32;
std::array<proof_system::plonk::stdlib::uint32<Composer>, NumWords> a32;

/* Switch between two different methods to retrieve the uint32 array */
if (cast_or_populate) {
Expand Down Expand Up @@ -444,7 +444,8 @@ template <typename Composer> class BitArrayFuzzBase {
if (bit_array.size() == MAX_ARRAY_SIZE / 32) {
std::array<uint32_t, MAX_ARRAY_SIZE> a32;
const auto a32_ =
static_cast<std::array<plonk::stdlib::uint32<Composer>, MAX_ARRAY_SIZE>>(bit_array);
static_cast<std::array<proof_system::plonk::stdlib::uint32<Composer>, MAX_ARRAY_SIZE>>(
bit_array);
for (size_t i = 0; i < a32_.size(); i++) {
a32[i] = static_cast<uint32_t>(a32_[i].get_value());
}
Expand Down Expand Up @@ -881,7 +882,7 @@ extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv)
*/
extern "C" size_t LLVMFuzzerCustomMutator(uint8_t* Data, size_t Size, size_t MaxSize, unsigned int Seed)
{
using FuzzerClass = BitArrayFuzzBase<plonk::StandardPlonkComposer>;
using FuzzerClass = BitArrayFuzzBase<proof_system::StandardCircuitConstructor>;
auto fast_random = FastRandom(Seed);
auto size_occupied = ArithmeticFuzzHelper<FuzzerClass>::MutateInstructionBuffer(Data, Size, MaxSize, fast_random);
if ((fast_random.next() % 200) < fuzzer_havoc_settings.GEN_LLVM_POST_MUTATION_PROB) {
Expand All @@ -902,7 +903,7 @@ extern "C" size_t LLVMFuzzerCustomCrossOver(const uint8_t* Data1,
size_t MaxOutSize,
unsigned int Seed)
{
using FuzzerClass = BitArrayFuzzBase<plonk::StandardPlonkComposer>;
using FuzzerClass = BitArrayFuzzBase<proof_system::StandardCircuitConstructor>;
auto fast_random = FastRandom(Seed);
auto vecA = ArithmeticFuzzHelper<FuzzerClass>::parseDataIntoInstructions(Data1, Size1);
auto vecB = ArithmeticFuzzHelper<FuzzerClass>::parseDataIntoInstructions(Data2, Size2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv)
*/
extern "C" size_t LLVMFuzzerCustomMutator(uint8_t* Data, size_t Size, size_t MaxSize, unsigned int Seed)
{
using FuzzerClass = BoolFuzzBase<plonk::StandardPlonkComposer>;
using FuzzerClass = BoolFuzzBase<proof_system::StandardCircuitConstructor>;
auto fast_random = FastRandom(Seed);
auto size_occupied = ArithmeticFuzzHelper<FuzzerClass>::MutateInstructionBuffer(Data, Size, MaxSize, fast_random);
if ((fast_random.next() % 200) < fuzzer_havoc_settings.GEN_LLVM_POST_MUTATION_PROB) {
Expand All @@ -821,7 +821,7 @@ extern "C" size_t LLVMFuzzerCustomCrossOver(const uint8_t* Data1,
size_t MaxOutSize,
unsigned int Seed)
{
using FuzzerClass = BoolFuzzBase<plonk::StandardPlonkComposer>;
using FuzzerClass = BoolFuzzBase<proof_system::StandardCircuitConstructor>;
auto fast_random = FastRandom(Seed);
auto vecA = ArithmeticFuzzHelper<FuzzerClass>::parseDataIntoInstructions(Data1, Size1);
auto vecB = ArithmeticFuzzHelper<FuzzerClass>::parseDataIntoInstructions(Data2, Size2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv)
*/
extern "C" size_t LLVMFuzzerCustomMutator(uint8_t* Data, size_t Size, size_t MaxSize, unsigned int Seed)
{
using FuzzerClass = ByteArrayFuzzBase<plonk::StandardPlonkComposer>;
using FuzzerClass = ByteArrayFuzzBase<proof_system::StandardCircuitConstructor>;
auto fast_random = FastRandom(Seed);
auto size_occupied = ArithmeticFuzzHelper<FuzzerClass>::MutateInstructionBuffer(Data, Size, MaxSize, fast_random);
if ((fast_random.next() % 200) < fuzzer_havoc_settings.GEN_LLVM_POST_MUTATION_PROB) {
Expand All @@ -950,7 +950,7 @@ extern "C" size_t LLVMFuzzerCustomCrossOver(const uint8_t* Data1,
size_t MaxOutSize,
unsigned int Seed)
{
using FuzzerClass = ByteArrayFuzzBase<plonk::StandardPlonkComposer>;
using FuzzerClass = ByteArrayFuzzBase<proof_system::StandardCircuitConstructor>;
auto fast_random = FastRandom(Seed);
auto vecA = ArithmeticFuzzHelper<FuzzerClass>::parseDataIntoInstructions(Data1, Size1);
auto vecB = ArithmeticFuzzHelper<FuzzerClass>::parseDataIntoInstructions(Data2, Size2);
Expand Down
Loading

0 comments on commit 1f5831c

Please sign in to comment.