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
3
#include "
barretenberg/crypto/poseidon2/poseidon2.hpp
"
4
#include "
barretenberg/vm2/common/aztec_constants.hpp
"
5
#include "
barretenberg/vm2/common/aztec_types.hpp
"
6
#include "
barretenberg/vm2/common/field.hpp
"
7
8
namespace
bb::avm2::simulation
{
9
10
using
Poseidon2
= crypto::Poseidon2<crypto::Poseidon2Bn254ScalarFieldParams>;
11
12
FF
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
26
FF
unconstrained_compute_leaf_slot
(
const
AztecAddress
&
contract_address
,
const
FF
&
slot
)
27
{
28
return
Poseidon2::hash
({
GENERATOR_INDEX__PUBLIC_LEAF_INDEX
,
contract_address
,
slot
});
29
}
30
31
FF
unconstrained_silo_nullifier
(
const
AztecAddress
&
contract_address
,
const
FF
&
nullifier
)
32
{
33
return
Poseidon2::hash
({
GENERATOR_INDEX__OUTER_NULLIFIER
,
contract_address
,
nullifier
});
34
}
35
36
FF
unconstrained_silo_note_hash
(
const
AztecAddress
&
contract_address
,
const
FF
& note_hash)
37
{
38
return
Poseidon2::hash
({
GENERATOR_INDEX__SILOED_NOTE_HASH
,
contract_address
, note_hash });
39
}
40
41
FF
unconstrained_make_unique_note_hash
(
const
FF
& siloed_note_hash,
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
aztec_constants.hpp
GENERATOR_INDEX__PUBLIC_LEAF_INDEX
#define GENERATOR_INDEX__PUBLIC_LEAF_INDEX
Definition
aztec_constants.hpp:256
GENERATOR_INDEX__NOTE_HASH_NONCE
#define GENERATOR_INDEX__NOTE_HASH_NONCE
Definition
aztec_constants.hpp:250
GENERATOR_INDEX__OUTER_NULLIFIER
#define GENERATOR_INDEX__OUTER_NULLIFIER
Definition
aztec_constants.hpp:253
GENERATOR_INDEX__SILOED_NOTE_HASH
#define GENERATOR_INDEX__SILOED_NOTE_HASH
Definition
aztec_constants.hpp:252
GENERATOR_INDEX__UNIQUE_NOTE_HASH
#define GENERATOR_INDEX__UNIQUE_NOTE_HASH
Definition
aztec_constants.hpp:251
aztec_types.hpp
bb::crypto::Poseidon2< crypto::Poseidon2Bn254ScalarFieldParams >::hash
static FF hash(const std::vector< FF > &input)
Hashes a vector of field elements.
bb::crypto::merkle_tree::ContentAddressedIndexedTree
Implements a parallelized batch insertion indexed tree Accepts template argument of the type of store...
Definition
content_addressed_indexed_tree.hpp:52
nullifier
FF nullifier
Definition
nullifier_tree_check.test.cpp:72
contract_address
AztecAddress contract_address
Definition
written_public_data_slots_tree_check.test.cpp:97
poseidon2.hpp
bb::avm2::simulation
Definition
address_derivation_event.hpp:6
bb::avm2::simulation::unconstrained_make_unique_note_hash
FF unconstrained_make_unique_note_hash(const FF &siloed_note_hash, const FF &first_nullifier, uint64_t note_hash_counter)
Definition
merkle.cpp:41
bb::avm2::simulation::unconstrained_root_from_path
FF unconstrained_root_from_path(const FF &leaf_value, const uint64_t leaf_index, std::span< const FF > path)
Definition
merkle.cpp:12
bb::avm2::simulation::unconstrained_compute_leaf_slot
FF unconstrained_compute_leaf_slot(const AztecAddress &contract_address, const FF &slot)
Definition
merkle.cpp:26
bb::avm2::simulation::unconstrained_silo_note_hash
FF unconstrained_silo_note_hash(const AztecAddress &contract_address, const FF ¬e_hash)
Definition
merkle.cpp:36
bb::avm2::simulation::unconstrained_silo_nullifier
FF unconstrained_silo_nullifier(const AztecAddress &contract_address, const FF &nullifier)
Definition
merkle.cpp:31
bb::avm2::AztecAddress
FF AztecAddress
Definition
aztec_types.hpp:12
bb::avm2::FF
AvmFlavorSettings::FF FF
Definition
field.hpp:10
std::get
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition
tuple.hpp:13
slot
FF slot
Definition
public_data_tree.test.cpp:96
field.hpp
src
barretenberg
vm2
simulation
lib
merkle.cpp
Generated by
1.9.8