Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
avm_io.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <ostream>
5#include <vector>
6
7#include "barretenberg/common/streams.hpp" // Derives operator<< from MSGPACK_FIELDS.
11#include "barretenberg/world_state/world_state.hpp" // For MSGPACK_ADD_ENUM(MerkleTreeId)
12
17#include "msgpack/adaptor/define_decl.hpp"
18
19namespace bb::avm2 {
20
22// Avm Circuit Public Inputs
24
27 // Inputs
45 // Outputs
52
53 static PublicInputs from(const std::vector<uint8_t>& data);
54
55 // A vector per public inputs column
57
58 // Flatten public input columns as a single vector
59 static std::vector<FF> columns_to_flat(std::vector<std::vector<FF>> const& columns);
60
61 // From flattened public inputs columns to vector per-column
62 // Reverse direction as the above but needs to be templated as
63 // recursive verifier needs it with a circuit type.
64 template <typename FF_> static std::vector<std::vector<FF_>> flat_to_columns(const std::vector<FF_>& input)
65 {
67 throw std::invalid_argument(
68 "Flattened public inputs vector size does not match the expected combined length.");
69 }
70
72
73 for (size_t i = 0; i < AVM_NUM_PUBLIC_INPUT_COLUMNS; ++i) {
74 typename std::vector<FF_>::const_iterator start =
75 input.begin() +
76 static_cast<typename std::vector<FF_>::difference_type>(i * AVM_PUBLIC_INPUTS_COLUMNS_MAX_LENGTH);
77 typename std::vector<FF_>::const_iterator end =
78 input.begin() +
79 static_cast<typename std::vector<FF_>::difference_type>((i + 1) * AVM_PUBLIC_INPUTS_COLUMNS_MAX_LENGTH);
80 cols[i] = std::vector<FF_>(start, end);
81 }
82
83 return cols;
84 }
85
86 bool operator==(const PublicInputs& other) const = default;
87
109 reverted);
110};
111
113// Hints (contracts)
128
150
162
172
182
184// Hints (merkle db)
188 // params
190 uint64_t index;
191 // return
192 std::vector<FF> path;
193
194 bool operator==(const GetSiblingPathHint& other) const = default;
195
197};
198
212
213template <typename LeafPreimage_> struct GetLeafPreimageHint {
215 // params (tree id will be implicit)
216 uint64_t index;
217 // return
218 LeafPreimage_ leaf_preimage;
219
220 bool operator==(const GetLeafPreimageHint<LeafPreimage_>& other) const = default;
221
223};
224
237
253
254// Hint for MerkleTreeDB.appendLeaves.
255// Note: only supported for NOTE_HASH_TREE and L1_TO_L2_MESSAGE_TREE.
267
269 // key
271 // current checkpoint evolution
274
275 bool operator==(const CheckpointActionNoStateChangeHint& other) const = default;
276
278};
279
282
297
301
303// Hints (other)
305
314
316 // TODO: add as needed.
317 std::vector<FF> note_hashes;
318 std::vector<FF> nullifiers;
320
321 bool operator==(const AccumulatedData& other) const = default;
322
324};
325
326// We are currently using this structure as the input to TX simulation.
327// That's why I'm not calling it TxHint. We can reconsider if the inner types seem to dirty.
356
360 // Protocol Contracts
362 // Contracts.
370 // Merkle DB.
386
387 bool operator==(const ExecutionHints& other) const = default;
388
390 tx,
411};
412
414// AVM Inputs
419
420 static AvmProvingInputs from(const std::vector<uint8_t>& data);
421 bool operator==(const AvmProvingInputs& other) const = default;
422
424};
425
441
463
476
478// Tx Simulation Result
480
481enum class CoarseTransactionPhase : uint8_t {
482 SETUP,
483 APP_LOGIC,
484 TEARDOWN,
485};
486
487inline std::ostream& operator<<(std::ostream& os, const CoarseTransactionPhase& phase)
488{
489 switch (phase) {
491 return os << "SETUP";
493 return os << "APP_LOGIC";
495 return os << "TEARDOWN";
496 default:
497 return os << "UNKNOWN";
498 }
499}
500
501// Metadata about a given (enqueued or external) call.
503 uint32_t timestamp;
507 std::vector<FF> calldata;
510 std::vector<FF> output; // returndata or revertdata.
511
514 std::vector<PC> internal_call_stack_at_exit; // At return/revert time. Last one is exit PC.
516 uint32_t num_nested_calls; // This will be different from the size of the nested vector if we went past some limit.
517
518 bool operator==(const CallStackMetadata& other) const = default;
520 phase,
522 caller_pc,
523 calldata,
525 gas_limit,
526 output,
527 reverted,
528 nested,
532};
533
546
548 // Simulation.
552 // The following fields are only guaranteed to be present if the simulator is configured to collect them.
553 std::vector<CallStackMetadata> call_stack_metadata; // One per enqueued call. All phases.
555 // Proving request data.
558
559 bool operator==(const TxSimulationResult& other) const = default;
560
562};
563
564} // namespace bb::avm2
565
566MSGPACK_ADD_ENUM(bb::avm2::CoarseTransactionPhase)
#define AVM_PUBLIC_INPUTS_COLUMNS_COMBINED_LENGTH
#define AVM_NUM_PUBLIC_INPUT_COLUMNS
#define AVM_PUBLIC_INPUTS_COLUMNS_MAX_LENGTH
const std::vector< MemoryValue > data
uint32_t PC
std::ostream & operator<<(std::ostream &os, const CoarseTransactionPhase &phase)
Definition avm_io.hpp:487
AvmFlavorSettings::FF FF
Definition field.hpp:10
CoarseTransactionPhase
Definition avm_io.hpp:481
FF ContractClassId
FF FunctionSelector
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::vector< FF > nullifiers
Definition avm_io.hpp:318
std::vector< FF > note_hashes
Definition avm_io.hpp:317
MSGPACK_CAMEL_CASE_FIELDS(note_hashes, nullifiers, l2_to_l1_messages)
bool operator==(const AccumulatedData &other) const =default
std::vector< ScopedL2ToL1Message > l2_to_l1_messages
Definition avm_io.hpp:319
MSGPACK_CAMEL_CASE_FIELDS(hint_key, state_after, tree_id, leaves)
AppendOnlyTreeSnapshot hint_key
Definition avm_io.hpp:257
world_state::MerkleTreeId tree_id
Definition avm_io.hpp:260
std::vector< FF > leaves
Definition avm_io.hpp:261
bool operator==(const AppendLeavesHint &other) const =default
AppendOnlyTreeSnapshot state_after
Definition avm_io.hpp:258
bool operator==(const AvmFastSimulationInputs &other) const =default
world_state::WorldStateRevision ws_revision
Definition avm_io.hpp:465
ProtocolContracts protocol_contracts
Definition avm_io.hpp:469
static AvmFastSimulationInputs from(const std::vector< uint8_t > &data)
Definition avm_io.cpp:129
MSGPACK_CAMEL_CASE_FIELDS(ws_revision, config, tx, global_variables, protocol_contracts)
PublicSimulatorConfig config
Definition avm_io.hpp:466
static AvmProvingInputs from(const std::vector< uint8_t > &data)
Definition avm_io.cpp:122
PublicInputs public_inputs
Definition avm_io.hpp:417
MSGPACK_CAMEL_CASE_FIELDS(public_inputs, hints)
bool operator==(const AvmProvingInputs &other) const =default
bool operator==(const BytecodeCommitmentHint &other) const =default
MSGPACK_CAMEL_CASE_FIELDS(hint_key, class_id, commitment)
CoarseTransactionPhase phase
Definition avm_io.hpp:504
MSGPACK_CAMEL_CASE_FIELDS(timestamp, phase, contract_address, caller_pc, calldata, is_static_call, gas_limit, output, reverted, nested, internal_call_stack_at_exit, halting_message, num_nested_calls)
std::vector< PC > internal_call_stack_at_exit
Definition avm_io.hpp:514
std::optional< std::string > halting_message
Definition avm_io.hpp:515
std::vector< CallStackMetadata > nested
Definition avm_io.hpp:513
bool operator==(const CallStackMetadata &other) const =default
std::vector< FF > calldata
Definition avm_io.hpp:507
std::vector< FF > output
Definition avm_io.hpp:510
bool operator==(const CheckpointActionNoStateChangeHint &other) const =default
MSGPACK_CAMEL_CASE_FIELDS(action_counter, old_checkpoint_id, new_checkpoint_id)
MSGPACK_CAMEL_CASE_FIELDS(max_debug_log_memory_reads, max_calldata_size_in_fields, max_returndata_size_in_fields, max_call_stack_depth, max_call_stack_items)
bool operator==(const CollectionLimitsConfig &other) const =default
MSGPACK_CAMEL_CASE_FIELDS(hint_key, class_id, artifact_hash, private_functions_root, packed_bytecode)
std::vector< uint8_t > packed_bytecode
Definition avm_io.hpp:156
bool operator==(const ContractClassHint &other) const =default
ContractClassId original_contract_class_id
Definition avm_io.hpp:135
MSGPACK_CAMEL_CASE_FIELDS(hint_key, address, salt, deployer, current_contract_class_id, original_contract_class_id, initialization_hash, public_keys)
ContractClassId current_contract_class_id
Definition avm_io.hpp:134
bool operator==(const ContractInstanceHint &other) const =default
bool operator==(const DebugFunctionNameHint &other) const =default
MSGPACK_FIELDS(address, selector, name)
std::vector< SequentialInsertHint< crypto::merkle_tree::NullifierLeafValue > > sequential_insert_hints_nullifier_tree
Definition avm_io.hpp:381
TreeSnapshots starting_tree_roots
Definition avm_io.hpp:371
GlobalVariables global_variables
Definition avm_io.hpp:358
std::vector< GetSiblingPathHint > get_sibling_path_hints
Definition avm_io.hpp:372
std::vector< DebugFunctionNameHint > debug_function_names
Definition avm_io.hpp:366
std::vector< ContractDBCreateCheckpointHint > contract_db_create_checkpoint_hints
Definition avm_io.hpp:367
std::vector< ContractDBCommitCheckpointHint > contract_db_commit_checkpoint_hints
Definition avm_io.hpp:368
std::vector< CommitCheckpointHint > commit_checkpoint_hints
Definition avm_io.hpp:384
std::vector< SequentialInsertHint< crypto::merkle_tree::PublicDataLeafValue > > sequential_insert_hints_public_data_tree
Definition avm_io.hpp:380
std::vector< RevertCheckpointHint > revert_checkpoint_hints
Definition avm_io.hpp:385
std::vector< ContractDBRevertCheckpointHint > contract_db_revert_checkpoint_hints
Definition avm_io.hpp:369
ProtocolContracts protocol_contracts
Definition avm_io.hpp:361
std::vector< GetPreviousValueIndexHint > get_previous_value_index_hints
Definition avm_io.hpp:373
std::vector< GetLeafPreimageHint< crypto::merkle_tree::IndexedLeaf< crypto::merkle_tree::PublicDataLeafValue > > > get_leaf_preimage_hints_public_data_tree
Definition avm_io.hpp:375
std::vector< GetLeafPreimageHint< crypto::merkle_tree::IndexedLeaf< crypto::merkle_tree::NullifierLeafValue > > > get_leaf_preimage_hints_nullifier_tree
Definition avm_io.hpp:377
std::vector< CreateCheckpointHint > create_checkpoint_hints
Definition avm_io.hpp:383
std::vector< GetLeafValueHint > get_leaf_value_hints
Definition avm_io.hpp:378
std::vector< AppendLeavesHint > append_leaves_hints
Definition avm_io.hpp:382
std::vector< ContractInstanceHint > contract_instances
Definition avm_io.hpp:363
MSGPACK_CAMEL_CASE_FIELDS(global_variables, tx, protocol_contracts, contract_instances, contract_classes, bytecode_commitments, debug_function_names, contract_db_create_checkpoint_hints, contract_db_commit_checkpoint_hints, contract_db_revert_checkpoint_hints, starting_tree_roots, get_sibling_path_hints, get_previous_value_index_hints, get_leaf_preimage_hints_public_data_tree, get_leaf_preimage_hints_nullifier_tree, get_leaf_value_hints, sequential_insert_hints_public_data_tree, sequential_insert_hints_nullifier_tree, append_leaves_hints, create_checkpoint_hints, commit_checkpoint_hints, revert_checkpoint_hints)
bool operator==(const ExecutionHints &other) const =default
std::vector< ContractClassHint > contract_classes
Definition avm_io.hpp:364
std::vector< BytecodeCommitmentHint > bytecode_commitments
Definition avm_io.hpp:365
MSGPACK_CAMEL_CASE_FIELDS(hint_key, index, leaf_preimage)
bool operator==(const GetLeafPreimageHint< LeafPreimage_ > &other) const =default
AppendOnlyTreeSnapshot hint_key
Definition avm_io.hpp:214
AppendOnlyTreeSnapshot hint_key
Definition avm_io.hpp:226
MSGPACK_CAMEL_CASE_FIELDS(hint_key, tree_id, index, value)
bool operator==(const GetLeafValueHint &other) const =default
world_state::MerkleTreeId tree_id
Definition avm_io.hpp:228
world_state::MerkleTreeId tree_id
Definition avm_io.hpp:202
MSGPACK_CAMEL_CASE_FIELDS(hint_key, tree_id, value, index, already_present)
bool operator==(const GetPreviousValueIndexHint &other) const =default
AppendOnlyTreeSnapshot hint_key
Definition avm_io.hpp:200
AppendOnlyTreeSnapshot hint_key
Definition avm_io.hpp:187
world_state::MerkleTreeId tree_id
Definition avm_io.hpp:189
bool operator==(const GetSiblingPathHint &other) const =default
std::vector< FF > path
Definition avm_io.hpp:192
MSGPACK_CAMEL_CASE_FIELDS(hint_key, tree_id, index, path)
bool operator==(const PublicCallRequestWithCalldata &other) const =default
PublicCallRequest public_teardown_call_request
Definition avm_io.hpp:39
PrivateToAvmAccumulatedDataArrayLengths previous_non_revertible_accumulated_data_array_lengths
Definition avm_io.hpp:40
static std::vector< FF > columns_to_flat(std::vector< std::vector< FF > > const &columns)
Definition avm_io.cpp:289
TreeSnapshots end_tree_snapshots
Definition avm_io.hpp:46
PrivateToAvmAccumulatedData previous_non_revertible_accumulated_data
Definition avm_io.hpp:42
std::vector< std::vector< FF > > to_columns() const
Serialization to columns.
Definition avm_io.cpp:142
GasSettings gas_settings
Definition avm_io.hpp:32
GlobalVariables global_variables
Definition avm_io.hpp:28
static PublicInputs from(const std::vector< uint8_t > &data)
Msgpack deserialization.
Definition avm_io.cpp:115
GasFees effective_gas_fees
Definition avm_io.hpp:33
PublicCallRequestArrayLengths public_call_request_array_lengths
Definition avm_io.hpp:36
AztecAddress fee_payer
Definition avm_io.hpp:34
TreeSnapshots start_tree_snapshots
Definition avm_io.hpp:30
std::array< PublicCallRequest, MAX_ENQUEUED_CALLS_PER_TX > public_app_logic_call_requests
Definition avm_io.hpp:38
ProtocolContracts protocol_contracts
Definition avm_io.hpp:29
AvmAccumulatedDataArrayLengths accumulated_data_array_lengths
Definition avm_io.hpp:48
MSGPACK_CAMEL_CASE_FIELDS(global_variables, protocol_contracts, start_tree_snapshots, start_gas_used, gas_settings, effective_gas_fees, fee_payer, prover_id, public_call_request_array_lengths, public_setup_call_requests, public_app_logic_call_requests, public_teardown_call_request, previous_non_revertible_accumulated_data_array_lengths, previous_revertible_accumulated_data_array_lengths, previous_non_revertible_accumulated_data, previous_revertible_accumulated_data, end_tree_snapshots, end_gas_used, accumulated_data_array_lengths, accumulated_data, transaction_fee, reverted)
PrivateToAvmAccumulatedDataArrayLengths previous_revertible_accumulated_data_array_lengths
Definition avm_io.hpp:41
bool operator==(const PublicInputs &other) const =default
std::array< PublicCallRequest, MAX_ENQUEUED_CALLS_PER_TX > public_setup_call_requests
Definition avm_io.hpp:37
AvmAccumulatedData accumulated_data
Definition avm_io.hpp:49
static std::vector< std::vector< FF_ > > flat_to_columns(const std::vector< FF_ > &input)
Definition avm_io.hpp:64
PrivateToAvmAccumulatedData previous_revertible_accumulated_data
Definition avm_io.hpp:43
AffinePoint master_incoming_viewing_public_key
Definition avm_io.hpp:117
AffinePoint master_tagging_public_key
Definition avm_io.hpp:119
AffinePoint master_nullifier_public_key
Definition avm_io.hpp:116
bool operator==(const PublicKeysHint &other) const =default
MSGPACK_CAMEL_CASE_FIELDS(master_nullifier_public_key, master_incoming_viewing_public_key, master_outgoing_viewing_public_key, master_tagging_public_key)
AffinePoint master_outgoing_viewing_public_key
Definition avm_io.hpp:118
MSGPACK_CAMEL_CASE_FIELDS(prover_id, skip_fee_enforcement, collect_call_metadata, collect_hints, collect_public_inputs, collect_debug_logs, collect_statistics, collection_limits)
bool operator==(const PublicSimulatorConfig &other) const =default
CollectionLimitsConfig collection_limits
Definition avm_io.hpp:450
bool operator==(const PublicTxEffect &other) const =default
std::vector< FF > note_hashes
Definition avm_io.hpp:536
std::vector< PublicLog > public_logs
Definition avm_io.hpp:539
std::vector< FF > nullifiers
Definition avm_io.hpp:537
MSGPACK_CAMEL_CASE_FIELDS(transaction_fee, note_hashes, nullifiers, l2_to_l1_msgs, public_logs, public_data_writes)
std::vector< PublicDataWrite > public_data_writes
Definition avm_io.hpp:540
std::vector< ScopedL2ToL1Message > l2_to_l1_msgs
Definition avm_io.hpp:538
MSGPACK_CAMEL_CASE_FIELDS(action_counter, old_checkpoint_id, new_checkpoint_id, state_before, state_after)
bool operator==(const RevertCheckpointHint &other) const =default
crypto::merkle_tree::LeafUpdateWitnessData< Leaf > low_leaves_witness_data
Definition avm_io.hpp:244
world_state::MerkleTreeId tree_id
Definition avm_io.hpp:241
MSGPACK_CAMEL_CASE_FIELDS(hint_key, tree_id, leaf, low_leaves_witness_data, insertion_witness_data, state_after)
bool operator==(const SequentialInsertHint< Leaf > &other) const =default
AppendOnlyTreeSnapshot hint_key
Definition avm_io.hpp:239
AppendOnlyTreeSnapshot state_after
Definition avm_io.hpp:247
crypto::merkle_tree::LeafUpdateWitnessData< Leaf > insertion_witness_data
Definition avm_io.hpp:245
AztecAddress fee_payer
Definition avm_io.hpp:340
GasFees effective_gas_fees
Definition avm_io.hpp:331
Gas gas_used_by_private
Definition avm_io.hpp:339
ContractDeploymentData non_revertible_contract_deployment_data
Definition avm_io.hpp:332
std::string hash
Definition avm_io.hpp:329
std::vector< PublicCallRequestWithCalldata > setup_enqueued_calls
Definition avm_io.hpp:336
ContractDeploymentData revertible_contract_deployment_data
Definition avm_io.hpp:333
std::optional< PublicCallRequestWithCalldata > teardown_enqueued_call
Definition avm_io.hpp:338
bool operator==(const Tx &other) const =default
std::vector< PublicCallRequestWithCalldata > app_logic_enqueued_calls
Definition avm_io.hpp:337
MSGPACK_CAMEL_CASE_FIELDS(hash, gas_settings, effective_gas_fees, non_revertible_contract_deployment_data, revertible_contract_deployment_data, non_revertible_accumulated_data, revertible_accumulated_data, setup_enqueued_calls, app_logic_enqueued_calls, teardown_enqueued_call, gas_used_by_private, fee_payer)
AccumulatedData revertible_accumulated_data
Definition avm_io.hpp:335
AccumulatedData non_revertible_accumulated_data
Definition avm_io.hpp:334
GasSettings gas_settings
Definition avm_io.hpp:330
PublicTxEffect public_tx_effect
Definition avm_io.hpp:551
std::optional< std::vector< DebugLog > > logs
Definition avm_io.hpp:554
std::vector< CallStackMetadata > call_stack_metadata
Definition avm_io.hpp:553
std::optional< ExecutionHints > hints
Definition avm_io.hpp:557
MSGPACK_CAMEL_CASE_FIELDS(gas_used, revert_code, public_tx_effect, call_stack_metadata, logs, public_inputs, hints)
bool operator==(const TxSimulationResult &other) const =default
std::optional< PublicInputs > public_inputs
Definition avm_io.hpp:556