Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
instruction_block.cpp
Go to the documentation of this file.
2
3#include <random>
4#include <vector>
5
9
10namespace bb::avm2::fuzzer {
11
13
15{
16 InstructionBlock instruction_block;
18 InstructionMutator instruction_mutator(instruction_block, context);
19 for (uint16_t i = 0; i < std::uniform_int_distribution<uint16_t>(1, MAX_INSTRUCTION_BLOCK_SIZE_ON_GENERATION)(rng);
20 i++) {
21 auto new_instructions = instruction_mutator.generate_instruction(rng);
22 instruction_block.instructions.insert(
23 instruction_block.instructions.end(), new_instructions.begin(), new_instructions.end());
24 }
25 return instruction_block;
26}
27
29{
30 InstructionMutator instruction_mutator(instruction_block, context);
31
32 // If vector is empty, force insertion (other mutations do nothing on empty vectors)
33 if (instruction_block.instructions.empty()) {
34 auto new_instructions = instruction_mutator.generate_instruction(rng);
35 instruction_block.instructions.insert(
36 instruction_block.instructions.end(), new_instructions.begin(), new_instructions.end());
37 return;
38 }
39
41 switch (option) {
43 // Custom insertion logic to handle vector-returning generator
44 auto new_instructions = instruction_mutator.generate_instruction(rng);
45 if (!new_instructions.empty()) {
46 std::uniform_int_distribution<size_t> dist(0, instruction_block.instructions.size());
47 size_t index = dist(rng);
48 instruction_block.instructions.insert(instruction_block.instructions.begin() +
49 static_cast<std::ptrdiff_t>(index),
50 new_instructions.begin(),
51 new_instructions.end());
52 }
53 break;
54 }
56 RandomDeletion::mutate(rng, instruction_block.instructions);
57 break;
59 RandomSwap::mutate(rng, instruction_block.instructions);
60 break;
63 rng, instruction_block.instructions, [&instruction_mutator](FuzzInstruction& instr, std::mt19937_64& r) {
64 instruction_mutator.mutate_instruction(instr, r);
65 });
66 break;
67 }
68}
69
70} // namespace bb::avm2::fuzzer
#define AVM_HIGHEST_MEM_ADDRESS
T select(std::mt19937_64 &rng) const
std::vector< FuzzInstruction > generate_instruction(std::mt19937_64 &rng)
Generate one instruction and optionally backfill.
VecMutationOptions
constexpr VecMutationConfig BASIC_VEC_MUTATION_CONFIGURATION
std::variant< ADD_8_Instruction, FDIV_8_Instruction, SET_8_Instruction, SET_16_Instruction, SET_32_Instruction, SET_64_Instruction, SET_128_Instruction, SET_FF_Instruction, MOV_8_Instruction, MOV_16_Instruction, SUB_8_Instruction, MUL_8_Instruction, DIV_8_Instruction, EQ_8_Instruction, LT_8_Instruction, LTE_8_Instruction, AND_8_Instruction, OR_8_Instruction, XOR_8_Instruction, SHL_8_Instruction, SHR_8_Instruction, NOT_8_Instruction, ADD_16_Instruction, SUB_16_Instruction, MUL_16_Instruction, DIV_16_Instruction, FDIV_16_Instruction, EQ_16_Instruction, LT_16_Instruction, LTE_16_Instruction, AND_16_Instruction, OR_16_Instruction, XOR_16_Instruction, NOT_16_Instruction, SHL_16_Instruction, SHR_16_Instruction, CAST_8_Instruction, CAST_16_Instruction, SSTORE_Instruction, SLOAD_Instruction, GETENVVAR_Instruction, EMITNULLIFIER_Instruction, NULLIFIEREXISTS_Instruction, L1TOL2MSGEXISTS_Instruction, EMITNOTEHASH_Instruction, NOTEHASHEXISTS_Instruction, CALLDATACOPY_Instruction, SENDL2TOL1MSG_Instruction, EMITPUBLICLOG_Instruction, CALL_Instruction, RETURNDATASIZE_Instruction, RETURNDATACOPY_Instruction, GETCONTRACTINSTANCE_Instruction, SUCCESSCOPY_Instruction, ECADD_Instruction, POSEIDON2PERM_Instruction, KECCAKF1600_Instruction, SHA256COMPRESSION_Instruction, TORADIXBE_Instruction, DEBUGLOG_Instruction > FuzzInstruction
constexpr uint16_t MAX_INSTRUCTION_BLOCK_SIZE_ON_GENERATION
InstructionBlock generate_instruction_block(std::mt19937_64 &rng, const FuzzerContext &context)
void mutate_instruction_block(InstructionBlock &instruction_block, std::mt19937_64 &rng, const FuzzerContext &context)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
static void mutate(std::mt19937_64 &rng, std::vector< T > &vec)
Definition vector.hpp:34
static void mutate(std::mt19937_64 &rng, std::vector< T > &vec, MutateFn &&mutate_element_function)
Definition vector.hpp:60
static void mutate(std::mt19937_64 &rng, std::vector< T > &vec)
Definition vector.hpp:46
std::vector< FuzzInstruction > instructions