Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
bb::avm2::simulation::PublicDataTreeCheck Class Reference

#include <public_data_tree_check.hpp>

Inheritance diagram for bb::avm2::simulation::PublicDataTreeCheck:
bb::avm2::simulation::PublicDataTreeCheckInterface bb::avm2::simulation::CheckpointNotifiable

Public Member Functions

 PublicDataTreeCheck (Poseidon2Interface &poseidon2, MerkleCheckInterface &merkle_check, FieldGreaterThanInterface &field_gt, ExecutionIdGetterInterface &execution_id_manager, EventEmitterInterface< PublicDataTreeCheckEvent > &read_event_emitter)
 
void assert_read (const FF &slot, const AztecAddress &contract_address, const FF &value, const PublicDataTreeLeafPreimage &low_leaf_preimage, uint64_t low_leaf_index, std::span< const FF > sibling_path, const AppendOnlyTreeSnapshot &snapshot) override
 Assert that a public data tree read is valid.
 
AppendOnlyTreeSnapshot write (const FF &slot, const AztecAddress &contract_address, const FF &value, const PublicDataTreeLeafPreimage &low_leaf_preimage, uint64_t low_leaf_index, std::span< const FF > low_leaf_sibling_path, const AppendOnlyTreeSnapshot &prev_snapshot, std::span< const FF > insertion_sibling_path, bool is_protocol_write) override
 Write a value to the public data tree.
 
void on_checkpoint_created () override
 Emit a checkpoint-created event for discard reconstruction.
 
void on_checkpoint_committed () override
 Emit a checkpoint-committed event for discard reconstruction.
 
void on_checkpoint_reverted () override
 Emit a checkpoint-reverted event for discard reconstruction.
 
void generate_ff_gt_events_for_squashing (const std::vector< FF > &written_leaf_slots)
 Generates ff_gt events for squashing.
 
- Public Member Functions inherited from bb::avm2::simulation::PublicDataTreeCheckInterface
virtual ~PublicDataTreeCheckInterface ()=default
 
- Public Member Functions inherited from bb::avm2::simulation::CheckpointNotifiable
virtual ~CheckpointNotifiable ()=default
 

Private Member Functions

void validate_low_leaf_jumps_over_slot (const PublicDataTreeLeafPreimage &low_leaf_preimage, const FF &leaf_slot)
 Validate that the low leaf's slot range covers (jumps over) the given leaf slot.
 
FF compute_leaf_slot (const AztecAddress &contract_address, const FF &slot)
 Compute the siloed leaf slot from a contract address and storage slot.
 

Private Attributes

EventEmitterInterface< PublicDataTreeCheckEvent > & events
 
Poseidon2Interfaceposeidon2
 
MerkleCheckInterfacemerkle_check
 
FieldGreaterThanInterfacefield_gt
 
ExecutionIdGetterInterfaceexecution_id_manager
 

Detailed Description

Definition at line 21 of file public_data_tree_check.hpp.

Constructor & Destructor Documentation

◆ PublicDataTreeCheck()

bb::avm2::simulation::PublicDataTreeCheck::PublicDataTreeCheck ( Poseidon2Interface poseidon2,
MerkleCheckInterface merkle_check,
FieldGreaterThanInterface field_gt,
ExecutionIdGetterInterface execution_id_manager,
EventEmitterInterface< PublicDataTreeCheckEvent > &  read_event_emitter 
)
inline

Definition at line 23 of file public_data_tree_check.hpp.

Member Function Documentation

◆ assert_read()

void bb::avm2::simulation::PublicDataTreeCheck::assert_read ( const FF slot,
const AztecAddress contract_address,
const FF value,
const PublicDataTreeLeafPreimage low_leaf_preimage,
uint64_t  low_leaf_index,
std::span< const FF sibling_path,
const AppendOnlyTreeSnapshot snapshot 
)
overridevirtual

Assert that a public data tree read is valid.

Verifies a membership proof for the low leaf, then checks the value:

  • If the leaf exists (low_leaf.slot == leaf_slot), asserts that the stored value matches.
  • If the leaf does not exist, validates the low leaf range and asserts value is zero.
Parameters
slotThe storage slot being read.
contract_addressThe contract address to silo the slot with.
valueThe expected value at this slot.
low_leaf_preimageThe preimage of the low leaf in the indexed tree.
low_leaf_indexThe index of the low leaf in the tree.
sibling_pathThe Merkle sibling path for the low leaf.
snapshotThe tree snapshot (root and size) to verify against.
Exceptions
std::runtime_errorIf the leaf value does not match or the non-membership proof fails.

Implements bb::avm2::simulation::PublicDataTreeCheckInterface.

Definition at line 63 of file public_data_tree_check.cpp.

◆ compute_leaf_slot()

FF bb::avm2::simulation::PublicDataTreeCheck::compute_leaf_slot ( const AztecAddress contract_address,
const FF slot 
)
private

Compute the siloed leaf slot from a contract address and storage slot.

