11#pragma clang diagnostic push
12#pragma clang diagnostic ignored "-Wc99-designator"
27#ifdef FUZZING_SHOW_INFORMATION
28#define PRINT_TWO_ARG_INSTRUCTION(first_index, second_index, vector, operation_name, preposition) \
30 std::cout << operation_name << " " << (vector[first_index].suint.is_constant() ? "constant(" : "witness(") \
31 << vector[first_index].suint.get_value() << ":" << vector[first_index].suint.current_max << ") at " \
32 << first_index << " " << preposition << " " \
33 << (vector[second_index].suint.is_constant() ? "constant(" : "witness(") \
34 << vector[second_index].suint.get_value() << ":" << vector[second_index].suint.current_max \
35 << ") at " << second_index << std::flush; \
38#define PRINT_THREE_ARG_INSTRUCTION( \
39 first_index, second_index, third_index, vector, operation_name, preposition1, preposition2) \
41 std::cout << operation_name << " " << (vector[first_index].suint.is_constant() ? "constant(" : "witness(") \
42 << vector[first_index].suint.get_value() << ":" << vector[first_index].suint.current_max << ") at " \
43 << first_index << " " << preposition1 << " " \
44 << (vector[second_index].suint.is_constant() ? "constant(" : "witness(") \
45 << vector[second_index].suint.get_value() << ":" << vector[second_index].suint.current_max \
46 << ") at " << second_index << " " << preposition2 << " " \
47 << (vector[third_index].suint.is_constant() ? "constant(" : "witness(") \
48 << vector[third_index].suint.get_value() << ":" << vector[third_index].suint.current_max << ") at " \
49 << third_index << std::flush; \
51#define PRINT_TWO_ARG_ONE_VALUE_INSTRUCTION( \
52 first_index, second_index, third_index, vector, operation_name, preposition1, preposition2) \
54 std::cout << operation_name << " " << (vector[first_index].suint.is_constant() ? "constant(" : "witness(") \
55 << vector[first_index].suint.get_value() << ":" << vector[first_index].suint.current_max << ") at " \
56 << first_index << " " << preposition1 << " " \
57 << (vector[second_index].suint.is_constant() ? "constant(" : "witness(") \
58 << vector[second_index].suint.get_value() << ":" << vector[second_index].suint.current_max \
59 << ") at " << second_index << " " << preposition2 << " " << third_index << std::flush; \
62#define PRINT_TWO_ARG_TWO_VALUES_INSTRUCTION( \
63 first_index, second_index, value1, value2, vector, operation_name, preposition1, preposition2, preposition3) \
65 std::cout << operation_name << " " << (vector[first_index].suint.is_constant() ? "constant(" : "witness(") \
66 << vector[first_index].suint.get_value() << ":" << vector[first_index].suint.current_max << ") at " \
67 << first_index << " " << preposition1 << " " \
68 << (vector[second_index].suint.is_constant() ? "constant(" : "witness(") \
69 << vector[second_index].suint.get_value() << ":" << vector[second_index].suint.current_max \
70 << ") at " << second_index << " " << preposition2 << " " << value1 << preposition3 << value2 \
74#define PRINT_SLICE(first_index, lsb, msb, vector) \
76 std::cout << "Slice:" \
77 << " " << (vector[first_index].suint.is_constant() ? "constant(" : "witness(") \
78 << vector[first_index].suint.get_value() << ":" << vector[first_index].suint.current_max << ") at " \
79 << first_index << " " \
80 << "(" << (size_t)lsb << ":" << (size_t)msb << ")" << std::flush; \
83#define PRINT_RESULT(prefix, action, index, value) \
85 std::cout << " result(" << value.suint.get_value() << " : " << value.suint.current_max << ") " << action \
86 << index << std::endl \
92#define PRINT_TWO_ARG_INSTRUCTION(first_index, second_index, vector, operation_name, preposition)
94#define PRINT_TWO_ARG_ONE_VALUE_INSTRUCTION( \
95 first_index, second_index, third_index, vector, operation_name, preposition1, preposition2)
96#define PRINT_TWO_ARG_TWO_VALUES_INSTRUCTION( \
97 first_index, second_index, value1, value2, vector, operation_name, preposition1, preposition2, preposition3)
99#define PRINT_THREE_ARG_INSTRUCTION( \
100 first_index, second_index, third_index, vector, operation_name, preposition1, preposition2)
101#define PRINT_RESULT(prefix, action, index, value)
103#define PRINT_SLICE(first_index, lsb, msb, vector)
106#define OPERATION_TYPE_SIZE 1
108#define ELEMENT_SIZE (sizeof(fr) + 1)
109#define TWO_IN_ONE_OUT 3
110#define THREE_IN_ONE_OUT 4
111#define SLICE_ARGS_SIZE 6
200 template <
typename T>
206 uint8_t in1, in2, in3, lsb, msb, out, out1, out2, out3, mask_size, bit_range;
209 switch (instruction_opcode) {
215 for (
size_t i = 0; i < (
sizeof(
uint256_t) >> 1); i++) {
216 *(((uint16_t*)&temp) + i) =
static_cast<uint16_t
>(rng.next() & 0xffff);
220 mask_size =
static_cast<uint8_t
>(rng.next() & 0xff);
223 bit_range =
static_cast<uint8_t
>(rng.next() & 0xff);
225 return { .id = instruction_opcode,
226 .arguments.element = { .value =
fr(temp & mask), .bit_range = bit_range } };
235 in1 =
static_cast<uint8_t
>(rng.next() & 0xff);
236 in2 =
static_cast<uint8_t
>(rng.next() & 0xff);
237 out =
static_cast<uint8_t
>(rng.next() & 0xff);
238 return { .id = instruction_opcode, .arguments.threeArgs = { .in1 = in1, .in2 = in2, .out = out } };
245 in1 =
static_cast<uint8_t
>(rng.next() & 0xff);
246 in2 =
static_cast<uint8_t
>(rng.next() & 0xff);
247 in3 =
static_cast<uint8_t
>(rng.next() & 0xff);
248 out =
static_cast<uint8_t
>(rng.next() & 0xff);
249 return { .id = instruction_opcode,
250 .arguments.fourArgs = { .in1 = in1, .in2 = in2, .in3 = in3, .out = out } };
256 in1 =
static_cast<uint8_t
>(rng.next() & 0xff);
257 in2 =
static_cast<uint8_t
>(rng.next() & 0xff);
258 in3 =
static_cast<uint8_t
>(rng.next() & 0xff);
259 lsb =
static_cast<uint8_t
>(rng.next() & 0xff);
260 out =
static_cast<uint8_t
>(rng.next() & 0xff);
261 return { .id = instruction_opcode,
262 .arguments.fiveArgs = { .in1 = in1, .in2 = in2, .qbs = in3, .rbs = lsb, .out = out } };
268 in1 =
static_cast<uint8_t
>(rng.next() & 0xff);
269 lsb =
static_cast<uint8_t
>(rng.next() & 0xff);
270 msb =
static_cast<uint8_t
>(rng.next() & 0xff);
271 out1 =
static_cast<uint8_t
>(rng.next() & 0xff);
272 out2 =
static_cast<uint8_t
>(rng.next() & 0xff);
273 out3 =
static_cast<uint8_t
>(rng.next() & 0xff);
274 return { .id = instruction_opcode,
275 .arguments.sliceArgs = {
276 .in1 = in1, .lsb = lsb, .msb = msb, .out1 = out1, .out2 = out2, .out3 = out3 } };
279 return { .id = instruction_opcode, .arguments.randomseed = rng.next() };
296 template <
typename T>
303 bool convert_to_montgomery = (rng.next() % (havoc_config.VAL_MUT_MONTGOMERY_PROBABILITY +
304 havoc_config.VAL_MUT_NON_MONTGOMERY_PROBABILITY)) <
305 havoc_config.VAL_MUT_MONTGOMERY_PROBABILITY;
308#define MONT_CONVERSION \
309 if (convert_to_montgomery) { \
310 value_data = uint256_t(e.to_montgomery_form()); \
312 value_data = uint256_t(e); \
315#define INV_MONT_CONVERSION \
316 if (convert_to_montgomery) { \
317 e = fr(value_data).from_montgomery_form(); \
319 e = fr(value_data); \
323 const size_t mutation_type_count = havoc_config.value_mutation_distribution.size();
325 const size_t choice = rng.next() % havoc_config.value_mutation_distribution[mutation_type_count - 1];
326 if (choice < havoc_config.value_mutation_distribution[0]) {
331 }
else if (choice < havoc_config.value_mutation_distribution[1]) {
333 if (convert_to_montgomery) {
334 e = e.to_montgomery_form();
336 if (rng.next() & 1) {
337 e +=
fr(rng.next() & 0xff);
339 e -=
fr(rng.next() & 0xff);
341 if (convert_to_montgomery) {
342 e = e.from_montgomery_form();
346 switch (rng.next() % 8) {
375 if (convert_to_montgomery) {
376 e = e.from_montgomery_form();
391 template <
typename T>
395#define PUT_RANDOM_BYTE_IF_LUCKY(variable) \
396 if (rng.next() & 1) { \
397 variable = rng.next() & 0xff; \
407 if (rng.next() & 1) {
465 static constexpr size_t ADD = 3;
470 static constexpr size_t MADD = 4;
495 .bit_range = *Data } };
500 .arguments.threeArgs = { .in1 = *Data, .in2 = *(Data + 1), .out = *(Data + 2) } };
505 .arguments.fourArgs = {
506 .in1 = *Data, .in2 = *(Data + 1), .in3 = *(Data + 2), .out = *(Data + 3) } };
508 if constexpr (opcode == Instruction::OPCODE::DIVIDE_WITH_CONSTRAINTS) {
509 return Instruction{ .id =
static_cast<typename Instruction::OPCODE
>(opcode),
510 .arguments.fiveArgs = { .in1 = *Data,
514 .out = *(Data + 4) } };
516 if constexpr (opcode == Instruction::OPCODE::SLICE) {
517 return Instruction{ .id =
static_cast<typename Instruction::OPCODE
>(opcode),
518 .arguments.sliceArgs = { .in1 = *Data,
523 .out3 = *(Data + 5) } };
525 if constexpr (opcode == Instruction::OPCODE::RANDOMSEED) {
527 memcpy(&randomseed, Data,
sizeof(uint32_t));
528 return Instruction{ .id =
static_cast<typename Instruction::OPCODE
>(opcode),
529 .arguments.randomseed = randomseed };
539 template <
typename Instruction::OPCODE instruction_opcode>
542 if constexpr (instruction_opcode == Instruction::OPCODE::CONSTANT ||
543 instruction_opcode == Instruction::OPCODE::WITNESS ||
544 instruction_opcode == Instruction::OPCODE::CONSTANT_WITNESS) {
546 *(Data + 1) =
instruction.arguments.element.bit_range;
550 if constexpr (instruction_opcode == Instruction::OPCODE::ADD ||
551 instruction_opcode == Instruction::OPCODE::DIVIDE ||
552 instruction_opcode == Instruction::OPCODE::MULTIPLY ||
553 instruction_opcode == Instruction::OPCODE::SUBTRACT) {
559 if constexpr (instruction_opcode == Instruction::OPCODE::ADD_TWO ||
560 instruction_opcode == Instruction::OPCODE::MADD ||
561 instruction_opcode == Instruction::OPCODE::SUBTRACT_WITH_CONSTRAINT) {
568 if constexpr (instruction_opcode == Instruction::OPCODE::DIVIDE_WITH_CONSTRAINTS) {
576 if constexpr (instruction_opcode == Instruction::OPCODE::SLICE) {
581 *(Data + 4) =
instruction.arguments.sliceArgs.out1;
582 *(Data + 5) =
instruction.arguments.sliceArgs.out2;
583 *(Data + 6) =
instruction.arguments.sliceArgs.out3;
585 if constexpr (instruction_opcode == Instruction::OPCODE::RANDOMSEED) {
588 memcpy(Data + 1, &
instruction.arguments.randomseed,
sizeof(uint32_t));
636 : reference_value(s.get_value())
645 if ((this->reference_value - other.
reference_value) >= (uint512_t(1) << difference_bit_size)) {
649 this->s().subtract(other.
s(), difference_bit_size));
664 auto quotient =
static_cast<uint512_t
>(this->reference_value.lo / other.
reference_value.lo);
665 auto remainder = this->reference_value.
lo - quotient.lo * other.
reference_value.lo;
666 if ((quotient.lo >= (
uint256_t(1) << quotient_bit_size)) ||
667 (remainder >= (
uint256_t(1) << remainder_bit_size))) {
670 return ExecutionHandler(quotient, this->s().divide(other.
s(), quotient_bit_size, remainder_bit_size));
678 this->s() / other.
s());
685 this->s().add_two(other1.
s(), other2.
s()));
692 this->s().madd(other1.
s(), other2.
s()));
697 const auto msb_plus_one = uint32_t(msb) + 1;
698 const auto hi_mask = ((
uint256_t(1) << (256 - uint32_t(msb))) - 1);
699 const auto hi_reference = (this->reference_value.lo >> msb_plus_one) & hi_mask;
701 const auto lo_mask = (
uint256_t(1) << lsb) - 1;
702 const auto lo_reference = this->reference_value.lo & lo_mask;
704 const auto slice_mask = ((
uint256_t(1) << (uint32_t(msb - lsb) + 1)) - 1);
705 const auto slice_reference = (this->reference_value.lo >> lsb) & slice_mask;
707 auto lo_slice_hi_suint_array = this->s().slice(msb, lsb);
727#ifdef FUZZING_SHOW_INFORMATION
746 size_t bit_range =
static_cast<size_t>(
instruction.arguments.element.bit_range);
748 if ((bit_range > suint_t::MAX_BIT_NUM) ||
753 if (bit_range == 0 &&
instruction.arguments.element.value != 0) {
759#ifdef FUZZING_SHOW_INFORMATION
760 std::cout <<
"Pushed witness value " <<
instruction.arguments.element.value <<
" < 2^" << (size_t)bit_range
761 <<
" to position " << stack.size() - 1 <<
std::endl;
778 stack.push_back(suint_t::create_constant_witness(
builder,
instruction.arguments.element.value));
779#ifdef FUZZING_SHOW_INFORMATION
780 std::cout <<
"Pushed constant witness value " <<
instruction.arguments.element.value <<
" to position "
799 if (stack.size() == 0) {
802 size_t first_index =
instruction.arguments.threeArgs.in1 % stack.size();
803 size_t second_index =
instruction.arguments.threeArgs.in2 % stack.size();
804 size_t output_index =
instruction.arguments.threeArgs.out;
807 if ((
static_cast<uint512_t
>(stack[first_index].suint.
current_max) *
808 static_cast<uint512_t
>(stack[second_index].suint.current_max))
815 result = stack[first_index] * stack[second_index];
816 }
catch (std::runtime_error& err) {
817 if (!strncmp(err.what(),
818 "exceeded modulus in safe_uint class",
819 sizeof(
"exceeded modulus in safe_uint class"))) {
830 if (output_index >= stack.size()) {
832 stack.push_back(result);
836 stack[output_index] = result;
853 if (stack.size() == 0) {
856 size_t first_index =
instruction.arguments.threeArgs.in1 % stack.size();
857 size_t second_index =
instruction.arguments.threeArgs.in2 % stack.size();
858 size_t output_index =
instruction.arguments.threeArgs.out;
862 result = stack[first_index] + stack[second_index];
863 }
catch (std::runtime_error& err) {
864 if (!strncmp(err.what(),
865 "exceeded modulus in safe_uint class",
866 sizeof(
"exceeded modulus in safe_uint class"))) {
876 if (output_index >= stack.size()) {
878 stack.push_back(result);
882 stack[output_index] = result;
899 if (stack.size() == 0) {
902 size_t first_index =
instruction.arguments.threeArgs.in1 % stack.size();
903 size_t second_index =
instruction.arguments.threeArgs.in2 % stack.size();
904 size_t output_index =
instruction.arguments.threeArgs.out;
907 if ((
static_cast<uint512_t
>(1 << (stack[first_index].suint.
current_max.
get_msb() + 1)) +
908 static_cast<uint512_t
>(stack[second_index].suint.current_max)) > suint_t::MAX_VALUE) {
913 if (stack[first_index].suint.
is_constant() && stack[second_index].suint.is_constant() &&
914 (
static_cast<uint256_t>(stack[first_index].suint.get_value()) <
926 result = stack[first_index] - stack[second_index];
927 }
catch (std::runtime_error& err) {
928 if (!strncmp(err.what(),
929 "exceeded modulus in safe_uint class",
930 sizeof(
"exceeded modulus in safe_uint class"))) {
933 if (!strncmp(err.what(),
934 "maximum value exceeded in safe_uint minus operator",
935 sizeof(
"maximum value exceeded in safe_uint minus operator"))) {
946 if (output_index >= stack.size()) {
948 stack.push_back(result);
952 stack[output_index] = result;
969 if (stack.size() == 0) {
972 size_t first_index =
instruction.arguments.threeArgs.in1 % stack.size();
973 size_t second_index =
instruction.arguments.threeArgs.in2 % stack.size();
974 size_t output_index =
instruction.arguments.threeArgs.out;
982 stack[second_index].suint.current_max)
988 result = stack[first_index] / stack[second_index];
989 }
catch (std::runtime_error& err) {
990 if (!strncmp(err.what(),
991 "exceeded modulus in safe_uint class",
992 sizeof(
"exceeded modulus in safe_uint class"))) {
995 if (!strncmp(err.what(),
996 "maximum value exceeded in safe_uint minus operator",
997 sizeof(
"maximum value exceeded in safe_uint minus operator"))) {
1006 if (stack[first_index].suint.
get_value().
is_zero() && stack[second_index].suint.get_value().is_zero()) {
1012 if (output_index >= stack.size()) {
1014 stack.push_back(result);
1018 stack[output_index] = result;
1036 if (stack.size() == 0) {
1039 size_t first_index =
instruction.arguments.fourArgs.in1 % stack.size();
1040 size_t second_index =
instruction.arguments.fourArgs.in2 % stack.size();
1041 size_t third_index =
instruction.arguments.fourArgs.in3 % stack.size();
1042 size_t output_index =
instruction.arguments.fourArgs.out;
1044 if ((
static_cast<uint512_t
>(stack[first_index].suint.
current_max) +
1045 static_cast<uint512_t
>(stack[second_index].suint.current_max) +
1046 static_cast<uint512_t
>(stack[third_index].suint.current_max)) >
1047 static_cast<uint512_t
>(suint_t::MAX_VALUE)) {
1052 result = stack[first_index].
add_two(stack[second_index], stack[third_index]);
1053 }
catch (std::runtime_error& err) {
1054 if (!strncmp(err.what(),
1055 "exceeded modulus in safe_uint class",
1056 sizeof(
"exceeded modulus in safe_uint class"))) {
1067 if (output_index >= stack.size()) {
1069 stack.push_back(result);
1073 stack[output_index] = result;
1091 if (stack.size() == 0) {
1094 size_t first_index =
instruction.arguments.fourArgs.in1 % stack.size();
1095 size_t second_index =
instruction.arguments.fourArgs.in2 % stack.size();
1096 size_t third_index =
instruction.arguments.fourArgs.in3 % stack.size();
1097 size_t output_index =
instruction.arguments.fourArgs.out;
1100 if ((
static_cast<uint512_t
>(stack[first_index].suint.
current_max) *
1101 static_cast<uint512_t
>(stack[second_index].suint.current_max) +
1102 static_cast<uint512_t
>(stack[third_index].suint.current_max)) >
1103 static_cast<uint512_t
>(suint_t::MAX_VALUE)) {
1108 result = stack[first_index].
madd(stack[second_index], stack[third_index]);
1109 }
catch (std::runtime_error& err) {
1110 if (!strncmp(err.what(),
1111 "exceeded modulus in safe_uint class",
1112 sizeof(
"exceeded modulus in safe_uint class"))) {
1123 if (output_index >= stack.size()) {
1125 stack.push_back(result);
1129 stack[output_index] = result;
1148 if (stack.size() == 0) {
1151 size_t first_index =
instruction.arguments.fourArgs.in1 % stack.size();
1152 size_t second_index =
instruction.arguments.fourArgs.in2 % stack.size();
1153 size_t difference_bit_size =
instruction.arguments.fourArgs.in3;
1154 size_t output_index =
instruction.arguments.fourArgs.out;
1156 if (difference_bit_size > suint_t::MAX_BIT_NUM) {
1160 if (stack[first_index].suint.
is_constant() && stack[second_index].suint.is_constant()) {
1165 result = stack[first_index].
subtract(stack[second_index], difference_bit_size);
1166 }
catch (std::runtime_error& err) {
1167 if (!strncmp(err.what(),
1168 "maximum value exceeded in safe_uint subtract",
1169 sizeof(
"maximum value exceeded in safe_uint subtract"))) {
1179 first_index, second_index, difference_bit_size, stack,
"SUBTRACT_WITH_CONSTRAINT:",
"-",
"<= 2**")
1181 if (output_index >= stack.size()) {
1183 stack.push_back(result);
1187 stack[output_index] = result;
1206 if (stack.size() == 0) {
1209 size_t first_index =
instruction.arguments.fiveArgs.in1 % stack.size();
1210 size_t second_index =
instruction.arguments.fiveArgs.in2 % stack.size();
1211 size_t quotient_bit_size =
instruction.arguments.fiveArgs.qbs;
1214 if (quotient_bit_size + stack[second_index].suint.
current_max.
get_msb() + 1 >= 256) {
1218 size_t remainder_bit_size =
instruction.arguments.fiveArgs.rbs;
1219 size_t output_index =
instruction.arguments.fiveArgs.out;
1221 if ((quotient_bit_size > suint_t::MAX_BIT_NUM) || (remainder_bit_size > suint_t::MAX_BIT_NUM)) {
1230 result = stack[first_index].
divide(stack[second_index], quotient_bit_size, remainder_bit_size);
1231 }
catch (std::runtime_error& err) {
1232 if (!strncmp(err.what(),
1233 "exceeded modulus in safe_uint class",
1234 sizeof(
"exceeded modulus in safe_uint class"))) {
1237 if (!strncmp(err.what(),
1238 "maximum value exceeded in safe_uint minus operator",
1239 sizeof(
"maximum value exceeded in safe_uint minus operator"))) {
1253 "DIVIDE_WITH_CONSTRAINTS:",
1259 if (output_index >= stack.size()) {
1261 stack.push_back(result);
1265 stack[output_index] = result;
1283 if (stack.size() == 0) {
1286 size_t first_index =
instruction.arguments.sliceArgs.in1 % stack.size();
1287 uint8_t lsb =
instruction.arguments.sliceArgs.lsb;
1288 uint8_t msb =
instruction.arguments.sliceArgs.msb;
1289 size_t second_index =
instruction.arguments.sliceArgs.out1;
1290 size_t third_index =
instruction.arguments.sliceArgs.out2;
1291 size_t output_index =
instruction.arguments.sliceArgs.out3;
1293 if ((lsb > msb) || (msb > 252) ||
1299 auto slices = stack[first_index].slice(lsb, msb);
1303 for (
auto& x : what_where) {
1304 auto suints_count = stack.size();
1305 if (x.second >= suints_count) {
1307 PRINT_RESULT(
"\t",
"pushed to ", stack.size(), x.first)
1308 stack.push_back(x.first);
1312 stack[x.second] = x.first;
1351 .GEN_MUTATION_COUNT_LOG = 5,
1352 .GEN_STRUCTURAL_MUTATION_PROBABILITY = 300,
1353 .GEN_VALUE_MUTATION_PROBABILITY = 700,
1354 .ST_MUT_DELETION_PROBABILITY = 100,
1355 .ST_MUT_DUPLICATION_PROBABILITY = 80,
1356 .ST_MUT_INSERTION_PROBABILITY = 120,
1357 .ST_MUT_MAXIMUM_DELETION_LOG = 6,
1358 .ST_MUT_MAXIMUM_DUPLICATION_LOG = 2,
1359 .ST_MUT_SWAP_PROBABILITY = 50,
1360 .VAL_MUT_LLVM_MUTATE_PROBABILITY = 250,
1361 .VAL_MUT_MONTGOMERY_PROBABILITY = 130,
1362 .VAL_MUT_NON_MONTGOMERY_PROBABILITY = 50,
1363 .VAL_MUT_SMALL_ADDITION_PROBABILITY = 110,
1364 .VAL_MUT_SPECIAL_VALUE_PROBABILITY = 130
1431 std::vector<size_t> structural_mutation_distribution;
1432 std::vector<size_t> value_mutation_distribution;
1434 temp += fuzzer_havoc_settings.ST_MUT_DELETION_PROBABILITY;
1435 structural_mutation_distribution.push_back(temp);
1436 temp += fuzzer_havoc_settings.ST_MUT_DUPLICATION_PROBABILITY;
1437 structural_mutation_distribution.push_back(temp);
1438 temp += fuzzer_havoc_settings.ST_MUT_INSERTION_PROBABILITY;
1439 structural_mutation_distribution.push_back(temp);
1440 temp += fuzzer_havoc_settings.ST_MUT_SWAP_PROBABILITY;
1441 structural_mutation_distribution.push_back(temp);
1442 fuzzer_havoc_settings.structural_mutation_distribution = structural_mutation_distribution;
1445 temp += fuzzer_havoc_settings.VAL_MUT_LLVM_MUTATE_PROBABILITY;
1446 value_mutation_distribution.push_back(temp);
1447 temp += fuzzer_havoc_settings.VAL_MUT_SMALL_ADDITION_PROBABILITY;
1448 value_mutation_distribution.push_back(temp);
1450 temp += fuzzer_havoc_settings.VAL_MUT_SPECIAL_VALUE_PROBABILITY;
1451 value_mutation_distribution.push_back(temp);
1452 fuzzer_havoc_settings.value_mutation_distribution = value_mutation_distribution;
1463 RunWithBuilders<SafeUintFuzzBase, FuzzerCircuitTypes>(Data, Size,
VarianceRNG);
1467#pragma clang diagnostic pop
#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)
#define PRINT_SLICE(first_index, lsb, msb, vector)
FastRandom VarianceRNG(0)
#define PRINT_TWO_ARG_TWO_VALUES_INSTRUCTION( first_index, second_index, value1, value2, vector, operation_name, preposition1, preposition2, preposition3)
#define PRINT_RESULT(prefix, action, index, value)
#define PRINT_TWO_ARG_ONE_VALUE_INSTRUCTION( first_index, second_index, third_index, vector, operation_name, preposition1, preposition2)
Class for quickly deterministically creating new random values. We don't care about distribution much...
void reseed(uint32_t seed)
static constexpr size_t MADD
static constexpr size_t SLICE
static constexpr size_t ADD
static constexpr size_t DIVIDE
static constexpr size_t CONSTANT_WITNESS
static constexpr size_t RANDOMSEED
static constexpr size_t SUBTRACT
static constexpr size_t WITNESS
static constexpr size_t CONSTANT
static constexpr size_t SUBTRACT_WITH_CONSTRAINT
static constexpr size_t MULTIPLY
static constexpr size_t DIVIDE_WITH_CONSTRAINTS
static constexpr size_t ADD_TWO
This class implements the execution of safeuint with an oracle to detect discrepancies.
static size_t execute_SUBTRACT(Builder *builder, std::vector< ExecutionHandler > &stack, Instruction &instruction)
Execute the subtraction operator instruction.
ExecutionHandler subtract(const ExecutionHandler &other, size_t difference_bit_size)
ExecutionHandler operator+(const ExecutionHandler &other)
ExecutionHandler operator*(const ExecutionHandler &other)
static size_t execute_MULTIPLY(Builder *builder, std::vector< ExecutionHandler > &stack, Instruction &instruction)
Execute the multiply instruction.
ExecutionHandler(uint512_t r, suint_t s)
static size_t execute_SLICE(Builder *builder, std::vector< ExecutionHandler > &stack, Instruction &instruction)
Execute the slice instruction.
static size_t execute_SUBTRACT_WITH_CONSTRAINT(Builder *builder, std::vector< ExecutionHandler > &stack, Instruction &instruction)
Execute the SUBTRACT_WITH_CONSTRAINT instruction.
static size_t execute_MADD(Builder *builder, std::vector< ExecutionHandler > &stack, Instruction &instruction)
Execute the MADD instruction.
ExecutionHandler add_two(const ExecutionHandler &other1, const ExecutionHandler &other2)
ExecutionHandler divide(const ExecutionHandler &other, size_t quotient_bit_size, size_t remainder_bit_size)
uint512_t reference_value
static size_t execute_CONSTANT(Builder *builder, std::vector< ExecutionHandler > &stack, Instruction &instruction)
Execute the constant instruction (push constant safeuint to the stack)
ExecutionHandler operator/(const ExecutionHandler &other)
static size_t execute_DIVIDE_WITH_CONSTRAINTS(Builder *builder, std::vector< ExecutionHandler > &stack, Instruction &instruction)
static size_t execute_DIVIDE(Builder *builder, std::vector< ExecutionHandler > &stack, Instruction &instruction)
Execute the division operator instruction.
ExecutionHandler(suint_t s)
std::array< ExecutionHandler, 3 > slice(uint8_t lsb, uint8_t msb)
ExecutionHandler operator-(const ExecutionHandler &other)
static size_t execute_ADD_TWO(Builder *builder, std::vector< ExecutionHandler > &stack, Instruction &instruction)
Execute the ADD_TWO instruction.
ExecutionHandler()=default
static size_t execute_RANDOMSEED(Builder *builder, std::vector< ExecutionHandler > &stack, Instruction &instruction)
Execute the RANDOMSEED instruction.
ExecutionHandler(uint512_t &r, suint_t &s)
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)
ExecutionHandler madd(const ExecutionHandler &other1, const ExecutionHandler &other2)
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_ADD(Builder *builder, std::vector< ExecutionHandler > &stack, Instruction &instruction)
Execute the addition operator instruction.
A class representing a single fuzzing instruction.
ArgumentContents arguments
static Instruction generateRandom(T &rng)
Generate a random instruction.
static Instruction mutateInstruction(Instruction instruction, T &rng, HavocSettings &havoc_config)
Mutate a single instruction.
@ DIVIDE_WITH_CONSTRAINTS
@ SUBTRACT_WITH_CONSTRAINT
static fr mutateFieldElement(fr e, T &rng, HavocSettings &havoc_config)
Mutate the value of a field element.
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 SafeUint fuzzing instructions, execution, etc.
std::vector< ExecutionHandler > ExecutionState
constexpr uint64_t get_msb() const
Implements boolean logic in-circuit.
Concept for a simple PRNG which returns a uint32_t when next is called.
size_t LLVMFuzzerMutate(uint8_t *Data, size_t Size, size_t MaxSize)
stdlib::witness_t< Builder > witness_t
constexpr size_t MAX_NO_WRAP_INTEGER_BIT_LENGTH
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.
char EXCEEDED_MAX_BITNUM_ERROR[43]
#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
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()