Skip to content

Commit

Permalink
4495 - address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanmon committed Feb 8, 2024
1 parent 18efd3a commit acfb1e9
Showing 1 changed file with 63 additions and 71 deletions.
134 changes: 63 additions & 71 deletions barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_execution.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,28 +66,23 @@ TEST_F(AvmMiniExecutionTests, basicAddReturn)
auto instructions = Deserialization::parse(bytecode);

// 2 instructions
EXPECT_THAT(instructions, SizeIs(2));
ASSERT_THAT(instructions, SizeIs(2));

// ADD
EXPECT_EQ(instructions.at(0).op_code, OpCode::ADD);

auto operands = instructions.at(0).operands;
EXPECT_THAT(operands,
ElementsAre(VariantWith<AvmMemoryTag>(AvmMemoryTag::U8),
VariantWith<uint32_t>(7),
VariantWith<uint32_t>(9),
VariantWith<uint32_t>(1)));
EXPECT_THAT(instructions.at(0),
AllOf(Field(&Instruction::op_code, OpCode::ADD),
Field(&Instruction::operands,
ElementsAre(VariantWith<AvmMemoryTag>(AvmMemoryTag::U8),
VariantWith<uint32_t>(7),
VariantWith<uint32_t>(9),
VariantWith<uint32_t>(1)))));

// RETURN
EXPECT_EQ(instructions.at(1).op_code, OpCode::RETURN);

operands = instructions.at(1).operands;
EXPECT_EQ(operands.size(), 2);
EXPECT_EQ(std::get<uint32_t>(operands.at(0)), 0);
EXPECT_EQ(std::get<uint32_t>(operands.at(1)), 0);
EXPECT_THAT(instructions.at(1),
AllOf(Field(&Instruction::op_code, OpCode::RETURN),
Field(&Instruction::operands, ElementsAre(VariantWith<uint32_t>(0), VariantWith<uint32_t>(0)))));

auto trace = Execution::gen_trace(instructions);

gen_proof_and_validate(bytecode, std::move(trace), {});
}

Expand All @@ -114,34 +109,32 @@ TEST_F(AvmMiniExecutionTests, setAndSubOpcodes)
auto bytecode = hex_to_bytes(bytecode_hex);
auto instructions = Deserialization::parse(bytecode);

EXPECT_THAT(instructions, SizeIs(4));
ASSERT_THAT(instructions, SizeIs(4));

// SET
EXPECT_EQ(instructions.at(0).op_code, OpCode::SET);

auto operands = instructions.at(0).operands;
EXPECT_THAT(operands,
ElementsAre(VariantWith<AvmMemoryTag>(AvmMemoryTag::U16),
VariantWith<uint16_t>(47123),
VariantWith<uint32_t>(170)));
EXPECT_THAT(instructions.at(0),
AllOf(Field(&Instruction::op_code, OpCode::SET),
Field(&Instruction::operands,
ElementsAre(VariantWith<AvmMemoryTag>(AvmMemoryTag::U16),
VariantWith<uint16_t>(47123),
VariantWith<uint32_t>(170)))));

// SET
EXPECT_EQ(instructions.at(1).op_code, OpCode::SET);
EXPECT_THAT(instructions.at(1),
AllOf(Field(&Instruction::op_code, OpCode::SET),
Field(&Instruction::operands,
ElementsAre(VariantWith<AvmMemoryTag>(AvmMemoryTag::U16),
VariantWith<uint16_t>(37123),
VariantWith<uint32_t>(51)))));

operands = instructions.at(1).operands;
EXPECT_THAT(operands,
ElementsAre(VariantWith<AvmMemoryTag>(AvmMemoryTag::U16),
VariantWith<uint16_t>(37123),
VariantWith<uint32_t>(51)));
// SUB
EXPECT_EQ(instructions.at(2).op_code, OpCode::SUB);

operands = instructions.at(2).operands;
EXPECT_THAT(operands,
ElementsAre(VariantWith<AvmMemoryTag>(AvmMemoryTag::U16),
VariantWith<uint32_t>(170),
VariantWith<uint32_t>(51),
VariantWith<uint32_t>(1)));
EXPECT_THAT(instructions.at(2),
AllOf(Field(&Instruction::op_code, OpCode::SUB),
Field(&Instruction::operands,
ElementsAre(VariantWith<AvmMemoryTag>(AvmMemoryTag::U16),
VariantWith<uint32_t>(170),
VariantWith<uint32_t>(51),
VariantWith<uint32_t>(1)))));

auto trace = Execution::gen_trace(instructions);

Expand Down Expand Up @@ -181,8 +174,7 @@ TEST_F(AvmMiniExecutionTests, powerWithMulOpcodes)
"00000000" // ret offset 0
"00000000"; // ret size 0

