Skip to content

Commit

Permalink
Merge branch 'master' into sync-noir
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench authored Nov 27, 2024
2 parents a33ae1a + eeea0aa commit 144907c
Show file tree
Hide file tree
Showing 80 changed files with 1,160 additions and 567 deletions.
100 changes: 67 additions & 33 deletions barretenberg/cpp/src/barretenberg/vm/avm/tests/execution.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ TEST_F(AvmExecutionTests, basicAddReturn)
"00FF"; // ret size offset 255

auto bytecode = hex_to_bytes(bytecode_hex);
auto instructions = Deserialization::parse_bytecode_statically(bytecode);
auto [instructions, error] = Deserialization::parse_bytecode_statically(bytecode);
ASSERT_TRUE(is_ok(error));

// 2 instructions
ASSERT_THAT(instructions, SizeIs(5));
Expand Down Expand Up @@ -214,7 +215,8 @@ TEST_F(AvmExecutionTests, setAndSubOpcodes)
"00FF"; // ret size offset 255

auto bytecode = hex_to_bytes(bytecode_hex);
auto instructions = Deserialization::parse_bytecode_statically(bytecode);
auto [instructions, error] = Deserialization::parse_bytecode_statically(bytecode);
ASSERT_TRUE(is_ok(error));

ASSERT_THAT(instructions, SizeIs(5));

Expand Down Expand Up @@ -295,7 +297,8 @@ TEST_F(AvmExecutionTests, powerWithMulOpcodes)
bytecode_hex.append(ret_hex);

auto bytecode = hex_to_bytes(bytecode_hex);
auto instructions = Deserialization::parse_bytecode_statically(bytecode);
auto [instructions, error] = Deserialization::parse_bytecode_statically(bytecode);
ASSERT_TRUE(is_ok(error));

ASSERT_THAT(instructions, SizeIs(16));

Expand Down Expand Up @@ -394,7 +397,8 @@ TEST_F(AvmExecutionTests, simpleInternalCall)
;

auto bytecode = hex_to_bytes(bytecode_hex);
auto instructions = Deserialization::parse_bytecode_statically(bytecode);
auto [instructions, error] = Deserialization::parse_bytecode_statically(bytecode);
ASSERT_TRUE(is_ok(error));

EXPECT_THAT(instructions, SizeIs(7));

Expand Down Expand Up @@ -475,7 +479,8 @@ TEST_F(AvmExecutionTests, nestedInternalCalls)
bytecode_f2 + bytecode_f1 + bytecode_g;

auto bytecode = hex_to_bytes(bytecode_hex);
auto instructions = Deserialization::parse_bytecode_statically(bytecode);
auto [instructions, error] = Deserialization::parse_bytecode_statically(bytecode);
ASSERT_TRUE(is_ok(error));

ASSERT_THAT(instructions, SizeIs(13));

Expand Down Expand Up @@ -555,7 +560,8 @@ TEST_F(AvmExecutionTests, jumpAndCalldatacopy)
;

auto bytecode = hex_to_bytes(bytecode_hex);
auto instructions = Deserialization::parse_bytecode_statically(bytecode);
auto [instructions, error] = Deserialization::parse_bytecode_statically(bytecode);
ASSERT_TRUE(is_ok(error));

ASSERT_THAT(instructions, SizeIs(8));

Expand Down Expand Up @@ -657,7 +663,8 @@ TEST_F(AvmExecutionTests, jumpiAndCalldatacopy)
;

auto bytecode = hex_to_bytes(bytecode_hex);
auto instructions = Deserialization::parse_bytecode_statically(bytecode);
auto [instructions, error] = Deserialization::parse_bytecode_statically(bytecode);
ASSERT_TRUE(is_ok(error));

ASSERT_THAT(instructions, SizeIs(9));

Expand Down Expand Up @@ -714,7 +721,8 @@ TEST_F(AvmExecutionTests, movOpcode)
"00FF"; // ret size offset 255

auto bytecode = hex_to_bytes(bytecode_hex);
auto instructions = Deserialization::parse_bytecode_statically(bytecode);
auto [instructions, error] = Deserialization::parse_bytecode_statically(bytecode);
ASSERT_TRUE(is_ok(error));

ASSERT_THAT(instructions, SizeIs(4));

Expand Down Expand Up @@ -773,7 +781,8 @@ TEST_F(AvmExecutionTests, indMovOpcode)
"00FF"; // ret size offset 255

