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
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)
116// Only ivpk_m is sent as a point; the others are field-element hashes.
129
153
165
175
185
187// Hints (merkle db)
191 // params
193 uint64_t index;
194 // return
195 std::vector<FF> path;
196
197 bool operator==(const GetSiblingPathHint& other) const = default;
198
200};
201
215
216template <typename LeafPreimage_> struct GetLeafPreimageHint {
218 // params (tree id will be implicit)
219 uint64_t index;
220 // return
221 LeafPreimage_ leaf_preimage;
222
223 bool operator==(const GetLeafPreimageHint<LeafPreimage_>& other) const = default;
224
226};
227
240
256
257// Hint for MerkleTreeDB.appendLeaves.
258// Note: only supported for NOTE_HASH_TREE and L1_TO_L2_MESSAGE_TREE.
270
272 // key
274 // current checkpoint evolution
277
278 bool operator==(const CheckpointActionNoStateChangeHint& other) const = default;
279
281};
282
285
300
304
306// Hints (other)
308
317
319 // TODO: add as needed.
320 std::vector<FF> note_hashes;
321 std::vector<FF> nullifiers;
323
324 bool operator==(const AccumulatedData& other) const = default;
325
327};
328
329// We are currently using this structure as the input to TX simulation.
330// That's why I'm not calling it TxHint. We can reconsider if the inner types seem to dirty.
359
363 // Protocol Contracts
365 // Contracts.
373 // Merkle DB.
389
390 bool operator==(const ExecutionHints& other) const = default;
391
393 tx,
414};
415
417// AVM Inputs
422
423 static AvmProvingInputs from(const std::vector<uint8_t>& data);
424 bool operator==(const AvmProvingInputs& other) const = default;
425
427};
428
444
466
479
481// Tx Simulation Result
483
484enum class CoarseTransactionPhase : uint8_t {
485 SETUP,
486 APP_LOGIC,
487 TEARDOWN,
488};
489
490inline std::ostream& operator<<(std::ostream& os, const CoarseTransactionPhase& phase)
491{
492 switch (phase) {
494 return os << "SETUP";
496 return os << "APP_LOGIC";
498 return os << "TEARDOWN";
499 default:
500 return os << "UNKNOWN";
501 }
502}
503
504// Metadata about a given (enqueued or external) call.
506 uint32_t timestamp;
510 std::vector<FF> calldata;
513 std::vector<FF> output; // returndata or revertdata.
514
517 std::vector<PC> internal_call_stack_at_exit; // At return/revert time. Last one is exit PC.
519 uint32_t num_nested_calls; // This will be different from the size of the nested vector if we went past some limit.
520
521 bool operator==(const CallStackMetadata& other) const = default;
523 phase,
525 caller_pc,
526 calldata,
528 gas_limit,
529 output,
530 reverted,
531 nested,
535};
536
549
551 // Simulation.
555 // The following fields are only guaranteed to be present if the simulator is configured to collect them.
556 std::vector<CallStackMetadata> call_stack_metadata; // One per enqueued call. All phases.
558 // Proving request data.
561
562 bool operator==(const TxSimulationResult& other) const = default;
563
565};
566
567} // namespace bb::avm2
568
569MSGPACK_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
uint32_t PC
std::ostream & operator<<(std::ostream &os, const CoarseTransactionPhase &phase)
Definition avm_io.hpp:490
AvmFlavorSettings::FF FF
Definition field.hpp:10
CoarseTransactionPhase
Definition avm_io.hpp:484
FF ContractClassId
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:321
std::vector< FF > note_hashes
Definition avm_io.hpp:320
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:322
MSGPACK_CAMEL_CASE_FIELDS(hint_key, state_after, tree_id, leaves)
AppendOnlyTreeSnapshot hint_key
Definition avm_io.hpp:260
world_state::MerkleTreeId tree_id
Definition avm_io.hpp:263
std::vector< FF > leaves
Definition avm_io.hpp:264
bool operator==(const AppendLeavesHint &other) const =default
AppendOnlyTreeSnapshot state_after
Definition avm_io.hpp:261
bool operator==(const AvmFastSimulationInputs &other) const =default
world_state::WorldStateRevision ws_revision
Definition avm_io.hpp:468
ProtocolContracts protocol_contracts
Definition avm_io.hpp:472
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:469
static AvmProvingInputs from(const std::vector< uint8_t > &data)
Definition avm_io.cpp:122
PublicInputs public_inputs
Definition avm_io.hpp:420
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:507
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:517
std::optional< std::string > halting_message
Definition avm_io.hpp:518
std::vector< CallStackMetadata > nested
Definition avm_io.hpp:516
bool operator==(const CallStackMetadata &other) const =default
std::vector< FF > calldata
Definition avm_io.hpp:510
std::vector< FF > output
Definition avm_io.hpp:513
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:159
bool operator==(const ContractClassHint &other) const =default
ContractClassId original_contract_class_id
Definition avm_io.hpp:136
ContractClassId current_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, 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:384
TreeSnapshots starting_tree_roots
Definition avm_io.hpp:374
GlobalVariables global_variables
Definition avm_io.hpp:361
std::vector< GetSiblingPathHint > get_sibling_path_hints
Definition avm_io.hpp:375
std::vector< DebugFunctionNameHint > debug_function_names
Definition avm_io.hpp:369
std::vector< ContractDBCreateCheckpointHint > contract_db_create_checkpoint_hints
Definition avm_io.hpp:370
std::vector< ContractDBCommitCheckpointHint > contract_db_commit_checkpoint_hints
Definition avm_io.hpp:371
std::vector< CommitCheckpointHint > commit_checkpoint_hints
Definition avm_io.hpp:387
std::vector< SequentialInsertHint< crypto::merkle_tree::PublicDataLeafValue > > sequential_insert_hints_public_data_tree
Definition avm_io.hpp:383
std::vector< RevertCheckpointHint > revert_checkpoint_hints
Definition avm_io.hpp:388
std::vector< ContractDBRevertCheckpointHint > contract_db_revert_checkpoint_hints
Definition avm_io.hpp:372
ProtocolContracts protocol_contracts
Definition avm_io.hpp:364
std::vector< GetPreviousValueIndexHint > get_previous_value_index_hints
Definition avm_io.hpp:376
std::vector< GetLeafPreimageHint< crypto::merkle_tree::IndexedLeaf< crypto::merkle_tree::PublicDataLeafValue > > > get_leaf_preimage_hints_public_data_tree
Definition avm_io.hpp:378
std::vector< GetLeafPreimageHint< crypto::merkle_tree::IndexedLeaf< crypto::merkle_tree::NullifierLeafValue > > > get_leaf_preimage_hints_nullifier_tree
Definition avm_io.hpp:380
std::vector< CreateCheckpointHint > create_checkpoint_hints
Definition avm_io.hpp:386
std::vector< GetLeafValueHint > get_leaf_value_hints
Definition avm_io.hpp:381
std::vector< AppendLeavesHint > append_leaves_hints
Definition avm_io.hpp:385
std::vector< ContractInstanceHint > contract_instances
Definition avm_io.hpp:366
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:367
std::vector< BytecodeCommitmentHint > bytecode_commitments
Definition avm_io.hpp:368
MSGPACK_CAMEL_CASE_FIELDS(hint_key, index, leaf_preimage)
bool operator==(const GetLeafPreimageHint< LeafPreimage_ > &other) const =default
AppendOnlyTreeSnapshot hint_key
Definition avm_io.hpp:217
AppendOnlyTreeSnapshot hint_key
Definition avm_io.hpp:229
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:231
world_state::MerkleTreeId tree_id
Definition avm_io.hpp:205
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:203
AppendOnlyTreeSnapshot hint_key
Definition avm_io.hpp:190
world_state::MerkleTreeId tree_id
Definition avm_io.hpp:192
bool operator==(const GetSiblingPathHint &other) const =default
std::vector< FF > path
Definition avm_io.hpp:195
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
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:453
bool operator==(const PublicTxEffect &other) const =default
std::vector< FF > note_hashes
Definition avm_io.hpp:539
std::vector< PublicLog > public_logs
Definition avm_io.hpp:542
std::vector< FF > nullifiers
Definition avm_io.hpp:540
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:543
std::vector< ScopedL2ToL1Message > l2_to_l1_msgs
Definition avm_io.hpp:541
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:247
world_state::MerkleTreeId tree_id
Definition avm_io.hpp:244
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:242
AppendOnlyTreeSnapshot state_after
Definition avm_io.hpp:250
crypto::merkle_tree::LeafUpdateWitnessData< Leaf > insertion_witness_data
Definition avm_io.hpp:248
AztecAddress fee_payer
Definition avm_io.hpp:343
GasFees effective_gas_fees
Definition avm_io.hpp:334
Gas gas_used_by_private
Definition avm_io.hpp:342
ContractDeploymentData non_revertible_contract_deployment_data
Definition avm_io.hpp:335
std::string hash
Definition avm_io.hpp:332
std::vector< PublicCallRequestWithCalldata > setup_enqueued_calls
Definition avm_io.hpp:339
ContractDeploymentData revertible_contract_deployment_data
Definition avm_io.hpp:336
std::optional< PublicCallRequestWithCalldata > teardown_enqueued_call
Definition avm_io.hpp:341
bool operator==(const Tx &other) const =default
std::vector< PublicCallRequestWithCalldata > app_logic_enqueued_calls
Definition avm_io.hpp:340
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:338
AccumulatedData non_revertible_accumulated_data
Definition avm_io.hpp:337
GasSettings gas_settings
Definition avm_io.hpp:333
PublicTxEffect public_tx_effect
Definition avm_io.hpp:554
std::optional< std::vector< DebugLog > > logs
Definition avm_io.hpp:557
std::vector< CallStackMetadata > call_stack_metadata
Definition avm_io.hpp:556
std::optional< ExecutionHints > hints
Definition avm_io.hpp:560
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:559