14#pragma clang diagnostic push
15#pragma clang diagnostic ignored "-Wc99-designator"
30#ifdef FUZZING_SHOW_INFORMATION
31#define PRINT_SINGLE_ARG_INSTRUCTION(first_index, vector, operation_name, preposition) \
33 std::cout << operation_name << " " << (vector[first_index].field.is_constant() ? "constant(" : "witness(") \
34 << vector[first_index].field.get_value() << ") at " << first_index << " " << preposition \
38#define PRINT_TWO_ARG_INSTRUCTION(first_index, second_index, vector, operation_name, preposition) \
40 std::cout << operation_name << " " << (vector[first_index].field.is_constant() ? "constant(" : "witness(") \
41 << vector[first_index].field.get_value() << ") at " << first_index << " " << preposition << " " \
42 << (vector[second_index].field.is_constant() ? "constant(" : "witness(") \
43 << vector[second_index].field.get_value() << ") at " << second_index << std::flush; \
46#define PRINT_THREE_ARG_INSTRUCTION( \
47 first_index, second_index, third_index, vector, operation_name, preposition1, preposition2) \
49 std::cout << operation_name << " " << (vector[first_index].field.is_constant() ? "constant(" : "witness(") \
50 << vector[first_index].field.get_value() << ") at " << first_index << " " << preposition1 << " " \
51 << (vector[second_index].field.is_constant() ? "constant(" : "witness(") \
52 << vector[second_index].field.get_value() << ") at " << second_index << " " << preposition2 << " " \
53 << (vector[third_index].field.is_constant() ? "constant(" : "witness(") \
54 << vector[third_index].field.get_value() << ") at " << third_index << std::flush; \
56#define PRINT_TWO_ARG_ONE_VALUE_INSTRUCTION( \
57 first_index, second_index, third_index, vector, operation_name, preposition1, preposition2) \
59 std::cout << operation_name << " " << (vector[first_index].field.is_constant() ? "constant(" : "witness(") \
60 << vector[first_index].field.get_value() << ") at " << first_index << " " << preposition1 << " " \
61 << (vector[second_index].field.is_constant() ? "constant(" : "witness(") \
62 << vector[second_index].field.get_value() << ") at " << second_index << " " << preposition2 << " " \
63 << third_index << std::flush; \
66#define PRINT_TWO_ARG_TWO_VALUES_INSTRUCTION( \
67 first_index, second_index, value1, value2, vector, operation_name, preposition1, preposition2, preposition3) \
69 std::cout << operation_name << " " << (vector[first_index].field.is_constant() ? "constant(" : "witness(") \
70 << vector[first_index].field.get_value() << ") at " << first_index << " " << preposition1 << " " \
71 << (vector[second_index].field.is_constant() ? "constant(" : "witness(") \
72 << vector[second_index].field.get_value() << ") at " << second_index << " " << preposition2 << " " \
73 << value1 << preposition3 << value2 << std::flush; \
76#define PRINT_RESULT(prefix, action, index, value) \
78 std::cout << " result(" << value.field.get_value() << ")" << action << index << std::endl << std::flush; \
83#define PRINT_SINGLE_ARG_INSTRUCTION(first_index, vector, operation_name, preposition)
84#define PRINT_TWO_ARG_INSTRUCTION(first_index, second_index, vector, operation_name, preposition)
86#define PRINT_TWO_ARG_ONE_VALUE_INSTRUCTION( \
87 first_index, second_index, third_index, vector, operation_name, preposition1, preposition2)
88#define PRINT_TWO_ARG_TWO_VALUES_INSTRUCTION( \
89 first_index, second_index, value1, value2, vector, operation_name, preposition1, preposition2, preposition3)
91#define PRINT_THREE_ARG_INSTRUCTION( \
92 first_index, second_index, third_index, vector, operation_name, preposition1, preposition2)
93#define PRINT_RESULT(prefix, action, index, value)
96#define OPERATION_TYPE_SIZE 1
98#define ELEMENT_SIZE (sizeof(bb::fr) + 1)
99#define TWO_IN_ONE_OUT 3
100#define THREE_IN_ONE_OUT 4
102#define MSUB_DIV_MINIMUM_MUL_PAIRS 1
103#define MSUB_DIV_MAXIMUM_MUL_PAIRS 8
104#define MSUB_DIV_MINIMUM_SUBTRACTED_ELEMENTS 0
105#define MSUB_DIV_MAXIMUM_SUBTRACTED_ELEMENTS 8
106#define MULT_MADD_MINIMUM_MUL_PAIRS 1
107#define MULT_MADD_MAXIMUM_MUL_PAIRS 8
108#define MULT_MADD_MINIMUM_ADDED_ELEMENTS 0
109#define MULT_MADD_MAXIMUM_ADDED_ELEMENTS 8
110#define SQR_ADD_MINIMUM_ADDED_ELEMENTS 0
111#define SQR_ADD_MAXIMUM_ADDED_ELEMENTS 8
137#ifndef DISABLE_DIVISION
224 template <
typename T>
230 uint8_t in1, in2, in3, out, mask_size;
234 switch (instruction_opcode) {
240 for (
size_t i = 0; i < (
sizeof(
uint256_t) >> 1); i++) {
241 *(((uint16_t*)&temp) + i) =
static_cast<uint16_t
>(rng.next() & 0xffff);
245 mask_size =
static_cast<uint8_t
>(rng.next() & 0xff);
249 return { .id = instruction_opcode, .arguments.element =
Element(temp & mask) };
253 in1 =
static_cast<uint8_t
>(rng.next() & 0xff);
254 return { .id = instruction_opcode, .arguments.singleArg = { .in = in1 } };
261 in1 =
static_cast<uint8_t
>(rng.next() & 0xff);
262 out =
static_cast<uint8_t
>(rng.next() & 0xff);
263 return { .id = instruction_opcode, .arguments.twoArgs = { .in = in1, .out = out } };
268#ifndef DISABLE_DIVISION
274 in1 =
static_cast<uint8_t
>(rng.next() & 0xff);
275 in2 =
static_cast<uint8_t
>(rng.next() & 0xff);
276 out =
static_cast<uint8_t
>(rng.next() & 0xff);
277 return { .id = instruction_opcode, .arguments.threeArgs = { .in1 = in1, .in2 = in2, .out = out } };
286 in1 =
static_cast<uint8_t
>(rng.next() & 0xff);
287 in2 =
static_cast<uint8_t
>(rng.next() & 0xff);
288 in3 =
static_cast<uint8_t
>(rng.next() & 0xff);
289 out =
static_cast<uint8_t
>(rng.next() & 0xff);
290 return { .id = instruction_opcode,
291 .arguments.fourArgs{ .in1 = in1, .in2 = in2, .in3 = in3, .out = out } };
294 return { .id = instruction_opcode, .arguments.randomseed = rng.next() };
311 template <
typename T>
318 bool convert_to_montgomery = (rng.next() % (havoc_config.VAL_MUT_MONTGOMERY_PROBABILITY +
319 havoc_config.VAL_MUT_NON_MONTGOMERY_PROBABILITY)) <
320 havoc_config.VAL_MUT_MONTGOMERY_PROBABILITY;
323#define MONT_CONVERSION \
324 if (convert_to_montgomery) { \
325 value_data = uint256_t(e.to_montgomery_form()); \
327 value_data = uint256_t(e); \
330#define INV_MONT_CONVERSION \
331 if (convert_to_montgomery) { \
332 e = bb::fr(value_data).from_montgomery_form(); \
334 e = bb::fr(value_data); \
338 const size_t mutation_type_count = havoc_config.value_mutation_distribution.size();
340 const size_t choice = rng.next() % havoc_config.value_mutation_distribution[mutation_type_count - 1];
341 if (choice < havoc_config.value_mutation_distribution[0]) {
346 }
else if (choice < havoc_config.value_mutation_distribution[1]) {
348 if (convert_to_montgomery) {
349 e = e.to_montgomery_form();
351 if (rng.next() & 1) {
352 e +=
bb::fr(rng.next() & 0xff);
354 e -=
bb::fr(rng.next() & 0xff);
356 if (convert_to_montgomery) {
357 e = e.from_montgomery_form();
361 switch (rng.next() % 9) {
393 if (convert_to_montgomery) {
394 e = e.from_montgomery_form();
409 template <
typename T>
413#define PUT_RANDOM_BYTE_IF_LUCKY(variable) \
414 if (rng.next() & 1) { \
415 variable = rng.next() & 0xff; \
424 if (rng.next() & 1) {
442#ifndef DISABLE_DIVISION
482 static constexpr size_t SQR = 2;
487 static constexpr size_t ADD = 3;
491#ifndef DISABLE_DIVISION
494 static constexpr size_t DIVIDE =
static_cast<size_t>(-1);
496 static constexpr size_t MADD = 4;
504 static constexpr size_t SET = 2;
518 static constexpr size_t ADD = 1;
521 static constexpr size_t SQR = 2;
527#ifndef DISABLE_DIVISION
530 static constexpr size_t MADD = 2;
538 static constexpr size_t SET = 0;
568 .arguments.singleArg = { .in = *Data } };
574 .arguments.twoArgs = { .in = *Data, .out = *(Data + 1) } };
577#ifndef DISABLE_DIVISION
582 .arguments.threeArgs = { .in1 = *Data, .in2 = *(Data + 1), .out = *(Data + 2) } };
584 if constexpr (opcode == Instruction::OPCODE::MADD || opcode == Instruction::OPCODE::ADD_TWO ||
585 opcode == Instruction::OPCODE::COND_SELECT || opcode == Instruction::OPCODE::SELECT_IF_ZERO ||
586 opcode == Instruction::OPCODE::SELECT_IF_EQ) {
588 return { .id =
static_cast<typename Instruction::OPCODE
>(opcode),
589 .arguments.fourArgs = {
590 .in1 = *Data, .in2 = *(Data + 1), .in3 = *(Data + 2), .out = *(Data + 3) } };
592 if constexpr (opcode == Instruction::OPCODE::RANDOMSEED) {
594 memcpy(&randomseed, Data,
sizeof(uint32_t));
595 return Instruction{ .id =
static_cast<typename Instruction::OPCODE
>(opcode),
596 .arguments.randomseed = randomseed };
606 template <
typename Instruction::OPCODE instruction_opcode>
609 if constexpr (instruction_opcode == Instruction::OPCODE::CONSTANT ||
610 instruction_opcode == Instruction::OPCODE::WITNESS ||
611 instruction_opcode == Instruction::OPCODE::CONSTANT_WITNESS) {
616 if constexpr (instruction_opcode == Instruction::OPCODE::ASSERT_ZERO ||
617 instruction_opcode == Instruction::OPCODE::ASSERT_NOT_ZERO) {
621 if constexpr (instruction_opcode == Instruction::OPCODE::SQR ||
622 instruction_opcode == Instruction::OPCODE::ASSERT_EQUAL ||
623 instruction_opcode == Instruction::OPCODE::ASSERT_NOT_EQUAL ||
624 instruction_opcode == Instruction::OPCODE::SET ||
625 instruction_opcode == Instruction::OPCODE::INVERT) {
630 if constexpr (instruction_opcode == Instruction::OPCODE::ADD ||
631#ifndef DISABLE_DIVISION
632 instruction_opcode == Instruction::OPCODE::DIVIDE ||
634 instruction_opcode == Instruction::OPCODE::MULTIPLY ||
635 instruction_opcode == Instruction::OPCODE::SUBTRACT ||
636 instruction_opcode == Instruction::OPCODE::COND_NEGATE) {
642 if constexpr (instruction_opcode == Instruction::OPCODE::ADD_TWO ||
643 instruction_opcode == Instruction::OPCODE::MADD ||
644 instruction_opcode == Instruction::OPCODE::COND_SELECT ||
645 instruction_opcode == Instruction::OPCODE::SELECT_IF_ZERO ||
646 instruction_opcode == Instruction::OPCODE::SELECT_IF_EQ) {
653 if constexpr (instruction_opcode == Instruction::OPCODE::RANDOMSEED) {
656 memcpy(Data + 1, &
instruction.arguments.randomseed,
sizeof(uint32_t));
670 const auto base_u256 =
static_cast<uint256_t>(this->base);
681 new_field.
context = this->field.context;
686 const auto& ref = new_field;
695 const bool predicate_has_ctx =
static_cast<bool>(
VarianceRNG.
next() % 2);
697 return bool_t(predicate_has_ctx ?
builder :
nullptr, predicate);
741 const auto b = this->base + other.
base;
763 const auto b = this->base - other.
base;
782 const auto b = this->base * other.
base;
806 const auto b = this->base / other.
base;
828 this->f().add_two(other1.
f(), other2.
f()));
845 if (this->f().is_constant()) {
850 this->assert_equal(other.
f() + to_add);
853 if (this->f().is_constant()) {
855 auto new_el = other.
f() + to_add;
856 this->assert_equal(new_el);
860 this->assert_equal(other.
f() + to_add);
867 if (this->base == other.
base) {
870 this->f().assert_not_equal(other.
f());
879 this->f().assert_is_zero();
886 this->f().assert_is_not_zero();
892 this->f().conditional_negate(construct_predicate(
builder, predicate)));
898 predicate ? other.
base : this->base,
912 field_t(
builder).conditional_assign(other1.
f() == other2.
f(), other1.
f(), this->f()));
921#ifdef FUZZING_SHOW_INFORMATION
926#ifdef FUZZING_SHOW_INFORMATION
929 return construct_via_cast<int>(std::numeric_limits<int>::max());
931#ifdef FUZZING_SHOW_INFORMATION
934 return construct_via_cast<unsigned int>(std::numeric_limits<unsigned int>::max());
936#ifdef FUZZING_SHOW_INFORMATION
939 return construct_via_cast<unsigned long>(std::numeric_limits<unsigned long>::max());
941#ifdef FUZZING_SHOW_INFORMATION
944 return construct_via_cast<uint256_t>();
946#ifdef FUZZING_SHOW_INFORMATION
970 if (
static_cast<uint256_t>(this->base) > 1) {
973#ifdef FUZZING_SHOW_INFORMATION
981#ifdef FUZZING_SHOW_INFORMATION
991 if (this->base == 0) {
1013#ifdef FUZZING_SHOW_INFORMATION
1037#ifdef FUZZING_SHOW_INFORMATION
1038 std::cout <<
"Pushed witness value " <<
instruction.arguments.element <<
" to position " << stack.size() - 1
1059 v.convert_constant_to_fixed_witness(
builder);
1061#ifdef FUZZING_SHOW_INFORMATION
1062 std::cout <<
"Pushed constant witness value " <<
instruction.arguments.element <<
" to position "
1081 if (stack.size() == 0) {
1084 size_t first_index =
instruction.arguments.threeArgs.in1 % stack.size();
1085 size_t second_index =
instruction.arguments.threeArgs.in2 % stack.size();
1086 size_t output_index =
instruction.arguments.threeArgs.out;
1091 result = stack[first_index] * stack[second_index];
1093 if (output_index >= stack.size()) {
1095 stack.push_back(result);
1099 stack[output_index] = result;
1116 if (stack.size() == 0) {
1119 size_t first_index =
instruction.arguments.threeArgs.in1 % stack.size();
1120 size_t second_index =
instruction.arguments.threeArgs.in2 % stack.size();
1121 size_t output_index =
instruction.arguments.threeArgs.out;
1126 result = stack[first_index] + stack[second_index];
1128 if (output_index >= stack.size()) {
1130 stack.push_back(result);
1134 stack[output_index] = result;
1152 if (stack.size() == 0) {
1155 size_t first_index =
instruction.arguments.twoArgs.in % stack.size();
1156 size_t output_index =
instruction.arguments.twoArgs.out;
1161 result = stack[first_index].
sqr();
1163 if (output_index >= stack.size()) {
1165 stack.push_back(result);
1169 stack[output_index] = result;
1187 if (stack.size() == 0) {
1190 size_t first_index =
instruction.arguments.twoArgs.in % stack.size();
1191 size_t second_index =
instruction.arguments.twoArgs.out % stack.size();
1194#ifdef FUZZING_SHOW_INFORMATION
1198 stack[first_index].assert_equal(stack[second_index]);
1215 if (stack.size() == 0) {
1218 size_t first_index =
instruction.arguments.twoArgs.in % stack.size();
1219 size_t second_index =
instruction.arguments.twoArgs.out % stack.size();
1222#ifdef FUZZING_SHOW_INFORMATION
1226 stack[first_index].assert_not_equal(stack[second_index]);
1243 if (stack.size() == 0) {
1246 size_t index =
instruction.arguments.singleArg.in % stack.size();
1249 if (stack[index].f().is_constant() && !stack[index].base.is_zero()) {
1253#ifdef FUZZING_SHOW_INFORMATION
1257 stack[index].assert_zero();
1274 if (stack.size() == 0) {
1277 size_t index =
instruction.arguments.singleArg.in % stack.size();
1279 if (stack[index].f().is_constant() && stack[index].base.is_zero()) {
1284#ifdef FUZZING_SHOW_INFORMATION
1287 stack[index].assert_not_zero();
1304 if (stack.size() == 0) {
1307 size_t first_index =
instruction.arguments.threeArgs.in1 % stack.size();
1308 size_t second_index =
instruction.arguments.threeArgs.in2 % stack.size();
1309 size_t output_index =
instruction.arguments.threeArgs.out;
1314 result = stack[first_index] - stack[second_index];
1316 if (output_index >= stack.size()) {
1318 stack.push_back(result);
1322 stack[output_index] = result;
1339 if (stack.size() == 0) {
1342 size_t first_index =
instruction.arguments.threeArgs.in1 % stack.size();
1343 size_t second_index =
instruction.arguments.threeArgs.in2 % stack.size();
1344 size_t output_index =
instruction.arguments.threeArgs.out;
1356 result = stack[first_index] / stack[second_index];
1358 if (output_index >= stack.size()) {
1360 stack.push_back(result);
1364 stack[output_index] = result;
1382 if (stack.size() == 0) {
1385 size_t first_index =
instruction.arguments.fourArgs.in1 % stack.size();
1386 size_t second_index =
instruction.arguments.fourArgs.in2 % stack.size();
1387 size_t third_index =
instruction.arguments.fourArgs.in3 % stack.size();
1388 size_t output_index =
instruction.arguments.fourArgs.out;
1392 result = stack[first_index].
add_two(stack[second_index], stack[third_index]);
1394 if (output_index >= stack.size()) {
1396 stack.push_back(result);
1400 stack[output_index] = result;
1418 if (stack.size() == 0) {
1421 size_t first_index =
instruction.arguments.fourArgs.in1 % stack.size();
1422 size_t second_index =
instruction.arguments.fourArgs.in2 % stack.size();
1423 size_t third_index =
instruction.arguments.fourArgs.in3 % stack.size();
1424 size_t output_index =
instruction.arguments.fourArgs.out;
1428 result = stack[first_index].
madd(stack[second_index], stack[third_index]);
1430 if (output_index >= stack.size()) {
1432 stack.push_back(result);
1436 stack[output_index] = result;
1472 if (stack.size() == 0) {
1475 size_t first_index =
instruction.arguments.threeArgs.in1 % stack.size();
1476 size_t output_index =
instruction.arguments.threeArgs.out % stack.size();
1477 bool predicate =
instruction.arguments.threeArgs.in2 % 2;
1482 if (output_index >= stack.size()) {
1484 stack.push_back(result);
1488 stack[output_index] = result;
1506 if (stack.size() == 0) {
1509 size_t first_index =
instruction.arguments.fourArgs.in1 % stack.size();
1510 size_t second_index =
instruction.arguments.fourArgs.in2 % stack.size();
1511 size_t output_index =
instruction.arguments.fourArgs.out % stack.size();
1512 bool predicate =
instruction.arguments.fourArgs.in3 % 2;
1517 if (output_index >= stack.size()) {
1519 stack.push_back(result);
1523 stack[output_index] = result;
1540 if (stack.size() == 0) {
1543 size_t first_index =
instruction.arguments.fourArgs.in1 % stack.size();
1544 size_t second_index =
instruction.arguments.fourArgs.in2 % stack.size();
1545 size_t third_index =
instruction.arguments.fourArgs.in3 % stack.size();
1546 size_t output_index =
instruction.arguments.fourArgs.out % stack.size();
1551 if (output_index >= stack.size()) {
1553 stack.push_back(result);
1557 stack[output_index] = result;
1574 if (stack.size() == 0) {
1577 size_t first_index =
instruction.arguments.fourArgs.in1 % stack.size();
1578 size_t second_index =
instruction.arguments.fourArgs.in2 % stack.size();
1579 size_t third_index =
instruction.arguments.fourArgs.in3 % stack.size();
1580 size_t output_index =
instruction.arguments.fourArgs.out % stack.size();
1583 result = stack[first_index].
select_if_eq(
builder, stack[second_index], stack[third_index]);
1585 if (output_index >= stack.size()) {
1587 stack.push_back(result);
1591 stack[output_index] = result;
1608 if (stack.size() == 0) {
1611 size_t first_index =
instruction.arguments.twoArgs.in % stack.size();
1612 size_t output_index =
instruction.arguments.twoArgs.out;
1619 if (output_index >= stack.size()) {
1621 stack.push_back(result);
1624 stack[output_index] = result;
1641 if (stack.size() == 0) {
1644 size_t first_index =
instruction.arguments.twoArgs.in % stack.size();
1645 size_t output_index =
instruction.arguments.twoArgs.out;
1650 result = stack[first_index].
invert();
1652 if (output_index >= stack.size()) {
1654 stack.push_back(result);
1657 stack[output_index] = result;
1679 for (
size_t i = 0; i < stack.size(); i++) {
1680 auto element = stack[i];
1682 std::cerr <<
"Failed at " << i <<
" with actual value " << element.base <<
" and value in field "
1683 << element.field.get_value() <<
std::endl;
1701 .GEN_MUTATION_COUNT_LOG = 5,
1702 .GEN_STRUCTURAL_MUTATION_PROBABILITY = 300,
1703 .GEN_VALUE_MUTATION_PROBABILITY = 700,
1704 .ST_MUT_DELETION_PROBABILITY = 100,
1705 .ST_MUT_DUPLICATION_PROBABILITY = 80,
1706 .ST_MUT_INSERTION_PROBABILITY = 120,
1707 .ST_MUT_MAXIMUM_DELETION_LOG = 6,
1708 .ST_MUT_MAXIMUM_DUPLICATION_LOG = 2,
1709 .ST_MUT_SWAP_PROBABILITY = 50,
1710 .VAL_MUT_LLVM_MUTATE_PROBABILITY = 250,
1711 .VAL_MUT_MONTGOMERY_PROBABILITY = 130,
1712 .VAL_MUT_NON_MONTGOMERY_PROBABILITY = 50,
1713 .VAL_MUT_SMALL_ADDITION_PROBABILITY = 110,
1714 .VAL_MUT_SPECIAL_VALUE_PROBABILITY = 130
1787 std::vector<size_t> structural_mutation_distribution;
1788 std::vector<size_t> value_mutation_distribution;
1790 temp += fuzzer_havoc_settings.ST_MUT_DELETION_PROBABILITY;
1791 structural_mutation_distribution.push_back(temp);
1792 temp += fuzzer_havoc_settings.ST_MUT_DUPLICATION_PROBABILITY;
1793 structural_mutation_distribution.push_back(temp);
1794 temp += fuzzer_havoc_settings.ST_MUT_INSERTION_PROBABILITY;
1795 structural_mutation_distribution.push_back(temp);
1796 temp += fuzzer_havoc_settings.ST_MUT_SWAP_PROBABILITY;
1797 structural_mutation_distribution.push_back(temp);
1798 fuzzer_havoc_settings.structural_mutation_distribution = structural_mutation_distribution;
1801 temp += fuzzer_havoc_settings.VAL_MUT_LLVM_MUTATE_PROBABILITY;
1802 value_mutation_distribution.push_back(temp);
1803 temp += fuzzer_havoc_settings.VAL_MUT_SMALL_ADDITION_PROBABILITY;
1804 value_mutation_distribution.push_back(temp);
1806 temp += fuzzer_havoc_settings.VAL_MUT_SPECIAL_VALUE_PROBABILITY;
1807 value_mutation_distribution.push_back(temp);
1808 fuzzer_havoc_settings.value_mutation_distribution = value_mutation_distribution;
1819 RunWithBuilders<FieldBase, FuzzerCircuitTypes>(Data, Size,
VarianceRNG);
1823#pragma clang diagnostic pop
#define PRINT_SINGLE_ARG_INSTRUCTION(first_index, vector, operation_name, preposition)
#define PRINT_THREE_ARG_INSTRUCTION( first_index, second_index, third_index, vector, operation_name, preposition1, preposition2)
#define PRINT_TWO_ARG_INSTRUCTION(first_index, second_index, vector, operation_name, preposition)
FastRandom VarianceRNG(0)
#define PRINT_RESULT(prefix, action, index, value)
Class for quickly deterministically creating new random values. We don't care about distribution much...
void reseed(uint32_t seed)
static constexpr size_t SELECT_IF_ZERO
static constexpr size_t ASSERT_NOT_EQUAL
static constexpr size_t COND_NEGATE
static constexpr size_t ASSERT_NOT_ZERO
static constexpr size_t INVERT
static constexpr size_t RANDOMSEED
static constexpr size_t MADD
static constexpr size_t WITNESS
static constexpr size_t MULTIPLY
static constexpr size_t SET
static constexpr size_t ASSERT_ZERO
static constexpr size_t ADD_TWO
static constexpr size_t ASSERT_EQUAL
static constexpr size_t CONSTANT_WITNESS
static constexpr size_t DIVIDE
static constexpr size_t SQR
static constexpr size_t SUBTRACT
static constexpr size_t ADD
static constexpr size_t CONSTANT
static constexpr size_t COND_SELECT
static constexpr size_t SELECT_IF_EQ
static constexpr size_t SUBTRACT_WITH_CONSTRAINT
static constexpr size_t DIVIDE_WITH_CONSTRAINTS
This class implements the execution of safeuint with an oracle to detect discrepancies.
ExecutionHandler select_if_zero(Builder *builder, ExecutionHandler &other1, ExecutionHandler &other2)
ExecutionHandler madd(const ExecutionHandler &other1, const ExecutionHandler &other2)
static bool_t construct_predicate(Builder *builder, const bool predicate)
static size_t execute_ASSERT_EQUAL(Builder *builder, std::vector< ExecutionHandler > &stack, Instruction &instruction)
Execute the ASSERT_EQUAL instruction.
static size_t execute_CONSTANT_WITNESS(Builder *builder, std::vector< ExecutionHandler > &stack, Instruction &instruction)
Execute the constant_witness instruction (push a safeuint witness equal to the constant to the stack)
static size_t execute_CONSTANT(Builder *builder, std::vector< ExecutionHandler > &stack, Instruction &instruction)
Execute the constant instruction (push constant safeuint to the stack)
void assert_equal(ExecutionHandler &other)
static size_t execute_SET(Builder *builder, std::vector< ExecutionHandler > &stack, Instruction &instruction)
Execute the SET instruction.
static size_t execute_ADD_TWO(Builder *builder, std::vector< ExecutionHandler > &stack, Instruction &instruction)
Execute the ADD_TWO instruction.
static size_t execute_SQR(Builder *builder, std::vector< ExecutionHandler > &stack, Instruction &instruction)
Execute the SQR instruction.
static size_t execute_ASSERT_NOT_EQUAL(Builder *builder, std::vector< ExecutionHandler > &stack, Instruction &instruction)
Execute the ASSERT_NOT_EQUAL instruction.
static size_t execute_DIVIDE(Builder *builder, std::vector< ExecutionHandler > &stack, Instruction &instruction)
Execute the division operator instruction.
void assert_not_equal(ExecutionHandler &other)
ExecutionHandler conditional_select(Builder *builder, ExecutionHandler &other, const bool predicate)
ExecutionHandler operator*(const ExecutionHandler &other)
static size_t execute_COND_NEGATE(Builder *builder, std::vector< ExecutionHandler > &stack, Instruction &instruction)
Execute the COND_NEGATE instruction.
ExecutionHandler(bb::fr a, field_t &b)
ExecutionHandler(bb::fr &a, field_t &b)
static size_t execute_INVERT(Builder *builder, std::vector< ExecutionHandler > &stack, Instruction &instruction)
Execute the INVERT instruction.
static size_t execute_ASSERT_ZERO(Builder *builder, std::vector< ExecutionHandler > &stack, Instruction &instruction)
Execute the ASSERT_ZERO instruction.
ExecutionHandler(bb::fr a, field_t b)
ExecutionHandler select_if_eq(Builder *builder, ExecutionHandler &other1, ExecutionHandler &other2)
ExecutionHandler operator/(const ExecutionHandler &other)
static size_t execute_SUBTRACT(Builder *builder, std::vector< ExecutionHandler > &stack, Instruction &instruction)
Execute the subtraction operator instruction.
ExecutionHandler add_two(const ExecutionHandler &other1, const ExecutionHandler &other2)
ExecutionHandler construct_via_cast(const std::optional< uint256_t > max=std::nullopt, const std::optional< T > value=std::nullopt) const
static size_t execute_ASSERT_NOT_ZERO(Builder *builder, std::vector< ExecutionHandler > &stack, Instruction &instruction)
Execute the ASSERT_NOT_ZERO instruction.
ExecutionHandler conditional_negate(Builder *builder, const bool predicate)
ExecutionHandler invert(void) const
static size_t execute_MADD(Builder *builder, std::vector< ExecutionHandler > &stack, Instruction &instruction)
Execute the MADD instruction.
static size_t execute_SELECT_IF_ZERO(Builder *builder, std::vector< ExecutionHandler > &stack, Instruction &instruction)
Execute the SELECT_IF_ZERO instruction.
void assert_equal(field_t f) const
static size_t execute_MULTIPLY(Builder *builder, std::vector< ExecutionHandler > &stack, Instruction &instruction)
Execute the multiply instruction.
static size_t execute_COND_SELECT(Builder *builder, std::vector< ExecutionHandler > &stack, Instruction &instruction)
Execute the COND_SELECT instruction.
ExecutionHandler set(Builder *builder)
ExecutionHandler operator+(const ExecutionHandler &other)
static size_t execute_ADD(Builder *builder, std::vector< ExecutionHandler > &stack, Instruction &instruction)
Execute the addition operator instruction.
static size_t execute_WITNESS(Builder *builder, std::vector< ExecutionHandler > &stack, Instruction &instruction)
Execute the witness instruction (push witness safeuit to the stack)
static size_t execute_RANDOMSEED(Builder *builder, std::vector< ExecutionHandler > &stack, Instruction &instruction)
Execute the RANDOMSEED instruction.
ExecutionHandler()=default
static size_t execute_SELECT_IF_EQ(Builder *builder, std::vector< ExecutionHandler > &stack, Instruction &instruction)
Execute the SELECT_IF_EQ instruction.
ExecutionHandler operator-(const ExecutionHandler &other)
A class representing a single fuzzing instruction.
static Instruction mutateInstruction(Instruction instruction, T &rng, HavocSettings &havoc_config)
Mutate a single instruction.
static Instruction generateRandom(T &rng)
Generate a random instruction.
static bb::fr mutateFieldElement(bb::fr e, T &rng, HavocSettings &havoc_config)
Mutate the value of a field element.
ArgumentContents arguments
Optional subclass that governs limits on the use of certain instructions, since some of them can be t...
static constexpr size_t ADD_TWO
static constexpr size_t COND_SELECT
static constexpr size_t MADD
static constexpr size_t SUBTRACT_WITH_CONSTRAINT
static constexpr size_t DIVIDE
static constexpr size_t ASSERT_ZERO
static constexpr size_t WITNESS
static constexpr size_t CONSTANT
static constexpr size_t DIVIDE_WITH_CONSTRAINTS
static constexpr size_t INVERT
static constexpr size_t SELECT_IF_EQ
static constexpr size_t CONSTANT_WITNESS
static constexpr size_t ASSERT_EQUAL
static constexpr size_t SQR
static constexpr size_t SUBTRACT
static constexpr size_t ADD
static constexpr size_t SET
static constexpr size_t SELECT_IF_ZERO
static constexpr size_t ASSERT_NOT_ZERO
static constexpr size_t ASSERT_NOT_EQUAL
static constexpr size_t _LIMIT
static constexpr size_t MULTIPLY
static constexpr size_t RANDOMSEED
static constexpr size_t COND_NEGATE
Parser class handles the parsing and writing the instructions back to data buffer.
static void writeInstruction(Instruction &instruction, uint8_t *Data)
Write a single instruction to buffer.
static Instruction parseInstructionArgs(uint8_t *Data)
Parse a single instruction from data.
The class parametrizing Field fuzzing instructions, execution, etc.
bb::stdlib::field_t< Builder > field_t
std::vector< ExecutionHandler > ExecutionState
bb::stdlib::public_witness_t< Builder > public_witness_t
bb::stdlib::witness_t< Builder > witness_t
bb::stdlib::bool_t< Builder > bool_t
static bool postProcess(Builder *builder, std::vector< FieldBase::ExecutionHandler > &stack)
Check that the resulting values are equal to expected.
Implements boolean logic in-circuit.
void assert_is_in_set(const std::vector< field_t > &set, std::string const &msg="field_t::assert_not_in_set") const
Constrain *this \in set by enforcing that P(X) = \prod_{s \in set} (X - s) is 0 at X = *this.
void assert_equal(const field_t &rhs, std::string const &msg="field_t::assert_equal") const
Copy constraint: constrain that *this field is equal to rhs element.
static field_t accumulate(const std::vector< field_t > &input)
Efficiently compute the sum of vector entries. Using big_add_gate we reduce the number of gates neede...
bb::fr get_value() const
Given a := *this, compute its value given by a.v * a.mul + a.add.
bool_t< Builder > is_zero() const
Validate whether a field_t element is zero.
Concept for a simple PRNG which returns a uint32_t when next is called.
StrictMock< MockContext > context
size_t LLVMFuzzerMutate(uint8_t *Data, size_t Size, size_t MaxSize)
stdlib::field_t< Builder > field_t
Instruction
Enumeration of VM instructions that can be executed.
field< Bn254FrParams > fr
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
#define INV_MONT_CONVERSION
FastRandom VarianceRNG(0)
int LLVMFuzzerInitialize(int *argc, char ***argv)
size_t LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
Fuzzer entry function.
#define PUT_RANDOM_BYTE_IF_LUCKY(variable)
size_t GEN_LLVM_POST_MUTATION_PROB
static constexpr field get_root_of_unity(size_t subgroup_size) noexcept
static constexpr field one()
static constexpr uint256_t modulus
BB_INLINE constexpr field sqr() const noexcept
static field serialize_from_buffer(const uint8_t *buffer)
static void serialize_to_buffer(const field &value, uint8_t *buffer)
constexpr std::pair< bool, field > sqrt() const noexcept
Compute square root of the field element.
BB_INLINE constexpr bool is_zero() const noexcept
static constexpr field zero()