auto bytecode = hex_to_bytes(bytecode_hex);
auto instructions = Deserialization::parse_bytecode_statically(bytecode);
auto [instructions, error] = Deserialization::parse_bytecode_statically(bytecode);
ASSERT_TRUE(is_ok(error));

ASSERT_THAT(instructions, SizeIs(6));

Expand Down Expand Up @@ -815,7 +824,8 @@ TEST_F(AvmExecutionTests, setAndCastOpcodes)
"00FF"; // ret size offset 255

auto bytecode = hex_to_bytes(bytecode_hex);
auto instructions = Deserialization::parse_bytecode_statically(bytecode);
auto [instructions, error] = Deserialization::parse_bytecode_statically(bytecode);
ASSERT_TRUE(is_ok(error));

ASSERT_THAT(instructions, SizeIs(4));

Expand Down Expand Up @@ -884,7 +894,8 @@ TEST_F(AvmExecutionTests, toRadixBeOpcodeBytes)
"0200"; // ret size offset 512

auto bytecode = hex_to_bytes(bytecode_hex);
auto instructions = Deserialization::parse_bytecode_statically(bytecode);
auto [instructions, error] = Deserialization::parse_bytecode_statically(bytecode);
ASSERT_TRUE(is_ok(error));

// Assign a vector that we will mutate internally in gen_trace to store the return values;
std::vector<FF> returndata;
Expand Down Expand Up @@ -958,7 +969,8 @@ TEST_F(AvmExecutionTests, toRadixBeOpcodeBitsMode)
"0200"; // ret size offset 512

auto bytecode = hex_to_bytes(bytecode_hex);
auto instructions = Deserialization::parse_bytecode_statically(bytecode);
auto [instructions, error] = Deserialization::parse_bytecode_statically(bytecode);
ASSERT_TRUE(is_ok(error));

// Assign a vector that we will mutate internally in gen_trace to store the return values;
std::vector<FF> returndata;
Expand Down Expand Up @@ -1031,7 +1043,8 @@ TEST_F(AvmExecutionTests, sha256CompressionOpcode)
"0200"; // ret size offset 512

auto bytecode = hex_to_bytes(bytecode_hex);
auto instructions = Deserialization::parse_bytecode_statically(bytecode);
auto [instructions, error] = Deserialization::parse_bytecode_statically(bytecode);
ASSERT_TRUE(is_ok(error));

// Assign a vector that we will mutate internally in gen_trace to store the return values;
std::vector<FF> calldata = std::vector<FF>();
Expand Down Expand Up @@ -1093,7 +1106,8 @@ TEST_F(AvmExecutionTests, poseidon2PermutationOpCode)
"0200"; // ret size offset 512

auto bytecode = hex_to_bytes(bytecode_hex);
auto instructions = Deserialization::parse_bytecode_statically(bytecode);
auto [instructions, error] = Deserialization::parse_bytecode_statically(bytecode);
ASSERT_TRUE(is_ok(error));

// Assign a vector that we will mutate internally in gen_trace to store the return values;
std::vector<FF> returndata = std::vector<FF>();
Expand Down Expand Up @@ -1168,7 +1182,8 @@ TEST_F(AvmExecutionTests, keccakf1600OpCode)
"0200"; // ret size offset 512

auto bytecode = hex_to_bytes(bytecode_hex);
auto instructions = Deserialization::parse_bytecode_statically(bytecode);
auto [instructions, error] = Deserialization::parse_bytecode_statically(bytecode);
ASSERT_TRUE(is_ok(error));

// Assign a vector that we will mutate internally in gen_trace to store the return values;
std::vector<FF> calldata = std::vector<FF>();
Expand Down Expand Up @@ -1241,7 +1256,8 @@ TEST_F(AvmExecutionTests, embeddedCurveAddOpCode)
"0200"; // ret size offset 512

auto bytecode = hex_to_bytes(bytecode_hex);
auto instructions = Deserialization::parse_bytecode_statically(bytecode);
auto [instructions, error] = Deserialization::parse_bytecode_statically(bytecode);
ASSERT_TRUE(is_ok(error));

// Assign a vector that we will mutate internally in gen_trace to store the return values;
std::vector<FF> returndata;
Expand Down Expand Up @@ -1336,7 +1352,8 @@ TEST_F(AvmExecutionTests, msmOpCode)
"0200"; // ret size offset 512

auto bytecode = hex_to_bytes(bytecode_hex);
auto instructions = Deserialization::parse_bytecode_statically(bytecode);
auto [instructions, error] = Deserialization::parse_bytecode_statically(bytecode);
ASSERT_TRUE(is_ok(error));

