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(uint64_t domain_separator,
13 const FF& leaf_value,
14 const uint64_t leaf_index,
16{
17 FF curr_value = leaf_value;
18 uint64_t curr_index = leaf_index;
19 for (const auto& i : path) {
20 bool index_is_even = (curr_index % 2 == 0);
21
22 curr_value = index_is_even ? Poseidon2::hash({ FF(domain_separator), curr_value, i })
23 : Poseidon2::hash({ FF(domain_separator), i, curr_value });
24 // Halve the index (to get the parent index) as we move up the tree
25 curr_index >>= 1;
26 }
27 return curr_value;
28}
29
30FF unconstrained_compute_leaf_slot(const AztecAddress& contract_address, const FF& slot)
31{
32 return Poseidon2::hash({ DOM_SEP__PUBLIC_LEAF_SLOT, contract_address, slot });
33}
34
35FF unconstrained_silo_nullifier(const AztecAddress& contract_address, const FF& nullifier)
36{
37 return Poseidon2::hash({ DOM_SEP__SILOED_NULLIFIER, contract_address, nullifier });
38}
39
41{
42 return Poseidon2::hash({ DOM_SEP__SILOED_NOTE_HASH, contract_address, note_hash });
43}
44
46 const FF& first_nullifier,
47 uint64_t note_hash_counter)
48{
49 FF nonce = Poseidon2::hash({ DOM_SEP__NOTE_HASH_NONCE, first_nullifier, note_hash_counter });
50 return Poseidon2::hash({ DOM_SEP__UNIQUE_NOTE_HASH, nonce, siloed_note_hash });
51}
52
53} // namespace bb::avm2::simulation
#define DOM_SEP__SILOED_NOTE_HASH
#define DOM_SEP__UNIQUE_NOTE_HASH
#define DOM_SEP__NOTE_HASH_NONCE
#define DOM_SEP__SILOED_NULLIFIER
#define DOM_SEP__PUBLIC_LEAF_SLOT
Native Poseidon2 hash function implementation.
Definition poseidon2.hpp:22
static FF hash(const std::vector< FF > &input)
Hashes a vector of field elements.
AVM range check gadget for witness generation.
FF unconstrained_make_unique_note_hash(const FF &siloed_note_hash, const FF &first_nullifier, uint64_t note_hash_counter)
Definition merkle.cpp:45
FF unconstrained_root_from_path(uint64_t domain_separator, 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:30
FF unconstrained_silo_note_hash(const AztecAddress &contract_address, const FF &note_hash)
Definition merkle.cpp:40
FF unconstrained_silo_nullifier(const AztecAddress &contract_address, const FF &nullifier)
Definition merkle.cpp:35
AvmFlavorSettings::FF FF
Definition field.hpp:10
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13