Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
bytecode_builder.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <cstdint>
5#include <span>
6#include <vector>
7
10
11namespace bb::avm2::testing {
12
13// Serializes a sequence of AVM instructions into a single contiguous bytecode buffer:
14// each instruction is serialized according to its wire format and the results are concatenated.
16 public:
19
20 // Appends raw bytes. Used by tests that craft malformed bytecode (invalid opcodes/tags,
21 // truncated instructions) which cannot be produced through the instruction encoder.
23
24 std::vector<uint8_t> build() const { return bytecode; }
25 size_t size() const { return bytecode.size(); }
26
27 private:
28 std::vector<uint8_t> bytecode;
29};
30
31// Convenience free function that serializes a sequence of instructions into a bytecode buffer.
32std::vector<uint8_t> encode_to_bytecode(const std::vector<simulation::Instruction>& instructions);
33
34// Returns the byte offset of the TAG operand within a serialized instruction of the given
35// wire opcode (including the leading opcode byte and addressing-mode byte). Used by tests that
36// patch the tag byte to an invalid value.
37// Asserts that the wire format for the opcode contains a TAG operand.
38size_t tag_byte_offset(WireOpCode opcode);
39
40} // namespace bb::avm2::testing
std::vector< uint8_t > build() const
BytecodeBuilder & add(const simulation::Instruction &instruction)
BytecodeBuilder & add_raw(std::span< const uint8_t > bytes)
BytecodeBuilder & add(const InstructionBuilder &builder)
AluTraceBuilder builder
Definition alu.test.cpp:124
Instruction instruction
size_t tag_byte_offset(WireOpCode opcode)
std::vector< uint8_t > encode_to_bytecode(const std::vector< Instruction > &instructions)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13