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.
13
18#include "msgpack/adaptor/define_decl.hpp"
19
20namespace bb::avm2 {
21
23// Avm Circuit Public Inputs
25
28 // Inputs
46 // Outputs
53
54 static PublicInputs from(const std::vector<uint8_t>& data);
55
56 // A vector per public inputs column
58
59 // Flatten public input columns as a single vector
60 static std::vector<FF> columns_to_flat(std::vector<std::vector<FF>> const& columns);
61
62 // From flattened public inputs columns to vector per-column
63 // Reverse direction as the above but needs to be templated as
64 // recursive verifier needs it with a circuit type.
65 template <typename FF_> static std::vector<std::vector<FF_>> flat_to_columns(const std::vector<FF_>& input)
66 {
68 throw std::invalid_argument(
69 "Flattened public inputs vector size does not match the expected combined length.");
70 }
71
73
74 for (size_t i = 0; i < AVM_NUM_PUBLIC_INPUT_COLUMNS; ++i) {
75 typename std::vector<FF_>::const_iterator start =
76 input.begin() +
77 static_cast<typename std::vector<FF_>::difference_type>(i * AVM_PUBLIC_INPUTS_COLUMNS_MAX_LENGTH);
78 typename std::vector<FF_>::const_iterator end =
79 input.begin() +
80 static_cast<typename std::vector<FF_>::difference_type>((i + 1) * AVM_PUBLIC_INPUTS_COLUMNS_MAX_LENGTH);
81 cols[i] = std::vector<FF_>(start, end);
82 }
83
84 return cols;
85 }
86
87 bool operator==(const PublicInputs& other) const = default;
88
110 reverted);
111};
112
114// Hints (contracts)
129
151
163
173
183
185// Hints (merkle db)
189 // params
191 uint64_t index;
192 // return
193 std::vector<FF> path;
194
195 bool operator==(const GetSiblingPathHint& other) const = default;
196
198};
199
213
214template <typename LeafPreimage_> struct GetLeafPreimageHint {
216 // params (tree id will be implicit)
217 uint64_t index;
218 // return
219 LeafPreimage_ leaf_preimage;
220
221 bool operator==(const GetLeafPreimageHint<LeafPreimage_>& other) const = default;
222
224};
225
238
254
255// Hint for MerkleTreeDB.appendLeaves.
256// Note: only supported for NOTE_HASH_TREE and L1_TO_L2_MESSAGE_TREE.
268
270 // key
272 // current checkpoint evolution
275
276 bool operator==(const CheckpointActionNoStateChangeHint& other) const = default;
277
279};
280
283
298
302
304// Hints (other)
306
315
317 // TODO: add as needed.
318 std::vector<FF> note_hashes;
319 std::vector<FF> nullifiers;
321
322 bool operator==(const AccumulatedData& other) const = default;
323
325};
326
327// We are currently using this structure as the input to TX simulation.
328// That's why I'm not calling it TxHint. We can reconsider if the inner types seem to dirty.
357
361 // Protocol Contracts
363 // Contracts.
371 // Merkle DB.
387
388 bool operator==(const ExecutionHints& other) const = default;
389
391 tx,
412};
413
415// AVM Inputs
420
421 static AvmProvingInputs from(const std::vector<uint8_t>& data);
422 bool operator==(const AvmProvingInputs& other) const = default;
423
425};
426
442
464
477
479// Tx Simulation Result
481
482enum class CoarseTransactionPhase : uint8_t {
483 SETUP,
484 APP_LOGIC,
485 TEARDOWN,
486};
487
488inline std::ostream& operator<<(std::ostream& os, const CoarseTransactionPhase& phase)
489{
490 switch (phase) {
492 return os << "SETUP";
494 return os << "APP_LOGIC";
496 return os << "TEARDOWN";
497 default:
498 return os << "UNKNOWN";
499 }
500}
501
502// Metadata about a given (enqueued or external) call.
504 uint32_t timestamp;
508 std::vector<FF> calldata;
511 std::vector<FF> output; // returndata or revertdata.
512
515 std::vector<PC> internal_call_stack_at_exit; // At return/revert time. Last one is exit PC.
517 uint32_t num_nested_calls; // This will be different from the size of the nested vector if we went past some limit.
518
519 bool operator==(const CallStackMetadata& other) const = default;
521 phase,
523 caller_pc,
524 calldata,
526 gas_limit,
527 output,
528 reverted,
529 nested,
533};
534
547
549 // Simulation.
553 // The following fields are only guaranteed to be present if the simulator is configured to collect them.
554 std::vector<CallStackMetadata> call_stack_metadata; // One per enqueued call. All phases.
556 // Proving request data.
559
560 bool operator==(const TxSimulationResult& other) const = default;
561
563};
564
565} // namespace bb::avm2
566
567MSGPACK_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:488
CoarseTransactionPhase
Definition avm_io.hpp:482
FF ContractClassId
FF FunctionSelector
AvmFlavorSettings::FF FF
Definition field.hpp:10
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::vector< FF > nullifiers
Definition avm_io.hpp:319
std::vector< FF > note_hashes
Definition avm_io.hpp:318
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:320
MSGPACK_CAMEL_CASE_FIELDS(hint_key, state_after, tree_id, leaves)
AppendOnlyTreeSnapshot hint_key
Definition avm_io.hpp:258
world_state::MerkleTreeId tree_id
Definition avm_io.hpp:261
std::vector< FF > leaves
Definition avm_io.hpp:262
bool operator==(const AppendLeavesHint &other) const =default
AppendOnlyTreeSnapshot state_after
Definition avm_io.hpp:259
bool operator==(const AvmFastSimulationInputs &other) const =default
world_state::WorldStateRevision ws_revision
Definition avm_io.hpp:466
ProtocolContracts protocol_contracts
Definition avm_io.hpp:470
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:467
static AvmProvingInputs from(const std::vector< uint8_t > &data)
Definition avm_io.cpp:122
PublicInputs public_inputs
Definition avm_io.hpp:418
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:505
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:515
std::optional< std::string > halting_message
Definition avm_io.hpp:516
std::vector< CallStackMetadata > nested
Definition avm_io.hpp:514
bool operator==(const CallStackMetadata &other) const =default
std::vector< FF > calldata
Definition avm_io.hpp:508
std::vector< FF > output
Definition avm_io.hpp:511
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:157
bool operator==(const ContractClassHint &other) const =default
ContractClassId original_contract_class_id
Definition avm_io.hpp:136
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:135
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:382
TreeSnapshots starting_tree_roots
Definition avm_io.hpp:372
GlobalVariables global_variables
Definition avm_io.hpp:359
std::vector< GetSiblingPathHint > get_sibling_path_hints
Definition avm_io.hpp:373
std::vector< DebugFunctionNameHint > debug_function_names
Definition avm_io.hpp:367
std::vector< ContractDBCreateCheckpointHint > contract_db_create_checkpoint_hints
Definition avm_io.hpp:368
std::vector< ContractDBCommitCheckpointHint > contract_db_commit_checkpoint_hints
Definition avm_io.hpp:369
std::vector< CommitCheckpointHint > commit_checkpoint_hints
Definition avm_io.hpp:385
std::vector< SequentialInsertHint< crypto::merkle_tree::PublicDataLeafValue > > sequential_insert_hints_public_data_tree
Definition avm_io.hpp:381
std::vector< RevertCheckpointHint > revert_checkpoint_hints
Definition avm_io.hpp:386
std::vector< ContractDBRevertCheckpointHint > contract_db_revert_checkpoint_hints
Definition avm_io.hpp:370
ProtocolContracts protocol_contracts
Definition avm_io.hpp:362
std::vector< GetPreviousValueIndexHint > get_previous_value_index_hints
Definition avm_io.hpp:374
std::vector< GetLeafPreimageHint< crypto::merkle_tree::IndexedLeaf< crypto::merkle_tree::PublicDataLeafValue > > > get_leaf_preimage_hints_public_data_tree
Definition avm_io.hpp:376
std::vector< GetLeafPreimageHint< crypto::merkle_tree::IndexedLeaf< crypto::merkle_tree::NullifierLeafValue > > > get_leaf_preimage_hints_nullifier_tree
Definition avm_io.hpp:378
std::vector< CreateCheckpointHint > create_checkpoint_hints
Definition avm_io.hpp:384
std::vector< GetLeafValueHint > get_leaf_value_hints
Definition avm_io.hpp:379
std::vector< AppendLeavesHint > append_leaves_hints
Definition avm_io.hpp:383
std::vector< ContractInstanceHint > contract_instances
Definition avm_io.hpp:364
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:365
std::vector< BytecodeCommitmentHint > bytecode_commitments
Definition avm_io.hpp:366
MSGPACK_CAMEL_CASE_FIELDS(hint_key, index, leaf_preimage)
bool operator==(const GetLeafPreimageHint< LeafPreimage_ > &other) const =default
AppendOnlyTreeSnapshot hint_key
Definition avm_io.hpp:215
AppendOnlyTreeSnapshot hint_key
Definition avm_io.hpp:227
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:229
world_state::MerkleTreeId tree_id
Definition avm_io.hpp:203
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:201
AppendOnlyTreeSnapshot hint_key
Definition avm_io.hpp:188
world_state::MerkleTreeId tree_id
Definition avm_io.hpp:190
bool operator==(const GetSiblingPathHint &other) const =default
std::vector< FF > path
Definition avm_io.hpp:193
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:40
PrivateToAvmAccumulatedDataArrayLengths previous_non_revertible_accumulated_data_array_lengths
Definition avm_io.hpp:41
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:47
PrivateToAvmAccumulatedData previous_non_revertible_accumulated_data
Definition avm_io.hpp:43
std::vector< std::vector< FF > > to_columns() const
Serialization to columns.
Definition avm_io.cpp:142
GasSettings gas_settings
Definition avm_io.hpp:33
GlobalVariables global_variables
Definition avm_io.hpp:29
static PublicInputs from(const std::vector< uint8_t > &data)
Msgpack deserialization.
Definition avm_io.cpp:115
GasFees effective_gas_fees
Definition avm_io.hpp:34
PublicCallRequestArrayLengths public_call_request_array_lengths
Definition avm_io.hpp:37
AztecAddress fee_payer
Definition avm_io.hpp:35
TreeSnapshots start_tree_snapshots
Definition avm_io.hpp:31
std::array< PublicCallRequest, MAX_ENQUEUED_CALLS_PER_TX > public_app_logic_call_requests
Definition avm_io.hpp:39
ProtocolContracts protocol_contracts
Definition avm_io.hpp:30
AvmAccumulatedDataArrayLengths accumulated_data_array_lengths
Definition avm_io.hpp:49
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:42
bool operator==(const PublicInputs &other) const =default
std::array< PublicCallRequest, MAX_ENQUEUED_CALLS_PER_TX > public_setup_call_requests
Definition avm_io.hpp:38
AvmAccumulatedData accumulated_data
Definition avm_io.hpp:50
static std::vector< std::vector< FF_ > > flat_to_columns(const std::vector< FF_ > &input)
Definition avm_io.hpp:65
PrivateToAvmAccumulatedData previous_revertible_accumulated_data
Definition avm_io.hpp:44
AffinePoint master_incoming_viewing_public_key
Definition avm_io.hpp:118
AffinePoint master_tagging_public_key
Definition avm_io.hpp:120
AffinePoint master_nullifier_public_key
Definition avm_io.hpp:117
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:119
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:451
bool operator==(const PublicTxEffect &other) const =default
std::vector< FF > note_hashes
Definition avm_io.hpp:537
std::vector< PublicLog > public_logs
Definition avm_io.hpp:540
std::vector< FF > nullifiers
Definition avm_io.hpp:538
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:541
std::vector< ScopedL2ToL1Message > l2_to_l1_msgs
Definition avm_io.hpp:539
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:245
world_state::MerkleTreeId tree_id
Definition avm_io.hpp:242
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:240
AppendOnlyTreeSnapshot state_after
Definition avm_io.hpp:248
crypto::merkle_tree::LeafUpdateWitnessData< Leaf > insertion_witness_data
Definition avm_io.hpp:246
AztecAddress fee_payer
Definition avm_io.hpp:341
GasFees effective_gas_fees
Definition avm_io.hpp:332
Gas gas_used_by_private
Definition avm_io.hpp:340
ContractDeploymentData non_revertible_contract_deployment_data
Definition avm_io.hpp:333
std::string hash
Definition avm_io.hpp:330
std::vector< PublicCallRequestWithCalldata > setup_enqueued_calls
Definition avm_io.hpp:337
ContractDeploymentData revertible_contract_deployment_data
Definition avm_io.hpp:334
std::optional< PublicCallRequestWithCalldata > teardown_enqueued_call
Definition avm_io.hpp:339
bool operator==(const Tx &other) const =default
std::vector< PublicCallRequestWithCalldata > app_logic_enqueued_calls
Definition avm_io.hpp:338
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:336
AccumulatedData non_revertible_accumulated_data
Definition avm_io.hpp:335
GasSettings gas_settings
Definition avm_io.hpp:331
PublicTxEffect public_tx_effect
Definition avm_io.hpp:552
std::optional< std::vector< DebugLog > > logs
Definition avm_io.hpp:555
std::vector< CallStackMetadata > call_stack_metadata
Definition avm_io.hpp:554
std::optional< ExecutionHints > hints
Definition avm_io.hpp:558
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:557