Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
fuzzer.hpp
Go to the documentation of this file.
1#pragma once
5
6// NOLINTBEGIN(cppcoreguidelines-macro-usage, google-runtime-int)
7#define PARENS ()
8
9// Rescan macro tokens 256 times
10#define EXPAND(arg) EXPAND1(EXPAND1(EXPAND1(EXPAND1(arg))))
11#define EXPAND1(arg) EXPAND2(EXPAND2(EXPAND2(EXPAND2(arg))))
12#define EXPAND2(arg) EXPAND3(EXPAND3(EXPAND3(EXPAND3(arg))))
13#define EXPAND3(arg) EXPAND4(EXPAND4(EXPAND4(EXPAND4(arg))))
14#define EXPAND4(arg) arg
15
16#define FOR_EACH(macro, ...) __VA_OPT__(EXPAND(FOR_EACH_HELPER(macro, __VA_ARGS__)))
17#define FOR_EACH_HELPER(macro, a1, ...) macro(a1) __VA_OPT__(FOR_EACH_AGAIN PARENS(macro, __VA_ARGS__))
18#define FOR_EACH_AGAIN() FOR_EACH_HELPER
19
20#define ALL_POSSIBLE_OPCODES \
21 CONSTANT, WITNESS, CONSTANT_WITNESS, ADD, SUBTRACT, MULTIPLY, DIVIDE, ADD_TWO, MADD, MULT_MADD, MSUB_DIV, SQR, \
22 ASSERT_EQUAL, ASSERT_NOT_EQUAL, SQR_ADD, ASSERT_EQUAL, ASSERT_NOT_EQUAL, SQR_ADD, SUBTRACT_WITH_CONSTRAINT, \
23 DIVIDE_WITH_CONSTRAINTS, SLICE, ASSERT_ZERO, ASSERT_NOT_ZERO, COND_NEGATE, ADD_MULTI, ASSERT_VALID, \
24 COND_SELECT, DOUBLE, RANDOMSEED, SELECT_IF_ZERO, SELECT_IF_EQ, REVERSE, GET_BIT, SET_BIT, SET, INVERT, AND, \
25 OR, XOR, MODULO, SHL, SHR, ROL, ROR, NOT, BATCH_MUL, COND_ASSIGN
26
28 size_t GEN_LLVM_POST_MUTATION_PROB; // Controls frequency of additional mutation after structural ones
29 size_t GEN_MUTATION_COUNT_LOG; // This is the logarithm of the number of micromutations applied during mutation of a
30 // testcase
31 size_t GEN_STRUCTURAL_MUTATION_PROBABILITY; // The probability of applying a structural mutation
32 // (DELETION/DUPLICATION/INSERTION/SWAP)
33 size_t GEN_VALUE_MUTATION_PROBABILITY; // The probability of applying a value mutation
34 size_t ST_MUT_DELETION_PROBABILITY; // The probability of applying DELETION mutation
35 size_t ST_MUT_DUPLICATION_PROBABILITY; // The probability of applying DUPLICATION mutation
36 size_t ST_MUT_INSERTION_PROBABILITY; // The probability of applying INSERTION mutation
37 size_t ST_MUT_MAXIMUM_DELETION_LOG; // The logarithm of the maximum of deletions
38 size_t ST_MUT_MAXIMUM_DUPLICATION_LOG; // The logarithm of the maximum of duplication
39 size_t ST_MUT_SWAP_PROBABILITY; // The probability of a SWAP mutation
40 size_t VAL_MUT_LLVM_MUTATE_PROBABILITY; // The probablity of using the LLVM mutator on field element value
41 size_t VAL_MUT_MONTGOMERY_PROBABILITY; // The probability of converting to montgomery form before applying value
42 // mutations
43 size_t VAL_MUT_NON_MONTGOMERY_PROBABILITY; // The probability of not converting to montgomery form before applying
44 // value mutations
45 size_t VAL_MUT_SMALL_ADDITION_PROBABILITY; // The probability of performing small additions
46 size_t VAL_MUT_SPECIAL_VALUE_PROBABILITY; // The probability of assigning special values (0,1, p-1, p-2, p-1/2)
47 std::vector<size_t> structural_mutation_distribution; // Holds the values to quickly select a structural mutation
48 // based on chosen probabilities
49 std::vector<size_t> value_mutation_distribution; // Holds the values to quickly select a value mutation based on
50 // chosen probabilities
51};
52#ifdef HAVOC_TESTING
53
54HavocSettings fuzzer_havoc_settings;
55#endif
56// This is an external function in Libfuzzer used internally by custom mutators
57extern "C" size_t LLVMFuzzerMutate(uint8_t* Data, size_t Size, size_t MaxSize);
58
64 uint32_t state;
65
66 public:
67 FastRandom(uint32_t seed) { reseed(seed); }
68 uint32_t next()
69 {
70 state = static_cast<uint32_t>(
71 (static_cast<uint64_t>(state) * static_cast<uint64_t>(363364578) + static_cast<uint64_t>(537)) %
72 static_cast<uint64_t>(3758096939));
73 return state;
74 }
75 void reseed(uint32_t seed)
76 {
77 if (seed == 0) {
78 seed = 1;
79 }
80 state = seed;
81 }
82};
83
84// Sample a uint256_t value from log distribution
85// That is we first sample the bit count in [0..255]
86// And then shrink the random [0..2^255] value
87// This helps to get smaller values more frequently
88template <typename T> static inline uint256_t fast_log_distributed_uint256(T& rng)
89{
90 uint256_t temp;
91 // Generate a random mask_size-bit value
92 // We want to sample from log distribution instead of uniform
93 uint16_t* p = (uint16_t*)&temp;
94 uint8_t mask_size = static_cast<uint8_t>(rng.next() & 0xff);
95 for (size_t i = 0; i < 16; i++) {
96 *(p + i) = static_cast<uint16_t>(rng.next() & 0xffff);
97 }
98 uint256_t mask = (uint256_t(1) << mask_size) - 1;
99 temp &= mask;
100 temp += 1; // I believe we want to avoid lots of infs
101 return temp;
102}
103
104// Read uint256_t from raw bytes.
105// Don't use dereference casts, since the data may be not aligned and it causes segfault
106uint256_t read_uint256(const uint8_t* data, size_t buffer_size = 32)
107{
108 BB_ASSERT_LTE(buffer_size, 32U);
109
110 uint64_t parts[4] = { 0, 0, 0, 0 };
111
112 for (size_t i = 0; i < (buffer_size + 7) / 8; i++) {
113 size_t to_read = (buffer_size - i * 8) < 8 ? buffer_size - i * 8 : 8;
114 std::memcpy(&parts[i], data + i * 8, to_read);
115 }
116 return uint256_t(parts[0], parts[1], parts[2], parts[3]);
117}
118
124template <typename T>
125concept SimpleRng = requires(T a) {
126 { a.next() } -> std::convertible_to<uint32_t>;
127};
133template <typename T>
134concept InstructionArgumentSizes = requires {
135 {
136 std::make_tuple(T::CONSTANT,
137 T::WITNESS,
138 T::CONSTANT_WITNESS,
139 T::ADD,
140 T::SUBTRACT,
141 T::MULTIPLY,
142 T::DIVIDE,
143 T::ADD_TWO,
144 T::MADD,
145 T::MULT_MADD,
146 T::MSUB_DIV,
147 T::SQR,
148 T::SQR_ADD,
149 T::SUBTRACT_WITH_CONSTRAINT,
150 T::DIVIDE_WITH_CONSTRAINTS,
151 T::SLICE,
152 T::ASSERT_ZERO,
153 T::ASSERT_NOT_ZERO)
155};
156
162template <typename T>
163concept HavocConfigConstraint = requires {
164 {
165 std::make_tuple(T::GEN_MUTATION_COUNT_LOG, T::GEN_STRUCTURAL_MUTATION_PROBABILITY)
167 T::GEN_MUTATION_COUNT_LOG <= 7;
168};
174template <typename T>
176 typename T::ArgSizes;
177 typename T::Instruction;
178 typename T::ExecutionState;
179 typename T::ExecutionHandler;
181};
182
188template <typename T>
189concept CheckableComposer = requires(T a) {
191};
192
200template <typename T, typename Composer, typename Context>
201concept PostProcessingEnabled = requires(Composer composer, Context context) {
202 { T::postProcess(&composer, context) } -> std::same_as<bool>;
203};
204
211template <typename T>
212concept InstructionWeightsEnabled = requires {
213 typename T::InstructionWeights;
214 T::InstructionWeights::_LIMIT;
215};
216
226template <typename T, typename FF>
227inline static FF mutateFieldElement(FF e, T& rng)
228 requires SimpleRng<T>
229{
230 // With a certain probability, we apply changes to the Montgomery form, rather than the plain form. This
231 // has merit, since the computation is performed in montgomery form and comparisons are often performed
232 // in it, too. Libfuzzer comparison tracing logic can then be enabled in Montgomery form
233 bool convert_to_montgomery = (rng.next() & 1);
234 uint256_t value_data;
235 // Conversion at the start
236#define MONT_CONVERSION_LOCAL \
237 if (convert_to_montgomery) { \
238 value_data = uint256_t(e.to_montgomery_form()); \
239 } else { \
240 value_data = uint256_t(e); \
241 }
242 // Inverse conversion at the end
243#define INV_MONT_CONVERSION_LOCAL \
244 if (convert_to_montgomery) { \
245 e = FF(value_data).from_montgomery_form(); \
246 } else { \
247 e = FF(value_data); \
248 }
249
250 // Pick the last value from the mutation distribution vector
251 // Choose mutation
252 const size_t choice = rng.next() % 4;
253 // 50% probability to use standard mutation
254 if (choice < 2) {
255 // Delegate mutation to libfuzzer (bit/byte mutations, autodictionary, etc)
257 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
258 LLVMFuzzerMutate(reinterpret_cast<uint8_t*>(&value_data), sizeof(uint256_t), sizeof(uint256_t));
260 } else if (choice < 3) { // 25% to use small additions
261
262 // Small addition/subtraction
263 if (convert_to_montgomery) {
264 e = e.to_montgomery_form();
265 }
266 if (rng.next() & 1) {
267 e += FF(rng.next() & 0xff);
268 } else {
269 e -= FF(rng.next() & 0xff);
270 }
271 if (convert_to_montgomery) {
272 e = e.from_montgomery_form();
273 }
274 } else { // 25% to use special values
275
276 // Substitute field element with a special value
277 switch (rng.next() % 8) {
278 case 0:
279 e = FF::zero();
280 break;
281 case 1:
282 e = FF::one();
283 break;
284 case 2:
285 e = -FF::one();
286 break;
287 case 3:
288 e = FF::one().sqrt().second;
289 break;
290 case 4:
291 e = FF::one().sqrt().second.invert();
292 break;
293 case 5:
295 break;
296 case 6:
297 e = FF(2);
298 break;
299 case 7:
300 e = FF((FF::modulus - 1) / 2);
301 break;
302 default:
303 abort();
304 break;
305 }
306 if (convert_to_montgomery) {
307 e = e.from_montgomery_form();
308 }
309 }
310 // Return instruction
311 return e;
312}
313
319template <typename T>
322 private:
330 {
331 const size_t instructions_count = instructions.size();
332 if (instructions_count <= 2) {
333 return;
334 }
335 const size_t first_element_index = rng.next() % instructions_count;
336 size_t second_element_index = rng.next() % instructions_count;
337 if (first_element_index == second_element_index) {
338 second_element_index = (second_element_index + 1) % instructions_count;
339 }
340 std::iter_swap(instructions.begin() + static_cast<int>(first_element_index),
341 instructions.begin() + static_cast<int>(second_element_index));
342 }
343
352 FastRandom& rng,
353 HavocSettings& havoc_settings)
354 {
355
356 const size_t instructions_count = instructions.size();
357 if (instructions_count == 0) {
358 return;
359 }
360 if ((rng.next() & 1) != 0U) {
361 instructions.erase(instructions.begin() + (rng.next() % instructions_count));
362 } else {
363 // We get the logarithm of number of instructions and subtract 1 to delete at most half
364 const size_t max_deletion_log =
365 std::min(static_cast<size_t>(64 - __builtin_clzll(static_cast<uint64_t>(instructions_count)) - 1),
366 havoc_settings.ST_MUT_MAXIMUM_DELETION_LOG);
367
368 if (max_deletion_log == 0) {
369 return;
370 }
371 const size_t deletion_size = 1 << (rng.next() % max_deletion_log);
372 const size_t start = rng.next() % (instructions_count + 1 - deletion_size);
373 instructions.erase(instructions.begin() + static_cast<int>(start),
374 instructions.begin() + static_cast<int>(start + deletion_size));
375 }
376 }
385 FastRandom& rng,
386 HavocSettings& havoc_settings)
387 {
388 const size_t instructions_count = instructions.size();
389 if (instructions_count == 0) {
390 return;
391 }
392 const size_t duplication_size = 1 << (rng.next() % havoc_settings.ST_MUT_MAXIMUM_DUPLICATION_LOG);
393 typename T::Instruction chosen_instruction = instructions[rng.next() % instructions_count];
394 instructions.insert(
395 instructions.begin() + (rng.next() % (instructions_count + 1)), duplication_size, chosen_instruction);
396 }
398 FastRandom& rng,
399 HavocSettings& havoc_settings)
400 {
401 (void)havoc_settings;
402 instructions.insert(instructions.begin() + static_cast<int>(rng.next() % (instructions.size() + 1)),
403 T::Instruction::template generateRandom<FastRandom>(rng));
404 }
413 FastRandom& rng,
414 HavocSettings& havoc_settings)
415 {
416 const size_t structural_mutators_count = havoc_settings.structural_mutation_distribution.size();
417 const size_t prob_pool = havoc_settings.structural_mutation_distribution[structural_mutators_count - 1];
418 const size_t choice = rng.next() % prob_pool;
419 if (choice < havoc_settings.structural_mutation_distribution[0]) {
420 deleteInstructions(instructions, rng, havoc_settings);
421 } else if (choice < havoc_settings.structural_mutation_distribution[1]) {
422
423 duplicateInstruction(instructions, rng, havoc_settings);
424 } else if (choice < havoc_settings.structural_mutation_distribution[2]) {
425 insertRandomInstruction(instructions, rng, havoc_settings);
426 } else {
427
428 swapTwoInstructions(instructions, rng);
429 }
430 }
439 FastRandom& rng,
440 HavocSettings& havoc_settings)
441 {
442
443 const size_t instructions_count = instructions.size();
444 if (instructions_count == 0) {
445 return;
446 }
447 const size_t chosen = rng.next() % instructions_count;
448 instructions[chosen] =
449 T::Instruction::template mutateInstruction<FastRandom>(instructions[chosen], rng, havoc_settings);
450 }
451
453 {
454#ifdef HAVOC_TESTING
455 // If we are testing which havoc settings are best, then we use global parameters
456 const size_t mutation_count = 1 << fuzzer_havoc_settings.GEN_MUTATION_COUNT_LOG;
457#else
458 const size_t mutation_count = 1 << T::HavocConfig::MUTATION_COUNT_LOG;
459 HavocSettings fuzzer_havoc_settings;
460 // FILL the values
461#endif
462 for (size_t i = 0; i < mutation_count; i++) {
463 uint32_t val = rng.next();
464 if ((val % (fuzzer_havoc_settings.GEN_STRUCTURAL_MUTATION_PROBABILITY +
465 fuzzer_havoc_settings.GEN_VALUE_MUTATION_PROBABILITY)) <
466 fuzzer_havoc_settings.GEN_STRUCTURAL_MUTATION_PROBABILITY) {
467 // mutate structure
468 mutateInstructionStructure(instructions, rng, fuzzer_havoc_settings);
469 } else {
470 // mutate a single instruction vector
471
472 mutateInstructionValue(instructions, rng, fuzzer_havoc_settings);
473 }
474 }
475 }
476
477 public:
489 FastRandom& rng)
490 {
491 // Get vector sizes
492 const size_t vecA_size = vecA.size();
493 const size_t vecB_size = vecB.size();
494 // If one of them is empty, just return the other one
495 if (vecA_size == 0) {
496 return vecB;
497 }
498 if (vecB_size == 0) {
499 return vecA;
500 }
502 // Choose the size of th resulting vector
503 const size_t final_result_size = rng.next() % (vecA_size + vecB_size) + 1;
504 size_t indexA = 0;
505 size_t indexB = 0;
506 size_t* inIndex = &indexA;
507 size_t inSize = vecA_size;
508 auto inIterator = vecA.begin();
509 size_t current_result_size = 0;
510 bool currentlyUsingA = true;
511 // What we do is basically pick a sequence from one, follow with a sequence from the other
512 while (current_result_size < final_result_size && (indexA < vecA_size || indexB < vecB_size)) {
513 // Get the size left
514 size_t result_size_left = final_result_size - current_result_size;
515 // If we can still read from this vector
516 if (*inIndex < inSize) {
517 // Get the size left in this vector and in the output vector and pick the lowest
518 size_t inSizeLeft = inSize - *inIndex;
519 size_t maxExtraSize = std::min(result_size_left, inSizeLeft);
520 if (maxExtraSize != 0) {
521 // If not zero, get a random number of elements from input
522 size_t copySize = (rng.next() % maxExtraSize) + 1;
523 result.insert(result.begin() + static_cast<long>(current_result_size),
524 inIterator + static_cast<long>((*inIndex)),
525
526 inIterator + static_cast<long>((*inIndex) + copySize));
527 // Update indexes and sizes
528 *inIndex += copySize;
529 current_result_size += copySize;
530 }
531 }
532 // Switch input vector
533 inIndex = currentlyUsingA ? &indexB : &indexA;
534 inSize = currentlyUsingA ? vecB_size : vecA_size;
535 inIterator = currentlyUsingA ? vecB.begin() : vecA.begin();
536 currentlyUsingA = !currentlyUsingA;
537 }
538 // Return spliced vector
539 return result;
540 }
549 {
550 std::vector<typename T::Instruction> fuzzingInstructions;
551 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
552 auto* pData = const_cast<uint8_t*>(Data);
553 size_t size_left = Size;
554 while (size_left != 0) {
555 uint8_t chosen_operation = *pData;
556 size_left -= 1;
557 pData++;
558 // If the opcode is enabled (exists and arguments' size is not -1), check if it's the right opcode. If it
559 // is, parse it with a designated function
560#define PARSE_OPCODE(name) \
561 if constexpr (requires { T::ArgSizes::name; }) \
562 if constexpr (T::ArgSizes::name != size_t(-1)) { \
563 if (chosen_operation == T::Instruction::OPCODE::name) { \
564 if (size_left < T::ArgSizes::name) { \
565 return fuzzingInstructions; \
566 } \
567 fuzzingInstructions.push_back( \
568 T::Parser::template parseInstructionArgs<T::Instruction::OPCODE::name>(pData)); \
569 size_left -= T::ArgSizes::name; \
570 pData += T::ArgSizes::name; \
571 continue; \
572 } \
573 }
574 // Create handlers for all opcodes that are in ArgsSizes
575#define PARSE_ALL_OPCODES(...) FOR_EACH(PARSE_OPCODE, __VA_ARGS__)
576
578 }
579 return fuzzingInstructions;
580 }
590 uint8_t* Data,
591 size_t MaxSize)
592 {
593 uint8_t* pData = Data;
594 size_t size_left = MaxSize;
595 for (auto& instruction : instructions) {
596 // If the opcode is enabled and it's this opcode, use a designated function to serialize it
597#define WRITE_OPCODE_IF(name) \
598 if constexpr (requires { T::ArgSizes::name; }) \
599 if constexpr (T::ArgSizes::name != (size_t)-1) { \
600 if (instruction.id == T::Instruction::OPCODE::name) { \
601 if (size_left >= (T::ArgSizes::name + 1)) { \
602 T::Parser::template writeInstruction<T::Instruction::OPCODE::name>(instruction, pData); \
603 size_left -= (T::ArgSizes::name + 1); \
604 pData += (T::ArgSizes::name + 1); \
605 } else { \
606 return MaxSize - size_left; \
607 } \
608 continue; \
609 } \
610 }
611 // Create handlers for all opcodes that are in ArgsSizes
612#define WRITE_ALL_OPCODES(...) FOR_EACH(WRITE_OPCODE_IF, __VA_ARGS__)
613
615 }
616 return MaxSize - size_left;
617 }
618
625 template <typename Composer>
626 // TODO(@Rumata888)(from Zac: maybe try to fix? not comfortable refactoring this myself. Issue #1807)
627 // NOLINTNEXTLINE(readability-function-size, google-readability-function-size)
630 {
631 typename T::ExecutionState state;
632 Composer composer = Composer();
633 // This is a global variable, so that the execution handling class could alter it and signal to the input tester
634 circuit_should_fail = false;
635 size_t total_instruction_weight = 0;
636 (void)total_instruction_weight;
637 for (auto& instruction : instructions) {
638 // If instruction enabled and this is it, delegate to the handler
639#define EXECUTE_OPCODE_IF(name) \
640 if constexpr (requires { T::ArgSizes::name; }) \
641 if constexpr (T::ArgSizes::name != size_t(-1)) { \
642 if (instruction.id == T::Instruction::OPCODE::name) { \
643 if constexpr (InstructionWeightsEnabled<T>) { \
644 if (!((total_instruction_weight + T::InstructionWeights::name) > T::InstructionWeights::_LIMIT)) { \
645 total_instruction_weight += T::InstructionWeights::name; \
646 if (T::ExecutionHandler::execute_##name(&composer, state, instruction)) { \
647 return; \
648 } \
649 } else { \
650 return; \
651 } \
652 } else { \
653 \
654 if (T::ExecutionHandler::execute_##name(&composer, state, instruction)) { \
655 return; \
656 } \
657 } \
658 } \
659 }
660#define EXECUTE_ALL_OPCODES(...) FOR_EACH(EXECUTE_OPCODE_IF, __VA_ARGS__)
661
663 }
664 bool final_value_check = true;
665 // If there is a posprocessing function, use it
667 final_value_check = T::postProcess(&composer, state);
668
669#ifdef FUZZING_SHOW_INFORMATION
670 if (!final_value_check) {
671 std::cerr << "Final value check failed" << std::endl;
672 }
673#endif
674 }
675 bool check_result = bb::CircuitChecker::check(composer) && final_value_check;
676#ifndef FUZZING_DISABLE_WARNINGS
678 info("circuit should fail");
679 }
680#endif
681 // If the circuit is correct, but it should fail, abort
682 if (check_result && circuit_should_fail) {
683 abort();
684 }
685 // If the circuit is incorrect, but there's no reason, abort
686 if ((!check_result) && (!circuit_should_fail)) {
687 if (!final_value_check) {
688 std::cerr << "Final value check failed" << std::endl;
689 } else {
690 std::cerr << "Circuit failed" << std::endl;
691 }
692
693 abort();
694 }
695 }
696
705 static size_t MutateInstructionBuffer(uint8_t* Data, size_t Size, size_t MaxSize, FastRandom& rng)
706 {
707 // Parse the vector
709 // Mutate the vector of instructions
710 mutateInstructionVector(instructions, rng);
711 // Serialize the vector of instructions back to buffer
712 return writeInstructionsToBuffer(instructions, Data, MaxSize);
713 }
714};
715
716template <template <typename> class Fuzzer, typename Composer>
717constexpr void RunWithBuilder(const uint8_t* Data, const size_t Size, FastRandom& VarianceRNG)
718{
720 auto instructions = ArithmeticFuzzHelper<Fuzzer<Composer>>::parseDataIntoInstructions(Data, Size);
721 ArithmeticFuzzHelper<Fuzzer<Composer>>::template executeInstructions<Composer>(instructions);
722}
723
724template <template <typename> class Fuzzer, uint64_t Composers>
725constexpr void RunWithBuilders(const uint8_t* Data, const size_t Size, FastRandom& VarianceRNG)
726{
727 RunWithBuilder<Fuzzer, bb::UltraCircuitBuilder>(Data, Size, VarianceRNG);
728}
729
730// NOLINTEND(cppcoreguidelines-macro-usage, google-runtime-int)
#define BB_ASSERT_LTE(left, right,...)
Definition assert.hpp:129
bb::fr FF
FastRandom VarianceRNG(0)
bool circuit_should_fail
A templated class containing most of the fuzzing logic for a generic Arithmetic class.
Definition fuzzer.hpp:321
static void mutateInstructionVector(std::vector< typename T::Instruction > &instructions, FastRandom &rng)
Definition fuzzer.hpp:452
static size_t writeInstructionsToBuffer(std::vector< typename T::Instruction > &instructions, uint8_t *Data, size_t MaxSize)
Write instructions into the buffer until there are no instructions left or there is no more space.
Definition fuzzer.hpp:589
static void duplicateInstruction(std::vector< typename T::Instruction > &instructions, FastRandom &rng, HavocSettings &havoc_settings)
Mutator duplicating an instruction.
Definition fuzzer.hpp:384
static std::vector< typename T::Instruction > parseDataIntoInstructions(const uint8_t *Data, size_t Size)
Parses a given data buffer into a vector of instructions for testing the arithmetic.
Definition fuzzer.hpp:548
static void swapTwoInstructions(std::vector< typename T::Instruction > &instructions, FastRandom &rng)
Mutator swapping two instructions together.
Definition fuzzer.hpp:329
static size_t MutateInstructionBuffer(uint8_t *Data, size_t Size, size_t MaxSize, FastRandom &rng)
Interpret the data buffer as a series of arithmetic instructions and mutate it accordingly.
Definition fuzzer.hpp:705
static std::vector< typename T::Instruction > crossoverInstructionVector(const std::vector< typename T::Instruction > &vecA, const std::vector< typename T::Instruction > &vecB, FastRandom &rng)
Splice two instruction vectors into one randomly.
Definition fuzzer.hpp:486
static void deleteInstructions(std::vector< typename T::Instruction > &instructions, FastRandom &rng, HavocSettings &havoc_settings)
Mutator, deleting a sequence of instructions.
Definition fuzzer.hpp:351
static void executeInstructions(std::vector< typename T::Instruction > &instructions)
Execute instructions in a loop.
Definition fuzzer.hpp:628
static void insertRandomInstruction(std::vector< typename T::Instruction > &instructions, FastRandom &rng, HavocSettings &havoc_settings)
Definition fuzzer.hpp:397
static void mutateInstructionValue(std::vector< typename T::Instruction > &instructions, FastRandom &rng, HavocSettings &havoc_settings)
Choose a random instruction from the vector and mutate it.
Definition fuzzer.hpp:438
static void mutateInstructionStructure(std::vector< typename T::Instruction > &instructions, FastRandom &rng, HavocSettings &havoc_settings)
Mutator for instruction structure.
Definition fuzzer.hpp:412
Class for quickly deterministically creating new random values. We don't care about distribution much...
Definition fuzzer.hpp:63
FastRandom(uint32_t seed)
Definition fuzzer.hpp:67
uint32_t state
Definition fuzzer.hpp:64
void reseed(uint32_t seed)
Definition fuzzer.hpp:75
uint32_t next()
Definition fuzzer.hpp:68
static bool check(const Builder &circuit)
Check the witness satisifies the circuit.
void info(Args... args)
Definition log.hpp:70
Concept specifying the class used by the fuzzer.
Definition fuzzer.hpp:175
Fuzzer uses only composers with check_circuit function.
Definition fuzzer.hpp:189
Concept for Havoc Configurations.
Definition fuzzer.hpp:163
Concept for forcing ArgumentSizes to be size_t.
Definition fuzzer.hpp:134
This concept is used when we want to limit the number of executions of certain instructions (for exam...
Definition fuzzer.hpp:212
The fuzzer can use a postprocessing function that is specific to the type being fuzzed.
Definition fuzzer.hpp:201
Concept for a simple PRNG which returns a uint32_t when next is called.
Definition fuzzer.hpp:125
const std::vector< FF > data
StrictMock< MockContext > context
FF a
#define INV_MONT_CONVERSION_LOCAL
#define WRITE_ALL_OPCODES(...)
uint256_t read_uint256(const uint8_t *data, size_t buffer_size=32)
Definition fuzzer.hpp:106
size_t LLVMFuzzerMutate(uint8_t *Data, size_t Size, size_t MaxSize)
constexpr void RunWithBuilder(const uint8_t *Data, const size_t Size, FastRandom &VarianceRNG)
Definition fuzzer.hpp:717
#define EXECUTE_ALL_OPCODES(...)
#define PARSE_ALL_OPCODES(...)
#define ALL_POSSIBLE_OPCODES
Definition fuzzer.hpp:20
#define MONT_CONVERSION_LOCAL
constexpr void RunWithBuilders(const uint8_t *Data, const size_t Size, FastRandom &VarianceRNG)
Definition fuzzer.hpp:725
Instruction instruction
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
size_t GEN_VALUE_MUTATION_PROBABILITY
Definition fuzzer.hpp:33
size_t ST_MUT_MAXIMUM_DELETION_LOG
Definition fuzzer.hpp:37
size_t GEN_MUTATION_COUNT_LOG
Definition fuzzer.hpp:29
size_t ST_MUT_MAXIMUM_DUPLICATION_LOG
Definition fuzzer.hpp:38
size_t VAL_MUT_LLVM_MUTATE_PROBABILITY
Definition fuzzer.hpp:40
size_t ST_MUT_DELETION_PROBABILITY
Definition fuzzer.hpp:34
size_t VAL_MUT_SMALL_ADDITION_PROBABILITY
Definition fuzzer.hpp:45
size_t ST_MUT_DUPLICATION_PROBABILITY
Definition fuzzer.hpp:35
size_t VAL_MUT_SPECIAL_VALUE_PROBABILITY
Definition fuzzer.hpp:46
std::vector< size_t > value_mutation_distribution
Definition fuzzer.hpp:49
size_t GEN_STRUCTURAL_MUTATION_PROBABILITY
Definition fuzzer.hpp:31
size_t VAL_MUT_MONTGOMERY_PROBABILITY
Definition fuzzer.hpp:41
size_t VAL_MUT_NON_MONTGOMERY_PROBABILITY
Definition fuzzer.hpp:43
size_t ST_MUT_SWAP_PROBABILITY
Definition fuzzer.hpp:39
size_t GEN_LLVM_POST_MUTATION_PROB
Definition fuzzer.hpp:28
std::vector< size_t > structural_mutation_distribution
Definition fuzzer.hpp:47
size_t ST_MUT_INSERTION_PROBABILITY
Definition fuzzer.hpp:36
static constexpr field get_root_of_unity(size_t subgroup_size) noexcept
static constexpr field one()
static constexpr uint256_t modulus
constexpr std::pair< bool, field > sqrt() const noexcept
Compute square root of the field element.
static constexpr field zero()