Skip to content

Commit a4ed36c

Browse files
authored
Merge branch 'next' into merge-train/docs
2 parents 1772105 + 7272357 commit a4ed36c

File tree

144 files changed

+1725
-242
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+1725
-242
lines changed

.github/workflows/nightly-docs-release.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,15 @@ jobs:
130130
- name: Create Aztec nightly docs version (Developer docs only)
131131
working-directory: ./docs
132132
run: |
133-
# Set the commit tag for version macros
133+
# Set the commit tag and release type for version macros
134134
export COMMIT_TAG=${{ env.NIGHTLY_TAG }}
135+
export RELEASE_TYPE=nightly
135136
136137
# Install dependencies
137138
yarn install
138139
139140
# Build docs to ensure everything works
140-
COMMIT_TAG=${{ env.NIGHTLY_TAG }} yarn build
141+
COMMIT_TAG=${{ env.NIGHTLY_TAG }} RELEASE_TYPE=nightly yarn build
141142
142143
# Create the versioned docs for Developer docs only
143144
# Network docs have separate versions for testnet/ignition releases

barretenberg/cpp/src/barretenberg/avm_fuzzer/fuzz_lib/control_flow.cpp

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,21 @@ void ControlFlow::process_finalize_with_return(FinalizeWithReturn instruction)
145145
current_block = non_terminated_blocks.at(0);
146146
}
147147

148+
void ControlFlow::process_finalize_with_revert(FinalizeWithRevert instruction)
149+
{
150+
if (this->current_block->terminator_type != TerminatorType::NONE) {
151+
return;
152+
}
153+
current_block->finalize_with_revert(instruction.revert_options.return_size,
154+
instruction.revert_options.return_value_tag,
155+
instruction.revert_options.return_value_offset_index);
156+
std::vector<ProgramBlock*> non_terminated_blocks = get_non_terminated_blocks();
157+
if (non_terminated_blocks.size() == 0) {
158+
return;
159+
}
160+
current_block = non_terminated_blocks.at(0);
161+
}
162+
148163
void ControlFlow::process_switch_to_non_terminated_block(SwitchToNonTerminatedBlock instruction)
149164
{
150165
std::vector<ProgramBlock*> non_terminated_blocks = get_non_terminated_blocks();
@@ -214,6 +229,7 @@ void ControlFlow::process_cfg_instruction(CFGInstruction instruction)
214229
[&](JumpToBlock arg) { process_jump_to_block(arg); },
215230
[&](JumpIfToBlock arg) { process_jump_if_to_block(arg); },
216231
[&](FinalizeWithReturn arg) { process_finalize_with_return(arg); },
232+
[&](FinalizeWithRevert arg) { process_finalize_with_revert(arg); },
217233
[&](SwitchToNonTerminatedBlock arg) { process_switch_to_non_terminated_block(arg); },
218234
[&](InsertInternalCall arg) { process_insert_internal_call(arg); } },
219235
instruction);
@@ -239,7 +255,8 @@ int predict_block_size(ProgramBlock* block)
239255
auto bytecode_length = static_cast<int>(create_bytecode(block->get_instructions()).size());
240256
switch (block->terminator_type) {
241257
case TerminatorType::RETURN:
242-
return bytecode_length; // finalized with return, already counted
258+
case TerminatorType::REVERT:
259+
return bytecode_length; // finalized with return/revert, already counted
243260
case TerminatorType::JUMP:
244261
return bytecode_length + JMP_SIZE; // finalized with jump
245262
case TerminatorType::JUMP_IF: {
@@ -263,9 +280,9 @@ int predict_block_size(ProgramBlock* block)
263280
return bytecode_length + JMP_IF_SIZE + JMP_SIZE; // finalized with jumpi
264281
}
265282
default:
266-
throw std::runtime_error("Predict block size: Every block should be terminated with return, jump, or jumpi, "
267-
"got " +
268-
std::to_string(static_cast<int>(block->terminator_type)));
283+
throw std::runtime_error(
284+
"Predict block size: Every block should be terminated with return, revert, jump, or jumpi, got " +
285+
std::to_string(static_cast<int>(block->terminator_type)));
269286
}
270287
throw std::runtime_error("Unreachable");
271288
}
@@ -315,6 +332,9 @@ std::vector<uint8_t> ControlFlow::build_bytecode(const ReturnOptions& return_opt
315332
case TerminatorType::RETURN: // finalized with return
316333
// already terminated with return
317334
break;
335+
case TerminatorType::REVERT: // finalized with revert
336+
// already terminated with revert
337+
break;
318338
case TerminatorType::JUMP: { // finalized with jump
319339
ProgramBlock* target_block = block->successors.at(0);
320340
size_t target_block_idx = find_block_idx(target_block, blocks);
@@ -347,7 +367,7 @@ std::vector<uint8_t> ControlFlow::build_bytecode(const ReturnOptions& return_opt
347367
}
348368
default:
349369
throw std::runtime_error(
350-
"Inject terminators: Every block should be terminated with return, jump, or jumpi");
370+
"Inject terminators: Every block should be terminated with return, revert, jump, or jumpi");
351371
}
352372
block_bytecodes.push_back(create_bytecode(instructions));
353373
}

