Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
merkle.cpp
Go to the documentation of this file.
1#include <cstdint>
2
7
8namespace bb::avm2::simulation {
9
11
12FF unconstrained_root_from_path(const FF& leaf_value, const uint64_t leaf_index, std::span<const FF> path)
13{
14 FF curr_value = leaf_value;
15 uint64_t curr_index = leaf_index;
16 for (const auto& i : path) {
17 bool index_is_even = (curr_index % 2 == 0);
18
19 curr_value = index_is_even ? Poseidon2::hash({ curr_value, i }) : Poseidon2::hash({ i, curr_value });
20 // Halve the index (to get the parent index) as we move up the tree
21 curr_index >>= 1;
22 }
23 return curr_value;
24}
25
30
35
40
42 const FF& first_nullifier,
43 uint64_t note_hash_counter)
44{
45 FF nonce = Poseidon2::hash({ GENERATOR_INDEX__NOTE_HASH_NONCE, first_nullifier, note_hash_counter });
46 return Poseidon2::hash({ GENERATOR_INDEX__UNIQUE_NOTE_HASH, nonce, siloed_note_hash });
47}
48
49} // namespace bb::avm2::simulation
#define GENERATOR_INDEX__PUBLIC_LEAF_INDEX
#define GENERATOR_INDEX__NOTE_HASH_NONCE
#define GENERATOR_INDEX__OUTER_NULLIFIER
#define GENERATOR_INDEX__SILOED_NOTE_HASH
#define GENERATOR_INDEX__UNIQUE_NOTE_HASH
static FF hash(const std::vector< FF > &input)
Hashes a vector of field elements.
FF unconstrained_make_unique_note_hash(const FF &siloed_note_hash, const FF &first_nullifier, uint64_t note_hash_counter)
Definition merkle.cpp:41
FF unconstrained_root_from_path(const FF &leaf_value, const uint64_t leaf_index, std::span< const FF > path)
Definition merkle.cpp:12
FF unconstrained_compute_leaf_slot(const AztecAddress &contract_address, const FF &slot)
Definition merkle.cpp:26
FF unconstrained_silo_note_hash(const AztecAddress &contract_address, const FF &note_hash)
Definition merkle.cpp:36
FF unconstrained_silo_nullifier(const AztecAddress &contract_address, const FF &nullifier)
Definition merkle.cpp:31
AvmFlavorSettings::FF FF
Definition field.hpp:10
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13