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 SERIALIZATION_FIELDS.
12#include "barretenberg/world_state/world_state.hpp" // For MSGPACK_ADD_ENUM(MerkleTreeId)
13
14#include "barretenberg/aztec/aztec_constants.hpp"
19#include "msgpack/adaptor/define_decl.hpp"
20
21namespace bb::avm2 {
22
24// Avm Circuit Public Inputs
26
29 // Inputs
47 // Outputs
54
55 static PublicInputs from(const std::vector<uint8_t>& data);
56
57 // A vector per public inputs column
59
60 // Flatten public input columns as a single vector
61 static std::vector<FF> columns_to_flat(std::vector<std::vector<FF>> const& columns);
62
63 // From flattened public inputs columns to vector per-column
64 // Reverse direction as the above but needs to be templated as
65 // recursive verifier needs it with a circuit type.
66 template <typename FF_> static std::vector<std::vector<FF_>> flat_to_columns(const std::vector<FF_>& input)
67 {
68 if (input.size() != AVM_PUBLIC_INPUTS_COLUMNS_COMBINED_LENGTH) {
69 throw std::invalid_argument(
70 "Flattened public inputs vector size does not match the expected combined length.");
71 }
72
73 std::vector<std::vector<FF_>> cols(AVM_NUM_PUBLIC_INPUT_COLUMNS);
74
75 // Columns are concatenated back-to-back with per-column lengths (not a uniform stride).
76 size_t offset = 0;
77 for (size_t i = 0; i < AVM_NUM_PUBLIC_INPUT_COLUMNS; ++i) {
78 const size_t col_length = AVM_PUBLIC_INPUTS_COLUMN_LENGTHS[i];
79 auto start = input.begin() + static_cast<typename std::vector<FF_>::difference_type>(offset);
80 auto end = start + static_cast<typename std::vector<FF_>::difference_type>(col_length);
81 cols[i] = std::vector<FF_>(start, end);
82 offset += col_length;
83 }
84
85 return cols;
86 }
87
88 bool operator==(const PublicInputs& other) const = default;
89
111 reverted);
112};
113
115// Hints (contracts)
117// Only ivpk_m is sent as a point; the others are field-element hashes.
130
154
166
176
186
188// Hints (merkle db)
192 // params
194 uint64_t index;
195 // return
196 std::vector<FF> path;
197
198 bool operator==(const GetSiblingPathHint& other) const = default;
199
201};
202
216
217template <typename LeafPreimage_> struct GetLeafPreimageHint {
219 // params (tree id will be implicit)
220 uint64_t index;
221 // return
222 LeafPreimage_ leaf_preimage;
223
224 bool operator==(const GetLeafPreimageHint<LeafPreimage_>& other) const = default;
225
227};
228
241
257
258// Hint for MerkleTreeDB.appendLeaves.
259// Note: only supported for NOTE_HASH_TREE and L1_TO_L2_MESSAGE_TREE.
271
273 // key
275 // current checkpoint evolution
278
279 bool operator==(const CheckpointActionNoStateChangeHint& other) const = default;
280
282};
283
286
301
305
307// Hints (other)
309
318
320 // TODO: add as needed.
321 std::vector<FF> note_hashes;
322 std::vector<FF> nullifiers;
324
325 bool operator==(const AccumulatedData& other) const = default;
326
328};
329
330// We are currently using this structure as the input to TX simulation.
331// That's why I'm not calling it TxHint. We can reconsider if the inner types seem to dirty.
360
364 // Protocol Contracts
366 // Contracts.
374 // Merkle DB.
390
391 bool operator==(const ExecutionHints& other) const = default;
392
394 tx,
415};
416
418// AVM Inputs
423
424 static AvmProvingInputs from(const std::vector<uint8_t>& data);
425 bool operator==(const AvmProvingInputs& other) const = default;
426
428};
429
445
467
480
482// Tx Simulation Result
484
485enum class CoarseTransactionPhase : uint8_t {
486 SETUP,
487 APP_LOGIC,
488 TEARDOWN,
489};
490
491inline std::ostream& operator<<(std::ostream& os, const CoarseTransactionPhase& phase)
492{
493 switch (phase) {
495 return os << "SETUP";
497 return os << "APP_LOGIC";
499 return os << "TEARDOWN";
500 default:
501 return os << "UNKNOWN";
502 }
503}
504
505// Metadata about a given (enqueued or external) call.
507 uint32_t timestamp;
511 std::vector<FF> calldata;
514 std::vector<FF> output; // returndata or revertdata.
515
518 std::vector<PC> internal_call_stack_at_exit; // At return/revert time. Last one is exit PC.
520 uint32_t num_nested_calls; // This will be different from the size of the nested vector if we went past some limit.
521
522 bool operator==(const CallStackMetadata& other) const = default;
524 phase,
526 caller_pc,
527 calldata,
529 gas_limit,
530 output,
531 reverted,
532 nested,
536};
537
550
552 // Simulation.
556 // The following fields are only guaranteed to be present if the simulator is configured to collect them.
557 std::vector<CallStackMetadata> call_stack_metadata; // One per enqueued call. All phases.
559 // Proving request data.
562
563 bool operator==(const TxSimulationResult& other) const = default;
564
566};
567
568} // namespace bb::avm2
569
570MSGPACK_ADD_ENUM(bb::avm2::CoarseTransactionPhase)
ssize_t offset
Definition engine.cpp:62
uint32_t PC
std::ostream & operator<<(std::ostream &os, const CoarseTransactionPhase &phase)
Definition avm_io.hpp:491
AvmFlavorSettings::FF FF
Definition field.hpp:10
CoarseTransactionPhase
Definition avm_io.hpp:485
FF ContractClassId
constexpr std::array< std::size_t, AVM_NUM_PUBLIC_INPUT_COLUMNS > AVM_PUBLIC_INPUTS_COLUMN_LENGTHS
Definition constants.hpp:19
FF FunctionSelector
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::byte * data
std::vector< FF > nullifiers
Definition avm_io.hpp:322
std::vector< FF > note_hashes
Definition avm_io.hpp:321
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:323
MSGPACK_CAMEL_CASE_FIELDS(hint_key, state_after, tree_id, leaves)
AppendOnlyTreeSnapshot hint_key
Definition avm_io.hpp:261
world_state::MerkleTreeId tree_id
Definition avm_io.hpp:264
std::vector< FF > leaves
Definition avm_io.hpp:265
bool operator==(const AppendLeavesHint &other) const =default
AppendOnlyTreeSnapshot state_after
Definition avm_io.hpp:262
bool operator==(const AvmFastSimulationInputs &other) const =default
world_state::WorldStateRevision ws_revision
Definition avm_io.hpp:469
ProtocolContracts protocol_contracts
Definition avm_io.hpp:473
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:470
static AvmProvingInputs from(const std::vector< uint8_t > &data)
Definition avm_io.cpp:122
PublicInputs public_inputs
Definition avm_io.hpp:421
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:508
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:518
std::optional< std::string > halting_message
Definition avm_io.hpp:519
std::vector< CallStackMetadata > nested
Definition avm_io.hpp:517
bool operator==(const CallStackMetadata &other) const =default
std::vector< FF > calldata
Definition avm_io.hpp:511
std::vector< FF > output
Definition avm_io.hpp:514
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:160
bool operator==(const ContractClassHint &other) const =default
ContractClassId original_contract_class_id
Definition avm_io.hpp:137
ContractClassId current_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, immutables_hash, public_keys)
bool operator==(const ContractInstanceHint &other) const =default
bool operator==(const DebugFunctionNameHint &other) const =default
SERIALIZATION_FIELDS(address, selector, name)
std::vector< SequentialInsertHint< crypto::merkle_tree::NullifierLeafValue > > sequential_insert_hints_nullifier_tree
Definition avm_io.hpp:385
TreeSnapshots starting_tree_roots
Definition avm_io.hpp:375
GlobalVariables global_variables
Definition avm_io.hpp:362
std::vector< GetSiblingPathHint > get_sibling_path_hints
Definition avm_io.hpp:376
std::vector< DebugFunctionNameHint > debug_function_names
Definition avm_io.hpp:370
std::vector< ContractDBCreateCheckpointHint > contract_db_create_checkpoint_hints
Definition avm_io.hpp:371
std::vector< ContractDBCommitCheckpointHint > contract_db_commit_checkpoint_hints
Definition avm_io.hpp:372
std::vector< CommitCheckpointHint > commit_checkpoint_hints
Definition avm_io.hpp:388
std::vector< SequentialInsertHint< crypto::merkle_tree::PublicDataLeafValue > > sequential_insert_hints_public_data_tree
Definition avm_io.hpp:384
std::vector< RevertCheckpointHint > revert_checkpoint_hints
Definition avm_io.hpp:389
std::vector< ContractDBRevertCheckpointHint > contract_db_revert_checkpoint_hints
Definition avm_io.hpp:373
ProtocolContracts protocol_contracts
Definition avm_io.hpp:365
std::vector< GetPreviousValueIndexHint > get_previous_value_index_hints
Definition avm_io.hpp:377
std::vector< GetLeafPreimageHint< crypto::merkle_tree::IndexedLeaf< crypto::merkle_tree::PublicDataLeafValue > > > get_leaf_preimage_hints_public_data_tree
Definition avm_io.hpp:379
std::vector< GetLeafPreimageHint< crypto::merkle_tree::IndexedLeaf< crypto::merkle_tree::NullifierLeafValue > > > get_leaf_preimage_hints_nullifier_tree
Definition avm_io.hpp:381
std::vector< CreateCheckpointHint > create_checkpoint_hints
Definition avm_io.hpp:387
std::vector< GetLeafValueHint > get_leaf_value_hints
Definition avm_io.hpp:382
std::vector< AppendLeavesHint > append_leaves_hints
Definition avm_io.hpp:386
std::vector< ContractInstanceHint > contract_instances
Definition avm_io.hpp:367
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:368
std::vector< BytecodeCommitmentHint > bytecode_commitments
Definition avm_io.hpp:369
MSGPACK_CAMEL_CASE_FIELDS(hint_key, index, leaf_preimage)
bool operator==(const GetLeafPreimageHint< LeafPreimage_ > &other) const =default
AppendOnlyTreeSnapshot hint_key
Definition avm_io.hpp:218
AppendOnlyTreeSnapshot hint_key
Definition avm_io.hpp:230
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:232
world_state::MerkleTreeId tree_id
Definition avm_io.hpp:206
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:204
AppendOnlyTreeSnapshot hint_key
Definition avm_io.hpp:191
world_state::MerkleTreeId tree_id
Definition avm_io.hpp:193
bool operator==(const GetSiblingPathHint &other) const =default
std::vector< FF > path
Definition avm_io.hpp:196
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:41
PrivateToAvmAccumulatedDataArrayLengths previous_non_revertible_accumulated_data_array_lengths
Definition avm_io.hpp:42
static std::vector< FF > columns_to_flat(std::vector< std::vector< FF > > const &columns)
Definition avm_io.cpp:292
TreeSnapshots end_tree_snapshots
Definition avm_io.hpp:48
PrivateToAvmAccumulatedData previous_non_revertible_accumulated_data
Definition avm_io.hpp:44
std::vector< std::vector< FF > > to_columns() const
Serialization to columns.
Definition avm_io.cpp:142
GasSettings gas_settings
Definition avm_io.hpp:34
GlobalVariables global_variables
Definition avm_io.hpp:30
static PublicInputs from(const std::vector< uint8_t > &data)
Msgpack deserialization.
Definition avm_io.cpp:115
GasFees effective_gas_fees
Definition avm_io.hpp:35
PublicCallRequestArrayLengths public_call_request_array_lengths
Definition avm_io.hpp:38
AztecAddress fee_payer
Definition avm_io.hpp:36
TreeSnapshots start_tree_snapshots
Definition avm_io.hpp:32
std::array< PublicCallRequest, MAX_ENQUEUED_CALLS_PER_TX > public_app_logic_call_requests
Definition avm_io.hpp:40
ProtocolContracts protocol_contracts
Definition avm_io.hpp:31
AvmAccumulatedDataArrayLengths accumulated_data_array_lengths
Definition avm_io.hpp:50
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:43
bool operator==(const PublicInputs &other) const =default
std::array< PublicCallRequest, MAX_ENQUEUED_CALLS_PER_TX > public_setup_call_requests
Definition avm_io.hpp:39
AvmAccumulatedData accumulated_data
Definition avm_io.hpp:51
static std::vector< std::vector< FF_ > > flat_to_columns(const std::vector< FF_ > &input)
Definition avm_io.hpp:66
PrivateToAvmAccumulatedData previous_revertible_accumulated_data
Definition avm_io.hpp:45
bool operator==(const PublicKeysHint &other) const =default
MSGPACK_CAMEL_CASE_FIELDS(npk_m_hash, ivpk_m, ovpk_m_hash, tpk_m_hash, mspk_m_hash, fbpk_m_hash)
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:454
bool operator==(const PublicTxEffect &other) const =default
std::vector< FF > note_hashes
Definition avm_io.hpp:540
std::vector< PublicLog > public_logs
Definition avm_io.hpp:543
std::vector< FF > nullifiers
Definition avm_io.hpp:541
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:544
std::vector< ScopedL2ToL1Message > l2_to_l1_msgs
Definition avm_io.hpp:542
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:248
world_state::MerkleTreeId tree_id
Definition avm_io.hpp:245
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:243
AppendOnlyTreeSnapshot state_after
Definition avm_io.hpp:251
crypto::merkle_tree::LeafUpdateWitnessData< Leaf > insertion_witness_data
Definition avm_io.hpp:249
AztecAddress fee_payer
Definition avm_io.hpp:344
GasFees effective_gas_fees
Definition avm_io.hpp:335
Gas gas_used_by_private
Definition avm_io.hpp:343
ContractDeploymentData non_revertible_contract_deployment_data
Definition avm_io.hpp:336
std::string hash
Definition avm_io.hpp:333
std::vector< PublicCallRequestWithCalldata > setup_enqueued_calls
Definition avm_io.hpp:340
ContractDeploymentData revertible_contract_deployment_data
Definition avm_io.hpp:337
std::optional< PublicCallRequestWithCalldata > teardown_enqueued_call
Definition avm_io.hpp:342
bool operator==(const Tx &other) const =default
std::vector< PublicCallRequestWithCalldata > app_logic_enqueued_calls
Definition avm_io.hpp:341
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:339
AccumulatedData non_revertible_accumulated_data
Definition avm_io.hpp:338
GasSettings gas_settings
Definition avm_io.hpp:334
PublicTxEffect public_tx_effect
Definition avm_io.hpp:555
std::optional< std::vector< DebugLog > > logs
Definition avm_io.hpp:558
std::vector< CallStackMetadata > call_stack_metadata
Definition avm_io.hpp:557
std::optional< ExecutionHints > hints
Definition avm_io.hpp:561
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:560