barretenberg/cpp/src/barretenberg/avm_fuzzer/fuzz_lib/control_flow.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ struct FinalizeWithReturn {
6464
MSGPACK_FIELDS(return_options);
6565
};
6666

67+
/// @brief finalizes the current block with Revert and switches to the first non-terminated block
68+
struct FinalizeWithRevert {
69+
ReturnOptions revert_options;
70+
MSGPACK_FIELDS(revert_options);
71+
};
72+
6773
/// @brief switches to the non-terminated block with the chosen index
6874
struct SwitchToNonTerminatedBlock {
6975
uint16_t non_terminated_block_idx;
@@ -83,6 +89,7 @@ using CFGInstruction = std::variant<InsertSimpleInstructionBlock,
8389
JumpToBlock,
8490
JumpIfToBlock,
8591
FinalizeWithReturn,
92+
FinalizeWithRevert,
8693
SwitchToNonTerminatedBlock,
8794
InsertInternalCall>;
8895
template <class... Ts> struct overloaded_cfg_instruction : Ts... {
@@ -111,6 +118,10 @@ inline std::ostream& operator<<(std::ostream& os, const CFGInstruction& instruct
111118
os << "FinalizeWithReturn " << arg.return_options.return_size << " "
112119
<< arg.return_options.return_value_tag << " " << arg.return_options.return_value_offset_index;
113120
},
121+
[&](FinalizeWithRevert arg) {
122+
os << "FinalizeWithRevert " << arg.revert_options.return_size << " "
123+
<< arg.revert_options.return_value_tag << " " << arg.revert_options.return_value_offset_index;
124+
},
114125
[&](SwitchToNonTerminatedBlock arg) {
115126
os << "SwitchToNonTerminatedBlock " << arg.non_terminated_block_idx;
116127
},
@@ -160,6 +171,10 @@ class ControlFlow {
160171
/// @param instruction the instruction to process
161172
void process_finalize_with_return(FinalizeWithReturn instruction);
162173

174+
/// @brief terminates the current block with Revert and switches to the first non-terminated block
175+
/// @param instruction the instruction to process
176+
void process_finalize_with_revert(FinalizeWithRevert instruction);
177+
163178
/// @brief switches to the non-terminated block with the chosen index
164179
/// @param instruction the instruction to process
165180
void process_switch_to_non_terminated_block(SwitchToNonTerminatedBlock instruction);

barretenberg/cpp/src/barretenberg/avm_fuzzer/fuzz_lib/program_block.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,6 +1586,34 @@ void ProgramBlock::finalize_with_return(uint8_t return_size,
15861586
instructions.push_back(return_instruction);
15871587
}
15881588

1589+
void ProgramBlock::finalize_with_revert(uint8_t revert_size,
1590+
MemoryTagWrapper revert_value_tag,
1591+
uint16_t revert_value_offset_index)
1592+
{
1593+
this->terminator_type = TerminatorType::REVERT;
1594+
1595+
auto revert_addr = memory_manager.get_memory_offset_16(revert_value_tag.value, revert_value_offset_index);
1596+
if (!revert_addr.has_value()) {
1597+
revert_addr = std::optional<uint32_t>(0);
1598+
}
1599+
1600+
// Once we do more of the randomness in Instruction selection, revert_size_offset we shouldnt need to hardcode
1601+
uint16_t revert_size_offset = 5U;
1602+
// Ensure operands are created as U16 to match wire format (UINT16)
1603+
auto set_size_instruction = bb::avm2::testing::InstructionBuilder(bb::avm2::WireOpCode::SET_16)
1604+
.operand(revert_size_offset)
1605+
.operand(bb::avm2::MemoryTag::U32)
1606+
.operand(static_cast<uint16_t>(revert_size))
1607+
.build();
1608+
instructions.push_back(set_size_instruction);
1609+
// REVERT_16 expects UINT16 operands, ensure we cast to uint16_t explicitly
1610+
auto revert_instruction = bb::avm2::testing::InstructionBuilder(bb::avm2::WireOpCode::REVERT_16)
1611+
.operand(static_cast<uint16_t>(revert_size_offset))
1612+
.operand(revert_addr.value())
1613+
.build();
1614+
instructions.push_back(revert_instruction);
1615+
}
1616+
15891617
void ProgramBlock::finalize_with_jump(ProgramBlock* target_block, bool copy_memory_manager)
15901618
{
15911619
this->terminator_type = TerminatorType::JUMP;

barretenberg/cpp/src/barretenberg/avm_fuzzer/fuzz_lib/program_block.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
enum class TerminatorType {
3131
RETURN,
32+
REVERT,
3233
JUMP,
3334
JUMP_IF,
3435
NONE,
@@ -139,6 +140,13 @@ class ProgramBlock {
139140
MemoryTagWrapper return_value_tag,
140141
uint16_t return_value_offset_index);
141142

143+
/// @brief finalize the program block with a revert instruction
144+
/// Similar to finalize_with_return but uses REVERT opcode instead.
145+
/// Sets the terminator type to REVERT.
146+
void finalize_with_revert(uint8_t revert_size,
147+
MemoryTagWrapper revert_value_tag,
148+
uint16_t revert_value_offset_index);
149+
142150
/// @brief finalize the block with a jump
143151
/// Sets the terminator type to JUMP, adds the target block to the successors and the current block to the
144152
/// predecessors.

barretenberg/cpp/src/barretenberg/avm_fuzzer/mutations/configuration.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,11 +555,12 @@ enum class CFGInstructionGenerationOptions {
555555
JumpToBlock,
556556
JumpIfToBlock,
557557
FinalizeWithReturn,
558+
FinalizeWithRevert,
558559
SwitchToNonTerminatedBlock,
559560
InsertInternalCall,
560561
};
561562

562-
using CFGInstructionGenerationConfig = WeightedSelectionConfig<CFGInstructionGenerationOptions, 8>;
563+
using CFGInstructionGenerationConfig = WeightedSelectionConfig<CFGInstructionGenerationOptions, 9>;
563564

564565
constexpr CFGInstructionGenerationConfig BASIC_CFG_INSTRUCTION_GENERATION_CONFIGURATION =
565566
CFGInstructionGenerationConfig({
@@ -569,6 +570,7 @@ constexpr CFGInstructionGenerationConfig BASIC_CFG_INSTRUCTION_GENERATION_CONFIG
569570
{ CFGInstructionGenerationOptions::JumpToBlock, 15 },
570571
{ CFGInstructionGenerationOptions::JumpIfToBlock, 15 },
571572
{ CFGInstructionGenerationOptions::FinalizeWithReturn, 7 },
573+
{ CFGInstructionGenerationOptions::FinalizeWithRevert, 3 },
572574
{ CFGInstructionGenerationOptions::SwitchToNonTerminatedBlock, 8 },
573575
{ CFGInstructionGenerationOptions::InsertInternalCall, 3 },
574576
});

barretenberg/cpp/src/barretenberg/avm_fuzzer/mutations/control_flow/control_flow_vec.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ void mutate_finalize_with_return(FinalizeWithReturn& instr, std::mt19937_64& rng
5858
mutate_return_options(instr.return_options, rng, BASIC_RETURN_OPTIONS_MUTATION_CONFIGURATION);
5959
}
6060

61+
void mutate_finalize_with_revert(FinalizeWithRevert& instr, std::mt19937_64& rng)
62+
{
63+
mutate_return_options(instr.revert_options, rng, BASIC_RETURN_OPTIONS_MUTATION_CONFIGURATION);
64+
}
65+
6166
void mutate_switch_to_non_terminated_block(SwitchToNonTerminatedBlock& instr, std::mt19937_64& rng)
6267
{
6368
mutate_uint16_t(instr.non_terminated_block_idx, rng, BASIC_UINT16_T_MUTATION_CONFIGURATION);
@@ -86,6 +91,10 @@ CFGInstruction generate_cfg_instruction(std::mt19937_64& rng)
8691
return FinalizeWithReturn(ReturnOptions(generate_random_uint8(rng),
8792
generate_memory_tag(rng, BASIC_MEMORY_TAG_GENERATION_CONFIGURATION),
8893
generate_random_uint16(rng)));
94+
case CFGInstructionGenerationOptions::FinalizeWithRevert:
95+
return FinalizeWithRevert(ReturnOptions(generate_random_uint8(rng),
96+
generate_memory_tag(rng, BASIC_MEMORY_TAG_GENERATION_CONFIGURATION),
97+
generate_random_uint16(rng)));
8998
case CFGInstructionGenerationOptions::SwitchToNonTerminatedBlock:
9099
return SwitchToNonTerminatedBlock(generate_random_uint16(rng));
91100
case CFGInstructionGenerationOptions::InsertInternalCall:
@@ -102,6 +111,7 @@ void mutate_cfg_instruction(CFGInstruction& cfg_instruction, std::mt19937_64& rn
102111
[&](JumpToBlock& instr) { mutate_jump_to_block(instr, rng); },
103112
[&](JumpIfToBlock& instr) { mutate_jump_if_to_block(instr, rng); },
104113
[&](FinalizeWithReturn& instr) { mutate_finalize_with_return(instr, rng); },
114+
[&](FinalizeWithRevert& instr) { mutate_finalize_with_revert(instr, rng); },
105115
[&](SwitchToNonTerminatedBlock& instr) { mutate_switch_to_non_terminated_block(instr, rng); },
106116
[&](InsertInternalCall& instr) { mutate_insert_internal_call(instr, rng); } },
107117
cfg_instruction);

0 commit comments

Comments
 (0)