uint8_t num = 12;
while (num-- > 0) {
for (int i = 0; i < 12; i++) {
bytecode_hex.append(mul_hex);
}

Expand All @@ -191,33 +183,30 @@ TEST_F(AvmMiniExecutionTests, powerWithMulOpcodes)
auto bytecode = hex_to_bytes(bytecode_hex);
auto instructions = Deserialization::parse(bytecode);

EXPECT_THAT(instructions, SizeIs(15));
ASSERT_THAT(instructions, SizeIs(15));

// MUL first pos
EXPECT_EQ(instructions.at(2).op_code, OpCode::MUL);

auto operands = instructions.at(2).operands;
EXPECT_THAT(operands,
ElementsAre(VariantWith<AvmMemoryTag>(AvmMemoryTag::U64),
VariantWith<uint32_t>(0),
VariantWith<uint32_t>(1),
VariantWith<uint32_t>(1)));
EXPECT_THAT(instructions.at(2),
AllOf(Field(&Instruction::op_code, OpCode::MUL),
Field(&Instruction::operands,
ElementsAre(VariantWith<AvmMemoryTag>(AvmMemoryTag::U64),
VariantWith<uint32_t>(0),
VariantWith<uint32_t>(1),
VariantWith<uint32_t>(1)))));

// MUL last pos
EXPECT_EQ(instructions.at(13).op_code, OpCode::MUL);

operands = instructions.at(13).operands;
EXPECT_THAT(operands,
ElementsAre(VariantWith<AvmMemoryTag>(AvmMemoryTag::U64),
VariantWith<uint32_t>(0),
VariantWith<uint32_t>(1),
VariantWith<uint32_t>(1)));
EXPECT_THAT(instructions.at(13),
AllOf(Field(&Instruction::op_code, OpCode::MUL),
Field(&Instruction::operands,
ElementsAre(VariantWith<AvmMemoryTag>(AvmMemoryTag::U64),
VariantWith<uint32_t>(0),
VariantWith<uint32_t>(1),
VariantWith<uint32_t>(1)))));

// RETURN
EXPECT_EQ(instructions.at(14).op_code, OpCode::RETURN);
operands = instructions.at(14).operands;

EXPECT_THAT(operands, ElementsAre(VariantWith<uint32_t>(0), VariantWith<uint32_t>(0)));
EXPECT_THAT(instructions.at(14),
AllOf(Field(&Instruction::op_code, OpCode::RETURN),
Field(&Instruction::operands, ElementsAre(VariantWith<uint32_t>(0), VariantWith<uint32_t>(0)))));

auto trace = Execution::gen_trace(instructions);

Expand Down Expand Up @@ -269,8 +258,9 @@ TEST_F(AvmMiniExecutionTests, simpleInternalCall)
// We test parsing step for INTERNALCALL and INTERNALRETURN.

// INTERNALCALL
EXPECT_EQ(instructions.at(1).op_code, OpCode::INTERNALCALL);
EXPECT_THAT(instructions.at(1).operands, ElementsAre(VariantWith<uint32_t>(4)));
EXPECT_THAT(instructions.at(1),
AllOf(Field(&Instruction::op_code, OpCode::INTERNALCALL),
Field(&Instruction::operands, ElementsAre(VariantWith<uint32_t>(4)))));

// INTERNALRETURN
EXPECT_EQ(instructions.at(5).op_code, OpCode::INTERNALRETURN);
Expand Down Expand Up @@ -340,7 +330,7 @@ TEST_F(AvmMiniExecutionTests, nestedInternalCalls)
auto bytecode = hex_to_bytes(bytecode_hex);
auto instructions = Deserialization::parse(bytecode);

EXPECT_THAT(instructions, SizeIs(12));
ASSERT_THAT(instructions, SizeIs(12));

// Expected sequence of opcodes
std::vector<OpCode> const opcode_sequence{ OpCode::SET, OpCode::SET,
Expand Down Expand Up @@ -403,19 +393,21 @@ TEST_F(AvmMiniExecutionTests, jumpAndCalldatacopy)
auto bytecode = hex_to_bytes(bytecode_hex);
auto instructions = Deserialization::parse(bytecode);

EXPECT_THAT(instructions, SizeIs(5));
ASSERT_THAT(instructions, SizeIs(5));

// We test parsing steps for CALLDATACOPY and JUMP.

// CALLDATACOPY
EXPECT_EQ(instructions.at(0).op_code, OpCode::CALLDATACOPY);

auto operands = instructions.at(0).operands;
EXPECT_THAT(operands, ElementsAre(VariantWith<uint32_t>(0), VariantWith<uint32_t>(2), VariantWith<uint32_t>(10)));
EXPECT_THAT(
instructions.at(0),
AllOf(Field(&Instruction::op_code, OpCode::CALLDATACOPY),
Field(&Instruction::operands,
ElementsAre(VariantWith<uint32_t>(0), VariantWith<uint32_t>(2), VariantWith<uint32_t>(10)))));

// JUMP
EXPECT_EQ(instructions.at(1).op_code, OpCode::JUMP);
EXPECT_THAT(instructions.at(1).operands, ElementsAre(VariantWith<uint32_t>(3)));
EXPECT_THAT(instructions.at(1),
AllOf(Field(&Instruction::op_code, OpCode::JUMP),
Field(&Instruction::operands, ElementsAre(VariantWith<uint32_t>(3)))));

auto trace = Execution::gen_trace(instructions, std::vector<FF>{ 13, 156 });

Expand Down

0 comments on commit acfb1e9

Please sign in to comment.