// Assign a vector that we will mutate internally in gen_trace to store the return values;
std::vector<FF> returndata;
Expand Down Expand Up @@ -1407,7 +1424,8 @@ TEST_F(AvmExecutionTests, getEnvOpcode)
"0200"; // ret size offset 512

auto bytecode = hex_to_bytes(bytecode_hex);
auto instructions = Deserialization::parse_bytecode_statically(bytecode);
auto [instructions, error] = Deserialization::parse_bytecode_statically(bytecode);
ASSERT_TRUE(is_ok(error));

ASSERT_THAT(instructions, SizeIs(13));

Expand Down Expand Up @@ -1623,7 +1641,8 @@ TEST_F(AvmExecutionTests, getEnvOpcode)
// "0001"; // dst_offset
//
// auto bytecode = hex_to_bytes(bytecode_hex);
// auto instructions = Deserialization::parse_bytecode_statically(bytecode);
// auto [instructions, error] = Deserialization::parse_bytecode_statically(bytecode);
// ASSERT_TRUE(is_ok(error));
//
// // Public inputs for the circuit
// std::vector<FF> calldata;
Expand Down Expand Up @@ -1660,7 +1679,8 @@ TEST_F(AvmExecutionTests, l2GasLeft)
"00FF"; // ret size offset 255

auto bytecode = hex_to_bytes(bytecode_hex);
auto instructions = Deserialization::parse_bytecode_statically(bytecode);
auto [instructions, error] = Deserialization::parse_bytecode_statically(bytecode);
ASSERT_TRUE(is_ok(error));

ASSERT_THAT(instructions, SizeIs(4));

Expand Down Expand Up @@ -1708,7 +1728,8 @@ TEST_F(AvmExecutionTests, daGasLeft)
"00FF"; // ret size offset 255

auto bytecode = hex_to_bytes(bytecode_hex);
auto instructions = Deserialization::parse_bytecode_statically(bytecode);
auto [instructions, error] = Deserialization::parse_bytecode_statically(bytecode);
ASSERT_TRUE(is_ok(error));

ASSERT_THAT(instructions, SizeIs(4));

Expand Down Expand Up @@ -1747,7 +1768,8 @@ TEST_F(AvmExecutionTests, ExecutorThrowsWithTooMuchGasAllocated)
public_inputs.gas_settings.gas_limits.l2_gas = MAX_L2_GAS_PER_ENQUEUED_CALL;

auto bytecode = hex_to_bytes(bytecode_hex);
auto instructions = Deserialization::parse_bytecode_statically(bytecode);
auto [instructions, error] = Deserialization::parse_bytecode_statically(bytecode);
ASSERT_TRUE(is_ok(error));

