Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
aztec_types.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <stdexcept>
5#include <vector>
6
9
10namespace bb::avm2 {
11
13using BytecodeId = FF;
15using PC = uint32_t;
17// In typescript the EthAddress is a byte vector, but in our circuit implementation
18// it's represented as a field element for simplicity
19using EthAddress = FF;
20
36
37using InternalCallId = uint32_t;
38
58
60 DEPLOYER = 0,
61 CLASS_ID = 1,
62 INIT_HASH = 2,
63 MAX = INIT_HASH,
64};
65
67// Keys, Instances, Classes
69
84
95
102
104// Size Effect Types
106
115
124struct PublicLog {
125 std::vector<FF> fields;
127
128 bool operator==(const PublicLog& other) const = default;
129
131};
132
134 uint32_t length;
135 std::array<FF, FLAT_PUBLIC_LOGS_PAYLOAD_LENGTH> payload;
136 bool operator==(const PublicLogs& other) const = default;
137
139
141 {
142 // Header
143 payload[length] = log.fields.size();
144 payload[length + 1] = log.contractAddress;
145 // Payload
146 for (size_t i = 0; i < log.fields.size(); ++i) {
148 }
149 length += log.fields.size() + PUBLIC_LOG_HEADER_LENGTH;
150 }
151};
152
156
157 bool operator==(const PublicDataWrite& other) const = default;
158
160};
161
163// Gas Types
165
174
175struct Gas {
176 uint32_t l2Gas;
177 uint32_t daGas;
178
179 bool operator==(const Gas& other) const = default;
180
181 Gas operator+(const Gas& other) const { return { l2Gas + other.l2Gas, daGas + other.daGas }; }
182 Gas operator-(const Gas& other) const { return { l2Gas - other.l2Gas, daGas - other.daGas }; }
183
185};
186
197
199// Public Call Requests
201
212
222
233
235// Accumulated Data Types
237
247
249 std::array<FF, MAX_NOTE_HASHES_PER_TX> noteHashes;
250 std::array<FF, MAX_NULLIFIERS_PER_TX> nullifiers;
252
253 bool operator==(const PrivateToAvmAccumulatedData& other) const = default;
254
256};
257
269
271// Global Variables
273
288
290// Tree Snapshots
292
296
298 bool operator==(const AppendOnlyTreeSnapshot& other) const = default;
299 friend std::ostream& operator<<(std::ostream& os, const AppendOnlyTreeSnapshot& obj)
300 {
301 os << "root: " << obj.root << ", nextAvailableLeafIndex: " << obj.nextAvailableLeafIndex;
302 return os;
303 }
304
306};
307
318
319struct TreeState {
321 uint32_t counter;
322
323 bool operator==(const TreeState& other) const = default;
324};
325
334
338
339 bool operator==(const SideEffectStates& other) const = default;
340};
341
342enum class DebugLogLevel {
343 SILENT = 0,
344 FATAL = 1,
345 ERROR = 2,
346 WARN = 3,
347 INFO = 4,
348 VERBOSE = 5,
349 DEBUG = 6,
350 TRACE = 7,
351 LAST = TRACE
352};
353
354inline bool is_valid_debug_log_level(uint8_t v)
355{
356 return v <= static_cast<uint8_t>(DebugLogLevel::LAST);
357}
358
360{
361 switch (lvl) {
363 return "silent";
365 return "fatal";
367 return "error";
369 return "warn";
371 return "info";
373 return "verbose";
375 return "debug";
377 return "trace";
378 }
379}
380
381struct DebugLog {
383 // Level is a string since on the TS side is a union type of strings
384 // We could make it a number but we'd need to/from validation and conversion on the TS side.
385 // Consider doing that if it becomes a performance problem.
386 std::string level;
387 std::string message;
388 std::vector<FF> fields;
389
390 bool operator==(const DebugLog& other) const = default;
392};
393
395 std::array<AztecAddress, MAX_PROTOCOL_CONTRACTS> derivedAddresses;
396
397 bool operator==(const ProtocolContracts& other) const = default;
398
400};
401
403{
404 return !address.is_zero() && static_cast<uint256_t>(address) <= MAX_PROTOCOL_CONTRACTS;
405}
406
408 const AztecAddress& canonical_address)
409{
410 assert(is_protocol_contract_address(canonical_address) && "Protocol contract canonical address out of bounds");
411 AztecAddress derived_address = protocol_contracts.derivedAddresses.at(static_cast<uint32_t>(canonical_address) - 1);
412 if (derived_address.is_zero()) {
413 return std::nullopt;
414 }
415 return derived_address;
416}
417
418} // namespace bb::avm2
#define PUBLIC_LOG_HEADER_LENGTH
#define MAX_PROTOCOL_CONTRACTS
group_elements::affine_element< Fq, Fr, Params > affine_element
Definition group.hpp:42
uint32_t PC
bool is_valid_debug_log_level(uint8_t v)
@ NR_NOTE_INSERTION
@ R_NULLIFIER_INSERTION
@ NR_L2_TO_L1_MESSAGE
@ R_L2_TO_L1_MESSAGE
@ NR_NULLIFIER_INSERTION
FF ContractClassId
uint32_t InternalCallId
std::optional< AztecAddress > get_derived_address(const ProtocolContracts &protocol_contracts, const AztecAddress &canonical_address)
bool is_protocol_contract_address(const AztecAddress &address)
std::string debug_log_level_to_string(DebugLogLevel lvl)
AvmFlavorSettings::FF FF
Definition field.hpp:10
size_t hash_as_tuple(const Ts &... ts)
Definition utils.hpp:22
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
unsigned __int128 uint128_t
Definition serialize.hpp:44
MSGPACK_FIELDS(root, nextAvailableLeafIndex)
bool operator==(const AppendOnlyTreeSnapshot &other) const =default
std::size_t hash() const noexcept
friend std::ostream & operator<<(std::ostream &os, const AppendOnlyTreeSnapshot &obj)
MSGPACK_FIELDS(noteHashes, nullifiers, l2ToL1Msgs, publicDataWrites)
bool operator==(const AvmAccumulatedDataArrayLengths &other) const =default
std::array< FF, MAX_NULLIFIERS_PER_TX > nullifiers
std::array< PublicDataWrite, MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX > publicDataWrites
std::array< ScopedL2ToL1Message, MAX_L2_TO_L1_MSGS_PER_TX > l2ToL1Msgs
std::array< FF, MAX_NOTE_HASHES_PER_TX > noteHashes
MSGPACK_FIELDS(noteHashes, nullifiers, l2ToL1Msgs, publicLogs, publicDataWrites)
bool operator==(const AvmAccumulatedData &other) const =default
std::vector< uint8_t > packed_bytecode
bool operator==(const ContractInstance &other) const =default
ContractClassId original_class_id
ContractClassId current_class_id
bool operator==(const DebugLog &other) const =default
MSGPACK_FIELDS(contractAddress, level, message, fields)
std::vector< FF > fields
AztecAddress contractAddress
bool operator==(const GasFees &other) const =default
MSGPACK_FIELDS(feePerDaGas, feePerL2Gas)
MSGPACK_FIELDS(l2Gas, daGas)
Gas operator+(const Gas &other) const
Gas operator-(const Gas &other) const
bool operator==(const Gas &other) const =default
MSGPACK_FIELDS(gasLimits, teardownGasLimits, maxFeesPerGas, maxPriorityFeesPerGas)
bool operator==(const GasSettings &other) const =default
MSGPACK_FIELDS(chainId, version, blockNumber, slotNumber, timestamp, coinbase, feeRecipient, gasFees)
bool operator==(const GlobalVariables &other) const =default
MSGPACK_FIELDS(recipient, content)
bool operator==(const L2ToL1Message &other) const =default
bool operator==(const PrivateToAvmAccumulatedDataArrayLengths &other) const =default
MSGPACK_FIELDS(noteHashes, nullifiers, l2ToL1Msgs)
MSGPACK_FIELDS(noteHashes, nullifiers, l2ToL1Msgs)
std::array< ScopedL2ToL1Message, MAX_L2_TO_L1_MSGS_PER_TX > l2ToL1Msgs
std::array< FF, MAX_NULLIFIERS_PER_TX > nullifiers
bool operator==(const PrivateToAvmAccumulatedData &other) const =default
std::array< FF, MAX_NOTE_HASHES_PER_TX > noteHashes
bool operator==(const ProtocolContracts &other) const =default
MSGPACK_FIELDS(derivedAddresses)
std::array< AztecAddress, MAX_PROTOCOL_CONTRACTS > derivedAddresses
MSGPACK_FIELDS(setupCalls, appLogicCalls, teardownCall)
bool operator==(const PublicCallRequestArrayLengths &other) const =default
bool operator==(const PublicCallRequest &other) const =default
MSGPACK_FIELDS(msgSender, contractAddress, isStaticCall, calldataHash)
bool operator==(const PublicDataWrite &other) const =default
MSGPACK_FIELDS(leafSlot, value)
AffinePoint nullifier_key
AffinePoint tagging_key
AffinePoint incoming_viewing_key
bool operator==(const PublicKeys &other) const =default
AffinePoint outgoing_viewing_key
std::vector< FF > to_fields() const
std::vector< FF > fields
MSGPACK_FIELDS(fields, contractAddress)
AztecAddress contractAddress
bool operator==(const PublicLog &other) const =default
std::array< FF, FLAT_PUBLIC_LOGS_PAYLOAD_LENGTH > payload
MSGPACK_FIELDS(length, payload)
bool operator==(const PublicLogs &other) const =default
void add_log(PublicLog log)
bool operator==(const ScopedL2ToL1Message &other) const =default
MSGPACK_FIELDS(message, contractAddress)
bool operator==(const SideEffectStates &other) const =default
bool operator==(const TreeSnapshots &other) const =default
MSGPACK_FIELDS(l1ToL2MessageTree, noteHashTree, nullifierTree, publicDataTree)
AppendOnlyTreeSnapshot noteHashTree
AppendOnlyTreeSnapshot nullifierTree
AppendOnlyTreeSnapshot l1ToL2MessageTree
AppendOnlyTreeSnapshot publicDataTree
bool operator==(const TreeState &other) const =default
AppendOnlyTreeSnapshot tree
bool operator==(const TreeStates &other) const =default