Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
serialization.hpp
Go to the documentation of this file.
1#pragma once
2
8
9#include <cstdint>
10#include <memory>
11#include <optional>
12#include <string>
13#include <variant>
14#include <vector>
15
16namespace bb::avm2::simulation {
17
18// Possible types for an instruction's operand in its wire format.
19// The counterpart TS file is: avm/serialization/instruction_serialization.ts.
20// INDIRECT is parsed as UINT8 where the bits represent the operands that have indirect mem access.
22
23namespace testonly {
24
27
28} // namespace testonly
29
31
34 uint16_t indirect = 0;
36
37 std::string to_string() const;
38
39 // Serialize the instruction according to the specification from OPCODE_WIRE_FORMAT.
40 // There is no validation that the instructions operands comply to the format. Namely,
41 // they are casted according to the operand variant specified in format (throw only in
42 // truncation case). If the number of operands is larger than specified in format,
43 // no error will be thrown neither.
44 std::vector<uint8_t> serialize() const;
45
46 size_t size_in_bytes() const;
48
49 bool operator==(const Instruction& other) const = default;
50};
51
52enum class InstrDeserializationEventError : uint8_t {
57 // FIXME: remove this once all execution opcodes are supported.
58 // Also uncomment proper constraining of error in instr_fetching.pil.
60};
61
65
66 // Constructor from error type only
71
72 // Constructor with error type and message
74 : type(t)
75 , message(msg)
76 {}
77
78 bool operator==(const InstrDeserializationError& other) const = default;
79};
80
92
103
104} // namespace bb::avm2::simulation
std::shared_ptr< Napi::ThreadSafeFunction > bytecode
Instruction instruction
const std::unordered_map< OperandType, uint32_t > & get_operand_type_sizes()
const std::unordered_map< WireOpCode, std::vector< OperandType > > & get_instruction_wire_formats()
bool check_tag(const Instruction &instruction)
Check whether the instruction must have a tag operand and whether the operand value is in the value t...
Instruction deserialize_instruction(std::span< const uint8_t > bytecode, size_t pos)
Parsing of an instruction in the supplied bytecode at byte position pos. This checks that the WireOpC...
AvmFlavorSettings::FF FF
Definition field.hpp:10
STL namespace.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
InstrDeserializationError(InstrDeserializationEventError t)
InstrDeserializationError(InstrDeserializationEventError t, const std::string &msg)
bool operator==(const InstrDeserializationError &other) const =default
std::vector< uint8_t > serialize() const
bool operator==(const Instruction &other) const =default
std::vector< Operand > operands
ExecutionOpCode get_exec_opcode() const