ExecutionHints execution_hints;
EXPECT_THROW_WITH_MESSAGE(gen_trace(bytecode, calldata, public_inputs, returndata, execution_hints),
Expand All @@ -1767,7 +1789,8 @@ TEST_F(AvmExecutionTests, ExecutorThrowsWithTooMuchGasAllocated)
// std::vector<FF> public_inputs = { 1 };
//
// auto bytecode = hex_to_bytes(bytecode_hex);
// auto instructions = Deserialization::parse_bytecode_statically(bytecode);
// auto [instructions, error] = Deserialization::parse_bytecode_statically(bytecode);
// ASSERT_TRUE(is_ok(error));
//
// ExecutionHints execution_hints;
// EXPECT_THROW_WITH_MESSAGE(gen_trace(bytecode, calldata, public_inputs, returndata, execution_hints),
Expand Down Expand Up @@ -1814,7 +1837,8 @@ TEST_F(AvmExecutionTests, kernelOutputEmitOpcodes)
"0000"; // ret size 0

auto bytecode = hex_to_bytes(bytecode_hex);
auto instructions = Deserialization::parse_bytecode_statically(bytecode);
auto [instructions, error] = Deserialization::parse_bytecode_statically(bytecode);
ASSERT_TRUE(is_ok(error));

ASSERT_THAT(instructions, SizeIs(8));

Expand Down Expand Up @@ -1943,7 +1967,8 @@ TEST_F(AvmExecutionTests, kernelOutputStorageLoadOpcodeSimple)
"00FF"; // ret size offset 255

auto bytecode = hex_to_bytes(bytecode_hex);
auto instructions = Deserialization::parse_bytecode_statically(bytecode);
auto [instructions, error] = Deserialization::parse_bytecode_statically(bytecode);
ASSERT_TRUE(is_ok(error));

ASSERT_THAT(instructions, SizeIs(5));

Expand Down Expand Up @@ -2010,7 +2035,8 @@ TEST_F(AvmExecutionTests, kernelOutputStorageStoreOpcodeSimple)
"0200"; // ret size offset 512

auto bytecode = hex_to_bytes(bytecode_hex);
auto instructions = Deserialization::parse_bytecode_statically(bytecode);
auto [instructions, error] = Deserialization::parse_bytecode_statically(bytecode);
ASSERT_TRUE(is_ok(error));

std::vector<FF> returndata;

Expand Down Expand Up @@ -2072,7 +2098,8 @@ TEST_F(AvmExecutionTests, kernelOutputStorageOpcodes)
"00FF"; // ret size offset 255

auto bytecode = hex_to_bytes(bytecode_hex);
auto instructions = Deserialization::parse_bytecode_statically(bytecode);
auto [instructions, error] = Deserialization::parse_bytecode_statically(bytecode);
ASSERT_TRUE(is_ok(error));

ASSERT_THAT(instructions, SizeIs(6));

Expand Down Expand Up @@ -2159,7 +2186,8 @@ TEST_F(AvmExecutionTests, kernelOutputHashExistsOpcodes)
"0200"; // ret size offset 512

auto bytecode = hex_to_bytes(bytecode_hex);
auto instructions = Deserialization::parse_bytecode_statically(bytecode);
auto [instructions, error] = Deserialization::parse_bytecode_statically(bytecode);
ASSERT_TRUE(is_ok(error));

ASSERT_THAT(instructions, SizeIs(7));

Expand Down Expand Up @@ -2313,7 +2341,8 @@ TEST_F(AvmExecutionTests, opCallOpcodes)
"0200"; // ret size offset 512

auto bytecode = hex_to_bytes(bytecode_hex);
auto instructions = Deserialization::parse_bytecode_statically(bytecode);
auto [instructions, error] = Deserialization::parse_bytecode_statically(bytecode);
ASSERT_TRUE(is_ok(error));

std::vector<FF> returndata;

Expand Down Expand Up @@ -2392,7 +2421,8 @@ TEST_F(AvmExecutionTests, opGetContractInstanceOpcode)
"0200"; // ret size offset 512

auto bytecode = hex_to_bytes(bytecode_hex);
auto instructions = Deserialization::parse_bytecode_statically(bytecode);
auto [instructions, error] = Deserialization::parse_bytecode_statically(bytecode);
ASSERT_TRUE(is_ok(error));

ASSERT_THAT(instructions, SizeIs(6));

Expand Down Expand Up @@ -2427,7 +2457,9 @@ TEST_F(AvmExecutionTests, opGetContractInstanceOpcodeBadEnum)
+ to_hex(static_cast<uint8_t>(ContractInstanceMember::MAX_MEMBER)); // member enum

auto bytecode = hex_to_bytes(bytecode_hex);
auto instructions = Deserialization::parse_bytecode_statically(bytecode);
auto [instructions, error] = Deserialization::parse_bytecode_statically(bytecode);
ASSERT_TRUE(is_ok(error));

ASSERT_THAT(instructions, SizeIs(2));

std::vector<FF> calldata;
Expand Down Expand Up @@ -2457,7 +2489,8 @@ TEST_F(AvmExecutionTests, invalidOpcode)
"0000"; // ret size 0

auto bytecode = hex_to_bytes(bytecode_hex);
EXPECT_THROW_WITH_MESSAGE(Deserialization::parse_bytecode_statically(bytecode), "Invalid opcode");
const auto [instructions, error] = Deserialization::parse_bytecode_statically(bytecode);
ASSERT_EQ(error, AvmError::INVALID_OPCODE);
}

// Negative test detecting an incomplete instruction: instruction tag present but an operand is missing
Expand All @@ -2474,7 +2507,8 @@ TEST_F(AvmExecutionTests, truncatedInstructionNoOperand)
"FF"; // addr b and missing address for c = a-b

auto bytecode = hex_to_bytes(bytecode_hex);
EXPECT_THROW_WITH_MESSAGE(Deserialization::parse_bytecode_statically(bytecode), "Operand is missing");
const auto [instructions, error] = Deserialization::parse_bytecode_statically(bytecode);
ASSERT_EQ(error, AvmError::PARSING_ERROR);
}

} // namespace tests_avm
Loading

0 comments on commit 144907c

Please sign in to comment.