diff --git a/barretenberg/cpp/src/barretenberg/avm_fuzzer/fuzz_lib/control_flow.cpp b/barretenberg/cpp/src/barretenberg/avm_fuzzer/fuzz_lib/control_flow.cpp index 812670eca02e..ff97bef684fd 100644 --- a/barretenberg/cpp/src/barretenberg/avm_fuzzer/fuzz_lib/control_flow.cpp +++ b/barretenberg/cpp/src/barretenberg/avm_fuzzer/fuzz_lib/control_flow.cpp @@ -250,22 +250,10 @@ int predict_block_size(ProgramBlock* block) case TerminatorType::JUMP: return bytecode_length + JMP_SIZE; // finalized with jump case TerminatorType::JUMP_IF: { - // if boolean condition is not set adding SET_8 instruction to the bytecode + // if boolean condition is not set add SET instruction to the bytecode if (!block->get_terminating_condition_value().has_value()) { - for (uint16_t address = 0; address < 65535; address++) { - // if the memory address is already in use, we skip it - if (block->is_memory_address_set(address)) { - continue; - } - auto set_16_instruction = - SET_16_Instruction{ .value_tag = bb::avm2::MemoryTag::U1, - .result_address = - AddressRef{ .address = address, .mode = AddressingMode::Direct }, - .value = 0 }; - block->process_instruction(set_16_instruction); - bytecode_length = static_cast(create_bytecode(block->get_instructions()).size()); - break; - } + block->process_write_terminating_condition_value(); + bytecode_length = static_cast(create_bytecode(block->get_instructions()).size()); } return bytecode_length + JMP_IF_SIZE + JMP_SIZE; // finalized with jumpi } diff --git a/barretenberg/cpp/src/barretenberg/avm_fuzzer/fuzz_lib/program_block.cpp b/barretenberg/cpp/src/barretenberg/avm_fuzzer/fuzz_lib/program_block.cpp index f94f23164dfc..02354a2c1757 100644 --- a/barretenberg/cpp/src/barretenberg/avm_fuzzer/fuzz_lib/program_block.cpp +++ b/barretenberg/cpp/src/barretenberg/avm_fuzzer/fuzz_lib/program_block.cpp @@ -1633,6 +1633,15 @@ std::optional ProgramBlock::get_terminating_condition_value() return condition_addr; } +void ProgramBlock::process_write_terminating_condition_value() +{ + uint16_t value = condition_offset_index % 2; + process_set_16_instruction(SET_16_Instruction{ + .value_tag = bb::avm2::MemoryTag::U1, + .result_address = AddressRef{ .address = condition_offset_index, .mode = AddressingMode::Direct }, + .value = value }); +} + bool ProgramBlock::is_memory_address_set(uint16_t address) { return memory_manager.is_memory_address_set(address); diff --git a/barretenberg/cpp/src/barretenberg/avm_fuzzer/fuzz_lib/program_block.hpp b/barretenberg/cpp/src/barretenberg/avm_fuzzer/fuzz_lib/program_block.hpp index a1665fde8395..e4adf49a53cd 100644 --- a/barretenberg/cpp/src/barretenberg/avm_fuzzer/fuzz_lib/program_block.hpp +++ b/barretenberg/cpp/src/barretenberg/avm_fuzzer/fuzz_lib/program_block.hpp @@ -173,6 +173,7 @@ class ProgramBlock { void insert_internal_call(ProgramBlock* target_block); std::optional get_terminating_condition_value(); + void process_write_terminating_condition_value(); std::vector get_instructions(); bool is_memory_address_set(uint16_t address);