Parameters
contract_addressThe contract address to silo with.
slotThe storage slot.
Returns
The siloed leaf slot, computed as poseidon2(DOM_SEP__PUBLIC_LEAF_SLOT, contract_address, slot).

Definition at line 19 of file public_data_tree_check.cpp.

◆ generate_ff_gt_events_for_squashing()

void bb::avm2::simulation::PublicDataTreeCheck::generate_ff_gt_events_for_squashing ( const std::vector< FF > &  written_leaf_slots)

Generates ff_gt events for squashing.

Parameters
written_leaf_slotsThe leaf slots that were written in the tx (unique and nondiscarded).

Definition at line 234 of file public_data_tree_check.cpp.

◆ on_checkpoint_committed()

void bb::avm2::simulation::PublicDataTreeCheck::on_checkpoint_committed ( )
overridevirtual

Emit a checkpoint-committed event for discard reconstruction.

Implements bb::avm2::simulation::CheckpointNotifiable.

Definition at line 216 of file public_data_tree_check.cpp.

◆ on_checkpoint_created()

void bb::avm2::simulation::PublicDataTreeCheck::on_checkpoint_created ( )
overridevirtual

Emit a checkpoint-created event for discard reconstruction.

Implements bb::avm2::simulation::CheckpointNotifiable.

Definition at line 208 of file public_data_tree_check.cpp.

◆ on_checkpoint_reverted()

void bb::avm2::simulation::PublicDataTreeCheck::on_checkpoint_reverted ( )
overridevirtual

Emit a checkpoint-reverted event for discard reconstruction.

Implements bb::avm2::simulation::CheckpointNotifiable.

Definition at line 224 of file public_data_tree_check.cpp.

◆ validate_low_leaf_jumps_over_slot()

void bb::avm2::simulation::PublicDataTreeCheck::validate_low_leaf_jumps_over_slot ( const PublicDataTreeLeafPreimage low_leaf_preimage,
const FF leaf_slot 
)
private

Validate that the low leaf's slot range covers (jumps over) the given leaf slot.

Checks that low_leaf.slot < leaf_slot and (low_leaf.next_slot > leaf_slot or next_slot == 0 meaning infinity). This is used to prove non-membership of the leaf slot in the indexed tree.

Parameters
low_leaf_preimageThe preimage of the low leaf.
leaf_slotThe siloed leaf slot to validate against.
Exceptions
std::runtime_errorIf low leaf slot is >= leaf slot.
std::runtime_errorIf leaf slot is >= low leaf next slot (when next slot is nonzero).

Definition at line 35 of file public_data_tree_check.cpp.

◆ write()

AppendOnlyTreeSnapshot bb::avm2::simulation::PublicDataTreeCheck::write ( const FF slot,
const AztecAddress contract_address,
const FF value,
const PublicDataTreeLeafPreimage low_leaf_preimage,
uint64_t  low_leaf_index,
std::span< const FF low_leaf_sibling_path,
const AppendOnlyTreeSnapshot prev_snapshot,
std::span< const FF insertion_sibling_path,
bool  is_protocol_write 
)
overridevirtual

Write a value to the public data tree.

Updates the low leaf (value if slot exists, pointers if it doesn't) If the slot doesn't exist, also inserts a new leaf into the tree.

Parameters
slotThe storage slot being written.
contract_addressThe contract address to silo the slot with.
valueThe value to write.
low_leaf_preimageThe preimage of the low leaf in the indexed tree.
low_leaf_indexThe index of the low leaf in the tree.
low_leaf_sibling_pathThe Merkle sibling path for the low leaf.
prev_snapshotThe tree snapshot before the write.
insertion_sibling_pathThe Merkle sibling path for inserting a new leaf (used only if slot is new).
is_protocol_writeWhether this is a protocol-level write (e.g., fee payment).
Returns
The new tree snapshot after the write.
Exceptions
std::runtime_errorIf low leaf / merkle validation fails

Implements bb::avm2::simulation::PublicDataTreeCheckInterface.

Definition at line 121 of file public_data_tree_check.cpp.

Member Data Documentation

◆ events

EventEmitterInterface<PublicDataTreeCheckEvent>& bb::avm2::simulation::PublicDataTreeCheck::events
private

Definition at line 60 of file public_data_tree_check.hpp.

◆ execution_id_manager

ExecutionIdGetterInterface& bb::avm2::simulation::PublicDataTreeCheck::execution_id_manager
private

Definition at line 64 of file public_data_tree_check.hpp.

◆ field_gt

FieldGreaterThanInterface& bb::avm2::simulation::PublicDataTreeCheck::field_gt
private

Definition at line 63 of file public_data_tree_check.hpp.

◆ merkle_check

MerkleCheckInterface& bb::avm2::simulation::PublicDataTreeCheck::merkle_check
private

Definition at line 62 of file public_data_tree_check.hpp.

◆ poseidon2

Poseidon2Interface& bb::avm2::simulation::PublicDataTreeCheck::poseidon2
private

Definition at line 61 of file public_data_tree_check.hpp.


The documentation for this class was generated from the following files: