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

#include <note_hash_tree_check.hpp>

Inheritance diagram for bb::avm2::simulation::NoteHashTreeCheck:
bb::avm2::simulation::NoteHashTreeCheckInterface bb::avm2::simulation::CheckpointNotifiable

Public Member Functions

 NoteHashTreeCheck (const FF &first_nullifier, Poseidon2Interface &poseidon2, MerkleCheckInterface &merkle_check, EventEmitterInterface< NoteHashTreeCheckEvent > &event_emitter)
 
FF get_first_nullifier () const override
 
bool note_hash_exists (const FF &unique_note_hash, const FF &leaf_value, uint64_t leaf_index, std::span< const FF > sibling_path, const AppendOnlyTreeSnapshot &snapshot) override
 Checks whether a note hash exists in the note hash tree via Merkle membership proof.
 
AppendOnlyTreeSnapshot append_note_hash (const FF &note_hash, AztecAddress contract_address, uint64_t note_hash_counter, std::span< const FF > sibling_path, const AppendOnlyTreeSnapshot &prev_snapshot) override
 Appends a raw (inner) note hash to the tree after siloing and making it unique.
 
AppendOnlyTreeSnapshot append_siloed_note_hash (const FF &siloed_note_hash, uint64_t note_hash_counter, std::span< const FF > sibling_path, const AppendOnlyTreeSnapshot &prev_snapshot) override
 Appends a pre-siloed note hash to the tree after making it unique.
 
AppendOnlyTreeSnapshot append_unique_note_hash (const FF &unique_note_hash, uint64_t note_hash_counter, std::span< const FF > sibling_path, const AppendOnlyTreeSnapshot &prev_snapshot) override
 Appends a pre-computed unique note hash directly to the tree.
 
void on_checkpoint_created () override
 Emits a checkpoint creation event for the note hash tree.
 
void on_checkpoint_committed () override
 Emits a checkpoint commit event, finalizing pending note hash tree changes.
 
void on_checkpoint_reverted () override
 Emits a checkpoint revert event, rolling back pending note hash tree changes.
 
- Public Member Functions inherited from bb::avm2::simulation::NoteHashTreeCheckInterface
virtual ~NoteHashTreeCheckInterface ()=default
 
- Public Member Functions inherited from bb::avm2::simulation::CheckpointNotifiable
virtual ~CheckpointNotifiable ()=default
 

Private Member Functions

FF make_siloed (AztecAddress contract_address, const FF &note_hash) const
 Computes the siloed note hash by hashing the contract address with the note hash.
 
FF make_nonce (uint64_t note_hash_counter) const
 Derives a nonce for a note hash from the transaction's first nullifier and the note hash counter.
 
FF make_unique (const FF &siloed_note_hash, const FF &nonce) const
 Computes a unique note hash by combining a siloed note hash with its nonce.
 
AppendOnlyTreeSnapshot append_note_hash_internal (FF note_hash, std::optional< AztecAddress > contract_address, bool should_make_unique, uint64_t note_hash_counter, std::span< const FF > sibling_path, const AppendOnlyTreeSnapshot &prev_snapshot)
 Internal implementation for all note hash append variants.
 

Private Attributes

FF first_nullifier
 
EventEmitterInterface< NoteHashTreeCheckEvent > & events
 
Poseidon2Interfaceposeidon2
 
MerkleCheckInterfacemerkle_check
 

Detailed Description

Definition at line 18 of file note_hash_tree_check.hpp.

Constructor & Destructor Documentation

◆ NoteHashTreeCheck()

bb::avm2::simulation::NoteHashTreeCheck::NoteHashTreeCheck ( const FF first_nullifier,
Poseidon2Interface poseidon2,
MerkleCheckInterface merkle_check,
EventEmitterInterface< NoteHashTreeCheckEvent > &  event_emitter 
)
inline

Definition at line 20 of file note_hash_tree_check.hpp.

Member Function Documentation

◆ append_note_hash()

AppendOnlyTreeSnapshot bb::avm2::simulation::NoteHashTreeCheck::append_note_hash ( const FF note_hash,
AztecAddress  contract_address,
uint64_t  note_hash_counter,
std::span< const FF sibling_path,
const AppendOnlyTreeSnapshot prev_snapshot 
)
overridevirtual

Appends a raw (inner) note hash to the tree after siloing and making it unique.

This is the standard entry point for user-space note hash insertion. The note hash is first siloed with the contract address, then made unique using a nonce derived from the first nullifier and the note hash counter, before being inserted into the tree.

Parameters
note_hashThe raw (inner) note hash to append.
contract_addressThe address of the contract that created the note.
note_hash_counterA counter distinguishing this note hash within the transaction.
sibling_pathThe Merkle sibling path for the append operation.
prev_snapshotThe tree snapshot before the append.
Returns
The updated tree snapshot after inserting the new leaf.

Implements bb::avm2::simulation::NoteHashTreeCheckInterface.

Definition at line 91 of file note_hash_tree_check.cpp.

◆ append_note_hash_internal()

AppendOnlyTreeSnapshot bb::avm2::simulation::NoteHashTreeCheck::append_note_hash_internal ( FF  note_hash,
std::optional< AztecAddress contract_address,
bool  should_make_unique,
uint64_t  note_hash_counter,
std::span< const FF sibling_path,
const AppendOnlyTreeSnapshot prev_snapshot 
)
private

Internal implementation for all note hash append variants.

Optionally silos and/or makes the note hash unique before inserting it as a new leaf at the next available index. Performs a Merkle write (replacing a zero leaf) and emits a read/write event capturing all intermediate data for constraint generation.

Parameters
note_hashThe note hash to insert (may be raw, siloed, or unique depending on caller).
contract_addressIf present, the note hash is siloed with this address before insertion.
should_make_uniqueIf true, a nonce is derived and the note hash is made unique.
note_hash_counterA counter distinguishing this note hash within the transaction.
sibling_pathThe Merkle sibling path for the append operation.
prev_snapshotThe tree snapshot before the append.
Returns
The updated tree snapshot after inserting the new leaf.

Definition at line 166 of file note_hash_tree_check.cpp.

◆ append_siloed_note_hash()

AppendOnlyTreeSnapshot bb::avm2::simulation::NoteHashTreeCheck::append_siloed_note_hash ( const FF siloed_note_hash,
uint64_t  note_hash_counter,
std::span< const FF sibling_path,
const AppendOnlyTreeSnapshot prev_snapshot 
)
overridevirtual

Appends a pre-siloed note hash to the tree after making it unique.

Skips the siloing step (the note hash is already bound to a contract) but still derives a nonce and computes the unique note hash before insertion.

Parameters
siloed_note_hashThe already-siloed note hash to append.
note_hash_counterA counter distinguishing this note hash within the transaction.
sibling_pathThe Merkle sibling path for the append operation.
prev_snapshotThe tree snapshot before the append.
Returns
The updated tree snapshot after inserting the new leaf.

Implements bb::avm2::simulation::NoteHashTreeCheckInterface.

Definition at line 113 of file note_hash_tree_check.cpp.

◆ append_unique_note_hash()

AppendOnlyTreeSnapshot bb::avm2::simulation::NoteHashTreeCheck::append_unique_note_hash ( const FF unique_note_hash,
uint64_t  note_hash_counter,
std::span< const FF sibling_path,
const AppendOnlyTreeSnapshot prev_snapshot 
)
overridevirtual

Appends a pre-computed unique note hash directly to the tree.

Skips both siloing and uniqueness derivation – the note hash is inserted as-is. This is used when the caller has already performed all transformations externally.

Parameters
unique_note_hashThe fully-unique note hash to append.
note_hash_counterA counter distinguishing this note hash within the transaction.
sibling_pathThe Merkle sibling path for the append operation.
prev_snapshotThe tree snapshot before the append.
Returns
The updated tree snapshot after inserting the new leaf.

Implements bb::avm2::simulation::NoteHashTreeCheckInterface.

Definition at line 138 of file note_hash_tree_check.cpp.

◆ get_first_nullifier()

FF bb::avm2::simulation::NoteHashTreeCheck::get_first_nullifier ( ) const
inlineoverridevirtual

◆ make_nonce()

FF bb::avm2::simulation::NoteHashTreeCheck::make_nonce ( uint64_t  note_hash_counter) const
private

Derives a nonce for a note hash from the transaction's first nullifier and the note hash counter.

The nonce ensures uniqueness of note hashes within and across transactions.

Parameters
note_hash_counterThe index of the note hash in the transaction.
Returns
The nonce: Poseidon2(DOM_SEP__NOTE_HASH_NONCE, first_nullifier, note_hash_counter).

Definition at line 58 of file note_hash_tree_check.cpp.

◆ make_siloed()

FF bb::avm2::simulation::NoteHashTreeCheck::make_siloed ( AztecAddress  contract_address,
const FF note_hash 
) const
private

Computes the siloed note hash by hashing the contract address with the note hash.

Siloing binds a note hash to its originating contract, preventing cross-contract collisions. Uses Poseidon2 with a domain separator for siloed note hashes.

Parameters
contract_addressThe address of the contract that created the note.
note_hashThe original (inner) note hash.
Returns
The siloed note hash: Poseidon2(DOM_SEP__SILOED_NOTE_HASH, contract_address, note_hash).

Definition at line 45 of file note_hash_tree_check.cpp.

◆ make_unique()

FF bb::avm2::simulation::NoteHashTreeCheck::make_unique ( const FF siloed_note_hash,
const FF nonce 
) const
private

Computes a unique note hash by combining a siloed note hash with its nonce.

This final transformation guarantees global uniqueness of the note hash.

Parameters
siloed_note_hashThe siloed note hash (already bound to a contract).
nonceThe nonce derived from the first nullifier and note hash counter.
Returns
The unique note hash: Poseidon2(DOM_SEP__UNIQUE_NOTE_HASH, nonce, siloed_note_hash).

Definition at line 72 of file note_hash_tree_check.cpp.

◆ note_hash_exists()

bool bb::avm2::simulation::NoteHashTreeCheck::note_hash_exists ( const FF unique_note_hash,
const FF leaf_value,
uint64_t  leaf_index,
std::span< const FF sibling_path,
const AppendOnlyTreeSnapshot snapshot 
)
overridevirtual

Checks whether a note hash exists in the note hash tree via Merkle membership proof.

Verifies that leaf_value is present at leaf_index in the tree whose root is given by snapshot, then compares it against the claimed unique_note_hash.

Note
This function does not validate that leaf_index is within the bounds of the tree nor that it is less than the next available leaf index.
Parameters
unique_note_hashThe unique note hash the caller claims to exist.
leaf_valueThe actual leaf value retrieved from the tree.
leaf_indexThe index of the leaf in the tree.
sibling_pathThe Merkle sibling path used for the membership proof.
snapshotThe tree snapshot (root + size) to verify against.
Returns
true if unique_note_hash equals leaf_value, false otherwise.

Implements bb::avm2::simulation::NoteHashTreeCheckInterface.

Definition at line 21 of file note_hash_tree_check.cpp.

◆ on_checkpoint_committed()

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

Emits a checkpoint commit event, finalizing pending note hash tree changes.

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

Definition at line 214 of file note_hash_tree_check.cpp.

◆ on_checkpoint_created()

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

Emits a checkpoint creation event for the note hash tree.

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

Definition at line 208 of file note_hash_tree_check.cpp.

◆ on_checkpoint_reverted()

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

Emits a checkpoint revert event, rolling back pending note hash tree changes.

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

Definition at line 220 of file note_hash_tree_check.cpp.

Member Data Documentation

◆ events

EventEmitterInterface<NoteHashTreeCheckEvent>& bb::avm2::simulation::NoteHashTreeCheck::events
private

Definition at line 67 of file note_hash_tree_check.hpp.

◆ first_nullifier

FF bb::avm2::simulation::NoteHashTreeCheck::first_nullifier
private

Definition at line 66 of file note_hash_tree_check.hpp.

◆ merkle_check

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

Definition at line 69 of file note_hash_tree_check.hpp.

◆ poseidon2

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

Definition at line 68 of file note_hash_tree_check.hpp.


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