Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
class_id_derivation.cpp
Go to the documentation of this file.
1
#include "
barretenberg/vm2/simulation/class_id_derivation.hpp
"
2
3
#include <cassert>
4
5
#include "
barretenberg/vm2/common/aztec_constants.hpp
"
6
#include "
barretenberg/vm2/simulation/lib/contract_crypto.hpp
"
7
#include "
barretenberg/vm2/simulation/poseidon2.hpp
"
8
9
namespace
bb::avm2::simulation
{
10
11
void
ClassIdDerivation::assert_derivation
(
const
ContractClassId
& class_id,
const
ContractClass
& klass)
12
{
13
// Check if we've already derived this class_id
14
if
(
cached_derivations
.contains(class_id)) {
15
// Already processed this class_id - cache hit, don't emit event
16
return
;
17
}
18
19
// First time seeing this class_id - do the actual derivation
20
FF
computed_class_id =
poseidon2
.
hash
({
GENERATOR_INDEX__CONTRACT_LEAF
,
21
klass.
artifact_hash
,
22
klass.
private_function_root
,
23
klass.
public_bytecode_commitment
});
24
(void)computed_class_id;
// Silence unused variable warning when assert is stripped out
25
assert(computed_class_id == class_id);
26
27
// Cache this derivation so we don't repeat it
28
cached_derivations
.insert(class_id);
29
30
events
.emit({ .class_id = class_id, .klass = klass });
31
}
32
33
}
// namespace bb::avm2::simulation
aztec_constants.hpp
GENERATOR_INDEX__CONTRACT_LEAF
#define GENERATOR_INDEX__CONTRACT_LEAF
Definition
aztec_constants.hpp:269
bb::avm2::simulation::ClassIdDerivation::events
EventEmitterInterface< ClassIdDerivationEvent > & events
Definition
class_id_derivation.hpp:28
bb::avm2::simulation::ClassIdDerivation::assert_derivation
void assert_derivation(const ContractClassId &class_id, const ContractClass &klass) override
Definition
class_id_derivation.cpp:11
bb::avm2::simulation::ClassIdDerivation::cached_derivations
std::unordered_set< ContractClassId > cached_derivations
Definition
class_id_derivation.hpp:32
bb::crypto::Poseidon2< crypto::Poseidon2Bn254ScalarFieldParams >
bb::crypto::Poseidon2::hash
static FF hash(const std::vector< FF > &input)
Hashes a vector of field elements.
contract_crypto.hpp
bb::avm2::simulation
Definition
address_derivation.cpp:8
bb::avm2::ContractClassId
FF ContractClassId
Definition
aztec_types.hpp:12
bb::avm2::FF
AvmFlavorSettings::FF FF
Definition
field.hpp:10
class_id_derivation.hpp
bb::avm2::ContractClass
Definition
aztec_types.hpp:93
bb::avm2::ContractClass::public_bytecode_commitment
FF public_bytecode_commitment
Definition
aztec_types.hpp:96
bb::avm2::ContractClass::artifact_hash
FF artifact_hash
Definition
aztec_types.hpp:94
bb::avm2::ContractClass::private_function_root
FF private_function_root
Definition
aztec_types.hpp:95
poseidon2.hpp
src
barretenberg
vm2
simulation
class_id_derivation.cpp
Generated by
1.9.8