Skip to content

Commit 153abee

Browse files
author
jeanmon
committed
5159 - add deserialization and execution for MOV and unit test
1 parent 4a88fe1 commit 153abee

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_deserialization.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const std::unordered_map<OpCode, std::vector<OperandType>> OPCODE_WIRE_FORMAT =
3838
{ OpCode::INTERNALRETURN, {} },
3939
// Machine State - Memory
4040
// OpCode::SET is handled differently
41+
{ OpCode::MOV, { OperandType::INDIRECT, OperandType::UINT32, OperandType::UINT32 } },
4142
// Control Flow - Contract Calls
4243
{ OpCode::RETURN, { OperandType::INDIRECT, OperandType::UINT32, OperandType::UINT32 } },
4344
};

barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ std::vector<Row> Execution::gen_trace(std::vector<Instruction> const& instructio
178178
trace_builder.set(val, dst_offset, in_tag);
179179
break;
180180
}
181+
case OpCode::MOV:
182+
trace_builder.op_mov(std::get<uint32_t>(inst.operands.at(1)), std::get<uint32_t>(inst.operands.at(2)));
183+
break;
181184
// Control Flow - Contract Calls
182185
case OpCode::RETURN:
183186
// Skip indirect at index 0

barretenberg/cpp/src/barretenberg/vm/tests/avm_execution.test.cpp

+48
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,54 @@ TEST_F(AvmExecutionTests, jumpAndCalldatacopy)
455455
gen_proof_and_validate(bytecode, std::move(trace), std::vector<FF>{ 13, 156 });
456456
}
457457

458+
// Positive test with MOV.
459+
TEST_F(AvmExecutionTests, movOpcode)
460+
{
461+
std::string bytecode_hex = to_hex(OpCode::SET) + // opcode SET
462+
"00" // Indirect flag
463+
"01" // U8
464+
"13" // val 19
465+
"000000AB" // dst_offset 171
466+
+ to_hex(OpCode::MOV) + // opcode MOV
467+
"00" // Indirect flag
468+
"000000AB" // src_offset 171
469+
"00000021" // dst_offset 33
470+
+ to_hex(OpCode::RETURN) + // opcode RETURN
471+
"00" // Indirect flag
472+
"00000000" // ret offset 0
473+
"00000000"; // ret size 0
474+
475+
auto bytecode = hex_to_bytes(bytecode_hex);
476+
auto instructions = Deserialization::parse(bytecode);
477+
478+
ASSERT_THAT(instructions, SizeIs(3));
479+
480+
// SET
481+
EXPECT_THAT(instructions.at(0),
482+
AllOf(Field(&Instruction::op_code, OpCode::SET),
483+
Field(&Instruction::operands,
484+
ElementsAre(VariantWith<uint8_t>(0),
485+
VariantWith<AvmMemoryTag>(AvmMemoryTag::U8),
486+
VariantWith<uint8_t>(19),
487+
VariantWith<uint32_t>(171)))));
488+
489+
// MOV
490+
EXPECT_THAT(
491+
instructions.at(1),
492+
AllOf(Field(&Instruction::op_code, OpCode::MOV),
493+
Field(&Instruction::operands,
494+
ElementsAre(VariantWith<uint8_t>(0), VariantWith<uint32_t>(171), VariantWith<uint32_t>(33)))));
495+
496+
auto trace = Execution::gen_trace(instructions);
497+
498+
// Find the first row enabling the MOV selector
499+
auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_mov == 1; });
500+
EXPECT_EQ(row->avm_main_ia, 19);
501+
EXPECT_EQ(row->avm_main_ic, 19);
502+
503+
gen_proof_and_validate(bytecode, std::move(trace), {});
504+
}
505+
458506
// Negative test detecting an invalid opcode byte.
459507
TEST_F(AvmExecutionTests, invalidOpcode)
460508
{

0 commit comments

Comments
 (0)