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.
2
3#include <cassert>
4
7
8namespace bb::avm2::simulation {
9
26{
27 // Check if we've already derived this class_id.
28 if (cached_derivations.contains(klass.id)) {
29 // Already processed this class_id - cache hit, don't emit event.
30 return;
31 }
32
33 // First time seeing this class_id - do the actual derivation.
34 // Emits Poseidon2HashEvent and Poseidon2PermutationEvents, see #[CLASS_ID_POSEIDON2_i]
35 // lookups in class_id_derivation.pil.
36 FF computed_class_id = poseidon2.hash({ DOM_SEP__CONTRACT_CLASS_ID,
37 klass.artifact_hash,
40 // This will throw an unexpected exception if it fails. If we have reached this point,
41 // the contract class registry should have enforced this.
42 BB_ASSERT_EQ(computed_class_id, klass.id, "Computed class ID mismatch");
43
44 // Cache this derivation so we don't repeat it.
45 cached_derivations.insert(klass.id);
46
47 // Emits ClassIdDerivationEvent.
48 events.emit({ .class_id = klass.id,
49 .artifact_hash = klass.artifact_hash,
50 .private_functions_root = klass.private_functions_root,
51 .public_bytecode_commitment = klass.public_bytecode_commitment });
52}
53
54} // namespace bb::avm2::simulation
#define BB_ASSERT_EQ(actual, expected,...)
Definition assert.hpp:83
#define DOM_SEP__CONTRACT_CLASS_ID
EventEmitterInterface< ClassIdDerivationEvent > & events
void assert_derivation(const ContractClassWithCommitment &klass) override
Computes the contract class ID and emits a ClassIdDerivationEvent. Corresponds to the subtrace class_...
unordered_flat_set< ContractClassId > cached_derivations
static FF hash(const std::vector< FF > &input)
Hashes a vector of field elements.
AVM range check gadget for witness generation.
AvmFlavorSettings::FF FF
Definition field.hpp:10